<?php

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

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

if (isset($_REQUEST['item'])) {
    $item = $_REQUEST['item'];
    $size = $_REQUEST['size'];
    $para = $_REQUEST['para'];
    $vouchno = $_REQUEST['vouchno'];
    $source = $_REQUEST['source'];

    $group = $source . $mvouch;
    $stqty = 0;

    if ($para == 'S') {
        $getm = mysqli_query($conn, "SELECT sum(qty) as tqty FROM `transacn` WHERE `itemcode`='$item' and size = '$size' and `group` != '$group'")or die(mysqli_error($conn));
//    print table($getm);
        if (!empty($getm)) {
            $m = mysqli_fetch_array($getm);
            $stkqty = $m['tqty'];
            if ($stkqty != 0) {
                $stqty = $stkqty;
            } else {
                $stqty = 0;
            }
        } else {
            $stqty = 0;
        }
    }

    $getm = mysqli_query($conn, "SELECT cost, rate FROM `prodsize` WHERE `code`='$item' and size='$size'")or die(mysqli_error($conn));
    $m = mysqli_fetch_array($getm);
    $ctr = 0;
    $mcost = $m['cost'];
    $mrate = $m['rate'];

    $rows = array('cost' => "$mcost",
        'rate' => "$mrate",
        'stkqty' => "$stqty"
    );
    header("Content-type: application\json");
    echo json_encode($rows);
}