-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayments.php
More file actions
51 lines (45 loc) · 1.57 KB
/
Copy pathpayments.php
File metadata and controls
51 lines (45 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
// payments.php - Cashier records payments
session_start();
include 'config.php';
if (!isset($_SESSION['user_role']) || $_SESSION['user_role'] !== 'cashier') {
header("Location: login.php");
exit();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['order_id'])) {
$order_id = intval($_POST['order_id']);
$payment_method = $_POST['payment_method'];
// Calculate total amount from order_items
$stmt = $conn->prepare("SELECT IFNULL(SUM(subtotal),0) as total FROM order_items WHERE order_id = ?");
$stmt->bind_param("i", $order_id);
$stmt->execute();
$res = $stmt->get_result()->fetch_assoc();
$amount = $res['total'] ?? 0.00;
// Insert payment record
$stmt = $conn->prepare("INSERT INTO payments (order_id, amount, payment_method) VALUES (?, ?, ?)");
$stmt->bind_param("ids", $order_id, $amount, $payment_method);
$stmt->execute();
// Update order status and total_amount
$stmt = $conn->prepare("UPDATE orders SET status = 'paid', total_amount = ? WHERE id = ?");
$stmt->bind_param("di", $amount, $order_id);
$stmt->execute();
echo "Payment successful!";
exit();
}
?>
<!DOCTYPE html>
<html>
<head><title>Process Payment</title></head>
<body>
<h1>Process Payment</h1>
<form method="POST">
<input type="hidden" name="order_id" value="<?= $_GET['order_id'] ?>">
<label>Payment Method:</label>
<select name="payment_method">
<option value="cash">Cash</option>
<option value="card">Card</option>
</select>
<button type="submit">Confirm Payment</button>
</form>
</body>
</html>