<?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];

if (isset($_REQUEST['salevcno'])) {
    $salevcno = $_REQUEST['salevcno'];

    $getm = mysqli_query($conn, "SELECT gstperc,addgst,salesman,party FROM `salemain` WHERE `vouchno`='$salevcno' order by vouchno DESC limit 0,1")or die(mysqli_error($conn));
    $m = mysqli_fetch_array($getm);

    $gsales = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE accode = '$m[salesman]' order by name") or die(mysqli_error($conn));
    $sales = mysqli_fetch_array($gsales);
    $salesname = $sales['name'];
    
    $gparty = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE accode = '$m[party]' order by name") or die(mysqli_error($conn));
    $party = mysqli_fetch_array($gparty);
    $partyname = $party['name'];
    $client = $partyname;

    $gstperc = $m['gstperc'];
    $addgst = $m['addgst'];
    $salesman = $salesname;
    // print_r($addgst);

    $data = array('addgst' => "$addgst", 'gstperc' => "$gstperc", 'salesman' => "$salesman", 'client' => "$client");
    header('Content-Type: application/json');
    echo json_encode($data);
}
?>