[ 'page_title' => 'Παραγγελίες - Hockey CMS', 'header_title' => 'Διαχείριση Παραγγελιών', 'th_id' => 'ID', 'th_customer' => 'Πελάτης', 'th_products' => 'Προϊόντα', 'th_total' => 'Σύνολο', 'th_actions' => 'Κατάσταση & Διαχείριση', 'status_pending' => 'Εκκρεμεί', 'status_completed' => 'Ολοκληρώθηκε', 'status_cancelled' => 'Ακύρωση & Επιστροφή Αποθ.', 'btn_update' => 'Ενημέρωση', 'btn_delete' => 'Διαγραφή', 'no_orders' => 'Καμία παραγγελία.', 'msg_ok' => 'Επιτυχής ενημέρωση της παραγγελίας και του αποθέματος!', 'msg_del' => 'Η παραγγελία διαγράφηκε οριστικά από το σύστημα.', 'confirm_del' => 'Είστε απόλυτα σίγουρος ότι θέλετε να ΔΙΑΓΡΑΨΕΤΕ αυτή την παραγγελία;' ], 'en' => [ 'page_title' => 'Orders - Hockey CMS', 'header_title' => 'Orders Management', 'th_id' => 'ID', 'th_customer' => 'Customer', 'th_products' => 'Products', 'th_total' => 'Total', 'th_actions' => 'Status & Management', 'status_pending' => 'Pending', 'status_completed' => 'Completed', 'status_cancelled' => 'Cancelled & Restock', 'btn_update' => 'Update', 'btn_delete' => 'Delete', 'no_orders' => 'No orders found.', 'msg_ok' => 'Order and inventory updated successfully!', 'msg_del' => 'Order deleted permanently.', 'confirm_del' => 'Are you sure you want to DELETE this order?' ] ]; $t = $translations[$current_lang]; header('Content-Type: text/html; charset=utf-8'); $message = ''; if (isset($_POST['update_status']) && isset($_POST['order_id'])) { $order_id = (int)$_POST['order_id']; $new_status = $_POST['status']; try { $pdo->beginTransaction(); $oldStatusStmt = $pdo->prepare("SELECT status FROM orders WHERE id = ?"); $oldStatusStmt->execute([$order_id]); $old_status = $oldStatusStmt->fetchColumn(); $stmt = $pdo->prepare("UPDATE orders SET status = ? WHERE id = ?"); $stmt->execute([$new_status, $order_id]); if ($new_status === 'cancelled' && $old_status !== 'cancelled') { $itemsStmt = $pdo->prepare("SELECT product_id, quantity FROM order_items WHERE order_id = ?"); $itemsStmt->execute([$order_id]); $items = $itemsStmt->fetchAll(PDO::FETCH_ASSOC); $restockStmt = $pdo->prepare("UPDATE products SET quantity = quantity + ?, status = 'available' WHERE id = ?"); foreach ($items as $item) { $restockStmt->execute([$item['quantity'], $item['product_id']]); } } if ($old_status === 'cancelled' && $new_status !== 'cancelled') { $itemsStmt = $pdo->prepare("SELECT product_id, quantity FROM order_items WHERE order_id = ?"); $itemsStmt->execute([$order_id]); $items = $itemsStmt->fetchAll(PDO::FETCH_ASSOC); $deductStmt = $pdo->prepare("UPDATE products SET status = CASE WHEN (quantity - ?) <= 0 THEN 'sold' ELSE status END, quantity = quantity - ? WHERE id = ?"); foreach ($items as $item) { $deductStmt->execute([$item['quantity'], $item['quantity'], $item['product_id']]); } } $pdo->commit(); $message = "
{$t['msg_ok']}
"; } catch (Exception $e) { $pdo->rollBack(); $message = "
Σφάλμα: " . $e->getMessage() . "
"; } } if (isset($_GET['delete_order'])) { $delete_id = (int)$_GET['delete_order']; try { $pdo->beginTransaction(); $pdo->prepare("DELETE FROM order_items WHERE order_id = ?")->execute([$delete_id]); $pdo->prepare("DELETE FROM orders WHERE id = ?")->execute([$delete_id]); $pdo->commit(); $message = "
{$t['msg_del']}
"; } catch (Exception $e) { $pdo->rollBack(); $message = "
Σφάλμα: " . $e->getMessage() . "
"; } } $orders = $pdo->query("SELECT * FROM orders ORDER BY id DESC")->fetchAll(PDO::FETCH_ASSOC); $order_items = []; $itemsStmt = $pdo->query("SELECT oi.order_id, oi.quantity, oi.price, p.title FROM order_items oi JOIN products p ON oi.product_id = p.id"); while ($row = $itemsStmt->fetch(PDO::FETCH_ASSOC)) { $order_items[$row['order_id']][] = $row; } ?> <?php echo $t['page_title']; ?>

0): ?>
#
  • (x)
€