Enhance product options and invoice data handling

Added support for `name`, `created_at`, and `updated_at` fields in product options API response for better data visibility. Updated invoice object logic to conditionally set draft and booked IDs based on `external_id`, improving flexibility and accuracy in handling external integrations.
This commit is contained in:
Jepp9350
2025-03-04 14:04:46 +01:00
parent 4d593c2b17
commit bf4879e593
2 changed files with 13 additions and 3 deletions
@@ -73,7 +73,7 @@ class collected_order_invoices_o extends db
public function asArray(): array
{
return [
$tmp = [
'id' => (int)$this->id,
'customer_number' => (int)$this->customer_number->value(),
'name' => (string)$this->name->value(),
@@ -84,9 +84,15 @@ class collected_order_invoices_o extends db
'updated_at' => (string)$this->updated_at->value(),
'closed_at' => (string)$this->closed_at->value(),
'orders' => $this->getOrders(),
'economic_invoice_draft_id' => self::isDraftExisting() ? self::getInvoiceDraftId() : null,
'economic_invoice_booked_id' => self::isBooked() ? self::getInvoiceBookedId() : null,
'economic_invoice_draft_id' => null, // This will be overwritten if the external id is set
'economic_invoice_booked_id' => null, // This will be overwritten if the external id is set
];
// If the external id is set, get the invoice draft id
if (!empty($this->external_id->value())) {
$tmp['economic_invoice_draft_id'] = self::isDraftExisting() ? self::getInvoiceDraftId() : null;
$tmp['economic_invoice_booked_id'] = self::isBooked() ? self::getInvoiceBookedId() : null;
}
return $tmp;
}
/**
@@ -32,6 +32,9 @@ class productOptionsRoute
'id',
'product_id',
'option_id',
'name',
'created_at',
'updated_at'
])
->listObjectsWithPaginationIfSet(
function ($option) use ($user) {
@@ -40,6 +43,7 @@ class productOptionsRoute
'id' => (int)$option['id'],
'product_id' => (int)$option['product_id'],
'option_id' => (int)$option['option_id'],
'name' => (string)$option['name'],
'created_at' => (string)$option['created_at'],
'updated_at' => (string)$option['updated_at'],
];