diff --git a/services/nginx/app/modules/economic/endpoints/invoices/economic_invoices_drafts_endpoint.php b/services/nginx/app/modules/economic/endpoints/invoices/economic_invoices_drafts_endpoint.php index 550799fa..dcfcf9ea 100644 --- a/services/nginx/app/modules/economic/endpoints/invoices/economic_invoices_drafts_endpoint.php +++ b/services/nginx/app/modules/economic/endpoints/invoices/economic_invoices_drafts_endpoint.php @@ -3,6 +3,7 @@ namespace endpoints\orders; use classes\economic; +use Exception; use traits\economic_endpoint_t; class economic_invoices_drafts_endpoint @@ -49,6 +50,7 @@ class economic_invoices_drafts_endpoint * @param int $customer_number The E-conomic customer number * @param string $external_id The external id of the invoice * @return object {id: number, getExternalId: string} + * @throws Exception If the request fails */ public function add(int $customer_number, string $external_id = ''): object { @@ -65,10 +67,10 @@ class economic_invoices_drafts_endpoint $customer = (new economic())->getCustomer($customer_number); // Set the recipient details - $customer_name = $customer->name ?? 'Ukendt'; - $customer_address = $customer->address ?? 'Ukendt'; - $customer_zip = $customer->zip ?? 'Ukendt'; - $customer_city = $customer->city ?? 'Ukendt'; + $customer_name = $customer->getName() ?? 'Ukendt'; + $customer_address = $customer->getAddress() ?? 'Ukendt'; + $customer_zip = $customer->getZipCode() ?? 'Ukendt'; + $customer_city = $customer->getCity() ?? 'Ukendt'; // Send the request $response = $this->send_request( @@ -126,7 +128,7 @@ class economic_invoices_drafts_endpoint // Return the response as an object try { return json_decode($response)->draftInvoiceNumber == $draft_invoice_number; - } catch (\Exception $e) { + } catch (Exception $e) { return false; } } diff --git a/services/nginx/app/modules/economic/helpers/economic_customer.php b/services/nginx/app/modules/economic/helpers/economic_customer.php index c6a31dbe..04e5665b 100644 --- a/services/nginx/app/modules/economic/helpers/economic_customer.php +++ b/services/nginx/app/modules/economic/helpers/economic_customer.php @@ -126,4 +126,71 @@ class economic_customer self::requireSelected(); return $this->customer_data_object; } + + /** + * Get the customer name + * @return string The customer name + * @throws Exception if the customer data is invalid or empty + */ + public function getName(): string + { + self::requireSelected(); + return $this->customer_data_object->name; + } + + /** + * Get the customer email + * @return string The customer email + * @throws Exception if the customer data is invalid or empty + */ + public function getEmail(): string + { + self::requireSelected(); + return $this->customer_data_object->email; + } + + /** + * Get the customer address + * @return string The customer address + * @throws Exception if the customer data is invalid or empty + */ + public function getAddress(): string + { + self::requireSelected(); + return $this->customer_data_object->address; + } + + /** + * Get the customer postal code + * @return string The customer postal code + * @throws Exception if the customer data is invalid or empty + */ + public function getZipCode(): string + { + self::requireSelected(); + return $this->customer_data_object->zip; + } + + /** + * Get the customer city + * @return string The customer city + * @throws Exception if the customer data is invalid or empty + */ + public function getCity(): string + { + self::requireSelected(); + return $this->customer_data_object->city; + } + + /** + * Get the customer country + * @return string The customer country + * @throws Exception if the customer data is invalid or empty + */ + public function getCountry(): string + { + self::requireSelected(); + return $this->customer_data_object->country; + } + } \ No newline at end of file diff --git a/services/nginx/app/routes/customerSearchRoute.php b/services/nginx/app/routes/customerSearchRoute.php index 8c37a14f..ed19876b 100644 --- a/services/nginx/app/routes/customerSearchRoute.php +++ b/services/nginx/app/routes/customerSearchRoute.php @@ -14,6 +14,7 @@ class customerSearchRoute public function run(): void { + //TODO: Remove this, this is deprecated in favor of the new search endpoint $this->post('/customers/search', function () { // Require the user to be logged in global $response;