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,6 +20,7 @@ use Ddeboer\DataImport\Workflow;
20 use Ddeboer\DataImport\Reader\ArrayReader; 20 use Ddeboer\DataImport\Reader\ArrayReader;
21 use Ddeboer\DataImport\Writer\CsvWriter; 21 use Ddeboer\DataImport\Writer\CsvWriter;
22 use Ddeboer\DataImport\ValueConverter\CallbackValueConverter; 22 use Ddeboer\DataImport\ValueConverter\CallbackValueConverter;
  23 +use Ddeboer\DataImport\ItemConverter\CallbackItemConverter;
23 24
24 use Doctrine\ORM\EntityManager; 25 use Doctrine\ORM\EntityManager;
25 use Symfony\Component\HttpFoundation\StreamedResponse; 26 use Symfony\Component\HttpFoundation\StreamedResponse;
@@ -124,6 +125,12 @@ class PrinterController extends Controller @@ -124,6 +125,12 @@ class PrinterController extends Controller
124 $workflow = new Workflow($reader); 125 $workflow = new Workflow($reader);
125 $data = new \DateTime(); 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 // As you can see, the first names are not capitalized correctly. Let's fix 135 // As you can see, the first names are not capitalized correctly. Let's fix
129 // that with a value converter: 136 // that with a value converter:
@@ -240,6 +247,12 @@ class PrinterController extends Controller @@ -240,6 +247,12 @@ class PrinterController extends Controller
240 // Create the workflow from the reader 247 // Create the workflow from the reader
241 $workflow = new Workflow($reader); 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 // As you can see, the first names are not capitalized correctly. Let's fix 257 // As you can see, the first names are not capitalized correctly. Let's fix
245 // that with a value converter: 258 // that with a value converter:
Entity/PrinterCounterRepository.php
@@ -27,9 +27,9 @@ class PrinterCounterRepository extends EntityRepository @@ -27,9 +27,9 @@ class PrinterCounterRepository extends EntityRepository
27 pc1.blackInk, 27 pc1.blackInk,
28 pc1.coloredInk, 28 pc1.coloredInk,
29 max(pc1.date) as endDate, 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 printer.name, 33 printer.name,
34 printer.description, 34 printer.description,
35 printer.serie, 35 printer.serie,
@@ -37,7 +37,6 @@ class PrinterCounterRepository extends EntityRepository @@ -37,7 +37,6 @@ class PrinterCounterRepository extends EntityRepository
37 printer.host 37 printer.host
38 FROM CocarBundle:Printer printer 38 FROM CocarBundle:Printer printer
39 LEFT JOIN CocarBundle:PrinterCounter pc1 WITH (pc1.printer = printer.id AND pc1.date BETWEEN :start AND :end) 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 GROUP BY printer.id, 40 GROUP BY printer.id,
42 pc1.blackInk, 41 pc1.blackInk,
43 pc1.coloredInk, 42 pc1.coloredInk,
@@ -70,12 +69,10 @@ class PrinterCounterRepository extends EntityRepository @@ -70,12 +69,10 @@ class PrinterCounterRepository extends EntityRepository
70 printer.host, 69 printer.host,
71 printer.serie, 70 printer.serie,
72 printer.local, 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 FROM CocarBundle:Printer printer 74 FROM CocarBundle:Printer printer
77 LEFT JOIN CocarBundle:PrinterCounter pc1 WITH (pc1.printer = printer.id AND pc1.date BETWEEN :start AND :end) 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 GROUP BY printer.id, 76 GROUP BY printer.id,
80 printer.name, 77 printer.name,
81 printer.description, 78 printer.description,
@@ -102,18 +99,16 @@ class PrinterCounterRepository extends EntityRepository @@ -102,18 +99,16 @@ class PrinterCounterRepository extends EntityRepository
102 99
103 100
104 $_dql = "SELECT printer.id, 101 $_dql = "SELECT printer.id,
105 - max(pc1.prints) as printsEnd,  
106 max(pc1.date) as endDate, 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 printer.name, 106 printer.name,
110 printer.host, 107 printer.host,
111 printer.serie, 108 printer.serie,
112 - printer.local,  
113 - (max(pc1.prints) - min(pc2.prints)) as totalPrints 109 + printer.local
114 FROM CocarBundle:Printer printer 110 FROM CocarBundle:Printer printer
115 LEFT JOIN CocarBundle:PrinterCounter pc1 WITH (pc1.printer = printer.id AND pc1.date BETWEEN :start AND :end) 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 GROUP BY printer.id, 112 GROUP BY printer.id,
118 printer.name, 113 printer.name,
119 printer.description, 114 printer.description,
Resources/views/Printer/index.html.twig
@@ -39,11 +39,8 @@ @@ -39,11 +39,8 @@
39 <th>Host</th> 39 <th>Host</th>
40 <th>Serie</th> 40 <th>Serie</th>
41 <th>Local</th> 41 <th>Local</th>
42 -<<<<<<< HEAD  
43 -=======  
44 <th>Contador Inicial</th> 42 <th>Contador Inicial</th>
45 <th>Contador Final</th> 43 <th>Contador Final</th>
46 ->>>>>>> d4656e0e44b6f43d88cea85fd3ca4cd16f0e76fd  
47 <th>Impressões</th> 44 <th>Impressões</th>
48 <th>Ações</th> 45 <th>Ações</th>
49 </tr> 46 </tr>