-
\ 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';
@@ -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'
+);