-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage_receiving.php
276 lines (264 loc) · 8.87 KB
/
manage_receiving.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
<?php include 'db_connect.php';
if(isset($_GET['id'])){
$qry = $conn->query("SELECT * FROM receiving_list where id=".$_GET['id'])->fetch_array();
foreach($qry as $k => $val){
$$k = $val;
}
$inv = $conn->query("SELECT * FROM inventory where type=1 and form_id=".$_GET['id']);
}
?>
<div class="container-fluid">
<div class="col-lg-12">
<div class="card">
<div class="card-header">
<h4>Manage Receiving</h4>
</div>
<div class="card-body">
<form action="" id="manage-receiving">
<input type="hidden" name="id" value="<?php echo isset($_GET['id']) ? $_GET['id'] : '' ?>">
<input type="hidden" name="ref_no" value="<?php echo isset($ref_no) ? $ref_no : '' ?>">
<div class="col-md-12">
<div class="row">
<div class="form-group col-md-5">
<label class="control-label">Supplier</label>
<select name="supplier_id" id="" class="custom-select browser-default select2">
<option value=""></option>
<?php
$supplier = $conn->query("SELECT * FROM supplier_list order by supplier_name asc");
while($row=$supplier->fetch_assoc()):
?>
<option value="<?php echo $row['id'] ?>"><?php echo $row['supplier_name'] ?></option>
<?php endwhile; ?>
</select>
</div>
</div>
<hr>
<div class="row mb-3">
<div class="col-md-4">
<label class="control-label">Product</label>
<select name="" id="product" class="custom-select browser-default select2">
<option value=""></option>
<?php
$cat = $conn->query("SELECT * FROM category_list order by name asc");
while($row=$cat->fetch_assoc()):
$cat_arr[$row['id']] = $row['name'];
endwhile;
$product = $conn->query("SELECT * FROM product_list order by name asc");
while($row=$product->fetch_assoc()):
$prod[$row['id']] = $row;
?>
<option value="<?php echo $row['id'] ?>" data-name="<?php echo $row['name'] ?>" data-description="<?php echo $row['description'] ?>"><?php echo $row['name'] . ' | ' . $row['product_id'] ?></option>
<?php endwhile; ?>
</select>
</div>
<div class="col-md-2">
<label class="control-label">Qty</label>
<input type="number" class="form-control text-right" step="any" id="qty" >
</div>
<div class="col-md-3">
<label class="control-label">Price</label>
<input type="number" class="form-control text-right" step="any" id="price" >
</div>
<div class="col-md-3">
<label class="control-label"> </label>
<button class="btn btn-block btn-sm btn-primary" type="button" id="add_list"><i class="fa fa-plus"></i> Add to List</button>
</div>
</div>
<div class="row">
<table class="table table-bordered" id="list">
<colgroup>
<col width="30%">
<col width="10%">
<col width="25%">
<col width="25%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th class="text-center">Product</th>
<th class="text-center">Qty</th>
<th class="text-center">Price</th>
<th class="text-center">Amount</th>
<th class="text-center"></th>
</tr>
</thead>
<tbody>
<?php
if(isset($id)):
while($row = $inv->fetch_assoc()):
foreach(json_decode($row['other_details']) as $k=>$v){
$row[$k] = $v;
}
?>
<tr class="item-row">
<td>
<input type="hidden" name="inv_id[]" value="<?php echo $row['id'] ?>">
<input type="hidden" name="product_id[]" value="<?php echo $row['product_id'] ?>">
<p class="pname">Name: <b><?php echo $prod[$row['product_id']]['name'] ?></b></p>
<p class="pdesc"><small><i>Description: <b><?php echo $prod[$row['product_id']]['description'] ?></b></i></small></p>
</td>
<td>
<input type="number" min="1" step="any" name="qty[]" value="<?php echo $row['qty'] ?>" class="text-right">
</td>
<td>
<input type="number" min="1" step="any" name="price[]" value="<?php echo $row['price'] ?>" class="text-right">
</td>
<td>
<p class="amount text-right"></p>
</td>
<td class="text-center">
<buttob class="btn btn-sm btn-danger" onclick = "rem_list($(this))"><i class="fa fa-trash"></i></buttob>
</td>
</tr>
<?php endwhile; ?>
<?php endif; ?>
</tbody>
<tfoot>
<tr>
<th class="text-right" colspan="3">Total</th>
<th class="text-right tamount"></th>
<th><input type="hidden" name="tamount" value=""></th>
</tr>
</tfoot>
</table>
</div>
<div class="row">
<button class="btn btn-primary btn-sm btn-block float-right .col-md-3">Save</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div id="tr_clone">
<table>
<tr class="item-row">
<td>
<input type="hidden" name="inv_id[]" value="">
<input type="hidden" name="product_id[]" value="">
<p class="pname">Name: <b>product</b></p>
<p class="pdesc"><small><i>Description: <b>Description</b></i></small></p>
</td>
<td>
<input type="number" min="1" step="any" name="qty[]" value="" class="text-right">
</td>
<td>
<input type="number" min="1" step="any" name="price[]" value="" class="text-right">
</td>
<td>
<p class="amount text-right"></p>
</td>
<td class="text-center">
<buttob class="btn btn-sm btn-danger" onclick = "rem_list($(this))"><i class="fa fa-trash"></i></buttob>
</td>
</tr>
</table>
</div>
<style type="text/css">
#tr_clone{
display: none;
}
td{
vertical-align: middle;
}
td p {
margin: unset;
}
td input[type='number']{
height: calc(100%);
width: calc(100%);
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
</style>
<script>
$('.select2').select2({
placeholder:"Please select here",
width:"100%"
})
$(document).ready(function(){
if('<?php echo isset($id) ?>' == 1){
$('[name="supplier_id"]').val('<?php echo isset($supplier_id) ? $supplier_id :'' ?>').select2({
placeholder:"Please select here",
width:"100%"
})
calculate_total()
}
})
function rem_list(_this){
_this.closest('tr').remove()
}
$('#add_list').click(function(){
// alert("TEST");
// return false;
var tr = $('#tr_clone tr.item-row').clone();
var product = $('#product').val(),
qty = $('#qty').val(),
price = $('#price').val();
if($('#list').find('tr[data-id="'+product+'"]').length > 0){
alert_toast("Product already on the list",'danger')
return false;
}
if(product == '' || qty == '' || price ==''){
alert_toast("Please complete the fields first",'danger')
return false;
}
tr.attr('data-id',product)
tr.find('.pname b').html($("#product option[value='"+product+"']").attr('data-name'))
tr.find('.pdesc b').html($("#product option[value='"+product+"']").attr('data-description'))
tr.find('[name="product_id[]"]').val(product)
tr.find('[name="qty[]"]').val(qty)
tr.find('[name="price[]"]').val(price)
var amount = parseFloat(price) * parseFloat(qty);
tr.find('.amount').html(parseFloat(amount).toLocaleString('en-US',{style:'decimal',maximumFractionDigits:2,minimumFractionDigits:2}))
$('#list tbody').append(tr)
calculate_total()
$('[name="qty[]"],[name="price[]"]').keyup(function(){
calculate_total()
})
$('#product').val('').select2({
placeholder:"Please select here",
width:"100%"
})
$('#qty').val('')
$('#price').val('')
})
function calculate_total(){
var total = 0;
$('#list tbody').find('.item-row').each(function(){
var _this = $(this).closest('tr')
var amount = parseFloat(_this.find('[name="qty[]"]').val()) * parseFloat(_this.find('[name="price[]"]').val());
amount = amount > 0 ? amount :0;
_this.find('p.amount').html(parseFloat(amount).toLocaleString('en-US',{style:'decimal',maximumFractionDigits:2,minimumFractionDigits:2}))
total+=parseFloat(amount);
})
$('#list [name="tamount"]').val(total)
$('#list .tamount').html(parseFloat(total).toLocaleString('en-US',{style:'decimal',maximumFractionDigits:2,minimumFractionDigits:2}))
}
$('#manage-receiving').submit(function(e){
e.preventDefault()
start_load()
if($("#list .item-row").length <= 0){
alert_toast("Please insert atleast 1 item first.",'danger');
end_load();
return false;
}
$.ajax({
url:'ajax.php?action=save_receiving',
method: 'POST',
data: $(this).serialize(),
success:function(resp){
if(resp==1){
alert_toast("Data successfully added",'success')
setTimeout(function(){
location.href = "index.php?page=receiving"
},1500)
}
}
})
})
</script>