0 and item_batch_no!='' "; error_log("query for available medicine : ".$query); if (!$result = @mysqli_query($GLOBALS['conn'],$query)) { die(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)) { die(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); ?>