Jump to content

need some help with modify the pdf invoice


Recommended Posts

Hello everyone.

i hope everyone is doing great. i need again some help from the community. hope someone correct my invoicepdf tpl file so it can complete my demand.

i have done some modify but  i can't understand how to fix some more.

 

i want to make my invoice like this

pdfinvoice-page-001.thumb.jpg.6c597ff6b35b0ec4cb26674b8714ce34.jpg

 

and this is my current code. its already modified mostly

 

<?php

# Logo
$logoFilename = 'placeholder.png';
if (file_exists(ROOTDIR . '/assets/img/logo.png')) {
    $logoFilename = 'logo.png';
} elseif (file_exists(ROOTDIR . '/assets/img/logo.jpg')) {
    $logoFilename = 'logo.jpg';
}
$pdf->Ln(5);
$pdf->SetFont($pdfFont, 'B', 15);
$pdf->SetFillColor(255);
$pdf->SetFont($pdfFont, '', 16);
$pdf->Cell(100, 6, "My Bill Summary", 0, 1, 'L', '1');
$pdf->Image(ROOTDIR . '/assets/img/' . $logoFilename, 120, 25, 75);
# Company Details
$pdf->SetXY(15, 70);
$pdf->SetFont($pdfFont, '', 13);
foreach ($companyaddress as $addressLine) {
    $pdf->Cell(180, 4, trim($addressLine), 0, 1, 'R');
    $pdf->SetFont($pdfFont, '', 9);
}
if ($taxCode) {
    $pdf->Cell(180, 4, $taxIdLabel . ': ' . trim($taxCode), 0, 1, 'R');
}
$pdf->Ln(5);

