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

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

$maindb = 'purmain';
$trandb = 'purtran';

$myyear = $_SESSION[$myyear];

$result = mysqli_query($conn, "SELECT vouchno, sum(qty) as tqty FROM `$trandb` WHERE `vouchno`!= '' group by vouchno order by vouchno") or die(mysqli_error($conn));

$getnum = mysqli_num_rows($result);
browse($getnum);

while ($get = mysqli_fetch_array($result)) {

    $vouchno = $get["vouchno"];
    $tqty = $get["tqty"];
    
    mysqli_query($conn, "update `$maindb` set `totqty`='$tqty' where vouchno = '$vouchno' ") or die(mysqli_error($conn));
}
browse("Success");
?>
