move_fund_invoice_due_date.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. // this hook offsets the due date of an invoice for add fund using order grace days
  3. if (!defined("WHMCS"))
  4. die("This file cannot be accessed directly");
  5. use WHMCS\Database\Capsule;
  6. function get_grace() {
  7. $grace = Capsule::table('tblconfiguration')->where('setting', 'OrderDaysGrace')->first();
  8. return $grace->value;
  9. }
  10. add_hook('InvoiceCreation', 1, function($vars) {
  11. $invoice = localAPI('GetInvoice', ['invoiceid' => $vars['invoiceid']]);
  12. if($invoice['duedate'] == $invoice['date']) {
  13. $grace = get_grace();
  14. array_shift($invoice);
  15. $dateTime = date_create($invoice['duedate']);
  16. date_add($dateTime,date_interval_create_from_date_string("$grace days"));
  17. $invoice['duedate'] = date_format($dateTime, 'Y-m-d');
  18. $result = localAPI('UpdateInvoice', $invoice);
  19. if($result['result'] == 'success') {
  20. return true;
  21. }
  22. logModuleCall(
  23. 'InvoiceCreation',
  24. __FUNCTION__,
  25. $result,
  26. "Hook Error",
  27. $invoice
  28. );
  29. return false;
  30. }
  31. return true;
  32. });
  33. ?>