-3
I’ve been working for stock out inventory process which can search all item in the search bar and display in the table1 and click the item selected to enter the quantity want to deduct.
And display each data in table row to table2 selected by the user.
Anyone can help me with this? i just wanna know on how to get the each value in table2 to save in the database with name "tblstockout" and update those item quantity in "tblstock"
Thank you and regards
here’s my code:
<!--- html code to display the table1 and table 2-->
<!DOCTYPE html>
<html>
<head>
<body class="hold-transition sidebar-mini layout-fixed">
<!--TABLE 1-->
<div class="input-group"><div class="input-group-prepend"><span class="input-group-text" id="basic-addon1"><i class="fas fa-search"></i></span></div>
<input class="form-control" type="text" placeholder="Product Search" aria-label="Search" id="search" name="search" onkeyup="loadproducts();"/>
</div></div>
<div id="product_area" class="table-responsive-sm table-wrapper-scroll-y my-custom-scrollbar" >
<table class="table table-bordered table-striped" style="cursor: pointer;" id="table1">
<thead>
<tr class='text-center'>
<td>Item Code</td>
<td>Item description</td>
<td>Unit</td>
<td>Stocks</td>
</tr>
<tbody id="products">
</tbody>
</thead>
</table>
</div>
</div>
<!--TABLE 2-->
<div id="content">
<div id="price_column" class="table-responsive-sm table-wrapper-scroll-y my-custom-scrollbar-a">
<form method="POST" action="">
<table class="table table-bordered table-striped" style="cursor: pointer;" id="table2">
<thead>
<tr class='text-center'>
<td>Item Code</td>
<td>Item description</td>
<td>Unit</td>
<td>Quantity</td>
<td>Action</td>
</tr>
</thead>
<tbody id="tableData">
</tbody>
</table>
</form>
</div>
</div>
<!--Button to submit-->
<button style="float: left;" id="buttons" type="button" name='enter' class="Enter btn btn-secondary border"><i class="fas fa-handshake"></i> Finish</button>
<!--Button to cancel-->
<button style="float: left;" id="buttons" type="button" class="cancel btn btn-secondary border"><i class="fas fa-ban"></i> Cancel</button>
</div>
</div>
</div>
<!--JQuery to display data search by the user-->
<?php include('templates/js_popper.php');?>
<!--script function-->
<script type="text/javascript" src="script.js"></script>
</body>
</html>
<!----PHP code for the item_load.php to fetch product in the database-->
<?php
//database included//
if (isset($_POST['products'])){
$name = mysqli_real_escape_string($con,$_POST['products']);
$show = "SELECT * FROM tblstock WHERE item_desc LIKE '$name%' AND qnty > 0 OR id LIKE '$name%' AND qnty > 0";
$query = mysqli_query($con,$show);
if(mysqli_num_rows($query)>0){
while($row = mysqli_fetch_array($query)){
echo "<tr class='js-add' data-barcode=".$row['id']." data-product=".$row['item_desc']." data-unit=".$row['unit'].">
<td><center>".$row['id']."</td>
<td>".$row['item_desc']."</td>";
echo "<td><center>".$row['unit']."</center></td>";
echo "<td><center>".$row['qnty']."</center></td>";
}
}
else{
echo "<td></td><td><center>No item found!</center></td><td></td><td></td>";
}
}?>
<script>
function loadproducts(){
var name = $("#search").val();
if(name){
$.ajax({
type: 'post',
data: {
products:name,
},
url: 'item_load.php',
success: function (Response){
$('#products').html(Response);
}
});
}
};
//The script function to put quantity of each item_desc selected and add another row to the table2//
$('body').on('click','.js-add',function(){
var target = $(this);
var product = target.attr('data-product');
var barcode = target.attr('data-barcode');
var unit = target.attr('data-unit');
swal({
title: "Enter Quantity:",
content: "input",
})
.then((value) => {
if (value == "") {
swal("Error","Entered none!","error");
}else{
var qtynum = value;
if (isNaN(qtynum)){
swal("Error","Please enter a valid number!","error");
}else if(qtynum == null){
swal("Error","Please enter a number!","error");
}else{
$('#tableData').append("<tr class='prd'><td class='barcode text-center'>"+barcode+"</td><td class='text-center'>"+product+"</td><td class='text-center'>"+unit+"</td><td class='qty text-center'>"+value+"</td><td class='text-center p-1'><button class='btn btn-danger btn-sm' type='button' id='delete-row'><i class='fas fa-times-circle'></i></button><tr>");
}
}
});
});
</script>