$cat) {
array_push($columnasvisibles, $cat['nombre']);
}
for ($i=0; $i < sizeof($columnasvisibles) ; $i++) {
$columnasvisibles[$i] = array('title' => $columnasvisibles[$i]);
}
$return->columnasvisibles = $columnasvisibles;
if (!empty($data)) {
$anterior = '';
$users = 0;
$fecha_max = null;
foreach ($data as $key1 => $col) {
//print_r($col);die;
//echo $col[2]."
";
if ($col['numempl'] == $anterior) {
//echo $col['numempl']." igual - ".$col['nomcat']."- ".$users."
";
if($fecha_max == null){
//$datos[($users-1)][$col['fecha']] = $col['fecha'];
$fecha_max = strtotime($col['fecha']);
}else if( strtotime($col['fecha']) >= $fecha_max){
$fecha_max = strtotime($col['fecha']);
//$datos[($users-1)][$col['fecha']] = $col['fecha'];
}
$datos[($users-1)][$col['nomcat']] = $col['estado1'];
}else{
//echo $col['numempl']." nuevo - ".$col['nomcat']." - ".$users."
";
if($fecha_max!=null){
$datos[($users-1)]["fecha"] = date("d-m-Y",$fecha_max);
}
$fecha_max = null;
$datos[$users] =
['estado_empleado' => $col['estado_empleado'],
'numempl' => $col['numempl'],
'nombre' => $col['nombre'],
'apellidos' =>$col['apellidos'],
'posicion'=>$col['posicion'],
'sociedad'=> $col['sociedad'],
'division'=> $col['division'],
'unidad_organizativa' => $col['unidad_organizativa'],
'ceco'=>$col['ceco'],
'nomdistrito'=>$col['nomdistrito'],
'nomcentro' => $col['nomcentro'],
'supervisor'=>$col['supervisor'],
'fecha'=>$col['fecha']
];
foreach ($categorias as $key2 => $cat) {
if ($cat['nombre'] == $col['nomcat']) {
if($fecha_max == null){
//$datos[$users][$col['fecha']] = $col['fecha'];
$fecha_max = strtotime($col['fecha']);
}else if( strtotime($col['fecha']) >= $fecha_max){
$fecha_max = strtotime($col['fecha']);
//$datos[$users][$col['fecha']] = $col['fecha'];
}
$datos[$users][$cat['nombre']] = $col['estado1'];
}else{
$datos[$users][$cat['nombre']] = 'No completado';
}
}
$users++;
}
$anterior = $col['numempl'];
}
//print_r($datos[0]);
foreach ($datos as $col => $columnas) {
$fill = [];
foreach ($columnas as $key => $value) {
array_push($fill, $value);
}
$datos[$col] = $fill;
}
}else{
$datos = [];
}
//echo json_encode($datos, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); die;
$filtered_resultusers = array_filter($datos, function($var) use ($fechainicio, $fechafin, $estado) {
$evtime = strtotime($var[12]);
return $evtime <= $fechafin && $evtime >= $fechainicio && $var[0] == $estado;
});
$finaldata = [];
foreach ($filtered_resultusers as $cols) {
$finaldata[] = $cols;
}
//echo $sqlusers;
//echo "
".print_r($finaldata,true).""; $return->data = $finaldata; mysqli_close($link); echo json_encode($return, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); exit; ?>