I started using SimpleInvoices yesterday and I am very impressed - it is exactly what I needed.
I have a question regarding how to add a function to the sql_queries.php. I need to show the due date on invoices. I created a new field in invoices table called due_date and I am using the invoice custom_field to add a number to each invoice for the # days until due (ex. 5 ) since it varies by invoice. I can manually update the data base and display the result in my template using (Due Date: {$invoice.due_date}) based on lines I have added to sql_queries.php.
I have it working in my invoice template. I do not want to manually update the database, but I do not know how to update sql_queries.php to reflect what I am doing manually, as follows:
UPDATE si_invoices SET `due_date` = DATE_ADD( `date`, INTERVAL `custom_field3` DAY) WHERE `custom_field3`>0
If someone can show me how to add this to the sql_queries.php, I am sure this will be useful to others who may want to do the same and I will post all of the changes in a final summary.
Thanks in advance!
Never mind my question. It is easier to use a smarty plugin and it works perfect to calculate the due date based on the custom field. Probably not the best method, but here is what I used if it is useful:
Add a custom_field to the invoices with label like Payment Terms or Due Date. I used custom_field3, but any field will work, just change the code below as needed.
Insert in invoice template the following where you want the due date - {due_date field1=$invoice.date field2=$invoice.custom_field3}
Here is the code for the plugin (save to the invoice plugin folder). Name the code function_due_date.php
<?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);
}
}
?>
hey 21st
thanks for posting your code ! sure to help others who want due date on invoices
cheers
justin
It looks like you're new here. If you want to get involved, click one of these buttons!