Jump to content

Errors in PDF Customisation


MattH

Recommended Posts

Good Afternoon

 

This is my post on the WHMCS forum, I have been recommended to use this resource for assistance in relation to the customisation of PDF Invoices in WHMCS.

 

I have had the code in the PHP file invoicepdf.tpl edited by our developer to include an additional section of the bottom which includes:

 

- An adjusted position of the due date of the invoice

- Four table cells for specific information on paying the account

- Terms of the invoice

 

This however is not appearing upon generation, we believe it may be being cut-off by the system.

 

Please see a copy of the code here.

 

<?php
# Logo

if (file_exists(ROOTDIR.'/images/logo.png')) $pdf->Image(ROOTDIR.'/images/logo.png',20,25,75);
elseif (file_exists(ROOTDIR.'/images/logo.jpg')) $pdf->Image(ROOTDIR.'/images/logo.jpg',20,25,75);
else $pdf->Image(ROOTDIR.'/images/placeholder.png',20,25,75);

# Company Details
$pdf->SetFont('freesans','',13);
$pdf->Cell(0,6,trim($companyaddress[0]),0,1,'R');
$pdf->SetFont('freesans','',9);
for ( $i = 1; $i <= ((count($companyaddress)>6) ? count($companyaddress) : 6); $i += 1) {
$pdf->Cell(0,4,trim($companyaddress[$i]),0,1,'R');
}
$pdf->Ln(5);

# Header Bar
$invoiceprefix = $_LANG["invoicenumber"];
/*
** This code should be uncommented for EU companies using the sequential invoice numbering so that when unpaid it is shown as a proforma invoice **
if ($status!="Paid") {
$invoiceprefix = $_LANG["proformainvoicenumber"];
}
*/
$pdf->SetFont('freesans','B',15);
$pdf->SetFillColor(239);
$pdf->Cell(0,8,$invoiceprefix.$invoicenum,0,1,'L','1');
$pdf->SetFont('freesans','',10);
$pdf->Cell(0,6,$_LANG["invoicesdatecreated"].': '.$datecreated.'',0,1,'L','1');
/*$pdf->Cell(0,6,$_LANG["invoicesdatedue"].': '.$duedate.'',0,1,'L','1');*/
$pdf->Ln(10);

$startpage = $pdf->GetPage();

# Clients Details
$addressypos = $pdf->GetY();
$pdf->SetFont('freesans','B',10);
$pdf->Cell(0,4,$_LANG["invoicesinvoicedto"],0,1);
$pdf->SetFont('freesans','',9);
if ($clientsdetails["companyname"]) {
$pdf->Cell(0,4,$clientsdetails["companyname"],0,1,'L');
$pdf->Cell(0,4,$_LANG["invoicesattn"].": ".$clientsdetails["firstname"]." ".$clientsdetails["lastname"],0,1,'L');
} else {
$pdf->Cell(0,4,$clientsdetails["firstname"]." ".$clientsdetails["lastname"],0,1,'L');
}
$pdf->Cell(0,4,$clientsdetails["address1"],0,1,'L');
if ($clientsdetails["address2"]) {
$pdf->Cell(0,4,$clientsdetails["address2"],0,1,'L');
}
$pdf->Cell(0,4,$clientsdetails["city"].", ".$clientsdetails["state"].", ".$clientsdetails["postcode"],0,1,'L');
$pdf->Cell(0,4,$clientsdetails["country"],0,1,'L');
if ($customfields) {
   $pdf->Ln();
   foreach ($customfields AS $customfield) {
       $pdf->Cell(0,4,$customfield['fieldname'].': '.$customfield['value'],0,1,'L');
   }
}
$pdf->Ln(10);

# Invoice Items
$tblhtml = '<table width="100%" bgcolor="#ccc" cellspacing="1" cellpadding="2" border="0">
   <tr height="30" bgcolor="#efefef" style="font-weight:bold;text-align:center;">
       <td width="80%">'.$_LANG['invoicesdescription'].'</td>
       <td width="20%">'.$_LANG['quotelinetotal'].'</td>
   </tr>';
foreach ($invoiceitems AS $item) {
   $tblhtml .= '
   <tr bgcolor="#fff">
       <td align="left">'.nl2br($item['description']).'<br /></td>
       <td align="center">'.$item['amount'].'</td>
   </tr>';
}
$tblhtml .= '
   <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
       <td align="right">'.$_LANG['invoicessubtotal'].'</td>
       <td align="center">'.$subtotal.'</td>
   </tr>';
if ($taxname) $tblhtml .= '
   <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
       <td align="right">'.$taxrate.'% '.$taxname.'</td>
       <td align="center">'.$tax.'</td>
   </tr>';
if ($taxname2) $tblhtml .= '
   <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
       <td align="right">'.$taxrate2.'% '.$taxname2.'</td>
       <td align="center">'.$tax2.'</td>
   </tr>';
$tblhtml .= '
   <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
       <td align="right">'.$_LANG['invoicescredit'].'</td>
       <td align="center">'.$credit.'</td>
   </tr>
   <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
       <td align="right">'.$_LANG['invoicestotal'].'</td>
       <td align="center">'.$total.'</td>
   </tr>
</table>';

$pdf->writeHTML($tblhtml, true, false, false, false, '');

$pdf->Ln(5);

# Transactions
$pdf->SetFont('freesans','B',12);
$pdf->Cell(0,4,$_LANG["invoicestransactions"],0,1);

