Excel óptimo
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<?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"); */
|
||||
|
||||
$ruta = "..";
|
||||
require_once "$ruta/class/c_login.php";
|
||||
@@ -13,11 +13,15 @@ if (!isset($_SESSION['user'])) {
|
||||
}
|
||||
$user = unserialize($_SESSION['user']);
|
||||
|
||||
/* $json = file_get_contents('php://input');
|
||||
$data = json_decode($json, true); */
|
||||
$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
|
||||
"SELECT
|
||||
auditoria->>'registro_fecha_ideal' as registro_fecha_ideal,
|
||||
auditoria->>'profesor_clave' as profesor_clave,
|
||||
auditoria->>'profesor_nombre' as profesor_nombre,
|
||||
@@ -38,13 +42,28 @@ $data = $db->query(
|
||||
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
|
||||
WHERE auditoria->>'registro_fecha_ideal' IS NOT NULL
|
||||
AND USUARIO_ID = ?",
|
||||
[$user->user['id']]
|
||||
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')",
|
||||
[
|
||||
'usuario_id' => $user->user['id'],
|
||||
'facultad_id' => $params['facultad_id'],
|
||||
'profesor_clave' => $profesor_clave,
|
||||
]
|
||||
);
|
||||
|
||||
$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;
|
||||
@@ -122,7 +141,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],
|
||||
],
|
||||
@@ -144,7 +163,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']
|
||||
];
|
||||
@@ -206,7 +225,12 @@ foreach ($data as $index => $registro) {
|
||||
|
||||
|
||||
foreach ($sheet->getColumnIterator() as $column) {
|
||||
$sheet->getColumnDimension($column->getColumnIndex())->setAutoSize(true);
|
||||
$colIndex = $column->getColumnIndex();
|
||||
if ($colIndex === 'Q') {
|
||||
$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