Add isIncludedInInvoicing method and implement invoicing exclusions
- Introduced `isIncludedInInvoicing` in `orders_o` to check department-based invoicing exclusions. - Updated routes and methods to skip orders excluded from invoicing. - Refined transaction and order handling to respect invoicing settings, ensuring correct filtering.
This commit is contained in:
@@ -101,7 +101,7 @@ class collected_order_invoices_o extends db
|
||||
// Check if the object is cached
|
||||
$cached = self::getCached('asArray', $this->id);
|
||||
if ($cached !== null) {
|
||||
return (array)$cached;
|
||||
//return (array)$cached;
|
||||
}
|
||||
$tmp = [
|
||||
'id' => (int)$this->id,
|
||||
@@ -170,6 +170,9 @@ class collected_order_invoices_o extends db
|
||||
foreach ( $order_ids as $order_id ) {
|
||||
$orders->select($order_id['id']);
|
||||
$orders->requireSelected();
|
||||
if (!$orders->isIncludedInInvoicing()) {
|
||||
continue;
|
||||
}
|
||||
$result[] = $orders->asArray();
|
||||
}
|
||||
return $result;
|
||||
@@ -194,6 +197,9 @@ class collected_order_invoices_o extends db
|
||||
$order = new orders_o();
|
||||
$order->select($order_id['id']);
|
||||
$order->requireSelected();
|
||||
if (!$order->isIncludedInInvoicing()) {
|
||||
continue;
|
||||
}
|
||||
// Get the net amount of the order
|
||||
$net_amount += $order->getNetAmount();
|
||||
}
|
||||
@@ -211,13 +217,22 @@ class collected_order_invoices_o extends db
|
||||
self::requireSelected();
|
||||
// Get the orders in the invoice collection
|
||||
$orders_o = new orders_o();
|
||||
return $orders_o->getFieldsWhere(
|
||||
$fields = $orders_o->getFieldsWhere(
|
||||
[
|
||||
'invoice_collection_id' => $this->id,
|
||||
'deleted_at' => null
|
||||
],
|
||||
['id']
|
||||
);
|
||||
// Remove all orders that are not included in invoicing
|
||||
foreach ( $fields as $key => $order ) {
|
||||
$orders_o->select($order['id']);
|
||||
$orders_o->requireSelected();
|
||||
if (!$orders_o->isIncludedInInvoicing()) {
|
||||
unset($fields[$key]);
|
||||
}
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1389,4 +1389,16 @@ class orders_o extends db
|
||||
$this->select((int)$new_order->id);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the transaction should be included in invoicing, based on the department.
|
||||
* Some departments have a setting to exclude them from invoicing.
|
||||
* @return bool
|
||||
* @throws Exception If the order is not selected
|
||||
*/
|
||||
public function isIncludedInInvoicing(): bool
|
||||
{
|
||||
self::requireSelected();
|
||||
return !(new departments_o())->select((int)$this->department_id->value())->isExcludedFromInvoicing();
|
||||
}
|
||||
}
|
||||
@@ -750,6 +750,7 @@ class InvoicingPeriodRoute
|
||||
'date' => $transaction->created_at->value(),
|
||||
'amount' => $transaction->temporary_net_amount, // Use the temporary net amount set earlier
|
||||
'booked' => $transaction->isBooked(),
|
||||
'excluded' => !$transaction->isIncludedInInvoicing()
|
||||
];
|
||||
}
|
||||
|
||||
@@ -761,7 +762,7 @@ class InvoicingPeriodRoute
|
||||
}
|
||||
// Check if any transaction is not booked
|
||||
foreach ( $parsed_transactions as $transaction ) {
|
||||
if (!$transaction['booked']) {
|
||||
if (!$transaction['booked'] && !$transaction['excluded']) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user