$pdf->Ln(5);

$pdf->SetFont('freesans','',9);

$tblhtml = '<table width="100%" bgcolor="#ccc" cellspacing="1" cellpadding="2" border="0">
   <tr height="30" bgcolor="#efefef" style="font-weight:bold;text-align:center;">
       <td width="25%">'.$_LANG['invoicestransdate'].'</td>
       <td width="25%">'.$_LANG['invoicestransgateway'].'</td>
       <td width="30%">'.$_LANG['invoicestransid'].'</td>
       <td width="20%">'.$_LANG['invoicestransamount'].'</td>
   </tr>';

if (!count($transactions)) {
   $tblhtml .= '
   <tr bgcolor="#fff">
       <td colspan="4" align="center">'.$_LANG['invoicestransnonefound'].'</td>
   </tr>';
} else {
   foreach ($transactions AS $trans) {
       $tblhtml .= '
       <tr bgcolor="#fff">
           <td align="center">'.$trans['date'].'</td>
           <td align="center">'.$trans['gateway'].'</td>
           <td align="center">'.$trans['transid'].'</td>
           <td align="center">'.$trans['amount'].'</td>
       </tr>';
   }
}
$tblhtml .= '
   <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
       <td colspan="3" align="right">'.$_LANG['invoicesbalance'].'</td>
       <td align="center">'.$balance.'</td>
   </tr>
</table>';

$pdf->writeHTML($tblhtml, true, false, false, false, '');

# Notes
if ($notes) {
   $pdf->Ln(5);
$pdf->SetFont('freesans','',;
$pdf->MultiCell(170,5,$_LANG["invoicesnotes"].": $notes");
}

# Footer Blocks

$pdf->SetFont('freesans','',10);

$blockhtml = '<table width="100%" bgcolor="#efefef" cellspacing="1" cellpadding="2" border="0">
		<tr height="30"  bgcolor="#efefef">
           	<td colspan="2">
               	<h3>Invoice Due Date: '.$duedate.'</h3>
				<p>Late charges may apply for payments received after this date in accordance with your service agreement.</p>
               </td>
           </tr>';
$blockhtml .= '<tr height="30"  bgcolor="#efefef">
           	<td colspan="2">
               	<h3>How to Pay:</h3>
               </td>
           </tr>';

$blockhtml .= '<tr height="30"  bgcolor="#efefef">
           	<td width="50%">
               	<p><strong>Electronic Funds Transfer</strong></p>
				<p>Contact your Financial Institution to make a payment through phone, internet banking or at your local bank branch to our account.</p>
                   <p><strong>Account:</strong> Holder Name<br /><strong>Number:</strong> 123 456 789 777<br  /><strong>BSB:</strong> 123 456<br  /><strong>Ref:</strong> Inv-'.$invoicenum.'</p>
               </td>
               <td width="50%">
               	<p><strong>PayPal</strong> – Online Payments</p>
                   <p>Pay using VISA/MasterCard or your bank account</p>
                   <p>To pay using PayPal please login to your account at:<br /><a href="https://www.locationofbilling.com/" target="_blank">https://www.locationofbilling/</a>  where you will find the electronic invoice awaiting payment.</p>
                   <p>No PayPal account is required to make a payment to us online.</p>
               </td>
           </tr>';

$blockhtml .= '<tr height="30"  bgcolor="#efefef">
           	<td width="50%">
               	<p><strong>Telephone Credit Card Payments</strong></p>
                   <p>Please phone <a href="tel:XXXXXXX">XX XXXX XXXX</a> to pay using your VISA or MasterCard.</p>
                   <p>Payments are processed on the spot and you will receive a receipt via email.</p>
               </td>
               <td width="50%">
               	<p><strong>Automated Credit Card Payments</strong></p>
                   <p>By providing us with a pre-authority to debit your card. We can automatically bill your card when invoices fall due without the hassle of manual payments.</p>
                   <p>Please call us to obtain a form which you will need to complete for automated payments.</p>
               </td>
           </tr>
	</table>';

$pdf->writeHTML($blockhtml, true, false, true, false, '');

# Generation Date
$pdf->SetFont('freesans','',;
$pdf->Ln(5);
$pdf->Cell(180,4,$_LANG['invoicepdfgenerated'].' '.getTodaysDate(),'','','C');

# Payment Status
$endpage = $pdf->GetPage();
$pdf->setPage($startpage);
$pdf->SetXY(85,$addressypos);
if ($status=="Cancelled") {
$statustext = $_LANG["invoicescancelled"];
   $pdf->SetTextColor(245,245,245);
} elseif ($status=="Unpaid") {
$statustext = $_LANG["invoicesunpaid"];
   $pdf->SetTextColor(204,0,0);
} elseif ($status=="Paid") {
$statustext = $_LANG["invoicespaid"];
   $pdf->SetTextColor(153,204,0);
} elseif ($status=="Refunded") {
$statustext = $_LANG["invoicesrefunded"];
   $pdf->SetTextColor(34,68,136);
} elseif ($status=="Collections") {
$statustext = $_LANG["invoicescollections"];
   $pdf->SetTextColor(255,204,0);
}
$pdf->SetFont('freesans','B',40);
$pdf->Cell(110,20,strtoupper($statustext),0,0,'C');
$pdf->setPage($endpage);

?>

 

The last section is not generating and we're not sure why, any assistance would be well received.

 

Thank you.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated