andre 1 year ago
parent
commit
7de93d240d
1 changed files with 13 additions and 14 deletions
  1. 13 14
      move_fund_invoice_due_date.php

+ 13 - 14
move_fund_invoice_due_date.php

@@ -12,28 +12,27 @@ function get_grace() {
 }
 
 add_hook('InvoiceCreation', 1, function($vars) {
-    $grace = get_grace();
     $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;
     }
-    if($result['result'] == 'success') {
-        return true;
-    }
-    
-    logModuleCall(
-        'InvoiceCreation',
-        __FUNCTION__,
-        $result,
-        "Hook Error",
-        $invoice
-    );
-
-    return false;
+    return true;
 });
 
 ?>