<?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='R' order by vouchno") or die(mysqli_error($conn));
$result = mysqli_query($conn, "SELECT * FROM `credmain` order by vouchno") or die(mysqli_error($conn));
//print table($result);
$getnum = mysqli_num_rows($result);
while ($get = mysqli_fetch_array($result)) {
    $billsrc = $get['billsrc'];
    $vouchno = $get['vouchno'];
    $bnkvouch = $get['vouchno'];
    $party = $get['party'];
    $source = $get['source'];
    $vouchdt = $get['vouchdt'];

//    if ($source == "CR") {
//        $mown = mysqli_query($conn, "SELECT * FROM `cashrecp` 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 `credmain` where vouchno ='$vouchno' and accode='$party'") or die(mysqli_error($conn));
//        if (mysqli_num_rows($mown) > 0) {
//            $town = mysqli_fetch_array($mown);
//            $vouchdt = $town["vouchdt"];
//        }
//    }

//    print "Update `billsett` set `billdate`='$vouchdt' WHERE `vouchno`='$vouchno' and bnkvouch='$bnkvouch' and party='$party'<br>";
    mysqli_query($conn, "Update `billsett` set `bnkdate`='$vouchdt' WHERE bnkvouch='$bnkvouch' and source='SR'") or die(mysqli_error($conn));
}
$resultc = mysqli_query($conn, "SELECT * FROM `cashrecp` order by vouchno") or die(mysqli_error($conn));
//print table($result);
$getnumc = mysqli_num_rows($resultc);
while ($getc = mysqli_fetch_array($resultc)) {
    $billsrc = $getc['billsrc'];
    $vouchno = $getc['vouchno'];
    $bnkvouch = $getc['vouchno'];
    $party = $getc['party'];
    $source = $getc['source'];
    $vouchdt = $getc['vouchdt'];

//    if ($source == "CR") {
//        $mown = mysqli_query($conn, "SELECT * FROM `cashrecp` 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 `credmain` where vouchno ='$vouchno' and accode='$party'") or die(mysqli_error($conn));
//        if (mysqli_num_rows($mown) > 0) {
//            $town = mysqli_fetch_array($mown);
//            $vouchdt = $town["vouchdt"];
//        }
//    }

//    print "Update `billsett` set `billdate`='$vouchdt' WHERE `vouchno`='$vouchno' and bnkvouch='$bnkvouch' and party='$party'<br>";
    mysqli_query($conn, "Update `billsett` set `bnkdate`='$vouchdt' WHERE bnkvouch='$bnkvouch' and source='CR'") or die(mysqli_error($conn));
}
//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 `salemain` 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");
?>