<?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++) {
        $barcode = $chrate[$i]["barcode"];
//        $igstperc = $chrate[$i]["gstperc"];
        $cost = $chrate[$i]["cost"];
        $rate = $chrate[$i]["rate"];
//        $mrp = $chrate[$i]["mrp"];
//        $msp = $chrate[$i]["msp"];
        
//        $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 `product` SET `cost`='$cost' , `rate`='$rate'
                       WHERE `barcode`='$barcode'")or die(mysqli_error($conn));
    }

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