function getColumns() {
	let columns = [
		{
			title: `N°`,
			data: `id`,
			className: 'text-center'
		},
		{
			title: `DNI`,
			data: `policia_dni`,
			className: `text-center`,
		},
		{
			title: `APELLIDOS Y NOMBRES`,
			data: `policia_nombres`,
			className: 'text-center'
		},
		{
			title: `TURNO`,
			data: `tiporol_descripcion`,
			className: `text-center`,
		},
		{
			title: `SEDE`,
			data: `sede_descripcion`,
			className: `text-center`,
		},
		{
			title: `COSTO`,
			data: `costo`,
			className: `text-center`,
		},
		{
			title: `FECHA ENTRADA`,
			data: `fecha_entrada`,
			className: `text-center`,
		},
		{
			title: `HORA ENTRADA`,
			data: `entrada_proyectada`,
			className: `text-center`,
		},
		{
			title: `HORA ENTRADA REAL`,
			data: `marcacion_entrada`,
			className: `text-center`,
		},
		{
			title: `DIFERENCIA ENTRADA(min)`,
			data: `diferencia_entrada`,
			className: `text-center`,
		},
		{
			title: `FECHA SALIDA`,
			data: `fecha_salida`,
			className: `text-center`,
		},
		{
			title: `HORA SALIDA`,
			data: `salida_proyectada`,
			className: `text-center`,
		},
		{
			title: `HORA SALIDA REAL`,
			data: `marcacion_salida`,
			className: `text-center`,
		},
		{
			title: `DIFERENCIA DE SALIDAS(min)`,
			data: `diferencia_salida`,
			className: `text-center`,
		},
		{
			title: `DIFERENCIA TOTAL`,
			data: `diferencia_total`,
			className: `text-center`,
		},
		{
			title: `MONTO`,
			data: `monto`,
			className: `text-center`,
		},
		{
			title: `OBSERVACION`,
			data: `observacion`,
			className: `text-center`,
		},
	];

	return columns;
}

function getColumnDefs() {
	let columnDefs = [
		{orderable: false, width: '3%', targets: 0, className: "text-center"},
		{orderable: false, width: '10%', targets: 1, className: "text-center"},
		{orderable: false, width: '30%', targets: 2, className: "text-center"},
		{orderable: false, width: '7%', targets: 3, className: "text-center"},
		{orderable: false, width: '7%', targets: 4, className: "text-center"},
		{orderable: false, width: '7%', targets: 5, className: "text-center"},
		{orderable: false, width: '7%', targets: 6, className: "text-center"},
		{orderable: false, width: '7%', targets: 7, className: "text-center"},
		{orderable: false, width: '7%', targets: 8, className: "text-center"},
		{orderable: false, width: '7%', targets: 9, className: "text-center"},
		{orderable: false, width: '7%', targets: 10, className: "text-center"},
		{orderable: false, width: '7%', targets: 11, className: "text-center"},
		{orderable: false, width: '7%', targets: 12, className: "text-center"},
		{orderable: false, width: '7%', targets: 13, className: "text-center"},
		{orderable: false, width: '7%', targets: 14, className: "text-center"},
		{orderable: false, width: '7%', targets: 15, className: "text-center"},
		{orderable: false, width: '7%', targets: 16, className: "text-center"},
	];
	return columnDefs;
}


function listarPolicias(selectorName) {
	initSelect2(selectorName, "http://sistem16:666/policias", {title: "nombres", subtitle: "dni"});
}

function verReporte() {	
//	let policia_nombres = $("#cboPolicias option:selected").text();
	let fecha_inicio = $("#dpFechaInicio").val();

	let jsonPolicia = $('#cboPolicias').select2('data')[0];

	let dni = jsonPolicia ? jsonPolicia.dni : "";

	let params = cleanQueryParams({
		policia_dni: dni,
		fecha_entrada: fecha_inicio
	});


	ajaxWebService.get(URI_POLICIA_PROYECTADO_COMPARATIVO, {params}).then((response) => {
		let columns = getColumns();
		let columnDefs = getColumnDefs();

		let wrapsNameDatatable = `divDatatable`;
		let classNameForDatatable = `display table table-bordered`;

		makeDatatable(wrapsNameDatatable,
		  {
			  data: response.data,
			  columns,
			  columnDefs,

		  },
		  classNameForDatatable
		  )
	}
	);
}


$().ready(function () {
	let nameDatePickers = ["#dpFechaInicio", "#dpFechaFin"];
	initDatePicker(...nameDatePickers);
	listarPolicias("#cboPolicias");
	$("#btnVerReporte").click(verReporte);
});