Refactor invoice collection creation logic in orders

Simplified the loop by removing the special-case handling for the first order. Adjusted variable usage to improve clarity and ensure proper assignment. This streamlines the creation of invoice collections for orders.
This commit is contained in:
Jepp9350
2025-04-11 12:49:37 +02:00
parent 4248a585d9
commit a3f158a920
@@ -779,14 +779,8 @@ class collected_order_invoices_o extends db
if (!empty($this->closed_at->value())) {
$closed_at = $this->closed_at->value();
}
// Create a new invoice collection for each order (Except the first one)
$first = true;
// Create a new invoice collection for each order
foreach ( $orders as $order ) {
// If this is the first order, skip it
if ($first) {
$first = false;
continue;
}
// Get the order object
$order_object = new orders_o();
$order_object->select((int)$order['id']);
@@ -796,11 +790,11 @@ class collected_order_invoices_o extends db
(int)$this->customer_number->value(),
$this->name->value(),
$this->notes->value(),
(!empty($this->processor->value()) ? (int)$this->processor->value() : null)
null
);
// Set the closed at date
if (!empty($closed_at)) {
$new_invoice_collection->closed_at->set($closed_at);
$tmp->closed_at->set($closed_at);
}
// Set the order to the new invoice collection
$order_object->invoice_collection_id->set($tmp->id);