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


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

if(isset($_REQUEST['name'])){
   $code   = mysqli_real_escape_string($conn, $_REQUEST["name"]);
   $cutperc = $_REQUEST["cutperc"];
   $result = mysqli_query($conn, "SELECT `barcode`, `cost` , `rate`,`hsncode` FROM `item` WHERE `name`='$code'") or die(mysqli_error($conn));
   $array  = mysqli_fetch_object($result);
   $rate = $array->rate;
   if ($cutperc > 0) {
            $ncutperc = $cutperc;
            $newrate = ($rate * $ncutperc) / 100;
        } else {
            $ncutperc = 0;
            $newrate = $rate;
        }
   
   $fetch = array(
     'barcode'  =>$array->barcode,
     'rate'     => $newrate,
     'hsncode'     =>$array->hsncode,
     'cost'     =>$array->cost
   );
   header("Content-type: application/json");
   echo json_encode($fetch);
}
?>
