|
|
@@ -8,20 +8,32 @@ if (!defined("WHMCS"))
|
|
|
use WHMCS\Database\Capsule;
|
|
|
function get_grace() {
|
|
|
$grace = Capsule::table('tblconfiguration')->where('setting', 'OrderDaysGrace')->first();
|
|
|
+ return $grace->value;
|
|
|
}
|
|
|
|
|
|
-add_hook('PreInvoicingGenerateInvoiceItems', 1, function($vars) {
|
|
|
+add_hook('InvoiceCreation', 1, function($vars) {
|
|
|
$grace = get_grace();
|
|
|
-
|
|
|
+ $invoice = localAPI('GetInvoice', ['invoiceid' => $vars['invoiceid']]);
|
|
|
+ if($invoice['duedate'] == $invoice['date']) {
|
|
|
+ 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');
|
|
|
+ $result = localAPI('UpdateInvoice', $invoice);
|
|
|
+ }
|
|
|
+ if($result['result'] == 'success') {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
logModuleCall(
|
|
|
- 'PreInvoicingGenerateInvoiceItems',
|
|
|
+ 'InvoiceCreation',
|
|
|
__FUNCTION__,
|
|
|
- $vars,
|
|
|
- "Debug",
|
|
|
- $grace
|
|
|
+ $result,
|
|
|
+ "Hook Error",
|
|
|
+ $invoice
|
|
|
);
|
|
|
-
|
|
|
- return true;
|
|
|
+
|
|
|
+ return false;
|
|
|
});
|
|
|
|
|
|
?>
|