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

if (isset($_REQUEST['item'])) {
    $item = $_REQUEST['item'];
    $rate = $_REQUEST['rate'];

    $getm = mysqli_query($conn, "SELECT * FROM `rawmat` WHERE `code`='$item'")or die(mysqli_error($conn));
    $m = mysqli_fetch_array($getm);

    $prodperc = $m['gstperc'];

//    $prodperc = $m['gstperc'];
//    $hsn = $m[hsncode];

    $cgst = $prodperc / 2;
    $sgst = $prodperc / 2;


    switch ($prodperc) {
        case '5' : $discperc = 4.762;
            break;
        case '12' : $discperc = 10.7143;
            break;
        case '18' : $discperc = 15.254;
            break;
        case '28' : $discperc = 21.875;
            break;
    }


    $rows = array('cgst' => "$cgst",
        'sgst'     => "$sgst",
        'igst'     => "$prodperc",
        'discperc' => "$discperc"
    );
    header("Content-type: application\json");
    echo json_encode($rows);
}