From 4bbeb16cfcf7dd0b050fe853fa3ee8c66ce09cfe Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Mon, 23 Feb 2026 13:12:33 +0000 Subject: [PATCH] Autosave: 20260223-131232 --- admin/customer_edit.php | 10 ++++- admin/customers.php | 8 +++- admin/orders.php | 38 +++++++++++++++++-- api/order.php | 1 + .../015_add_redemptions_to_customers.sql | 11 ++++++ 5 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 db/migrations/015_add_redemptions_to_customers.sql diff --git a/admin/customer_edit.php b/admin/customer_edit.php index 428ba8c..f35f2cd 100644 --- a/admin/customer_edit.php +++ b/admin/customer_edit.php @@ -65,6 +65,14 @@ include 'includes/header.php'; +
+ +
+
+
+ +
+
@@ -78,4 +86,4 @@ include 'includes/header.php';
- \ No newline at end of file + diff --git a/admin/customers.php b/admin/customers.php index f5a5211..eb81f2d 100644 --- a/admin/customers.php +++ b/admin/customers.php @@ -60,6 +60,7 @@ include 'includes/header.php'; Email Phone Address + Redemptions Actions @@ -70,6 +71,9 @@ include 'includes/header.php'; ... + + +
@@ -80,7 +84,7 @@ include 'includes/header.php'; - No customers found. + No customers found. @@ -130,4 +134,4 @@ include 'includes/header.php';
- \ No newline at end of file + diff --git a/admin/orders.php b/admin/orders.php index 8278aab..e96422f 100644 --- a/admin/orders.php +++ b/admin/orders.php @@ -6,6 +6,7 @@ require_once __DIR__ . '/../includes/functions.php'; $pdo = db(); require_permission('orders_view'); +// Handle status updates if (isset($_POST['action']) && $_POST['action'] === 'update_status') { if (!has_permission('orders_add')) { header("Location: orders.php?error=permission_denied"); @@ -19,6 +20,19 @@ if (isset($_POST['action']) && $_POST['action'] === 'update_status') { exit; } +// Handle stopping all promotions +if (isset($_POST['action']) && $_POST['action'] === 'stop_promotions') { + if (!has_permission('manage_products')) { + header("Location: orders.php?error=permission_denied"); + exit; + } + // Set promo_date_to to yesterday for all currently active promotions + $stmt = $pdo->prepare("UPDATE products SET promo_date_to = DATE_SUB(CURDATE(), INTERVAL 1 DAY) WHERE (promo_date_to >= CURDATE() OR promo_date_to IS NULL) AND promo_discount_percent IS NOT NULL"); + $stmt->execute(); + header("Location: orders.php?success=promotions_stopped"); + exit; +} + // Fetch Outlets for Filter $outlets = $pdo->query("SELECT id, name FROM outlets ORDER BY name")->fetchAll(PDO::FETCH_ASSOC); @@ -78,15 +92,31 @@ include 'includes/header.php';

Order Management

- - Live - +
+ +
+ + +
+ + + Live + +
Access Denied: You do not have permission to perform this action.
+ +
+ All running promotions have been stopped successfully. +
+ +
@@ -318,4 +348,4 @@ include 'includes/header.php';
- + \ No newline at end of file diff --git a/api/order.php b/api/order.php index 9b13593..3de35c9 100644 --- a/api/order.php +++ b/api/order.php @@ -102,6 +102,7 @@ try { } // Deduct points $deductStmt = $pdo->prepare("UPDATE customers SET points = points - ? WHERE id = ?"); + $pdo->prepare("UPDATE customers SET loyalty_redemptions_count = loyalty_redemptions_count + 1 WHERE id = ?")->execute([$customer_id]); $deductStmt->execute([$points_threshold, $customer_id]); $points_deducted = $points_threshold; diff --git a/db/migrations/015_add_redemptions_to_customers.sql b/db/migrations/015_add_redemptions_to_customers.sql new file mode 100644 index 0000000..133d748 --- /dev/null +++ b/db/migrations/015_add_redemptions_to_customers.sql @@ -0,0 +1,11 @@ +-- Add loyalty_redemptions_count to customers table +ALTER TABLE customers ADD COLUMN loyalty_redemptions_count INT DEFAULT 0; + +-- Optional: Initialize count from existing orders +UPDATE customers c +SET c.loyalty_redemptions_count = ( + SELECT COUNT(*) + FROM orders o + JOIN payment_types pt ON o.payment_type_id = pt.id + WHERE o.customer_id = c.id AND pt.name = 'Loyalty Redeem' +);