Skip orders without registration number and simplify order queries for department-based filtering

This commit is contained in:
Jeppe Bundgaard
2025-08-07 12:19:15 +02:00
parent abd21e0ad7
commit f281b1c4d6
+10 -1
View File
@@ -1069,6 +1069,10 @@ class orders_o extends db
}
$orders = [];
while ($row = $result->fetch_assoc()) {
if (empty($row['reg_1'])) {
continue; // Skip orders without a registration number
}
// Prepare the order data
$tmp = [
'id' => (int)$row['id'],
'reg_1' => (string)$row['reg_1'],
@@ -1201,8 +1205,13 @@ class orders_o extends db
if ($department_id <= 0) {
throw new Exception('Invalid department ID provided');
}
if (empty($reg_1)) {
return []; // No registration number provided, return empty array
}
// Select the unique order ids that match the registration numbers and department ID within the 24 hour range
$sql = "SELECT id FROM $this->table WHERE (reg_1 = '$reg_1' AND reg_2 = '$reg_2' AND reg_3 = '$reg_3') AND department_id = $department_id AND created_at BETWEEN '$created_at_from' AND '$created_at_to' AND deleted_at IS NULL";
$sql = "SELECT id FROM $this->table WHERE (reg_1 = '$reg_1') AND department_id = $department_id AND created_at BETWEEN '$created_at_from' AND '$created_at_to' AND deleted_at IS NULL";
//$sql = "SELECT id FROM $this->table WHERE (reg_1 = '$reg_1' AND reg_2 = '$reg_2' AND reg_3 = '$reg_3') AND department_id = $department_id AND created_at BETWEEN '$created_at_from' AND '$created_at_to' AND deleted_at IS NULL";
// Execute the query
$result = $db->query($sql);
if ($result->num_rows === 0) {