<?php
include ('includes/config/config.php');
include ('includes/functions.php');
include ('log_entry.php');
error_reporting(E_ERROR | E_PARSE);

$item_batch = $_POST["item_batch_no"];
$item_id = $_POST['item_id'];
$appointment_id = $_POST['apt_id'];
$miscellaneous = $_POST['miscellaneous'];

error_log("miscellaneous " . $miscellaneous);

$data = null;

if ($miscellaneous == 'Y') {
    $sql_treatment_qty = "select * from  opd_miscellaneous_treatment where appointment_id='" . $appointment_id . "' and medicine='" . $item_id . "' and miscellaneous_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 = $row_treatment_qty['miscellaneous_issued_qty'];
} else {
    $sql_treatment_qty = "select * from  opd_consumables where consume_id='" . $appointment_id . "' and medicine='" . $item_id . "' and consum_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 = $row_treatment_qty['issued_qty'];
}
echo json_encode($data);
?>