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

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

//    $hsn = $m[hsncode];
    $prodperc = $m['gstperc'];
    
    $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);
}