Jump to content

Working on a customization for the PDF invoice - testing dates


siteone

Recommended Posts

I'm working on a customization to the invoicepdf.tpl file to have the 'unpaid' messages change based on the current date's relationship to the date created and the due date. Here's the code I am working on, which should be reasonably easy to figure out:

 

 

		
               $today = date("Y/d/m");
	if ($datecreated === $today) {
		$statustext = $_LANG["invoicesfirsttime"];
		$pdf->SetFont('helvetica','B',12);
		$pdf->SetTextColor(0,0,151);

	} elseif ($datecreated < $today && $today < $duedate) {
		$statustext = $_LANG["invoicesunpaid"];
		$pdf->SetFont('helvetica','B',12);
		$pdf->SetTextColor(0,0,151);

	} elseIf($today > $duedate) {
		$statustext = $_LANG["invoicesoverdue"];
		$pdf->SetFont('helvetica','B',12);
		$pdf->SetTextColor(204,0,0);
	}

 

The problem is that it's always giving me the "overdue" message (which is defined in the language file, BTW). So, the date comparison isn't working; I think it has something to do with the format of the$datecreated and $duedate fields as compared to the way I'm getting and formatting the $today field. Any ideas on where I'm going wrong?

Link to comment
Share on other sites

  • 5 weeks later...

I finally got the modification working. Change the following code around lines 113-129:

 

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('helvetica','B',40);

 

with the following:

 

switch ($status) {

case "Cancelled" :
	$statustext = $_LANG["invoicescancelled"];
	$pdf->SetFont('helvetica','B',15);
	$pdf->SetTextColor(245,245,245);
	break;

case "Unpaid" :
	$today = date("m/d/Y", time());

	if ($datecreated === $today) {
		// Invoice created today so first time
		$statustext = $_LANG["invoicesfirsttime"];
		$pdf->SetFont('helvetica','B',12);
		$pdf->SetTextColor(0,0,151);

	} elseif ($datecreated < $today && $today < $duedate) {
		// invoice unpaid not due yet
		$statustext = $_LANG["invoicesunpaid"];
		$pdf->SetFont('helvetica','B',12);
		$pdf->SetTextColor(0,0,151);

	} elseIf($today > $date_due) {
		// invoice overdue
		$statustext = $_LANG["invoicesoverdue"];
		$pdf->SetFont('helvetica','B',10);
		$pdf->SetTextColor(204,0,0);
	}
	break;

case "Paid" :
	$statustext = $_LANG["invoicespaid"];
	$pdf->SetFont('helvetica','B',20);
	$pdf->SetTextColor(153,204,0);
	break;

case "Refunded" :
	$statustext = $_LANG["invoicesrefunded"];
	$pdf->SetFont('helvetica','B',20);
	$pdf->SetTextColor(34,68,136);
	break;

case "Collections" :
	$statustext = $_LANG["invoicescollections"];
	$pdf->SetFont('helvetica','B',20);
	$pdf->SetTextColor(255,204,0);

default:
	break;
}

 

Essentially, it changes the conditionals to a SWITCH statement (easier for me to debug) and changes the "UNPAID" section to use the dates to display the appropriate message.

 

Note that you will also need to add the $_LANG["invoicesfirsttime"] and $_LANG["invoicesoverdue"] lines to the language file.

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