Jump to content

Text at top right of PDF Invoice


jrnetwork

Recommended Posts

Hello,

 

I've got the following in my invoicepdf.tpl file, and all I've changed are is the size and colour. I'd like to know if there is a status for Overdue that I can use so that when an overdue invoice goes out, the text panel at the top right is red. Happy to add a string to my language override file if need bed.

 

I can see there are the standard ones for Paid, Cancelled etc, but would like to know if there is one for Overdue?

 

Look forward to any replies.

 

# Invoice Status

$statustext = $_LANG['invoices'.strtolower($status)];

$pdf->SetFillColor(71,181,232);

$pdf->SetDrawColor(0,129,200);

if ($status=="Paid") {

$pdf->SetFillColor(151,223,74);

$pdf->SetDrawColor(110,192,70);

}elseif ($status=="Cancelled") {

$pdf->SetFillColor(200);

$pdf->SetDrawColor(140);

} elseif ($status=="Refunded") {

$pdf->SetFillColor(131,182,218);

$pdf->SetDrawColor(91,136,182);

} elseif ($status=="Collections") {

$pdf->SetFillColor(3,3,2);

$pdf->SetDrawColor(127);

}

Link to comment
Share on other sites

I think those statuses are hard-coded into WHMCS and there isn't one for Overdue...

 

however, you could do this with a bit of PHP - i.e., check if today's date is after the due date, and the invoice is unpaid...

 

unfortunately, I don't have any overdue invoices to test this with, but I think the following code should work...

 

$today = new DateTime('now');
$deadline = new DateTime($duedate);
if (($today > $deadline) and ($status=="Unpaid")) {
$overdue = "Overdue" ;
}

# Invoice Status
$statustext = $_LANG['invoices'.strtolower($status)];
$pdf->SetFillColor(223,85,74);
$pdf->SetDrawColor(171,49,43);
if ($status=="Paid") {
   $pdf->SetFillColor(151,223,74);
   $pdf->SetDrawColor(110,192,70);
}elseif ($status=="Cancelled") {
   $pdf->SetFillColor(200);
   $pdf->SetDrawColor(140);
} elseif ($status=="Refunded") {
   $pdf->SetFillColor(131,182,218);
   $pdf->SetDrawColor(91,136,182);
} elseif ($status=="Collections") {
   $pdf->SetFillColor(3,3,2);
   $pdf->SetDrawColor(127);
} elseif ($overdue=="Overdue") {    
   $pdf->SetFillColor(223,85,74);
   $pdf->SetDrawColor(171,49,43);
}
$pdf->SetXY(0,0);
$pdf->SetFont('freesans','B',28);
$pdf->SetTextColor(255);
$pdf->SetLineWidth(0.75);
$pdf->StartTransform();
$pdf->Rotate(-35,100,225);
if ($overdue=="Overdue"){
$pdf->Cell(100,18,strtoupper($_LANG['invoiceoverdue']),'TB',0,'C','1');
}
else
{
$pdf->Cell(100,18,strtoupper($statustext),'TB',0,'C','1');
}
$pdf->StopTransform();
$pdf->SetTextColor(0);

when I coded this to test, I hard-coded the output - but as you mentioned language files, i've now tweaked it to use an entry in the language files - there wasn't an existing appropriate entry, so you'll have to create one for each language required and place them in the language override files - http://docs.whmcs.com/Language_Overrides

 

$_LANG['invoiceoverdue'] = "Overdue";

hopefully, you'll be able to test this against overdue invoices and confirm that it works! :)

Link to comment
Share on other sites

Hi Brian,

 

I gave that a whirl and used my language override file to put this entry in:

 

$_LANG['invoiceoverdue'] = "Overdue";

 

When I put the following code into my invoicepdf.tpl file, it worked great for an invoice that was overdue. The only change I made to it was for the size of the text and the rotation of the object, so I made this change:

 

$pdf->SetFont('freesans','B',18);

 

and

 

$pdf->Rotate(-35,105,230);

 

When I view a pdf of an invoice that is overdue, it looks perfect, spot on. However now when I view any other invoice that is yet to be paid but not overdue, I get a massive error on the screen. Here's the code I used in full, would you mind trying that at your end to see what's causing the error:

 

 

# Determine if invoice is overdue
$today = new DateTime('now');
$deadline = new DateTime($duedate);
if (($today > $deadline) and ($status=="Unpaid")) {
$overdue = "Overdue" ;
}

# Invoice Status
$statustext = $_LANG['invoices'.strtolower($status)];
$pdf->SetFillColor(223,85,74);
$pdf->SetDrawColor(171,49,43);
if ($status=="Paid") {
   $pdf->SetFillColor(151,223,74);
   $pdf->SetDrawColor(110,192,70);
}elseif ($status=="Cancelled") {
   $pdf->SetFillColor(200);
   $pdf->SetDrawColor(140);
} elseif ($status=="Refunded") {
   $pdf->SetFillColor(131,182,218);
   $pdf->SetDrawColor(91,136,182);
} elseif ($status=="Collections") {
   $pdf->SetFillColor(3,3,2);
   $pdf->SetDrawColor(127);
} elseif ($overdue=="Overdue") {
   $pdf->SetFillColor(223,85,74);
   $pdf->SetDrawColor(171,49,43);
}
$pdf->SetXY(0,0);
$pdf->SetFont('freesans','B',18);
$pdf->SetTextColor(255);
$pdf->SetLineWidth(0.75);
$pdf->StartTransform();
$pdf->Rotate(-35,105,230);
if ($overdue=="Overdue"){
$pdf->Cell(100,18,strtoupper($_LANG['invoiceoverdue']),'TB',0,'C','1');
}
else
{
$pdf->Cell(100,18,strtoupper($statustext),'TB',0,'C','1');
}
$pdf->StopTransform();
$pdf->SetTextColor(0);

 

Cheers :)

Link to comment
Share on other sites

Hi,

 

I tried your code changes and it works fine for me - i've got an invoice that is unpaid but not overdue and it shows correctly as unpaid in the pdf... i've tried this on our modified invoicepdf.tpl and also the one that comes with "default" template... i'm using v5.3.5

 

btw, I like your font size change, I may go with that from now on!

 

when you say "massive error", what are you seeing?

Link to comment
Share on other sites

ok, here's an update to the above code...

 

i've rewritten the first section to pull the info from the database and perform come calculations on the two dates... the second section of code remains the same...

 

# Determine if invoice is overdue
$today = date("Y-m-d");

$query = mysql_query("SELECT * FROM tblinvoices WHERE id=$invoicenum");
$result = mysql_fetch_array($query);
$deadline = $result["duedate"];

$timestamp_start = strtotime($today);
$timestamp_end = strtotime($deadline);
$difference = $timestamp_end - $timestamp_start;
$days = floor($difference/(60*60*24));

if (($days < 0) and ($status=="Unpaid")) {
$overdue = "Overdue" ;
}

so $today is now calculated in the easiest way and formatted the same as other dates in the database.

second block pulls the duedate from the database.

third block converts the dates to a unix timestamp, calculates the difference between them and then converts into days...

fourth block decides if invoice is overdue and unpaid and if so creates $overdue :idea:

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