<?php

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

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

$chrate = $_REQUEST[chrate];
$ctr = $_REQUEST[count];

if (isset($chrate) != "") {
    for ($i = 0; $i < $ctr; $i++) {
        $name = $chrate[$i]["name"];
        $igstperc = $chrate[$i]["gstperc"];
        $hsncode = $chrate[$i]["hsncode"];
        $unit = $chrate[$i]["unit"];
        $cost = $chrate[$i]["cost"];
        $rate = $chrate[$i]["rate"];
        
        $getperc = mysqli_query($conn, "SELECT `per`, `code` FROM `gsttype` WHERE per='$igstperc'") or die(mysqli_error($conn));
        $fgstperc = mysqli_fetch_array($getperc);
        $gstperc = $fgstperc[code];
        
        mysqli_query($conn, "UPDATE `item` SET `gstperc`= '$gstperc', `cost`='$cost' , `rate`='$rate' WHERE `name`='$name'")or die(mysqli_error($conn));
    }

    $success = true;
    $show = ["success" => $success];
    header("Content-type: application\json");
    echo json_encode($show);
}
    