Parcourir la source

fix getOrders and getOrderByTable now accepts order_flag 'a' and 'p'

EduLascala il y a 4 mois
Parent
commit
167459c6da
1 fichiers modifiés avec 38 ajouts et 30 suppressions
  1. 38 30
      models/OrderModel.php

+ 38 - 30
models/OrderModel.php

@@ -156,42 +156,50 @@ class OrderModel
 
 
     public function getOrders(int $companyId, ?int $statusId = null): array
-    {
-        $sql = "SELECT * FROM `order` WHERE company_id = :company_id AND order_flag = 'a'";
-        $params = ['company_id' => $companyId];
+{
+    $sql = "SELECT * 
+            FROM `order` 
+            WHERE company_id = :company_id 
+              AND order_flag IN ('a', 'p')";
+    $params = ['company_id' => $companyId];
+
+    if ($statusId !== null) {
+        $sql .= " AND status_id = :status_id";
+        $params['status_id'] = $statusId;
+    }
 
-        if ($statusId !== null) {
-            $sql .= " AND status_id = :status_id";
-            $params['status_id'] = $statusId;
-        }
+    $stmt = $this->pdo->prepare($sql);
+    $stmt->execute($params);
+    return $stmt->fetchAll(\PDO::FETCH_ASSOC);
+}
 
-        $stmt = $this->pdo->prepare($sql);
-        $stmt->execute($params);
-        return $stmt->fetchAll(\PDO::FETCH_ASSOC);
+public function getOrdersByTable(int $tableId, int $companyId, ?int $statusId = null): array
+{
+    if (!$this->tableExists($tableId, $companyId)) {
+        error_log("Tentativa de obter pedidos de mesa inválida: table_id={$tableId}, company_id={$companyId}");
+        return [];
     }
 
-    public function getOrdersByTable(int $tableId, int $companyId, ?int $statusId = null): array
-    {
-        if (!$this->tableExists($tableId, $companyId)) {
-            error_log("Tentativa de obter pedidos de mesa inválida: table_id={$tableId}, company_id={$companyId}");
-            return [];
-        }
-
-        $sql = "SELECT * FROM `order` WHERE table_id = :table_id AND company_id = :company_id AND order_flag = 'a'";
-        $params = [
-            'table_id' => $tableId,
-            'company_id' => $companyId
-        ];
+    $sql = "SELECT * 
+            FROM `order` 
+            WHERE table_id = :table_id 
+              AND company_id = :company_id 
+              AND order_flag IN ('a', 'p')";
+    $params = [
+        'table_id' => $tableId,
+        'company_id' => $companyId
+    ];
+
+    if ($statusId !== null) {
+        $sql .= " AND status_id = :status_id";
+        $params['status_id'] = $statusId;
+    }
 
-        if ($statusId !== null) {
-            $sql .= " AND status_id = :status_id";
-            $params['status_id'] = $statusId;
-        }
+    $stmt = $this->pdo->prepare($sql);
+    $stmt->execute($params);
+    return $stmt->fetchAll(\PDO::FETCH_ASSOC);
+}
 
-        $stmt = $this->pdo->prepare($sql);
-        $stmt->execute($params);
-        return $stmt->fetchAll(\PDO::FETCH_ASSOC);
-    }
 
     public function getOrderById(int $orderId, int $companyId, bool $onlyActive = true): ?array
     {