Refactor invoice handling and add total net amount calculation

Introduce logic for validating booked and draft invoices in E-conomic. Add methods to calculate the total net amount for invoice collections and improve error handling for specific invoice states. Updated related workflows to ensure consistent validation and data integrity.
This commit is contained in:
Jepp9350
2025-03-07 16:22:14 +01:00
parent d160ecbb63
commit b3c4e9696f
3 changed files with 125 additions and 12 deletions
+18
View File
@@ -446,4 +446,22 @@ class orders_o extends db
$result = $db->query($sql);
return $db->fetch_all($result);
}
public function getNetAmount(): float
{
self::requireSelected();
$net = 0;
// Get the order items object
$order_items = new order_items_o();
// Get the price, quantity of the order items
$items = $order_items->getAllItemsAsArray($this->id);
// Loop through the items and get the net amount
foreach ( $items as $item ) {
$tmp_price = (int)$item['price'];
$tmp_quantity = (int)$item['quantity'];
// Add the price to the net amount
$net += $tmp_price * $tmp_quantity;
}
return $net;
}
}