-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathreturn-action.php
379 lines (348 loc) · 19.8 KB
/
return-action.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
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<?php
session_start();
if(!isset($_SESSION['store_id'])) {
header("location:login.php");
exit();
}else{
if(!isset($_GET['invoice']) || empty($_GET['invoice'])){
header("location:return.php");
exit();
}else{
include('config/db.php');
$invoice = $_GET['invoice'];
$customer = $_GET['customer'];
$invoiceDetails = mysqli_fetch_assoc($conn->query("SELECT * FROM `p_invoice_summary` WHERE `invoice` = '$invoice'"));
// emptying return cart
unset($_SESSION["return_item"]);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Pharmacy</title>
<!-- All CSS -->
<?php include("part/all-css.php");?>
<!-- All CSS end -->
</head>
<body class="hold-transition sidebar-mini layout-fixed">
<div class="wrapper">
<!-- Navbar -->
<?php include("part/navbar.php");?>
<!-- Navbar end -->
<!-- Sidebar -->
<?php include("part/sidebar.php");?>
<!-- Sidebar end -->
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<div class="container-fluid">
<form action="actions/return.php" method="POST">
<div class="row">
<div class="col-lg-4">
<div class="card">
<div class="card-header">
<h3>Basic Details</h3>
</div>
<div class="card-body">
<table id="example1" class="table table-bordered table-hover">
<tbody>
<tr>
<th>Invoice:</th>
<td>
<?php echo $invoice; ?>
<input type="hidden" name="re_invoice" value="<?php echo $invoice;?>">
</td>
</tr>
<tr>
<th>Customer Name:</th>
<td>
<?php echo $customer; ?>
<input type="hidden" name="re_customer" value="<?php echo $customer;?>">
<input type="hidden" name="re_customer_code" value="<?php echo $invoiceDetails['client'];?>">
</td>
</tr>
<tr>
<th>Product Price <small>(without %)</small> :</th>
<td class="productPrice">
<?php echo $invoiceDetails['total_price']; ?>
<input type="hidden" name="re_total" value="<?php echo $invoiceDetails['total_price'];?>">
</td>
</tr>
<tr>
<th>Discount</th>
<td class="discount" data-discount="<?php echo $invoiceDetails['discount'];?>" data-discountType="<?php echo $invoiceDetails['discount_type'];?>">
<?php echo $invoiceDetails['discount']." (".$invoiceDetails['discount_type'].")"; ?>
<input type="hidden" name="re_discount" value="<?php echo $invoiceDetails['discount']." (".$invoiceDetails['discount_type'].")";?>">
</td>
</tr>
<tr>
<th>Total Receivable <small>(after %)</small> :</th>
<td>
<?php
if($invoiceDetails['discount_type'] == "flat"){
$receivable = $invoiceDetails['total_price'] - $invoiceDetails['discount'];
}else{
$receivable = $invoiceDetails['total_price'] - ($invoiceDetails['total_price']*($invoiceDetails['discount']/100));
}
echo "$receivable";
?>
</td>
</tr>
<tr>
<th>Total Paid:</th>
<td class="totalPaid">
<?php echo $invoiceDetails['paid']; ?>
<input type="hidden" name="re_paid" value="<?php echo $invoiceDetails['paid'];?>">
</td>
</tr>
<tr>
<th>Due:</th>
<td>
<span class="due">
<?php echo $invoiceDetails['due']; ?>
</span>
</td>
</tr>
<!-- <tr>
<th>Returned Product Value</th>
<td>
0
<input type="text" class="previous_returned_product_value" value="0"
hidden="">
</td>
</tr> -->
</tbody>
</table>
</div>
</div>
</div>
<div class="col-lg-8">
<div class="card">
<div class="card-header">
<h3>Return Poduct</h3>
</div>
<div class="card-body">
<!-- <form action="" method="POST" class="return_form"> -->
<table id="example1" class="table table-bordered table-hover">
<thead>
<tr>
<th style="max-width:10%;">No.</th>
<th>Name</th>
<th>Unit Price</th>
<th>Ordered Quantity</th>
<th>Return Quantity</th>
<th>Price</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$n = 0;
$totalQty = 0;
$sql = $conn->query("SELECT * FROM `p_invoice` WHERE `invoice` = '$invoice' AND `store` = '$_SESSION[store_id]'");
while($row = mysqli_fetch_assoc($sql)){
$totalQty += $row['qty'];
?>
<tr>
<td><?php echo ++$n; ?></td>
<td class="cl<?php echo $row['id']; ?>2" data-product="<?php echo $row['product']; ?>"> <?php echo $row['product']; ?> </td>
<td> <?php echo $row['price']; ?> </td>
<td class="odq<?php echo $row['id']; ?>"> <?php echo $row['qty']; ?> </td>
<td>
<input type="number" name="qty" class="form-control qty returnQty cl<?php echo $row['id']; ?>3" value="0" min="0" max="<?php echo $row['qty']; ?>"
data-product_id="<?php echo $row['id']; ?>" data-price="<?php echo $row['price']; ?>">
</td>
<td>
<p class="totalprice cl<?php echo $row['id']; ?>">0</p>
<input type="hidden" class="cl<?php echo $row['id']; ?>" name="med<?php echo $row['product']; ?>" value="">
</td>
<td> <button type="button" class="btn btn-danger btn-sm no-return" data-product_id="<?php echo $row['id']; ?>" data-price="<?php echo $row['price']; ?>" data-returnQtyField="cl<?php echo $row['id']; ?>3"> <i class="fa fa-times"></i> No Return </button> </td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<td style="text-align:right;" colspan="6">Total:</td>
<td>
<span class="return_total_price">0.00</span>
<input type="hidden" name="return_total_price" class="return_total_price">
</td>
</tr>
<tr>
<td style="text-align:right;" colspan="6">Discount:</td>
<td>
<span class="discount_amount">58</span>
<input type="text" name="calculated_discount" class="calculated_discount" value="0" hidden="">
</td>
</tr>
<tr>
<td style="text-align:right;" colspan="6">After Discount:</td>
<td>
<span class="return_product_value">0.00</span>
<input type="hidden" name="return_product_value" class="return_product_value">
</td>
</tr>
</tfoot>
</table>
<div class="row">
<div class="col-md-8">
<div class="form-group">
<label for="">Considering The Paid Amount & Discount Amount --
You Should Return:</label>
<h4 class="cus_should_payable">0.00</h4>
<input type="hidden" name="cus_should_payable" class="cus_should_payable">
<input type="number" name="should_pay" value="0"
class="form-control cus_should_pay" hidden="">
</div>
</div>
<div class="col-md-8">
<label for="">Decided to Pay</label>
<input type="text" name="payable_to_customer" value="0" class="form-control decided_to_pay" min="0">
<!-- <label style="margin-top:20px; font-size:1.3em">
<input type="checkbox" class="form-control"
style="height:15px; width:15px; display:inline;"
name="pay_customer">
Make Payment
</label> -->
</div>
</div>
<input type="submit" value="Return Product" class="btn btn-info return_to_customer" name="return_to_customer" style="margin-top:20px;">
<!-- </form> -->
</div>
</div>
</div>
</div>
</form>
</div>
</section>
</div>
<!-- Footer -->
<?php include("part/footer.php");?>
<!-- Footer End -->
</div>
<!-- All JS -->
<?php include("part/all-js.php");?>
<!-- All JS end -->
<script>
$(function () {
//Initialize Select2 Elements
$(".select2").select2();
//Initialize Select2 Elements
$(".select2bs4").select2({
theme: "bootstrap4",
});
});
</script>
<script>
$(function () {
var invoice = <?php echo $invoice ?>;
var aa = $(".productPrice").text();
// $(".return_total_price").text(aa);
// $(".return_total_price").val(aa);
var discount = $(".discount").attr("data-discount");
var discountType = $(".discount").attr("data-discountType");
$(".discount_amount").text(discount+" ("+discountType+")");
$(".returnQty").on("change", function(){
var qty = $(this).val();
var product = $(this).attr("data-product_id");
var product_name = $(".cl"+product+"2").attr("data-product");
var orderQty = $(".odq"+product).text();
var price = $(this).attr("data-price");
// var crr = "cl"+product;
$(".cl"+product).val(qty*price);
$(".cl"+product).text(qty*price);
// Total return quantity
var totalReturnQty = 0;
$('.returnQty').each(function(){
totalReturnQty += parseFloat($(this).val());
});
var sum = 0;
$('.totalprice').each(function()
{
sum += parseFloat($(this).text());
});
$(".return_total_price").text(sum);
$(".return_total_price").val(sum);
var vl;
if(discountType == "flat"){
var perQty = parseFloat(discount) / parseFloat(<?php echo $totalQty ?>);
var returnQtyPriceTotal = totalReturnQty * perQty;
vl = (sum - returnQtyPriceTotal).toFixed(2);
}else{
vl = sum - (sum*(discount/100));
}
$(".return_product_value").text(vl);
$(".return_product_value").val(vl);
var totalPaid = $(".totalPaid").text();
// $(".cus_should_payable").text(totalPaid - vl);
$(".cus_should_payable").text(vl);
$(".cus_should_payable").val(vl);
// console.log(invoice+" "+product+" "+product_name+" "+price+" "+orderQty+" "+qty);
var reeq = $.ajax({
method: "GET",
url: "ajaxreq/returnProduct.php",
data: {
invoice: invoice,
product_id: product,
product_name: product_name,
price: price,
orderQty: orderQty,
returnQty: qty,
applyReturn: "applyReturn"
}
});
// reeq.done(function(data) {
// console.log(data);
// });
});
$(".no-return").on("click", function(){
var inputField = $(this).attr("data-returnQtyField");
var product = $(this).attr("data-product_id");
var product_name = $(".cl"+product+"2").attr("data-product");
$("."+inputField).val(0);
var aa = $(".productPrice").text(); // total price without discount
var price = $(this).attr("data-price");
// console.log(invoice);
var qty = 0;
$(".cl"+product).val(qty*price);
$(".cl"+product).text(qty*price);
var sum = 0;
$('.totalprice').each(function()
{
sum += parseFloat($(this).text());
});
$(".return_total_price").text(sum);
$(".return_total_price").val(sum);
var vl;
if(discountType == "flat"){
vl = sum - discount;
}else{
vl = sum - (sum*(discount/100));
}
$(".return_product_value").text(vl);
$(".return_product_value").val(vl);
var totalPaid = $(".totalPaid").text();
// $(".cus_should_payable").text(totalPaid - vl);
$(".cus_should_payable").text(vl);
$(".cus_should_payable").val(vl);
var reeq = $.ajax({
method: "GET",
url: "ajaxreq/returnProduct.php",
data: {
invoice: invoice,
product_name: product_name,
removeFromReturn: "removeFromReturn"
}
});
reeq.done(function(data) {
console.log(data);
});
});
});
</script>
</body>
</html>