<?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['itemcode'])) {
    $itemcode = $_REQUEST['itemcode'];
    $flag = $_REQUEST['flag'];
    $disp = $_REQUEST['disp'];

    $getitm = mysqli_query($conn, "SELECT * FROM `item` WHERE `code`='$itemcode'")or die(mysqli_error($conn));
    $itm = mysqli_fetch_array($getitm);
    $count = mysqli_num_rows($getitm);


    if ($disp != 'D') {
        $dispunit = $itm["stkunit"];
    } else {
        if ($flag == 'O') {
            $dispunit = $itm["unitoutwd"];
        } else {
            $dispunit = $itm["unitinwd"];
        }
    }

    if ($count > 0) {
        if ($disp != 'S') {
            Echo "<option value='$dispunit'>$dispunit</option>";



            $getitm2 = mysqli_query($conn, "SELECT unit FROM `itemunit` where code='$itemcode' ORDER BY `unit`")or die(mysqli_error($conn));
            while ($itm2 = mysqli_fetch_array($getitm2)) {
                Echo "<option value='$itm2[unit]'>$itm2[unit]</option>";
            }
        } else {
            echo "$dispunit";
        }
    }
}
?>