ohctech_p8/select_item_store.php
2024-10-16 19:18:52 +05:30

59 lines
1.9 KiB
PHP

<?php
include('includes/config/config.php');
$itemId = $_REQUEST['item_id'];
function getStock($itemId){
$query = "select a.item_id, b.stock_qty,b.expiry_date, a.unit_id from tbl_items a left join item_stock b on a.item_id = b.item_id where a.item_id = '".$itemId."' and a.is_group_item = 'N' and b.ohc_type_id = '".$_SESSION['current_ohcttype']."' and stock_qty > 0 and item_batch_no!='' ";
error_log("query for available medicine : ".$query);
if (!$result = @mysqli_query($GLOBALS['conn'],$query)) {
exit(mysqli_error($GLOBALS['conn']));
}
$qty=0;
if(mysqli_num_rows($result) > 0) {
while ($row = @mysqli_fetch_assoc($result)) {
if($row['expiry_date']!="0000-00-00" && $row['expiry_date']!="" && $row['expiry_date']!=null){
$date= date('Y-m-d', strtotime($row['expiry_date'])) ;
$date_today= date("Y-m-d");
// error_log($date_today." pp ".$date);
if($date>=$date_today){
$qty+=$row["stock_qty"];
}
}else{
$qty+=$row["stock_qty"];
}
}
return $qty;
}
}
$query = "select i.item_name, i.item_form_id, d.item_batch_no, i.is_prescription, i.unit_id, i.item_id from tbl_items i inner join item_stock d on i.item_id = d.item_id where d.expiry_date>=CURDATE() and d.item_batch_no!='' and d.ohc_type_id ='".$_SESSION['current_ohcttype']."' and i.item_id = '".$itemId."' and stock_qty > 0";
error_log("str availabe_qty".$query);
if (!$result = @mysqli_query($conn,$query)) {
exit(mysqli_error($conn));
}
$data = array();
if(mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
////
$row['current_stock_level'] =getStock($itemId);
$data = $row;
}
}
else
{
$data['status'] = 200;
$data['message'] = "Data not found!";
}
echo json_encode($data);
?>