Excel óptimo
This commit is contained in:
@@ -44,6 +44,7 @@ try {
|
|||||||
), INSERTION AS (
|
), INSERTION AS (
|
||||||
INSERT INTO last_auditoria
|
INSERT INTO last_auditoria
|
||||||
SELECT :usuario_id, to_jsonb(AUDITORIA_DATA) FROM AUDITORIA_DATA
|
SELECT :usuario_id, to_jsonb(AUDITORIA_DATA) FROM AUDITORIA_DATA
|
||||||
|
WHERE REGISTRO_FECHA_IDEAL IS NOT NULL
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
registro_id,
|
registro_id,
|
||||||
@@ -59,6 +60,8 @@ try {
|
|||||||
color,
|
color,
|
||||||
estado_color,
|
estado_color,
|
||||||
estado_icon,
|
estado_icon,
|
||||||
|
estado_supervisor_id,
|
||||||
|
facultad_id,
|
||||||
usuario_nombre,
|
usuario_nombre,
|
||||||
registro_fecha_supervisor,
|
registro_fecha_supervisor,
|
||||||
comentario,
|
comentario,
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$fecha = date('d_m_Y');
|
$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("Content-Disposition: attachment;filename=horario_$fecha.xlsx");
|
||||||
header("Cache-Control: max-age=0");
|
header("Cache-Control: max-age=0"); */
|
||||||
|
|
||||||
$ruta = "..";
|
$ruta = "..";
|
||||||
require_once "$ruta/class/c_login.php";
|
require_once "$ruta/class/c_login.php";
|
||||||
@@ -13,8 +13,12 @@ if (!isset($_SESSION['user'])) {
|
|||||||
}
|
}
|
||||||
$user = unserialize($_SESSION['user']);
|
$user = unserialize($_SESSION['user']);
|
||||||
|
|
||||||
/* $json = file_get_contents('php://input');
|
$json = file_get_contents('php://input');
|
||||||
$data = json_decode($json, true); */
|
$params = json_decode($json, true);
|
||||||
|
|
||||||
|
$profesor_clave = isset($params['profesor'])
|
||||||
|
? preg_replace('/[^\d]/', '', $params['profesor'])
|
||||||
|
: null;
|
||||||
|
|
||||||
$data = $db->query(
|
$data = $db->query(
|
||||||
"SELECT
|
"SELECT
|
||||||
@@ -38,13 +42,28 @@ $data = $db->query(
|
|||||||
auditoria->>'justificacion' as justificacion,
|
auditoria->>'justificacion' as justificacion,
|
||||||
auditoria->>'horario_hora' as horario_hora,
|
auditoria->>'horario_hora' as horario_hora,
|
||||||
auditoria->>'horario_fin' as horario_fin,
|
auditoria->>'horario_fin' as horario_fin,
|
||||||
|
(auditoria->>'estado_supervisor_id')::integer as estado_id,
|
||||||
auditoria->>'registro_retardo' as registro_retardo
|
auditoria->>'registro_retardo' as registro_retardo
|
||||||
FROM last_auditoria
|
FROM last_auditoria
|
||||||
WHERE auditoria->>'registro_fecha_ideal' IS NOT NULL
|
WHERE USUARIO_ID = :usuario_id
|
||||||
AND USUARIO_ID = ?",
|
AND auditoria->>'facultad_id' = COALESCE(:facultad_id, auditoria->>'facultad_id')
|
||||||
[$user->user['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]));
|
empty($data) and die(json_encode(['error' => 'No se recibieron datos', 'data' => $data]));
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
@@ -122,7 +141,7 @@ array_walk($keys, function ($key, $index) use ($sheet) {
|
|||||||
$sheet->getStyle($headers_range)->applyFromArray([
|
$sheet->getStyle($headers_range)->applyFromArray([
|
||||||
'font' => [
|
'font' => [
|
||||||
'bold' => true,
|
'bold' => true,
|
||||||
'size' => 15,
|
'size' => 12,
|
||||||
'name' => 'Indivisa Text Sans',
|
'name' => 'Indivisa Text Sans',
|
||||||
'color' => ['argb' => Color::COLOR_WHITE],
|
'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
|
// Styles that are common for all rows can be set outside the loop
|
||||||
|
|
||||||
const DEFAULT_FONT = [
|
const DEFAULT_FONT = [
|
||||||
'size' => 12,
|
'size' => 10,
|
||||||
'name' => 'Indivisa Text Sans',
|
'name' => 'Indivisa Text Sans',
|
||||||
'color' => ['argb' => '001d68']
|
'color' => ['argb' => '001d68']
|
||||||
];
|
];
|
||||||
@@ -206,7 +225,12 @@ foreach ($data as $index => $registro) {
|
|||||||
|
|
||||||
|
|
||||||
foreach ($sheet->getColumnIterator() as $column) {
|
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');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||||||
|
|||||||
@@ -290,7 +290,11 @@ const store = reactive({
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'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();
|
const blob = await res.blob();
|
||||||
window.saveAs(blob, `auditoria_${new Date().toISOString().slice(0, 10)}.xlsx`);
|
window.saveAs(blob, `auditoria_${new Date().toISOString().slice(0, 10)}.xlsx`);
|
||||||
|
|||||||
Reference in New Issue
Block a user