|
|
@@ -1,6 +1,6 @@
|
|
|
<?php
|
|
|
|
|
|
-// this hook offsets the due date of an invoice for add fund using order grace days
|
|
|
+// this hook offsets the due date of an invoice using order grace days
|
|
|
|
|
|
if (!defined("WHMCS"))
|
|
|
die("This file cannot be accessed directly");
|
|
|
@@ -13,12 +13,13 @@ function get_grace() {
|
|
|
|
|
|
add_hook('InvoiceCreation', 1, function($vars) {
|
|
|
$invoice = localAPI('GetInvoice', ['invoiceid' => $vars['invoiceid']]);
|
|
|
- if($invoice['duedate'] == $invoice['date']) {
|
|
|
+ $dueDate = date_create($invoice['duedate']);
|
|
|
+ $invoiceDate = date_create($invoice['date']);
|
|
|
+ if($dueDate <= $invoiceDate) {
|
|
|
$grace = get_grace();
|
|
|
array_shift($invoice);
|
|
|
- $dateTime = date_create($invoice['duedate']);
|
|
|
- date_add($dateTime,date_interval_create_from_date_string("$grace days"));
|
|
|
- $invoice['duedate'] = date_format($dateTime, 'Y-m-d');
|
|
|
+ date_add($invoiceDate,date_interval_create_from_date_string("$grace days"));
|
|
|
+ $invoice['duedate'] = date_format($invoiceDate, 'Y-m-d');
|
|
|
$result = localAPI('UpdateInvoice', $invoice);
|
|
|
if($result['result'] == 'success') {
|
|
|
return true;
|