<?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 (isset($_REQUEST['stafcode'])) {
    $stafcode = $_REQUEST['stafcode'];

    $getitm = mysqli_query($conn, "SELECT `accode`, `name` FROM `accmast` WHERE `custcode`='$stafcode'  ORDER BY `name`")or die(mysqli_error($conn));
    $itm = mysqli_fetch_array($getitm);

    Echo "<option value='$itm[accode]'>$itm[name]</option>";
    $getitm2 = mysqli_query($conn, "SELECT accode, name FROM `accmast` where grpcode = '040'  ORDER BY `name`")or die(mysqli_error($conn));
    while ($itm2 = mysqli_fetch_array($getitm2)) {
        Echo "<option value='$itm2[accode]'>$itm2[name]</option>";
    }
}

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

    $getitm = mysqli_query($conn, "SELECT `accode`, `custcode`, `name` FROM `accmast` WHERE `accode`='$salesman'  ORDER BY `name`")or die(mysqli_error($conn));
    $itm = mysqli_fetch_array($getitm);
    $stfcode = $itm['custcode'];
    Echo "$stfcode";
}

if (isset($_REQUEST['salesm'])) {
    $salesman = $_REQUEST['salesm'];
//    browse($salesman);
    $stafcode = $_REQUEST['stafco'];
    $salescond = "";
    $staffcond = "";
    if(!empty($salesman)){
        $salescond = "and `accode`='$salesman'";
    }
    if(!empty($stafcode)){
        $staffcond = "and `custcode`='$stafcode'";
    }

    $getitm = mysqli_query($conn, "SELECT `accode`, `custcode`, `name`, percent FROM `accmast` WHERE (custcode = '$stafcode' or accode = '$salesman') ORDER BY `name`")or die(mysqli_error($conn));
    $itm = mysqli_fetch_array($getitm);
    $stfcode = $itm['percent'];
    Echo "$stfcode";
}
?>