<?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];
$success = false;


//if (isset($_REQUEST["itemname"])) {
    $brand = $_REQUEST['brand'];
    $itemgrp = $_REQUEST['itemgrp'];
    

    $compcond = "";
//    $igrpcond = "";
    if (!empty($brand)) {
        $compcond = " AND `brand` ='$brand' ";
    }
    if (!empty($itemgrp)) {
        $igrpcond = " AND `itemgrp` ='$itemgrp' ";
    }

    $query = "SELECT * FROM `item` WHERE code !='' $compcond  $igrpcond
              and  cost > 0 GROUP BY `brand` ";

    $result = mysqli_query($conn, $query) or die(mysqli_error($conn));

    $rows = array();
    $ctr = 0;
    $r = mysqli_fetch_assoc($result);
    $rows = array('success' => true,
        'vatperc'    => "$r[vatperc]",
//        'cstperc'    => "$r[cstperc]",
//        'cessperc'   => "$r[cessperc]",
//        'exciseperc' => "$r[exciseperc]",
//        'bell'       => "$r[bell]",
//        'lock'       => "$r[lock]",
//        'fitting'    => "$r[fitting]",
        'miscperc'   => "$r[miscperc]");
//        'sellalc'    => "$r[sellalc]",
//        'mrpalc'     => "$r[mrpalc]");
    header("Content-type: application\json");
    echo json_encode($rows);
//}