<?php

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

$maindb = 'salemain';
$trandb = 'saletran';

$accdb = 'actran';
$stkdb = 'transacn';

$trandbexist = 1;
$source = "SL  ";

$keyfld = "vouchno";
$myyear = $_SESSION["tit_" . $dbname];

date_default_timezone_set('Asia/Kolkata');
$time = date('H:i:s');

$usertype = $_SESSION["usertype"];
$username = $_SESSION["username_" . $dbname];

//browse($username);
$formname = 'Sale';

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];

mysqli_select_db($conn, $zdb);

//browse($zdb);

$getmain = mysqli_query($conn, "Select vouchno, sum(qty) as totqty from `$trandb` group by vouchno order by vouchno") or die(mysqli_error($conn));
//print table($getmain);
while ($fetmain = mysqli_fetch_array($getmain)) {
    $vouchno = $fetmain["vouchno"];
    $totqty = $fetmain["totqty"];
    
//    if ($vouchno > 1 && $vouchno < 5) {
//        browse("a");
//    }
    
    mysqli_query($conn, "update `$maindb` set totalqty = '$totqty' where vouchno = '$vouchno' ") or die(mysqli_error($conn));
}
echo "Success";