# Clients Details
$pdf->SetXY(15, 70);
$pdf->SetFont($pdfFont, 'B', 10);
$pdf->SetFont($pdfFont, '', 9);
if ($clientsdetails["companyname"]) {
    $pdf->Cell(0, 4, $clientsdetails["companyname"], 0, 1, 'L');
    $pdf->Cell(0, 4, Lang::trans('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["postcode"], 0, 1, 'L');
$pdf->Cell(0, 4, $clientsdetails["country"], 0, 1, 'L');
if (array_key_exists('tax_id', $clientsdetails) && $clientsdetails['tax_id']) {
    $pdf->Cell(0, 4, $taxIdLabel . ': ' . $clientsdetails['tax_id'], 0, 1, 'L');
}
$pdf->Ln(10);
$pdf->Ln(10);
$pdf->Ln(10);
# Header Bar

/**
 * Invoice header
 *
 * You can optionally define a header/footer in a way that is repeated across page breaks.
 * For more information, see http://docs.whmcs.com/PDF_Invoice#Header.2FFooter
 */

$pdf->SetFont($pdfFont, 'B', 15);
$pdf->SetFillColor(239);
$pdf->SetFont($pdfFont, '', 12);
if ($customfields) {
    foreach ($customfields as $customfield) {
        $pdf->Cell(125, 6, $customfield['fieldname'] . ':                                                            ' . $customfield['value'], 0, 1, 'L', '1');
    }
}
$pdf->Cell(125, 6, "Invoice Number " . ':                                                               ' . $invoiceid, 0, 1, 'L', '1');
$pdf->Cell(125, 6, "Bill Issue Date" . ':                                                              ' . $datecreated, 0, 1, 'L', '1');
$pdf->Cell(125, 6, "Billing Period" . ':                                                              ' . $datecreated, 0, 1, 'L', '1');
$pdf->Ln(10);
                                     
$startpage = $pdf->GetPage();

# Invoice Items
$tblhtml = '<table width="70%" bgcolor="#ccc" cellspacing="1" cellpadding="2" border="0">
    <tr height="30" bgcolor="#efefef" style="font-weight:bold;text-align:center;">
        <td width="80%">' . Lang::trans('invoicesdescription') . '</td>
        <td width="20%">' . Lang::trans('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::trans('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::trans('invoicescredit') . '</td>
        <td align="center">' . $credit . '</td>
    </tr>
    <tr height="30" bgcolor="#efefef" style="font-weight:bold;font-size:14px;">
        <td align="right">' . "Total Amount Due" . '</td>
        <td align="center">' . $total . '</td>
    </tr>
</table>';

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

$pdf->Ln(5);

if ($status == 'Unpaid'){
$html = "<h2 style=\"color:red;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Please pay by ${duedate} </h2>";
$pdf->writeHTML($html, true, false, false, false, '');
$pdf->Ln(10);
$pdf->SetFont($pdfFont, 'B', 15);
$pdf->SetFillColor(239);
$pdf->SetFont($pdfFont, '', 10);
$pdf->Cell(125, 6, "Failure to pay your account in full may result in loss of service.", 0, 1, 'L', '1');
$pdf->Cell(125, 6, "Reactivation of your service could take up to 7 days and will incur a fee. ", 0, 1, 'L', '1');
$pdf->Ln(10);
}
# Notes
if ($notes) {
    $pdf->Ln(5);
    $pdf->SetFont($pdfFont, '', 8);
    $pdf->MultiCell(170, 5, Lang::trans('invoicesnotes') . ': ' . $notes);
}

/**
 * Invoice footer
 */

============================

can someone please correct the code so my pdf invoice will be looks same like the image i provide

 

 

thanks everyone and plesae stay safe

Link to comment
Share on other sites

with regards to Billing Period on the grey banner, what happens if the invoice contains multiple products all with different billing cycles ?

increasing the font size is just adding 1 to the setfont numeric value, and bold is just adding 'B' instead of ''

Link to comment
Share on other sites

On 7/13/2020 at 4:25 PM, brian! said:

with regards to Billing Period on the grey banner, what happens if the invoice contains multiple products all with different billing cycles ?

increasing the font size is just adding 1 to the setfont numeric value, and bold is just adding 'B' instead of ''

thanks brian for reply.. yes its good point. but i will be have only one product in the invoice. one customer = one product only

can it possible to do?

Link to comment
Share on other sites

19 hours ago, sokalsondha said:

yes its good point. but i will be have only one product in the invoice. one customer = one product only

that simplifies the problem.

19 hours ago, sokalsondha said:

can it possible to do?

to get the billing period, it might be necessary to run a database query to pull the value directly from the tblhosting table (you could work it out from the dates if you had to, but it's much simpler to just get it from the database!) - then you'd have to decide if you're just going to use that value, or whether it needs to be translated to the client's language.

Link to comment
Share on other sites

4 hours ago, brian! said:

to get the billing period, it might be necessary to run a database query to pull the value directly from the tblhosting table (you could work it out from the dates if you had to, but it's much simpler to just get it from the database!) - then you'd have to decide if you're just going to use that value, or whether it needs to be translated to the client's language.

yes brian you are very right as always.. from the database pulling will be the best idea. i will try to work it out

thanks again for the kind help

Link to comment
Share on other sites

13 hours ago, sokalsondha said:

from the database pulling will be the best idea. i will try to work it out

the way to think of it is that you know you can easily get the invoice ID value from the template.. so then you're looking up the first result for that ID in tblinvoiceitems... if it's type is 'Hosting', then the relid value from invoiceitems will be the id value in tblhosting and then that can be used to return the billingcycle value... i've posted something similar previously before, so it would be along the lines of...

use WHMCS\Database\Capsule;

$billingcycle = Capsule::table('tblinvoiceitems')
->leftjoin('tblhosting', function ($join) {
	$join->on('tblinvoiceitems.relid', '=', 'tblhosting.id')
	->where('tblinvoiceitems.type', '=', 'Hosting');
})
->where('invoiceid', $id)
->value('billingcycle');

as written, if there are no products in the invoice, e.g it's domains only or a custom invoice etc, then $billingcycle will be empty - so i'd suggest checking to see that it's not before trying to output it.

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.

×
×
  • 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