Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Erro ao gerar relatório com pdf Boa tarde, estou com um problema que não consigo resolver, pesquisei no forum encontrei algumas soluções e fui acrescentar ao meu código porém sem sucesso, eu estou tentando fazer com que meu cabeçalho seja repetido nas outras páginas do pdf , porém esta dando erro, segue meu código abaixo. ...
AM
Erro ao gerar relatório com pdf  
Boa tarde, estou com um problema que não consigo resolver, pesquisei no forum encontrei algumas soluções e fui acrescentar ao meu código porém sem sucesso, eu estou tentando fazer com que meu cabeçalho seja repetido nas outras páginas do pdf , porém esta dando erro, segue meu código abaixo.
  1. <?php
  2. /**
  3.  * NotasfornecedoresReport Report
  4.  * @author  <Alex>
  5.  */
  6. class NotasfornecedoresReport extends TPage
  7. {
  8.     protected $form// form
  9.     private static $paginas 2;
  10.     /**
  11.      * Class constructor
  12.      * Creates the page and the registration form
  13.      */
  14.     function __construct()
  15.     {
  16.         parent::__construct();
  17.         
  18.         // creates the form
  19.         $this->form = new BootstrapFormBuilder('form_NotasfornecedoresModel_report');
  20.         $this->form->setFormTitle('Relatórios de Notas dos Fornecedores');
  21.         
  22.         
  23.         // create the form fields
  24.         $tbl_NotasEmissao = new TDate('tbl_NotasEmissao');
  25.         $tbl_NotasRecebimento = new TDate('tbl_NotasRecebimento');
  26.         $tbl_NotasValor = new TEntry('tbl_NotasValor');
  27.         //$tbl_classificacao_idtbl_classificacao = new TDBCombo('tbl_classificacao_idtbl_classificacao', 'conexao', 'ClassificacaoModel', 'idtbl_classificacao', 'tbl_classificacaoTipo');
  28.         $tbl_fornecedores_idtbl_Fornecedores = new TDBCombo('tbl_fornecedores_idtbl_Fornecedores''conexao''FornecedoresModel''idtbl_Fornecedores''tbl_FornecedoresNome');
  29.         $tbl_fornecedores_tbl_Empresa_idtbl_Empresa = new TDBCombo('tbl_fornecedores_tbl_Empresa_idtbl_Empresa''conexao''EmpresaModel''idtbl_Empresa''tbl_EmpresaNome');
  30.         $output_type = new TRadioGroup('output_type');
  31.         // add the fields
  32.         $this->form->addFields( [ new TLabel('Data Emissão :') ], [ $tbl_NotasEmissao ] );
  33.         $this->form->addFields( [ new TLabel('Data Recebimento :') ], [ $tbl_NotasRecebimento ] );
  34.         //$this->form->addFields( [ new TLabel('Valor :') ], [ $tbl_NotasValor ] );
  35.         //$this->form->addFields( [ new TLabel('Código da Operação :') ], [ $tbl_classificacao_idtbl_classificacao ] );
  36.         $this->form->addFields( [ new TLabel('Fornecedor :') ], [ $tbl_fornecedores_idtbl_Fornecedores ] );
  37.         $this->form->addFields( [ new TLabel('Empresa :') ], [ $tbl_fornecedores_tbl_Empresa_idtbl_Empresa ] );
  38.         $this->form->addFields( [ new TLabel('Tipo') ], [ $output_type ] );
  39.         $output_type->addValidation('Output', new TRequiredValidator);
  40.         // set sizes
  41.         $tbl_NotasEmissao->setSize('100%');
  42.         $tbl_NotasRecebimento->setSize('100%');
  43.         $tbl_NotasValor->setSize('100%');
  44.        // $tbl_classificacao_idtbl_classificacao->setSize('100%');
  45.         $tbl_fornecedores_idtbl_Fornecedores->setSize('100%');
  46.         $tbl_fornecedores_tbl_Empresa_idtbl_Empresa->setSize('100%');
  47.         $output_type->setSize('100%');
  48.         
  49.         $output_type->addItems(array('html'=>'HTML''pdf'=>'PDF''rtf'=>'RTF''xls' => 'XLS'));
  50.         $output_type->setLayout('horizontal');
  51.         $output_type->setUseButton();
  52.         $output_type->setValue('pdf');
  53.         $output_type->setSize(70);
  54.         
  55.         // add the action button
  56.         $btn $this->form->addAction(_t('Generate'), new TAction(array($this'onGenerate')), 'fa:cog');
  57.         $btn->class 'btn btn-sm btn-primary';
  58.         
  59.         // vertical box container
  60.         $container = new TVBox;
  61.         $container->style 'width: 90%';
  62.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  63.         $container->add($this->form);
  64.         
  65.         parent::add($container);
  66.     }
  67.     public function getNativeWriter() 
  68.     { 
  69.     return $this->pdf
  70.     } 
  71.     
  72.     public function Cabecalho($pdf)
  73. {
  74.          try
  75.         {
  76.             // open a transaction with database 'conexao'
  77.             TTransaction::open('conexao');
  78.             
  79.             // get the form data into an active record
  80.             $data $this->form->getData();
  81.             
  82.             $this->form->validate();
  83.             
  84.             $repository1 = new TRepository('FornecedoresModel');
  85.             $criteria1 = new TCriteria;
  86.             $objectos $repository1->load($criteria1FALSE);
  87.                       
  88.                  foreach ($objectos as $objecto)
  89.                 {
  90.                 $empresa $objecto->empresa_model->tbl_EmpresaNome;
  91.                 }
  92.                 
  93.              // fill the form with the active record data
  94.             $this->form->setData($data);
  95.             
  96.             // close the transaction
  97.             TTransaction::close();
  98.         }
  99.         catch (Exception $e// in case of exception
  100.         {
  101.             // shows the exception error message
  102.             new TMessage('error'$e->getMessage());
  103.             
  104.             // undo all pending operations
  105.             TTransaction::rollback();
  106.         }
  107.     
  108.     $numeroPagina self::$paginas;
  109.         $pdf->SetFont('Arial''I'8);
  110.         // TITULO 
  111.         $pdf->Cell(00"LIVRO FISCAL"00);
  112.         $pdf->Cell(80);
  113.         $pdf->PageNo();
  114.         $pdf->Cell(00, ("FL: {$numeroPagina} /{nb}"), 00'R');
  115.         $pdf->Ln(20);
  116.         $pdf->Cell(00"REGISTRO DE ENTRADAS"00'C');
  117.         $pdf->Ln(20);
  118.         $pdf->Cell(1000, ( "EMPRESA : {$empresa}"), 00);
  119.         // Line break 
  120.         $pdf->Ln(20);
  121.         self::$paginas++;
  122.     
  123. }
  124.    
  125.     /**
  126.      * Generate the report
  127.      */
  128.     function onGenerate()
  129.     {
  130.         try
  131.         {
  132.             // open a transaction with database 'conexao'
  133.             TTransaction::open('conexao');
  134.             
  135.             // get the form data into an active record
  136.             $data $this->form->getData();
  137.             
  138.             $this->form->validate();
  139.             
  140.             
  141.             
  142.             $repository = new TRepository('NotasfornecedoresModel');
  143.             $criteria   = new TCriteria;
  144.             
  145.             if ($data->tbl_NotasEmissao)
  146.             {
  147.                 $criteria->add(new TFilter('tbl_NotasEmissao''like'"%{$data->tbl_NotasEmissao}%"));
  148.             }
  149.             if ($data->tbl_NotasRecebimento)
  150.             {
  151.                 $criteria->add(new TFilter('tbl_NotasRecebimento''like'"%{$data->tbl_NotasRecebimento}%"));
  152.             }
  153.             //if ($data->tbl_NotasValor)
  154.             //{
  155.               //  $criteria->add(new TFilter('tbl_NotasValor', 'like', "%{$data->tbl_NotasValor}%"));
  156.             //}
  157.             //if ($data->tbl_classificacao_idtbl_classificacao)
  158.             //{
  159.               //  $criteria->add(new TFilter('tbl_classificacao_idtbl_classificacao', 'like', "%{$data->tbl_classificacao_idtbl_classificacao}%"));
  160.             //}
  161.             if ($data->tbl_fornecedores_idtbl_Fornecedores)
  162.             {
  163.                 $criteria->add(new TFilter('tbl_fornecedores_idtbl_Fornecedores''like'"%{$data->tbl_fornecedores_idtbl_Fornecedores}%"));
  164.             }
  165.             if ($data->tbl_fornecedores_tbl_Empresa_idtbl_Empresa)
  166.             {
  167.                 $criteria->add(new TFilter('tbl_fornecedores_tbl_Empresa_idtbl_Empresa''like'"%{$data->tbl_fornecedores_tbl_Empresa_idtbl_Empresa}%"));
  168.             }
  169.             
  170.                        
  171.             $objects $repository->load($criteriaFALSE);
  172.             $format  $data->output_type;
  173.             
  174.             if ($objects)
  175.             {
  176.                 $widths = array(50,50,100,100,100,100);
  177.                 
  178.                 switch ($format)
  179.                 {
  180.                     case 'html':
  181.                         $tr = new TTableWriterHTML($widths);
  182.                         
  183.                         break;
  184.                     case 'pdf':
  185.                         $tr = new TTableWriterPDF($widths);
  186.                         $fpdf $tr->getNativeWriter();
  187.                         $fpdf->setHeaderCallback(array($this,'Cabecalho'));
  188.                         $this->Cabecalho($fpdf);
  189.                         break;
  190.                     case 'xls':
  191.                         $tr = new TTableWriterXLS($widths);
  192.                         break;
  193.                     case 'rtf':
  194.                         $tr = new TTableWriterRTF($widths);
  195.                         break;
  196.                 }
  197.                 
  198.                 // create the document styles
  199.                 $tr->addStyle('title',      'Arial''10''B',    '#ffffff''#EA9C98');
  200.                 $tr->addStyle('datap',      'Arial''10''' ,    '#000000''#EEEEEE');
  201.                 $tr->addStyle('datai',      'Arial''10''' ,    '#000000''#ffffff');
  202.                 $tr->addStyle('header',     'Arial''16''' ,    '#ffffff''#904F49');
  203.                 $tr->addStyle('footer',     'Times''10''I',    '#000000''#F2BEBC');
  204.                 
  205.                
  206.                 
  207.                // add a header row
  208.                 $tr->addRow();
  209.                 $tr->addCell(' Registro de Entradas ''center''header'15);
  210.                 
  211.                                               
  212.                 // add titles row
  213.                 $tr->addRow();
  214.                 $tr->addCell('Fornecedor :''center''title',2);
  215.                 $tr->addCell('Data Emissão :''center''title',2);
  216.                 $tr->addCell('Entrada :''center''title',2);
  217.                 $tr->addCell('Valor Contábil :''center''title',2);
  218.                 $tr->addCell('Código da Operação :''center''title',2);
  219.                 
  220.                 
  221.                 
  222.                 // controls the background filling
  223.                 $colourFALSE;
  224.                 $total 0;
  225.                 // data rows
  226.                 foreach ($objects as $object)
  227.                 {
  228.                     
  229.                     $style $colour 'datap' 'datai';
  230.                     $tr->addRow();
  231.                     
  232.                     $tr->addCell($object->fornecedores_model->tbl_FornecedoresNome'left'$style2);
  233.                     $emissao date_parse($object->tbl_NotasEmissao);
  234.                     $emissao str_pad($emissao['day'],2'0' STR_PAD_LEFT).'/'.
  235.                                str_pad($emissao['month'],2'0' STR_PAD_LEFT).'/'.
  236.                                $emissao['year'];
  237.                     $tr->addCell($emissao'center'$style,2);
  238.                     $recebimento date_parse($object->tbl_NotasRecebimento);
  239.                     $recebimento str_pad($recebimento['day'],2'0' STR_PAD_LEFT).'/'.
  240.                                str_pad($recebimento['month'],2'0' STR_PAD_LEFT).'/'.
  241.                                $recebimento['year'];
  242.                     $tr->addCell($recebimento'center'$style,2);
  243.                     $valor = ($object->tbl_NotasValor);
  244.                     $tr->addCell(number_format($valor,2,',','.'),'center'$style,2); 
  245.                     
  246.                     $tr->addCell($object->classificacao_model->tbl_classificacaoCodigo'center'$style,2);           
  247.                     $total += $object->tbl_NotasTotal;
  248.                     
  249.                     $colour = !$colour;
  250.                 }
  251.                 
  252.                
  253.                 
  254.                 $tr->addRow();
  255.                 $tr->addCell('','center','footer');
  256.                 
  257.                 $tr->addRow();
  258.                 $tr->addCell('Total Geral R$:''center''footer',4);
  259.                 $tr->addCell(number_format($total,2,',','.'),'center'$style,4);  
  260.                 
  261.                 
  262.                 // footer row
  263.                 $tr->addRow();
  264.                 $tr->addCell(date('d/m/Y h:i:s'), 'center''footer'10);
  265.                 
  266.                 
  267.                 // stores the file
  268.                 if (!file_exists("app/output/NotasfornecedoresModel.{$format}") OR is_writable("app/output/NotasfornecedoresModel.{$format}"))
  269.                 {
  270.                     $tr->save("app/output/NotasfornecedoresModel.{$format}");
  271.                 }
  272.                 else
  273.                 {
  274.                     throw new Exception(_t('Permission denied') . ': ' "app/output/NotasfornecedoresModel.{$format}");
  275.                 }
  276.                 
  277.                 // open the report file
  278.                 parent::openFile("app/output/NotasfornecedoresModel.{$format}");
  279.                 
  280.                 // shows the success message
  281.                 new TMessage('info''Relatório Gerado.');
  282.             }
  283.             else
  284.             {
  285.                 new TMessage('error''Relatório não gerado pois não teve movimento no periodo solicitado');
  286.             }
  287.     
  288.             // fill the form with the active record data
  289.             $this->form->setData($data);
  290.             
  291.             // close the transaction
  292.             TTransaction::close();
  293.         }
  294.         catch (Exception $e// in case of exception
  295.         {
  296.             // shows the exception error message
  297.             new TMessage('error'$e->getMessage());
  298.             
  299.             // undo all pending operations
  300.             TTransaction::rollback();
  301.         }
  302.     }
  303. }
  304. ?>

este relatório tem que sair assim:
Livro Fiscal FL : pagina

Registro de Saida

Fornecedor Emissao
resultado pagina 1
Livro Fiscal FL : pagina

Registro de Saida

Fornecedor Emissao
resultado pagina 2
e assim sucessivamente só que não estou conseguindo esta me gerando o erro abaixo :
Notice: Undefined offset: 9 in C:xampphtdocsAdiantiProjetosSoftwareLivrosapplibreportsTTableWriterPDF.class.php on line 169

Fatal error: Uncaught Error: Call to a member function addRow() on null in C:xampphtdocsAdiantiProjetosSoftwareLivrosapplibpdfFPDF.php:385 Stack trace: #0 C:xampphtdocsAdiantiProjetosSoftwareLivrosapplibpdfFPDF.php(342): FPDF->Header() #1 C:xampphtdocsAdiantiProjetosSoftwareLivrosapplibpdfFPDF.php(619): FPDF->AddPage('P', Array, 0) #2 C:xampphtdocsAdiantiProjetosSoftwareLivrosapplibreportsTTableWriterPDF.class.php(172): FPDF->Cell(100, 15, 'Fornecedor 2', 1, 0, 'L', true) #3 C:xampphtdocsAdiantiProjetosSoftwareLivrosappcontrolsistemarelatoriosfornecedoresNotasfornecedoresReport.class.php(242): TTableWriterPDF->addCell('Fornecedor 2', 'left', 'datap', 2) #4 [internal function]: NotasfornecedoresReport->onGenerate(Array) #5 C:xampphtdocsAdiantiProjetosSoftwareLivroslibadianticontrolTPage.php(51): call_user_func(Array, Array) #6 C:xampphtdocsAdiantiProjetosSoftwareLivroslibadianticontrolTPage.php(205): AdiantiControlTPage->run() #7 in C:xampphtdocsAdiantiProjetosSoftwareLivrosapplibpdfFPDF.php on line 385

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 (0)