-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbill.php
258 lines (237 loc) · 9.53 KB
/
bill.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
<?php
include("db.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Document</title>
<style>
.result{
color:red;
}
td
{
text-align:center;
}
input[type=submit]{
background-color: #4CAF50;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
}
</style>
</head>
<body>
<form name="back" action="cashier.php">
<input type="submit" value="BACK">
</form>
<section class="mt-3">
<div class="container-fluid">
<h4 class="text-center" style="color:green"> BILLING </h4>
<h6 class="text-center"> A CUBE INNOVATIONS</h6>
<div class="row">
<div class="col-md-5 mt-4 ">
<table class="table" style="background-color:#f5f5f5;">
<thead>
<tr>
<th>No.</th>
<th>Meal Items</th>
<th style="width: 31%">Qty</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">1</td>
<td style="width:60%">
<select name="vegitable" id="vegitable" class="form-control">
<?php
$sql = "SELECT * FROM orders";
$query = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($query)){
?>
<option id="<?php echo $row['id']; ?>" value="<?php echo $row['product_name']; ?>" class="vegitable custom-select">
<?php echo $row['product_name']; ?>
</option>
<?php }?>
</select>
</td>
<td style="width:1%">
<input type="number" id="qty" min="0" value="0" class="form-control">
</td>
<td>
<p id="price"></p>
</td>
<td><button id="add" class="btn btn-primary">Add</button></td>
</tr>
</tbody>
</table>
<div role="alert" id="errorMsg" class="mt-5" >
<!-- Error msg -->
</div>
</div>
<div class="col-md-7 mt-4" style="background-color:#f5f5f5;">
<div class="p-4">
<div class="text-center">
<h4>Receipt</h4>
</div>
<span class="mt-4"> Time : </span><span class="mt-4" id="time"></span>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6 ">
<span id="day"></span> : <span id="year"></span>
</div>
<div class="col-xs-6 col-sm-6 col-md-6 text-right">
<p>Order No:</p>
</div>
</div>
<div class="row">
</span>
<table id="receipt_bill" class="table">
<thead>
<tr>
<th> No.</th>
<th>Product Name</th>
<th>Quantity</th>
<th class="text-center">Price</th>
<th class="text-center">Total</th>
</tr>
</thead>
<tbody id="new" >
</tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="text-right text-dark" >
<h5><strong>Sub Total: ₹ </strong></h5>
<p><strong>Tax (5%) : ₹ </strong></p>
</td>
<td class="text-center text-dark" >
<h5> <strong><span id="subTotal"></strong></h5>
<h5> <strong><span id="taxAmount"></strong></h5>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="text-right text-dark">
<h5><strong>Gross Total: ₹ </strong></h5>
</td>
<td class="text-center text-danger">
<h5 id="totalPayment"><strong> </strong></h5>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
<script>
$(document).ready(function(){
$('#vegitable').change(function() {
var id = $(this).find(':selected')[0].id;
$.ajax({
method:'POST',
url:'fetch_product.php',
data:{id:id},
dataType:'json',
success:function(data)
{
$('#price').text(data.product_price);
//$('#qty').text(data.product_qty);
}
});
});
//add to cart
var count = 1;
$('#add').on('click',function(){
var name = $('#vegitable').val();
var qty = $('#qty').val();
var price = $('#price').text();
if(qty == 0)
{
var erroMsg = '<span class="alert alert-danger ml-5">Minimum Qty should be 1 or More than 1</span>';
$('#errorMsg').html(erroMsg).fadeOut(9000);
}
else
{
billFunction(); // Below Function passing here
}
function billFunction()
{
var total = 0;
$("#receipt_bill").each(function () {
var total = price*qty;
var subTotal = 0;
subTotal += parseInt(total);
var table = '<tr><td>'+ count +'</td><td>'+ name + '</td><td>' + qty + '</td><td>' + price + '</td><td><strong><input type="hidden" id="total" value="'+total+'">' +total+ '</strong></td></tr>';
$('#new').append(table)
// Code for Sub Total of Vegitables
var total = 0;
$('tbody tr td:last-child').each(function() {
var value = parseInt($('#total', this).val());
if (!isNaN(value)) {
total += value;
}
});
$('#subTotal').text(total);
// Code for calculate tax of Subtoal 5% Tax Applied
var Tax = (total * 5) / 100;
$('#taxAmount').text(Tax.toFixed(2));
// Code for Total Payment Amount
var Subtotal = $('#subTotal').text();
var taxAmount = $('#taxAmount').text();
var totalPayment = parseFloat(Subtotal) + parseFloat(taxAmount);
$('#totalPayment').text(totalPayment.toFixed(2)); // Showing using ID
});
count++;
}
});
// Code for year
var currentdate = new Date();
var datetime = currentdate.getDate() + "/"
+ (currentdate.getMonth()+1) + "/"
+ currentdate.getFullYear();
$('#year').text(datetime);
// Code for extract Weekday
function myFunction()
{
var d = new Date();
var weekday = new Array(7);
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
var day = weekday[d.getDay()];
return day;
}
var day = myFunction();
$('#day').text(day);
});
</script>
<!-- // Code for TIME -->
<script>
window.onload = displayClock();
function displayClock(){
var time = new Date().toLocaleTimeString();
document.getElementById("time").innerHTML = time;
setTimeout(displayClock, 1000);
}
</script>