Advertisement
Guest User

mpdf

a guest
Aug 17th, 2018
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. /*
  2. | -------------------------------------------------------------------------------------------
  3. | Below functions to generate item reports
  4. | ------------------------------------------------------------------------------------------
  5. |
  6. */
  7.  
  8. function generateHeader(){
  9. $data = date('j/m/Y');
  10. $retorno = "<table class=\"tbl_header\" width=\"1000\">
  11. <tr>
  12. <td align=\"left\">Relatório de Clientes</td>
  13. <td align=\"right\">Gerado em: $data</td>
  14. </tr>
  15. </table>";
  16. return $retorno;
  17. }
  18.  
  19.  
  20. function generateFooter(){
  21. $retorno = "<table class=\"tbl_footer\" width=\"1000\">
  22. <tr>
  23. <td align=\"left\">Petit Fru Fru Mimos de Luxo</td>
  24. <td align=\"right\">Página: {PAGENO}</td>
  25. </tr>
  26. </table>";
  27. return $retorno;
  28. }
  29.  
  30.  
  31. function generateTable( $data = array() )
  32. {
  33.  
  34. $CI =& get_instance();
  35. $color = false;
  36. $retorno = "";
  37.  
  38. $retorno .= "<h2 style=\"text-align:center\">Relatório Orçamento Clientes</h2>";
  39. $retorno .= "<table border='0' width='1000' align='center'> ";
  40.  
  41. foreach ( dataClient( $data ) as $c) :
  42.  
  43. $retorno .= "<tr>
  44. <td>&nbsp;</td>
  45. <td>&nbsp;</td>
  46. <td>&nbsp;</td>
  47. <td>&nbsp;</td>
  48. <td>&nbsp;</td>
  49. </tr>
  50. <tr>
  51. <td>&nbsp;</td>
  52. <td>&nbsp;</td>
  53. <td>&nbsp;</td>
  54. <td>&nbsp;</td>
  55. <td>&nbsp;</td>
  56. </tr>
  57. <tr class='header'>
  58. <th>Código do Cliente</td>
  59. <th>Nome do Cliente</td>
  60. <th>Nome do Aniversariante</td>
  61. <th>Idade do Aniversariante</td>
  62. <th>Data do Evento</td>
  63. </tr>";
  64.  
  65. $retorno .= ($color) ? "<tr>" : "<tr class=\"zebra\">";
  66. $retorno .= "<td>{$c->budgets_code_customer}</td>";
  67. $retorno .= "<td>{$c->budgets_name_customer}</td>";
  68. $retorno .= "<td>{$c->budgets_name_birthday_person}</td>";
  69. $retorno .= "<td>{$c->budgets_age_customers}</td>";
  70. $retorno .= "<td>" . dateBr($c->budgets_date_event) . "</td>";
  71.  
  72. $retorno .= "<tr class='header'>
  73. <th>Código do Produto</td>
  74. <th>Descrição do Produto</td>
  75. <th>Quantidade</td>
  76. <th>Observação</td>
  77. <th>&nbsp;</td>
  78. </tr>";
  79.  
  80. foreach ( dataProducts( $data, $c->budgets_id_customer ) as $r) :
  81.  
  82. $retorno .= ($color) ? "<tr>" : "<tr class=\"zebra\">";
  83. $retorno .= "<td>{$r->budgets_item_code_product}</td>";
  84. $retorno .= "<td>{$r->budgets_item_name_product}</td>";
  85. $retorno .= "<td>{$r->budgets_item_quantity}</td>";
  86. $retorno .= "<td>{$r->budgets_item_observation}</td>";
  87. $retorno .= "<tr>";
  88. $color = !$color;
  89.  
  90. endforeach;
  91.  
  92. $color = !$color;
  93.  
  94. endforeach;
  95.  
  96. $retorno .= "</table>";
  97.  
  98. return $retorno;
  99. }
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110. function dataClient( $data = array() )
  111. {
  112.  
  113. $CI =& get_instance();
  114.  
  115. return $CI->db->select( '*' )->from( 'tb_budgets' )
  116. ->where( 'budgets_code_customer BETWEEN "'. $data['code_start'] . '" AND "' . $data['code_end'] . '"')
  117. ->where( 'budgets_date_event BETWEEN "'. $data['date_start'] . '" AND "' . $data['date_end'] . '"')
  118. ->get()->result();
  119.  
  120. }
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131. function dataProducts( $data = array(), $idClient )
  132. {
  133.  
  134. $CI =& get_instance();
  135.  
  136. return $CI->db->select( '*' )->from( 'tb_budgets_itens' )
  137. ->where( 'budgets_item_code_customer BETWEEN "'. $data['code_start'] . '" AND "' . $data['code_end'] . '"')
  138. ->where( 'budgets_item_id_customer = "'. $idClient . '"' )
  139. ->get()->result();
  140.  
  141. }
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152. function generateReports( $data = array() )
  153. {
  154.  
  155. require_once DIR_VENDOR;
  156.  
  157. $mpdf = new \Mpdf\Mpdf(['debug' => 'true']);
  158. $stylesheet = file_get_contents( DIR_CSS );
  159. $mpdf->WriteHTML($stylesheet,1);
  160. $mpdf->SetHTMLHeader( generateHeader() );
  161. $mpdf->SetHTMLFooter( generateFooter() );
  162. $mpdf->WriteHTML( generateTable( $data ) );
  163. $mpdf->Output( 'teste de relatorio', 'I');
  164.  
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement