Merge branch 'master' of https://github.apps.lci.ulsa.mx/PAAD/paad
This commit is contained in:
@@ -1,12 +1,76 @@
|
||||
|
||||
<?php
|
||||
|
||||
$fecha = date('d_m_Y');
|
||||
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
/* header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
header("Content-Disposition: attachment;filename=horario_$fecha.xlsx");
|
||||
header("Cache-Control: max-age=0");
|
||||
header("Cache-Control: max-age=0"); */
|
||||
|
||||
require_once "../vendor/autoload.php";
|
||||
$ruta = "..";
|
||||
require_once "$ruta/class/c_login.php";
|
||||
if (!isset($_SESSION['user'])) {
|
||||
http_response_code(401);
|
||||
die(json_encode(['error' => 'unauthorized']));
|
||||
}
|
||||
$user = unserialize($_SESSION['user']);
|
||||
|
||||
$json = file_get_contents('php://input');
|
||||
$params = json_decode($json, true);
|
||||
|
||||
$profesor_clave = isset($params['profesor'])
|
||||
? preg_replace('/[^\d]/', '', $params['profesor'])
|
||||
: null;
|
||||
|
||||
$data = $db->query(
|
||||
"SELECT DISTINCT
|
||||
auditoria->>'registro_fecha_ideal' as registro_fecha_ideal,
|
||||
auditoria->>'profesor_clave' as profesor_clave,
|
||||
auditoria->>'profesor_nombre' as profesor_nombre,
|
||||
NULLIF(auditoria->>'profesor_correo', '') as profesor_correo,
|
||||
auditoria->>'facultad' as facultad,
|
||||
auditoria->>'materia' as materia,
|
||||
auditoria->>'carrera' as carrera,
|
||||
NULLIF(auditoria->>'horario_grupo', '') as horario_grupo,
|
||||
auditoria->>'horario_hora_completa' as horario_hora_completa,
|
||||
auditoria->>'salon' as salon,
|
||||
(
|
||||
SELECT string_agg(value, ' / ' ORDER BY value)
|
||||
FROM jsonb_array_elements_text(auditoria->'salon_array') AS value
|
||||
) as salon_array,
|
||||
auditoria->>'asistencia' as asistencia,
|
||||
auditoria->>'registro_fecha' as registro_fecha,
|
||||
auditoria->>'usuario_nombre' as usuario_nombre,
|
||||
auditoria->>'nombre' as nombre,
|
||||
auditoria->>'registro_fecha_supervisor' as registro_fecha_supervisor,
|
||||
auditoria->>'comentario' as comentario,
|
||||
auditoria->>'justificacion' as justificacion,
|
||||
auditoria->>'horario_hora' as horario_hora,
|
||||
auditoria->>'horario_fin' as horario_fin,
|
||||
(auditoria->>'estado_supervisor_id')::integer as estado_id,
|
||||
auditoria->>'registro_retardo' as registro_retardo
|
||||
FROM last_auditoria
|
||||
-- JOIN BLOQUE_HORARIO ON ((auditoria->>'horario_hora')::TIME, (auditoria->>'horario_fin')::TIME) OVERLAPS (HORA_INICIO, HORA_FIN)
|
||||
WHERE USUARIO_ID = :usuario_id
|
||||
AND auditoria->>'facultad_id' = COALESCE(:facultad_id, auditoria->>'facultad_id')
|
||||
AND auditoria->>'profesor_clave' = COALESCE(:profesor_clave, auditoria->>'profesor_clave')
|
||||
--AND BLOQUE_HORARIO.ID = COALESCE(:bloque_horario_id, BLOQUE_HORARIO.ID)",
|
||||
[
|
||||
'usuario_id' => $user->user['id'],
|
||||
'facultad_id' => $params['facultad_id'],
|
||||
'profesor_clave' => $profesor_clave,
|
||||
/* 'bloque_horario_id' => $params['bloque_horario'] */
|
||||
]
|
||||
);
|
||||
|
||||
$estados = empty($params['estados']) ? null : $params['estados'];
|
||||
|
||||
$data = array_filter(
|
||||
$data,
|
||||
fn($fila) => in_array($fila['estado_id'], $estados ?? [$fila['estado_id']])
|
||||
);
|
||||
|
||||
$data = array_values($data);
|
||||
|
||||
empty($data) and die(json_encode(['error' => 'No se recibieron datos', 'data' => $data]));
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||
@@ -28,11 +92,6 @@ $drawing->setName('La Salle')
|
||||
->setOffsetX(10)
|
||||
->setWorksheet($spreadsheet->getActiveSheet());
|
||||
|
||||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json, true);
|
||||
|
||||
empty($data) and die(json_encode(['error' => 'No se recibieron datos', 'data' => $data]));
|
||||
|
||||
$data_excel = array(
|
||||
"FECHA" => 'registro_fecha_ideal',
|
||||
"CLAVE" => 'profesor_clave',
|
||||
@@ -88,7 +147,7 @@ array_walk($keys, function ($key, $index) use ($sheet) {
|
||||
$sheet->getStyle($headers_range)->applyFromArray([
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 15,
|
||||
'size' => 12,
|
||||
'name' => 'Indivisa Text Sans',
|
||||
'color' => ['argb' => Color::COLOR_WHITE],
|
||||
],
|
||||
@@ -110,7 +169,7 @@ $sheet->setAutoFilter($headers_range);
|
||||
// Styles that are common for all rows can be set outside the loop
|
||||
|
||||
const DEFAULT_FONT = [
|
||||
'size' => 12,
|
||||
'size' => 10,
|
||||
'name' => 'Indivisa Text Sans',
|
||||
'color' => ['argb' => '001d68']
|
||||
];
|
||||
@@ -132,15 +191,21 @@ const DEFAULT_STYLE = [
|
||||
function getFormattedValue($key, $registro)
|
||||
{
|
||||
return match ($key) {
|
||||
'asistencia' => is_null($registro['registro_fecha']) ? "Sin registro" : ($registro['registro_retardo'] ? "Retardo " : "Asistencia "),
|
||||
'asistencia' => $registro['registro_fecha'] === null
|
||||
? "Sin registro"
|
||||
: ($registro['registro_retardo'] ? "Retardo " : "Asistencia "),
|
||||
'registro_fecha',
|
||||
'registro_fecha_supervisor' => is_null($registro[$key]) ? 'Sin registro' : date('H:i', strtotime($registro[$key])),
|
||||
'registro_fecha_supervisor' => $registro[$key] === null
|
||||
? 'Sin registro'
|
||||
: date('H:i', strtotime($registro[$key])),
|
||||
'nombre' => $registro[$key] ?? "Sin registro",
|
||||
'horario_hora_completa' => "{$registro['horario_hora']} - {$registro['horario_fin']}",
|
||||
'usuario_nombre',
|
||||
'salon_array' => implode(", ", json_decode($registro[$key], true)),
|
||||
'usuario_nombre' => $registro[$key] ?? "Sin registro",
|
||||
'salon_array' => $registro[$key],
|
||||
'justificacion',
|
||||
'comentario' => $registro[$key] ?? "Sin registro",
|
||||
'horario_grupo' => $registro[$key] ?? "Sin registro",
|
||||
'profesor_correo' => $registro[$key] ?? "Sin correo",
|
||||
default => $registro[$key]
|
||||
};
|
||||
}
|
||||
@@ -164,7 +229,7 @@ foreach ($data as $index => $registro) {
|
||||
|
||||
$sheet->setCellValue($cellLocation, $value);
|
||||
|
||||
if ($value == "Sin registro") {
|
||||
if (in_array($value, ["Sin registro", "Sin asignar", "Sin correo"])) {
|
||||
$sheet->getStyle($cellLocation)->applyFromArray(['font' => ['color' => ['argb' => 'ea0029']]]);
|
||||
}
|
||||
});
|
||||
@@ -172,7 +237,12 @@ foreach ($data as $index => $registro) {
|
||||
|
||||
|
||||
foreach ($sheet->getColumnIterator() as $column) {
|
||||
$sheet->getColumnDimension($column->getColumnIndex())->setAutoSize(true);
|
||||
$colIndex = $column->getColumnIndex();
|
||||
if (in_array($colIndex, ['Q', 'R'])) {
|
||||
$sheet->getColumnDimension($colIndex)->setWidth(100); // Ajusta el valor según el tamaño deseado
|
||||
} else {
|
||||
$sheet->getColumnDimension($colIndex)->setAutoSize(true);
|
||||
}
|
||||
}
|
||||
|
||||
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||||
|
||||
Reference in New Issue
Block a user