Payment before - Invoice Due Date
Our customers pay via a variety of payment options, and some of them can take up to 8-12 days before we see the deposit, we have put all our service to create an invoice 30 days before the Next Due Date, but it does not help something when there's going to be the same Due Date on the invoice.
Example a service going from 01.01.2013 to 01.07.2013 so there will be issued a new invoice on 01.06.2013, but there is still Due Date 01.07.2013 which is the date when service stops and we see first payment on 12.07.2013 as the service will be suspended 8-12 days, we receive payment approx. 12 days So we need an opportunity to set the number of days of Payment before.
So the invoice is issued on 01.06.2013 can get a payment date of 14 days as final due payment will be the 15.06.2013 there will be time to record payment before suspended date 01.07.2013 + 0 to 4 days.
This would be great if it was made so it could be put to customer groups.
Hey there,
If the product expires on 2013-01-01, the invoice would probably have been generated 14 days in advance, so the invoice would be in Unpaid status since it was generated, right?
I believe you can setup your invoice notifications to fire up 14 days after due date, so this way your customer is only notified about the Unpaid invoice 14 days after the product due date.
Sorry if I'm understanding your needs incorrectly.
I think the original poster meant, If I create a new product invoice for you today, but want a due date in 15 days, as it is currently setup: You will immediately be past due on the invoice created today, even if you wanted a due date 15 days from now.
Ive had this issue when I am creating invoices for customers that were not being tracked in WHMCS until now. They end up getting invoice nastygrams way earlier than thier intended due dates.
$sql = "UPDATE tblinvoices SET duedate = '".$newdate."' WHERE id = ".$invoiceid;
add_hook("InvoiceCreated",1,"setDueDate");
This I believe can be simulated with some settings in WHMCS, but one important thing is missing: The due date will always be wrong one way or the other. We need the possibility to have a different duedate on invoice and product. This is important for us and most enterprises in EU that does not want to change their customer billing just because they started using WHMCS.
This would solve my problem as well. When I add a new order for a client, an invoice is generated with a due date of the same date! That is often unrealistic. If I could enter a due date on the order, of a week or so out, that would work fine. The client wouldn't get an overdue noticed the day after placing an order, and I wouldn't have to manually edit the invoices generated for new orders.
Actually we would like a field to set the invoice due date X-many days before the expiry/renewal date of a service to eliminate similar issues. This functionality exists already in WHMCS for Domain names. But not the same for services, such as hosting.
automatically set the new due date on invoice date when client make payment.
I made solution for me like this - works well for me.
If you wanna have different payment days for customers, create a custom field(i.e. Rechnungstage)
Create a file /includes/hooks/InvoiceCreationPreEmail.php
Content:
<?php
/*
change due date after invoicing
*/
$CUSTOM_FIELD_NAME = 'Rechnungstage';
$DEFAULT_DAYS = 30;
function setDueDate($vars)
{
global $CUSTOM_FIELD_NAME, $DEFAULT_DAYS;
$invoiceId = $vars['invoiceid'];
$sql = "SELECT userid FROM tblinvoices WHERE id = ".$invoiceId;
$result = mysql_query($sql);
$numrows = mysql_num_rows($result);
if ($numrows > 0)
{
$numdays = $DEFAULT_DAYS;
// Get clients id
$row = mysql_fetch_array($result);
$clientId = $row[0];
// Find number of days before due date for client
$sql = "SELECT DISTINCT cv.value FROM tblcustomfieldsvalues AS cv JOIN tblcustomfields AS cf ON cv.fieldid = cf.id WHERE cf.fieldname LIKE '".$CUSTOM_FIELD_NAME."' AND cv.relid = ".$clientId;
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
if (!empty($row['value'])) $numdays = $row['value'];
}
// Update due date
$sql = "UPDATE tblinvoices SET duedate = date_add(date, interval ".$numdays." day) WHERE id = ".$invoiceId;
mysql_query($sql);
}
}
add_hook("InvoiceCreationPreEmail",1,"setDueDate");
?>
Hello,
The script is automatic or it must be triggered manually?
I can see from the code that he's using a hook - so it will be automatic. It's quite clever and I'll be using this as I want payment terms of 14 days for all Bank Transfers. I'll be able to change his code to look up the Payment Method and set the due date if the Payment Method = Bank Transfer.
https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicecreationpreemail
That's the hook that's being used. It's a shame there's not a comprehensive API so the read and update database operations can be changed into API calls.
Either way, thanks a bunch U2 Pas!
I can see from the code that he's using a hook - so it will be automatic. It's quite clever and I'll be using this as I want payment terms of 14 days for all Bank Transfers. I'll be able to change his code to look up the Payment Method and set the due date if the Payment Method = Bank Transfer.
https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicecreationpreemail
That's the hook that's being used. It's a shame there's not a comprehensive API so the read and update database operations can be changed into API calls.
Either way, thanks a bunch U2 Pas!
Here is an updated hook code that uses the whmcs 7 API.
it basically does this:
if the due date of an invoice would be behind the invoice date then set the due date to invoice date+days set in the settings that invoices are normally generated before a due date:
//Get current invoice and due date
$params = array(
"invoiceid" => $vars["invoiceid"]
);
$result = localAPI("GetInvoice",$params);
$format = "Y-m-d";
$duedate = date_create_from_format($format, $result["duedate"]);
$date = date_create_from_format($format, $result["date"]);
//get how many days are normally between due date and invoice date:
$result = localAPI("GetConfigurationValue",array("setting" => "CreateInvoiceDaysBefore"));
$days = $result["value"];
if($duedate<=$date){
$duedate = date_add($date,date_interval_create_from_date_string($days.' days'));
$duedate_sql = date_format($duedate, 'Y-m-d');
$params = array(
"invoiceid" => $vars["invoiceid"],
"duedate" => $duedate_sql
);
$result = localAPI("UpdateInvoice",$params);
}
}
add_hook("InvoiceCreation",1,"setDueDate");
I am upgrading to the latest WHMCS and am updating all my hooks. I re-wrote this one to use the Internal API. It sets the due date for all bank transfers based on defined payment term.
<?php
function setDueDate($vars)
{
// Number of days client has to pay an invoice
$PAYMENT_TERM = 14;
// Get the invoice id
$invoiceId = $vars['invoiceid'];
$params = array(
'invoiceid' => $invoiceId
);
// Get invoice and cast to an Object (I prefer working with objects)
$invoice = (object) localAPI('GetInvoice', $params);
if ($invoice->result == 'success' && $invoice->paymentmethod == 'banktransfer') {
// Calculate the due date
$dueDate = new DateTime($invoice->date);
$dueDate->add(new DateInterval('P' . $PAYMENT_TERM . 'D'));
// Update the invoice
$params = array(
'invoiceid' => $invoiceId,
'duedate' => $dueDate->format('Y-m-d')
);
$result = (object) localAPI('UpdateInvoice', $params);
}
}
// Update due date when invoice is created or gateway is changed
add_hook("InvoiceCreationPreEmail", 1, "setDueDate");
add_hook("InvoiceChangeGateway", 1, "setDueDate");
Comments have been locked on this page!