solicitudes_excel.php 4.9 KB

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