Commit 9a0af8e0 by Billy Larru

proyectado de asistencia con array de promesas

parent 76bac4fb
......@@ -27,6 +27,7 @@ const URI_POLICIAS_ASISTENCIA = "asistenciaPolicias";
const URI_POLICIA_MONTOS_AMANECIDAS = "montoAmanecidas";
const URI_POLICIA_CONCEPTOSEDES = "conceptoSedes";
const URI_POLICIA_REPORTE_MONTOS = "reporteMontosPolicias";
const URI_POLICIA_PROYECCION = "proyeccion";
//</editor-fold>
......@@ -302,7 +303,7 @@ data: [],
classNameForDatatable: ``,
footerFilter: false,
highlighting: true
}) => {
}) => {
let data = jsonForDatatable.data;
let columns = jsonForDatatable.columns;
let columnDefs = jsonForDatatable.columns;
......
......@@ -5,250 +5,242 @@ let handsonTable;
const TA_EDITOR_HORA = Handsontable.editors.TextEditor.prototype.extend();
TA_EDITOR_HORA.prototype.createElements = function () {
Handsontable.editors.TextEditor.prototype.createElements.apply(this, arguments);
Handsontable.editors.TextEditor.prototype.createElements.apply(this, arguments);
// You need to require/import the "inputmask" library
var im = new Inputmask('99:99');
// You need to require/import the "inputmask" library
var im = new Inputmask('99:99');
// Create password input and update relevant properties
this.TEXTAREA = document.createElement('input');
this.TEXTAREA.setAttribute('type', 'text');
this.TEXTAREA.className = 'text';
im.mask(this.TEXTAREA);
this.textareaStyle = this.TEXTAREA.style;
this.textareaStyle.width = 0;
this.textareaStyle.height = 0;
// Create password input and update relevant properties
this.TEXTAREA = document.createElement('input');
this.TEXTAREA.setAttribute('type', 'text');
this.TEXTAREA.className = 'text';
im.mask(this.TEXTAREA);
this.textareaStyle = this.TEXTAREA.style;
this.textareaStyle.width = 0;
this.textareaStyle.height = 0;
// Replace textarea with password input
Handsontable.dom.empty(this.TEXTAREA_PARENT);
this.TEXTAREA_PARENT.appendChild(this.TEXTAREA);
// Replace textarea with password input
Handsontable.dom.empty(this.TEXTAREA_PARENT);
this.TEXTAREA_PARENT.appendChild(this.TEXTAREA);
};
function listarSedes(selectorName) {
ajaxWebService.get(URI_SEDES).then((result) => {
let sedes = result.data;
sedes = _.orderBy(sedes, s => s.descripcion);
listaSedes = _.map(sedes, s => s.descripcion);
let html = `<option value="">[TODOS]</option>`;
sedes.forEach(sede => html += `<option value="${sede.codigo}">${sede.descripcion}</option>`);
$(`${selectorName}`).html(html);
$('.select-search').select2();
});
ajaxWebService.get(URI_SEDES).then((result) => {
let sedes = result.data;
sedes = _.orderBy(sedes, s => s.descripcion);
listaSedes = _.map(sedes, s => s.descripcion);
let html = `<option value="">[TODOS]</option>`;
sedes.forEach(sede => html += `<option value="${sede.codigo}">${sede.descripcion}</option>`);
$(`${selectorName}`).html(html);
$('.select-search').select2();
});
}
function listarPolicias(selectorName) {
ajaxWebService.get(URI_POLICIAS).then((result) => {
let policias = result.data;
policias = _.orderBy(policias, p => p.nombres);
let html = `<option value="">[TODOS]</option>`;
policias.forEach(p => html += `<option documento_identidad="${p.dni}" value="${p.id}">${p.nombres}</option>`);
$(`${selectorName}`).html(html);
$('.select-search').select2();
});
ajaxWebService.get(URI_POLICIAS).then((result) => {
let policias = result.data;
policias = _.orderBy(policias, p => p.nombres);
let html = `<option value="">[TODOS]</option>`;
policias.forEach(p => html += `<option documento_identidad="${p.dni}" value="${p.id}">${p.nombres}</option>`);
$(`${selectorName}`).html(html);
$('.select-search').select2();
});
}
function defaultConfigHandsonTable() {
let container = document.getElementById("tblProyectado");
handsonTable = new Handsontable(container, {
data: [],
stretchH: 'all',
rowHeaders: true,
colHeaders: ['DNI', 'Apellidos y Nombres', 'Sede', 'Horario', 'Rol', 'Fecha Entrada', 'Hora entrada', 'Hora Salida', 'Fecha Salida'],
columns: [{}, {}, {}, {}, {}, {}, {}, {}, {}]
});
let container = document.getElementById("tblProyectado");
handsonTable = new Handsontable(container, {
data: [],
stretchH: 'all',
rowHeaders: true,
colHeaders: ['DNI', 'Apellidos y Nombres', 'Sede', 'Horario', 'Rol', 'Fecha Entrada', 'Hora entrada', 'Hora Salida', 'Fecha Salida'],
columns: [{}, {}, {}, {}, {}, {}, {}, {}, {}]
});
}
function mostrarVistaPrevia() {
ajaxWebService.get(URI_ROL_POLICIA).then((response) => {
debugger
if (response.status) {
handsonTable.destroy();
let container = document.getElementById("tblProyectado");
let data = [];
response.data.forEach(rol => {
rol.detalles_rol
.map(dr => {
dr.horario = `${dr.fecha_entrada.split(" ")[1]} - ${dr.fecha_salida.split(" ")[1]}`;
dr.fecha_entrada = dr.fecha_entrada.split(" ")[0];
dr.fecha_salida = dr.fecha_salida.split(" ")[0];
dr.asistencia_entrada = dr.asistencia_entrada === null ? "" : dr.asistencia_entrada.split(" ")[1];
dr.asistencia_salida = dr.asistencia_salida === null ? "" : dr.asistencia_salida.split(" ")[1];
return dr;
})
.forEach(dr => {
let obj = {
rol_id: rol.id,
detallerol_id: dr.id,
policia_dni: rol.policia_dni,
policia_nombres: rol.policia_nombres,
fecha_entrada: dr.fecha_entrada,
fecha_salida: dr.fecha_salida,
sede_id: rol.sede_id,
sede_descripcion: rol.sede_descripcion,
horario: dr.horario,
tiporol_descripcion: rol.tiporol_descripcion,
marcacion_entrada: dr.asistencia_entrada,
marcacion_salida: dr.asistencia_salida
};
data.push(obj);
});
});
handsonTable = new Handsontable(container, {
data: data,
stretchH: 'all',
rowHeaders: true,
colHeaders: ['DNI', 'Apellidos y Nombres', 'Sede', 'Horario', 'Rol', 'Fecha Entrada', 'Hora entrada', 'Hora Salida', 'Fecha Salida'],
columns: [
{
data: "policia_dni",
className: 'text-center',
readOnly: true
},
{
"data": "policia_nombres",
readOnly: true
},
{
"data": "sede_descripcion",
"className": "text-center",
ajaxWebService.get(URI_POLICIA_PROYECCION).then((response) => {
debugger
if (response.status) {
handsonTable.destroy();
let container = document.getElementById("tblProyectado");
handsonTable = new Handsontable(container, {
data: response.data,
stretchH: 'all',
rowHeaders: true,
colHeaders: ['DNI', 'Apellidos y Nombres', 'Sede', 'Horario', 'Rol', 'Fecha Entrada', 'Hora entrada', 'Hora Salida', 'Fecha Salida'],
columns: [
{
data: "policia_dni",
className: 'text-center',
readOnly: true
},
{
"data": "policia_nombres",
readOnly: true
},
{
"data": "sede_descripcion",
"className": "text-center",
// editor: 'select',
// selectOptions: sedes,
source: listaSedes,
strict: true,
type: 'autocomplete',
allowInvalid: false
},
{
"data": "horario",
"className": "text-center",
readOnly: true
},
{
"data": "tiporol_descripcion",
"className": "text-center",
readOnly: true
},
{
"data": "fecha_entrada",
"className": 'text-center',
type: 'date',
dateFormat: 'DD/MM/YYYY',
readOnly: true
},
{
data: "marcacion_entrada",
className: 'text-center',
editor: TA_EDITOR_HORA,
type: 'time',
timeFormat: 'HH:mm',
correctFormat: true,
allowInvalid: false
},
{
data: "marcacion_salida",
className: 'text-center',
timeFormat: 'HH:mm',
editor: TA_EDITOR_HORA,
type: 'time',
correctFormat: true,
allowInvalid: false,
},
{
data: "fecha_salida",
className: 'text-center',
type: 'date',
dateFormat: 'DD/MM/YYYY',
readOnly: true
}
],
source: listaSedes,
strict: true,
type: 'autocomplete',
allowInvalid: false
},
{
"data": "horario",
"className": "text-center",
readOnly: true
},
{
"data": "tiporol_descripcion",
"className": "text-center",
readOnly: true
},
{
"data": "fecha_entrada",
"className": 'text-center',
type: 'date',
dateFormat: 'DD/MM/YYYY',
readOnly: true
},
{
data: "asistencia_entrada",
className: 'text-center',
editor: TA_EDITOR_HORA,
type: 'time',
timeFormat: 'HH:mm',
correctFormat: true,
allowInvalid: false
},
{
data: "asistencia_salida",
className: 'text-center',
timeFormat: 'HH:mm',
editor: TA_EDITOR_HORA,
type: 'time',
correctFormat: true,
allowInvalid: false,
},
{
data: "fecha_salida",
className: 'text-center',
type: 'date',
dateFormat: 'DD/MM/YYYY',
readOnly: true
}
],
// afterChange: (change, source) => {
// console.log(`change= ${change}, source=${source}`);
// }
});
registrarEventoTab();
}
});
registrarEventoTab();
}
});
});
}
function registrarEventoTab() {
Handsontable.Dom.addEvent(document.body, 'keydown', function (e) {
if (e.keyCode === 9 && handsonTable) {
Handsontable.Dom.addEvent(document.body, 'keydown', function (e) {
if (e.keyCode === 9 && handsonTable) {
e.stopPropagation();
var selection = handsonTable.getSelected();
e.stopPropagation();
var selection = handsonTable.getSelected();
var rowIndex = selection[0];
var colIndex = selection[1];
var rowIndex = selection[0];
var colIndex = selection[1];
// console.log(`row=${rowIndex}, col=${colIndex}`)
//rowIndex++;
colIndex++;
//rowIndex++;
colIndex++;
if (colIndex > 7) {
rowIndex++;
colIndex = 6;
} else if (colIndex < 6) {
colIndex = 6;
}
if (colIndex > 7) {
rowIndex++;
colIndex = 6;
} else if (colIndex < 6) {
colIndex = 6;
}
handsonTable.selectCell(rowIndex, colIndex);
}
});
handsonTable.selectCell(rowIndex, colIndex);
}
});
}
function guardarCambios() {
let data = handsonTable.getSourceData();
let data = handsonTable.getSourceData();
let dataRequest = data.map(d => {
return {
id: d.id,
sede_descripcion: d.sede_descripcion,
asistencia_entrada: d.asistencia_entrada,
asistencia_salida: d.asistencia_salida
}
});
let promises = []
dataRequest.forEach(d => {
promises.push(ajaxWebService.patch(`${URI_POLICIA_PROYECCION}/${d.id}`, d))
});
axios.all(promises)
.then(axios.spread(function (acct, perms) {
debugger
}));
// ajaxWebService.patch(URI_POLICIA_PROYECCION, dataRequest).then((response) => {
//
// });
}
$().ready(function () {
listarPolicias("#cboPoliciasFiltro");
listarSedes("#cboSedesFiltro");
$("#dpFechaInicio").datepicker({
minDate: new Date(2000, 1 - 1, 1), maxDate: new Date(),
dateFormat: 'dd/mm/yy',
defaultDate: new Date(),
changeMonth: true,
changeYear: true,
yearRange: '-18:+0',
onSelect: function () {
listarPolicias("#cboPoliciasFiltro");
listarSedes("#cboSedesFiltro");
$("#dpFechaInicio").datepicker({
minDate: new Date(2000, 1 - 1, 1), maxDate: new Date(),
dateFormat: 'dd/mm/yy',
defaultDate: new Date(),
changeMonth: true,
changeYear: true,
yearRange: '-18:+0',
onSelect: function () {
// $(this).valid();
}
});
$("#dpFechaInicio").datepicker('setDate', 'now');
$("#dpFechaFin").datepicker({
minDate: new Date(2000, 1 - 1, 1), maxDate: new Date(),
dateFormat: 'dd/mm/yy',
defaultDate: new Date(),
changeMonth: true,
changeYear: true,
yearRange: '-18:+0',
onSelect: function () {
}
});
$("#dpFechaInicio").datepicker('setDate', 'now');
$("#dpFechaFin").datepicker({
minDate: new Date(2000, 1 - 1, 1), maxDate: new Date(),
dateFormat: 'dd/mm/yy',
defaultDate: new Date(),
changeMonth: true,
changeYear: true,
yearRange: '-18:+0',
onSelect: function () {
// $(this).valid();
}
});
$("#dpFechaFin").datepicker('setDate', 'now');
}
});
$("#dpFechaFin").datepicker('setDate', 'now');
// defaultConfigDataTable();
defaultConfigHandsonTable();
$("#btnVistaPrevia").click(mostrarVistaPrevia);
$("#btnGuardarCambios").click(guardarCambios);
defaultConfigHandsonTable();
$("#btnVistaPrevia").click(mostrarVistaPrevia);
$("#btnGuardarCambios").click(guardarCambios);
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment