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

$status = 0;
$credit = 0;
$debit = 0;
$total_due = 0;

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

    $student_id = $_GET['uid'];
    $session = $_GET['session'];

    $income=$db->getVal("select sum(amount) from transaction where rid='".$student_id."' and type='deposit' and tfor='hostel-income' and session='".$session."' and school_id = '1' ");

    if ($income == ''){
        $income = 0;
    }

    $expance=$db->getVal("select sum(amount) from transaction where rid='".$student_id."' and type='withdraw' and tfor='hostel-expance' and session='".$session."' and school_id = '1' ");

    if ($expance == ''){
        $expance = 0;
    }

    $total_due = $expance - $income;

    $credit = $income;
    $debit = $expance;

    $status = 1;
}

echo json_encode(array("status" => $status, "credit" => $credit, "debit" => $debit, "total_due" => $total_due));
