query('SELECT * FROM fs_estado_reposicion' ); $repoParams = array(); $user = Login::get_user(); $user->access(); $query=""; if($user->rol["rol_id"] == 9){//es coordinador $query .= ":facultad, "; $repoParams[":facultad"] = $user->facultad["facultad_id"]; }else{//supervisor $query .= "NULL, "; } if(isset($_POST["prof"]) ){ $query .= ":prof,"; $profesor = trim($_POST["prof"]);//limpia texto $repoParams[":prof"] = $profesor; }else{ $query .= "NULL,"; } $query .= ":f_ini, :f_fin, "; $repoParams[":f_ini"] = DateTime::createFromFormat('d/m/Y', $fecha_ini)->format('Y-m-d'); $repoParams[":f_fin"] = DateTime::createFromFormat('d/m/Y', $fecha_fin)->format('Y-m-d'); $spreadsheet = new Spreadsheet(); // Set document properties $spreadsheet->getProperties()->setCreator('Universidad La Salle') ->setLastModifiedBy('Universidad La Salle') ->setTitle('Solicitudes') ->setDescription('Reporte de solicitudes.'); $headerStyle = [ 'fill' => [ 'fillType' => Fill::FILL_SOLID, 'color' => ['argb' => 'FF001d68'], ], 'borders' => [ 'bottom' => ['borderStyle' => Border::BORDER_THIN], 'right' => ['borderStyle' => Border::BORDER_MEDIUM], ], 'font' => [ 'bold' => true, 'color' => ['argb' => 'FFFFFFFF'], ] ]; $row_base = 6; $i=0; foreach($repEdo_rs as $redo){ $row = $row_base; if($i >= $spreadsheet->getSheetCount()){ $spreadsheet->createSheet(); } $spreadsheet->setActiveSheetIndex($i); //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()); $spreadsheet->getActiveSheet() /*->setCellValue('A'.$row, 'Estado') ->setCellValue('B'.$row, 'Tipo') ->setCellValue('C'.$row, 'Profesor') ->setCellValue('D'.$row, 'Materia') ->setCellValue('E'.$row, 'Grupo') ->setCellValue('F'.$row, 'Fecha falta') ->setCellValue('G'.$row, 'Fecha reposición') ->setCellValue('H'.$row, 'Salón');*/ ->setCellValue('A'.$row, 'Tipo de solicitud') ->setCellValue('B'.$row, 'Profesor') ->setCellValue('C'.$row, 'Dependencia') ->setCellValue('D'.$row, 'Carrera') ->setCellValue('E'.$row, 'Materia') ->setCellValue('F'.$row, 'Grupo') ->setCellValue('G'.$row, 'Ciclo') ->setCellValue('H'.$row, 'Bloque') ->setCellValue('I'.$row, 'Fecha de falta') ->setCellValue('J'.$row, 'Horario de falta inicio') ->setCellValue('K'.$row, 'Horario de falta fin') ->setCellValue('L'.$row, 'Fecha de reposición') ->setCellValue('M'.$row, 'Horario de reposición inicio') ->setCellValue('N'.$row, 'Horario de reposición fin') ->setCellValue('O'.$row, 'Tipo de aula') ->setCellValue('P'.$row, 'Salón'); $spreadsheet->getActiveSheet()->getStyle('A'.$row.':P'.$row)->applyFromArray($headerStyle); $repoParams[":edo"]=$redo["estado_reposicion_id"]; if($user->rol["rol_id"] == 7){//es supervisor $repoParams[":sup"] = $user->user["id"]; $solicitudes_rs = $db->query('SELECT * FROM fs_solicitud(NULL, '.$query.':edo, NULL, :sup) ', $repoParams ); }else{ $solicitudes_rs = $db->query('SELECT * FROM fs_solicitud(NULL, '.$query.':edo, NULL, NULL) ', $repoParams ); } $row++; $sheet = $spreadsheet->getActiveSheet(); $sheet->setTitle($redo["estado_nombre"]); if(isset($solicitudes_rs) && count($solicitudes_rs)>0){ foreach($solicitudes_rs as $reposicion){ /* RETURNS TABLE(solicitud_id integer, horario_id integer, fecha_nueva date, hora_nueva time without time zone, hora_nueva_fin time without time zone, profesor_id integer, profesor_nombre character varying, profesor_clave character varying, descripcion text, estado_reposicion_id integer, estado_nombre character varying, estado_color character varying, alumnos integer, fecha_clase date, tipoaula_id integer, tipoaula_nombre character varying, tipoaula_supervisor boolean, solicitudtipo_id integer, solicitudtipo_nombre character varying, salon_id integer, salon_nombre character varying, salon_array json, usuario_id integer, usuario_nombre character varying, bloque integer, ciclo integer, duracion_interval interval, supervisor_id integer, supervisor_nombre character varying, facultad_id integer, facultad_nombre character varying, clave_dependencia character varying, carrera_nombre character varying, materia_id integer, materia_nombre character varying, horario_grupo character varying, horario_hora time without time zone, horario_hora_fin time without time zone, motivo_cancelacion text, horario_dia integer, horario_carrera character varying, carrera_comun boolean) */ $sheet->setCellValue('A'.$row, $reposicion["solicitudtipo_nombre"]); $sheet->setCellValue('B'.$row, $reposicion["profesor_clave"]." - ".$reposicion["profesor_nombre"]); $sheet->setCellValue('C'.$row, $reposicion["facultad_nombre"]); $sheet->setCellValue('D'.$row, $reposicion["carrera_nombre"]); $sheet->setCellValue('E'.$row, $reposicion["materia_nombre"]); if($reposicion["horario_grupo"]!="") $sheet->setCellValue('F'.$row, $reposicion["horario_grupo"]); else $sheet->setCellValue('F'.$row, "Sin grupo"); $sheet->setCellValue('G'.$row, $reposicion["ciclo"]); $sheet->setCellValue('H'.$row, $reposicion["bloque"]); if(!empty($reposicion["fecha_clase"])){ $fechaI = DateTime::createFromFormat('Y-m-d', $reposicion["fecha_clase"])->format('d/m/Y'); $sheet->setCellValue('I'.$row, $fechaI); $sheet->setCellValue('J'.$row, "".substr($reposicion["horario_hora"],0, 5)); $sheet->setCellValue('K'.$row, "".substr($reposicion["horario_hora_fin"],0, 5)); } $fechaF = DateTime::createFromFormat('Y-m-d', $reposicion["fecha_nueva"])->format('d/m/Y'); $sheet->setCellValue('L'.$row, $fechaF); $sheet->setCellValue('M'.$row, "".substr($reposicion["hora_nueva"],0, 5)); $sheet->setCellValue('N'.$row, "".substr($reposicion["hora_nueva_fin"],0, 5)); $sheet->setCellValue('O'.$row, $reposicion["tipoaula_nombre"]); if($reposicion["salon_id"] != ""){ $salon_json = json_decode($reposicion["salon_array"], true); $sheet->setCellValue('P'.$row, $salon_json[count($salon_json)-1]); }else $sheet->setCellValue('P'.$row, "Pendiente"); $row++; }//foreach }//if foreach ($sheet->getColumnIterator() as $column) { $sheet->getColumnDimension($column->getColumnIndex())->setAutoSize(true); } $sheet->setAutoFilter('A'.$row_base.':P'.$row_base); $i++; } $spreadsheet->setActiveSheetIndex(0); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->save('php://output');