<?php
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);

$mvisano = $_REQUEST["visano"]; 
$midno   = $_REQUEST["idno"]; 


$subadd = mysqli_query($conn, "SELECT sum(qty) as adqty from visasacn 
                                             WHERE `visano` = '$mvisano'  AND `idno` ='$midno' AND qty > 0") or die(mysqli_error($conn));
$madd = mysqli_fetch_object($subadd);
                  
$subless = mysqli_query($conn, "SELECT sum(qty) as adqty from visasacn 
                                              WHERE `visano` = '$mvisano' AND `idno` ='$midno' AND qty < 0") or die(mysqli_error($conn));
$mless = mysqli_fetch_object($subless);
 
$add = $madd->adqty;
$les = abs($mless->adqty);

$balqty = $add - $les;

echo $balqty;

?>