Commit 5fffddc6f8ebebaa19fc9beb50bab4f0b0b3d4e2

Authored by Eduardo Santos
1 parent 847424d3
Exists in master and in 2 other branches 3,1, 3.1

Corrige relatório de impressoras garantindo que o valor retornado seja sempre o …

…apresentado pelo contador.
Controller/PrinterController.php
... ... @@ -20,6 +20,7 @@ use Ddeboer\DataImport\Workflow;
20 20 use Ddeboer\DataImport\Reader\ArrayReader;
21 21 use Ddeboer\DataImport\Writer\CsvWriter;
22 22 use Ddeboer\DataImport\ValueConverter\CallbackValueConverter;
  23 +use Ddeboer\DataImport\ItemConverter\CallbackItemConverter;
23 24  
24 25 use Doctrine\ORM\EntityManager;
25 26 use Symfony\Component\HttpFoundation\StreamedResponse;
... ... @@ -124,6 +125,12 @@ class PrinterController extends Controller
124 125 $workflow = new Workflow($reader);
125 126 $data = new \DateTime();
126 127  
  128 + // Contador geral das impressorasa
  129 + $converter = new CallbackItemConverter(function ($item) {
  130 + $item['totalPrints'] = $item['printsEnd'] - $item['printsStart'];
  131 + return $item;
  132 + });
  133 + $workflow->addItemConverter($converter);
127 134  
128 135 // As you can see, the first names are not capitalized correctly. Let's fix
129 136 // that with a value converter:
... ... @@ -240,6 +247,12 @@ class PrinterController extends Controller
240 247 // Create the workflow from the reader
241 248 $workflow = new Workflow($reader);
242 249  
  250 + // Contador geral das impressorasa
  251 + $converter = new CallbackItemConverter(function ($item) {
  252 + $item['totalPrints'] = $item['printsEnd'] - $item['printsStart'];
  253 + return $item;
  254 + });
  255 + $workflow->addItemConverter($converter);
243 256  
244 257 // As you can see, the first names are not capitalized correctly. Let's fix
245 258 // that with a value converter:
... ...
Entity/PrinterCounterRepository.php
... ... @@ -27,9 +27,9 @@ class PrinterCounterRepository extends EntityRepository
27 27 pc1.blackInk,
28 28 pc1.coloredInk,
29 29 max(pc1.date) as endDate,
30   - max(pc1.prints) as printsEnd,
31   - min(pc2.date) as startDate,
32   - min(pc2.prints) as printsStart,
  30 + (SELECT pc2.prints FROM CocarBundle:PrinterCounter pc2 WHERE pc2.date = max(pc1.date) AND pc2.printer = printer.id) as printsEnd,
  31 + min(pc1.date) as startDate,
  32 + (SELECT pc3.prints FROM CocarBundle:PrinterCounter pc3 WHERE pc3.date = min(pc1.date) AND pc3.printer = printer.id) as printsStart,
33 33 printer.name,
34 34 printer.description,
35 35 printer.serie,
... ... @@ -37,7 +37,6 @@ class PrinterCounterRepository extends EntityRepository
37 37 printer.host
38 38 FROM CocarBundle:Printer printer
39 39 LEFT JOIN CocarBundle:PrinterCounter pc1 WITH (pc1.printer = printer.id AND pc1.date BETWEEN :start AND :end)
40   - LEFT JOIN CocarBundle:PrinterCounter pc2 WITH (pc2.printer = printer.id AND pc2.date BETWEEN :start AND :end)
41 40 GROUP BY printer.id,
42 41 pc1.blackInk,
43 42 pc1.coloredInk,
... ... @@ -70,12 +69,10 @@ class PrinterCounterRepository extends EntityRepository
70 69 printer.host,
71 70 printer.serie,
72 71 printer.local,
73   - max(pc1.prints) as printsEnd,
74   - min(pc2.prints) as printsStart,
75   - (max(pc1.prints) - min(pc2.prints)) as totalPrints
  72 + (SELECT pc2.prints FROM CocarBundle:PrinterCounter pc2 WHERE pc2.date = max(pc1.date) AND pc2.printer = printer.id) as printsEnd,
  73 + (SELECT pc3.prints FROM CocarBundle:PrinterCounter pc3 WHERE pc3.date = min(pc1.date) AND pc3.printer = printer.id) as printsStart
76 74 FROM CocarBundle:Printer printer
77 75 LEFT JOIN CocarBundle:PrinterCounter pc1 WITH (pc1.printer = printer.id AND pc1.date BETWEEN :start AND :end)
78   - LEFT JOIN CocarBundle:PrinterCounter pc2 WITH (pc2.printer = printer.id AND pc2.date BETWEEN :start AND :end)
79 76 GROUP BY printer.id,
80 77 printer.name,
81 78 printer.description,
... ... @@ -102,18 +99,16 @@ class PrinterCounterRepository extends EntityRepository
102 99  
103 100  
104 101 $_dql = "SELECT printer.id,
105   - max(pc1.prints) as printsEnd,
106 102 max(pc1.date) as endDate,
107   - min(pc2.prints) as printsStart,
108   - min(pc2.date) as startDate,
  103 + (SELECT pc2.prints FROM CocarBundle:PrinterCounter pc2 WHERE pc2.date = max(pc1.date) AND pc2.printer = printer.id) as printsEnd,
  104 + min(pc1.date) as startDate,
  105 + (SELECT pc3.prints FROM CocarBundle:PrinterCounter pc3 WHERE pc3.date = min(pc1.date) AND pc3.printer = printer.id) as printsStart,
109 106 printer.name,
110 107 printer.host,
111 108 printer.serie,
112   - printer.local,
113   - (max(pc1.prints) - min(pc2.prints)) as totalPrints
  109 + printer.local
114 110 FROM CocarBundle:Printer printer
115 111 LEFT JOIN CocarBundle:PrinterCounter pc1 WITH (pc1.printer = printer.id AND pc1.date BETWEEN :start AND :end)
116   - LEFT JOIN CocarBundle:PrinterCounter pc2 WITH (pc2.printer = printer.id AND pc2.date BETWEEN :start AND :end)
117 112 GROUP BY printer.id,
118 113 printer.name,
119 114 printer.description,
... ...
Resources/views/Printer/index.html.twig
... ... @@ -39,11 +39,8 @@
39 39 <th>Host</th>
40 40 <th>Serie</th>
41 41 <th>Local</th>
42   -<<<<<<< HEAD
43   -=======
44 42 <th>Contador Inicial</th>
45 43 <th>Contador Final</th>
46   ->>>>>>> d4656e0e44b6f43d88cea85fd3ca4cd16f0e76fd
47 44 <th>Impressões</th>
48 45 <th>Ações</th>
49 46 </tr>
... ...