-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_transaction_card.php
More file actions
362 lines (309 loc) · 10.7 KB
/
Copy pathgenerate_transaction_card.php
File metadata and controls
362 lines (309 loc) · 10.7 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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<?php
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "automotive";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$booking_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($booking_id <= 0) {
header("Location: index.php");
exit();
}
// Get booking details
$stmt = $conn->prepare("SELECT * FROM bookings WHERE id = ?");
$stmt->bind_param("i", $booking_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 0) {
header("Location: index.php");
exit();
}
$booking = $result->fetch_assoc();
// Check if transaction code exists
if (empty($booking['transaction_code'])) {
header("Location: booking_success.php?id=" . $booking_id);
exit();
}
// Get service names
function getServiceNames($conn, $service_ids)
{
if (empty($service_ids)) {
return '';
}
$ids = explode(',', $service_ids);
$names = [];
foreach ($ids as $id) {
if (!is_numeric($id)) {
continue;
}
$stmt = $conn->prepare("SELECT name FROM services WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
if ($row = $result->fetch_assoc()) {
$names[] = $row['name'];
}
}
return implode(', ', $names);
}
// Check if payment is downpayment or full payment
$is_downpayment = strtolower($booking['payment_type']) === 'down';
$is_full_payment = strtolower($booking['payment_type']) === 'full';
// Debug info
$debug_info = "Payment Type in DB: " . (isset($booking['payment_type']) ? $booking['payment_type'] : 'Not set');
// Calculate remaining balance if it's a downpayment
$remaining_balance = 0;
$total_cost = 0;
// Get total service cost
$service_ids = explode(',', $booking['service_id']);
foreach ($service_ids as $id) {
if (!is_numeric($id)) {
continue;
}
$cost_stmt = $conn->prepare("SELECT price FROM services WHERE id = ?");
$cost_stmt->bind_param("i", $id);
$cost_stmt->execute();
$cost_result = $cost_stmt->get_result();
if ($row = $cost_result->fetch_assoc()) {
$total_cost += $row['price'];
}
}
if ($is_downpayment) {
// Calculate remaining balance
$remaining_balance = $total_cost - $booking['downpayment_amount'];
}
$service_names = getServiceNames($conn, $booking['service_id']);
// Generate HTML transaction card instead of PNG
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Transaction Card - RJM AutoShop</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
/* Copy all CSS variables and base styles from booking_success.php */
:root {
--primary: #3b82f6;
--primary-light: #60a5fa;
--primary-dark: #2563eb;
--primary-hover: #93c5fd;
--primary-bg: #eff6ff;
--secondary: #8b5cf6;
--accent: #38bdf8;
--success: #4ade80;
--warning: #fbbf24;
--danger: #f87171;
--info: #22d3ee;
--background: #f9fafb;
--card: #ffffff;
--text: #1e293b;
--text-light: #64748b;
--text-lighter: #94a3b8;
--border: #e2e8f0;
--border-light: #f1f5f9;
--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
--shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
--shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
--radius-sm: 0.25rem;
--radius: 0.5rem;
--radius-md: 0.75rem;
--radius-lg: 1rem;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Poppins', sans-serif;
line-height: 1.6;
color: var(--text);
background-color: var(--background);
padding: 2rem;
}
.container {
max-width: 800px;
margin: 0 auto;
background-color: var(--card);
border-radius: var(--radius-lg);
box-shadow: var(--shadow-md);
overflow: hidden;
}
.card-header {
background: linear-gradient(135deg, var(--primary-light), var(--primary));
color: white;
padding: 1.5rem;
text-align: center;
font-weight: 600;
font-size: 1.25rem;
}
.payment-type {
background-color: #ffebee;
color: #c62828;
padding: 0.5rem 1rem;
margin: 1rem;
border-radius: var(--radius);
text-align: center;
font-weight: 500;
}
.transaction-code {
background-color: var(--primary-bg);
border-radius: var(--radius-lg);
padding: 2rem;
margin: 1rem;
text-align: center;
border: 1px solid var(--border);
}
.transaction-code h4 {
color: var(--primary);
margin-bottom: 1rem;
}
.transaction-code-value {
font-size: 2rem;
font-weight: 700;
color: var(--primary);
letter-spacing: 2px;
margin: 1rem 0;
}
.booking-details {
padding: 2rem;
}
.detail-item {
display: flex;
justify-content: space-between;
padding: 0.75rem 0;
border-bottom: 1px solid var(--border-light);
}
.detail-label {
font-weight: 500;
color: var(--text);
}
.detail-value {
color: var(--text-light);
}
.payment-info {
background-color: #f0fdf4;
border-radius: var(--radius);
padding: 1.5rem;
margin: 1rem;
border: 1px solid #86efac;
}
.important-note {
background-color: #fff8e1;
border-radius: var(--radius);
padding: 1.5rem;
margin: 1rem;
border: 1px solid #ffd54f;
}
.btn {
background: linear-gradient(90deg, var(--success), var(--accent));
color: white;
border: none;
padding: 0.75rem 1.5rem;
border-radius: var(--radius);
text-decoration: none;
display: inline-block;
margin: 1rem;
text-align: center;
font-weight: 500;
transition: all 0.3s ease;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: var(--shadow);
}
@media print {
body {
padding: 0;
background: white;
}
.container {
box-shadow: none;
}
.btn {
display: none;
}
}
</style>
</head>
<body>
<div class="container">
<div class="card-header">
RJM AutoShop - Transaction Card
</div>
<div class="payment-type">
Payment Type in DB: <?php echo htmlspecialchars($booking['payment_type']); ?>
</div>
<div class="transaction-code">
<h4>Your Transaction Code</h4>
<div class="transaction-code-value"><?php echo $booking['transaction_code']; ?></div>
<p>Use this code to check your booking status</p>
</div>
<div class="booking-details">
<div class="detail-item">
<div class="detail-label">Booking ID:</div>
<div class="detail-value"><?php echo $booking_id; ?></div>
</div>
<div class="detail-item">
<div class="detail-label">Customer:</div>
<div class="detail-value"><?php echo htmlspecialchars($booking['customer_name']); ?></div>
</div>
<div class="detail-item">
<div class="detail-label">Contact:</div>
<div class="detail-value"><?php echo htmlspecialchars($booking['contact_number']); ?></div>
</div>
<div class="detail-item">
<div class="detail-label">Service(s):</div>
<div class="detail-value"><?php echo htmlspecialchars($service_names); ?></div>
</div>
<div class="detail-item">
<div class="detail-label">Date:</div>
<div class="detail-value"><?php echo htmlspecialchars($booking['booking_date']); ?></div>
</div>
<div class="detail-item">
<div class="detail-label">Time:</div>
<div class="detail-value"><?php echo htmlspecialchars($booking['booking_time']); ?></div>
</div>
<div class="detail-item">
<div class="detail-label">Payment Type:</div>
<div class="detail-value"><?php echo $is_full_payment ? 'Full Payment' : 'Down Payment'; ?></div>
</div>
<div class="detail-item">
<div class="detail-label">Amount:</div>
<div class="detail-value">₱<?php echo number_format($booking['amount'], 2); ?></div>
</div>
<div class="detail-item">
<div class="detail-label">Status:</div>
<div class="detail-value"><?php echo ucfirst($booking['status']); ?></div>
</div>
</div>
<?php if ($is_full_payment): ?>
<div class="payment-info">
<p>You have made a full payment of ₱<?php echo number_format($booking['amount'], 2); ?></p>
<p>Your service is fully paid and confirmed.</p>
</div>
<?php endif; ?>
<div class="important-note">
<p><strong>Important:</strong> Please save or download this card for your records.</p>
<p>You will need this transaction code to check your booking status.</p>
</div>
<!--<div style="text-align: center; padding: 1rem;">
<button onclick="window.print()" class="btn">
<i class="fas fa-print"></i> Download This Card
</button>-->
<a href="index.php" class="btn btn-primary">
<i class="fas fa-home"></i> Back to Home
</a>
</div>
</div>
</body>
</html>