<?php

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

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

$stor = $_SESSION["stor_" . $dbname];


if (isset($_REQUEST['itemcode'])) {
    $itemcode = $_REQUEST['itemcode'];
//    browse($itemcode);
    $prodtype = $_REQUEST['prodtype'];
    $prodcond = '';
    if (!empty($prodtype)) {
        $prodcond = " and `prodtype`='$prodtype'";
    }
//    $series = $_REQUEST['series'];

    if ($stor == 1) {
        $getitm = mysqli_query($conn, "SELECT `code`, `barcode`, `name` FROM `item` WHERE `barcode`='$itemcode' and retail ='1'  ORDER BY `name`")or die(mysqli_error($conn));
    } else {
        $getitm = mysqli_query($conn, "SELECT `code`, `barcode`, `name` FROM `item` WHERE `barcode`='$itemcode'  ORDER BY `name`")or die(mysqli_error($conn));
    }

    $itm = mysqli_fetch_array($getitm);
    $count = mysqli_num_rows($getitm);

    if ($count > 0) {
        Echo "<option value='$itm[code]'>$itm[name]</option>";
//        if ($usertype == 1) {

        $getitm2 = mysqli_query($conn, "SELECT code, name FROM `item` where code != ''  ORDER BY `name`")or die(mysqli_error($conn));
        while ($itm2 = mysqli_fetch_array($getitm2)) {
            Echo "<option value='$itm2[code]'>$itm2[name]</option>";
        }
//        }
    }
}
?>