Add method to retrieve customer payment terms number

Introduced `getPaymentTermsNumber` method in the customer helper to fetch payment terms directly from the customer object. Refactored invoice drafts endpoint to use this method, ensuring cleaner and more reliable access to payment terms data.
This commit is contained in:
Jepp9350
2025-03-10 16:48:32 +01:00
parent 48ad281baa
commit aa07219b7a
2 changed files with 12 additions and 5 deletions
@@ -59,10 +59,6 @@ class economic_invoices_drafts_endpoint
// Get the date
$date = date('Y-m-d');
// Get the payment terms
$paymentTermsNumber = (int)(new economic())->config->payment_terms->getVariableValue();
// Get the customer object
$customer = (new economic())->getCustomer($customer_number);
@@ -87,7 +83,7 @@ class economic_invoices_drafts_endpoint
// Set the payment terms to the default payment terms (This is defined in the E-conomic module settings)
'paymentTerms' => [
'paymentTermsNumber' => $paymentTermsNumber
'paymentTermsNumber' => (int)$customer->getPaymentTermsNumber(),
],
// Set the customer number
@@ -193,4 +193,15 @@ class economic_customer
return $this->customer_data_object->country;
}
/**
* Get the customers payment terms number
* @return int The customers payment terms number
* @throws Exception if the customer data is invalid or empty
*/
public function getPaymentTermsNumber(): int
{
self::requireSelected();
return $this->customer_data_object->paymentTerms->paymentTermsNumber;
}
}