Commit 2b7de230784f91f55a59f074a44bf762777064d3

Authored by gabrielamayoli
1 parent d0db7614
Exists in master and in 1 other branch 3.1

Correção na apresentação do CSV no 'faturamento' e 'sem coletas'. E adição do bo…

…tão para a apresentação do CSV onde é mostrado as máquinas de cada subrede.
src/Cacic/RelatorioBundle/Controller/FaturamentoController.php
... ... @@ -16,7 +16,7 @@
16 16  
17 17 class FaturamentoController extends Controller {
18 18  
19   -
  19 + //Página inicial faturamento
20 20 public function faturamentoAction(Request $request) {
21 21  
22 22 $locale = $request->getLocale();
... ... @@ -30,10 +30,12 @@
30 30 );
31 31 }
32 32  
  33 + //Página que exibe todas as regionais faturamento
33 34 public function faturamentoRelatorioAction(Request $request){
34 35  
35 36 $locale = $request->getLocale();
36 37 $form = $this->createForm( new LogPesquisaType() );
  38 +
37 39 if ( $request->isMethod('POST') )
38 40 {
39 41 $form->bind( $request );
... ... @@ -66,8 +68,53 @@
66 68 );
67 69 }
68 70  
69   - public function listarAction( Request $request, $idRede) {
  71 + //botão csv de todas faturamento
  72 + public function faturamentoCsvAction(Request $request)
  73 + {
  74 + $em = $this->getDoctrine()->getManager();
  75 +
  76 + $form = $this->createForm( new LogPesquisaType() );
  77 +
  78 + $form->bind( $request );
  79 + $data = $form->getData();
  80 + $filtroLocais = array(); // Inicializa array com locais a pesquisar
  81 + foreach ( $data['idLocal'] as $locais ) {
  82 + array_push( $filtroLocais, $locais->getIdLocal() );
  83 + }
  84 +
  85 + $printers = $em->getRepository( 'CacicCommonBundle:LogAcesso')
  86 + ->faturamentoCsv( $data['dtAcaoInicio'], $data['dtAcaoFim'], $filtroLocais);
  87 +
  88 + // Gera CSV
  89 + $reader = new ArrayReader($printers);
  90 +
  91 + // Create the workflow from the reader
  92 + $workflow = new Workflow($reader);
  93 +
  94 + $workflow->addValueConverter("reader",new CharsetValueConverter('UTF-8',$reader));
  95 +
  96 + // Add the writer to the workflow
  97 + $tmpfile = tempnam(sys_get_temp_dir(), 'Faturamento');
  98 + $file = new \SplFileObject($tmpfile, 'w');
  99 + $writer = new CsvWriter($file);
  100 + $writer->writeItem(array('Local', 'Subrede','Endereço IP','Estações'));
  101 + $workflow->addWriter($writer);
  102 +
  103 + // Process the workflow
  104 + $workflow->process();
70 105  
  106 + // Retorna o arquivo
  107 + $response = new BinaryFileResponse($tmpfile);
  108 + $response->headers->set('Content-Type', 'text/csv');
  109 + $response->headers->set('Content-Disposition', 'attachment; filename="Faturamento.csv"');
  110 + $response->headers->set('Content-Transfer-Encoding', 'binary');
  111 +
  112 +
  113 + return $response;
  114 + }
  115 +
  116 + //Página que exibe cada regional faturamento
  117 + public function listarAction( Request $request, $idRede) {
71 118  
72 119 $dataInicio = $request->get('dtAcaoInicio');
73 120 $dataFim = $request->get('dtAcaoFim');
... ... @@ -76,19 +123,25 @@
76 123 $locale = $request->getLocale();
77 124 $dados = $this->getDoctrine()
78 125 ->getRepository('CacicCommonBundle:LogAcesso')
79   - ->gerarRelatorioRede($filtros = array(),$idRede, $dataInicio, $dataFim);
  126 + ->gerarRelatorioRede($filtros = array(),$idRede, $dataInicio, $dataFim);
  127 +
80 128  
81 129 return $this->render(
82 130 'CacicRelatorioBundle:Faturamento:listar.html.twig',
83 131 array(
84 132 'rede'=> $dados[0]['nmRede'],
85 133 'idioma'=> $locale,
86   - 'dados' => $dados
  134 + 'dados' => ( isset( $dados ) ? $dados : null ),
  135 + 'idRede' => $idRede,
  136 + 'dtAcaoInicio' => $dataInicio,
  137 + 'dtAcaoFim' => $dataFim
  138 +
87 139 )
88 140 );
89 141 }
90   - public function listarCsvAction( Request $request) {
91 142  
  143 + //Botão csv cada faturamento
  144 + public function listarCsvAction( Request $request) {
92 145  
93 146 $dataInicio = $request->get('dtAcaoInicio');
94 147 $dataFim = $request->get('dtAcaoFim');
... ... @@ -96,7 +149,7 @@
96 149  
97 150 $printers = $this->getDoctrine()
98 151 ->getRepository('CacicCommonBundle:LogAcesso')
99   - ->listarCsv($filtros = array(), $idRede, $dataInicio, $dataFim);
  152 + ->listarCsv($filtros = array(),$idRede, $dataInicio , $dataFim);
100 153  
101 154  
102 155 // Gera CSV
... ... @@ -105,11 +158,6 @@
105 158 // Create the workflow from the reader
106 159 $workflow = new Workflow($reader);
107 160  
108   -
109   -
110   - // Create the workflow from the reader
111   - $workflow = new Workflow($reader);
112   -
113 161 $workflow->addValueConverter("reader",new CharsetValueConverter('UTF-8',$reader));
114 162  
115 163 // Add the writer to the workflow
... ... @@ -125,11 +173,15 @@
125 173 // Retorna o arquivo
126 174 $response = new BinaryFileResponse($tmpfile);
127 175 $response->headers->set('Content-Type', 'text/csv');
128   - $response->headers->set('Content-Disposition', 'attachment; filename="Faturamento.csv"');
  176 + $response->headers->set('Content-Disposition', 'attachment; filename="Faturamento_subrede.csv"');
129 177 $response->headers->set('Content-Transfer-Encoding', 'binary');
130 178  
131 179 return $response;
  180 +
132 181 }
  182 +
  183 +
  184 + //Página inicial inativos
133 185 public function inativosAction(Request $request) {
134 186  
135 187 $locale = $request->getLocale();
... ... @@ -144,21 +196,20 @@
144 196 );
145 197 }
146 198  
  199 + //Página que exibe todas as regionais inativos
147 200 public function inativosRelatorioAction(Request $request){
148   - $locale = $request->getLocale();
149 201  
  202 + $locale = $request->getLocale();
150 203 $form = $this->createForm( new LogPesquisaType() );
151 204  
152   -
153 205 if ( $request->isMethod('POST') )
154 206 {
155 207 $form->bind( $request );
156 208 $data = $form->getData();
157 209 $filtroLocais = array(); // Inicializa array com locais a pesquisar
158   - foreach ( $data['idLocal'] as $locais ) {
159   - array_push( $filtroLocais, $locais->getIdLocal() );
160   - }
161   -
  210 + foreach ( $data['idLocal'] as $locais ) {
  211 + array_push( $filtroLocais, $locais->getIdLocal() );
  212 + }
162 213  
163 214 $logs = $this->getDoctrine()->getRepository( 'CacicCommonBundle:Computador')
164 215 ->pesquisarInativos( $data['dtAcaoInicio'], $data['dtAcaoFim'], $filtroLocais);
... ... @@ -170,6 +221,7 @@
170 221 }
171 222 }
172 223  
  224 +
173 225 return $this->render( 'CacicRelatorioBundle:Faturamento:inativosResultado.html.twig',
174 226 array(
175 227 'idioma'=> $locale,
... ... @@ -181,6 +233,7 @@
181 233 );
182 234 }
183 235  
  236 + //Página que exibe cada regional inativos
184 237 public function listarInativosAction( Request $request, $idRede) {
185 238  
186 239  
... ... @@ -193,97 +246,62 @@
193 246 ->getRepository('CacicCommonBundle:Computador')
194 247 ->gerarRelatorioRede($filtros = array(),$idRede, $dataInicio, $dataFim);
195 248  
196   - return $this->render(
197   - 'CacicRelatorioBundle:Faturamento:listarInativos.html.twig',
  249 +
  250 + return $this->render( 'CacicRelatorioBundle:Faturamento:listarInativos.html.twig',
198 251 array(
199 252 'rede'=> $dados[0]['nmRede'],
200 253 'idioma'=> $locale,
201   - 'dados' => $dados
  254 + 'dados' => ( isset( $dados ) ? $dados : null ),
  255 + 'idRede' => $idRede,
  256 + 'dtAcaoInicio' => $dataInicio,
  257 + 'dtAcaoFim' => $dataFim
  258 +
202 259 )
203 260 );
204 261 }
205   - public function listarInativosCsvAction( Request $request) {
206 262  
  263 + //botão csv de cada inativos
  264 + public function listarInativosCsvAction ( Request $request) {
207 265  
208 266 $dataInicio = $request->get('dtAcaoInicio');
209 267 $dataFim = $request->get('dtAcaoFim');
210 268 $idRede = $request->get('idRede');
211 269  
212 270 $printers = $this->getDoctrine()
213   - ->getRepository('CacicCommonBundle:Computador')
214   - ->listarInativosCsv($filtros = array(),$idRede, $dataInicio, $dataFim);
  271 + ->getRepository('CacicCommonBundle:Computador')
  272 + ->listarInativosCsv($filtros = array(),$idRede, $dataInicio, $dataFim);
215 273  
216 274  
217   - // Gera CSV
  275 + // Gera CSV
218 276 $reader = new ArrayReader($printers);
219 277  
220   - // Create the workflow from the reader
  278 + // Create the workflow from the reader
221 279 $workflow = new Workflow($reader);
222 280  
223 281 $workflow->addValueConverter("reader",new CharsetValueConverter('UTF-8',$reader));
224 282  
225   - // Add the writer to the workflow
226   - $tmpfile = tempnam(sys_get_temp_dir(), 'Maquinas Sem Coletas');
  283 + // Add the writer to the workflow
  284 + $tmpfile = tempnam(sys_get_temp_dir(), 'Máquinas sem Coletas');
227 285 $file = new \SplFileObject($tmpfile, 'w');
228 286 $writer = new CsvWriter($file);
229   - $writer->writeItem(array('Computador', 'Mac Address','Endereço IP','Sistema Operacional','Local','Subrede','Range IP'));
  287 + $writer->writeItem(array('Computador', 'Mac Address','Endereço IP','Sistema Operacional','Local','Subrede'));
230 288 $workflow->addWriter($writer);
231 289  
232   - // Process the workflow
  290 + // Process the workflow
233 291 $workflow->process();
234 292  
235   - // Retorna o arquivo
  293 + // Retorna o arquivo
236 294 $response = new BinaryFileResponse($tmpfile);
237 295 $response->headers->set('Content-Type', 'text/csv');
238   - $response->headers->set('Content-Disposition', 'attachment; filename="Máquinas Sem Coletas.csv"');
  296 + $response->headers->set('Content-Disposition', 'attachment; filename="Não_Coletadas_subrede.csv"');
239 297 $response->headers->set('Content-Transfer-Encoding', 'binary');
240 298  
241 299 return $response;
242   - }
243   -
244   - public function faturamentoCsvAction(Request $request)
245   - {
246   - $em = $this->getDoctrine()->getManager();
247   -
248   - $form = $this->createForm( new LogPesquisaType() );
249   -
250   - $form->bind( $request );
251   - $data = $form->getData();
252   - $filtroLocais = array(); // Inicializa array com locais a pesquisar
253   - foreach ( $data['idLocal'] as $locais ) {
254   - array_push( $filtroLocais, $locais->getIdLocal() );
255   - }
256   -
257   - $printers = $em->getRepository( 'CacicCommonBundle:LogAcesso')
258   - ->faturamentoCsv( $data['dtAcaoInicio'], $data['dtAcaoFim'], $filtroLocais);
259   -
260   - // Gera CSV
261   - $reader = new ArrayReader($printers);
262   -
263   - // Create the workflow from the reader
264   - $workflow = new Workflow($reader);
265   -
266   - $workflow->addValueConverter("reader",new CharsetValueConverter('UTF-8',$reader));
267   -
268   - // Add the writer to the workflow
269   - $tmpfile = tempnam(sys_get_temp_dir(), 'Faturamento');
270   - $file = new \SplFileObject($tmpfile, 'w');
271   - $writer = new CsvWriter($file);
272   - $writer->writeItem(array('Local', 'Subrede','Endereço IP','Estações'));
273   - $workflow->addWriter($writer);
274   -
275   - // Process the workflow
276   - $workflow->process();
  300 + }
277 301  
278   - // Retorna o arquivo
279   - $response = new BinaryFileResponse($tmpfile);
280   - $response->headers->set('Content-Type', 'text/csv');
281   - $response->headers->set('Content-Disposition', 'attachment; filename="Faturamento.csv"');
282   - $response->headers->set('Content-Transfer-Encoding', 'binary');
283 302  
284   - return $response;
285   - }
286   - public function inativosCsvAction(Request $request)
  303 + // botão csv todos inativo
  304 + public function inativosCsvAction (Request $request)
287 305 {
288 306 $em = $this->getDoctrine()->getManager();
289 307  
... ... @@ -308,7 +326,7 @@
308 326 $workflow->addValueConverter("reader",new CharsetValueConverter('UTF-8',$reader));
309 327  
310 328 // Add the writer to the workflow
311   - $tmpfile = tempnam(sys_get_temp_dir(), 'Não_Coletada');
  329 + $tmpfile = tempnam(sys_get_temp_dir(), 'Máquinas sem Coletas');
312 330 $file = new \SplFileObject($tmpfile, 'w');
313 331 $writer = new CsvWriter($file);
314 332 $writer->writeItem(array('Local', 'Subrede','Endereço IP','Estações'));
... ... @@ -320,7 +338,9 @@
320 338 // Retorna o arquivo
321 339 $response = new BinaryFileResponse($tmpfile);
322 340 $response->headers->set('Content-Type', 'text/csv');
323   - $response->headers->set('Content-Disposition', 'attachment; filename="Não Coletadas.csv"');
  341 + $response->headers->set('Content-Disposition', 'attachment; filename="Não_Coletadas.csv"');
324 342 $response->headers->set('Content-Transfer-Encoding', 'binary');
325   -}
326   -}
  343 +
  344 + return $response;
  345 + }
  346 +}
327 347 \ No newline at end of file
... ...