Update code with changes from git diff
This commit is contained in:
65
export/control.php
Normal file
65
export/control.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<button onclick="getExcel()">
|
||||
Get excel
|
||||
</button>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
|
||||
<script>
|
||||
async function getExcel() {
|
||||
const res = await fetch('supervisor_excel.php', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify([
|
||||
{
|
||||
"profesor_id": 1089,
|
||||
"estado_supervisor_id": 1,
|
||||
"horario_id": 3538,
|
||||
"registro_id": 1,
|
||||
"registro_fecha": null,
|
||||
"registro_retardo": null,
|
||||
"registro_justificada": null,
|
||||
"registro_fecha_ideal": "2023-08-03",
|
||||
"comentario": "Hola mundo",
|
||||
"registro_fecha_supervisor": "2023-08-03 12:21:38.336147",
|
||||
"supervisor_id": 6,
|
||||
"justificacion": null,
|
||||
"fecha_justificacion": null,
|
||||
"horario_hora": "12:00:00",
|
||||
"horario_fin": "13:30:00",
|
||||
"horario_grupo": "MG 45030102",
|
||||
"horario_dia": 4,
|
||||
"dia": "jueves",
|
||||
"duracion_id": 2,
|
||||
"duracion": "01:30:00",
|
||||
"carrera_id": 439,
|
||||
"carrera": "LICENCIATURA EN INGENIERÍA ELECTRÓNICA PARA SISTEMAS INTELIGENTES",
|
||||
"facultad_id": 28,
|
||||
"facultad": "FACULTAD DE INGENIERÍA",
|
||||
"periodo_id": null,
|
||||
"periodo": "LICENCIATURA: agosto - noviembre 2023",
|
||||
"materia_id": 191,
|
||||
"materia": "Dinámica",
|
||||
"nivel_id": 1,
|
||||
"nivel": "Licenciatura",
|
||||
"salon_id": 1245,
|
||||
"salon": "ING MM 208",
|
||||
"nombre": "Asistencia",
|
||||
"estado_color": "success",
|
||||
"estado_icon": "ing-autorizar",
|
||||
"profesor_nombre": "ISRAEL WOOD CANO",
|
||||
"profesor_clave": "008999",
|
||||
"profesor_correo": "israel.wood@lasallistas.org.mx",
|
||||
"profesor_grado": null,
|
||||
"usuario_id": 6,
|
||||
"usuario_nombre": "Francisco Javier Garrido Alfaro",
|
||||
"usuario_correo": null,
|
||||
"usuario_admin": false,
|
||||
"usuario_clave": "ad011538",
|
||||
"rol_id": 7
|
||||
}
|
||||
])
|
||||
});
|
||||
const blob = await res.blob();
|
||||
saveAs(blob, 'excel.xlsx');
|
||||
}
|
||||
</script>
|
||||
139
export/horario_excel.php
Normal file
139
export/horario_excel.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
$ruta = "../";
|
||||
require_once "../vendor/autoload.php";
|
||||
require_once "../class/c_login.php";
|
||||
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
//crea imagen
|
||||
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
|
||||
$drawing->setName('La Salle');
|
||||
$drawing->setDescription('La Salle');
|
||||
$drawing->setPath('../imagenes/logo.png'); // put your path and image here
|
||||
$drawing->setCoordinates('A1');
|
||||
$drawing->setHeight(100);
|
||||
$drawing->setOffsetX(10);
|
||||
//agrega imagen
|
||||
$drawing->setWorksheet($spreadsheet->getActiveSheet());
|
||||
|
||||
|
||||
extract($_POST);
|
||||
$row = 6;
|
||||
$sábado = $sábado == 'true';
|
||||
$sheet->setCellValue("A$row", 'Hora');
|
||||
$sheet->setCellValue("B$row", 'Lunes');
|
||||
$sheet->setCellValue("C$row", 'Martes');
|
||||
$sheet->setCellValue("D$row", 'Miércoles');
|
||||
$sheet->setCellValue("E$row", 'Jueves');
|
||||
$sheet->setCellValue("F$row", 'Viernes');
|
||||
if ($sábado)
|
||||
$sheet->setCellValue("G$row", 'Sábado');
|
||||
|
||||
// to this row set bold, font size 12 and Indivisa Sans, and center the text, bg color to #101097, color to white,
|
||||
$until = $sábado ? 'G' : 'F';
|
||||
|
||||
$sheet->getStyle("A$row:$until$row")->getFont()->setBold(true);
|
||||
$sheet->getStyle("A$row:$until$row")->getFont()->setSize(15);
|
||||
$sheet->getStyle("A$row:$until$row")->getFont()->setName('Indivisa Display Sans');
|
||||
$sheet->getStyle("A$row:$until$row")->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
|
||||
$sheet->getStyle("A$row:$until$row")->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
|
||||
$sheet->getStyle("A$row:$until$row")->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID);
|
||||
$sheet->getStyle("A$row:$until$row")->getFill()->getStartColor()->setARGB('001d68');
|
||||
$sheet->getStyle("A$row:$until$row")->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);
|
||||
|
||||
# the first column is the hour of the day merged with 4 rows each
|
||||
$row++;
|
||||
foreach (range($min, $max) as $hour) {
|
||||
$sheet->setCellValue("A$row", "$hour:00");
|
||||
$sheet->mergeCells("A$row:A" . ($row + 3));
|
||||
|
||||
for ($i = 0; $i < 4; $i++)
|
||||
$sheet->getRowDimension($row + $i)->setRowHeight(25);
|
||||
|
||||
|
||||
// align to center
|
||||
$sheet->getStyle("A$row")->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
|
||||
$sheet->getStyle("A$row")->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
|
||||
|
||||
$sheet->getStyle("A$row")->getFont()->setBold(true);
|
||||
$sheet->getStyle("A$row")->getFont()->setName('Indivisa Text Sans');
|
||||
$sheet->getStyle("A$row")->getFont()->setSize(12);
|
||||
|
||||
|
||||
$row += 4;
|
||||
}
|
||||
|
||||
|
||||
# Size columns to 30
|
||||
foreach (range('A', 'G') as $column) {
|
||||
if ($column == 'G' && !$sábado)
|
||||
continue;
|
||||
$sheet->getColumnDimension($column)->setWidth(($column == 'A' ? 10 : 30));
|
||||
}
|
||||
|
||||
# foreach horarios
|
||||
$row = 7;
|
||||
$días = ['lunes', 'martes', 'miércoles', 'jueves', 'viernes', 'sábado'];
|
||||
$lista_minutos = ['00', '15', '30', '45'];
|
||||
foreach (json_decode($horarios) as $horario) {
|
||||
[$hora, $minutos] = array_map(fn($x) => intval($x), explode(':', $horario->hora));
|
||||
$rowHora = $row + ($hora - $min) * 4;
|
||||
$rowHora += array_search($minutos, $lista_minutos);
|
||||
|
||||
$colHora = array_search($horario->dia, $días) + 2;
|
||||
$content = new \PhpOffice\PhpSpreadsheet\RichText\RichText();
|
||||
$content->createText("$horario->hora");
|
||||
// $content = "$horario->hora $horario->materia\n$horario->salon\n$horario->profesor";
|
||||
$content->createTextRun(" $horario->materia\n")->getFont()->setBold(true)->setName('Indivisa Text Sans')->setSize(12);
|
||||
$content->createTextRun("Salón: $horario->salon\n")->getFont()->setBold(true);
|
||||
foreach ($horario->profesores as $profesor) $content->createTextRun("🎓 $profesor->profesor\n")->getFont()->setBold(true);
|
||||
// APPLY THE FONT FAMILY
|
||||
$sheet->setCellValueByColumnAndRow($colHora, $rowHora, $content);
|
||||
|
||||
$sheet->getStyleByColumnAndRow($colHora, $rowHora)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
|
||||
$sheet->getStyleByColumnAndRow($colHora, $rowHora)->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
|
||||
|
||||
// merge cells
|
||||
$sheet->mergeCellsByColumnAndRow($colHora, $rowHora, $colHora, $rowHora + $horario->bloques - 1);
|
||||
// set border white
|
||||
$sheet->getStyleByColumnAndRow($colHora, $rowHora)->getBorders()->getOutline()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN);
|
||||
$sheet->getStyleByColumnAndRow($colHora, $rowHora)->getBorders()->getOutline()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);
|
||||
// set bg color d4d9dd
|
||||
$sheet->getStyleByColumnAndRow($colHora, $rowHora)->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID);
|
||||
$sheet->getStyleByColumnAndRow($colHora, $rowHora)->getFill()->getStartColor()->setARGB('d4d9dd');
|
||||
|
||||
// set font size 12
|
||||
$sheet->getStyleByColumnAndRow($colHora, $rowHora)->getFont()->setSize(12);
|
||||
// set font name Indivisa Text Sans
|
||||
$sheet->getStyleByColumnAndRow($colHora, $rowHora)->getFont()->setName('Indivisa Text Sans');
|
||||
// set font color 001d68z
|
||||
$sheet->getStyleByColumnAndRow($colHora, $rowHora)->getFont()->getColor()->setARGB('001d68');
|
||||
|
||||
// wrap text
|
||||
$sheet->getStyleByColumnAndRow($colHora, $rowHora)->getAlignment()->setWrapText(true);
|
||||
// border white
|
||||
$sheet->getStyleByColumnAndRow($colHora, $rowHora)->getBorders()->getOutline()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN);
|
||||
$sheet->getStyleByColumnAndRow($colHora, $rowHora)->getBorders()->getOutline()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);
|
||||
}
|
||||
|
||||
|
||||
#$writer = new Xlsx($spreadsheet);
|
||||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||||
# $writer->save('asistencias.xlsx');
|
||||
|
||||
// download
|
||||
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
header('Content-Disposition: attachment;filename="asistencias.xlsx"');
|
||||
header('Cache-Control: max-age=0');
|
||||
|
||||
// cache expires in 60 seconds (1 minute)
|
||||
header('Expires: mon 26 jul 1997 05:00:00 gmt');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
header('Cache-Control: cache, must-revalidate');
|
||||
header('Pragma: public');
|
||||
|
||||
$writer->save('php://output');
|
||||
179
export/supervisor_excel.php
Normal file
179
export/supervisor_excel.php
Normal file
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
$fecha = date('d_m_Y');
|
||||
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
header("Content-Disposition: attachment;filename=horario_$fecha.xlsx");
|
||||
header("Cache-Control: max-age=0");
|
||||
|
||||
require_once "../vendor/autoload.php";
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Color;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
// Image settings
|
||||
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
|
||||
$drawing->setName('La Salle')
|
||||
->setDescription('La Salle')
|
||||
->setPath('../imagenes/logo.png')
|
||||
->setCoordinates('B1')
|
||||
->setHeight(100)
|
||||
->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',
|
||||
"PROFESOR" => 'profesor_nombre',
|
||||
"CORREO" => 'profesor_correo',
|
||||
"FACULTAD" => 'facultad',
|
||||
"MATERIA" => 'materia',
|
||||
"CARRERA / PROGRAMA" => 'carrera',
|
||||
"GRUPO" => 'horario_grupo',
|
||||
"HORARIO" => 'horario_hora_completa',
|
||||
"SALÓN" => 'salon',
|
||||
"REGISTRO PROFESOR" => 'asistencia',
|
||||
"HORA DE REGISTRO" => 'registro_fecha',
|
||||
"NOMBRE SUPERVISOR" => 'usuario_nombre',
|
||||
"REGISTRO SUPERVISOR" => 'nombre',
|
||||
"HORA DE SUPERVISIÓN" => 'registro_fecha_supervisor',
|
||||
"OBSERVACIONES" => 'comentario',
|
||||
"JUSTIFICACIÓN" => 'justificacion',
|
||||
); // Same as before
|
||||
|
||||
|
||||
|
||||
const ROW = 6;
|
||||
// Merge cells from A1 to C+ ROW
|
||||
$sheet->mergeCells('A1:C' . (ROW - 1));
|
||||
// Merge cells from D1 to size of $data_excel + 1
|
||||
$sheet->mergeCells('D1:' . chr(65 + count($data_excel) - 1) . (ROW - 1));
|
||||
|
||||
// Set the title in D1 Sistema de Auditoría de Asistencia
|
||||
$sheet->setCellValue('D1', 'Sistema de Auditoría de Asistencia');
|
||||
$sheet->getStyle('D1')->applyFromArray([
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 30,
|
||||
'name' => 'Indivisa Text Sans',
|
||||
'color' => ['argb' => '001d68'],
|
||||
],
|
||||
'alignment' => [
|
||||
'vertical' => Alignment::VERTICAL_CENTER,
|
||||
],
|
||||
]);
|
||||
|
||||
|
||||
$lastColumnLetter = chr(65 + count($data_excel) - 1);
|
||||
$headers_range = 'A' . ROW . ':' . $lastColumnLetter . ROW;
|
||||
|
||||
$keys = array_keys($data_excel);
|
||||
array_walk($keys, function ($key, $index) use ($sheet) {
|
||||
$sheet->setCellValue(chr(65 + $index) . ROW, $key);
|
||||
});
|
||||
// Apply the header styles
|
||||
$sheet->getStyle($headers_range)->applyFromArray([
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 15,
|
||||
'name' => 'Indivisa Text Sans',
|
||||
'color' => ['argb' => Color::COLOR_WHITE],
|
||||
],
|
||||
'alignment' => [
|
||||
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
||||
'vertical' => Alignment::VERTICAL_CENTER,
|
||||
],
|
||||
'fill' => [
|
||||
'fillType' => Fill::FILL_SOLID,
|
||||
'startColor' => ['argb' => '001d68'],
|
||||
]
|
||||
]);
|
||||
|
||||
// set filters
|
||||
$sheet->setAutoFilter($headers_range);
|
||||
|
||||
|
||||
|
||||
// Styles that are common for all rows can be set outside the loop
|
||||
|
||||
const DEFAULT_FONT = [
|
||||
'size' => 12,
|
||||
'name' => 'Indivisa Text Sans',
|
||||
'color' => ['argb' => '001d68']
|
||||
];
|
||||
|
||||
const DEFAULT_STYLE = [
|
||||
'alignment' => [
|
||||
'vertical' => Alignment::VERTICAL_CENTER,
|
||||
'wrapText' => true,
|
||||
],
|
||||
'font' => DEFAULT_FONT,
|
||||
'borders' => [
|
||||
'outline' => [
|
||||
'borderStyle' => Border::BORDER_THIN,
|
||||
'color' => ['argb' => Color::COLOR_WHITE],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
function getFormattedValue($key, $registro)
|
||||
{
|
||||
return match ($key) {
|
||||
'asistencia' => is_null($registro['registro_fecha'])
|
||||
? "Sin registro"
|
||||
: ($registro['registro_retardo'] ? "Retardo " : "Asistencia "),
|
||||
'registro_fecha', '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', 'justificacion', 'comentario' =>
|
||||
$registro[$key] ?? "Sin registro",
|
||||
default => $registro[$key]
|
||||
};
|
||||
}
|
||||
|
||||
foreach ($data as $index => $registro) {
|
||||
$pair = $index % 2 == 0;
|
||||
$cellRange = 'A' . (ROW + $index + 1) . ':' . $lastColumnLetter . (ROW + $index + 1);
|
||||
$styleArray = DEFAULT_STYLE;
|
||||
$styleArray['fill'] = [
|
||||
'fillType' => Fill::FILL_SOLID,
|
||||
'startColor' => ['argb' => $pair ? 'd4d9dd' : 'f6f7f8'],
|
||||
];
|
||||
|
||||
$sheet->getStyle($cellRange)->applyFromArray($styleArray);
|
||||
|
||||
$values = array_values($data_excel);
|
||||
|
||||
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") {
|
||||
$sheet->getStyle($cellLocation)->applyFromArray(['font' => ['color' => ['argb' => 'ea0029']]]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
foreach ($sheet->getColumnIterator() as $column) {
|
||||
$sheet->getColumnDimension($column->getColumnIndex())->setAutoSize(true);
|
||||
}
|
||||
|
||||
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||||
$writer->save('php://output');
|
||||
Reference in New Issue
Block a user