Excel sin recibir datos

This commit is contained in:
Your Name
2025-01-20 09:28:41 -06:00
parent 13f89636fc
commit 184abed9a1
2 changed files with 64 additions and 11 deletions

View File

@@ -1,4 +1,3 @@
<?php
$fecha = date('d_m_Y');
@@ -6,7 +5,24 @@ header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetm
header("Content-Disposition: attachment;filename=horario_$fecha.xlsx");
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');
$data = json_decode($json, true); */
$query = $db
->where('usuario_id', $user->user['id'])
->getOne('last_auditoria', 'auditoria')['auditoria'];
$data = json_decode($query, true);
empty($data) and die(json_encode(['error' => 'No se recibieron datos', 'data' => $data]));
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Border;
@@ -28,11 +44,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',
@@ -137,8 +148,8 @@ function getFormattedValue($key, $registro)
'registro_fecha_supervisor' => is_null($registro[$key]) ? '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' => json_encode($registro[$key], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
'justificacion',
'comentario' => $registro[$key] ?? "Sin registro",
default => $registro[$key]
@@ -161,7 +172,7 @@ foreach ($data as $index => $registro) {
array_walk($values, function ($row, $column_index) use ($sheet, $index, $registro) {
$value = getFormattedValue($row, $registro);
$cellLocation = chr(65 + $column_index) . (ROW + $index + 1);
$sheet->setCellValue($cellLocation, $value);
if ($value == "Sin registro") {