Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Erro na query para gerar Relatorio ...
IM
Erro na query para gerar Relatorio  
  1. <?php
  2. //<fileHeader>
  3. //</fileHeader>
  4. class RelatorioTabular extends TPage
  5. {
  6.     private $form// form
  7.     private $loaded;
  8.     private static $database 'clinica';
  9.     private static $activeRecord 'Agendamento';
  10.     private static $primaryKey 'id';
  11.     private static $formName 'formReport_Agendamento';
  12.     //<classProperties>
  13.     //</classProperties>
  14.     /**
  15.      * Class constructor
  16.      * Creates the page, the form and the listing
  17.      */
  18.     public function __construct()
  19.     {
  20.         parent::__construct();
  21.         // creates the form
  22.         $this->form = new BootstrapFormBuilder(self::$formName);
  23.         // define the form title
  24.         $this->form->setFormTitle("RelatorioTabular");
  25.         $criteria_unidade_id = new TCriteria();
  26.         $criteria_profissional = new TCriteria();
  27.         $filterVar TSession::getValue("userunitids");
  28.         $criteria_unidade_id->add(new TFilter('id''in'$filterVar)); 
  29.         $filterVar Grupo::PROFISSIONAL;
  30.         $criteria_profissional->add(new TFilter('id''in'"(SELECT pessoa_id FROM pessoa_grupo WHERE grupo_id in  (SELECT id FROM grupo WHERE id = '{$filterVar}') )")); 
  31.         $unidade_id = new TDBCombo('unidade_id''clinica''SystemUnit''id''{name}','name asc' $criteria_unidade_id );
  32.         $profissional = new TDBCombo('profissional''clinica''Pessoa''id''{nome}','nome asc' $criteria_profissional );
  33.         $data_ini = new TDate('data_ini');
  34.         $data_fim = new TDate('data_fim');
  35.         
  36.         
  37.         $data_ini->setDatabaseMask('yyyy-mm-dd');
  38.         $data_fim->setDatabaseMask('yyyy-mm-dd');
  39.         
  40.         $data_ini->setMask('dd/mm/yyyy');
  41.         $data_fim->setMask('dd/mm/yyyy');
  42.         
  43.         $data_ini->setSize(160);
  44.         $data_fim->setSize(160);
  45.         
  46.         $unidade_id->setSize('97%');
  47.         $profissional->setSize('97%');
  48.         $row1 $this->form->addFields([new TLabel("Unidade:"null'14px'null'100%')],[$unidade_id],[new TLabel("Profissional:"null'14px'null)],[$profissional]);
  49.         $row2 $this->form->addFields([new TLabel("Data inicial:"null'14px'null)],[$data_ini],[new TLabel("Data final:"null'14px'null)],[$data_fim]);
  50.         // keep the form filled during navigation with session data
  51.         $this->form->setDataTSession::getValue(__CLASS__.'_filter_data') );
  52.         
  53.         $btn_ongeneratehtml $this->form->addAction("Gerar HTML", new TAction([$this'onGenerateHtml']), 'fa:code #ffffff');
  54.         $btn_ongeneratehtml->addStyleClass('btn-primary'); 
  55.         $btn_ongeneratepdf $this->form->addAction("Gerar PDF", new TAction([$this'onGeneratePdf']), 'fa:file-pdf-o #d44734');
  56.         $btn_ongeneratexls $this->form->addAction("Gerar XLS", new TAction([$this'onGenerateXls']), 'fa:file-excel-o #00a65a');
  57.         $btn_ongeneratertf $this->form->addAction("Gerar RTF", new TAction([$this'onGenerateRtf']), 'fa:file-text-o #324bcc');
  58.         
  59.         // vertical box container
  60.         $container = new TVBox;
  61.         $container->style 'width: 100%';
  62.         $container->add(TBreadCrumb::create(["Gráficos","Gráficos de ajustes"]));
  63.         $container->add($this->form);
  64.         parent::add($container);
  65.     }
  66. //<generated-FormAction-onGenerateHtml>
  67.     public function onGenerateHtml($param null
  68.     {
  69.         $this->onGenerate('html');
  70.     }//</end>
  71. //</generated-FormAction-onGenerateHtml>
  72. //<generated-FormAction-onGeneratePdf>
  73.     public function onGeneratePdf($param null
  74.     {
  75.         $this->onGenerate('pdf');
  76.     }//</end>
  77. //</generated-FormAction-onGeneratePdf>
  78. //<generated-FormAction-onGenerateXls>
  79.     public function onGenerateXls($param null
  80.     {
  81.         $this->onGenerate('xls');
  82.     }//</end>
  83. //</generated-FormAction-onGenerateXls>
  84. //<generated-FormAction-onGenerateRtf>
  85.     public function onGenerateRtf($param null
  86.     {
  87.         $this->onGenerate('rtf');
  88.     }//</end>
  89. //</generated-FormAction-onGenerateRtf>
  90.     /**
  91.      * Register the filter in the session
  92.      */
  93.     public function getFilters()
  94.     {
  95.         // get the search form data
  96.         $data $this->form->getData();
  97.         $filters = [];
  98.         TSession::setValue('filter_data'NULL);
  99.         
  100.         if ($data->unidade_id)
  101.         {
  102.             $filters['unidade_id'] = $data->unidade_id;// create the filter
  103.         };
  104.         if (($data->data_ini !== '') AND ($data->data_fim !== ''))
  105.         {
  106.             $filters['data_ini'] = $data->data_ini;
  107.             $filters['data_fim'] = $data->data_fim;
  108.         }
  109.        
  110.         // fill the form with data again
  111.         $this->form->setData($data);
  112.         // keep the search data in the session
  113.         TSession::setValue('filter_data'$filters);
  114.         
  115.         return $filters;
  116.     }
  117.     public function onGenerate($format)
  118.     {
  119.         try
  120.         {
  121.             $filters $this->getFilters();
  122.             // open a transaction with database 'clinica'
  123.             TTransaction::open('clinica');
  124.             
  125.             $dt_ini $filters['data_ini'];
  126.             $dt_fim $filters['data_fim'];
  127.             $sql "create temporary table a (index (data))
  128.                     SELECT count(id) qtd, date(dt_clinica) as data FROM movto_clinico 
  129.                     where dt_clinica between '$dt_ini' and '$dt_fim' group by dt_clinica;
  130.                     
  131.                     create temporary table b (index (data))
  132.                     SELECT count(id) cad, date(dt_ativacao) as data FROM pessoa
  133.                      where dt_ativacao between '$dt_ini' and '$dt_fim' group by dt_ativacao;
  134.                      
  135.                     create temporary table c (index (data)) 
  136.                      SELECT count(id) age, date(start_time) as data FROM agendamento
  137.                      where date(start_time) between '$dt_ini' and '$dt_fim' group by date(start_time);
  138.                     
  139.                     create temporary table d (index (data))
  140.                      SELECT sum(valorparcial) sum, date(dt_pagamento) as data FROM movto_financeiro
  141.                      where dt_pagamento is not NULL and dt_pagamento between '$dt_ini' and '$dt_fim' group by dt_pagamento;
  142.                      
  143.                     select a.*, b.cad, c.age, d.sum
  144.                          from a left outer join b using (data) left outer join c using (data) left outer join d using (data)";
  145.             $conn TTransaction::get(); 
  146.             $objects $conn->query($sql);
  147.             // load the objects according to criteria
  148.             //$objects = $repository->load($criteria, FALSE);
  149.             if ($objects)
  150.             {
  151.                 $widths = array(200,200,200,200,200,200,200,200);
  152.                 switch ($format)
  153.                 {
  154.                     case 'html':
  155.                         $tr = new TTableWriterHTML($widths);
  156.                         break;
  157.                     case 'xls':
  158.                         $tr = new TTableWriterXLS($widths);
  159.                         break;
  160.                     case 'pdf':
  161.                         $tr = new TTableWriterPDF($widths'L');
  162.                         break;
  163.                     case 'rtf':
  164.                         if (!class_exists('PHPRtfLite_Autoloader'))
  165.                         {
  166.                             PHPRtfLite::registerAutoloader();
  167.                         }
  168.                         $tr = new TTableWriterRTF($widths'L');
  169.                         break;
  170.                 }
  171.                 if (!empty($tr))
  172.                 {
  173.                     // create the document styles
  174.                     $tr->addStyle('title''Helvetica''10''B',   '#000000''#dbdbdb');
  175.                     $tr->addStyle('datap''Arial''10''',    '#333333''#f0f0f0');
  176.                     $tr->addStyle('datai''Arial''10''',    '#333333''#ffffff');
  177.                     $tr->addStyle('header''Helvetica''16''B',   '#5a5a5a''#6B6B6B');
  178.                     $tr->addStyle('footer''Helvetica''10''B',  '#5a5a5a''#A3A3A3');
  179.                     $tr->addStyle('break''Helvetica''10''B',  '#ffffff''#9a9a9a');
  180.                     $tr->addStyle('total''Helvetica''10''I',  '#000000''#c7c7c7');
  181.                     $tr->addStyle('breakTotal''Helvetica''10''I',  '#000000''#c6c8d0');
  182.                     
  183.                     // add titles row
  184.                     $tr->addRow();
  185.                     $tr->addCell("Data"'left''title');
  186.                     $tr->addCell("Quantidade de retorno"'left''title');
  187.                     $tr->addCell("Pacientes novos"'left''title');
  188.                     $tr->addCell("Pessoas atendidas"'left''title');
  189.                     $tr->addCell("Valor recebido"'left''title');
  190.                     $grandTotal = [];
  191.                     $breakTotal = [];
  192.                     $breakValue null;
  193.                     $firstRow true;
  194.                     
  195.                     // controls the background filling
  196.                     $colour false;         
  197.                     
  198.                     while ($linha $objects->fetch(PDO::FETCH_OBJ))
  199.                     {
  200.                         $style $colour 'datap' 'datai';
  201.                         $firstRow false;
  202.                         $tr->addRow();
  203.                         
  204.                         $tr->addCell($object->data'left'$style);
  205.                         $tr->addCell($object->qtd'left'$style);
  206.                         $tr->addCell($object->cad'left'$style);
  207.                         $tr->addCell($object->age'left'$style);
  208.                         $tr->addCell($object->sum'left'$style);
  209.                         $colour = !$colour;
  210.                     };
  211.                     var_dump('ate aqui');
  212.                     $file 'report_'.uniqid().".{$format}";
  213.                     // stores the file
  214.                     if (!file_exists("app/output/{$file}") || is_writable("app/output/{$file}"))
  215.                     {
  216.                         $tr->save("app/output/{$file}");
  217.                     }
  218.                     else
  219.                     {
  220.                         throw new Exception(_t('Permission denied') . ': ' "app/output/{$file}");
  221.                     }
  222.                     parent::openFile("app/output/{$file}");
  223.                     // shows the success message
  224.                     new TMessage('info'_t('Report generated. Please, enable popups'));
  225.                 }
  226.             }
  227.             else
  228.             {
  229.                 new TMessage('error'_t('No records found'));
  230.             }
  231.             // close the transaction
  232.             TTransaction::close();
  233.         }
  234.         catch (Exception $e// in case of exception
  235.         {
  236.             // shows the exception error message
  237.             new TMessage('error'$e->getMessage());
  238.             // undo all pending operations
  239.             TTransaction::rollback();
  240.         }
  241.     }
  242.     public function onShow($param null)
  243.     {
  244.         //<onShow>
  245.         //</onShow>
  246.     }
  247.     //</hideLine> <addUserFunctionsCode/>
  248.     //<userCustomFunctions>
  249.     //</userCustomFunctions>
  250. }
  251. ?>

Pessoal já tentei de tudo e não consigo gerar o relatorio ... dá erro no for each

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (3)


RB

Linha 37, 39 esta estranho ....

37 - $filterVar = TSession::getValue("userunitids");

39 - $filterVar = Grupo::PROFISSIONAL;
IM

problema está o=no while .,.
Linha 229 em diante
RB


  1. <?php
  2. //Tenta tira o ponto e virgula 244
  3. // };
  4. }
  5. ?>