ohctech_p8/get_medicine_available_qty_store.php

55 lines
1.9 KiB
PHP
Raw Normal View History

2024-10-16 19:18:52 +05:30
<?php
include('includes/config/config.php');
include('log_entry.php');
$value = $_REQUEST['value'];
$appointment_id = $_POST['appointment_id'];
$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 = '".$value."' 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($conn,$query)) {
2024-11-02 18:03:13 +05:30
die(mysqli_error($conn));
2024-10-16 19:18:52 +05:30
}
$data = array();
if(mysqli_num_rows($result) > 0) {
$qty=0;
while ($row = @mysqli_fetch_assoc($result)) {
$item_batch=$_POST["batch"];
$item_id = $row['item_id'];
$sql_treatment_qty = "select * from treatment where appointment_id='" . $appointment_id . "' and is_display!='N' and item_id='" . $item_id . "' and item_batch_no='".$item_batch."' ";
error_log("qyery ".$sql_treatment_qty);
$res_treatment_qty = mysqli_query($conn, $sql_treatment_qty);
$row_treatment_qty = mysqli_fetch_assoc($res_treatment_qty);
$data["pre_issued_qty"] = $row_treatment_qty['issued_qty'];
$data["unit_id"]=$row["unit_id"];
$data["item_id"]=$row["item_id"];
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"];
}
}
$data["stock_qty"]=$qty;
}
else
{
$data['status'] = 200;
$data['message'] = "Data not found!";
}
error_log(print_r($data,true));
echo json_encode($data);
?>