Jump to content

Multi Page PDF Invoice


tandyuk

Recommended Posts

I use WHMCS to handle all of my billing, that is online services and offline.

I have just tried to create an invoice with a lot of items, and discovered that WHMCS does not support multi page pdf invoices.

 

I've just fixed the problem so my modified pdfconfig.php is attached.

Hopefully this can be included in the next release of whmcs, possibly with a better method of working out where the end of the page is.

 

Regards,

James

 

 

<?php
# Logo
$pdf->Image(ROOTDIR.'/images/logo.jpg',20,25);
# Company Details
$pdf->SetFont('Arial','',13);
$pdf->Cell(0,6,$companyname,0,1,'R');
$pdf->SetFont('Arial','',;
for ( $i = 0; $i <= 4; $i += 1) {
       $pdf->Cell(0,4,trim($companyaddress[$i]),0,1,'R');
}
$pdf->Ln(5);
# Header Bar
$invoiceprefix = $_LANG["invoicenumber"];
$pdf->SetFont('Arial','B',15);
$pdf->SetFillColor(239);
$pdf->Cell(0,8,$invoiceprefix.$invoicenum,0,1,'L','1');
$pdf->SetFont('Arial','',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);
# Status
$pdf->SetXY(70,60);
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);
}
$pdf->SetFont('Arial','B',40);
$pdf->Cell(120,20,strtoupper($statustext),0,0,'C');
#Reset Font/Colour
$pdf->SetFont('Arial','',10);
        $pdf->SetTextColor(0,0,0);
$pdf->SetXY(20,90);
# Clients Details
$pdf->Cell(0,4,$_LANG["invoicesinvoicedto"],0,1);
$pdf->SetFont('Arial','',;
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'); } $
       $pdf->Cell(0,4,$clientsdetails["firstname"]." ".$clientsdetails["lastname"],0,1,'L');
}
$pdf->SetFont('Arial','',;
$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');
$pdf->Ln(10);
$pdf->SetDrawColor(200);
$pdf->SetFont('Arial','B',10);
$pdf->SetFillColor(239);
$pdf->Cell(130,7,$_LANG["invoicesdescription"],1,0,'C','1');
$pdf->Cell(40,7,$_LANG["invoicesamount"],1,0,'C','1');
$pdf->Ln();
$pdf->SetFont('Arial','',10);
#Invoice Items
foreach ($invoiceitems AS $item) {
   if (strlen($item["description"])>75) {
       $numlines = ceil(strlen($item["description"])/75);
       $cellheight = $numlines * 5;
       $pdf->MultiCell(130,$cellheight,$item["description"],1,'L','',0);
       $pdf->MultiCell(40,$cellheight,$currencysymbol.$item["amount"],1,'C','',0);
       $pdf->SetXY(20,$pdf->GetY());
   } else {
       $pdf->Cell(130,6,$item["description"],1);
       $pdf->Cell(40,6,$currencysymbol.$item["amount"],1,0,'C');
   }
   $pdf->Ln();
   #Add new page?
   if($pdf->GetY() > 260){
       $pdf->addPage();
   }
}
$pdf->SetFont('Arial','B',10);
$pdf->Cell(130,7,$_LANG["invoicessubtotal"],1,0,'R','1');
$pdf->Cell(40,7,$currencysymbol.$subtotal,1,0,'C','1');
$pdf->Ln();
if ($taxrate!="0.00") {
       $pdf->Cell(130,7,$taxrate."% ".$taxname,1,0,'R','1');
       $pdf->Cell(40,7,$currencysymbol.$tax,1,0,'C','1');
       $pdf->Ln();
}
if ($taxrate2!="0.00") {
       $pdf->Cell(130,7,$taxrate2."% ".$taxname2,1,0,'R','1');
       $pdf->Cell(40,7,$currencysymbol.$tax2,1,0,'C','1');
       $pdf->Ln();
}
$pdf->Cell(130,7,$_LANG["invoicescredit"],1,0,'R','1');
$pdf->Cell(40,7,$currencysymbol.$credit,1,0,'C','1');
$pdf->Ln();
$pdf->Cell(130,7,$_LANG["invoicestotal"],1,0,'R','1');
$pdf->Cell(40,7,$currencysymbol.$total,1,0,'C','1');
$pdf->Ln();
$pdf->Ln();
if ($notes) {
       $pdf->SetFont('Arial','',;
       $pdf->MultiCell(170,5,$_LANG["invoicesnotes"].": $notes");
}
?>

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