monto_policias.js 5.64 KB
Newer Older
1
function getColumns() {
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
	let columns = [
		{
			title: `N°`,
			data: `id`,
			className: 'text-center'
		},
		{
			title: `POLICIA`,
			data: `policia_nombres`,
			className: `text-center`,
		},
		{
			title: `SEDE`,
			data: `sede_descripcion`,
			className: `text-center`,
17 18 19
			render: (data) => {
				return `<span class="label label-default">${data}</span>`;
			}
20 21 22 23 24 25 26 27 28
		},
		{
			title: `HORARIO`,
			data: `horario`,
			className: 'text-center'
		},
		{
			title: `ROL`,
			data: `tiporol_descripcion`,
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
			className: 'text-center',
			render: (data) => {
				let label = "";

				switch (data) {
					case "REGULAR":
						label = "label bg-slate";
						break;
					case "AMANECIDA 24H":
						label = "label bg-teal";
						break;
					case "AMANECIDA 12H":
						label = "label bg-brown";
						break;
				}
				return `<span class="${label}">${data}</span>`;
			}
46
		},
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
		{
			title: `FECHA ENTRADA`,
			data: `fecha_entrada`,
			className: 'text-center'
		},
		{
			title: `MARC. ENTRADA`,
			data: `marcacion_entrada`,
			className: 'text-center'
		},
		{
			title: `MARC. SALIDA`,
			data: `marcacion_salida`,
			className: 'text-center'
		},
		{
			title: `FECHA SALIDA`,
			data: `fecha_salida`,
			className: 'text-center'
		},
67 68 69
		{
			title: `COSTO HORA`,
			data: `costo_hora`,
70 71 72 73 74 75 76 77 78
			className: 'text-center',
			render: (data) => {
				let label = "";

				if (data > 0) {
					label = "text-primary";
				}
				return `<span class="${label}">${data}0</span>`;
			}
79 80 81 82 83 84 85 86 87
		},
		{
			title: `TIEMPO LABORADO`,
			data: `tiempo_laborado`,
			className: 'text-center'
		},
		{
			title: `MONTO`,
			data: `monto`,
88 89 90 91 92 93 94 95 96
			className: 'text-center',
			render: (data) => {
				let label = "";

				if (data > 0) {
					label = "text-primary";
				}
				return `<span class="${label}">${data}.00</span>`;
			}
97 98 99 100
		},
		{
			title: `DCTO POR NO MARCAR`,
			data: `descuento_no_marco`,
101 102 103 104 105 106 107 108 109
			className: 'text-center',
			render: (data) => {
				let label = "";

				if (data > 0) {
					label = "text-danger";
				}
				return `<span class="${label}">${data}.00</span>`;
			}
110 111 112 113 114 115 116 117 118
		},
		{
			title: `TIEMPO EXTRA`,
			data: `tiempo_extra`,
			className: 'text-center'
		},
		{
			title: `MONTO EXTRAS`,
			data: `monto_extras`,
119 120 121 122 123 124 125 126 127
			className: 'text-center',
			render: (data) => {
				let label = "";

				if (data > 0) {
					label = "text-primary";
				}
				return `<span class="${label}">${data}.00</span>`;
			}
128 129 130 131
		},
		{
			title: `ESTADO EXTRAS`,
			data: `estado_extras`,
132 133 134 135 136 137 138 139 140 141 142 143 144 145
			className: 'text-center',
			render: (data) => {
				let label = "";
				let contenido = "";

				if (data == 1) {
					label = "label label-success";
					contenido = "APROBADO";
				} else {
					label = "label label-danger";
					contenido = "SIN APROBAR";
				}
				return `<span class="${label}">${contenido}</span>`;
			}
146 147 148 149
		},
		{
			title: `MONTO TOTAL`,
			data: `monto_total`,
150 151 152 153 154 155 156 157 158
			className: 'text-center',
			render: (data) => {
				let label = "";

				if (data > 0) {
					label = "text-primary";
				}
				return `<span class="${label}">${data}.00</span>`;
			}
159 160
		},
	];
161

162
	return columns;
163 164
}

165
function listarPolicias(selectorName) {
166 167 168 169 170 171 172 173
	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();
	});
174 175
}
function defaultConfigDateRangePicker(selectorName) {
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
	$(selectorName).daterangepicker({
		"autoApply": true,
		"locale": {
			"format": "DD/MM/YYYY",
			"separator": " - ",
			"applyLabel": "Apply",
			"cancelLabel": "Cancel",
			"fromLabel": "From",
			"toLabel": "To",
			"customRangeLabel": "Custom",
			"weekLabel": "W",
			"daysOfWeek": [
				"Do",
				"Lu",
				"Ma",
				"Mi",
				"Ju",
				"Vi",
				"Sa"
			],
			"monthNames": [
				"Enero",
				"Febrero",
				"Marzo",
				"Abril",
				"Mayo",
				"Junio",
				"Julio",
				"Agosto",
				"Setiembre",
				"Octubre",
				"Noviembre",
				"Diciembre"
			],
			"firstDay": 1
		},
		"startDate": "17/08/2018",
		"endDate": "23/08/2018"
	}, function (start, end, label) {
215
//                    console.log('New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')');
216 217
	});
	$(selectorName).datepicker('setDate', 'now');
218 219
}

220

221
function mostrarTodos(objParams = {}) {
222 223
	ajaxWebService.get(URI_POLICIA_REPORTE_MONTOS, objParams).then((response) => {
		let columns = getColumns();
224

225 226
		let wrapsNameDatatable = `divDatatable`;
		let classNameForDatatable = `display table table-bordered`;
227

228
		makeDatatable(
229 230 231 232 233 234 235
			wrapsNameDatatable,
			{
				data: response.data,
				columns
			},
			classNameForDatatable,
			);
236
	});
237 238 239
}


240

241
function aplicarFiltro() {
242 243 244 245
	debugger
	let rango_fechas = $("#dpRangoFechas").val();
	let split_fechas = rango_fechas.split("-").map(f => f.trim());
	let fecha_inicio = split_fechas[0];
246
	let fecha_fin = split_fechas[1];
247 248
	let policia_nombres = $("#cboPoliciasFiltro option:selected").text();
	let sede_descripcion = $("#cboSedesFiltro option:selected").text();
249
	let intervalo_fechas = generarFechas(fecha_inicio, fecha_fin);
250 251 252 253
	policia_nombres = policia_nombres.includes("TODOS") ? "" : policia_nombres
	sede_descripcion = sede_descripcion.includes("TODOS") ? "" : sede_descripcion

	let params = cleanQueryParams({
254
		fecha_entrada: intervalo_fechas,
255 256 257 258
		policia_nombres,
		sede_descripcion
	});

259
	mostrarTodos({params});
260 261
}

262
$().ready(function () {
263 264 265
	listarPolicias("#cboPoliciasFiltro");
	listarSedes("#cboSedesFiltro");
	defaultConfigDateRangePicker("#dpRangoFechas");
266 267
	$("#btnMostrarTodos").click(mostrarTodos);
	$("#btnAplicarFiltro").click(aplicarFiltro);
268
});