PC
Relatórios em PDF
Fechado
Estou com a seguinte dúlvida:
Estou criando um relatório utilizando a TPDFDesigner no meio do relatório quero gerar uma seção tabular posso chamar a TTableWriterPDF?
Estou criando um relatório utilizando a TPDFDesigner no meio do relatório quero gerar uma seção tabular posso chamar a TTableWriterPDF?
- <?php
- function onGenerate()
- {
- try
- {
- ttransaction::open('sispag');
- $object = $this->form->getData();
- $this->form->validate();
- $repository = new TRepository('relatorio');
- $criteria = new TCriteria;
- if($object->proposta_id)
- {
- $criteria->add(new TFilter('id','=',"{$object->proposta_id}"));
- }
- $relatorios = $repository->load($criteria);
- $designer = new TPDFDesigner;
- $designer->fromXml('app/reports/relViagem2.pdf.xml');
- $designer->generate();
- //$designer->SetFont('Sans Serif', 'B', 12);
- $designer->setFontColorRGB( '#000000' );
- if($relatorios)
- {
- foreach($relatorios as $relatorio)
- {
- $x=array($relatorio->id_item);
- $designer->SetFont('Times', '', 12.5);
- $designer->writeAtAnchor('proposta', $relatorio->proposta);
- $designer->writeAtAnchor('despesa_de', $relatorio->despesa_de);
- $designer->writeAtAnchor('solicitante', $relatorio->solicitante);
- $designer->writeAtAnchor('cliente', $relatorio->cliente);
- $designer->writeAtAnchor('cidade_1', $relatorio->cidade);
- $designer->writeAtAnchor('estado_1', $relatorio->estado_1);
- $designer->writeAtAnchor('cidade_2', $relatorio->cidade_2);
- $designer->writeAtAnchor('estado_2', $relatorio->estado_2);
- $designer->writeAtAnchor('tecnico', utf8_decode($relatorio->tecnico));
- switch($relatorio->tipo_visita)
- {
- case '1':
- $designer->writeAtAnchor('visita', 'X');
- break;
- case '2':
- $designer->writeAtAnchor('implantacao', 'X');
- break;
- case '3';
- $designer->writeAtAnchor('treinamento', 'X');
- break;
- case '4';
- $designer->writeAtAnchor('outros', 'X');
- break;
- }
- switch($relatorio->tipo_transporte)
- {
- case '1':
- $designer->writeAtAnchor('proprio', 'X');
- break;
- case '2':
- $designer->writeAtAnchor('alugado', 'X');
- break;
- case '3':
- $designer->writeAtAnchor('publico', 'X');
- break;
- case '4':
- $designer->writeAtAnchor('taxi', 'X');
- break;
- }
- $designer->writeAtAnchor('partida', $relatorio->data_inicio);
- $designer->writeAtAnchor('chegada', $relatorio->data_final);
- $designer->writeAtAnchor('distancia', $relatorio->distancia);
- $tipos=array();
- $tipos[]=array('tipo'=>$relatorio->tipo_despesa,'total'=>$relatorio->total_item);
- $widths = array(50,200,50);
- $tr = new TTableWriterPDF($widths);
- // create the document styles
- $tr->addStyle('title', 'Arial', '10', 'BI', '#ffffff', '#407B49');
- $tr->addStyle('datap', 'Arial', '10', '', '#000000', '#869FBB');
- $tr->addStyle('datai', 'Arial', '10', '', '#000000', '#ffffff');
- $tr->addStyle('header', 'Times', '16', 'BI', '#ff0000', '#FFF1B2');
- $tr->addStyle('footer', 'Times', '12', 'BI', '#2B2B2B', '#B5FFB4');
- // add a header row
- $tr->addRow();
- $tr->addCell('Customers', 'center', 'header', 5);
- // add titles row
- $tr->addRow();
- $tr->addCell('Code', 'left', 'title');
- $tr->addCell('Name', 'left', 'title');
- // controls the background filling
- $colour= FALSE;
- // data rows
- foreach($tipos as $tp)
- {
- $style = $colour ? 'datap' : 'datai';
- $tr->addRow();
- $tr->addCell($tp['tipo'], 'left', $style);
- $tr->addCell($tp['total'], 'left', $style);// $tr->addCell($customer->category_name , 'left', $style);
- $colour = !$colour;
- $tr->addStyle('title', 'Arial', '10', 'BI', '#ffffff', '#407B49');
- $tr->addStyle('datap', 'Arial', '10', '', '#000000', '#869FBB');
- $tr->addStyle('datai', 'Arial', '10', '', '#000000', '#ffffff');
- $tr->addStyle('header', 'Times', '16', 'BI', '#ff0000', '#FFF1B2');
- $tr->addStyle('footer', 'Times', '12', 'BI', '#2B2B2B', '#B5FFB4');
- }
- }
- }
- $designer->SetFont('Arial','B',12);
- $designer->Ln(16);
- $designer->gotoAnchorX('details2');
- $designer->cell(550,12,utf8_decode('Total Geral'),0,0,'L',$fill);
- $designer->Cell(1,12,number_format((double)$relatorio->total_geral,2,',',''),0,0,'R',$fill);
- //$designer->writeAtAnchor('totgeral',number_format((double)$relatorio->total_geral,2,',',''));
- $designer->writeAtAnchor('adiantamento',number_format((double)$relatorio->adiantamento,2,',',''));
- $res=$relatorio->total_geral - $relatorio->adiantamento;
- if($res<0)
- {
- $designer->SetFont('Arial','B',14);
- $designer->writeAtAnchor('devolver',number_format((double)$res*-1,2,',',''));
- }
- else
- {
- $designer->SetFont('Arial','B',14);
- $designer->writeAtAnchor('receber',number_format((double)$res,2,',',''));
- }
- $designer->SetFont('Arial','B',14);
- $designer->writeAtAnchor('data',date('d/m/Y'));
- }
- $file = 'app/output/relviagem3.pdf';
- ?>
Oi Paulo,
Não, mas você pode utilizar qualquer método da FPDF, como o método cell(), uma vez que a classe TPDFDesigner é filha da classe FPDF. Caso você precise conhecer melhor a FPDF, segue o material:
fpdf.org/
Clique em "Manual"
Atenciosamente,
Pablo