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.
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
- <?php
- /**
- * NotasfornecedoresReport Report
- * @author <Alex>
- */
- class NotasfornecedoresReport extends TPage
- {
- protected $form; // form
- private static $paginas = 2;
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_NotasfornecedoresModel_report');
- $this->form->setFormTitle('Relatórios de Notas dos Fornecedores');
- // create the form fields
- $tbl_NotasEmissao = new TDate('tbl_NotasEmissao');
- $tbl_NotasRecebimento = new TDate('tbl_NotasRecebimento');
- $tbl_NotasValor = new TEntry('tbl_NotasValor');
- //$tbl_classificacao_idtbl_classificacao = new TDBCombo('tbl_classificacao_idtbl_classificacao', 'conexao', 'ClassificacaoModel', 'idtbl_classificacao', 'tbl_classificacaoTipo');
- $tbl_fornecedores_idtbl_Fornecedores = new TDBCombo('tbl_fornecedores_idtbl_Fornecedores', 'conexao', 'FornecedoresModel', 'idtbl_Fornecedores', 'tbl_FornecedoresNome');
- $tbl_fornecedores_tbl_Empresa_idtbl_Empresa = new TDBCombo('tbl_fornecedores_tbl_Empresa_idtbl_Empresa', 'conexao', 'EmpresaModel', 'idtbl_Empresa', 'tbl_EmpresaNome');
- $output_type = new TRadioGroup('output_type');
- // add the fields
- $this->form->addFields( [ new TLabel('Data Emissão :') ], [ $tbl_NotasEmissao ] );
- $this->form->addFields( [ new TLabel('Data Recebimento :') ], [ $tbl_NotasRecebimento ] );
- //$this->form->addFields( [ new TLabel('Valor :') ], [ $tbl_NotasValor ] );
- //$this->form->addFields( [ new TLabel('Código da Operação :') ], [ $tbl_classificacao_idtbl_classificacao ] );
- $this->form->addFields( [ new TLabel('Fornecedor :') ], [ $tbl_fornecedores_idtbl_Fornecedores ] );
- $this->form->addFields( [ new TLabel('Empresa :') ], [ $tbl_fornecedores_tbl_Empresa_idtbl_Empresa ] );
- $this->form->addFields( [ new TLabel('Tipo') ], [ $output_type ] );
- $output_type->addValidation('Output', new TRequiredValidator);
- // set sizes
- $tbl_NotasEmissao->setSize('100%');
- $tbl_NotasRecebimento->setSize('100%');
- $tbl_NotasValor->setSize('100%');
- // $tbl_classificacao_idtbl_classificacao->setSize('100%');
- $tbl_fornecedores_idtbl_Fornecedores->setSize('100%');
- $tbl_fornecedores_tbl_Empresa_idtbl_Empresa->setSize('100%');
- $output_type->setSize('100%');
- $output_type->addItems(array('html'=>'HTML', 'pdf'=>'PDF', 'rtf'=>'RTF', 'xls' => 'XLS'));
- $output_type->setLayout('horizontal');
- $output_type->setUseButton();
- $output_type->setValue('pdf');
- $output_type->setSize(70);
- // add the action button
- $btn = $this->form->addAction(_t('Generate'), new TAction(array($this, 'onGenerate')), 'fa:cog');
- $btn->class = 'btn btn-sm btn-primary';
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 90%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
- parent::add($container);
- }
- public function getNativeWriter()
- {
- return $this->pdf;
- }
- public function Cabecalho($pdf)
- {
- try
- {
- // open a transaction with database 'conexao'
- TTransaction::open('conexao');
- // get the form data into an active record
- $data = $this->form->getData();
- $this->form->validate();
- $repository1 = new TRepository('FornecedoresModel');
- $criteria1 = new TCriteria;
- $objectos = $repository1->load($criteria1, FALSE);
- foreach ($objectos as $objecto)
- {
- $empresa = $objecto->empresa_model->tbl_EmpresaNome;
- }
- // fill the form with the active record data
- $this->form->setData($data);
- // close the transaction
- TTransaction::close();
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- $numeroPagina = self::$paginas;
- $pdf->SetFont('Arial', 'I', 8);
- // TITULO
- $pdf->Cell(0, 0, "LIVRO FISCAL", 0, 0);
- $pdf->Cell(80);
- $pdf->PageNo();
- $pdf->Cell(0, 0, ("FL: {$numeroPagina} /{nb}"), 0, 0, 'R');
- $pdf->Ln(20);
- $pdf->Cell(0, 0, "REGISTRO DE ENTRADAS", 0, 0, 'C');
- $pdf->Ln(20);
- $pdf->Cell(100, 0, ( "EMPRESA : {$empresa}"), 0, 0);
- // Line break
- $pdf->Ln(20);
- self::$paginas++;
- }
- /**
- * Generate the report
- */
- function onGenerate()
- {
- try
- {
- // open a transaction with database 'conexao'
- TTransaction::open('conexao');
- // get the form data into an active record
- $data = $this->form->getData();
- $this->form->validate();
- $repository = new TRepository('NotasfornecedoresModel');
- $criteria = new TCriteria;
- if ($data->tbl_NotasEmissao)
- {
- $criteria->add(new TFilter('tbl_NotasEmissao', 'like', "%{$data->tbl_NotasEmissao}%"));
- }
- if ($data->tbl_NotasRecebimento)
- {
- $criteria->add(new TFilter('tbl_NotasRecebimento', 'like', "%{$data->tbl_NotasRecebimento}%"));
- }
- //if ($data->tbl_NotasValor)
- //{
- // $criteria->add(new TFilter('tbl_NotasValor', 'like', "%{$data->tbl_NotasValor}%"));
- //}
- //if ($data->tbl_classificacao_idtbl_classificacao)
- //{
- // $criteria->add(new TFilter('tbl_classificacao_idtbl_classificacao', 'like', "%{$data->tbl_classificacao_idtbl_classificacao}%"));
- //}
- if ($data->tbl_fornecedores_idtbl_Fornecedores)
- {
- $criteria->add(new TFilter('tbl_fornecedores_idtbl_Fornecedores', 'like', "%{$data->tbl_fornecedores_idtbl_Fornecedores}%"));
- }
- if ($data->tbl_fornecedores_tbl_Empresa_idtbl_Empresa)
- {
- $criteria->add(new TFilter('tbl_fornecedores_tbl_Empresa_idtbl_Empresa', 'like', "%{$data->tbl_fornecedores_tbl_Empresa_idtbl_Empresa}%"));
- }
- $objects = $repository->load($criteria, FALSE);
- $format = $data->output_type;
- if ($objects)
- {
- $widths = array(50,50,100,100,100,100);
- switch ($format)
- {
- case 'html':
- $tr = new TTableWriterHTML($widths);
- break;
- case 'pdf':
- $tr = new TTableWriterPDF($widths);
- $fpdf = $tr->getNativeWriter();
- $fpdf->setHeaderCallback(array($this,'Cabecalho'));
- $this->Cabecalho($fpdf);
- break;
- case 'xls':
- $tr = new TTableWriterXLS($widths);
- break;
- case 'rtf':
- $tr = new TTableWriterRTF($widths);
- break;
- }
- // create the document styles
- $tr->addStyle('title', 'Arial', '10', 'B', '#ffffff', '#EA9C98');
- $tr->addStyle('datap', 'Arial', '10', '' , '#000000', '#EEEEEE');
- $tr->addStyle('datai', 'Arial', '10', '' , '#000000', '#ffffff');
- $tr->addStyle('header', 'Arial', '16', '' , '#ffffff', '#904F49');
- $tr->addStyle('footer', 'Times', '10', 'I', '#000000', '#F2BEBC');
- // add a header row
- $tr->addRow();
- $tr->addCell(' Registro de Entradas ', 'center', 'header', 15);
- // add titles row
- $tr->addRow();
- $tr->addCell('Fornecedor :', 'center', 'title',2);
- $tr->addCell('Data Emissão :', 'center', 'title',2);
- $tr->addCell('Entrada :', 'center', 'title',2);
- $tr->addCell('Valor Contábil :', 'center', 'title',2);
- $tr->addCell('Código da Operação :', 'center', 'title',2);
- // controls the background filling
- $colour= FALSE;
- $total = 0;
- // data rows
- foreach ($objects as $object)
- {
- $style = $colour ? 'datap' : 'datai';
- $tr->addRow();
- $tr->addCell($object->fornecedores_model->tbl_FornecedoresNome, 'left', $style, 2);
- $emissao = date_parse($object->tbl_NotasEmissao);
- $emissao = str_pad($emissao['day'],2, '0' , STR_PAD_LEFT).'/'.
- str_pad($emissao['month'],2, '0' , STR_PAD_LEFT).'/'.
- $emissao['year'];
- $tr->addCell($emissao, 'center', $style,2);
- $recebimento = date_parse($object->tbl_NotasRecebimento);
- $recebimento = str_pad($recebimento['day'],2, '0' , STR_PAD_LEFT).'/'.
- str_pad($recebimento['month'],2, '0' , STR_PAD_LEFT).'/'.
- $recebimento['year'];
- $tr->addCell($recebimento, 'center', $style,2);
- $valor = ($object->tbl_NotasValor);
- $tr->addCell(number_format($valor,2,',','.'),'center', $style,2);
- $tr->addCell($object->classificacao_model->tbl_classificacaoCodigo, 'center', $style,2);
- $total += $object->tbl_NotasTotal;
- $colour = !$colour;
- }
- $tr->addRow();
- $tr->addCell('','center','footer');
- $tr->addRow();
- $tr->addCell('Total Geral R$:', 'center', 'footer',4);
- $tr->addCell(number_format($total,2,',','.'),'center', $style,4);
- // footer row
- $tr->addRow();
- $tr->addCell(date('d/m/Y h:i:s'), 'center', 'footer', 10);
- // stores the file
- if (!file_exists("app/output/NotasfornecedoresModel.{$format}") OR is_writable("app/output/NotasfornecedoresModel.{$format}"))
- {
- $tr->save("app/output/NotasfornecedoresModel.{$format}");
- }
- else
- {
- throw new Exception(_t('Permission denied') . ': ' . "app/output/NotasfornecedoresModel.{$format}");
- }
- // open the report file
- parent::openFile("app/output/NotasfornecedoresModel.{$format}");
- // shows the success message
- new TMessage('info', 'Relatório Gerado.');
- }
- else
- {
- new TMessage('error', 'Relatório não gerado pois não teve movimento no periodo solicitado');
- }
- // fill the form with the active record data
- $this->form->setData($data);
- // close the transaction
- TTransaction::close();
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- }
- ?>
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