<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');
$zdb = $_SESSION["zdbyear_$dbname"];
mysqli_select_db($conn, $zdb);
$myyear = $_SESSION[$myyear];
$result = mysqli_query($conn, "SELECT * FROM `billsett` WHERE type= 'S' order by vouchno") or die(mysqli_error($conn));
//print table($result);
$getnum = mysqli_num_rows($result);
while ($get = mysqli_fetch_array($result)) {
    $source = $get['source'];
    $billsrc = $get['billsrc'];
    $vouchno = $get['vouchno'];
    $bnkvouch = $get['bnkvouch'];
    $party = $get['party'];

    $mown = mysqli_query($conn, "SELECT * FROM `rawmain` where vouchno ='$vouchno' and party='$party'") or die(mysqli_error($conn));
    if (mysqli_num_rows($mown) > 0) {
        $town = mysqli_fetch_array($mown);
        $vouchdt = $town["vouchdt"];
    } else {
        $mown = mysqli_query($conn, "SELECT * FROM `gstmain` where vouchno ='$vouchno' and party='$party'") or die(mysqli_error($conn));
        if (mysqli_num_rows($mown) > 0) {
            $town = mysqli_fetch_array($mown);
            $vouchdt = $town["vouchdt"];
        } else {
            $mown = mysqli_query($conn, "SELECT * FROM `prevbill` where vouchno ='$vouchno' and accode='$party'") or die(mysqli_error($conn));
            if (mysqli_num_rows($mown) > 0) {
                $town = mysqli_fetch_array($mown);
                $vouchdt = $town["billdate"];
            }
        }
    }
//    print "Update `billsett` set `billdate`='$vouchdt' WHERE `vouchno`='$vouchno' and bnkvouch='$bnkvouch' and party='$party'<br>";
    mysqli_query($conn, "Update `billsett` set `billdate`='$vouchdt' WHERE `vouchno`='$vouchno' and bnkvouch='$bnkvouch' and party='$party'") or die(mysqli_error($conn));
}
browse("Success");
?>