<?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];
$success = false;


if ($_REQUEST['para'] == "P") {

    $vouchno = $_REQUEST['vouchno'];
    $invno = $_REQUEST['invno'];
    $vouchdt = $_REQUEST['vouchdt'];
    $party = $_REQUEST['party'];
    
    $query = mysqli_query($conn, "SELECT  `party`,`vouchdt`,`vouchno`,`invno` FROM `salemain` WHERE `party`='$party' and `vouchdt`='$vouchdt' and vouchno!='$vouchno' AND `invno`='$invno'") or die(mysqli_error($conn));
    $fetnum = mysqli_num_rows($query);
    if ($fetnum > 0) {
        $fetdat = mysqli_fetch_array($query);
        echo "Sale Already Exist for this Party and Date on Voucher No." . $fetdat['vouchno'];
    }
}
if ($_REQUEST['para'] == "I") {
    $invno = $_REQUEST['invno'];
    $vouchno = $_REQUEST['vouchno'];

    $query = mysqli_query($conn, "SELECT  `invno`,vouchno FROM `salemain` WHERE invno='$invno'  and vouchno != '$vouchno'") or die(mysqli_error($conn));
    $fetnum = mysqli_num_rows($query);
    if ($fetnum > 0) {
        $fetdat = mysqli_fetch_array($query);
        echo "Invoice No.". $fetdat['invno'] . " Already Used On Voucher No." . $fetdat['vouchno'];
    }
}
?>