-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsalesPreview.php
128 lines (107 loc) · 4.07 KB
/
salesPreview.php
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
include "redisconnect.php";
include "dbconfig.php";
$me = $_COOKIE['PHPSESSID'];
$logged = $redis->hgetall("user:$me");
// Start session
session_start();
// Close Redis connection (Predis automatically handles connections, so no explicit close is needed)
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sales</title>
<link rel="stylesheet" href="home.css">
<script src="https://kit.fontawesome.com/f7e75704ad.js" crossorigin="anonymous"></script>
<script src="title.js"></script>
<title>Selected Products</title>
<style>
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
th,
td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
color: black;
}
th {
background-color: #f2f2f2;
color: black;
}
.belowTables div {
margin-right: 2vw;
}
.belowTables button {
flex: 1;
}
.belowTables {
display: flex;
justify-content: space-around;
}
</style>
</head>
<body>
<header>
<h1>
<?php
if (isset($logged['merchantname'])) {
echo "{$logged['merchantname']} Invoice";
}
?>
</h1>
</header>
<div id="maindiv">
<div class="main-content" id="div2">
<h1>Selected Products</h1>
<?php
if (isset($_GET['selected_products'])) {
$selectedProducts = filter_input(INPUT_GET, 'selected_products', FILTER_SANITIZE_SPECIAL_CHARS);
$productIDs = explode(',', $selectedProducts);
$sql = "SELECT `product_id`, `name`, `price`, `quantity` FROM `product` WHERE `product_id` = ?";
$stmt = $conn->prepare($sql);
echo '<form action="process_sale.php" method="post">'; // Form for submitting sales data
echo '<table>';
echo '<tr><th>Name</th><th>Price</th><th>Stock</th><th>Quantity</th><th>Discount</th></tr>';
foreach ($productIDs as $productId) {
$stmt->bind_param("i", $productId);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
echo '<tr>';
echo '<td>' . htmlspecialchars($row["name"]) . '</td>';
echo '<td>' . htmlspecialchars($row["price"]) . '</td>';
echo '<td>' . htmlspecialchars($row["quantity"]) . '</td>';
echo '<td><input type="number" min="1" max="' . htmlspecialchars($row["quantity"]) . '" name="quantity[]" value="1"></td>';
echo '<td><input type="number" min="0" max="' . htmlspecialchars($row["price"]) . '" name="discount[]" value="0"></td>';
echo '<input type="hidden" name="product_id[]" value="' . htmlspecialchars($row["product_id"]) . '">';
echo '<input type="hidden" name="prod_price[]" value="' . htmlspecialchars($row["price"]) . '">';
echo '</tr>';
}
}
echo '</table>';
echo '<div class="belowTables">';
echo '<div><button class="button" onclick="toRoot()"><i class="fa-solid fa-house-user"></i></button></div>';
echo '<button type="submit" class="button" name="sell">Sell</button>';
echo '</div>';
echo '</form></br>';
$stmt->close();
$conn->close();
} else {
echo '<p>No product(s) selected.</p>';
}
?>
</div>
</div>
<footer>
<p style="font-size: 10px;">
© 2024 posperity,all rights reserved</p>
</footer>
</body>
</html>