invoicepdf.tpl 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. # Logo
  3. $logoFilename = 'placeholder.png';
  4. if (file_exists(ROOTDIR . '/assets/img/logo.png')) {
  5. $logoFilename = 'logo.png';
  6. } elseif (file_exists(ROOTDIR . '/assets/img/logo.jpg')) {
  7. $logoFilename = 'logo.jpg';
  8. } elseif (file_exists(ROOTDIR . '/assets/img/logo.jpeg')) {
  9. $logoFilename = 'logo.jpeg';
  10. }
  11. $pdf->Image(ROOTDIR . '/assets/img/' . $logoFilename, 15, 25, 75);
  12. # Invoice Status
  13. $pdf->SetXY(0, 0);
  14. $pdf->SetFont($pdfFont, 'B', 28);
  15. $pdf->SetTextColor(255);
  16. $pdf->SetLineWidth(0.75);
  17. $pdf->StartTransform();
  18. $pdf->Rotate(-35, 100, 225);
  19. if ($status == 'Draft') {
  20. $pdf->SetFillColor(200);
  21. $pdf->SetDrawColor(140);
  22. } elseif ($status == 'Paid') {
  23. $pdf->SetFillColor(151, 223, 74);
  24. $pdf->SetDrawColor(110, 192, 70);
  25. } elseif ($status == 'Cancelled') {
  26. $pdf->SetFillColor(200);
  27. $pdf->SetDrawColor(140);
  28. } elseif ($status == 'Refunded') {
  29. $pdf->SetFillColor(131, 182, 218);
  30. $pdf->SetDrawColor(91, 136, 182);
  31. } elseif ($status == 'Collections') {
  32. $pdf->SetFillColor(3, 3, 2);
  33. $pdf->SetDrawColor(127);
  34. } else {
  35. $pdf->SetFillColor(223, 85, 74);
  36. $pdf->SetDrawColor(171, 49, 43);
  37. }
  38. if ($status == 'Payment Pending'){
  39. $pdf->Cell(100, 18, strtoupper(Lang::trans('invoices' . str_replace(' ', '', $status))), 'TB', 0, 'C', '1');
  40. } else {
  41. $pdf->Cell(100, 18, strtoupper(Lang::trans('invoices' . strtolower($status))), 'TB', 0, 'C', '1');
  42. }
  43. $pdf->StopTransform();
  44. $pdf->SetTextColor(0);
  45. # Company Details
  46. $pdf->SetXY(15, 42);
  47. $pdf->SetFont($pdfFont, '', 13);
  48. foreach ($companyaddress as $addressLine) {
  49. $pdf->Cell(180, 4, trim($addressLine), 0, 1, 'R');
  50. $pdf->SetFont($pdfFont, '', 9);
  51. }
  52. if ($taxCode) {
  53. $pdf->Cell(180, 4, $taxIdLabel . ': ' . trim($taxCode), 0, 1, 'R');
  54. }
  55. $pdf->Ln(5);
  56. # Header Bar
  57. /**
  58. * Invoice header
  59. *
  60. * You can optionally define a header/footer in a way that is repeated across page breaks.
  61. * For more information, see https://docs.whmcs.com/PDF_Invoice#Header.2FFooter
  62. */
  63. $pdf->SetFont($pdfFont, 'B', 15);
  64. $pdf->SetFillColor(239);
  65. $pdf->Cell(0, 8, $pagetitle, 0, 1, 'L', '1');
  66. $pdf->SetFont($pdfFont, '', 10);
  67. $pdf->Cell(0, 6, Lang::trans('invoicesdatecreated') . ': ' . $datecreated, 0, 1, 'L', '1');
  68. $pdf->Cell(0, 6, Lang::trans('invoicesdatedue') . ': ' . $duedate, 0, 1, 'L', '1');
  69. $pdf->Ln(10);
  70. $startpage = $pdf->GetPage();
  71. # Clients Details
  72. $addressypos = $pdf->GetY();
  73. $pdf->SetFont($pdfFont, 'B', 10);
  74. $pdf->Cell(0, 4, Lang::trans('invoicesinvoicedto'), 0, 1);
  75. $pdf->SetFont($pdfFont, '', 9);
  76. if ($clientsdetails["companyname"]) {
  77. $pdf->Cell(0, 4, $clientsdetails["companyname"], 0, 1, 'L');
  78. $pdf->Cell(0, 4, Lang::trans('invoicesattn') . ': ' . $clientsdetails["firstname"] . ' ' . $clientsdetails["lastname"], 0, 1, 'L');
  79. } else {
  80. $pdf->Cell(0, 4, $clientsdetails["firstname"] . " " . $clientsdetails["lastname"], 0, 1, 'L');
  81. }
  82. $pdf->Cell(0, 4, $clientsdetails["address1"], 0, 1, 'L');
  83. if ($clientsdetails["address2"]) {
  84. $pdf->Cell(0, 4, $clientsdetails["address2"], 0, 1, 'L');
  85. }
  86. $pdf->Cell(0, 4, $clientsdetails["city"] . ", " . $clientsdetails["state"] . ", " . $clientsdetails["postcode"], 0, 1, 'L');
  87. $pdf->Cell(0, 4, $clientsdetails["country"], 0, 1, 'L');
  88. if (array_key_exists('tax_id', $clientsdetails) && $clientsdetails['tax_id']) {
  89. $pdf->Cell(0, 4, $taxIdLabel . ': ' . $clientsdetails['tax_id'], 0, 1, 'L');
  90. }
  91. if ($customfields) {
  92. $pdf->Ln();
  93. foreach ($customfields as $customfield) {
  94. $pdf->Cell(0, 4, $customfield['fieldname'] . ': ' . $customfield['value'], 0, 1, 'L');
  95. }
  96. }
  97. $pdf->Ln(10);
  98. # Invoice Items
  99. $tblhtml = '<table width="100%" bgcolor="#ccc" cellspacing="1" cellpadding="2" border="0">
  100. <tr height="30" bgcolor="#efefef" style="font-weight:bold;text-align:center;">
  101. <td width="80%">' . Lang::trans('invoicesdescription') . '</td>
  102. <td width="20%">' . Lang::trans('quotelinetotal') . '</td>
  103. </tr>';
  104. foreach ($invoiceitems as $item) {
  105. $tblhtml .= '
  106. <tr bgcolor="#fff">
  107. <td align="left">' . nl2br($item['description']) . '<br /></td>
  108. <td align="center">' . $item['amount'] . '</td>
  109. </tr>';
  110. }
  111. $tblhtml .= '
  112. <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
  113. <td align="right">' . Lang::trans('invoicessubtotal') . '</td>
  114. <td align="center">' . $subtotal . '</td>
  115. </tr>';
  116. if ($taxname) {
  117. $tblhtml .= '
  118. <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
  119. <td align="right">' . $taxrate . '% ' . $taxname . '</td>
  120. <td align="center">' . $tax . '</td>
  121. </tr>';
  122. }
  123. if ($taxname2) {
  124. $tblhtml .= '
  125. <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
  126. <td align="right">' . $taxrate2 . '% ' . $taxname2 . '</td>
  127. <td align="center">' . $tax2 . '</td>
  128. </tr>';
  129. }
  130. $tblhtml .= '
  131. <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
  132. <td align="right">' . Lang::trans('invoicescredit') . '</td>
  133. <td align="center">' . $credit . '</td>
  134. </tr>
  135. <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
  136. <td align="right">' . Lang::trans('invoicestotal') . '</td>
  137. <td align="center">' . $total . '</td>
  138. </tr>
  139. </table>';
  140. $pdf->writeHTML($tblhtml, true, false, false, false, '');
  141. $pdf->Ln(5);
  142. # Transactions
  143. $pdf->SetFont($pdfFont, 'B', 12);
  144. $pdf->Cell(0, 4, Lang::trans('invoicestransactions'), 0, 1);
  145. $pdf->Ln(5);
  146. $pdf->SetFont($pdfFont, '', 9);
  147. $tblhtml = '<table width="100%" bgcolor="#ccc" cellspacing="1" cellpadding="2" border="0">
  148. <tr height="30" bgcolor="#efefef" style="font-weight:bold;text-align:center;">
  149. <td width="25%">' . Lang::trans('invoicestransdate') . '</td>
  150. <td width="25%">' . Lang::trans('invoicestransgateway') . '</td>
  151. <td width="30%">' . Lang::trans('invoicestransid') . '</td>
  152. <td width="20%">' . Lang::trans('invoicestransamount') . '</td>
  153. </tr>';
  154. if (!count($transactions)) {
  155. $tblhtml .= '
  156. <tr bgcolor="#fff">
  157. <td colspan="4" align="center">' . Lang::trans('invoicestransnonefound') . '</td>
  158. </tr>';
  159. } else {
  160. foreach ($transactions AS $trans) {
  161. $tblhtml .= '
  162. <tr bgcolor="#fff">
  163. <td align="center">' . $trans['date'] . '</td>
  164. <td align="center">' . $trans['gateway'] . '</td>
  165. <td align="center">' . $trans['transid'] . '</td>
  166. <td align="center">' . $trans['amount'] . '</td>
  167. </tr>';
  168. }
  169. }
  170. $tblhtml .= '
  171. <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
  172. <td colspan="3" align="right">' . Lang::trans('invoicesbalance') . '</td>
  173. <td align="center">' . $balance . '</td>
  174. </tr>
  175. </table>';
  176. $pdf->writeHTML($tblhtml, true, false, false, false, '');
  177. # Notes
  178. if ($notes) {
  179. $pdf->Ln(5);
  180. $pdf->SetFont($pdfFont, '', 8);
  181. $pdf->MultiCell(170, 5, Lang::trans('invoicesnotes') . ': ' . $notes);
  182. }
  183. # Generation Date
  184. $pdf->SetFont($pdfFont, '', 8);
  185. $pdf->Ln(5);
  186. $pdf->Cell(180, 4, Lang::trans('invoicepdfgenerated') . ' ' . getTodaysDate(1), '', '', 'C');
  187. /**
  188. * Invoice footer
  189. */