solicitudes_excel.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. $fecha = date('d_m_Y');
  3. require_once '../class/c_login.php';
  4. if (!isset($_SESSION['user'])){
  5. die(header('Location: index.php'));
  6. }
  7. header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
  8. header("Content-Disposition: attachment;filename=solicitudes_$fecha.xlsx");
  9. header("Cache-Control: max-age=0");
  10. require_once "../vendor/autoload.php";
  11. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  12. use PhpOffice\PhpSpreadsheet\Style\Border;
  13. use PhpOffice\PhpSpreadsheet\Style\Color;
  14. use PhpOffice\PhpSpreadsheet\Style\Fill;
  15. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  16. use PhpOffice\PhpSpreadsheet\IOFactory;
  17. $fecha_ini = $_POST["fecha_inicial"];
  18. $fecha_fin = $_POST["fecha_final"];
  19. //Reposiciones
  20. $repEdo_rs = $db->query('SELECT * FROM fs_estado_reposicion' );
  21. $repoParams = array();
  22. if($user->rol["rol_id"] == 9){//es coordinador
  23. $query .= ":facultad, ";
  24. $repoParams[":facultad"] = $user->facultad["facultad_id"];
  25. }else{//supervisor
  26. $query .= "NULL, ";
  27. }
  28. if(isset($_POST["prof"]) ){
  29. $query .= ":prof,";
  30. $profesor = trim($_POST["prof"]);//limpia texto
  31. $repoParams[":prof"] = $profesor;
  32. }else{
  33. $query .= "NULL,";
  34. }
  35. $query .= ":f_ini, :f_fin, ";
  36. $spreadsheet = new Spreadsheet();
  37. // Set document properties
  38. $spreadsheet->getProperties()->setCreator('Universidad La Salle')
  39. ->setLastModifiedBy('Universidad La Salle')
  40. ->setTitle('Solicitudes')
  41. ->setDescription('Reporte de solicitudes.');
  42. $headerStyle = new Style();
  43. $headerStyle->applyFromArray(
  44. [
  45. 'fill' => [
  46. 'fillType' => Fill::FILL_SOLID,
  47. 'color' => ['argb' => 'FF001d68'],
  48. ],
  49. 'borders' => [
  50. 'bottom' => ['borderStyle' => Border::BORDER_THIN],
  51. 'right' => ['borderStyle' => Border::BORDER_MEDIUM],
  52. ],
  53. 'font' => [
  54. 'bold' => true,
  55. 'color' => ['argb' => 'FFFFFFFF'],
  56. ]
  57. ]
  58. );
  59. $row_base = 6;
  60. $i=0;
  61. foreach($repEdo_rs as $redo){
  62. $row = $row_base;
  63. $spreadsheet->setActiveSheetIndex($i);
  64. //crea imagen
  65. $drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
  66. $drawing->setName('La Salle');
  67. $drawing->setDescription('La Salle');
  68. $drawing->setPath('../imagenes/logo.png'); // put your path and image here
  69. $drawing->setCoordinates('A1');
  70. $drawing->setHeight(100);
  71. $drawing->setOffsetX(10);
  72. //agrega imagen
  73. $drawing->setWorksheet($spreadsheet->getActiveSheet());
  74. $spreadsheet->getActiveSheet()
  75. ->setCellValue('A'.$row, 'Estado')
  76. ->setCellValue('B'.$row, 'Tipo')
  77. ->setCellValue('C'.$row, 'Profesor')
  78. ->setCellValue('D'.$row, 'Materia')
  79. ->setCellValue('E'.$row, 'Grupo')
  80. ->setCellValue('F'.$row, 'Fecha falta')
  81. ->setCellValue('G'.$row, 'Fecha reposición')
  82. ->setCellValue('H'.$row, 'Salón');
  83. $repoParams[":edo"]=$redo["estado_reposicion_id"];
  84. if($user->rol["rol_id"] == 7){//es supervisor
  85. $repoParams[":sup"] = $user->user["id"];
  86. $solicitudes_rs = $db->query('SELECT * FROM fs_solicitud(NULL, '.$query.':edo, NULL, :sup) ', $repoParams );
  87. }else{
  88. $solicitudes_rs = $db->query('SELECT * FROM fs_solicitud(NULL, '.$query.':edo, NULL, NULL) ', $repoParams );
  89. }
  90. $spreadsheet->setActiveSheetIndex($sheet)->setTitle($redo["estado_nombre"]);
  91. if(isset($solicitudes_rs) && count($solicitudes_rs)>0){
  92. foreach($solicitudes_rs as $reposicion){
  93. $sheet = $spreadsheet->getActiveSheet();
  94. $sheet->setCellValue('A'.$row, $reposicion["estado_nombre"]);
  95. $sheet->setCellValue('B'.$row, $reposicion["solicitudtipo_nombre"]);
  96. $sheet->setCellValue('C'.$row, $reposicion["profesor_clave"]." - ".$reposicion["profesor_nombre"]);
  97. $sheet->setCellValue('D'.$row, $reposicion["materia_nombre"]);
  98. if($reposicion["horario_grupo"]!="")
  99. $sheet->setCellValue('E'.$row, $reposicion["grupo_nombre"]);
  100. if($reposicion["fecha_clase"]!=""){
  101. $sheet->setCellValue('F'.$row, $fechaI." ".substr($reposicion["horario_hora"],0, 5));
  102. }
  103. $fechaF = date("d/m/Y", strtotime($reposicion["fecha_nueva"]));
  104. $sheet->setCellValue('G'.$row, $fechaF." ".substr($reposicion["hora_nueva"],0, 5)." a ".substr($reposicion["hora_nueva_fin"],0, 5));
  105. if($reposicion["salon_id"] != ""){
  106. $salon_json = json_decode($reposicion["salon_array"], true);
  107. $sheet->setCellValue('H'.$row, $salon_json[count($salon_json)-1]);
  108. }else
  109. $sheet->setCellValue('H'.$row, "Pendiente");
  110. $row++;
  111. }//foreach
  112. }//if
  113. $i++;
  114. }
  115. $spreadsheet->setActiveSheetIndex(0);
  116. foreach ($sheet->getColumnIterator() as $column) {
  117. $sheet->getColumnDimension($column->getColumnIndex())->setAutoSize(true);
  118. }
  119. $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
  120. $writer->save('php://output');