|
|
@@ -22,20 +22,47 @@ class OrderModel
|
|
|
int $companyId,
|
|
|
string $orderName,
|
|
|
string $orderPhone,
|
|
|
- int $statusId
|
|
|
+ int $statusId,
|
|
|
+ string $kitchenNote = ''
|
|
|
): int|false {
|
|
|
- if (!$this->tableExists($tableId, $companyId) || !$this->userExists($userId, $companyId) || !$this->companyExists($companyId) || !$this->statusExists($statusId)) {
|
|
|
+ if (
|
|
|
+ !$this->tableExists($tableId, $companyId) ||
|
|
|
+ !$this->userExists($userId, $companyId) ||
|
|
|
+ !$this->companyExists($companyId) ||
|
|
|
+ !$this->statusExists($statusId)
|
|
|
+ ) {
|
|
|
error_log("Tentativa de criar pedido com IDs inválidos: table_id={$tableId}, user_id={$userId}, company_id={$companyId}, status_id={$statusId}");
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$stmt = $this->pdo->prepare("
|
|
|
- INSERT INTO `order` (table_id, user_id, company_id, order_name, order_phone, status_id, order_created_at, order_finished_at, order_flag)
|
|
|
- VALUES (:table_id, :user_id, :company_id, :order_name, :order_phone, :status_id, :order_created_at, :order_finished_at, 'a')
|
|
|
+ INSERT INTO `order` (
|
|
|
+ table_id,
|
|
|
+ user_id,
|
|
|
+ company_id,
|
|
|
+ order_name,
|
|
|
+ order_phone,
|
|
|
+ status_id,
|
|
|
+ order_created_at,
|
|
|
+ order_finished_at,
|
|
|
+ order_flag,
|
|
|
+ kitchen_note
|
|
|
+ ) VALUES (
|
|
|
+ :table_id,
|
|
|
+ :user_id,
|
|
|
+ :company_id,
|
|
|
+ :order_name,
|
|
|
+ :order_phone,
|
|
|
+ :status_id,
|
|
|
+ :order_created_at,
|
|
|
+ :order_finished_at,
|
|
|
+ 'a',
|
|
|
+ :kitchen_note
|
|
|
+ )
|
|
|
");
|
|
|
-
|
|
|
+
|
|
|
$currentTime = date('Y-m-d H:i:s');
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
$executed = $stmt->execute([
|
|
|
'table_id' => $tableId,
|
|
|
@@ -45,8 +72,10 @@ class OrderModel
|
|
|
'order_phone' => $orderPhone,
|
|
|
'status_id' => $statusId,
|
|
|
'order_created_at' => $currentTime,
|
|
|
- 'order_finished_at' => ' '
|
|
|
+ 'order_finished_at' => ' ',
|
|
|
+ 'kitchen_note' => $kitchenNote
|
|
|
]);
|
|
|
+
|
|
|
return $executed ? (int)$this->pdo->lastInsertId() : false;
|
|
|
} catch (\PDOException $e) {
|
|
|
error_log("PDO Exception during order creation: " . $e->getMessage());
|
|
|
@@ -72,25 +101,36 @@ class OrderModel
|
|
|
return $executed && $stmt->rowCount() > 0;
|
|
|
}
|
|
|
|
|
|
- public function deleteOrder(int $orderId, int $companyId): bool
|
|
|
+ public function deleteOrder(int $orderId, int $companyId, bool $hardDelete = false): bool
|
|
|
{
|
|
|
- $currentTime = date('Y-m-d H:i:s');
|
|
|
+ if ($hardDelete) {
|
|
|
+ $stmtItems = $this->pdo->prepare("DELETE FROM order_item WHERE order_id = :order_id");
|
|
|
+ $stmtItems->execute(['order_id' => $orderId]);
|
|
|
|
|
|
- $stmt = $this->pdo->prepare("
|
|
|
- UPDATE `order`
|
|
|
- SET order_flag = 'd', order_finished_at = :order_finished_at
|
|
|
- WHERE order_id = :order_id AND company_id = :company_id AND order_flag = 'a'
|
|
|
- ");
|
|
|
-
|
|
|
- $executed = $stmt->execute([
|
|
|
- 'order_finished_at' => $currentTime,
|
|
|
- 'order_id' => $orderId,
|
|
|
- 'company_id' => $companyId
|
|
|
- ]);
|
|
|
+ $stmtOrder = $this->pdo->prepare("DELETE FROM `order` WHERE order_id = :order_id AND company_id = :company_id");
|
|
|
+ $stmtOrder->execute(['order_id' => $orderId, 'company_id' => $companyId]);
|
|
|
|
|
|
- return $executed && $stmt->rowCount() > 0;
|
|
|
+ return $stmtOrder->rowCount() > 0;
|
|
|
+ } else {
|
|
|
+ $currentTime = date('Y-m-d H:i:s');
|
|
|
+
|
|
|
+ $stmt = $this->pdo->prepare("
|
|
|
+ UPDATE `order`
|
|
|
+ SET order_flag = 'd', order_finished_at = :order_finished_at
|
|
|
+ WHERE order_id = :order_id AND company_id = :company_id AND order_flag = 'a'
|
|
|
+ ");
|
|
|
+
|
|
|
+ $executed = $stmt->execute([
|
|
|
+ 'order_finished_at' => $currentTime,
|
|
|
+ 'order_id' => $orderId,
|
|
|
+ 'company_id' => $companyId
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return $executed && $stmt->rowCount() > 0;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public function getOrders(int $companyId, ?int $statusId = null): array
|
|
|
{
|
|
|
$sql = "SELECT * FROM `order` WHERE company_id = :company_id AND order_flag = 'a'";
|