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

$zdb = $_SESSION["zdbyear_$dbname"];
mysqli_select_db($conn, $zdb);
if ($_REQUEST["item"]){
    $item    = $_REQUEST["item"];
    $packing = $_REQUEST["location"];
    $vouchdt = $_REQUEST["vouchdt"];
    
    $getiname = mysqli_query($conn, "SELECT * FROM `item` WHERE `name` = '$item' ")or die(mysqli_error($conn));
    $itemcode = mysqli_fetch_object($getiname);
//    $mopen1    = $itemcode->openqty;
    
    $getvess = mysqli_query($conn, "SELECT SUM(qty) AS tqty FROM `transacn` WHERE itemcode = '$itemcode->code'
                            AND `location`='$packing' AND `vouchdt` < $vouchdt GROUP BY location order by location")or die(mysqli_error($conn));
    $mves = mysqli_fetch_object($getvess);
    $mopen2    = $mves->tqty;
//    $mopen = $mopen1 + $mopen2;
    $mopen = $mopen2;
    echo $mopen;
    
}
?> 