Relatórios em PDF 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? ...
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?
 
  1. <?php
  2. function onGenerate()
  3. {
  4. try
  5. {
  6. ttransaction::open('sispag');
  7. $object = $this->form->getData();
  8. $this->form->validate();
  9. $repository = new TRepository('relatorio');
  10. $criteria = new TCriteria;
  11. if($object->proposta_id)
  12. {
  13. $criteria->add(new TFilter('id','=',"{$object->proposta_id}"));
  14. }
  15. $relatorios = $repository->load($criteria);
  16. $designer = new TPDFDesigner;
  17. $designer->fromXml('app/reports/relViagem2.pdf.xml');
  18. $designer->generate();
  19. //$designer->SetFont('Sans Serif', 'B', 12);
  20. $designer->setFontColorRGB( '#000000' );
  21. if($relatorios)
  22. {
  23. foreach($relatorios as $relatorio)
  24. {
  25. $x=array($relatorio->id_item);
  26. $designer->SetFont('Times', '', 12.5);
  27. $designer->writeAtAnchor('proposta', $relatorio->proposta);
  28. $designer->writeAtAnchor('despesa_de', $relatorio->despesa_de);
  29. $designer->writeAtAnchor('solicitante', $relatorio->solicitante);
  30. $designer->writeAtAnchor('cliente', $relatorio->cliente);
  31. $designer->writeAtAnchor('cidade_1', $relatorio->cidade);
  32. $designer->writeAtAnchor('estado_1', $relatorio->estado_1);
  33. $designer->writeAtAnchor('cidade_2', $relatorio->cidade_2);
  34. $designer->writeAtAnchor('estado_2', $relatorio->estado_2);
  35. $designer->writeAtAnchor('tecnico', utf8_decode($relatorio->tecnico));
  36. switch($relatorio->tipo_visita)
  37. {
  38. case '1':
  39. $designer->writeAtAnchor('visita', 'X');
  40. break;
  41. case '2':
  42. $designer->writeAtAnchor('implantacao', 'X');
  43. break;
  44. case '3';
  45. $designer->writeAtAnchor('treinamento', 'X');
  46. break;
  47. case '4';
  48. $designer->writeAtAnchor('outros', 'X');
  49. break;
  50. }
  51. switch($relatorio->tipo_transporte)
  52. {
  53. case '1':
  54. $designer->writeAtAnchor('proprio', 'X');
  55. break;
  56. case '2':
  57. $designer->writeAtAnchor('alugado', 'X');
  58. break;
  59. case '3':
  60. $designer->writeAtAnchor('publico', 'X');
  61. break;
  62. case '4':
  63. $designer->writeAtAnchor('taxi', 'X');
  64. break;
  65. }
  66. $designer->writeAtAnchor('partida', $relatorio->data_inicio);
  67. $designer->writeAtAnchor('chegada', $relatorio->data_final);
  68. $designer->writeAtAnchor('distancia', $relatorio->distancia);
  69. $tipos=array();
  70. $tipos[]=array('tipo'=>$relatorio->tipo_despesa,'total'=>$relatorio->total_item);
  71. $widths = array(50,200,50);
  72. $tr = new TTableWriterPDF($widths);
  73. // create the document styles
  74. $tr->addStyle('title', 'Arial', '10', 'BI', '#ffffff', '#407B49');
  75. $tr->addStyle('datap', 'Arial', '10', '', '#000000', '#869FBB');
  76. $tr->addStyle('datai', 'Arial', '10', '', '#000000', '#ffffff');
  77. $tr->addStyle('header', 'Times', '16', 'BI', '#ff0000', '#FFF1B2');
  78. $tr->addStyle('footer', 'Times', '12', 'BI', '#2B2B2B', '#B5FFB4');
  79. // add a header row
  80. $tr->addRow();
  81. $tr->addCell('Customers', 'center', 'header', 5);
  82. // add titles row
  83. $tr->addRow();
  84. $tr->addCell('Code', 'left', 'title');
  85. $tr->addCell('Name', 'left', 'title');
  86. // controls the background filling
  87. $colour= FALSE;
  88. // data rows
  89. foreach($tipos as $tp)
  90. {
  91. $style = $colour ? 'datap' : 'datai';
  92. $tr->addRow();
  93. $tr->addCell($tp['tipo'], 'left', $style);
  94. $tr->addCell($tp['total'], 'left', $style);// $tr->addCell($customer->category_name , 'left', $style);
  95. $colour = !$colour;
  96. $tr->addStyle('title', 'Arial', '10', 'BI', '#ffffff', '#407B49');
  97. $tr->addStyle('datap', 'Arial', '10', '', '#000000', '#869FBB');
  98. $tr->addStyle('datai', 'Arial', '10', '', '#000000', '#ffffff');
  99. $tr->addStyle('header', 'Times', '16', 'BI', '#ff0000', '#FFF1B2');
  100. $tr->addStyle('footer', 'Times', '12', 'BI', '#2B2B2B', '#B5FFB4');
  101. }
  102. }
  103. }
  104. $designer->SetFont('Arial','B',12);
  105. $designer->Ln(16);
  106. $designer->gotoAnchorX('details2');
  107. $designer->cell(550,12,utf8_decode('Total Geral'),0,0,'L',$fill);
  108. $designer->Cell(1,12,number_format((double)$relatorio->total_geral,2,',',''),0,0,'R',$fill);
  109. //$designer->writeAtAnchor('totgeral',number_format((double)$relatorio->total_geral,2,',',''));
  110. $designer->writeAtAnchor('adiantamento',number_format((double)$relatorio->adiantamento,2,',',''));
  111. $res=$relatorio->total_geral - $relatorio->adiantamento;
  112. if($res<0)
  113. {
  114. $designer->SetFont('Arial','B',14);
  115. $designer->writeAtAnchor('devolver',number_format((double)$res*-1,2,',',''));
  116. }
  117. else
  118. {
  119. $designer->SetFont('Arial','B',14);
  120. $designer->writeAtAnchor('receber',number_format((double)$res,2,',',''));
  121. }
  122. $designer->SetFont('Arial','B',14);
  123. $designer->writeAtAnchor('data',date('d/m/Y'));
  124. }
  125. $file = 'app/output/relviagem3.pdf';
  126. ?>

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (1)


PD

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