Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Imprimir Data Início e Data Fim no Relatório Tabular Boa noite Dev's estou tentando imprimir no relatório pdf a data inicio e data fim que coloco no formulário para pesquisar dados. Mas esta aparecendo assim no relatório tabular: " Data Início: ci/in/data Data Fim: /fi/data " Abaixo código usado para mostrar as datas. ...
PC
Imprimir Data Início e Data Fim no Relatório Tabular  
Boa noite Dev's estou tentando imprimir no relatório pdf a data inicio e data fim que coloco no formulário para pesquisar dados. Mas esta aparecendo assim no relatório tabular:
" Data Início: ci/in/data Data Fim: /fi/data "
Abaixo código usado para mostrar as datas.

  1. <?php
  2. $table->addRow();
  3. $table->addCell('Data Início: '.TDate::date2br('data_inicio').'  Data Fim: '.TDate::date2br('data_fim'), 'center','title'4);
  4. ?>

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (13)


LC

Documentação do comando:
https://www.adianti.com.br/api-framework-widget-form-TDate#date2br

Passe como parametro a data no formato ano-mes-dia (yyyy-mm-dd)
TDate::date2br('2020-03-05')
PC

Luiz Coelho, quando coloco números da certo (2020-03-05), mas quando é variável não aparece a data_inicio que esta no formulário e nem a data_fim e sim o seguinte erro. Data Início: ci/in/data Data Fim: m/_f/$dat

  1. <?php
  2. class RelatorioUnidadeMensal extends TPage
  3. {
  4.     private $form// form
  5.     
  6.     /**
  7.      * Class constructor
  8.      * Creates the page and the registration form
  9.      */
  10.     function __construct()
  11.     {
  12.         parent::__construct();
  13.         
  14.         // creates the form
  15.         $this->form = new BootstrapFormBuilder('form_RelatorioUnidadeMensal_report');
  16.         $this->form->setFormTitle'Relatório Mensal da Unidade' );
  17.         
  18.         $data_inicio = new TDate('data_inicio');
  19.         $data_fim = new TDate('data_fim');
  20.         
  21.         $tipo_conta_id = new TDBCombo('tipo_conta_id''gecon''TipoConta''id''descricao');
  22.         $unidade_id = new TDBCombo('unidade_id''gecon''Unidade''id''numero');
  23.               
  24.         // create the form fields
  25.         $this->form->addFields( [ new TLabel('Data Início''red') ], [ $data_inicio] ,
  26.                                 [ new TLabel('Data Fim''red') ], [ $data_fim ] );         
  27.         $this->form->addFields( [ new TLabel('Tipo Conta') ], [ $tipo_conta_id ] ,
  28.                                 [ new TLabel('Unidade') ], [ $unidade_id]);
  29.                                 
  30.         //set Mask
  31.         $data_inicio->setMask('dd/mm/yyyy');
  32.         $data_fim->setMask('dd/mm/yyyy');
  33.         
  34.         $output_type  = new TRadioGroup('output_type');
  35.         $this->form->addFields( [new TLabel('Mostrar em:')],   [$output_type] );
  36.         
  37.         // define field properties
  38.         $output_type->setUseButton();
  39.         $options = ['html' =>'HTML''pdf' =>'PDF''rtf' =>'RTF''xls' =>'XLS'];
  40.         $output_type->addItems($options);
  41.         $output_type->setValue('pdf');
  42.         $output_type->setLayout('horizontal');
  43.         
  44.         $this->form->addAction'Gerar Relatório', new TAction(array($this'onGenerate')), 'fa:download blue');
  45.         
  46.         // wrap the page content using vertical box
  47.         $vbox = new TVBox;
  48.         $vbox->style 'width: 100%';
  49.         // $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  50.         $vbox->add($this->form);
  51.         
  52.         parent::add($vbox);      
  53. }
  54.     /**
  55.      * method onGenerate()
  56.      * Executed whenever the user clicks at the generate button
  57.      */
  58.     function onGenerate()
  59.     {
  60.         try
  61.         {
  62.             // get the form data into an active record Customer
  63.             $data $this->form->getData();
  64.             $this->form->setData($data);
  65.             
  66.             $format $data->output_type;
  67.             
  68.             // open a transaction with database ''
  69.             $source TTransaction::open('gecon');
  70.                         
  71.             // define the query
  72.             $query =   'SELECT unidade.numero, tipo_conta.descricao, unidade.areaUtil, condominio_lancamento.valor, (unidade.areaUtil * condominio_lancamento.valor) AS Total
  73.                         FROM unidade, tipo_conta, condominio_lancamento 
  74.                         WHERE condominio_lancamento.valor > 0
  75.                         AND tipo_conta.id = condominio_lancamento.tipo_conta_id
  76.                         AND condominio_lancamento.data_lancamento BETWEEN :data_inicio AND :data_fim ';
  77.             /*                                
  78.             if ( !empty($data->data_lancamento ) )
  79.             {
  80.                 $query .= " and data_lancamento >= '" . DateTime::createFromFormat('d/m/Y', $data->data_lancamento )->format( 'Y-m-d' ) ."' ";
  81.             }
  82.              */            
  83.             if ( !empty($data->tipo_conta_id) )
  84.             {
  85.                 $query .= " and condominio_lancamento.tipo_conta_id = {$data->tipo_conta_id}";
  86.             }
  87.             
  88.             if ( !empty($data->unidade_id) )
  89.             {
  90.                 $query .= " and unidade.id = {$data->unidade_id}";
  91.             }       
  92.                   
  93.             $filters = [];
  94.             $filters['data_inicio'] = TDate::date2us($data->data_inicio);
  95.             $filters['data_fim'] = TDate::date2us($data->data_fim);            
  96.                         
  97.             $data TDatabase::getData($source$querynull$filters );
  98.             
  99.             if ($data)
  100.             {
  101.                 $widths = [200,200,200,200,200];
  102.                 
  103.                 switch ($format)
  104.                 {
  105.                     case 'html':
  106.                         $table = new TTableWriterHTML($widths);
  107.                         break;
  108.                     case 'pdf':
  109.                         $table = new TTableWriterPDF($widths);
  110.                         break;
  111.                     case 'rtf':
  112.                         $table = new TTableWriterRTF($widths);
  113.                         break;
  114.                     case 'xls':
  115.                         $table = new TTableWriterXLS($widths);
  116.                         break;
  117.                 }
  118.                 
  119.                 if (!empty($table))
  120.                 {
  121.                     // create the document styles
  122.                     $table->addStyle('header''Helvetica''16''B''#ffffff''#4B8E57');
  123.                     $table->addStyle('title',  'Helvetica''10''B''#ffffff''#6CC361');
  124.                     $table->addStyle('datap',  'Helvetica''10''',  '#000000''#E3E3E3''LR');
  125.                     $table->addStyle('datai',  'Helvetica''10''',  '#000000''#ffffff''LR');
  126.                     $table->addStyle('footer''Helvetica''10''',  '#2B2B2B''#B5FFB4');
  127.                     
  128.                     $table->setHeaderCallback( function($table) {
  129.                         $table->addRow();
  130.                         $table->addCell('Relatorio Condomínio Lançamento''center''header'4);
  131.                         
  132.                         $table->addRow();
  133.                         $table->addCell('Data Início: '.TDate::date2br('data_inicio').' Data Fim: '.TDate::date2br('data_fim'), 'center','title'4);
  134.                         $table->addRow();
  135.                         $table->addCell('Unidade''center''title');
  136.                         $table->addCell('Tipo Conta''center''title');
  137.                         $table->addCell('Valor''center''title');
  138.                         $table->addCell('Total''center''title');
  139.                     });
  140.                     
  141.                     $table->setFooterCallback( function($table) {                        
  142.                         $table->addRow();                                            
  143.                         $table->addCell(date('d/m/Y h:i:s'), 'center''footer'4);                        
  144.                     });                    
  145.                     
  146.                     // controls the background filling
  147.                     $colourFALSE;                    
  148.                     $ValorTotal 0;
  149.                     
  150.                     // data rows
  151.                     foreach ($data as $row)
  152.                     {                       
  153.                         $style $colour 'datap' 'datai';
  154.                         
  155.                         $table->addRow();
  156.                         $table->addCell($row['numero'], 'left'$style);
  157.                         $table->addCell($row['descricao'], 'left'$style);
  158.                         $table->addCell($row['valor'], 'rigth'$style);
  159.                         $table->addCell(number_format($row['Total'],2,',','.'), 'rigth'$style);                        
  160.                         
  161.                         $ValorTotal += $row['Total'];
  162.                         
  163.                         $colour = !$colour;
  164.                     }
  165.                     $table->addRow();
  166.                     $table->addCell('Valor Total: ''left''footer'1);
  167.                     $table->addCell(number_format($ValorTotal,2,',','.'), 'rigth''footer'3);
  168.                     
  169.                     $output "app/output/tabular.{$format}";
  170.                     
  171.                     // stores the file
  172.                     if (!file_exists($output) OR is_writable($output))
  173.                     {
  174.                         $table->save($output);
  175.                         parent::openFile($output);
  176.                     }
  177.                     else
  178.                     {
  179.                         throw new Exception(_t('Permission denied') . ': ' $output);
  180.                     }
  181.                     
  182.                     // shows the success message
  183.                     new TMessage('info''Relatório gerado. Por favor, ative popups no navegador.');
  184.                 }
  185.             }
  186.             else
  187.             {
  188.                 new TMessage('error''Registros não encontrado');
  189.             }
  190.     
  191.             // close the transaction
  192.             TTransaction::close();
  193.         }
  194.         catch (Exception $e// in case of exception
  195.         {
  196.             new TMessage('error'$e->getMessage());
  197.             TTransaction::rollback();
  198.         }
  199.     }
  200. ?>
LC

Desta forma: TDate::date2br('data_inicio') você esta passando uma uma string e não uma data.
Tente:
TDate::date2br( $data->data_inicio );
PC

Leandro Coelho, já tinha colocado $data->data_inicio </> mas aparece Notice abaixo:

Notice: Undefined variable: data in /var/www/html/gecon/app/control/gecon/relatorios/RelatorioUnidadeMensal.php on line 144

Notice: Trying to get property 'data_inicio' of non-object in /var/www/html/gecon/app/control/gecon/relatorios/RelatorioUnidadeMensal.php on line 144
LC

Esta linha no incio recebe os dados da tela e joga em $data
$data = $this->form->getData();

Essa linha recebe os dados da consulta do banco e também joga em $data, isso mata os dados recebidos acima
$data = TDatabase::getData($source, $query, null, $filters );

Depois desta linha vc fica sem os dados recebidos da tela

Muda estas linhas:
$rows = TDatabase::getData($source, $query, null, $filters );
foreach ($rows as $row)
PC

Fiz alterações sugeridas, mas ainda nada de pegar a data do formulário.
PC

Pega este valor:

Data Início: 06pm31pm_373372020-03-06T17:37:57-03:00372020
LC

Coloca seu código ai pra eu ver como ficou
PC

Amigo Leandro, abaixo o código completo.

  1. <?php
  2. class RelatorioUnidadeMensal extends TPage
  3. {
  4.     private $form// form
  5.     
  6.     /**
  7.      * Class constructor
  8.      * Creates the page and the registration form
  9.      */
  10.     function __construct()
  11.     {
  12.         parent::__construct();
  13.         
  14.         // creates the form
  15.         $this->form = new BootstrapFormBuilder('form_RelatorioUnidadeMensal_report');
  16.         $this->form->setFormTitle'Relatório Mensal da Unidade' );
  17.         
  18.         $data_inicio = new TDate('data_inicio');
  19.         $data_fim = new TDate('data_fim');
  20.         
  21.         $tipo_conta_id = new TDBCombo('tipo_conta_id''gecon''TipoConta''id''descricao');
  22.         $unidade_id = new TDBCombo('unidade_id''gecon''Unidade''id''numero');
  23.               
  24.         // create the form fields
  25.         $this->form->addFields( [ new TLabel('Data Início''red') ], [ $data_inicio] ,
  26.                                 [ new TLabel('Data Fim''red') ], [ $data_fim ] );         
  27.         $this->form->addFields( [ new TLabel('Tipo Conta') ], [ $tipo_conta_id ] ,
  28.                                 [ new TLabel('Unidade') ], [ $unidade_id]);
  29.                                 
  30.         //set Mask
  31.         $data_inicio->setMask('dd/mm/yyyy');
  32.         $data_fim->setMask('dd/mm/yyyy');
  33.         
  34.         $output_type  = new TRadioGroup('output_type');
  35.         $this->form->addFields( [new TLabel('Mostrar em:')],   [$output_type] );
  36.         
  37.         // define field properties
  38.         $output_type->setUseButton();
  39.         $options = ['html' =>'HTML''pdf' =>'PDF''rtf' =>'RTF''xls' =>'XLS'];
  40.         $output_type->addItems($options);
  41.         $output_type->setValue('pdf');
  42.         $output_type->setLayout('horizontal');
  43.         
  44.         $this->form->addAction'Gerar Relatório', new TAction(array($this'onGenerate')), 'fa:download blue');
  45.         
  46.         // wrap the page content using vertical box
  47.         $vbox = new TVBox;
  48.         $vbox->style 'width: 100%';
  49.         // $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  50.         $vbox->add($this->form);
  51.         
  52.         parent::add($vbox);      
  53. }
  54.     /**
  55.      * method onGenerate()
  56.      * Executed whenever the user clicks at the generate button
  57.      */
  58.     function onGenerate()
  59.     {
  60.         try
  61.         {
  62.             // get the form data into an active record Customer
  63.             $data $this->form->getData();
  64.             $this->form->setData($data);
  65.             
  66.             $format $data->output_type;
  67.             
  68.             // open a transaction with database ''
  69.             $source TTransaction::open('gecon');
  70.                         
  71.             // define the query
  72.             $query =   'SELECT unidade.numero, tipo_conta.descricao, unidade.areaUtil, condominio_lancamento.valor, (unidade.areaUtil * condominio_lancamento.valor) AS Total
  73.                         FROM unidade, tipo_conta, condominio_lancamento 
  74.                         WHERE condominio_lancamento.valor > 0
  75.                         AND tipo_conta.id = condominio_lancamento.tipo_conta_id
  76.                         AND condominio_lancamento.data_lancamento BETWEEN :data_inicio AND :data_fim ';
  77.                                  
  78.             if ( !empty($data->tipo_conta_id) )
  79.             {
  80.                 $query .= " and condominio_lancamento.tipo_conta_id = {$data->tipo_conta_id}";
  81.             }
  82.             
  83.             if ( !empty($data->unidade_id) )
  84.             {
  85.                 $query .= " and unidade.id = {$data->unidade_id}";
  86.             }
  87.                   
  88.             $filters = [];
  89.             $filters['data_inicio'] = TDate::date2us($data->data_inicio);
  90.             $filters['data_fim'] = TDate::date2us($data->data_fim);            
  91.                         
  92.             $rows TDatabase::getData($source$querynull$filters );
  93.             
  94.             if ($data)
  95.             {
  96.                 $widths = [200,200,200,200,200];
  97.                 
  98.                 switch ($format)
  99.                 {
  100.                     case 'html':
  101.                         $table = new TTableWriterHTML($widths);
  102.                         break;
  103.                     case 'pdf':
  104.                         $table = new TTableWriterPDF($widths);
  105.                         break;
  106.                     case 'rtf':
  107.                         $table = new TTableWriterRTF($widths);
  108.                         break;
  109.                     case 'xls':
  110.                         $table = new TTableWriterXLS($widths);
  111.                         break;
  112.                 }
  113.                 
  114.                 if (!empty($table))
  115.                 {
  116.                     // create the document styles
  117.                     $table->addStyle('header''Helvetica''16''B''#ffffff''#4B8E57');
  118.                     $table->addStyle('title',  'Helvetica''10''B''#ffffff''#6CC361');
  119.                     $table->addStyle('datap',  'Helvetica''10''',  '#000000''#E3E3E3''LR');
  120.                     $table->addStyle('datai',  'Helvetica''10''',  '#000000''#ffffff''LR');
  121.                     $table->addStyle('footer''Helvetica''10''',  '#2B2B2B''#B5FFB4');
  122.                     
  123.                     $table->setHeaderCallback( function($table) {
  124.                         $table->addRow();
  125.                         $table->addCell('Relatorio Condomínio Lançamento''center''header'4);
  126.                          
  127.                         $table->addRow();
  128.                         $table->addCell('Data Início: '.date('data_inicio').' - Data Fim: '.date('data_fim'), 'center','title'4);
  129.                         
  130.                         $table->addRow();
  131.                         $table->addCell('Unidade''center''title');
  132.                         $table->addCell('Tipo Conta''center''title');
  133.                         $table->addCell('Valor''center''title');
  134.                         $table->addCell('Total''center''title');
  135.                     });
  136.                     
  137.                     $table->setFooterCallback( function($table) {                        
  138.                         $table->addRow();                                            
  139.                         $table->addCell(date('d/m/Y h:i:s'), 'center''footer'4);                        
  140.                     });                    
  141.                     
  142.                     // controls the background filling
  143.                     $colourFALSE;                    
  144.                     
  145.                     $ValorTotal 0;
  146.                     
  147.                     // data rows
  148.                     foreach ($rows as $row)
  149.                     {                       
  150.                         $style $colour 'datap' 'datai';
  151.                         
  152.                         $table->addRow();
  153.                         $table->addCell($row['numero'], 'left'$style);
  154.                         $table->addCell($row['descricao'], 'left'$style);
  155.                         $table->addCell($row['valor'], 'rigth'$style);
  156.                         $table->addCell(number_format($row['Total'],2,',','.'), 'rigth'$style);
  157.                         
  158.                         $ValorTotal += $row['Total'];
  159.                         
  160.                         $colour = !$colour;
  161.                     }
  162.                     
  163.                     $table->addRow();
  164.                     $table->addCell('Valor Total: ''left''footer'1);
  165.                     $table->addCell(number_format($ValorTotal,2,',','.'), 'rigth''footer'3);
  166.                     
  167.                     $output "app/output/tabular.{$format}";
  168.                     
  169.                     // stores the file
  170.                     if (!file_exists($output) OR is_writable($output))
  171.                     {
  172.                         $table->save($output);
  173.                         parent::openFile($output);
  174.                     }
  175.                     else
  176.                     {
  177.                         throw new Exception(_t('Permission denied') . ': ' $output);
  178.                     }
  179.                     
  180.                     // shows the success message
  181.                     new TMessage('info''Relatório gerado. Por favor, ative popups no navegador.');
  182.                 }
  183.             }
  184.             else
  185.             {
  186.                 new TMessage('error''Registros não encontrado');
  187.             }
  188.     
  189.             // close the transaction
  190.             TTransaction::close();
  191.         }
  192.         catch (Exception $e// in case of exception
  193.         {
  194.             new TMessage('error'$e->getMessage());
  195.             TTransaction::rollback();
  196.         }
  197.     }
  198. }
  199. ?>
