Files
LMS-Estafeta/admin/reporte_general.php
T

745 lines
23 KiB
PHP

<?php
require_once __DIR__.'/auth_guard.php';
include '../config.php';
session_name($CFG->sessionname);
session_start();
if(!isset($_SESSION['usersession'])){
header("Location: ".$CFG->wwwroot);
}
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
?>
<div class="col-12 text-primary mt-3">
<h1>Reporte general</h1>
</div>
<div class="col-12 text-left my-5 d-none">
<a target="_blank" href="reporteExportGeneral.php?query=&key=<?php echo generateRandomString(); ?>" class="p-3 btn-primary text-white btn-descarga" >Descargar reporte general</a>
</div>
<div class="filter col-lg-12 col-md-12 col-12 mt-4 mb-5" style="display: block;">
Selecciona un rango o el estado de los usuarios
<form class="row">
<div id="daterangegeneral" class="daterange form-control pull-left col-lg-4 col-sm-4 col-12 mr-2 mb-2">
<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>&nbsp;
<span></span> <b class="caret"></b>
</div>
<input type="hidden" class="form-control col-lg-2 col-md-2 col-6 mb-2 mr-sm-2" placeholder="Fecha inicio" id="fechaini" name="fechaini">
<input type="hidden" class="form-control col-lg-2 col-md-2 col-6 mb-2 mr-sm-2" placeholder="Fecha fin" id="fechafin" name="fechafin">
<!--
<input type="number" class="form-control col-lg-2 col-md-2 col-6 mb-2 mr-sm-2" placeholder="Número de empleado" id="numempl" name="numempl">
-->
<select class="form-control col-lg-4 col-md-4 col-12 mb-2 mr-sm-2" id="filestadouser" name="filestadouser">
<option value="all">Todos</option>
<option value="1">Activo</option>
<option value="0">Baja</option>
</select>
<button type="button" class="btnfilter btn btn-primary mb-2">Buscar</button>
</form>
</div>
<div class="col-lg-12 col-md-12 col-12">
<button type="button" class="btn-advance btn btn-danger mb-4" style="display: none;">Mostrar Filtro avanzado</button>
</div>
<div class="col-lg-12 col-12">
<table class="table table-striped table-bordered table-responsive" id="estafetatable1" width="100%" style="display: none;">
<thead>
<tr>
<th>Fecha</th>
<th>Estado del empleado</th>
<th>Alta de usuario</th>
<th>Número de empleado</th>
<th>Nombres(s)</th>
<th>Apellidos</th>
<th>Posición</th>
<th>Sociedad</th>
<th>División</th>
<th>Unidad organizativa</th>
<th>CeCo</th>
<th>Distrito</th>
<th>Centro de trabajo</th>
<th>Supervisor</th>
<th>Categoría</th>
<th>Tema</th>
<th>Subtema</th>
<th>Estado</th>
</tr>
</thead>
<tbody>
<tr class="text-center"><td colspan="17">Procesando...</td></tr>
</tbody>
<tfoot>
<tr>
<th>Fecha</th>
<th>Estado del empleado</th>
<th>Alta de usuario</th>
<th>Número de empleado</th>
<th>Nombres(s)</th>
<th>Apellidos</th>
<th>Posición</th>
<th>Sociedad</th>
<th>División</th>
<th>Unidad organizativa</th>
<th>CeCo</th>
<th>Distrito</th>
<th>Centro de trabajo</th>
<th>Supervisor</th>
<th>Categoría</th>
<th>Tema</th>
<th>Subtema</th>
<th>Estado</th>
</tr>
</tfoot>
</table>
</div>
<script type="text/javascript">
var query;
$(".layer-load").hide();
//extractData();
$(".btnfilter").click(function(){
$(".btnfilter").html('Buscando...');
$("#estafetatable1").hide();
$(".layer-load").show();
if (!$("#wrapper").hasClass('toggled')) {
$("#wrapper").toggleClass("toggled");
}
if ($('#estafetatable1').hasClass('Initialize')) {
$("#estafetatable1").hide();
$(".layer-load").show();
$("#estafetatable1").dataTable().fnDestroy();
setTimeout(function(){ extractData(); }, 800);
}else{
$('#estafetatable1').addClass('Initialize');
extractData();
}
});
//----------------------------------------------------------------------
//------------------------ DATTEPICKER --------------------------------
//----------------------------------------------------------------------
(function (factory) {
factory(moment);
}(function (moment) {
var monthsShortDot = 'Ene._Feb._Mar._Abr._May._Jun._Jul._Ago._Sep._Oct._Nov._Dic.'.split('_'),
monthsShort = 'Ene_Feb_Mar_Abr_May_Jun_Jul_Ago_Sep_Oct_Nov_Dic'.split('_');
return moment.defineLocale('es', {
months : 'Enero_Febrero_Marzo_Abril_Mayo_Junio_Julio_Agosto_Septiembre_Octubre_Noviembre_Diciembre'.split('_'),
monthsShort : function (m, format) {
if (/-MMM-/.test(format)) {
return monthsShort[m.month()];
} else {
return monthsShortDot[m.month()];
}
},
weekdays : 'domingo_lunes_martes_miércoles_jueves_viernes_sábado'.split('_'),
weekdaysShort : 'dom._lun._mar._mié._jue._vie._sáb.'.split('_'),
weekdaysMin : 'Do_Lu_Ma_Mi_Ju_Vi_Sa'.split('_'),
longDateFormat : {
LT : 'H:mm',
LTS : 'LT:ss',
L : 'DD/MM/YYYY',
LL : 'D [de] MMMM [de] YYYY',
LLL : 'D [de] MMMM [de] YYYY LT',
LLLL : 'dddd, D [de] MMMM [de] YYYY LT'
},
calendar : {
sameDay : function () {
return '[hoy a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
},
nextDay : function () {
return '[mañana a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
},
nextWeek : function () {
return 'dddd [a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
},
lastDay : function () {
return '[ayer a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
},
lastWeek : function () {
return '[el] dddd [pasado a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
},
sameElse : 'L'
},
relativeTime : {
future : 'en %s',
past : 'hace %s',
s : 'unos segundos',
m : 'un minuto',
mm : '%d minutos',
h : 'una hora',
hh : '%d horas',
d : 'un día',
dd : '%d días',
M : 'un mes',
MM : '%d meses',
y : 'un año',
yy : '%d años'
},
ordinalParse : /\d{1,2}º/,
ordinal : '%dº',
week : {
dow : 1, // Monday is the first day of the week.
doy : 4 // The week that contains Jan 4th is the first week of the year.
}
});
}));
function cb(start, end){
$('#daterangegeneral span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
}
cb(moment().subtract(1, 'month'),moment());
date = $('#daterangegeneral').daterangepicker({
locale: {
format: 'YYYY-MM-DD',
customRangeLabel: 'Selecciona Rango'
},
ranges: {
'Ultimos 30 Dias': [moment().subtract(29, 'days'), moment()],
'Este Mes': [moment().startOf('month'), moment().endOf('month')],
'Mes Pasado': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
'A\u00f1o pasado': [moment().subtract(1, 'year').startOf('year'), moment().subtract(1, 'year').endOf('year')],
'A\u00f1o pasado - Hoy': [moment().subtract(1, 'year').startOf('year'), moment()],
'Este A\u00f1o': [moment().startOf('year'), moment()]
}
},cb);
$('.applyBtn').text('Aceptar');
$('.applyBtn').removeClass('btn-primary');
$('.applyBtn').addClass('btn-info');
$('.cancelBtn ').text('Cancelar');
$('.cancelBtn ').removeClass('btn-default');
$('.cancelBtn ').addClass('btn-danger');
$('#daterangegeneral').on('apply.daterangepicker', function(ev, picker) {
getJson(picker.startDate.format('YYYY-MM-DD'),picker.endDate.format('YYYY-MM-DD'));
});
function getJson ( fechaInicio, fechaFin){
if(fechaInicio==''){
fechaInicio=moment().subtract(1, 'month').format('YYYY-MM-DD');
}
if(fechaFin==''){
fechaFin=moment().format('YYYY-MM-DD');
}
$('#fechaini').val(fechaInicio);
$('#fechafin').val(fechaFin);
}
//----------------------------------------------------------------------
//--------------------------- DATA ------------------------------------
//----------------------------------------------------------------------
function extractData(){
/*
$('#estafetatable1 tfoot th').each(function() {
var title = $(this).text();
$(this).html('<input type="text" placeholder="Search ' + title + '" />');
});
*/
if ($('#fechaini').val() == '' && $('#fechafin').val() == '') {
console.log('vacio');
getJson('','');
}
var fechainit = $('#fechaini').val();
var fechafin = $('#fechafin').val();
var estado = $('#filestadouser').val();
var data = {fechaini:fechainit,fechafin:fechafin,estado:estado};
$(".layer-load").show();
var table = $('#estafetatable1').DataTable({
searchPanes: {
viewTotal: true
},
dom: 'PBfrtip',
//dom: 'Plfrtip',
//dom: "Bfrtip",
buttons: [{
text: 'Exportar',
action: function (e, dt, node, config) {
exportar(e, dt, node, config);
},
attr: {
id: 'btn_export'
}
},
'colvis'
],
"language": {
"url": "../json/Spanish.json"
},
'order': [
[2, 'desc'],
[0, 'asc']
],
"responsive":true,
"processing": true,
"serverSide": true,
"ajax":{
"url": "reporte_getGeneral.php?fechaini="+fechainit+"&fechafin="+fechafin+"&estado="+estado
},
orderCellsTop: true,
fixedHeader: true,
"initComplete": function( settings, json ) {
query = json.query;
//$('.btn-advance').show(300);
$('.dtsp-panesContainer').hide();
/*
this.api().columns().every( function () {
var column = this;
$(column.footer()).empty();
var select = $('<select class="myselect"><option value="">TODOS</option></select>')
.appendTo( $(column.footer()).after())
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
});
column.data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
});
});
*/
//$(".myselect").select2();
$("#estafetatable1").show();
$(".layer-load").hide();
$(".btnfilter").html('Buscar');
//$("#estafetatable1").columns.adjust().draw();
//$("#estafetatable1").columns.adjust().draw(); // Redraw the DataTable
}
});
table.on( 'xhr', function () {
var json = table.ajax.json();
query = json.query;
});
}
function exportar(){
//console.log(query);
window.open('reporteExportGeneral.php?query='+query, '_blank');
}
$(".btn-advance").click(function(){
if($('.dtsp-panesContainer').is(':visible')) {
$(".btn-advance").text('Mostrar filtro avanzado');
}else{
$(".btn-advance").text('Ocultar filtro avanzado');
}
$('.dtsp-panesContainer').toggle(300);
});
//----------------------------------------------------------------------------------------
//-------------------------------------- LISTADOS --------------------------------------
//----------------------------------------------------------------------------------------
/*
function listadoPosiciones(){
$(".layer-load").show();
$.ajax({
url: 'usuarios_posiciones_list.php',
type: 'POST'
})
.done(function (response) {
var _data = JSON.parse(response);
if (_data.code == "1") {
$("#filposicion").html("");
$("#filposicion").html('<option value="0">Todas las posiciones</option>');
$.each(_data.datos, function (index, val) {
$("#filposicion").append('<option value="' + val.posicion+ '">' + val.posicion + '</option>');
});
} else {
$("#filposicion").html('<option value="0">Todas las posiciones</option>');
}
$(".layer-load").hide();
})
.fail(function () {
})
.always(function () {
});
}
function listadoSociedades(){
$(".layer-load").show();
$.ajax({
url: 'usuarios_sociedades_list.php',
type: 'POST'
})
.done(function (response) {
var _data = JSON.parse(response);
if (_data.code == "1") {
$("#filsociedad").html("");
$("#filsociedad").html('<option value="0">Todas las sociedades</option>');
$.each(_data.datos, function (index, val) {
$("#filsociedad").append('<option value="' + val.sociedad+ '">' + val.sociedad + '</option>');
});
} else {
$("#filsociedad").html('<option value="0">Todas las sociedades</option>');
}
$(".layer-load").hide();
})
.fail(function () {
})
.always(function () {
});
}
function listadoDivisiones(){
$(".layer-load").show();
$.ajax({
url: 'usuarios_divisiones_list.php',
type: 'POST'
})
.done(function (response) {
var _data = JSON.parse(response);
if (_data.code == "1") {
$("#fildivision").html("");
$("#fildivision").html('<option value="0">Todas las divisiones</option>');
$.each(_data.datos, function (index, val) {
$("#fildivision").append('<option value="' + val.division+ '">' + val.division + '</option>');
});
} else {
$("#fildivision").html('<option value="0">Todas las divisiones</option>');
}
$(".layer-load").hide();
})
.fail(function () {
})
.always(function () {
});
}
function listadoUnidades(){
$(".layer-load").show();
$.ajax({
url: 'usuarios_unidades_list.php',
type: 'POST'
})
.done(function (response) {
var _data = JSON.parse(response);
if (_data.code == "1") {
$("#filunidad").html("");
$("#filunidad").html('<option value="0">Todas las unidades</option>');
$.each(_data.datos, function (index, val) {
$("#filunidad").append('<option value="' + val.unidad+ '">' + val.unidad + '</option>');
});
} else {
$("#filunidad").html('<option value="0">Todas las unidades</option>');
}
$(".layer-load").hide();
})
.fail(function () {
})
.always(function () {
});
}
function listadoCeCo(){
$(".layer-load").show();
$.ajax({
url: 'usuarios_ceco_list.php',
type: 'POST'
})
.done(function (response) {
var _data = JSON.parse(response);
if (_data.code == "1") {
$("#filceco").html("");
$("#filceco").html('<option value="0">Todos los CeCo</option>');
$.each(_data.datos, function (index, val) {
$("#filceco").append('<option value="' + val.ceco+ '">' + val.ceco + '</option>');
});
} else {
$("#filceco").html('<option value="0">Todos los CeCo</option>');
}
$(".layer-load").hide();
})
.fail(function () {
})
.always(function () {
});
}
function listadoDistritos(){
$(".layer-load").show();
$.ajax({
url: 'usuarios_distritos_list.php',
type: 'POST'
})
.done(function (response) {
var _data = JSON.parse(response);
if (_data.code == "1") {
$("#fildistrito").html("");
$("#fildistrito").html('<option value="0">Todos los distritos</option>');
$.each(_data.datos, function (index, val) {
$("#fildistrito").append('<option value="' + val.distritoid + '">' + val.nombredistrito + '</option>');
});
} else {
$("#fildistrito").html('<option value="0">Todos los distritos</option>');
}
$(".layer-load").hide();
})
.fail(function () {
})
.always(function () {
});
}
function listadoSupervisores(){
$(".layer-load").show();
$.ajax({
url: 'usuarios_supervisores_list.php',
type: 'POST'
})
.done(function (response) {
var _data = JSON.parse(response);
if (_data.code == "1") {
$("#filsupervisor").html("");
$("#filsupervisor").html('<option value="0">Todos los supervisores</option>');
$.each(_data.datos, function (index, val) {
$("#filsupervisor").append('<option value="' + val.supervisor+ '">' + val.supervisor + '</option>');
});
} else {
$("#filsupervisor").html('<option value="0">Todos los supervisores</option>');
}
$(".layer-load").hide();
})
.fail(function () {
})
.always(function () {
});
}
function listadoCategorias(){
$(".layer-load").show();
$.ajax({
url: 'list_categorias.php',
type: 'POST'
})
.done(function (response) {
var _data = JSON.parse(response);
if (_data.code == "1") {
$("#filcategoria").html("");
$("#filcategoria").html('<option value="0">Todas las categorías</option>');
$.each(_data.datos, function (index, val) {
if(val.padre == 0){
$("#filcategoria").append('<option value="' + val.id+ '">' + val.nombre + '</option>');
}
});
} else {
$("#filcategoria").html('<option value="0">Todas las categorías</option>');
}
$(".layer-load").hide();
})
.fail(function () {
})
.always(function () {
});
}
function listadoTema(){
$(".layer-load").show();
$.ajax({
url: 'list_categorias.php',
type: 'POST'
})
.done(function (response) {
var _data = JSON.parse(response);
if (_data.code == "1") {
$("#filtema").html("");
$("#filtema").html('<option value="0">Todos los temas</option>');
$.each(_data.datos, function (index, val) {
if(val.padre != 0){
$("#filtema").append('<option class="'+val.padre+'" value="' + val.id+ '">' + val.nombre + '</option>');
}
});
} else {
$("#filtema").html('<option value="0">Todos los temas</option>');
}
$(".layer-load").hide();
})
.fail(function () {
})
.always(function () {
});
}
function listadoSubtema(){
$(".layer-load").show();
$.ajax({
url: 'list_subtemas.php',
type: 'POST'
})
.done(function (response) {
var _data = JSON.parse(response);
if (_data.code == "1") {
$("#filsubtema").html("");
$("#filsubtema").html('<option value="0">Todos los subtemas</option>');
$.each(_data.datos, function (index, val) {
if(val.padre != 0){
$("#filsubtema").append('<option class="'+val.idcategoria+'" value="' + val.id+ '">' + val.nombre + '</option>');
}
});
} else {
$("#filsubtema").html('<option value="0">Todos los subtemas</option>');
}
$(".layer-load").hide();
})
.fail(function () {
})
.always(function () {
});
}
function loadtemacat(subtema){
$(".layer-load").show();
var data = {subtema:subtema};
$.ajax({
data:data,
url: 'list_temacat.php',
type: 'POST'
})
.done(function (response) {
var _data = JSON.parse(response);
if (_data.code == "1") {
$('#filcategoria').val(_data.datos[0].categoria);
//$('#filtema option').hide();
//$("#filtema option:first").show();
//$('#filtema .'+_data.datos[0].tema).show();
$('#filtema').val(_data.datos[0].tema);
} else {
$('#filsubtema option').show();
$('#filtema option').show();
}
$(".layer-load").hide();
})
.fail(function () {
})
.always(function () {
});
}
$("#Categoría").focusout(function(){
var cat = $(this).val();
if(cat == 0){
$('#Tema option').show();
$('#Subtema option').show();
$("#Tema").val($("#Tema option:first").val());
$("#Subtema").val($("#Subtema option:first").val());
}else{
$('#Tema option').hide();
$('#Tema .'+cat).show();
$("#Tema option:first").show();
$("#Tema").val($("#Tema option:first").val());
$("#Subtema").val($("#Tema option:first").val());
}
});
$("#Tema").focusout(function(){
var sub = $(this).val();
if(sub == 0){
$('#Subtema option').show();
$("#Subtema").val($("#Subtema option:first").val());
}else{
$('#Subtema option').hide();
$('#Subtema .'+sub).show();
$("#Subtema option:first").show();
$("#Subtema").val($("#Subtema option:first").val());
}
});
$("#Subtema").focusout(function(){
$('#Subtema option').show();
var subtema = $(this).val();
loadtemacat(subtema);
});
listadoDistritos();
listadoPosiciones();
listadoSociedades();
listadoDivisiones();
listadoUnidades();
listadoCeCo();
listadoSupervisores();
listadoCategorias();
listadoTema();
listadoSubtema();
*/
</script>