$query_received_ref_no="select max( CAST(substring(received_ref_no,locate('-',received_ref_no)+1,length(received_ref_no)-(5+locate('-',received_ref_no))) as UNSIGNED) ) from received_master where received_ref_no like '%$year%' and ohc_location_id=$ohc_type";
*$current_stock_query="update tbl_items set current_stock_level='".$current_stock_level_items_qty."' where item_id='".$rows_procurement_items['item_id']."' ";
updateDispensaryStockForItemInward($_SESSION['current_ohcttype'],${"item_id$i"},${"dispensary_item_qty$i"});//keeping it same as no difference here with packing item
}
// echo $i;
/*$current_stock__query="select stock_qty,expiry_date from item_stock where item_id=${"item_id$i"} and item_batch_no='".${"item_batch_no$i"}."' ";
$current_stock_query="update item_stock set stock_qty='".$stock_qty."' where item_id='${"item_id$i"}' and item_batch_no='${"item_batch_no$i"}' ";
// echo $current_stock_query;
mysqli_query($conn,$current_stock_query);*/
/*$current_stock__query_dispensary="select stock_qty from item_stock_dispensary where item_id=${"item_id$i"} and item_batch_no='".${"item_batch_no$i"}."' and ohc_location_id='".$_POST['ohc_location_id']."' ";
$current_stock_query_dispensary="update item_stock_dispensary set stock_qty='".$stock_qty_dispensary."' where item_id='${"item_id$i"}' and item_batch_no='${"item_batch_no$i"}' and ohc_location_id='".$_POST['ohc_location_id']."' ";
$current_stock_query_dispensary="insert into item_stock_dispensary set expiry_date=STR_TO_DATE('".${"expiry_date$i"}."','%Y-%m-%d'), stock_qty='".$stock_qty_dispensary."',ohc_location_id='".$_POST['ohc_location_id']."' , item_id='${"item_id$i"}', item_batch_no='${"item_batch_no$i"}' ";
$rate_sql="select * from item_cost where item_id='".${"item_id$i"}."'";
$rate_result=mysqli_query($conn,$rate_sql);
$num_count=mysqli_num_rows($rate_result);
$row_rate=mysqli_fetch_assoc($rate_result);
$new_applicable_date=date("Y/m/d");
// getting new cost from latest procurement start
$cost_per_unit=0;
$total_qty=0;
$total_mrp=0;
$total_cost=0;
$rate_sql_proc="select * from procurement p left join procurement_items pt on p.procurement_id=pt.procurement_id where pt.item_id= '".${"item_id$i"}."' and pt.ohc_type_id='".$_SESSION['current_ohcttype']."' order by pt.procurement_item_id desc limit 1";
error_log("query to get latest item cost ".$rate_sql_proc);
$rate_update_sql="update item_cost set item_rate_latest='".$new_cost."',item_rate_old='".$old_cost."',applicable_date='".$new_applicable_date."',ohc_type_id='".$_SESSION['current_ohcttype']."' where item_id='".${"item_id$i"}."' ";
error_log("error in update item ".mysqli_error($conn));
}
}else{
$new_cost=$cost_per_unit;
$insert_item_rate="insert into item_cost set item_id='".${"item_id$i"}."', item_rate_latest='".$new_cost."',item_rate_old='".$new_cost."',applicable_date='".$new_applicable_date."',ohc_type_id='".$_SESSION['current_ohcttype']."'";