LC

Troca essa linha:
  1. <?php
  2. if ($data)
  3. ?>

por:
  1. <?php
  2. if ($rows)
  3. ?>


Troca essa linha:
  1. <?php
  2. $table->addCell('Data Início: '.date('data_inicio').' - Data Fim: '.date('data_fim'), 'center','title'4);
  3. ?>

por:
  1. <?php
  2. $table->addCell('Data Início: ' $data->data_inicio ' - Data Fim: ' $data->data_fim'center','title'4);
  3. ?>

PC

No formulário do relatório aparece assim na Data:
Data Início: - Data Fim:

No Form aparece estes erros:

Notice: Undefined variable: data in /var/www/html/gecon/app/control/gecon/relatorios/RelatorioUnidadeMensal.php on line 139
Notice: Trying to get property 'data_inicio' of non-object in /var/www/html/gecon/app/control/gecon/relatorios/RelatorioUnidadeMensal.php on line 139

Notice: Undefined variable: data in /var/www/html/gecon/app/control/gecon/relatorios/RelatorioUnidadeMensal.php on line 139
Notice: Trying to get property 'data_fim' of non-object in /var/www/html/gecon/app/control/gecon/relatorios/RelatorioUnidadeMensal.php on line 139
LC

A função não consegue acessar o $data->data_inicio , pq no caso ela fica fora do onGenerate, é mais ou menos isso, rsrsrs.

