<?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["prodcode"])) {
    $prodcode = $_REQUEST['prodcode'];

    $cond = "";
    if (!empty($prodcode)) {
        $cond = " AND `prodcode` ='$prodcode' ";
    }

    $query = "SELECT `code`, `prodcode`,`name` ,`hsncode`, `rate` FROM `product` WHERE `code` !='' $cond";

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

    $rows = array();
    $ctr = 0;
    $r = mysqli_fetch_assoc($result);
//    $getunit = mysqli_query($conn,  "SELECT `code`, `name` FROM `unit` WHERE code='$r[unit]'")or die(mysqli_error($conn));
//    $fetunit = mysqli_fetch_array($getunit);

    $rows = array('success' => true,
        'code'      => "$r[code]",
        'prodcode'  => "$r[prodcode]",
        'name'      => "$r[name]",
        'rate'      => "$r[rate]",
        'hsncode' => "$r[hsncode]");
//        'msp'     => "$r[msp]");
    header("Content-type: application\json");
    echo json_encode($rows);
}