<?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 vouchno,gstperc,oms,totcgst as cgstamt, totsgst as sgstamt, totigst as igstamt
                       FROM `$maindb` WHERE `vouchno`!= '' ") or die(mysqli_error($conn));
//print table($result);
$getnum = mysqli_num_rows($result);
browse($getnum);
$cgstamt = 0;
$sgstamt = 0;
$igstamt = 0;
$amount = 0;
$discount = 0;
$subtot = 0;
$total = 0;
while ($get = mysqli_fetch_array($result)) {
    $cgst5    = 0;
    $sgst5    = 0;
    $igst5    = 0;
    $totgst5  = 0;
    $cgst12   = 0;
    $sgst12   = 0;
    $igst12   = 0;
    $totgst12 = 0;
    $cgst18   = 0;
    $sgst18   = 0;
    $igst18   = 0;
    $totgst18 = 0;
    $cgst28   = 0;
    $sgst28   = 0;
    $igst28   = 0;
    $totgst28 = 0;

    $gstperc  = $get["gstperc"];
    $vouchno  = $get["vouchno"];
    $amount   = $get["amount"];
    $cgstamt  = $get["cgstamt"];
    $sgstamt  = $get["sgstamt"];
    $igstamt  = $get["igstamt"];
    $discount = $get["discount"];
    $subtot   = $get["subtot"];
    $totbillamt   = round($get["total"]);
    
    switch ($gstperc) {
        case 1:
            $cgst5   = $cgstamt;
            $sgst5   = $sgstamt;
            $igst5   = $igstamt;
            $totgst5 = $cgst5 + $sgst5 + $igst5;
            break;
        case 2:
            $cgst12   = $cgstamt;
            $sgst12   = $sgstamt;
            $igst12   = $igstamt;
            $totgst12 = $cgst12 + $sgst12 + $igst12;

            break;
        case 3:
            $cgst18   = $cgstamt;
            $sgst18   = $sgstamt;
            $igst18   = $igstamt;
            $totgst18 = $cgst18 + $sgst18 + $igst18;

            break;
        case 4:
            $cgst28   = $cgstamt;
            $sgst28   = $sgstamt;
            $igst28   = $igstamt;
            $totgst28 = $cgst28 + $sgst28 + $igst28;

            break;

    }

//$totbillamt = $subtot + $totgst5 + $totgst12 + $totgst18 + $totgst28;




    mysqli_query($conn, "update `$maindb` set `cgst5`='$cgst5',`sgst5`='$sgst5',`igst5`='$igst5',
                                      `cgst12`='$cgst12',`sgst12`='$sgst12',`igst12`='$igst12',
                                      `cgst18`='$cgst18',`sgst18`='$sgst18',`igst18`='$igst18',
                                      `cgst28`='$cgst28',`sgst28`='$sgst28',`igst28`='$igst28',
                                      `totgst5`='$totgst5', `totgst12`='$totgst12',`totgst18`='$totgst18',`totgst28`='$totgst28'
                                       where vouchno = '$vouchno'") or die(mysqli_error($conn));
    
}
browse("Success");
?>
 