<?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];
$maindb = "challan";
$zroot = $_SESSION['zdbroot'];
$zroot1 = substr($zroot, 0, -4);


$myyear = $_SESSION[$myyear];


$getcomp = mysqli_query($conn, "Select * from $zroot.compyear where finyear != '$myyear' order by lastdate DESC") or die(mysqli_error($conn));
$fetcomp = mysqli_fetch_array($getcomp);
$oldyear = $fetcomp['finyear'];
$olddb = $zroot1 . '1_' . $oldyear;



if ($_REQUEST["vouchdt"]) {

    $vouchno = $_REQUEST["vouchno"];
    $vouchdt = $_REQUEST["vouchdt"];
    $party = $_REQUEST["party"];
    $sizemm = $_REQUEST["sizemm"];
    $guagemm = $_REQUEST["guagemm"];
    $makemm = $_REQUEST["makemm"];
    $nag = $_REQUEST["nag"];
    $foot = $_REQUEST["foot"];

    $partycond = "";
    if ($party != '') {
        $partycond = "and b.`name`='$party'";
    }

    $vouchdtcond = "";
    if ($vouchdt != '') {
        $vouchdtcond = "and a.`vouchdt`!='$vouchdt'";
    }


    $query = "SELECT a.*, DATE_FORMAT(a.`vouchdt`,'%d-%m-%Y') as mydt, DATE_FORMAT(a.`delvdate`,'%d-%m-%Y') as delvdt, b.name  FROM `$maindb` a , accmast b
                         where a.party = b.accode and b.name = '$party' and a.sizemm='$sizemm' 
            and a.nag='$nag' and a.foot ='$foot' and a.vouchdt = '$vouchdt' and a.vouchno !='$vouchno'";
    $result = mysqli_query($conn, $query) or die(mysqli_error($conn));
//    print table($result);
    $data = 0;
    if (mysqli_num_rows($result) > 0) {
        $data = mysqli_num_rows($result);
        echo "$data";
    }
} else {
    echo "ERROR";
}
?>