<?php
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ("includes/function.php");

$zdb = $_SESSION["zdbyear_$dbname"];
mysqli_select_db($conn, $zdb);

if ($_REQUEST["invno"]) {
    $invno = $_REQUEST["invno"];
    $vouchno = $_REQUEST["vouchno"];
    $code = $_REQUEST["party"];
    $file = $_REQUEST["file"];

    if ($file == 'purchase_mi.php') {
        $getprate = mysqli_query($conn, "SELECT `invno`,`party`,`voucher` FROM `rawmain` WHERE `invno`= '$invno' and `party` = '$code'")or die(mysqli_error($conn));
    } elseif ($file == 'sale_ti.php') {
        $getprate = mysqli_query($conn, "SELECT `invno`,`voucher` FROM `salemain` WHERE  `vouchno` != '$vouchno' and `invno`= '$invno' ")or die(mysqli_error($conn));
    } elseif ($file == 'invoexp.php') {
        
        $getprate = mysqli_query($conn, "SELECT `invoice`,`voucher` FROM `salemainexp` WHERE  `vouchno` != '$vouchno' and `invoice`= '$invno' ")or die(mysqli_error($conn));
    }

    $row = mysqli_num_rows($getprate);
    if ($row > 0) {
        $fetch = mysqli_fetch_array($getprate);
        $vouchno = $fetch['voucher'];
        $s = 1;
        $data = array('vouchno' => $vouchno, 's' => $s);
        header('Content-Type: application/json');
        echo json_encode($data);
    }
}
?>
