$sql="select cat_id from tbl_categories order by sequence asc";
error_log("cat id selecting from tbl_categories".$sql);
$result=mysqli_query($conn,$sql);
$med_cat=array();
functiontotal($item_id,$m,$y,$ohc)
{
$issued_qty_total=0;
$sql_diect_issue_query="SELECT ifnull(sum(dd.issue_qty),0) as direct_issue FROM direct_medicine_issue_log_details dd LEFT JOIN direct_medicine_issue_log dm ON dd.issue_log_id = dm.issue_log_id WHERE item_id='$item_id' and month(dm.date_of_issue)='$m' and year(dm.date_of_issue)='$y' and ohc_location_id = '".$ohc."' group by item_id";
$sql_opd_consumables="SELECT ifnull(sum(c.issued_qty),0) as consumable_issue,e.ticket_no FROM opd_consumables c LEFT JOIN employee_appointment e ON c.consume_id = e.appointment_id where medicine = '$item_id' and month(e.appointment_date) = '$m' and year(e.appointment_date) = '$y' and ohc_type_id = '".$ohc."' group by item_id ";
$sql_consume="select a.appointment_id, (ifnull(sum(a.issued_qty),0)+ifnull(sum(c.issued_qty),0)) as total_issued,b.ticket_no from treatment a left join employee_appointment b on a.appointment_id = b.appointment_id left join detention_intake c on b.appointment_id = c.det_id where item_id = '$item_id' and month(b.appointment_date) = '$m' and year(b.appointment_date) = '$y' and b.ohc_type_id = '".$ohc."' group by item_id ";
$sql_diect_issue_query="SELECT ifnull(sum(dd.issue_qty),0) as direct_issue FROM direct_medicine_issue_log_details dd LEFT JOIN direct_medicine_issue_log dm ON dd.issue_log_id = dm.issue_log_id WHERE item_id='$item_id' and day(dm.date_of_issue) = '$d' and month(dm.date_of_issue)='$m' and year(dm.date_of_issue)='$y' and ohc_location_id = '".$ohc."' group by item_id";
$sql_opd_consumables="SELECT ifnull(sum(c.issued_qty),0) as consumable_issue,e.ticket_no FROM opd_consumables c LEFT JOIN employee_appointment e ON c.consume_id = e.appointment_id where medicine = '$item_id' and day(e.appointment_date)='$d' and month(e.appointment_date) = '$m' and year(e.appointment_date) = '$y' and ohc_type_id = '".$ohc."' group by item_id ";
$sql_consume="select a.appointment_id, (ifnull(sum(a.issued_qty),0)+ifnull(sum(c.issued_qty),0)) as total_issued,b.ticket_no from treatment a left join employee_appointment b on a.appointment_id = b.appointment_id left join detention_intake c on b.appointment_id = c.det_id where item_id = '$item_id' and day(b.appointment_date)='$d' and month(b.appointment_date) = '$m' and year(b.appointment_date) = '$y' and b.ohc_type_id = '".$ohc."' group by item_id ";
$query="select a.item_id,c.item_name from item_stock a, tbl_items c where a.item_id = c.item_id and c.cat = '$value' and c.status = '1' group by a.item_id order by a.item_id asc ";