From 2b7de230784f91f55a59f074a44bf762777064d3 Mon Sep 17 00:00:00 2001 From: gabrielamayoli Date: Tue, 15 Jul 2014 11:32:27 -0300 Subject: [PATCH] Correção na apresentação do CSV no 'faturamento' e 'sem coletas'. E adição do botão para a apresentação do CSV onde é mostrado as máquinas de cada subrede. --- src/Cacic/RelatorioBundle/Controller/FaturamentoController.php | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------- 1 file changed, 99 insertions(+), 79 deletions(-) diff --git a/src/Cacic/RelatorioBundle/Controller/FaturamentoController.php b/src/Cacic/RelatorioBundle/Controller/FaturamentoController.php index ff9b29e..ce734f2 100755 --- a/src/Cacic/RelatorioBundle/Controller/FaturamentoController.php +++ b/src/Cacic/RelatorioBundle/Controller/FaturamentoController.php @@ -16,7 +16,7 @@ class FaturamentoController extends Controller { - + //Página inicial faturamento public function faturamentoAction(Request $request) { $locale = $request->getLocale(); @@ -30,10 +30,12 @@ ); } + //Página que exibe todas as regionais faturamento public function faturamentoRelatorioAction(Request $request){ $locale = $request->getLocale(); $form = $this->createForm( new LogPesquisaType() ); + if ( $request->isMethod('POST') ) { $form->bind( $request ); @@ -66,8 +68,53 @@ ); } - public function listarAction( Request $request, $idRede) { + //botão csv de todas faturamento + public function faturamentoCsvAction(Request $request) + { + $em = $this->getDoctrine()->getManager(); + + $form = $this->createForm( new LogPesquisaType() ); + + $form->bind( $request ); + $data = $form->getData(); + $filtroLocais = array(); // Inicializa array com locais a pesquisar + foreach ( $data['idLocal'] as $locais ) { + array_push( $filtroLocais, $locais->getIdLocal() ); + } + + $printers = $em->getRepository( 'CacicCommonBundle:LogAcesso') + ->faturamentoCsv( $data['dtAcaoInicio'], $data['dtAcaoFim'], $filtroLocais); + + // Gera CSV + $reader = new ArrayReader($printers); + + // Create the workflow from the reader + $workflow = new Workflow($reader); + + $workflow->addValueConverter("reader",new CharsetValueConverter('UTF-8',$reader)); + + // Add the writer to the workflow + $tmpfile = tempnam(sys_get_temp_dir(), 'Faturamento'); + $file = new \SplFileObject($tmpfile, 'w'); + $writer = new CsvWriter($file); + $writer->writeItem(array('Local', 'Subrede','Endereço IP','Estações')); + $workflow->addWriter($writer); + + // Process the workflow + $workflow->process(); + // Retorna o arquivo + $response = new BinaryFileResponse($tmpfile); + $response->headers->set('Content-Type', 'text/csv'); + $response->headers->set('Content-Disposition', 'attachment; filename="Faturamento.csv"'); + $response->headers->set('Content-Transfer-Encoding', 'binary'); + + + return $response; + } + + //Página que exibe cada regional faturamento + public function listarAction( Request $request, $idRede) { $dataInicio = $request->get('dtAcaoInicio'); $dataFim = $request->get('dtAcaoFim'); @@ -76,19 +123,25 @@ $locale = $request->getLocale(); $dados = $this->getDoctrine() ->getRepository('CacicCommonBundle:LogAcesso') - ->gerarRelatorioRede($filtros = array(),$idRede, $dataInicio, $dataFim); + ->gerarRelatorioRede($filtros = array(),$idRede, $dataInicio, $dataFim); + return $this->render( 'CacicRelatorioBundle:Faturamento:listar.html.twig', array( 'rede'=> $dados[0]['nmRede'], 'idioma'=> $locale, - 'dados' => $dados + 'dados' => ( isset( $dados ) ? $dados : null ), + 'idRede' => $idRede, + 'dtAcaoInicio' => $dataInicio, + 'dtAcaoFim' => $dataFim + ) ); } - public function listarCsvAction( Request $request) { + //Botão csv cada faturamento + public function listarCsvAction( Request $request) { $dataInicio = $request->get('dtAcaoInicio'); $dataFim = $request->get('dtAcaoFim'); @@ -96,7 +149,7 @@ $printers = $this->getDoctrine() ->getRepository('CacicCommonBundle:LogAcesso') - ->listarCsv($filtros = array(), $idRede, $dataInicio, $dataFim); + ->listarCsv($filtros = array(),$idRede, $dataInicio , $dataFim); // Gera CSV @@ -105,11 +158,6 @@ // Create the workflow from the reader $workflow = new Workflow($reader); - - - // Create the workflow from the reader - $workflow = new Workflow($reader); - $workflow->addValueConverter("reader",new CharsetValueConverter('UTF-8',$reader)); // Add the writer to the workflow @@ -125,11 +173,15 @@ // Retorna o arquivo $response = new BinaryFileResponse($tmpfile); $response->headers->set('Content-Type', 'text/csv'); - $response->headers->set('Content-Disposition', 'attachment; filename="Faturamento.csv"'); + $response->headers->set('Content-Disposition', 'attachment; filename="Faturamento_subrede.csv"'); $response->headers->set('Content-Transfer-Encoding', 'binary'); return $response; + } + + + //Página inicial inativos public function inativosAction(Request $request) { $locale = $request->getLocale(); @@ -144,21 +196,20 @@ ); } + //Página que exibe todas as regionais inativos public function inativosRelatorioAction(Request $request){ - $locale = $request->getLocale(); + $locale = $request->getLocale(); $form = $this->createForm( new LogPesquisaType() ); - if ( $request->isMethod('POST') ) { $form->bind( $request ); $data = $form->getData(); $filtroLocais = array(); // Inicializa array com locais a pesquisar - foreach ( $data['idLocal'] as $locais ) { - array_push( $filtroLocais, $locais->getIdLocal() ); - } - + foreach ( $data['idLocal'] as $locais ) { + array_push( $filtroLocais, $locais->getIdLocal() ); + } $logs = $this->getDoctrine()->getRepository( 'CacicCommonBundle:Computador') ->pesquisarInativos( $data['dtAcaoInicio'], $data['dtAcaoFim'], $filtroLocais); @@ -170,6 +221,7 @@ } } + return $this->render( 'CacicRelatorioBundle:Faturamento:inativosResultado.html.twig', array( 'idioma'=> $locale, @@ -181,6 +233,7 @@ ); } + //Página que exibe cada regional inativos public function listarInativosAction( Request $request, $idRede) { @@ -193,97 +246,62 @@ ->getRepository('CacicCommonBundle:Computador') ->gerarRelatorioRede($filtros = array(),$idRede, $dataInicio, $dataFim); - return $this->render( - 'CacicRelatorioBundle:Faturamento:listarInativos.html.twig', + + return $this->render( 'CacicRelatorioBundle:Faturamento:listarInativos.html.twig', array( 'rede'=> $dados[0]['nmRede'], 'idioma'=> $locale, - 'dados' => $dados + 'dados' => ( isset( $dados ) ? $dados : null ), + 'idRede' => $idRede, + 'dtAcaoInicio' => $dataInicio, + 'dtAcaoFim' => $dataFim + ) ); } - public function listarInativosCsvAction( Request $request) { + //botão csv de cada inativos + public function listarInativosCsvAction ( Request $request) { $dataInicio = $request->get('dtAcaoInicio'); $dataFim = $request->get('dtAcaoFim'); $idRede = $request->get('idRede'); $printers = $this->getDoctrine() - ->getRepository('CacicCommonBundle:Computador') - ->listarInativosCsv($filtros = array(),$idRede, $dataInicio, $dataFim); + ->getRepository('CacicCommonBundle:Computador') + ->listarInativosCsv($filtros = array(),$idRede, $dataInicio, $dataFim); - // Gera CSV + // Gera CSV $reader = new ArrayReader($printers); - // Create the workflow from the reader + // Create the workflow from the reader $workflow = new Workflow($reader); $workflow->addValueConverter("reader",new CharsetValueConverter('UTF-8',$reader)); - // Add the writer to the workflow - $tmpfile = tempnam(sys_get_temp_dir(), 'Maquinas Sem Coletas'); + // Add the writer to the workflow + $tmpfile = tempnam(sys_get_temp_dir(), 'Máquinas sem Coletas'); $file = new \SplFileObject($tmpfile, 'w'); $writer = new CsvWriter($file); - $writer->writeItem(array('Computador', 'Mac Address','Endereço IP','Sistema Operacional','Local','Subrede','Range IP')); + $writer->writeItem(array('Computador', 'Mac Address','Endereço IP','Sistema Operacional','Local','Subrede')); $workflow->addWriter($writer); - // Process the workflow + // Process the workflow $workflow->process(); - // Retorna o arquivo + // Retorna o arquivo $response = new BinaryFileResponse($tmpfile); $response->headers->set('Content-Type', 'text/csv'); - $response->headers->set('Content-Disposition', 'attachment; filename="Máquinas Sem Coletas.csv"'); + $response->headers->set('Content-Disposition', 'attachment; filename="Não_Coletadas_subrede.csv"'); $response->headers->set('Content-Transfer-Encoding', 'binary'); return $response; - } - - public function faturamentoCsvAction(Request $request) - { - $em = $this->getDoctrine()->getManager(); - - $form = $this->createForm( new LogPesquisaType() ); - - $form->bind( $request ); - $data = $form->getData(); - $filtroLocais = array(); // Inicializa array com locais a pesquisar - foreach ( $data['idLocal'] as $locais ) { - array_push( $filtroLocais, $locais->getIdLocal() ); - } - - $printers = $em->getRepository( 'CacicCommonBundle:LogAcesso') - ->faturamentoCsv( $data['dtAcaoInicio'], $data['dtAcaoFim'], $filtroLocais); - - // Gera CSV - $reader = new ArrayReader($printers); - - // Create the workflow from the reader - $workflow = new Workflow($reader); - - $workflow->addValueConverter("reader",new CharsetValueConverter('UTF-8',$reader)); - - // Add the writer to the workflow - $tmpfile = tempnam(sys_get_temp_dir(), 'Faturamento'); - $file = new \SplFileObject($tmpfile, 'w'); - $writer = new CsvWriter($file); - $writer->writeItem(array('Local', 'Subrede','Endereço IP','Estações')); - $workflow->addWriter($writer); - - // Process the workflow - $workflow->process(); + } - // Retorna o arquivo - $response = new BinaryFileResponse($tmpfile); - $response->headers->set('Content-Type', 'text/csv'); - $response->headers->set('Content-Disposition', 'attachment; filename="Faturamento.csv"'); - $response->headers->set('Content-Transfer-Encoding', 'binary'); - return $response; - } - public function inativosCsvAction(Request $request) + // botão csv todos inativo + public function inativosCsvAction (Request $request) { $em = $this->getDoctrine()->getManager(); @@ -308,7 +326,7 @@ $workflow->addValueConverter("reader",new CharsetValueConverter('UTF-8',$reader)); // Add the writer to the workflow - $tmpfile = tempnam(sys_get_temp_dir(), 'Não_Coletada'); + $tmpfile = tempnam(sys_get_temp_dir(), 'Máquinas sem Coletas'); $file = new \SplFileObject($tmpfile, 'w'); $writer = new CsvWriter($file); $writer->writeItem(array('Local', 'Subrede','Endereço IP','Estações')); @@ -320,7 +338,9 @@ // Retorna o arquivo $response = new BinaryFileResponse($tmpfile); $response->headers->set('Content-Type', 'text/csv'); - $response->headers->set('Content-Disposition', 'attachment; filename="Não Coletadas.csv"'); + $response->headers->set('Content-Disposition', 'attachment; filename="Não_Coletadas.csv"'); $response->headers->set('Content-Transfer-Encoding', 'binary'); -} -} + + return $response; + } +} \ No newline at end of file -- libgit2 0.21.2