Autosave: 20260223-131232

This commit is contained in:
Flatlogic Bot 2026-02-23 13:12:33 +00:00
parent 370ceb510e
commit 4bbeb16cfc
5 changed files with 61 additions and 7 deletions

View File

@ -65,6 +65,14 @@ include 'includes/header.php';
<label class="form-label">Phone</label>
<input type="text" name="phone" class="form-control" value="<?= htmlspecialchars($customer['phone']) ?>">
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Loyalty Points</label>
<div class="form-control bg-light"><?= intval($customer['points']) ?></div>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Total Redemptions</label>
<div class="form-control bg-light"><?= intval($customer['loyalty_redemptions_count']) ?></div>
</div>
<div class="col-md-12 mb-3">
<label class="form-label">Address</label>
<textarea name="address" class="form-control" rows="3"><?= htmlspecialchars($customer['address']) ?></textarea>

View File

@ -60,6 +60,7 @@ include 'includes/header.php';
<th>Email</th>
<th>Phone</th>
<th>Address</th>
<th class="text-center">Redemptions</th>
<th>Actions</th>
</tr>
</thead>
@ -70,6 +71,9 @@ include 'includes/header.php';
<td><?= htmlspecialchars($customer['email']) ?></td>
<td><?= htmlspecialchars($customer['phone']) ?></td>
<td><?= htmlspecialchars(substr($customer['address'] ?? '', 0, 30)) ?>...</td>
<td class="text-center">
<span class="badge bg-info text-dark"><?= intval($customer['loyalty_redemptions_count'] ?? 0) ?></span>
</td>
<td>
<div class="btn-group">
<a href="customer_edit.php?id=<?= $customer['id'] ?>" class="btn btn-sm btn-outline-primary" title="Edit Customer"><i class="bi bi-pencil"></i></a>
@ -80,7 +84,7 @@ include 'includes/header.php';
<?php endforeach; ?>
<?php if (empty($customers)): ?>
<tr>
<td colspan="5" class="text-center py-4 text-muted">No customers found.</td>
<td colspan="6" class="text-center py-4 text-muted">No customers found.</td>
</tr>
<?php endif; ?>
</tbody>

View File

@ -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';
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="fw-bold mb-0">Order Management</h2>
<span class="badge bg-success bg-opacity-10 text-success border border-success px-3 py-2 rounded-pill">
<div class="d-flex gap-2">
<?php if (has_permission('manage_products')): ?>
<form method="POST" onsubmit="return confirm('Are you sure you want to stop all running promotions? This will end all active promotions by setting their end date to yesterday.');">
<input type="hidden" name="action" value="stop_promotions">
<button type="submit" class="btn btn-danger shadow-sm">
<i class="bi bi-stop-circle me-1"></i> Stop All Promotions
</button>
</form>
<?php endif; ?>
<span class="badge bg-success bg-opacity-10 text-success border border-success px-3 py-2 rounded-pill d-flex align-items-center">
<i class="bi bi-circle-fill small me-1"></i> Live
</span>
</div>
</div>
<?php if (isset($_GET['error']) && $_GET['error'] === 'permission_denied'): ?>
<div class="alert alert-danger border-0 shadow-sm rounded-3">Access Denied: You do not have permission to perform this action.</div>
<?php endif; ?>
<?php if (isset($_GET['success']) && $_GET['success'] === 'promotions_stopped'): ?>
<div class="alert alert-success border-0 shadow-sm rounded-3">
<i class="bi bi-check-circle-fill me-2"></i> All running promotions have been stopped successfully.
</div>
<?php endif; ?>
<!-- Summary Stats -->
<div class="row mb-4">
<div class="col-md-4">

View File

@ -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;

View File

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