<?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["totqty"])){
    $vouchno        = $_REQUEST["vouchno"];
    $srno           = $_REQUEST["srno"];
    $containerno    = $_REQUEST["containerno"] ;
    $totqty         = $_REQUEST["totqty"] * - 1;
    $qty            = $_REQUEST["qty"] * - 1;
    $baleqty        = $_REQUEST["baleqty"] * - 1;
    $mitemcode = $_REQUEST["itemcode"];
    $brand = $_REQUEST["brand"];
    $getbr = mysqli_query($conn, "SELECT code,name FROM `brand` WHERE `name`='$brand'") or die(mysqli_error($conn));
    $bcode = mysqli_fetch_array($getbr);
    $brcode = $bcode['code'];
    $finditem = mysqli_query($conn, "SELECT * FROM `item` WHERE `code`='$mitemcode' and brand='$brcode'") or die(mysqli_error($conn));
    $fitem = mysqli_fetch_array($finditem);
    $mitem = $fitem['barcode'];

    
    mysqli_query($conn, "UPDATE `dumstock` SET `containerno`='$containerno', `totqty`='$totqty', `baleqty`='$baleqty',brand ='$brcode',
             `qty`='$qty', `itemcode`='$mitem' WHERE `vouchno`='$vouchno' AND `srno`='$srno' AND `containerno`='$containerno'");
}