<?php

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

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

$maindb = 'salemain';
$trandb = 'saletran';
$myyear = $_SESSION[$myyear];




$result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `vouchno`!= ''") or die(mysqli_error($conn));

$getnum = mysqli_num_rows($result);
while ($get = mysqli_fetch_array($result)) {
    $gstperc = $get["gstperc"];
    $oms = $get["oms"];
    $vouchno = $get["vouchno"];

    $getgst = mysqli_query($conn, "select * from saletype where code='$gstperc'");
    $fetgst = mysqli_fetch_array($getgst);

    $per = $fetgst[per];
    $discperc = $fetgst[discperc];

    if ($oms != 'Y') {
        $cgstperc = $per / 2;
    } else {
        $igstperc = $per;
    }

    mysqli_query($conn, "update `$trandb` set `cgstrate`='$cgstperc',`sgstrate`='$cgstperc',`igstrate`='$igstperc',`discperc`='$discperc' where vouchno = '$vouchno'") or die(mysqli_error($conn));
    
}
    browse("Success");

?>