Faz assim, no incio da classe, onde tem:
private $form; // form
Adicione uma linha abaixo, como esta:
protected $data;

Ai no onGenerate, vc vai trocar todos os $data, assim:
$data
para:
$this->data
PC

Leandro Coelho, show meu irmão. Deu certo. Grato pela contribuição. Espero um dia retornar para a comunidade.

Código correto.

  1. <?php
  2. class RelatorioUnidadeMensal extends TPage
  3. {
  4.     private $form// form
  5.     protected $data;
  6.     
  7.     /**
  8.      * Class constructor
  9.      * Creates the page and the registration form
  10.      */
  11.     function __construct()
  12.     {
  13.         parent::__construct();
  14.         
  15.         // creates the form
  16.         $this->form = new BootstrapFormBuilder('form_RelatorioUnidadeMensal_report');
  17.         $this->form->setFormTitle'Relatório Mensal da Unidade' );
  18.         
  19.         $data_inicio = new TDate('data_inicio');
  20.         $data_fim = new TDate('data_fim');
  21.         
  22.         $tipo_conta_id = new TDBCombo('tipo_conta_id''gecon''TipoConta''id''descricao');
  23.         $unidade_id = new TDBCombo('unidade_id''gecon''Unidade''id''numero');
  24.               
  25.         // create the form fields
  26.         $this->form->addFields( [ new TLabel('Data Início''red') ], [ $data_inicio] ,
  27.                                 [ new TLabel('Data Fim''red') ], [ $data_fim ] );         
  28.         $this->form->addFields( [ new TLabel('Tipo Conta') ], [ $tipo_conta_id ] ,
  29.                                 [ new TLabel('Unidade') ], [ $unidade_id]);
  30.                                 
  31.         //set Mask
  32.         $data_inicio->setMask('dd/mm/yyyy');
  33.         $data_fim->setMask('dd/mm/yyyy');
  34.         
  35.         $output_type  = new TRadioGroup('output_type');
  36.         $this->form->addFields( [new TLabel('Mostrar em:')],   [$output_type] );
  37.         
  38.         // define field properties
  39.         $output_type->setUseButton();
  40.         $options = ['html' =>'HTML''pdf' =>'PDF''rtf' =>'RTF''xls' =>'XLS'];
  41.         $output_type->addItems($options);
  42.         $output_type->setValue('pdf');
  43.         $output_type->setLayout('horizontal');
  44.         
  45.         $this->form->addAction'Gerar Relatório', new TAction(array($this'onGenerate')), 'fa:download blue');
  46.         
  47.         // wrap the page content using vertical box
  48.         $vbox = new TVBox;
  49.         $vbox->style 'width: 100%';
  50.         // $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  51.         $vbox->add($this->form);
  52.         
  53.         parent::add($vbox);      
  54. }
  55.     /**
  56.      * method onGenerate()
  57.      * Executed whenever the user clicks at the generate button
  58.      */
  59.     function onGenerate()
  60.     {
  61.         try
  62.         {
  63.             // get the form data into an active record Customer
  64.             $this->data $this->form->getData();
  65.             $this->form->setData($this->data);
  66.             
  67.             $format $this->data->output_type;
  68.             
  69.             // open a transaction with database ''
  70.             $source TTransaction::open('gecon');
  71.                         
  72.             // define the query
  73.             $query =   'SELECT unidade.numero, tipo_conta.descricao, unidade.areaUtil, condominio_lancamento.valor, (unidade.areaUtil * condominio_lancamento.valor) AS Total
  74.                         FROM unidade, tipo_conta, condominio_lancamento 
  75.                         WHERE condominio_lancamento.valor > 0
  76.                         AND tipo_conta.id = condominio_lancamento.tipo_conta_id
  77.                         AND condominio_lancamento.data_lancamento BETWEEN :data_inicio AND :data_fim ';
  78.                                            
  79.             if ( !empty($this->data->tipo_conta_id) )
  80.             {
  81.                 $query .= " and condominio_lancamento.tipo_conta_id = {$data->tipo_conta_id}";
  82.             }
  83.             
  84.             if ( !empty($this->data->unidade_id) )
  85.             {
  86.                 $query .= " and unidade.id = {$data->unidade_id}";
  87.             }
  88.                   
  89.             $filters = [];
  90.             $filters['data_inicio'] = TDate::date2us($this->data->data_inicio);
  91.             $filters['data_fim'] = TDate::date2us($this->data->data_fim);            
  92.                         
  93.             $rows TDatabase::getData($source$querynull$filters );
  94.             
  95.             if ($rows)
  96.             {
  97.                 $widths = [200,200,200,200,200];
  98.                 
  99.                 switch ($format)
  100.                 {
  101.                     case 'html':
  102.                         $table = new TTableWriterHTML($widths);
  103.                         break;
  104.                     case 'pdf':
  105.                         $table = new TTableWriterPDF($widths);
  106.                         break;
  107.                     case 'rtf':
  108.                         $table = new TTableWriterRTF($widths);
  109.                         break;
  110.                     case 'xls':
  111.                         $table = new TTableWriterXLS($widths);
  112.                         break;
  113.                 }
  114.                 
  115.                 if (!empty($table))
  116.                 {
  117.                     // create the document styles
  118.                     $table->addStyle('header''Helvetica''16''B''#ffffff''#4B8E57');
  119.                     $table->addStyle('title',  'Helvetica''10''B''#ffffff''#6CC361');
  120.                     $table->addStyle('datap',  'Helvetica''10''',  '#000000''#E3E3E3''LR');
  121.                     $table->addStyle('datai',  'Helvetica''10''',  '#000000''#ffffff''LR');
  122.                     $table->addStyle('footer''Helvetica''10''',  '#2B2B2B''#B5FFB4');
  123.                     
  124.                     $table->setHeaderCallback( function($table) {
  125.                         $table->addRow();
  126.                         $table->addCell('Relatorio Condomínio Lançamento''center''header'4);
  127.                         
  128.                         
  129.                          
  130.                         $table->addRow();
  131.                         $table->addCell('Data Início: ' $this->data->data_inicio ' - Data Fim: ' $this->data->data_fim'center','title'4);
  132.                         //$table->addCell('Data Início: '.date('data_inicio').' - Data Fim: '.date('data_fim'), 'center','title', 4);
  133.                         
  134.                         $table->addRow();
  135.                         $table->addCell('Unidade''center''title');
  136.                         $table->addCell('Tipo Conta''center''title');
  137.                         $table->addCell('Valor''center''title');
  138.                         $table->addCell('Total''center''title');
  139.                     });
  140.                     
  141.                     $table->setFooterCallback( function($table) {                        
  142.                         $table->addRow();                                            
  143.                         $table->addCell(date('d/m/Y h:i:s'), 'center''footer'4);                        
  144.                     });                    
  145.                     
  146.                     // controls the background filling
  147.                     $colourFALSE;                    
  148.                     
  149.                     $ValorTotal 0;
  150.                     
  151.                     // data rows
  152.                     foreach ($rows as $row)
  153.                     {                       
  154.                         $style $colour 'datap' 'datai';
  155.                         
  156.                         $table->addRow();
  157.                         $table->addCell($row['numero'], 'left'$style);
  158.                         $table->addCell($row['descricao'], 'left'$style);
  159.                         $table->addCell($row['valor'], 'rigth'$style);
  160.                         $table->addCell(number_format($row['Total'],2,',','.'), 'rigth'$style);
  161.                         
  162.                         $ValorTotal += $row['Total'];
  163.                         
  164.                         $colour = !$colour;
  165.                     }
  166.                     
  167.                     $table->addRow();
  168.                     $table->addCell('Valor Total: ''left''footer'1);
  169.                     $table->addCell(number_format($ValorTotal,2,',','.'), 'rigth''footer'3);
  170.                     
  171.                     $output "app/output/tabular.{$format}";
  172.                     
  173.                     // stores the file
  174.                     if (!file_exists($output) OR is_writable($output))
  175.                     {
  176.                         $table->save($output);
  177.                         parent::openFile($output);
  178.                     }
  179.                     else
  180.                     {
  181.                         throw new Exception(_t('Permission denied') . ': ' $output);
  182.                     }
  183.                     
  184.                     // shows the success message
  185.                     new TMessage('info''Relatório gerado. Por favor, ative popups no navegador.');
  186.                 }
  187.             }
  188.             else
  189.             {
  190.                 new TMessage('error''Registros não encontrado');
  191.             }
  192.     
  193.             // close the transaction
  194.             TTransaction::close();
  195.         }
  196.         catch (Exception $e// in case of exception
  197.         {
  198.             new TMessage('error'$e->getMessage());
  199.             TTransaction::rollback();
  200.         }
  201.     }
  202. }
  203. ?>