Hey everybody!
Like SimpleInvoices a lot and I'm being adopting it to my needs.
I have a simple modification for the invoice template to show a payment date
in the PDF. There's not more functionality but it's cool for me ... for now ;)
Just add a file called function.get_duedate.php in the plugin folder of your invoice template,
and enter the following code:
<?php<br />/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
* @author Thomas Hilburger, www.tnt-designstudio.de
*/
/**
* Due date plugin
*
* @param mixed $params Array with 'invoiceId' and 'length'. Length will be defaulted to 6, if not set.
* @param Object $smarty
* @example {invoiceNumber invoiceId=$invoice.id length=8}
*/
function smarty_function_get_duedate($params, &$smarty)
{
if(empty($params['days']))
{
$params['days'] = 14;
}
$timeInvoice = strtotime($params['invoiceDate']."+".$params['days']." days");
echo date("d.m.Y", $timeInvoice);
}
?>
Then you simply add the placeholder with this line
{get_duedate invoiceDate=$invoice.date days=14}
where you need it - enter the amount of days (default is 14 in the function) and you're done :)
Simple but useful I hope.
Best regards,
Thomas
Hi Thomas,
Interesting, but there's something else I 'd love to have and I silently hope you can help me out.
We make invoices 4 times a year (every quarter)
The invoices are generated every last month of the quarter and apply to the next quarter. (So end of march we make invoice for apr/may/jun)
I would like to print this period on the generated invoices, can you help me with this?
Kind regards & tnx
EDIT: also, when I add the placeholder to my template, I get a blanc screen on pdf generation. I guess I do something wrong?
Thanks for your contribution.
I somehow didn't look for a solution before I spent a few minutes last night to create a similar function.
Here is my solution to do the exact same thing:
[code]
<?php<br />
//function smarty_function_due_date($params, &$smarty)
/**
* Function: due_date
*
* Calculates the due date by adding the amount of days to the unix timestamp.
*
* Arguments:
*
* date - the default date output - in this format: eg: 25 May 2011
* days - amount of days to due date - eg: 14
*
* How to add to template:
*
* Paste this where you wish the due date to appear:
*
* {due_date date=$invoice.date days=14}
*
**/
function smarty_function_due_date($params, &$smarty)
{
if ($params['date'] != null AND $params['days'] != null) {
$today = htmlsafe($params[date]);
$days_to_add = htmlsafe($params[days]);
$timestamp = strtotime($today);
$due_date_stamp = strtotime($days_to_add.' day', $timestamp);
echo date('d M Y', $due_date_stamp);
}
}
?>
[/code]
Take this code and paste it into the a text-file. Call the text-file: function.due_date.php and upload it to the templates/invoices/default/plugins/ folder.
If you are using a different template to the default one, upload it into the plugins folder in your specific template directory.
SOLUTION to hide due date on quotes, estimates and receipts (make due date visible only on invoices):
1. First, follow tecjam's instructions above.
2. Make a slight adjustment to tecjam's line of code above which goes into your invoice template where you want the due date to appear: {due_date date=$invoice.date days=14}
ADD this code {if $preference.pref_id == 1 }
just BEFORE and this code {/if}
immediately AFTER. The code should now look something like this:
{if $preference.pref_id == 1 } Due Date: {due_date date=$invoice.date days=14} {/if}
Thanks tecjam for your wonderful plugin!
I found 4 methods to show the invoice payment due date. But being a newbie and a dummie, I could not get any of the methods to work . Pls be a bit more clear and specific (maybe I am over my head to try getting simple invoice to work, with so little knowledge.)
Method 1 and 2 : Smarty plug-in
http://www.simpleinvoices.org/forum/discussion/comment/9164/#Comment_9164
2 methods I will therefore called this method 1 and 2:
Method 1:
by hilburger
Step 1
copy following as function.get_duedate.php in
si/templates/invoices/default/plugins folder
(in method 3, naming is function_get_duedate.php, underscore instead of a period, does it matter?)
<?php<br />/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
* @author Thomas Hilburger, www.tnt-designstudio.de
*/
/**
* Due date plugin
*
* @param mixed $params Array with 'invoiceId' and 'length'. Length will be defaulted to 6, if not set.
* @param Object $smarty
* @example {invoiceNumber invoiceId=$invoice.id length=8}
*/
function smarty_function_get_duedate($params, &$smarty)
{
if(empty($params['days']))
{
$params['days'] = 14;
}
$timeInvoice = strtotime($params['invoiceDate']."+".$params['days']." days");
echo date("d.m.Y", $timeInvoice);
}
?>
Step 2:
In si/templates/invoices/default/template.tpl
add this line{get_duedate invoiceDate=$invoice.date days=14}
resulting in a blank page.
Method 2
Step1
copy following as function.get_duedate.php in
si/templates/invoices/default/plugins folder
<?php<br />
//function smarty_function_due_date($params, &$smarty)
/**
* Function: due_date
*
* Calculates the due date by adding the amount of days to the unix timestamp.
*
* Arguments:
*
* date - the default date output - in this format: eg: 25 May 2011
* days - amount of days to due date - eg: 14
*
* How to add to template:
*
* Paste this where you wish the due date to appear:
*
* {due_date date=$invoice.date days=14}
*
**/
function smarty_function_due_date($params, &$smarty)
{
if ($params['date'] != null AND $params['days'] != null) {
$today = htmlsafe($params[date]);
$days_to_add = htmlsafe($params[days]);
$timestamp = strtotime($today);
$due_date_stamp = strtotime($days_to_add.' day', $timestamp);
echo date('d M Y', $due_date_stamp);
}
}
?>
Step 2:
In si/templates/invoices/default/template.tpl
add this line {get_duedate invoiceDate=$invoice.date days=14}
resulting in a blank page.
Maybe it is not that simple as just adding the line {due_date date=$invoice.date days=14} into the template.tpl? I must be missing something!
Method 3 : sql_queries
http://www.simpleinvoices.org/forum/discussion/comment/4321/#Comment_4321
Step 1
Add to si/include/sql_queries.php, around line 950 (version 2010.2.update 1)
$invoice['due_date'] = date('d.m.Y', strtotime( $invoice['date'] . '+28 days' ) );
(do I need to change to d.m.Y to Y-m-d like the format in calc_date)
after these 2 existing lines
$invoice['calc_date'] = date('Y-m-d', strtotime( $invoice['date'] ) );
$invoice['date'] = siLocal::date( $invoice['date'] );
Step 2
in si/templates/invoices/default/template.tpl
I added
{$preference.pref_inv_wording|htmlsafe} {$LANG.due_date}:
{$invoice.due_date}
Step 3
I also add in lang file $LANG['due_date'] = "Due_date";//1
si/lang/en_GB folder .
The label showed up but not the value of due date???
What did I do wrong?
Did I put in the right folder?
Method 4 : input no. of due days in invoice custom field 3
(or other invoice custom field, adjust accordinginly)
http://www.simpleinvoices.org/forum/discussion/comment/5386/#Comment_5386
Step 1
save following lines as function_due_date.php
in si/templates/invoices/default/plugins folder
<?php<br />function smarty_function_due_date($params, &$smarty)
{
if ($params['field1'] != null && $params['field2'] != null) {
$due_date = date("m/d/Y",(($params['field2']*60*60*24)+strtotime($params['field1'])));
return ($due_date);
}
}
?>
Step 2
put in 14 in invoice custom field 3.
Step 3
in si/templates/invoices/default/template.tpl
add this line {due_date field1=$invoice.date field2=$invoice.custom_field3}
give me a blank page.
Hi guys, I found this thread very helpful. Just wanted to add my code here as well. This is what I wanted:
We have customers that have different payment terms (due dates) depending on what product/service that we provide. Some customers are on 30 days, some are on 7 etc. So I setup the customer custom field 1 to read 'Payment Terms'. I then set every customers payment terms to whatever integer is applicable.
I then edited my invoice template and included 'hillburgers' cool little duedate code (at the top of this thread). Once that was done I just plug my $customer.custom_field1 into hillburgers code, and hey-presto, now every customer can have their due date set for all invoices.
This is the code that hillburger adds to the template:
{get_duedate invoiceDate=$invoice.date days=14}
I changed this to:
{get_duedate invoiceDate=$invoice.date days=$customer.custom_field1}
took 10 mins, saved loads of hassle!
thanks for a really good little invoicing system.
Thanks for sharing! :o)