| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- // this hook offsets the due date of an invoice using order grace days
- if (!defined("WHMCS"))
- die("This file cannot be accessed directly");
- use WHMCS\Database\Capsule;
- function get_grace() {
- $grace = Capsule::table('tblconfiguration')->where('setting', 'OrderDaysGrace')->first();
- return $grace->value;
- }
- add_hook('InvoiceCreation', 1, function($vars) {
- $invoice = localAPI('GetInvoice', ['invoiceid' => $vars['invoiceid']]);
- $dueDate = date_create($invoice['duedate']);
- $invoiceDate = date_create($invoice['date']);
- if($dueDate <= $invoiceDate) {
- $grace = get_grace();
- array_shift($invoice);
- 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;
- }
- logModuleCall(
- 'InvoiceCreation',
- __FUNCTION__,
- $result,
- "Hook Error",
- $invoice
- );
- return false;
- }
- return true;
- });
- ?>
|