I am facing another issue. i have pharmacy stock with two different purchase price . for example medicine name “ABC” entered in stock with 50 qty and 50 USD per unit price. and 10 days later, same medicine “ABC” need to be entered in stock but due to inflation price become 60 USD per unit. everything is fine at this point as both the purchasing have different invoice no to differentiate between them.
but the problem start when customer purchase medicine and operator enter details in following below code form . The gfg.php fetch data from stock table . But the issue is there can be more than one entry of same name medicine “ABC” in stock table with different purchase date and invoice no .
Now I want to learn from you that is it possible that in customer bill, when operator select medicine name, then medicine should be select from first entered stock. And when all quantity of first stock stock ended than it automatically select from 2nd entered stock and so on…
is it possible to manage or not ???
<table class="table table-bordered">
<thead class="table-success" style="background-color: #3fbbc0;">
<tr>
<th width="15%"><center>Medicine Name</th>
<th width="10%"><center>Qty</th>
<th width="10%"><center>Purchase Price</th>
<th width="10%"><center>Sell Price</th>
<th width="10%"><center>Discount</th>
<th width="10%"><center>Total</th>
<th width="20%"><center>Remarks</th>
<th width="5%"></th>
<button type="button" class="btn btn-sm btn-success" onclick="BtnAdd()">Add Item</button>
</th>
</tr>
</thead>
<tbody id="TBody">
<tr id="TRow" class="d-none">
<td><Select class="scode form-control text-end" name="scode[]" id = "tutorial_name" required onchange="GetDetail(this.closest('tr'))">
<option value="">Select Product</option>
<?php
include('db.php');
$sql = mysqli_query($con,"SELECT * FROM procd2");
while($row=mysqli_fetch_array($sql))
{
echo '<option value="'.$row['pro1'].'">'.$row['pro1'].'</option>';
} ?></select>
</td>
<td><input type="text" class="qty form-control text-end" name="qty[]" id="ccc" onfocus="Calc(this);"></td>
<td><input type="text" class="purprice form-control text-end" name="purprice[]" id="ddd1" onfocus="Calc(this);" readonly style="background-color: #3fbbc0;"></td>
<td><input type="text" class="price form-control text-end" name="price1[]" id="ddd" onfocus="Calc(this);" readonly style="background-color: #3fbbc0;"></td>
<td><input type="text" class="discunt form-control text-end" name="discunt[]" id="eee" onchange="Calc(this);"></td>
<td><input type="text" class="tot4 form-control text-end" name="tot4[]" id="fff" readonly style="background-color: #3fbbc0;"></td>
<td><input type="text" class="form-control text-end" name="remarks3[]" id="zzz" ></td>
<td class="NoPrint"><button type="button" class="btn btn-success" style="line-height: 1;" onclick="BtnDel(this)">x</button></td>
</tr> </tbody> </table>
below script which fetch auto fill value from database file gfg.php
<script>
// onkeyup event will occur when the user
// release the key and calls the function
// assigned to this event
function GetDetail(row) {
let str = row.querySelector(".scode").value;
if (str.length == 0) {
row.querySelector(".qty").value = "";
row.querySelector(".purprice").value = "";
row.querySelector(".price").value = "";
row.querySelector(".discunt").value = "";
row.querySelector(".tot4").value = "";
return;
} else {
// Creates a new XMLHttpRequest object
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
// Defines a function to be called when
// the readyState property changes
if (this.readyState == 4 &&
this.status == 200) {
// Typical action to be performed
// when the document is ready
var myObj = JSON.parse(this.responseText);
// Returns the response data as a
// string and store this array in
// a variable assign the value
// received to first name input field
row.querySelector(".qty").value = myObj[0];
row.querySelector(".purprice").value = myObj[0];
row.querySelector(".price").value = myObj[1];
row.querySelector(".discunt").value = myObj[2];
row.querySelector(".tot4").value = myObj[3];
}
};
// xhttp.open("GET", "filename", true);
xmlhttp.open("GET", "gfg.php?user_id=" + str, true); // value came from gfg.php
// Sends the request to the server
xmlhttp.send();
}
}
</script>