<?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;

$itemgrp = $_REQUEST["itemgrp"];

if ($itemgrp != "") {


    $query = "SELECT * FROM `item` WHERE `itemgrp`='$itemgrp' ORDER BY `code`";
    $result = mysqli_query($conn, $query)or die(mysqli_error($conn));
    

    if (mysqli_num_rows($result) > "0") {
        $success = true;
    }

    $rows = array();
    $ctr = 1;
    while ($r = mysqli_fetch_assoc($result)) {
        
        $rows[] = ['success' => $success,
            'ctr' => $ctr,
            'name' => $r[name],
            'unit' => $r[unit],
            'gstperc' => $r[gstperc],
            'hsncode' => $r[hsncode],
            'cost' => $r[cost],
            'rate' => $r[rate]
        ];
        $ctr++;
    }
    header("Content-type: application\json");
    echo json_encode($rows);
}