<?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'];
    
    $getsales = mysqli_query($conn, "SELECT `salesman` FROM `salemain` WHERE `vouchno`='$salevcno' order by vouchno DESC ")or die(mysqli_error($conn));
    $fetsales = mysqli_fetch_array($getsales);
    $staff = $fetsales['salesman'];
    
    $getsalesman = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`='$staff' ")or die(mysqli_error($conn));
    $fetsalesman = mysqli_fetch_array($getsalesman);
    $salesman = $fetsalesman['name'];

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