PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Core/MainBundle/Controller/DefaultController.php

https://bitbucket.org/arturoblack/tomoyo
PHP | 941 lines | 746 code | 54 blank | 141 comment | 78 complexity | 0e32ec97d7d14e8c0f7b669e8f0fb96c MD5 | raw file
Possible License(s): BSD-3-Clause, BSD-2-Clause, Apache-2.0, LGPL-2.1, CC-BY-3.0, LGPL-3.0
  1. <?php
  2. namespace Core\MainBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Ps\PdfBundle\Annotation\Pdf;
  6. use Core\MainBundle\Entity\ReportTicketStatus;
  7. use Core\MainBundle\Entity\GlpiTickets;
  8. use Symfony\Component\HttpFoundation\Session\Session;
  9. /**
  10. * Clase principal encargada de ejecutar los reportes
  11. * y mostrarlos en la pagina web
  12. * @package ReporteCore
  13. * @subpackage Controllers
  14. */
  15. class DefaultController extends Controller
  16. {
  17. public function valorateListAction(){
  18. $request = Request::createFromGlobals();
  19. $rs = $this->get('report_service');
  20. $op = $this->getDatesPost();
  21. $title = "Reporte de Valoracion de atención".$op['label'];
  22. $data = $rs->getValoratesReport($op);
  23. # generar resumen
  24. $sum = 0;
  25. $tot = 0;
  26. foreach ($data[0]['campos'] as $row) {
  27. # code...
  28. // var_dump($row);
  29. $sum += $row['cantidad'];
  30. $tot += $row['ranking']*$row['cantidad'];
  31. }
  32. if($sum and $tot)
  33. $valProm = round(($tot/$sum),0);
  34. else
  35. $valProm = 0;
  36. //var_dump($data);
  37. if($this->getRequest()->isXmlHttpRequest()){
  38. $ajax='Ajax';
  39. return $this->render(
  40. 'CoreMainBundle:Default:valorateListAjax.html.twig',
  41. array('title'=>$title
  42. ,'datos'=>$data
  43. ,'del'=> $op['del']
  44. ,'al' => $op['al']
  45. ,'valProm'=>$valProm
  46. )
  47. );
  48. }
  49. return $this->render(
  50. 'CoreMainBundle:Default:valorateList.html.twig',
  51. array('title'=>$title
  52. ,'datos'=>$data
  53. ,'valProm'=>$valProm
  54. )
  55. );
  56. }
  57. public function getValoratesTicketsAction(){
  58. $request = Request::createFromGlobals();
  59. $rs = $this->get('report_service');
  60. $del = $request->query->get('del',false);
  61. $al = $request->query->get('al',false);
  62. $st = $request->query->get('stars',false);
  63. $op = array('del'=>$del,'al'=>$al,'stars'=>$st);
  64. $data = $rs->getValoratesTicketsReport($op);
  65. return $this->render(
  66. 'CoreMainBundle:Default:valorateTickets.html.twig',
  67. array('datos' => $data)
  68. );
  69. }
  70. public function testAction(){
  71. $cs = $this->get('config_service');
  72. $red = $cs->getConfParam('ranking','rojo');
  73. // echo "<h1>$red </h1>";
  74. return $this->render('CoreMainBundle:Default:index.html.twig',
  75. array('tickets' => 'ss'));
  76. }
  77. /**
  78. * Este Action se encarga de mostar la pantalla de index
  79. * @return html rendereado de la pagina index
  80. */
  81. public function indexAction()
  82. {
  83. $cs = $this->get('config_service');
  84. $time = $cs->getConfParam('ranking','time_act');
  85. return $this->render('CoreMainBundle:Default:index.html.twig',
  86. array('time' => $time));
  87. }
  88. /**
  89. * Este Action se encarga de generar el archivo de Exel
  90. * para el reporte de personas
  91. * @param area Boolead false sin area
  92. * @param area String area
  93. * @return archivo XLS
  94. */
  95. public function timeReportXlsAction($area = false){
  96. /** Aqui inicia el core **/
  97. $title = "Reporte de Tickets Generados y Cerrados ";
  98. $data = $this->getDatesPost();
  99. $od = $this->getDestOrigPost();
  100. $op = $this->getOptionsPost();
  101. $rs = $this->get('report_service');
  102. $report = $rs->getTimeReport($data, $od, $area);
  103. $title = "Reporte de Tiempo promedio de Atención por personas del".$data['label'];
  104. // ask the service for a Excel5
  105. $excelService = $this->get('xls.service_xls5');
  106. $excelService->excelObj->getProperties()->setCreator("ReportesGLPI")
  107. ->setLastModifiedBy("ReportesGLPI")
  108. ->setTitle($title)
  109. ->setSubject("Reporte de Personal GLPI")
  110. ->setDescription($title)
  111. ->setKeywords("office 2005 openxml php")
  112. ->setCategory("XLS result file");
  113. $letras = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
  114. 'Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF');
  115. $excelService->excelObj->setActiveSheetIndex(0)
  116. ->setCellValue('A2',$title);
  117. // {% for key, data in datos %}
  118. foreach ($report as $key => $value) {
  119. if($key == 0){
  120. $i=1;
  121. foreach ($value as $k => $val) {
  122. $excelService->excelObj->setActiveSheetIndex(0)
  123. ->setCellValue($letras[$i].'2',$k);
  124. $i+=2;
  125. }
  126. }
  127. }
  128. foreach ($report as $key => $value) {
  129. if($key == 0){
  130. $i=1;
  131. foreach ($value as $k => $val) {
  132. $excelService->excelObj->setActiveSheetIndex(0)
  133. ->setCellValue($letras[$i].'3','Numero de Tickets')
  134. ->setCellValue($letras[$i+1].'3','Tiempo Prom');
  135. $i+=2;
  136. }
  137. }
  138. }
  139. $n= 4;
  140. foreach ($report as $key => $value) {
  141. $excelService->excelObj->setActiveSheetIndex(0)
  142. ->setCellValue('A'.$n,$key);
  143. $i=2;
  144. foreach ($value as $k => $val) {
  145. $excelService->excelObj->setActiveSheetIndex(0)
  146. ->setCellValue($letras[$i].$n,$val['ticket'])
  147. ->setCellValue($letras[$i+1].$n,$val['prom']);
  148. $i+=2;
  149. }
  150. $n++;
  151. }
  152. $excelService->excelObj->getActiveSheet()->setTitle('Estados-'.$area);
  153. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  154. $excelService->excelObj->setActiveSheetIndex(0);
  155. //create the response
  156. $response = $excelService->getResponse();
  157. $response->headers->set('Content-Type', 'text/vnd.ms-excel; charset=utf-8');
  158. $response->headers->set('Content-Disposition', 'attachment;filename='.$area.'.xls');
  159. // If you are using a https connection, you have to set those two headers for compatibility with IE <9
  160. $response->headers->set('Pragma', 'public');
  161. $response->headers->set('Cache-Control', 'maxage=1');
  162. return $response;
  163. }
  164. /**
  165. *@Pdf()
  166. */
  167. public function timeReportAction($area = false){
  168. $request = Request::createFromGlobals();
  169. if ($request->getMethod() != 'POST'){
  170. #escapar a un plantilla vacio
  171. if($area)
  172. return $this->render('CoreMainBundle:Default:noPost.html.twig'
  173. ,array('person'=>'person','report' => 'person','area'=>$area));
  174. else
  175. return $this->render('CoreMainBundle:Default:noPost.html.twig'
  176. ,array('person'=>'person','report' => 'person'));
  177. }
  178. // Is ajax Action?
  179. $ajax = '';
  180. if($this->getRequest()->isXmlHttpRequest()){ $ajax='Ajax'; }
  181. // is pdf Request?
  182. $format = 'html';
  183. if($this->get('request')->get('_format') == 'pdf'){ $format='pdf'; }
  184. /** Aqui inicia el core **/
  185. $data = $this->getDatesPost();
  186. $od = $this->getDestOrigPost();
  187. $op = $this->getOptionsPost();
  188. $rs = $this->get('report_service');
  189. $report = $rs->getTimeReport($data, $od, $area);
  190. $title = "Reporte de Tiempo promedio de Atención por personas del".$data['label'];
  191. return $this->render(
  192. 'CoreMainBundle:Default:reporteTimeCute'.$ajax.'.'.$format.'.twig'
  193. ,array(
  194. 'datos' => $report
  195. ,'title'=> $title
  196. ,'type'=> $data['type']
  197. ,'options' => $op
  198. ,'area' => $area
  199. ,'report' => 'person'
  200. )
  201. );
  202. }
  203. /**
  204. *@Pdf()
  205. */
  206. public function mainReportAction(){
  207. $request = Request::createFromGlobals();
  208. if ($request->getMethod() != 'POST'){
  209. #escapar a un plantilla vacio
  210. return $this->render(
  211. 'CoreMainBundle:Default:noPost.html.twig',
  212. array('report' => 'main'));
  213. }
  214. // Is ajax Action?
  215. $ajax = '';
  216. if($this->getRequest()->isXmlHttpRequest()){ $ajax='Ajax'; }
  217. // is pdf Request?
  218. $format = 'html';
  219. if($this->get('request')->get('_format') == 'pdf'){ $format='pdf'; }
  220. /** Aqui inicia el core **/
  221. $data = $this->getDatesPost();
  222. $od = $this->getDestOrigPost();
  223. $op = $this->getOptionsPost();
  224. $rs = $this->get('report_service');
  225. $report = $rs->getMainReport($data, $od);
  226. $abstract = $rs->getAbstract($report);
  227. $title = "Reporte de Tickets Generados y Cerrados del ".$data['label'];
  228. return $this->render(
  229. 'CoreMainBundle:Default:reporte2'.$ajax.'.'.$format.'.twig'
  230. ,array(
  231. 'datos' => $report
  232. ,'title'=> $title
  233. ,'type'=> $data['type']
  234. ,'options' => $op
  235. ,'abs' => $abstract
  236. ,'report' => 'main'
  237. )
  238. );
  239. }
  240. /**
  241. * Este Action se encarga de generar el archivo de Exel
  242. * para el reporte de Tickets
  243. * @return archivo XLS
  244. */
  245. public function mainReportXlsAction(){
  246. $request = Request::createFromGlobals();
  247. if ($request->getMethod() != 'POST'){
  248. #escapar a un plantilla vacio
  249. return $this->render('CoreMainBundle:Default:noPost.html.twig');
  250. }
  251. // Is ajax Action?
  252. $ajax = '';
  253. if($this->getRequest()->isXmlHttpRequest()){ $ajax='Ajax'; }
  254. // is pdf Request?
  255. $format = 'html';
  256. if($this->get('request')->get('_format') == 'pdf'){ $format='pdf'; }
  257. // verificar si hay data enviada por post
  258. if ($request->getMethod() != 'POST'){
  259. #escapar a un plantilla vacio
  260. return $this->render(
  261. 'CoreMainBundle:Default:noPost.html.twig');
  262. }
  263. /** Aqui inicia el core **/
  264. $title = "Reporte de Tickets Generados y Cerrados ";
  265. $data = $this->getDatesPost();
  266. $od = $this->getDestOrigPost();
  267. $op = $this->getOptionsPost();
  268. $rs = $this->get('report_service');
  269. $report = $rs->getMainReport($data, $od);
  270. // $abstract = $rs->getAbstract($report);
  271. #$title = " Reportes del Area de $area ";
  272. // ask the service for a Excel5
  273. $excelService = $this->get('xls.service_xls5');
  274. // or $this->get('xls.service_pdf');
  275. // or create your own is easy just modify services.yml
  276. // create the object see http://phpexcel.codeplex.com documentation
  277. $excelService->excelObj->getProperties()->setCreator("ReportesGLPI")
  278. ->setLastModifiedBy("ReportesGLPI")
  279. ->setTitle("Office 2005 XLSX Test Document")
  280. ->setSubject("Office 2005 XLSX Test Document")
  281. ->setDescription("Test document for Office 2005 XLSX, generated using PHP classes.")
  282. ->setKeywords("office 2005 openxml php")
  283. ->setCategory("Test result file");
  284. $letras = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
  285. 'Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF');
  286. $i=1;
  287. foreach ($report as $data) {
  288. $excelService->excelObj->setActiveSheetIndex(0)
  289. ->setCellValue('A1',$title)
  290. ->setCellValue('A3','Tickets Generados.')
  291. ->setCellValue('A4','Tickets Atendidos..')
  292. ->setCellValue('A5','Tickets Pendientes del Dia.')
  293. ->setCellValue('A6','Tickets Pendientes Acumulados del dia anterior.')
  294. ->setCellValue('A7','Tickets endientes Totales.')
  295. ->setCellValue($letras[$i].'2', $data['fecha'])
  296. ->setCellValue($letras[$i].'3', $data['campos']['generados'])
  297. ->setCellValue($letras[$i+1].'3', $data['campos']['pendAnteriores'])
  298. ->setCellValue($letras[$i].'4', $data['campos']['atendidos'])
  299. ->setCellValue($letras[$i+1].'4', $data['campos']['atenAnteriores'])
  300. ->setCellValue($letras[$i].'5', $data['campos']['pendientes'])
  301. ->setCellValue($letras[$i+1].'5', $data['campos']['restantes'])
  302. ->setCellValue($letras[$i].'6', $data['campos']['pendAnteriores'])
  303. ->setCellValue($letras[$i+1].'6', '----')
  304. ->setCellValue($letras[$i].'7', $data['campos']['pendTotales'])
  305. ->setCellValue($letras[$i+1].'7', '----');
  306. $i+=2;
  307. }
  308. $excelService->excelObj->getActiveSheet()->setTitle('Simple ');
  309. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  310. $excelService->excelObj->setActiveSheetIndex(0);
  311. //create the response
  312. $response = $excelService->getResponse();
  313. $response->headers->set('Content-Type', 'text/vnd.ms-excel; charset=utf-8');
  314. $response->headers->set('Content-Disposition', 'attachment;filename=report.xls');
  315. // If you are using a https connection, you have to set those two headers for compatibility with IE <9
  316. $response->headers->set('Pragma', 'public');
  317. $response->headers->set('Cache-Control', 'maxage=1');
  318. return $response;
  319. }
  320. /**
  321. *@Pdf()
  322. */
  323. public function mainAreaReportAction($area){
  324. $request = Request::createFromGlobals();
  325. if ($request->getMethod() != 'POST'){
  326. #escapar a un plantilla vacio
  327. return $this->render('CoreMainBundle:Default:noPost.html.twig',
  328. array('area'=>$area,'report' => 'main'));
  329. }
  330. // Is ajax Action?
  331. $ajax = '';
  332. if($this->getRequest()->isXmlHttpRequest()){ $ajax='Ajax'; }
  333. // is pdf Request?
  334. $format = 'html';
  335. if($this->get('request')->get('_format') == 'pdf'){ $format='pdf'; }
  336. /** Aqui inicia el core **/
  337. $data = $this->getDatesPost();
  338. $od = $this->getDestOrigPost();
  339. $op = $this->getOptionsPost();
  340. $rs = $this->get('report_service');
  341. $report = $rs->getMainReport($data, $od, $area);
  342. $abstract = $rs->getAbstract($report);
  343. $title = "Reporte de Tickets del área $area, Generados y Cerrados del ".$data['label'];
  344. return $this->render(
  345. 'CoreMainBundle:Default:reporte2'.$ajax.'.'.$format.'.twig'
  346. ,array(
  347. 'datos' => $report
  348. ,'title'=> $title
  349. ,'type'=> $data['type']
  350. ,'options' => $op
  351. ,'area' => $area
  352. ,'abs' => $abstract
  353. ,'report' => 'main'
  354. )
  355. );
  356. }
  357. /**
  358. * Este Action se encarga de generar el archivo de Exel
  359. * para el reporte de tickets por area
  360. * @param area String area
  361. * @return archivo XLS
  362. */
  363. public function areaReportXlsAction($area)
  364. {
  365. /** Aqui inicia el core **/
  366. $title = "Reporte de Tickets Generados y Cerrados ";
  367. $data = $this->getDatesPost();
  368. $od = $this->getDestOrigPost();
  369. $op = $this->getOptionsPost();
  370. $rs = $this->get('report_service');
  371. $datos = $rs->getMainReport($data, $od, $area);
  372. $title = " Reportes del Area de $area ";
  373. // ask the service for a Excel5
  374. $excelService = $this->get('xls.service_xls5');
  375. // or $this->get('xls.service_pdf');
  376. // or create your own is easy just modify services.yml
  377. // create the object see http://phpexcel.codeplex.com documentation
  378. $excelService->excelObj->getProperties()->setCreator("ReportesGLPI")
  379. ->setLastModifiedBy("ReportesGLPI")
  380. ->setTitle("Office 2005 XLSX Test Document")
  381. ->setSubject("Office 2005 XLSX Test Document")
  382. ->setDescription("Test document for Office 2005 XLSX, generated using PHP classes.")
  383. ->setKeywords("office 2005 openxml php")
  384. ->setCategory("Test result file");
  385. $letras = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
  386. 'Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF');
  387. $i=1;
  388. foreach ($datos as $data) {
  389. $excelService->excelObj->setActiveSheetIndex(0)
  390. ->setCellValue('A1',$title)
  391. ->setCellValue('A3','Tickets Generados.')
  392. ->setCellValue('A4','Tickets Atendidos..')
  393. ->setCellValue('A5','Tickets Pendientes del Dia.')
  394. ->setCellValue('A6','Tickets Pendientes Acumulados del dia anterior.')
  395. ->setCellValue('A7','Tickets endientes Totales.')
  396. ->setCellValue($letras[$i].'2', $data['fecha'])
  397. ->setCellValue($letras[$i].'3', $data['campos']['generados'])
  398. ->setCellValue($letras[$i+1].'3', $data['campos']['pendAnteriores'])
  399. ->setCellValue($letras[$i].'4', $data['campos']['atendidos'])
  400. ->setCellValue($letras[$i+1].'4', $data['campos']['atenAnteriores'])
  401. ->setCellValue($letras[$i].'5', $data['campos']['pendientes'])
  402. ->setCellValue($letras[$i+1].'5', $data['campos']['restantes'])
  403. ->setCellValue($letras[$i].'6', $data['campos']['pendAnteriores'])
  404. ->setCellValue($letras[$i+1].'6', '----')
  405. ->setCellValue($letras[$i].'7', $data['campos']['pendTotales'])
  406. ->setCellValue($letras[$i+1].'7', '----');
  407. $i+=2;
  408. }
  409. $excelService->excelObj->getActiveSheet()->setTitle('Simple '.$area);
  410. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  411. $excelService->excelObj->setActiveSheetIndex(0);
  412. //create the response
  413. $response = $excelService->getResponse();
  414. $response->headers->set('Content-Type', 'text/vnd.ms-excel; charset=utf-8');
  415. $response->headers->set('Content-Disposition', 'attachment;filename='.$area.'.xls');
  416. // If you are using a https connection, you have to set those two headers for compatibility with IE <9
  417. $response->headers->set('Pragma', 'public');
  418. $response->headers->set('Cache-Control', 'maxage=1');
  419. return $response;
  420. }
  421. /**
  422. *@Pdf()
  423. */
  424. public function statusReportAction($area = false)
  425. {
  426. $request = Request::createFromGlobals();
  427. if ($request->getMethod() != 'POST'){
  428. #escapar a un plantilla vacio
  429. if($area)
  430. return $this->render('CoreMainBundle:Default:noPost.html.twig'
  431. ,array('status'=>'status','area'=>$area,'report' => 'status'));
  432. else
  433. return $this->render('CoreMainBundle:Default:noPost.html.twig'
  434. ,array('status'=>'status','report' => 'status'));
  435. }
  436. // Is ajax Action?
  437. $ajax = '';
  438. if($this->getRequest()->isXmlHttpRequest()){ $ajax='Ajax'; }
  439. // is pdf Request?
  440. $format = 'html';
  441. if($this->get('request')->get('_format') == 'pdf'){ $format='pdf'; }
  442. /** Aqui inicia el core **/
  443. $data = $this->getDatesPost();
  444. $od = $this->getDestOrigPost();
  445. $op = $this->getOptionsPost();
  446. $rs = $this->get('report_service');
  447. $datos = $rs->getStatusReport($data,$od, $area);
  448. $title = "Reporte de Estado de los Tickets del ".$data['label'];
  449. // $datos = $this->reciveStatusInformation();
  450. return $this->render(
  451. 'CoreMainBundle:Default:reporte1'.$ajax.'.'.$format.'.twig'
  452. ,array('datos' => $datos
  453. ,'title'=> $title
  454. ,'type'=> $data['type']
  455. ,'options' => $op
  456. ,'area' => $area
  457. ,'report' => 'status'
  458. //,'abs' => $abstract
  459. )
  460. );
  461. }
  462. /**
  463. * Este Action se encarga de generar el archivo de Exel
  464. * para el reporte de Estados
  465. * @param area Boolead false sin area
  466. * @param area String area
  467. * @return archivo XLS
  468. */
  469. public function statusReportXlsAction($area = false)
  470. {
  471. /** Aqui inicia el core **/
  472. $title = "Reporte de Tickets Generados y Cerrados ";
  473. $data = $this->getDatesPost();
  474. $od = $this->getDestOrigPost();
  475. $op = $this->getOptionsPost();
  476. $rs = $this->get('report_service');
  477. $datos = $rs->getStatusReport($data,$od, $area);
  478. $title = "Reporte de Estado de los Tickets del ".$data['label'];
  479. // ask the service for a Excel5
  480. $excelService = $this->get('xls.service_xls5');
  481. $excelService->excelObj->getProperties()->setCreator("ReprtesGLPI")
  482. ->setLastModifiedBy("ReprtesGLPI")
  483. ->setTitle($title)
  484. ->setSubject("Reporte de estados GLPI")
  485. ->setDescription($title)
  486. ->setKeywords("office 2005 openxml php")
  487. ->setCategory("XLS result file");
  488. $letras = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
  489. 'Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF');
  490. $i=1;
  491. foreach ($datos as $data) {
  492. if(!isset($data['campos']['new'])) $data['campos']['new']=0;
  493. if(!isset($data['campos']['assign'])) $data['campos']['assign']=0;
  494. if(!isset($data['campos']['plan'])) $data['campos']['plan']=0;
  495. if(!isset($data['campos']['waiting'])) $data['campos']['waiting']=0;
  496. if(!isset($data['campos']['closed'])) $data['campos']['closed']=0;
  497. $excelService->excelObj->setActiveSheetIndex(0)
  498. ->setCellValue('A2',$title)
  499. ->setCellValue('A3','Tickets Nuevos.')
  500. ->setCellValue('A4','Tickets Asignados.')
  501. ->setCellValue('A5','Tickets Planificados.')
  502. ->setCellValue('A6','Tickets en Espera.')
  503. ->setCellValue('A7','Tickets Cerrados.')
  504. ->setCellValue($letras[$i].'2', $data['fecha'])
  505. ->setCellValue($letras[$i].'3', $data['campos']['new'])
  506. ->setCellValue($letras[$i].'4', $data['campos']['assign'])
  507. ->setCellValue($letras[$i].'5', $data['campos']['plan'])
  508. ->setCellValue($letras[$i].'6', $data['campos']['waiting'])
  509. ->setCellValue($letras[$i].'7', $data['campos']['closed']);
  510. $i+=1;
  511. }
  512. $excelService->excelObj->getActiveSheet()->setTitle('Estados-'.$area);
  513. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  514. $excelService->excelObj->setActiveSheetIndex(0);
  515. //create the response
  516. $response = $excelService->getResponse();
  517. $response->headers->set('Content-Type', 'text/vnd.ms-excel; charset=utf-8');
  518. $response->headers->set('Content-Disposition', 'attachment;filename='.$area.'.xls');
  519. // If you are using a https connection, you have to set those two headers for compatibility with IE <9
  520. $response->headers->set('Pragma', 'public');
  521. $response->headers->set('Cache-Control', 'maxage=1');
  522. return $response;
  523. }
  524. /**
  525. * Obtiene los filtros de Fechas elegidas por el usuario
  526. * esta clase revisa las peticiones POST y regresa
  527. * - los parametros de la consulta
  528. * - tipo seleccionado
  529. * @return Array fechas de fltrado
  530. */
  531. private function getDatesPost(){
  532. $request = Request::createFromGlobals();
  533. if ($request->getMethod() != 'POST'){
  534. return array(
  535. 'parameters'=>false
  536. ,'type'=>false
  537. ,'label'=>'');
  538. }
  539. $request->getPathInfo();
  540. // leyendo las variables Basicas
  541. $tipoFech = $request->request->get('tipoFecha', false);
  542. // inicializando variables
  543. $label = "";
  544. $dataPar = array();
  545. // si se selecciono Dia
  546. if($tipoFech == 'day'){
  547. $val = $request->request->get('dayValue', '2012-01-01');
  548. $nextDay = date(
  549. 'Y-m-d',strtotime('+1 day', strtotime($val)));
  550. $beforeDay = date(
  551. 'Y-m-d',strtotime('-1 day', strtotime($val)));
  552. $parametros = array(
  553. 'day' => $val
  554. ,'protoDay' => $beforeDay
  555. ,'nextDay' => $nextDay
  556. ,'beforeDay' => $beforeDay
  557. );
  558. $dataPar[]=$parametros;
  559. $label = 'día '.$this->days[date('l',strtotime($val))].' '
  560. .date('d',strtotime($val))
  561. .' de '.$this->months[date('F',strtotime($val))].' '
  562. .date('Y',strtotime($val));
  563. $delDay = $beforeDay;
  564. $alDay = $nextDay;
  565. }
  566. // si se selecciono Semana
  567. elseif($tipoFech == 'week'){
  568. $year = $request->request->get('weekYearValue', '13');
  569. $week = $request->request->get('weekValue', '2013');
  570. $rs = $this->get('report_service');
  571. $days = $rs->WeekToDates($week, $year);
  572. $diaIni = $days['monday'];
  573. $diaFin = $days['sunday'];
  574. $datos = array();
  575. $i=0;
  576. $proDay = $diaIni;
  577. while (strtotime($diaIni) <= strtotime($diaFin) ){
  578. $nextDay = date(
  579. 'Y-m-d',strtotime('+1 day', strtotime($diaIni)));
  580. $beforeDay = date(
  581. 'Y-m-d',strtotime('-1 day', strtotime($diaIni)));
  582. $parametros = array(
  583. 'day' => $diaIni
  584. ,'protoDay' => $proDay
  585. ,'nextDay' => $nextDay
  586. ,'beforeDay' => $beforeDay
  587. );
  588. $dataPar[]=$parametros;
  589. $diaIni = date(
  590. 'Y-m-d',strtotime('+1 day', strtotime($diaIni)));
  591. $dia = date('l',strtotime($diaIni));
  592. if($dia == 'Sunday'){
  593. $diaIni = date(
  594. 'Y-m-d',strtotime('+1 day', strtotime($diaIni)));
  595. }
  596. $i++;
  597. }
  598. $label = ' día '
  599. .$this->days[date('l',strtotime($proDay))].' '
  600. .date('d',strtotime($proDay))
  601. .' de '.$this->months[date('F',strtotime($proDay))].' '
  602. .date('Y',strtotime($proDay))
  603. .' al día '.$this->days[date('l',strtotime($diaFin))].' '
  604. .date('d',strtotime($diaFin))
  605. .' de '.$this->months[date('F',strtotime($diaFin))].' '
  606. .date('Y',strtotime($diaFin));
  607. $delDay = $proDay;
  608. $alDay = $diaFin;
  609. }
  610. // si se selecciono Mes
  611. elseif($tipoFech == 'month'){
  612. $year = $request->request->get('yearMonthValue', '2012');
  613. $month = $request->request->get('monthValue', '01');
  614. $diaIni = "$year-$month-01";
  615. if($month < 12){ $month2 = $month+1; }
  616. else { $year +=1; $month2=1; }
  617. $diaFin = "$year-$month2-01";
  618. $datos = array();
  619. $i=0;
  620. $proDay = $diaIni;
  621. while (strtotime($diaIni) < strtotime($diaFin) ){
  622. // echo "$diaIni - $diaFin <br>";
  623. $nextDay = date(
  624. 'Y-m-d',strtotime('+7 day', strtotime($diaIni)));
  625. if(strtotime($nextDay) >= strtotime($diaFin)) {
  626. $nextDay = date(
  627. 'Y-m-d',strtotime('-1 day', strtotime($diaFin)));
  628. }
  629. $beforeDay = date(
  630. 'Y-m-d',strtotime('-7 day', strtotime($diaIni)));
  631. $labelNextDay = date(
  632. 'Y-m-d',strtotime('+6 day', strtotime($diaIni)));
  633. $parametros = array(
  634. 'day' => $diaIni
  635. ,'protoDay' => $proDay
  636. ,'nextDay' => $nextDay
  637. ,'beforeDay' => $beforeDay
  638. );
  639. $dataPar[]=$parametros;
  640. #sumarle una Semana
  641. $diaIni = date(
  642. 'Y-m-d',strtotime('+7 day', strtotime($diaIni)));
  643. $dia = date('l',strtotime($diaIni));
  644. $i++;
  645. }
  646. $label = ' mes de '.$this->months[date('F',strtotime($proDay))].' de '
  647. .date('Y',strtotime($proDay));
  648. $delDay = date('Y',strtotime($proDay)).'-'.$month.'-01';
  649. $alDay = date('Y',strtotime($proDay)).'-'.$month.'-31';
  650. }
  651. // si se selecciono Anio
  652. elseif($tipoFech == 'year'){
  653. $year = $request->request->get('yearValue', '2012');
  654. $year2 = $year + 1;
  655. $diaIni = "$year-01-01";
  656. $diaFin = "$year2-01-01";
  657. $datos = array();
  658. $i=0;
  659. $proDay = $diaIni;
  660. while (strtotime($diaIni) < strtotime($diaFin) ){
  661. $nextDay = date(
  662. 'Y-m-d',strtotime('+1 month', strtotime($diaIni)));
  663. $beforeDay = date(
  664. 'Y-m-d',strtotime('-1 month', strtotime($diaIni)));
  665. $parametros = array(
  666. 'day' => $diaIni
  667. ,'protoDay' => $proDay
  668. ,'nextDay' => $nextDay
  669. ,'beforeDay' => $beforeDay
  670. );
  671. $dataPar[]=$parametros;
  672. #ordenar los resultados
  673. $label = 'año '.date('Y',strtotime($diaIni));
  674. #sumarle un dia
  675. $diaIni = date(
  676. 'Y-m-d',strtotime('+1 month', strtotime($diaIni)));
  677. $i++;
  678. if($nextDay > date('Y-m-d')){ break;}
  679. }
  680. $delDay = $year.'-01-01';
  681. $alDay = $year2.'-01-01';
  682. }
  683. // si se selecciono Custom/personalizado
  684. elseif($tipoFech == 'custom'){
  685. $diaIni = $request->request->get('cusValue', '2012-01-01');
  686. $diaFin = $request->request->get('cusValue1', '2012-01-07');
  687. $datos = array();
  688. $i=0;
  689. $proDay = $diaIni;
  690. while (strtotime($diaIni) <= strtotime($diaFin) ){
  691. $nextDay = date(
  692. 'Y-m-d',strtotime('+1 day', strtotime($diaIni)));
  693. $beforeDay = date(
  694. 'Y-m-d',strtotime('-1 day', strtotime($diaIni)));
  695. $parametros = array(
  696. 'day' => $diaIni
  697. ,'protoDay' => $proDay
  698. ,'nextDay' => $nextDay
  699. ,'beforeDay' => $beforeDay
  700. );
  701. $dataPar[]=$parametros;
  702. $diaIni = date(
  703. 'Y-m-d',strtotime('+1 day', strtotime($diaIni)));
  704. $dia = date('l',strtotime($diaIni));
  705. if($dia == 'Sunday'){
  706. $diaIni = date(
  707. 'Y-m-d',strtotime('+1 day', strtotime($diaIni)));
  708. }
  709. $i++;
  710. }
  711. $label = 'día '.$this->days[date('l',strtotime($proDay))].' '
  712. .date('d',strtotime($proDay))
  713. .' de '.$this->months[date('F',strtotime($proDay))].' '
  714. .date('Y',strtotime($proDay))
  715. .' al día '.$this->days[date('l',strtotime($diaFin))].' '
  716. .date('d',strtotime($diaFin))
  717. .' de '.$this->months[date('F',strtotime($diaFin))].' '
  718. .date('Y',strtotime($diaFin));
  719. $delDay = $proDay;
  720. $alDay = $diaFin;
  721. }
  722. return array(
  723. 'parameters'=>$dataPar
  724. ,'type'=>$tipoFech
  725. ,'label' => $label
  726. ,'del'=> $delDay
  727. ,'al'=>$alDay
  728. );
  729. }
  730. /**
  731. * Obtiene los Destinos/Origenes seleccionadas por el usuario
  732. * esta clase revisa las peticiones POST y regresa
  733. * - los valores de opciones
  734. * - el query "cleanned"
  735. * - el query "bruto"
  736. * @return Array opciones de filtrado adicional
  737. */
  738. private function getDestOrigPost(){
  739. $request = Request::createFromGlobals();
  740. $request->getPathInfo();
  741. if ($request->getMethod() != 'POST'){
  742. return array(
  743. 'cleannedQuery'=> false
  744. ,'parameters'=>false
  745. ,'query' => false
  746. );
  747. }
  748. # Tipos Generales
  749. $tipoArea = $request->request->get('tipoArea', false);
  750. $tipoServ = $request->request->get('tipoServicio', false);
  751. $tipoPers = $request->request->get('tipoPersona', false);
  752. $query="";
  753. $filterQuery = "";
  754. $filterParametros = array();
  755. $cont=0;
  756. if($tipoArea){
  757. $uneg = $request->request->get('uneg', 'corp');
  758. $areas = $request->request->get('areaValues', false );
  759. if(!$areas){
  760. //filtra solo unidad de negocio
  761. $unegs= array(
  762. 'uc' => $this->container->getParameter('uneg_uc')
  763. ,'cic' => $this->container->getParameter('uneg_cic')
  764. ,'apec' => $this->container->getParameter('uneg_apec' )
  765. ,'epgc' => $this->container->getParameter('uneg_epgc' )
  766. ,'ceg' => $this->container->getParameter('uneg_ceg')
  767. ,'corp' => $this->container->getParameter('uneg_corp' )
  768. );
  769. $value = $unegs[$uneg];
  770. $filterQuery .="(r.unidadnegocio = :value )" ;
  771. $query .= "( r.unidadnegocio = $value )";
  772. $filterParametros['value'] = $value;
  773. }
  774. else{
  775. $filterQuery .= " ( ";
  776. $query .= " ( ";
  777. $aux = 0;
  778. foreach ($areas as $key => $value) {
  779. if($aux>0) { $filterQuery .= " or "; $query .= " or ";}
  780. $filterQuery .="t.requesttypesId = :orig$key " ;
  781. $query .= "t.requesttypes_id = $value ";
  782. $filterParametros['orig'.$key] = $value;
  783. $aux++;
  784. }
  785. $filterQuery .=" )";
  786. $query .= " )";
  787. $cont++;
  788. }
  789. }
  790. if($tipoServ){
  791. $servicios = $request->request->get(
  792. 'servicioValues', array(0) );
  793. if($cont>0) { $filterQuery .= " and "; $query.=" and "; }
  794. $filterQuery .=" ( ";
  795. $query .= " ( ";
  796. $aux = 0;
  797. foreach ($servicios as $key => $value) {
  798. if($aux>0) { $filterQuery .= " or "; $query .= " or ";}
  799. $filterQuery .="t.itilcategoriesId = :servicio$key " ;
  800. $query .= "t.itilcategories_id = $value ";
  801. $filterParametros['servicio'.$key] = $value;
  802. $filterQuery++;
  803. $aux++;
  804. }
  805. $filterQuery .= " ) ";
  806. $query .= " ) ";
  807. $cont++;
  808. }
  809. if($tipoPers){
  810. $personas = $request->request->get(
  811. 'personaValues', '1' );
  812. $personas = explode(',', $personas);
  813. if($cont>0) { $filterQuery .= " and "; $query.=" and "; }
  814. $filterQuery .=" ( ";
  815. $query .= " ( ";
  816. $aux = 0;
  817. foreach ($personas as $key => $value) {
  818. if($aux>0) { $filterQuery .= " or "; $query .= " or ";}
  819. $filterQuery .="u.id = :user$key " ;
  820. $query .= "u.id = $value ";
  821. $filterParametros['user'.$key] = $value;
  822. #$filterQuery++;
  823. $aux++;
  824. }
  825. $filterQuery .= " ) ";
  826. $query .= " ) ";
  827. $cont++;
  828. // echo "<h1>$query<br>$filterQuery </h1>";
  829. }
  830. return array(
  831. 'cleannedQuery'=> $filterQuery
  832. ,'parameters'=>$filterParametros
  833. ,'query' => $query
  834. );
  835. }
  836. /**
  837. * Obtiene las opciones seleccionadas por el usuario
  838. * esta clase revisa las peticiones POST y regresa
  839. * - los valores de opciones adicinales
  840. * - Parte del labeval in /home/arturo/www/reportes/src/l del titulo
  841. * @return Array Opciones extras
  842. */
  843. private function getOptionsPost(){
  844. $request = Request::createFromGlobals();
  845. if ($request->getMethod() != 'POST'){
  846. return false;
  847. }
  848. $data = array(
  849. 'showHoyayer' => $request->request->get('showHoyayer', false)
  850. ,'showGrafica1' => $request->request->get('showGrafica1', false)
  851. ,'showGrafica2' => $request->request->get('showGrafica2', false)
  852. ,'showGrafica3' => $request->request->get('showGrafica3', false)
  853. ,'showResumen' => $request->request->get('showResumen', false)
  854. ,'showComent ' => $request->request->get('showComent', false)
  855. );
  856. return $data;
  857. }
  858. private $areas = array(
  859. "Redes"=>"Redes"
  860. ,"Desarrollo"=>"Desarrollo"
  861. ,"Service"=>"ServiceDesk"
  862. ,"Soporte"=>"Soporte T."
  863. );
  864. private $months = array(
  865. "Jan"=>"Ene" ,"January"=>"Enero"
  866. ,"Feb"=>"Feb" ,"February"=>"Febrero"
  867. ,"Mar"=>"Mar" ,"March"=>"Marzo"
  868. ,"Apr"=>"Abr" ,"April"=>"Abril"
  869. ,"May"=>"May" ,"May"=>"Mayo"
  870. ,"Jun"=>"Jun" ,"June"=>"Junio"
  871. ,"Jul"=>"Jul" ,"July"=>"Julio"
  872. ,"Aug"=>"Ago" ,"August"=>"Agosto"
  873. ,"Sep"=>"Sep" ,"September"=>"Septiembre"
  874. ,"Oct"=>"Oct" ,"October"=>"Octubre"
  875. ,"Nov"=>"Nov" ,"November"=>"Noviembre"
  876. ,"Dec"=>"Dic" ,"December"=>"Diciembre"
  877. );
  878. private $days = array(
  879. "Monday"=>"Lunes"
  880. ,"Tuesday"=>"Martes"
  881. ,"Wednesday"=>"Miercoles"
  882. ,"Thursday"=>"Jueves"
  883. ,"Friday"=>"Viernes"
  884. ,"Saturday"=>"Sabado"
  885. ,"Sunday"=>"Domingo"
  886. );
  887. }