<?php
include("../../db.php");
header('Content-Type: application/json');

$status = 0;
$outstanding = 0;

if (isset($_GET['adm_no']) && isset($_GET['idno']) && isset($_GET['session'])){

    $adm_no = $_GET['adm_no'];
    $idno = $_GET['idno'];
    $session = $_GET['session'];

    $reff_receipt_amt = 0;

    $reff_rec_res = $db->getRows("SELECT amount FROM reff_receipt WHERE idno = '$idno' AND session = '$session' AND type LIKE 'pocket_money_%' ");
    if (is_array($reff_rec_res) && count($reff_rec_res) > 0) {
        foreach ($reff_rec_res as $row) {
            $reff_receipt_amt += $row['amount'];
        }
    }

    $pocket_money = $db->getVal("select pocket_money from pocket_money where admissionno='$adm_no'");

    if ($pocket_money != ''){
        $outstanding = $pocket_money - $reff_receipt_amt;
        $status = 1;
    }

}

echo json_encode(array("status" => $status, "outstanding" => $outstanding));