RC
Criar cabeçalho em relatório tabular TTableWriterPDF
Fechado
Boa tarde
Estou tentando seguir este exemplo www.adianti.com.br/forum/pt/view_833?cabecalho-de-relatorio-usando-t fornecido pelo Pablo para criar um cabeçalho e rodapé em um relatório tabular, mas não está dando certo.
Alguém pode me ajudar? Como não tenho o adianti stúdio pro para simplificar essa tarefa, estou apanhando para fazer isso manualmente.
Segue meu código fonte:
Estou tentando seguir este exemplo www.adianti.com.br/forum/pt/view_833?cabecalho-de-relatorio-usando-t fornecido pelo Pablo para criar um cabeçalho e rodapé em um relatório tabular, mas não está dando certo.
Alguém pode me ajudar? Como não tenho o adianti stúdio pro para simplificar essa tarefa, estou apanhando para fazer isso manualmente.
Segue meu código fonte:
- <?php
- class SaldoFisicoFinanceiro extends TPage {
- function __construct() {
- parent::__construct();
- try {
- TTransaction::open('estoque');
- $repository = new TRepository('Produto');
- $criteria = new TCriteria;
- $criteria->add(new TFilter('tipo', '=', 'P'));
- $criteria->add(new TFilter('saldofisico', '>', '0'));
- $produtos = $repository->load($criteria);
- $format = 'pdf';
- if ($produtos) {
- $widths = array(40, 320, 60, 60, 60);
- $tr = new TTableWriterPDF($widths);
- $tr->getNativeWriter()->setHeaderCallback(array($this, 'header'));
- if (!empty($tr)) {
- // create the document styles
- $tr->addStyle('title', 'Arial', '10', 'BI', '#222222', '#DDDDDD');
- $tr->addStyle('datap', 'Arial', '10', '', '#000000', '#ffffff');
- $tr->addStyle('datai', 'Arial', '10', '', '#000000', '#ffffff');
- $tr->addStyle('total', 'Arial', '14', 'BI', '#222222', '#ffffff');
- $tr->addStyle('header', 'Arial', '14', 'BI', '#222222', '#DDDDDD');
- $tr->addStyle('footer', 'Times', '12', 'BI', '#2B2B2B', '#DDDDDD');
- // add a header row
- $tr->addRow();
- $tr->addCell('RELATÓRIO DE SALDOS FÍSICO E FINANCEIRO DE PRODUTOS', 'center', 'header', 5);
- // add titles row
- $tr->addRow();
- $tr->addCell('CÓD.', 'center', 'title');
- $tr->addCell('PRODUTO', 'left', 'title');
- $tr->addCell('UNIDADE', 'center', 'title');
- $tr->addCell('QTDE', 'center', 'title');
- $tr->addCell('SALDO (R$)', 'center', 'title');
- // controls the background filling
- $colour = FALSE;
- // data rows
- $total = 0;
- foreach ($produtos as $prod) {
- $style = $colour ? 'datap' : 'datai';
- $tr->addRow();
- $tr->addCell($prod->id, 'center', $style);
- $tr->addCell($prod->descricao, 'left', $style);
- $tr->addCell($prod->nome_unidade, 'center', $style);
- $tr->addCell(Uteis::numeroBrasil($prod->saldofisico), 'center', $style);
- $tr->addCell(Uteis::numeroBrasil($prod->valortotal), 'center', $style);
- $total+= $prod->valortotal;
- $colour = !$colour;
- }
- $valortotal = Uteis::numeroBrasil($total);
- $tr->addRow();
- $tr->addCell('TOTAL: R$ ' . $valortotal, 'rigth', 'total', 5);
- // footer row
- $tr->addRow();
- $tr->addCell(date('d/m/Y H:i:s'), 'center', 'footer', 5);
- // stores the file
- if (!file_exists("app/output/saldofisicofinanceiro.{$format}") OR is_writable("app/output/saldofisicofinanceiro.{$format}")) {
- $tr->save("app/output/saldofisicofinanceiro.{$format}");
- } else {
- throw new Exception(_t('Permission denied') . ': ' . "app/output/saldofisicofinanceiro.{$format}");
- }
- parent::openFile("app/output/saldofisicofinanceiro.{$format}");
- // shows the success message
- new TMessage('info', 'Relatório gerado. Por favor, habilite popups no navegador.');
- }
- } else {
- new TMessage('error', 'Nenhum registro foi encontrado.');
- }
- // fill the form with the active record data
- //$this->form->setData($object);
- // close the transaction
- TTransaction::close();
- } catch (Exception $e) { // in case of exception
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- function header($pdf) {
- $pdf->SetFont('Arial', 'B', 15);
- // Move to the right
- $pdf->Cell(80);
- // Title
- $pdf->Cell(30, 10, 'Title', 1, 0, 'C');
- // Line break
- $pdf->Ln(20);
- }
- }
- ?>
Segue este artigo
www.adianti.com.br/forum/pt/view_851?criando-cabecalhos-e-rodapes-no
Eu tentei seguir esse exemplo ai mas não funcionou. Estou usando o template ERP3 e percebi que não há essa classe TPDFDesigner no Framework.
Achei uma tal de AdiantPDFDesigner mas a mesma não tem métodos Header e nem Footer.
Alguma sugestão? Será que essa TPDFDesigner foi descontinuada?
Rapaz olhei tudo agora como assim a classe não existe mais se ainda utilizo. bem somente depois percebi em seu post que não usa o studio pro na versão 3 a equipe do adianti realmente mudou o nome da classe, mas manteve um alias para o nome então continua funcionando.
Porém vc está fazendo a mão, uma solução seria vc criar uma classe e estender a TTableWriterPDF criando uma seção header e footer igual como está no artigo.
Isso mesmo, estou fazendo na mão pois não tenho o studio pro! Então se eu criar uma classe e estender de TTableWriterPDF e criar uma seção Header e Footer como no artigo é pta funcionar?
Mas vou ter que salvar como .xml ou não?
Eu salvaria como essa classe TableWritePDF colocaria outro nome incluiria a seção header e footer e chamava essa nova classe igual no artigo vou dar uma olhada nessa classe no livro para ver como ela é feita sinceramente nunca usei pois uso o studio pró que facilita muito nessa parte de reports.
Tem como disponibilizar o código da classe TPDFDesigner? Vou tentar criar uma outra classe me baseando nela.
Ricelli
No seu caso aconselho a usar a FPDF direto. www.fpdf.org/
Pois é Felipe, imagino que terei que fazer isso mesmo.
De qualquer forma, obrigado pelo help.
Já tem solução:
www.adianti.com.br/forum/pt/view_833?cabecalho-de-relatorio-usando-t
Abraço,