forked from ABHRADEEP800/PHP-E_Commerce_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvoice.php
322 lines (284 loc) · 12 KB
/
invoice.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
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
<?php
session_start();
// if user is not logged in, redirect to login page
if (!isset($_SESSION['customer'])) {
header('location: login.php');
exit;
}
// including database connection file
require('env/database.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Order Invoice</title>
<link rel="icon" type="image/x-icon" href="assets/svg-logo/logo-bg.svg">
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' type='text/css' media='screen' href='main.css'>
<script src='main.js'></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" />
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://kit.fontawesome.com/db79afedbd.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/boxicons@latest/css/boxicons.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous" />
<link rel="stylesheet" href="asset/card.css" />
<!-- html to pdf script -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
<script>
function generatePDF() {
const element = document.getElementById('container_content');
var opt = {
margin: 0,
filename: 'invoice.pdf',
image: {
type: 'jpeg',
quality: 0.98
},
html2canvas: {
scale: 2
},
jsPDF: {
unit: 'in',
format: 'A3',
orientation: 'portrait'
}
};
// Choose the element that our invoice is rendered in.
html2pdf().set(opt).from(element).save();
}
</script>
<link rel="stylesheet" type="text/css" media="screen" href="assets/css/main.css" />
</head>
<body>
<!-- ----------------------------------------------------Loading Screen-------------------------------------------------------- -->
<div id="loading">
<img src="assets/svg-logo/LOADER.svg" alt="Loading..." />
</div>
<script>
var loader = document.getElementById("loading");
window.addEventListener("load", function() {
loader.style.display = "none";
})
</script>
<!-- download invoice button -->
<div class="container text-center " style="padding:20px;">
<div class="row">
<div class="col-6 d-flex justify-content-start">
<a href="account.php?tab=orders" class="btn btn-primary"><i class="fas fa-arrow-left me-2"></i>Back</a>
</div>
<div class="col-6 d-flex justify-content-end">
<button class=" btn btn-primary" onclick="generatePDF()">Invoice<i class="fas fa-download ms-2"></i></button>
</div>
</div>
</div>
<?php
// taking order id from url
$id = $_GET['orderId'];
//fetch user_id
$user_email = $_SESSION['customer'];
$sql = "SELECT user_id FROM user WHERE user_email = '$user_email'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$user_id = $row['user_id'];
// fetching order details from database
$sql1 = "SELECT user.user_name, user.user_email, product.product_name, product.product_img, order_p.order_qu, product.product_price, orders.order_date, orders.order_status, orders.order_id, orders.discount,orders.shipping_address
FROM orders
INNER JOIN user ON user.user_id=orders.order_user
INNER JOIN order_p ON order_p.order_id=orders.order_id
INNER JOIN product ON product.product_id=order_p.order_item
WHERE orders.order_id = '$id' && orders.order_user = '$user_id'";
// executing query
$result1 = mysqli_query($conn, $sql1);
//fetch row count
$rowcount = mysqli_num_rows($result1);
if ($rowcount > 0) {
//fetching result in variable
$row = mysqli_fetch_assoc($result1);
} else {
echo "<script>alert('Invalid Order Id');</script>";
echo "<script>window.location.href='account.php';</script>";
}
?>
<!------------- main invoice for pdf -->
<div id="container_content">
<div class="container mt-5 mb-5">
<div class="row d-flex justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="text-left logo p-2 px-5">
<img src="app\asset\image\logo-bg.svg" width="100" />
</div>
<div class="invoice p-3">
<div class="d-flex justify-content-center">
<div>
<h2>Invoice</h2>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="py-2">
<span class="d-block text-muted">User</span>
<span><?= $row['user_name'] ?></span>
</div>
</div>
<div class="col-md-6 d-flex justify-content-end">
<div class="py-2">
<span class="d-block text-muted">Shipping Address</span>
<span><?= $row['shipping_address'] ?></span>
</div>
</div>
<!-- order details -->
<div class="payment border-top mt-3 mb-3 border-bottom table-responsive">
<!-- order details table -->
<table class="table table-borderless">
<tbody>
<tr>
<td>
<div class="py-2">
<span class="d-block text-muted">Order Date</span>
<span><?= $row['order_date'] ?></span>
</div>
</td>
<td>
<div class="py-2">
<span class="d-block text-muted">Order No</span>
<span><?= $row['order_id'] ?></span>
</div>
</td>
<td>
<div class="py-2">
<span class="d-block text-muted">Payment</span>
<span>Cash On delivery</span>
</div>
</td>
<td>
<div class="py-2">
<span class="d-block text-muted">Order Status</span>
<span><?= $row['order_status'] ?></span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- order items -->
<div class="product border-bottom table-responsive">
<table class="table table-borderless">
<tbody>
<?php
$total = 0;
$order_id = $row['order_id'];
$order_discount = $row['discount'];
// getting order items from database
$sql = "SELECT * FROM order_p
INNER JOIN product ON product.product_id = order_p.order_item
WHERE order_p.order_id = '$order_id'";
$result = mysqli_query($conn, $sql);
while ($row1 = mysqli_fetch_assoc($result)) {
$product_name = $row1['product_name'];
$product_price = $row1['price'];
$product_img = $row1['product_img'];
$product_qty = $row1['order_qu'];
$product_id = $row1['product_id'];
$product_total = $product_price * $product_qty;
?>
<tr>
<td width="20%">
<img src="<?php echo $product_img; ?>" width="90" />
</td>
<td width="60%">
<span class="font-weight-bold"><?php echo $product_name; ?></span>
<div class="product-qty">
<span class="d-block">Quantity:<?php echo $product_qty; ?> Pcs</span>
</div>
</td>
<td width="20%">
<div class="text-right">
<span class="font-weight-bold">₹ <?php echo $product_price; ?></span>
</div>
</td>
</tr>
<?php
$total = $total + $product_total;
}
?>
</tbody>
</table>
</div>
<!-- order total -->
<div class="row d-flex justify-content-end">
<div class="col-md-5">
<table class="table table-borderless">
<tbody class="totals">
<tr>
<td>
<div class="text-left">
<span class="text-muted">Subtotal</span>
</div>
</td>
<td>
<div class="text-right">
<span>₹ <?php echo $total; ?></span>
</div>
</td>
</tr>
<tr>
<td>
<div class="text-left">
<span class="text-muted">Shipping Fee</span>
</div>
</td>
<td>
<div class="text-right">
<span>₹ 0</span>
</div>
</td>
</tr>
<tr>
<td>
<div class="text-left">
<span class="text-muted">Discount</span>
</div>
</td>
<td>
<div class="text-right">
<span class="text-success"><?= $order_discount ?> %</span>
</div>
</td>
</tr>
<tr class="border-top border-bottom">
<td>
<div class="text-left">
<span class="font-weight-bold">Total</span>
</div>
</td>
<td>
<div class="text-right">
<span class="font-weight-bold">₹ <?php echo $total - ($total * $order_discount / 100); ?></span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- order status -->
<p class="font-weight-bold mb-0">Thanks for shopping with us!</p>
<span>Grapple Team</span>
</div>
<div class="d-flex justify-content-between footer p-3">
<span>© 2023 Grapple Inc. All rights reserved</span>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>