Add booked_invoice_id property and optimize invoice handling
Introduce the booked_invoice_id property in collected_order_invoices_o for improved invoice management. Optimize performance by avoiding redundant requests to external systems when the booked_invoice_id is already set. Enhance routes to include the booked_invoice_id in relevant responses and ensure a consistent structure for associated data.
This commit is contained in:
@@ -17,6 +17,8 @@ class collected_order_invoices_o extends db
|
||||
public object_property $notes;
|
||||
public object_property $processor;
|
||||
public object_property $external_id;
|
||||
|
||||
public object_property $booked_invoice_id;
|
||||
public object_property $created_at;
|
||||
public object_property $updated_at;
|
||||
public object_property $closed_at;
|
||||
@@ -66,6 +68,7 @@ class collected_order_invoices_o extends db
|
||||
$this->created_at = new object_property($this->table, $this->id, 'created_at', 'string', false);
|
||||
$this->updated_at = new object_property($this->table, $this->id, 'updated_at', 'string', false);
|
||||
$this->closed_at = new object_property($this->table, $this->id, 'closed_at', 'string', false);
|
||||
$this->booked_invoice_id = new object_property($this->table, $this->id, 'booked_invoice_id', 'int', false);
|
||||
}
|
||||
|
||||
public function asArray(): array
|
||||
@@ -179,10 +182,15 @@ class collected_order_invoices_o extends db
|
||||
{
|
||||
// Require the invoice collection to be selected
|
||||
self::requireSelected();
|
||||
// Check if the invoice_booked_id is already set (We don't want to make a request to E-conomic if we already have the id - Since this is slow.)
|
||||
if (!empty($this->booked_invoice_id->value())) {
|
||||
return (int)$this->booked_invoice_id->value();
|
||||
}
|
||||
// Create an economic object
|
||||
$economic = new economic();
|
||||
// Get the invoice booked id from the external id
|
||||
$invoice_booked_id = $economic->invoices->booked->get_from_external_id($this->external_id->value());
|
||||
$this->booked_invoice_id->set($invoice_booked_id);
|
||||
return (int)$invoice_booked_id;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace routes;
|
||||
|
||||
use classes\authentication;
|
||||
use classes\response;
|
||||
use objects\collected_order_invoices_o;
|
||||
use objects\departments_o;
|
||||
use objects\economic_module_orders;
|
||||
use objects\logs_o;
|
||||
@@ -42,6 +43,15 @@ class ordersRoute
|
||||
if ($stripe_module_orders->exists()) {
|
||||
$order['stripe_invoice_module'] = $stripe_module_orders->asArray();
|
||||
}
|
||||
// If the invoice collection is set, add it to the order
|
||||
if (!empty($order['invoice_collection_id'])) {
|
||||
$order['invoice_collection'] = [
|
||||
'id' => $order['invoice_collection_id'],
|
||||
'closed_at' => (new collected_order_invoices_o())->select($order['invoice_collection_id'])->closed_at->value(),
|
||||
'booked_invoice_id' => (new collected_order_invoices_o())->select($order['invoice_collection_id'])->booked_invoice_id->value() ?? null,
|
||||
'processor' => (int)(new collected_order_invoices_o())->select($order['invoice_collection_id'])->processor->value() ?? null,
|
||||
];
|
||||
}
|
||||
// Add the customer name to the order
|
||||
$order['customer_name'] = (new users_o())->getCustomerName($order['customer_id']);
|
||||
/** @var array $order */
|
||||
|
||||
@@ -53,7 +53,9 @@ class productsRoute
|
||||
$products = (new products_o())->applyDepartmentPricing((array)$products, (int)$data['department_id']);
|
||||
}
|
||||
$response->success(
|
||||
$products
|
||||
array_map(function ($product) {
|
||||
return parseProduct($product);
|
||||
}, $products)
|
||||
);
|
||||
}
|
||||
// Log the incident
|
||||
|
||||
@@ -27,9 +27,6 @@ COPY /nginx/app /var/www/html
|
||||
RUN chown -R www-data:www-data /var/www/html \
|
||||
&& chmod -R 755 /var/www/html
|
||||
|
||||
# Require the phpmailer/phpmailer package
|
||||
RUN composer require phpmailer/phpmailer
|
||||
|
||||
# Install using Composer
|
||||
RUN composer install --no-dev
|
||||
|
||||
|
||||
Reference in New Issue
Block a user