config = new economic_c(); $this->orders = new economic_orders_endpoint(); $this->invoices = new economic_invoices_endpoint(); $this->departments = new economic_departments_endpoint(); $this->layouts = new economic_layouts_endpoint(); $this->payment_terms = new economic_payment_terms_endpoint(); $this->customers = new economic_customers_endpoint(); $this->products = new economic_products_endpoint(); $this->helpers = new economic_helpers(); } /** * Get a customer by their customer number * @param int $customer_number The Economic customer number * @return economic_customer */ public function getCustomer(int $customer_number): economic_customer { return new $this->helpers->economic_customer($customer_number); } /** * Get a invoiceDraft (Helper) from the Economic system * @param int $draft_invoice_number The Economic draft invoice number * @param string $currency The conversion rate to use (default: DKK) * @param bool $skip_fetch Skip fetching the invoice draft from the Economic system (default: false) * @return economic_invoice_draft */ public function getInvoiceDraft(int $draft_invoice_number, string $currency = 'DKK', bool $skip_fetch = false): economic_invoice_draft { return new $this->helpers->economic_invoice_draft($draft_invoice_number, $currency, $skip_fetch); } /** * Get the tasks helper * @return economic_tasks */ public function getTasks(): economic_tasks { return new $this->helpers->economic_tasks(); } public function getTransactionDraftCustomerNumber(): ?int { $value = $this->config->transaction_draft_customer_number->getVariableValue(); if ($value === null || $value === '') { return null; } $customer_number = (int)$value; return $customer_number > 0 ? $customer_number : null; } public function isDraftCustomerNumber(?int $customer_number): bool { $configured_customer_number = $this->getTransactionDraftCustomerNumber(); if ($configured_customer_number === null || $customer_number === null) { return false; } return $configured_customer_number === (int)$customer_number; } /** * @throws \Exception */ public function assertCustomerNumberIsNotDraft(?int $customer_number): void { if ($this->isDraftCustomerNumber($customer_number)) { throw new \Exception(self::DRAFT_CUSTOMER_EXPORT_BLOCKED_MESSAGE); } } /** * Create a customer in e-conomic and return the raw upstream payload. */ public function createCustomer(int $customer_number, string $name, int $cvr_number, string $email, int $phone): object { return $this->customers->customers->create([ 'customerNumber' => $customer_number, 'corporateIdentificationNumber' => (string)$cvr_number, 'customerGroup' => [ 'customerGroupNumber' => 1, ], 'paymentTerms' => [ 'paymentTermsNumber' => 12, ], 'name' => $name, 'email' => $email, 'phone' => $phone, 'currency' => 'DKK', 'vatZone' => [ 'vatZoneNumber' => 1, ] ]); } /** * @throws \Exception */ public function getInvoiceBookedFromExternalId(string $external_id): economic_invoice_booked { $bookedId = $this->invoices->booked->get_from_external_id($external_id); $raw = $this->invoices->booked->getFromId($bookedId); // Return the booked invoice helper return (new economic_invoice_booked($raw)); } }