-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_receipt.php
235 lines (195 loc) · 7.55 KB
/
print_receipt.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
ob_start();
session_start();
// Access user session data
$user_id = $_SESSION['user_id'];
$user_name = $_SESSION['user_name'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Print Receipt</title>
<!-- Add Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
/* Add custom styles for a receipt look */
body {
font-family: 'Arial', sans-serif;
background-color: #f8f9fa;
color: #343a40;
}
.receipt-container {
max-width: 400px;
margin: auto;
padding: 10px;
border-radius: 10px;
margin-top: 50px;
background-color: #ffffff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
/* Tambahkan shadow di sini */
}
.receipt-header {
text-align: center;
margin-bottom: 20px;
}
.receipt-header h1 {
color: #ff0021;
font-size: 24px;
}
.receipt-header p {
font-size: 14px;
color: #6c757d;
}
.receipt-details {
margin-top: 20px;
}
.table th,
.table td {
border: none;
padding: 8px;
text-align: left;
}
.total-section {
margin-top: 20px;
font-weight: bold;
color: #ff0021;
}
.footer-text {
text-align: center;
margin-top: 20px;
font-size: 14px;
color: #6c757d;
}
.btn-section {
margin-top: 20px;
text-align: center;
}
.btn-back,
.btn-print {
background-color: #ff0021;
border: none;
color: #ffffff;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
text-decoration: none;
}
.btn-back {
margin-right: 10px;
}
.btn-back:hover,
.btn-print:hover {
background-color: #d90017;
}
.btn-print {
margin-top: 20px;
}
/* Tambahkan CSS kustom di sini jika diperlukan */
#purchase-details {
margin-top: 20px;
}
.purchase-item {
margin-bottom: 10px;
}
.purchase-total {
margin-top: 20px;
font-weight: bold;
color: #ff0021;
}
</style>
</head>
<body class="container mt-5">
<div class="receipt-container">
<div class="receipt-header">
<img src="src/emyu.png" alt="" width="48" height="48">
<h1><strong>UnitedKU</strong></h1>
<p>Your Fashion Partner</p>
</div>
<div class="receipt-details">
<!-- Display the receipt details here -->
<?php
// Include configuration file and start session
include('config.php');
include('checkout.php');
// Check if the user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
// Get user_id from the session
$user_id = $_SESSION['user_id'];
// Check if there is data sent through the checkout form
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get checkout form data
$customer_id = $_POST["customer_id"];
$products = $_POST["products"];
// Get transaction date from the database
$transaction_query = mysqli_query($conn, "SELECT transaction_date FROM table_transaction WHERE user_id = '$user_id' ORDER BY transaction_id DESC LIMIT 1");
$transaction_row = mysqli_fetch_assoc($transaction_query);
$transaction_date = date('F j, Y, g:i a', strtotime($transaction_row['transaction_date']));
// Display purchase details
echo "<div id='summary'>
<h3>Purchase Details</h3>
<p>Date: $transaction_date</p>";
// Display product details in a table
echo "<table class='table'>
<tbody>";
foreach ($products as $product) {
$product_id = $product['product_id'];
$quantity = $product['quantity'];
$product_query = mysqli_query($conn, "SELECT * FROM table_product WHERE product_id = '$product_id'");
$product_row = mysqli_fetch_assoc($product_query);
echo "<tr>
<td>{$product_row['product_name']}</td>
<td>{$quantity} pcs</td>
<td>£{$product_row['product_price']}</td>
</tr>";
}
// Apply discount based on membership category
$discount_percentage = 0;
switch ($membership_category) {
case 'Premium':
$discount_percentage = 15;
break;
case 'Silver':
$discount_percentage = 10;
break;
case 'Standard':
$discount_percentage = 5;
break;
default:
$discount_percentage = 0;
break;
}
// Calculate total price after discount
$totalPriceAfterDiscount = $totalPrice - ($discount_percentage / 100 * $totalPrice);
// Display total and discount in Pound Sterling (£)
echo "</tbody>
</table>
<div class='total-section'>
<p>Total Quantity: {$totalQuantity} pcs</p>
<p>Discount: {$discount_percentage}%</p>
<p>Total Price after discount: £{$totalPriceAfterDiscount}</p>
</div>";
echo "</div>"; // End of summary div
// Add buttons
echo "<div class='btn-section'>
<a href='checkout.php' class='btn btn-secondary btn-back'>Back to Checkout</a>
<button class='btn btn-primary btn-print' onclick='window.print()'>Print Receipt</button>
</div>";
exit(); // Stop execution after displaying purchase details
}
?>
</div>
<div class="footer-text">
<p>Thank you for shopping with us!</p>
</div>
</div>
<!-- Add Bootstrap and other scripts if needed -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2kKI4zcBXH+VdU+ZkE+yQ0Z1EGwCyf3oIdjOZy4ZE2J/sYp" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>