<?php

include "../../myDatabase2.php";
$registrationNo = $_GET['registrationNo'];
$itemNo = $_GET['itemNo'];
$quantity = $_GET['quantity'];
$username = $_GET['username'];
$show = $_GET['show'];
$desc = $_GET['desc'];
$ro = new database2();
$titlez = $ro->getTitle($itemNo);
if ($ro->doubleSelectNow("patientCharges", "quantity", "itemNo", $itemNo, "registrationNo", $registrationNo) < $quantity) {
    echo "<br><br><br><font color=red>Ooopsss.. you are trying to return {$quantity} but there is only " . $ro->doubleSelectNow("patientCharges", "quantity", "itemNo", $itemNo, "registrationNo", $registrationNo) . " Dispensed to the patient</font>";
    echo "\n<script type='text/javascript'>\nwindow.location='http://" . $ro->getMyUrl() . "/COCONUT/patientProfile/patientChargesTitle.php?registrationNo={$registrationNo}&title={$titlez}&username={$username}&show={$show}&desc={$desc}';\n</script>\n";
} else {
    if (($ro->getTitle($itemNo) == "MEDICINE" || $ro->getTitle($itemNo) == "SUPPLIES") && $ro->getChargesStatusDept($itemNo)) {
        if ($ro->selectNow("inventory", "autoDispense", "inventoryCode", $ro->selectNow("patientCharges", "chargesCode", "itemNo", $itemNo)) == "yes") {
            $currentQTY = $ro->selectNow("inventory", "quantity", "inventoryCode", $ro->selectNow("patientCharges", "chargesCode", "itemNo", $itemNo));
            // current qty ng meds/sup sa inventory
            $newQTY = $currentQTY + $quantity;
            //dagdag inventory once return
            $ro->editNow("inventory", "inventoryCode", $ro->selectNow("patientCharges", "chargesCode", "itemNo", $itemNo), "quantity", $newQTY);
            // update qty sa database
            $ro->deletePatientCharges($registrationNo, $itemNo);
            echo "\n<script type='text/javascript'>\nwindow.location='http://" . $ro->getMyUrl() . "/COCONUT/patientProfile/patientChargesTitle.php?registrationNo={$registrationNo}&title={$titlez}&username={$username}&show={$show}&desc={$desc}';\n</script>\n";
        } else {
            $ro->editNow("patientCharges", "itemNo", $itemNo, "status", "Return");
            $ro->editNow("patientCharges", "itemNo", $itemNo, "dateReturn", date("Y-m-d"));
            $ro->editNow("patientCharges", "itemNo", $itemNo, "departmentStatus", $quantity . "_" . $registrationNo);
            $ro->returnInventory($itemNo, $registrationNo, $ro->selectNow("patientCharges", "description", "itemNo", $itemNo), $quantity, date("Y-m-d") . "@" . $ro->getSynapseTime(), $username);
            echo "\n<script type='text/javascript'>\nwindow.location='http://" . $ro->getMyUrl() . "/COCONUT/patientProfile/patientChargesTitle.php?registrationNo={$registrationNo}&title={$titlez}&username={$username}&show={$show}&desc={$desc}';\n</script>\n";
<?php

include "../../myDatabase2.php";
$registrationNo = $_GET['registrationNo'];
$itemNo = $_GET['itemNo'];
$quantity = $_GET['quantity'];
$username = $_GET['username'];
$show = $_GET['show'];
$desc = $_GET['desc'];
$ro = new database2();
$titlez = $ro->getTitle($itemNo);
if ($ro->doubleSelectNow("patientCharges", "quantity", "itemNo", $itemNo, "registrationNo", $registrationNo) < $quantity) {
    echo "<br><br><br><font color=red>Ooopsss.. you are trying to return {$quantity} but there is only " . $ro->doubleSelectNow("patientCharges", "quantity", "itemNo", $itemNo, "registrationNo", $registrationNo) . " Dispensed to the patient</font>";
} else {
    if (($ro->getTitle($itemNo) == "MEDICINE" || $ro->getTitle($itemNo) == "SUPPLIES") && $ro->getChargesStatusDept($itemNo)) {
        if ($ro->selectNow("inventory", "autoDispense", "inventoryCode", $ro->selectNow("patientCharges", "chargesCode", "itemNo", $itemNo)) == "yes") {
            $currentQTY = $ro->selectNow("inventory", "quantity", "inventoryCode", $ro->selectNow("patientCharges", "chargesCode", "itemNo", $itemNo));
            // current qty ng meds/sup sa inventory
            $newQTY = $currentQTY + $quantity;
            //dagdag inventory once return
            $ro->editNow("inventory", "inventoryCode", $ro->selectNow("patientCharges", "chargesCode", "itemNo", $itemNo), "quantity", $newQTY);
            // update qty sa database
            $ro->deletePatientCharges($registrationNo, $itemNo);
        } else {
            $ro->editNow("patientCharges", "itemNo", $itemNo, "status", "Return");
            $ro->editNow("patientCharges", "itemNo", $itemNo, "dateReturn", date("Y-m-d"));
            $ro->editNow("patientCharges", "itemNo", $itemNo, "departmentStatus", $quantity . "_" . $registrationNo);
            $ro->returnInventory($itemNo, $registrationNo, $ro->selectNow("patientCharges", "description", "itemNo", $itemNo), $quantity, date("Y-m-d") . "@" . $ro->getSynapseTime(), $username);
            /*
            $regNo = $ro->selectNow("patientCharges","registrationNo","itemNo",$itemNo);
            $chargeCodez = $ro->selectNow("patientCharges","chargesCode","itemNo",$itemNo);
<?php

include "../../myDatabase2.php";
$registrationNo = $_GET['registrationNo'];
$itemNo = $_GET['itemNo'];
$quantity = $_GET['quantity'];
$username = $_GET['username'];
$show = $_GET['show'];
$desc = $_GET['desc'];
$ro = new database2();
$titlez = $ro->getTitle($itemNo);
if ($ro->doubleSelectNow("patientCharges", "quantity", "itemNo", $itemNo, "registrationNo", $registrationNo) < $quantity) {
    echo "<br><br><br><font color=red>Ooopsss.. you are trying to return {$quantity} but there is only " . $ro->doubleSelectNow("patientCharges", "quantity", "itemNo", $itemNo, "registrationNo", $registrationNo) . " Dispensed to the patient</font>";
} else {
    if (($ro->getTitle($itemNo) == "MEDICINE" || $ro->getTitle($itemNo) == "SUPPLIES") && $ro->getChargesStatusDept($itemNo) && $ro->selectNow("inventory", "classification", "inventoryCode", $ro->selectNow("patientCharges", "chargesCode", "itemNo", $itemNo)) != "noInventory") {
        if ($ro->selectNow("inventory", "autoDispense", "inventoryCode", $ro->selectNow("patientCharges", "chargesCode", "itemNo", $itemNo)) == "yes") {
            $currentQTY = $ro->selectNow("inventory", "quantity", "inventoryCode", $ro->selectNow("patientCharges", "chargesCode", "itemNo", $itemNo));
            // current qty ng meds/sup sa inventory
            $newQTY = $currentQTY + $quantity;
            //dagdag inventory once return
            $ro->editNow("inventory", "inventoryCode", $ro->selectNow("patientCharges", "chargesCode", "itemNo", $itemNo), "quantity", $newQTY);
            // update qty sa database
            $ro->deletePatientCharges($registrationNo, $itemNo);
        } else {
            $ro->editNow("patientCharges", "itemNo", $itemNo, "status", "Return");
            $ro->editNow("patientCharges", "itemNo", $itemNo, "dateReturn", date("Y-m-d"));
            $ro->editNow("patientCharges", "itemNo", $itemNo, "departmentStatus", $quantity . "_" . $registrationNo);
            $ro->returnInventory($itemNo, $registrationNo, $ro->selectNow("patientCharges", "description", "itemNo", $itemNo), $quantity, date("Y-m-d") . "@" . $ro->getSynapseTime(), $username);
            /*
            $regNo = $ro->selectNow("patientCharges","registrationNo","itemNo",$itemNo);
            $chargeCodez = $ro->selectNow("patientCharges","chargesCode","itemNo",$itemNo);