Enhance orders_o, order_items_o, and InvoicingPeriodRoute: add transaction and calculation methods, implement debug execution timing, refine invoicing period handling, optimize order retrieval, improve caching, and expand database query logic.
This commit is contained in:
@@ -236,17 +236,22 @@ class order_items_o extends db
|
||||
];
|
||||
}
|
||||
|
||||
public function getAllItemsAsArray(int $orderId): array
|
||||
public function getAllItemsAsArray(int $orderId, ?array $onlySpecificColumns = null): array
|
||||
{
|
||||
global $db;
|
||||
$sql = "SELECT * FROM $this->table WHERE order_id = $orderId AND deleted_at IS NULL";
|
||||
// Get all items for the order
|
||||
if ($onlySpecificColumns) {
|
||||
$columns = implode(', ', $onlySpecificColumns);
|
||||
} else {
|
||||
$columns = '*';
|
||||
}
|
||||
$sql = "SELECT $columns FROM $this->table WHERE order_id = $orderId AND deleted_at IS NULL";
|
||||
$result = $db->query($sql);
|
||||
// Circumvent the repeated instantiation of the object, by just selecting the fields
|
||||
$items = [];
|
||||
if ($result->num_rows > 0) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$items[] = $row;
|
||||
}
|
||||
// Fetch all rows
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user