Excel óptimo

This commit is contained in:
Your Name
2025-01-21 10:56:42 -06:00
parent 37f4cc42c1
commit 8d96d45f58
3 changed files with 43 additions and 12 deletions

View File

@@ -44,6 +44,7 @@ try {
), INSERTION AS (
INSERT INTO last_auditoria
SELECT :usuario_id, to_jsonb(AUDITORIA_DATA) FROM AUDITORIA_DATA
WHERE REGISTRO_FECHA_IDEAL IS NOT NULL
)
SELECT
registro_id,
@@ -59,6 +60,8 @@ try {
color,
estado_color,
estado_icon,
estado_supervisor_id,
facultad_id,
usuario_nombre,
registro_fecha_supervisor,
comentario,

View File

@@ -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,8 +13,12 @@ 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
@@ -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');

View File

@@ -290,7 +290,11 @@ const store = reactive({
headers: {
'Content-Type': 'application/json'
},
// body: JSON.stringify(this.relevant)
body: JSON.stringify({
'facultad_id': store.filters.facultad_id,
'estados': store.filters.estados,
'profesor': store.filters.profesor,
})
});
const blob = await res.blob();
window.saveAs(blob, `auditoria_${new Date().toISOString().slice(0, 10)}.xlsx`);