Commit dc673a78aa4d15ec040647e6438cdc89bed7a8f5
1 parent
2fc869b7
Exists in
master
and in
2 other branches
Mudanças no relatório inicial para atender à PGFN
Showing
4 changed files
with
240 additions
and
57 deletions
Show diff stats
Controller/PrinterController.php
| ... | ... | @@ -49,6 +49,9 @@ class PrinterController extends Controller |
| 49 | 49 | */ |
| 50 | 50 | public function indexAction(Request $request) |
| 51 | 51 | { |
| 52 | + ini_set('memory_limit', '1024M'); | |
| 53 | + gc_enable(); | |
| 54 | + | |
| 52 | 55 | $em = $this->getDoctrine()->getManager(); |
| 53 | 56 | |
| 54 | 57 | $form = $request->query->get('form'); |
| ... | ... | @@ -65,42 +68,109 @@ class PrinterController extends Controller |
| 65 | 68 | $start = isset($start) ? $start : (time() - ((60*60*24)*30)); |
| 66 | 69 | $end = isset($end) ? $end : time(); |
| 67 | 70 | |
| 68 | - /* | |
| 71 | + $printers = $em->getRepository('CocarBundle:PrinterCounter')->relatorioGeral($start, $end); | |
| 72 | + | |
| 73 | + return array( | |
| 74 | + "printer" => $printers, | |
| 75 | + //"printerCounter" => $pCounter, | |
| 76 | + "form" => $this->createCalendarForm(0, new \DateTime(date("Y-m-d", $start)), new \DateTime(date("Y-m-d", $end)))->createView(), | |
| 77 | + "start" => $start, | |
| 78 | + "end" => $end | |
| 79 | + ); | |
| 69 | 80 | |
| 70 | - $printers = $em->getRepository('CocarBundle:Printer')->findAll(); | |
| 81 | + } | |
| 71 | 82 | |
| 72 | - $printerCounter = array(); | |
| 83 | + /** | |
| 84 | + * Generate a CSV file | |
| 85 | + * | |
| 86 | + * @Route("/csv", name="printer_csv") | |
| 87 | + * | |
| 88 | + */ | |
| 89 | + public function csvAction(Request $request) | |
| 90 | + { | |
| 91 | + ini_set('memory_limit', '1024M'); | |
| 92 | + gc_enable(); | |
| 93 | + | |
| 94 | + $em = $this->getDoctrine()->getManager(); | |
| 95 | + | |
| 96 | + $form = $request->query->get('form'); | |
| 73 | 97 | |
| 74 | - foreach ($printers as $printer) | |
| 98 | + if($form) | |
| 75 | 99 | { |
| 76 | - $printerCounter[$printer->getId()] = $em->createQuery( | |
| 77 | - "SELECT pc.id, pc.prints, pc.blackInk, pc.coloredInk FROM CocarBundle:PrinterCounter pc | |
| 78 | - WHERE (pc.date >= :start AND pc.date <= :end) AND (pc.printer = :id) | |
| 79 | - ORDER BY pc.id ASC" | |
| 80 | - ) | |
| 81 | - ->setParameter('start', $start) | |
| 82 | - ->setParameter('end', $end) | |
| 83 | - ->setParameter('id', $printer->getId()) | |
| 84 | - ->getResult(); | |
| 100 | + $start = new \DateTime($form['startDate']); | |
| 101 | + $start = $start->format('U'); | |
| 102 | + | |
| 103 | + $end = new \DateTime($form['endDate']); | |
| 104 | + $end = $end->format('U'); | |
| 85 | 105 | } |
| 86 | 106 | |
| 87 | - $pCounter = array(); | |
| 107 | + $start = isset($start) ? $start : (time() - ((60*60*24)*30)); | |
| 108 | + $end = isset($end) ? $end : time(); | |
| 109 | + | |
| 110 | + $printers = $em->getRepository('CocarBundle:PrinterCounter')->relatorioCsvGeral($start, $end); | |
| 88 | 111 | |
| 89 | - foreach ($printerCounter as $key => $counter) | |
| 112 | + // Gera CSV | |
| 113 | + $reader = new ArrayReader($printers); | |
| 114 | + | |
| 115 | + // Create the workflow from the reader | |
| 116 | + $workflow = new Workflow($reader); | |
| 117 | + | |
| 118 | + | |
| 119 | + // As you can see, the first names are not capitalized correctly. Let's fix | |
| 120 | + // that with a value converter: | |
| 121 | + //$converter = new CallbackValueConverter(function ($input) { | |
| 122 | + // return date('d/m/Y', $input); | |
| 123 | + //}); | |
| 124 | + //$workflow->addValueConverter('endDate', $converter); | |
| 125 | + //$workflow->addValueConverter('startDate', $converter); | |
| 126 | + | |
| 127 | + // Add the writer to the workflow | |
| 128 | + $tmpfile = tempnam(sys_get_temp_dir(), 'impressoras'); | |
| 129 | + $file = new \SplFileObject($tmpfile, 'w'); | |
| 130 | + $writer = new CsvWriter($file); | |
| 131 | + $workflow->addWriter($writer); | |
| 132 | + | |
| 133 | + // Process the workflow | |
| 134 | + $workflow->process(); | |
| 135 | + | |
| 136 | + // Retorna o arquivo | |
| 137 | + $response = new BinaryFileResponse($tmpfile); | |
| 138 | + $response->headers->set('Content-Type', 'text/csv'); | |
| 139 | + $response->headers->set('Content-Disposition', 'attachment; filename="impressoras.csv"'); | |
| 140 | + $response->headers->set('Content-Transfer-Encoding', 'binary'); | |
| 141 | + | |
| 142 | + return $response; | |
| 143 | + } | |
| 144 | + | |
| 145 | + /** | |
| 146 | + * Lists all Printer entities. | |
| 147 | + * | |
| 148 | + * @Route("/detalhado", name="printer_index_detalhado") | |
| 149 | + * @Method("GET") | |
| 150 | + * @Template() | |
| 151 | + */ | |
| 152 | + public function indexDetalhadoAction(Request $request) | |
| 153 | + { | |
| 154 | + ini_set('memory_limit', '1024M'); | |
| 155 | + gc_enable(); | |
| 156 | + | |
| 157 | + $em = $this->getDoctrine()->getManager(); | |
| 158 | + | |
| 159 | + $form = $request->query->get('form'); | |
| 160 | + | |
| 161 | + if($form) | |
| 90 | 162 | { |
| 91 | - $size = sizeof($counter)-1; | |
| 163 | + $start = new \DateTime($form['startDate']); | |
| 164 | + $start = $start->format('U'); | |
| 92 | 165 | |
| 93 | - if(isset($counter[$size])) | |
| 94 | - { | |
| 95 | - $pCounter[$key]['prints'] = ($size == 0) ? | |
| 96 | - $counter[$size]['prints'] : $counter[$size]['prints'] - $counter[0]['prints']; | |
| 97 | - $pCounter[$key]['blackInk'] = $counter[$size]['blackInk']; | |
| 98 | - $pCounter[$key]['coloredInk'] = $counter[$size]['coloredInk']; | |
| 99 | - } | |
| 166 | + $end = new \DateTime($form['endDate']); | |
| 167 | + $end = $end->format('U'); | |
| 100 | 168 | } |
| 101 | 169 | |
| 102 | - $displayAll = ($request->query->get('all')) ? $request->query->get('all') : 0; | |
| 103 | - */ | |
| 170 | + $start = isset($start) ? $start : (time() - ((60*60*24)*30)); | |
| 171 | + $end = isset($end) ? $end : time(); | |
| 172 | + | |
| 173 | + | |
| 104 | 174 | $displayAll = true; |
| 105 | 175 | |
| 106 | 176 | $printers = $em->getRepository('CocarBundle:PrinterCounter')->relatorioGeral($start, $end); |
| ... | ... | @@ -124,11 +194,14 @@ class PrinterController extends Controller |
| 124 | 194 | /** |
| 125 | 195 | * Generate a CSV file |
| 126 | 196 | * |
| 127 | - * @Route("/csv", name="printer_csv") | |
| 197 | + * @Route("/detalhado/csv", name="printer_csv_detalhado") | |
| 128 | 198 | * |
| 129 | 199 | */ |
| 130 | - public function csvAction(Request $request) | |
| 200 | + public function csvDetalhadoAction(Request $request) | |
| 131 | 201 | { |
| 202 | + ini_set('memory_limit', '1024M'); | |
| 203 | + gc_enable(); | |
| 204 | + | |
| 132 | 205 | $em = $this->getDoctrine()->getManager(); |
| 133 | 206 | |
| 134 | 207 | $form = $request->query->get('form'); |
| ... | ... | @@ -145,7 +218,7 @@ class PrinterController extends Controller |
| 145 | 218 | $start = isset($start) ? $start : (time() - ((60*60*24)*30)); |
| 146 | 219 | $end = isset($end) ? $end : time(); |
| 147 | 220 | |
| 148 | - $printers = $em->getRepository('CocarBundle:PrinterCounter')->relatorioCsvGeral($start, $end); | |
| 221 | + $printers = $em->getRepository('CocarBundle:PrinterCounter')->relatorioCsvGeralDetalhado($start, $end); | |
| 149 | 222 | |
| 150 | 223 | // Gera CSV |
| 151 | 224 | $reader = new ArrayReader($printers); | ... | ... |
Entity/PrinterCounterRepository.php
| ... | ... | @@ -66,6 +66,40 @@ class PrinterCounterRepository extends EntityRepository |
| 66 | 66 | |
| 67 | 67 | |
| 68 | 68 | $_dql = "SELECT printer.id, |
| 69 | + printer.name, | |
| 70 | + printer.host, | |
| 71 | + printer.serie, | |
| 72 | + printer.local, | |
| 73 | + (max(pc1.prints) - min(pc2.prints)) as totalPrints | |
| 74 | + FROM CocarBundle:Printer printer | |
| 75 | + LEFT JOIN CocarBundle:PrinterCounter pc1 WITH (pc1.printer = printer.id AND pc1.date BETWEEN :start AND :end) | |
| 76 | + LEFT JOIN CocarBundle:PrinterCounter pc2 WITH (pc2.printer = printer.id AND pc2.date BETWEEN :start AND :end) | |
| 77 | + GROUP BY printer.id, | |
| 78 | + printer.name, | |
| 79 | + printer.description, | |
| 80 | + printer.host, | |
| 81 | + printer.serie, | |
| 82 | + printer.local | |
| 83 | + ORDER BY printer.id ASC"; | |
| 84 | + | |
| 85 | + return $this->getEntityManager()->createQuery( $_dql ) | |
| 86 | + ->setParameter('start', $start) | |
| 87 | + ->setParameter('end', $end) | |
| 88 | + ->getArrayResult(); | |
| 89 | + | |
| 90 | + } | |
| 91 | + | |
| 92 | + /** | |
| 93 | + * Classe do relatório geral de impressão no formato CSV detalhado | |
| 94 | + * | |
| 95 | + * @param $start | |
| 96 | + * @param $end | |
| 97 | + * @return array | |
| 98 | + */ | |
| 99 | + public function relatorioCsvGeralDetalhado($start, $end) { | |
| 100 | + | |
| 101 | + | |
| 102 | + $_dql = "SELECT printer.id, | |
| 69 | 103 | max(pc1.prints) as printsEnd, |
| 70 | 104 | max(pc1.date) as endDate, |
| 71 | 105 | min(pc2.prints) as printsStart, | ... | ... |
Resources/views/Printer/index.html.twig
| 1 | 1 | {% extends 'CocarBundle::layout.html.twig' %} |
| 2 | 2 | |
| 3 | 3 | {% block main -%} |
| 4 | - <h2 class="general-title">Impressoras cadastradas</h2> | |
| 4 | + <h2 class="general-title">{{ "Impressoras Cadastradas"|trans }}</h2> | |
| 5 | 5 | <center> |
| 6 | 6 | <ul> |
| 7 | 7 | <li> |
| ... | ... | @@ -9,12 +9,28 @@ |
| 9 | 9 | {{ form_errors(form) }} |
| 10 | 10 | {{ form_widget(form.startDate) }} |
| 11 | 11 | {{ form_widget(form.endDate) }} |
| 12 | - <button type="submit">Enviar</button> | |
| 13 | - <button type="submit" formaction="{{ path('printer_csv') }}">Gerar CSV</button> | |
| 12 | + <button type="submit">{{ "Enviar"|trans }}</button> | |
| 13 | + <button type="submit" formaction="{{ path('printer_csv') }}">{{ "Gerar CSV"|trans }}</button> | |
| 14 | + <button type="submit" formaction="{{ path('printer_index_detalhado') }}">{{ "Relatório detalhado"|trans }}</button> | |
| 14 | 15 | </form> |
| 15 | 16 | </li> |
| 16 | 17 | </ul> |
| 17 | 18 | </center> |
| 19 | + <br> | |
| 20 | + <div class="row-fluid"> | |
| 21 | + <div class="span12 flat_box"> | |
| 22 | + <div class="padding_20"> | |
| 23 | + <p>{{ "Relatório de impressão"|trans }}</p> | |
| 24 | + <br> | |
| 25 | + <p> | |
| 26 | + <ul> | |
| 27 | + <li><b>{{ "Data Inicial"|trans }}</b>: {{ start|date }}</li> | |
| 28 | + <li><b>{{ "Data Final"|trans }}</b>: {{ end|date }}</li> | |
| 29 | + </ul> | |
| 30 | + </p> | |
| 31 | + </div> | |
| 32 | + </div> | |
| 33 | + </div> | |
| 18 | 34 | <table class="records_list"> |
| 19 | 35 | <thead> |
| 20 | 36 | <tr> |
| ... | ... | @@ -23,10 +39,6 @@ |
| 23 | 39 | <th>Host</th> |
| 24 | 40 | <th>Serie</th> |
| 25 | 41 | <th>Local</th> |
| 26 | - <th>Contador Inicial</th> | |
| 27 | - <th>Data Inicial</th> | |
| 28 | - <th>Contador Final</th> | |
| 29 | - <th>Data Final</th> | |
| 30 | 42 | <th>Impressões</th> |
| 31 | 43 | <th>Ações</th> |
| 32 | 44 | </tr> |
| ... | ... | @@ -39,18 +51,6 @@ |
| 39 | 51 | <td>{{ entity.host }}</td> |
| 40 | 52 | <td>{{ entity.serie }}</td> |
| 41 | 53 | <td>{{ entity.local }}</td> |
| 42 | - <td>{{ entity.printsStart }}</td> | |
| 43 | - {% if entity.startDate %} | |
| 44 | - <td>{{ entity.startDate|date("d/m/Y") }}</td> | |
| 45 | - {% else %} | |
| 46 | - <td></td> | |
| 47 | - {% endif %} | |
| 48 | - <td>{{ entity.printsEnd }}</td> | |
| 49 | - {% if entity.endDate %} | |
| 50 | - <td>{{ entity.endDate|date("d/m/Y") }}</td> | |
| 51 | - {% else %} | |
| 52 | - <td></td> | |
| 53 | - {% endif %} | |
| 54 | 54 | <td>{{ (entity.printsEnd - entity.printsStart) }}</td> |
| 55 | 55 | <td> |
| 56 | 56 | <ul> |
| ... | ... | @@ -66,16 +66,6 @@ |
| 66 | 66 | {% endfor %} |
| 67 | 67 | </tbody> |
| 68 | 68 | </table> |
| 69 | - {% if displayAll == 0 %} | |
| 70 | - {{ knp_pagination_render(printer, "CocarBundle::pagination.html.twig") }} | |
| 71 | - <div style="padding-top:30px"> | |
| 72 | - <ul class="tsc_paginationB tsc_paginationB09"> | |
| 73 | - <li> | |
| 74 | - <a href="{{ path('printer_index', {all: true}) }}">Visualizar todas as impressoras</a> | |
| 75 | - </li> | |
| 76 | - </ul> | |
| 77 | - </div> | |
| 78 | - {% endif %} | |
| 79 | 69 | <ul class="button"> |
| 80 | 70 | <li> |
| 81 | 71 | <a href="{{ path('printer_new') }}"> | ... | ... |
| ... | ... | @@ -0,0 +1,86 @@ |
| 1 | +{% extends 'CocarBundle::layout.html.twig' %} | |
| 2 | + | |
| 3 | +{% block main -%} | |
| 4 | + <h2 class="general-title">Impressoras cadastradas</h2> | |
| 5 | + <center> | |
| 6 | + <ul> | |
| 7 | + <li> | |
| 8 | + <form action="{{ path('printer_index_detalhado') }}" method="get" {{ form_enctype(form) }}> | |
| 9 | + {{ form_errors(form) }} | |
| 10 | + {{ form_widget(form.startDate) }} | |
| 11 | + {{ form_widget(form.endDate) }} | |
| 12 | + <button type="submit">Enviar</button> | |
| 13 | + <button type="submit" formaction="{{ path('printer_csv_detalhado') }}">Gerar CSV</button> | |
| 14 | + </form> | |
| 15 | + </li> | |
| 16 | + </ul> | |
| 17 | + </center> | |
| 18 | + <table class="records_list"> | |
| 19 | + <thead> | |
| 20 | + <tr> | |
| 21 | + <th>Id</th> | |
| 22 | + <th>Nome</th> | |
| 23 | + <th>Host</th> | |
| 24 | + <th>Serie</th> | |
| 25 | + <th>Local</th> | |
| 26 | + <th>Contador Inicial</th> | |
| 27 | + <th>Data Inicial</th> | |
| 28 | + <th>Contador Final</th> | |
| 29 | + <th>Data Final</th> | |
| 30 | + <th>Impressões</th> | |
| 31 | + <th>Ações</th> | |
| 32 | + </tr> | |
| 33 | + </thead> | |
| 34 | + <tbody> | |
| 35 | + {% for entity in printer %} | |
| 36 | + <tr> | |
| 37 | + <td><a href="{{ path('printer_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td> | |
| 38 | + <td>{{ entity.name }}</td> | |
| 39 | + <td>{{ entity.host }}</td> | |
| 40 | + <td>{{ entity.serie }}</td> | |
| 41 | + <td>{{ entity.local }}</td> | |
| 42 | + <td>{{ entity.printsStart }}</td> | |
| 43 | + {% if entity.startDate %} | |
| 44 | + <td>{{ entity.startDate|date("d/m/Y") }}</td> | |
| 45 | + {% else %} | |
| 46 | + <td></td> | |
| 47 | + {% endif %} | |
| 48 | + <td>{{ entity.printsEnd }}</td> | |
| 49 | + {% if entity.endDate %} | |
| 50 | + <td>{{ entity.endDate|date("d/m/Y") }}</td> | |
| 51 | + {% else %} | |
| 52 | + <td></td> | |
| 53 | + {% endif %} | |
| 54 | + <td>{{ (entity.printsEnd - entity.printsStart) }}</td> | |
| 55 | + <td> | |
| 56 | + <ul> | |
| 57 | + <li> | |
| 58 | + <a href="{{ path('printer_show', { 'id': entity.id }) }}">Visualizar</a> | |
| 59 | + </li> | |
| 60 | + <li> | |
| 61 | + <a href="{{ path('printer_edit', { 'id': entity.id }) }}">Editar</a> | |
| 62 | + </li> | |
| 63 | + </ul> | |
| 64 | + </td> | |
| 65 | + </tr> | |
| 66 | + {% endfor %} | |
| 67 | + </tbody> | |
| 68 | + </table> | |
| 69 | + {% if displayAll == 0 %} | |
| 70 | + {{ knp_pagination_render(printer, "CocarBundle::pagination.html.twig") }} | |
| 71 | + <div style="padding-top:30px"> | |
| 72 | + <ul class="tsc_paginationB tsc_paginationB09"> | |
| 73 | + <li> | |
| 74 | + <a href="{{ path('printer_index', {all: true}) }}">Visualizar todas as impressoras</a> | |
| 75 | + </li> | |
| 76 | + </ul> | |
| 77 | + </div> | |
| 78 | + {% endif %} | |
| 79 | + <ul class="button"> | |
| 80 | + <li> | |
| 81 | + <a href="{{ path('printer_new') }}"> | |
| 82 | + Cadastrar uma nova impressora | |
| 83 | + </a> | |
| 84 | + </li> | |
| 85 | + </ul> | |
| 86 | + {% endblock %} | ... | ... |