Commit f68f0fb5ccfd20b1eab9f9740bb3017cf0e16967

Authored by Bruno Noronha
1 parent b94227af
Exists in master and in 1 other branch 3.1

filtros csv

src/Cacic/RelatorioBundle/Controller/FaturamentoController.php
... ... @@ -41,6 +41,7 @@
41 41 {
42 42 $form->bind( $request );
43 43 $data = $form->getData();
  44 +
44 45 $filtroLocais = array(); // Inicializa array com locais a pesquisar
45 46 foreach ( $data['idLocal'] as $locais ) {
46 47 array_push( $filtroLocais, $locais->getIdLocal() );
... ... @@ -73,16 +74,65 @@
73 74 public function faturamentoCsvAction(Request $request)
74 75 {
75 76  
  77 + $locale = $request->getLocale();
  78 + $form = $this->createForm( new LogPesquisaType() );
  79 +
  80 + if ( $request->isMethod('POST') )
  81 + {
  82 + $form->bind( $request );
  83 + $data = $form->getData();
  84 +
  85 + $filtroLocais = array(); // Inicializa array com locais a pesquisar
  86 + foreach ( $data['idLocal'] as $locais ) {
  87 + array_push( $filtroLocais, $locais->getIdLocal() );
  88 + }
  89 +
  90 + $printers = $this->getDoctrine()->getRepository( 'CacicCommonBundle:LogAcesso')
  91 + ->faturamentoCsv( $data['dtAcaoInicio'], $data['dtAcaoFim'], $filtroLocais);
  92 +
  93 + }
  94 +
  95 + // Gera CSV
  96 + $reader = new ArrayReader($printers);
  97 +
  98 + // Create the workflow from the reader
  99 + $workflow = new Workflow($reader);
  100 +
  101 + $workflow->addValueConverter("reader",new CharsetValueConverter('UTF-8',$reader));
  102 +
  103 + // Add the writer to the workflow
  104 + $tmpfile = tempnam(sys_get_temp_dir(), 'Faturamento');
  105 + $file = new \SplFileObject($tmpfile, 'w');
  106 + $writer = new CsvWriter($file);
  107 + $writer->writeItem(array('Local', 'Subrede','Endereço IP','Estações'));
  108 + $workflow->addWriter($writer);
  109 +
  110 + // Process the workflow
  111 + $workflow->process();
  112 +
  113 + // Retorna o arquivo
  114 + $response = new BinaryFileResponse($tmpfile);
  115 + $response->headers->set('Content-Type', 'text/csv');
  116 + $response->headers->set('Content-Disposition', 'attachment; filename="Faturamento.csv"');
  117 + $response->headers->set('Content-Transfer-Encoding', 'binary');
  118 +
  119 +
  120 + return $response;
  121 + }
  122 +
  123 + //botão csv de todas faturamento
  124 + public function faturamentoCsvInternoAction(Request $request)
  125 + {
  126 +
76 127 $dataInicio = $request->get('dtAcaoInicio');
77 128 $dataFim = $request->get('dtAcaoFim');
  129 + $idLocal = $_POST;
78 130  
79   - $filtroLocais = $_POST;
80   -
81   - foreach ( $filtroLocais as $locais ) {
  131 + foreach ( $idLocal as $locais ) {
82 132 }
83 133  
84 134 $printers = $this->getDoctrine()->getRepository( 'CacicCommonBundle:LogAcesso')
85   - ->faturamentoCsv( $dataInicio, $dataFim, $filtroLocais);
  135 + ->faturamentoCsv( $dataInicio, $dataFim, $locais);
86 136  
87 137 // Gera CSV
88 138 $reader = new ArrayReader($printers);
... ...