Advertisement
Guest User

Invoice whmcs

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