<commit_before><?php
 namespace Cacic\RelatorioBundle\Controller;
 use Cacic\CommonBundle\Entity\ComputadorColetaRepository;
 use Ddeboer\DataImport\ValueConverter\ArrayValueConverterMap;
 use Ddeboer\DataImport\ValueConverter\CharsetValueConverter;
 use Doctrine\Common\Util\Debug;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Cacic\CommonBundle\Form\Type\LogPesquisaType;
 use Ddeboer\DataImport\Workflow;
 use Ddeboer\DataImport\Reader\ArrayReader;
 use Ddeboer\DataImport\Writer\CsvWriter;
 use Ddeboer\DataImport\ValueConverter\CallbackValueConverter;
 use Symfony\Component\HttpFoundation\BinaryFileResponse;


    class FaturamentoController extends Controller {


        public function faturamentoAction(Request $request) {

            $locale = $request->getLocale();

            $form = $this->createForm( new LogPesquisaType() );
            return $this->render( 'CacicRelatorioBundle:Faturamento:faturamento.html.twig',
                array(
                    'locale'=> $locale,
                    'form' => $form->createView()
                )
            );
        }

        public function faturamentoRelatorioAction(Request $request){

            $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() );
                }


                $logs = $this->getDoctrine()->getRepository( 'CacicCommonBundle:LogAcesso')
                    ->pesquisar( $data['dtAcaoInicio'], $data['dtAcaoFim'], $filtroLocais);

                $TotalnumComp = 0;

                foreach ($logs as $cont  ){
                    $TotalnumComp += $cont['numComp'];
		}

            }

            return $this->render( 'CacicRelatorioBundle:Faturamento:faturamentoResultado.html.twig',
                array(
                    'idioma'=> $locale,
                    'form' => $form->createView(),
                    'data' =>$data,
                    'logs' => ( isset( $logs ) ? $logs : null ),
                    'totalnumcomp' => $TotalnumComp
                )
            );
        }

        public function listarAction( Request $request, $idRede) {


            $dataInicio = $request->get('dtAcaoInicio');
            $dataFim = $request->get('dtAcaoFim');


            $locale = $request->getLocale();
            $dados = $this->getDoctrine()
                ->getRepository('CacicCommonBundle:LogAcesso')
                ->gerarRelatorioRede($filtros = array(),$idRede, $dataInicio, $dataFim);

            return $this->render(
                'CacicRelatorioBundle:Faturamento:listar.html.twig',
                array(
                    'rede'=> $dados[0]['nmRede'],
                    'idioma'=> $locale,
                    'dados' => $dados
                )
            );
        }
        public function listarCsvAction( Request $request) {


            $dataInicio = $request->get('dtAcaoInicio');
            $dataFim = $request->get('dtAcaoFim');
            $idRede = $request->get('idRede');

            $printers = $this->getDoctrine()
                ->getRepository('CacicCommonBundle:LogAcesso')
                ->listarCsv($filtros = array(), $idRede, $dataInicio, $dataFim);


            // Gera CSV
            $reader = new ArrayReader($printers);

            // 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
            $tmpfile = tempnam(sys_get_temp_dir(), 'Faturamento');
            $file = new \SplFileObject($tmpfile, 'w');
            $writer = new CsvWriter($file);
            $writer->writeItem(array('Computador', 'Mac Address','Endereço IP','Sistema Operacional','Local','Subrede','Data/Hora da Última Coleta'));
            $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 inativosAction(Request $request) {

            $locale = $request->getLocale();

            $form = $this->createForm( new LogPesquisaType() );

            return $this->render( 'CacicRelatorioBundle:Faturamento:inativos.html.twig',
                array(
                    'locale'=> $locale,
                    'form' => $form->createView()
                )
            );
        }

        public function inativosRelatorioAction(Request $request){
            $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() );
                }


                $logs = $this->getDoctrine()->getRepository( 'CacicCommonBundle:Computador')
                    ->pesquisarInativos( $data['dtAcaoInicio'], $data['dtAcaoFim'], $filtroLocais);

                $TotalnumComp = 0;

                foreach ($logs as $cont  ){
                    $TotalnumComp = $cont['numComp']+$TotalnumComp;
                }
            }

            return $this->render( 'CacicRelatorioBundle:Faturamento:inativosResultado.html.twig',
                array(
                    'idioma'=> $locale,
                    'form' => $form->createView(),
                    'data' => $data,
                    'totalnumcomp' =>$TotalnumComp,
                    'logs' => ( isset( $logs ) ? $logs : null )
                )
            );
        }

        public function listarInativosAction( Request $request, $idRede) {


            $dataInicio = $request->get('dtAcaoInicio');
            $dataFim = $request->get('dtAcaoFim');


            $locale = $request->getLocale();
            $dados = $this->getDoctrine()
                ->getRepository('CacicCommonBundle:Computador')
                ->gerarRelatorioRede($filtros = array(),$idRede, $dataInicio, $dataFim);

            return $this->render(
                'CacicRelatorioBundle:Faturamento:listarInativos.html.twig',
                array(
                    'rede'=> $dados[0]['nmRede'],
                    'idioma'=> $locale,
                    'dados' => $dados
                )
            );
        }
        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);


            // 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(), 'Maquinas 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'));
            $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="Máquinas Sem Coletas.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)
        {
            $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:Computador')
                ->inativosCsv( $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(), 'Não_Coletada');
            $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="Não Coletadas.csv"');
            $response->headers->set('Content-Transfer-Encoding', 'binary');
}
}
<commit_msg>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.<commit_after><?php
 namespace Cacic\RelatorioBundle\Controller;
 use Cacic\CommonBundle\Entity\ComputadorColetaRepository;
 use Ddeboer\DataImport\ValueConverter\ArrayValueConverterMap;
 use Ddeboer\DataImport\ValueConverter\CharsetValueConverter;
 use Doctrine\Common\Util\Debug;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Cacic\CommonBundle\Form\Type\LogPesquisaType;
 use Ddeboer\DataImport\Workflow;
 use Ddeboer\DataImport\Reader\ArrayReader;
 use Ddeboer\DataImport\Writer\CsvWriter;
 use Ddeboer\DataImport\ValueConverter\CallbackValueConverter;
 use Symfony\Component\HttpFoundation\BinaryFileResponse;


    class FaturamentoController extends Controller {

        //Página inicial faturamento
        public function faturamentoAction(Request $request) {

            $locale = $request->getLocale();

            $form = $this->createForm( new LogPesquisaType() );
            return $this->render( 'CacicRelatorioBundle:Faturamento:faturamento.html.twig',
                array(
                    'locale'=> $locale,
                    'form' => $form->createView()
                )
            );
        }

        //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 );
                $data = $form->getData();
                $filtroLocais = array(); // Inicializa array com locais a pesquisar
                foreach ( $data['idLocal'] as $locais ) {
                    array_push( $filtroLocais, $locais->getIdLocal() );
                }


                $logs = $this->getDoctrine()->getRepository( 'CacicCommonBundle:LogAcesso')
                    ->pesquisar( $data['dtAcaoInicio'], $data['dtAcaoFim'], $filtroLocais);

                $TotalnumComp = 0;

                foreach ($logs as $cont  ){
                    $TotalnumComp += $cont['numComp'];
		}

            }

            return $this->render( 'CacicRelatorioBundle:Faturamento:faturamentoResultado.html.twig',
                array(
                    'idioma'=> $locale,
                    'form' => $form->createView(),
                    'data' =>$data,
                    'logs' => ( isset( $logs ) ? $logs : null ),
                    'totalnumcomp' => $TotalnumComp
                )
            );
        }

        //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');


            $locale = $request->getLocale();
            $dados = $this->getDoctrine()
                ->getRepository('CacicCommonBundle:LogAcesso')
               ->gerarRelatorioRede($filtros = array(),$idRede, $dataInicio, $dataFim);


            return $this->render(
                'CacicRelatorioBundle:Faturamento:listar.html.twig',
                array(
                    'rede'=> $dados[0]['nmRede'],
                    'idioma'=> $locale,
                    'dados' => ( isset( $dados ) ? $dados : null ),
                    'idRede' => $idRede,
                    'dtAcaoInicio' => $dataInicio,
                    'dtAcaoFim' => $dataFim

                )
            );
        }

        //Botão csv cada faturamento
        public function listarCsvAction( Request $request) {

            $dataInicio = $request->get('dtAcaoInicio');
            $dataFim = $request->get('dtAcaoFim');
            $idRede = $request->get('idRede');

            $printers = $this->getDoctrine()
                ->getRepository('CacicCommonBundle:LogAcesso')
                ->listarCsv($filtros = array(),$idRede, $dataInicio , $dataFim);


            // 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('Computador', 'Mac Address','Endereço IP','Sistema Operacional','Local','Subrede','Data/Hora da Última Coleta'));
            $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_subrede.csv"');
            $response->headers->set('Content-Transfer-Encoding', 'binary');

            return $response;

        }


        //Página inicial inativos
        public function inativosAction(Request $request) {

            $locale = $request->getLocale();

            $form = $this->createForm( new LogPesquisaType() );

            return $this->render( 'CacicRelatorioBundle:Faturamento:inativos.html.twig',
                array(
                    'locale'=> $locale,
                    'form' => $form->createView()
                )
            );
        }

        //Página que exibe todas as regionais inativos
        public function inativosRelatorioAction(Request $request){

            $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() );
                 }

                $logs = $this->getDoctrine()->getRepository( 'CacicCommonBundle:Computador')
                    ->pesquisarInativos( $data['dtAcaoInicio'], $data['dtAcaoFim'], $filtroLocais);

                $TotalnumComp = 0;

                foreach ($logs as $cont  ){
                    $TotalnumComp = $cont['numComp']+$TotalnumComp;
                }
            }


            return $this->render( 'CacicRelatorioBundle:Faturamento:inativosResultado.html.twig',
                array(
                    'idioma'=> $locale,
                    'form' => $form->createView(),
                    'data' => $data,
                    'totalnumcomp' =>$TotalnumComp,
                    'logs' => ( isset( $logs ) ? $logs : null )
                )
            );
        }

        //Página que exibe cada regional inativos
        public function listarInativosAction( Request $request, $idRede) {


            $dataInicio = $request->get('dtAcaoInicio');
            $dataFim = $request->get('dtAcaoFim');


            $locale = $request->getLocale();
            $dados = $this->getDoctrine()
                ->getRepository('CacicCommonBundle:Computador')
                ->gerarRelatorioRede($filtros = array(),$idRede, $dataInicio, $dataFim);


            return $this->render( 'CacicRelatorioBundle:Faturamento:listarInativos.html.twig',
                array(
                    'rede'=> $dados[0]['nmRede'],
                    'idioma'=> $locale,
                    'dados' => ( isset( $dados ) ? $dados : null ),
                    'idRede' => $idRede,
                    'dtAcaoInicio' => $dataInicio,
                    'dtAcaoFim' => $dataFim

                )
            );
        }

       //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);


                // 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(), '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'));
            $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="Não_Coletadas_subrede.csv"');
            $response->headers->set('Content-Transfer-Encoding', 'binary');

            return $response;
            }


        // botão csv todos inativo
        public function inativosCsvAction (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:Computador')
                ->inativosCsv( $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(), 'Máquinas sem Coletas');
            $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="Não_Coletadas.csv"');
            $response->headers->set('Content-Transfer-Encoding', 'binary');

            return $response;
        }
}
{'fraction_non_alphanumeric': 0.1357660210990395, 'fraction_numerical': 0.000629822075263738, 'mean_word_length': 1.941755442334414, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 273, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3521461', 'n_tokens_mistral': 7328, 'n_tokens_neox': 6937, 'n_words': 1285}