| 1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- // this hook offsets the due date of an invoice for add fund 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']]);
- if($invoice['duedate'] == $invoice['date']) {
- $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');
- $result = localAPI('UpdateInvoice', $invoice);
- if($result['result'] == 'success') {
- return true;
- }
- logModuleCall(
- 'InvoiceCreation',
- __FUNCTION__,
- $result,
- "Hook Error",
- $invoice
- );
- return false;
- }
- return true;
- });
- ?>
|