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

$maindb = 'purexpmain';
$trandb = 'purexptran';

$accdb = 'actran';
$imgdb = "";
$file = 'purchase_exp.php';
$trandbexist = 1;
$comp = $_SESSION["comp_" . $dbname];
$myyear = $_SESSION[$myyear];

$source = 'PUEX';
$formname = 'Purchase - Expense';
$salelock = $_SESSION["salelock"];
$usertype = $_SESSION["usertype"];
$username = $_SESSION["username_" . $dbname];
$keycond = "";
//$fseries = $_SESSION["series_" . $dbname];
$myyear = $_SESSION["tit_" . $dbname];
$keyfld = "vouchno";
$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$zyear = right($zdb, 4);
$zStartDate = getzdates($zyear, 'S');
$zEndDate = getzdates($zyear, 'E');
mysqli_select_db($conn, $zdb);

date_default_timezone_set('Asia/Kolkata');
$adduser = $_SESSION['username_' . $dbname];
$adddate = date("Y-m-d");
$addtime = date("h:i:sa");
include("includes/vouchno_generate.php");
include("includes/prev&next.php");

if (isset($_POST["submit"])) {

    $a = 1;

    $vouchdt = $_POST["vouchdt"];
    $qvouch = $_POST["vouchno"];

    $voucher = trim($_POST["voucher"]);
    $mono = $_POST["monno"];
    $invno = $_POST["invno"];

    //    $debitac = $_POST["debitac"];

    $paidby = trim($_POST["paidby"]);
    $party = trim($_POST["party"]);
    $taxableamt = trim($_POST["taxableamt"]);
    $totbillamt = trim($_POST["totbillamt"]);
    $grossamt = trim($_POST["grossamt"]);
    $gstno = trim($_POST["gstno"]);
    $totdiscamt = trim($_POST["totdiscamt"]);
    $type = trim($_POST["type"]);

    $rem1 = trim($_POST["remark1"]);
    $rem2 = trim($_POST["remark2"]);

    $cgst3 = $_POST['cgst3'];
    $sgst3 = $_POST['sgst3'];
    $igst3 = $_POST['igst3'];

    $cgst5 = $_POST['cgst5'];
    $sgst5 = $_POST['sgst5'];
    $igst5 = $_POST['igst5'];

    $cgst12 = $_POST['cgst12'];
    $sgst12 = $_POST['sgst12'];
    $igst12 = $_POST['igst12'];

    $cgst18 = $_POST['cgst18'];
    $sgst18 = $_POST['sgst18'];
    $igst18 = $_POST['igst18'];

    $cgst28 = $_POST['cgst28'];
    $sgst28 = $_POST['sgst28'];
    $igst28 = $_POST['igst28'];

    $totgst3 = $_POST['totgst3'];
    $totgst5 = $_POST['totgst5'];
    $totgst12 = $_POST['totgst12'];
    $totgst18 = $_POST['totgst18'];
    $totgst28 = $_POST['totgst28'];

    $roundoff = $_POST['roundoff'];
    $reverse = $_POST['reverse'];
    $godown = $_POST['godown'];

    $tottaxble0 = $_POST['tottaxble0'];
    $tottaxble3 = $_POST['tottaxble3'];
    $tottaxble5 = $_POST['tottaxble5'];
    $tottaxble12 = $_POST['tottaxble12'];
    $tottaxble18 = $_POST['tottaxble18'];
    $tottaxble28 = $_POST['tottaxble28'];

    //////////TCS ////////////    
    $pretottcs = $_POST["pretottcs"];
    $tcsperc = $_POST["tcsperc"];
    $tcsamt = $_POST["tcsamt"];
    $unclaimgst = $_POST["unclaimgst"];
    //////////////////////////

    $mvouch = $qvouch;

    $oms = $_POST['oms'];

    $count = $_POST["items"];

    if ($totbillamt <= 0) {
        browse("Bill Amount Cannot Be Zero");
        $a = 0;
    }

    if (empty($party)) {
        $a = 0;
        browse("Party Cannot Be Empty");
    }

    if ($paidby == "C") {
        $purcode = 11;
    } else {
        $purcode = 12;
    }

    if ($a == 1) {

        mysqli_query($conn, "LOCK TABLES `$maindb` WRITE, `$trandb` WRITE, `$accdb` WRITE, `cashpay` WRITE, `accmast` WRITE");

        if ($addflag == 1) {
            $gen1 = mysqli_query($conn, "SELECT MAX(vouchno) AS maxcode FROM `$maindb` where vouchno != '' LIMIT 0,1 ") or die(mysqli_error($conn));
            if (mysqli_num_rows($gen1) > 0) {
                $vvouch = mysqli_fetch_assoc($gen1);
                $qvouch = $vvouch["maxcode"] + 1;
            } else {
                $qvouch = '1';
            }
            $mvouch = $qvouch;
        }

        $qrygrp = mysqli_query($conn, "select `grpcode` from accmast where `accode` = '$party'") or die(mysqli_error($conn));
        $fetgrp = mysqli_fetch_array($qrygrp);
        $pgrp = $fetgrp['grpcode'];

        //**************************************************        auto cash Entry Start  ***************************************

        $mcashvouch = $_POST["cashvouch"];

        if ($cashcred == 'C') {
            if ($mcashvouch == '0' || $mcashvouch == '') {
                $gen1 = mysqli_query($conn, "SELECT MAX(vouchno) AS maxcode FROM `cashpay` where vouchno!=''   LIMIT 0,1 ") or die(mysqli_error($conn));
                if (mysqli_num_rows($gen1) > 0) {
                    $vvouch = mysqli_fetch_assoc($gen1);
                    $tcashvouch = $vvouch["maxcode"] + 1;
                } else {
                    $tcashvouch = '1';
                }
                $mcashvouch = $tcashvouch;
            }


            $genrecp = mysqli_query($conn, "SELECT * FROM `cashpay` where `vouchno` = '$mcashvouch' ") or die(mysqli_error($conn));
            if (mysqli_num_rows($genrecp) > 0) {
                $fetrecp = mysqli_fetch_array($genrecp);
                $mrecpno = $fetrecp['recpno'];
                $mcashvouch = $fetrecp['vouchno'];
            } else {

                $gen2 = mysqli_query($conn, "SELECT MAX(recpno) AS maxcode FROM `cashpay` where bankcode = '3'   LIMIT 0,1 ") or die(mysqli_error($conn));
                if (mysqli_num_rows($gen2) > 0) {
                    $gvouch = mysqli_fetch_assoc($gen2);
                    $mrecpno1 = $gvouch["maxcode"] + 1;
                } else {
                    $mrecpno1 = '1';
                }
                $mrecpno = $mrecpno1;
            }

            mysqli_query($conn, "DELETE FROM `cashpay` WHERE `$keyfld`='$mcashvouch' ") or die(mysqli_error($conn));


            mysqli_query($conn, "INSERT INTO `cashpay`( vouchno , `vouchdt`, `bankcode`, `bankinit`, `recpno`, `accode`,`amount`,`narr1`,`narr2`,`trnflag`)
                                       Values ('$mcashvouch', '$vouchdt', '3', 'COH', '$mrecpno','$party','$totbillamt','Cash Paid For','Purchase No.$mvouch','S')") or die(mysqli_error($conn));

            // cash part  
            $minus_amt = ($totbillamt * -1);

            mysqli_query($conn, "DELETE FROM `$accdb` WHERE `$keyfld`='$mcashvouch' and `source` = 'CP' ") or die(mysqli_error($conn));

            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, recpno, trnno, bankinit, accode,  grpcode, amount)
                    VALUES ('$vouchdt', '$mcashvouch', 'CP', '$mrecpno', '001', 'COH', '3', '002', '$totbillamt', '$mono')");

            // party part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, recpno, trnno, bankinit, accode, grpcode, amount)
                     VALUES ('$vouchdt', '$mcashvouch', 'CP', '$mrecpno', '002', 'COH', '$party',  '$pgrp', '$minus_amt', '$mono')");
        } else {
            mysqli_query($conn, "DELETE FROM `cashpay` WHERE `$keyfld`='$mcashvouch' ") or die(mysqli_error($conn));
            mysqli_query($conn, "DELETE FROM `actran` WHERE `$keyfld`='$mcashvouch' AND `source`='CP' ") or die(mysqli_error($conn));
            $mcashvouch = "";
        }


        //**************************************************        auto cash Entry End    ***************************************
        //        
        //        $nettotal = round($total - $discount + $vat + $packing);
        if ($addflag == 1) {
            $newvoucher = $mono . $mvouch;

            mysqli_query($conn, "INSERT INTO `$maindb`(vouchno, `vouchdt`, `voucher`, `invno`, `mono`, `party`, `oms`, `paidby`, `debitac`, 
                                               `rem1`, `rem2`,  `cashvouch`, `gstno`, `discamt`,`grossamt`, `godown`,`adduser`, `adddate`, `addtime`,
                                               `taxableamt`,`cgst3`,`sgst3`,`igst3`,`cgst5`,`sgst5`,`igst5`,`cgst12`,`sgst12`,`igst12`,`cgst18`,`sgst18`,`igst18`,`cgst28`,
                                               `sgst28`,`igst28`, `totgst3`,`totgst5`,`totgst12`,`totgst18`,`totgst28`, `purcode`,`billamt`,`mattype`,`roundoff`,
                                               `tottaxble0`, `tottaxble3`, `tottaxble5`, `tottaxble12`, `tottaxble18`, `tottaxble28`, `pretottcs`, `tcsperc`, `tcsamt`, `unclaimgst`)
                                      VALUES('$mvouch', '$vouchdt', '$newvoucher', '$invno', '$mono', '$party', '$oms', '$paidby', '$debitac',
                                             '$rem1', '$rem2', '$mcashvouch', '$gstno', '$totdiscamt','$grossamt', '$godown','$adduser', '$adddate', '$addtime',
                                             '$taxableamt','$cgst3','$sgst3','$igst3', '$cgst5','$sgst5','$igst5', '$cgst12','$sgst12','$igst12',
                                             '$cgst18', '$sgst18','$igst18','$cgst28', '$sgst28','$igst28','$totgst3','$totgst5','$totgst12',
                                             '$totgst18', '$totgst28', '$debitac','$totbillamt', '$type','$roundoff',
                                             '$tottaxble0','$tottaxble3' ,'$tottaxble5','$tottaxble12','$tottaxble18','$tottaxble28', '$pretottcs', '$tcsperc', '$tcsamt', '$unclaimgst')") or die(mysqli_error($conn));
        } else {
            $editdate = date("Y-m-d");
            $edittime = date("h:i:sa");
            mysqli_query($conn, "UPDATE `$maindb` SET  `vouchdt`='$vouchdt',  `invno`='$invno', `mono`='$mono',`edituser`='$adduser',`edittime`='$edittime',`editdate`='$editdate' , 
                                               `party`='$party', `paidby`='$paidby', `gstno`='$gstno', `cashvouch`='$mcashvouch',
                                               `rem1`='$rem1', `rem2`='$rem2', `discamt`='$totdiscamt',`grossamt`='$grossamt',`debitac`='$debitac',`purcode`='$debitac',
                                               `godown`='$godown', `taxableamt`='$taxableamt',`cgst3`='$cgst3',`sgst3`='$sgst3',`igst3`='$igst3',
                                                `cgst5`='$cgst5',`sgst5`='$sgst5', `igst5`='$igst5',`cgst12`='$cgst12',`sgst12`='$sgst12',`igst12`='$igst12',
                                                `cgst18`='$cgst18', `sgst18`='$sgst18',`igst18`='$igst18', `cgst28`='$cgst28', `sgst28`='$sgst28',`igst28`='$igst28',`totgst3`='$totgst3',
                                                `totgst5`='$totgst5',`totgst12`='$totgst12', `totgst18`='$totgst18',`totgst28`='$totgst28',`billamt`='$totbillamt',
                                                `roundoff`='$roundoff', `mattype` = '$type',tottaxble0='$tottaxble0', 
                                                `tottaxble3`='$tottaxble3',`tottaxble5`='$tottaxble5',`tottaxble12`='$tottaxble12',
                                                `tottaxble18`='$tottaxble18',`tottaxble28`='$tottaxble28',pretottcs='$pretottcs', tcsperc='$tcsperc', tcsamt='$tcsamt', `unclaimgst`='$unclaimgst'
                                                 WHERE `vouchno` = '$mvouch' ") or die(mysqli_error($conn));
        }

        // $cgst5code = 36;
        // $sgst5code = 37;
        // $igst5code = 38;

        // $cgst12code = 39;
        // $sgst12code = 40;
        // $igst12code = 41;

        // $cgst18code = 42;
        // $sgst18code = 43;
        // $igst18code = 44;

        // $cgst28code = 45;
        // $sgst28code = 46;
        // $igst28code = 47;

        if ($unclaimgst != 1) {
            $cgst5code = 36;
            $sgst5code = 37;
            $igst5code = 38;

            $cgst12code = 39;
            $sgst12code = 40;
            $igst12code = 41;

            $cgst18code = 42;
            $sgst18code = 43;
            $igst18code = 44;

            $cgst28code = 45;
            $sgst28code = 46;
            $igst28code = 47;
        } else {
            $cgst5code = 26;
            $sgst5code = 27;
            $igst5code = 28;

            $cgst12code = 29;
            $sgst12code = 30;
            $igst12code = 31;

            $cgst18code = 32;
            $sgst18code = 33;
            $igst18code = 34;

            $cgst28code = 48;
            $sgst28code = 49;
            $igst28code = 50;
        }


        mysqli_query($conn, "DELETE FROM `$trandb` WHERE vouchno='$mvouch' ") or die(mysqli_error($conn));
        mysqli_query($conn, "DELETE FROM `$accdb` WHERE `vouchno` = '$mvouch' AND `source` = '$source'") or die(mysqli_error($conn));

        $cnt = 0;
        $cntamt = 0;
        $trno = 1;

        for ($i = 0; $i < $count; $i++) {
            $msrno = $_POST["srno_$i"];
            $mitem = mysqli_real_escape_string($conn, $_POST["itemname_$i"]);
            $unit = $_POST["unit_$i"];
            $qty = $_POST["qty_$i"];
            $rate = $_POST["rate_$i"];
            $amt = $_POST["amount_$i"];
            $discperc = $_POST["discperc_$i"];
            $discamt = $_POST["discamt_$i"];
            $cgstrate = $_POST["cgstrate_$i"];
            $cgstamt = $_POST["cgstamt_$i"];
            $sgstrate = $_POST["sgstrate_$i"];
            $sgstamt = $_POST["sgstamt_$i"];
            $igstrate = $_POST["igstrate_$i"];
            $igstamt = $_POST["igstamt_$i"];
            $total = $_POST["total_$i"];
            $hsncode = $_POST["hsncode_$i"];
            $subtot = $_POST["subtot_$i"];
            $expense = $_POST["expense_$i"];

            $gstperc = $cgstrate + $sgstrate + $igstrate;

            $cnt++;
            $group = $source . $mvouch;
            if (!empty($expense)) {
                mysqli_query($conn, "INSERT INTO `$trandb`(vouchno, expense, vouchdt, srno, itemcode, itemname, unit, qty, rate, amount, `discperc`, `discamt`, `cgstrate`,
                                                  `cgstamt`, `sgstrate`, `sgstamt`, `igstrate`, `igstamt`, `total`,`hsncode`,`subtot`,`gstperc`, `rptype`)
                                                  VALUES('$mvouch', '$expense', '$vouchdt', '$cnt', '$itcode', '$mitem', '$unit', '$qty', '$rate', '$amt',
                                   '$discperc', '$discamt', '$cgstrate', '$cgstamt', '$sgstrate', '$sgstamt', '$igstrate', '$igstamt', '$total','$hsncode','$subtot','$gstperc', '$type' )") or die(mysqli_error($conn));

                $samtmin = $subtot * -1;
                // purchase part
                $trno++;
                if ($trno < 9) {
                    $trno1 = '00' . $trno;
                } else {
                    $trno1 = '0' . $trno;
                }

                $qrygrp2 = mysqli_query($conn, "select `grpcode` from accmast where `accode` = '$expense'") or die(mysqli_error($conn));
                $fetgrp2 = mysqli_fetch_array($qrygrp2);
                $pgrp2 = $fetgrp2['grpcode'];

                mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount)
                        VALUES ('$vouchdt','$mvouch', '$source', '$trno1', '$expense','$pgrp2', '$samtmin')") or die(mysqli_error($conn));
            }
        }

        ############################### Accounts Part ####################################################

        $gstamt = $totgst3 + $totgst5 + $totgst12 + $totgst18 + $totgst28;

        $totbillamt1 = $pretottcs + $tcsamt;

        if ($totbillamt > 0) {
            $samtmin = $taxableamt * -1;
            $gstmin = $gstamt * -1;

            if ($totbillamt != $totbillamt1) {
                $roff = round($totbillamt - $totbillamt1, 2) * -1;
            } else {
                $roff = $roundoff * -1;
                //               browse($roff);
            }

            $trno++;
            if ($trno < 9) {
                $trno1 = '00' . $trno;
            } else {
                $trno1 = '0' . $trno;
            }

            // purchase part
            //            mysqli_query($conn, "INSERT INTO `$accdb`(godown, date, vouchno, source, trnno, accode, grpcode, amount,monno)
            //                    VALUES ('$godown','$vouchdt','$mvouch', '$source', '001', '$debitac','004', '$samtmin','$mono')");
            // party part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount)
                     VALUES ('$vouchdt','$mvouch', '$source', '001', '$party','$pgrp', '$totbillamt')") or die(mysqli_error($conn));
            // round off part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount)
                     VALUES ('$vouchdt','$mvouch', '$source', '$trno1', '25','012', '$roff')") or die(mysqli_error($conn));


            // GST part
//            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount)
//                     VALUES ('$vouchdt','$mvouch', '$source', '$trno1', '36','020', '$gstmin')") or die(mysqli_error($conn));

            $cgst5min = ($cgst5 * -1);
            $igst5min = ($igst5 * -1);

            $cgst12min = ($cgst12 * -1);
            $igst12min = ($igst12 * -1);

            $cgst18min = ($cgst18 * -1);
            $igst18min = ($igst18 * -1);

            $cgst28min = ($cgst28 * -1);
            $igst28min = ($igst28 * -1);

            
            if ($oms != 1) {
                if ($totgst5 > 0) {
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$cgst5code','020', '$cgst5min')") or die(mysqli_error($conn));
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$sgst5code','020', '$cgst5min')") or die(mysqli_error($conn));
                }
                if ($totgst12 > 0) {
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$cgst12code','020', '$cgst12min')") or die(mysqli_error($conn));
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$sgst12code','020', '$cgst12min')") or die(mysqli_error($conn));
                }
                if ($totgst18 > 0) {

                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$cgst18code','020', '$cgst18min')") or die(mysqli_error($conn));
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$sgst18code','020', '$cgst18min')") or die(mysqli_error($conn));
                }
                if ($totgst28 > 0) {
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$cgst28code','020', '$cgst28min')") or die(mysqli_error($conn));
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$sgst28code','020', '$cgst28min')") or die(mysqli_error($conn));
                }
            } else {
                if ($totgst5 > 0) {
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$igst5code','020', '$igst5min')") or die(mysqli_error($conn));
                }
                if ($totgst12 > 0) {
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$igst12code','020', '$igst12min')") or die(mysqli_error($conn));
                }
                if ($totgst18 > 0) {
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$igst18code','020', '$igst18min')") or die(mysqli_error($conn));
                }
                if ($totgst28 > 0) {
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$igst28code','020', '$igst28min')") or die(mysqli_error($conn));
                }
            }
        }

        if ($addflag == 1) {
            insmess();
            header("refresh: 1; $file?mode=edit&$keyfld=$mvouch&type=$type");
        } else {
            updmess();
            header("refresh: 1; $file?mode=edit&$keyfld=$mvouch&type=$type");
        }
        mysqli_query($conn, "UNLOCK TABLES");
    }
}
if ($addflag != 1) {

    $getvouch = '';
    if ($addflag == 0) {
        $getvouch = $_GET[$keyfld];
    } else {
        $getvouch = $qvouch;
    }

    $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE $keyfld='$getvouch' ") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);

    $getparty = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`= '$get[party]'") or die(mysqli_error($conn));
    $lparty = mysqli_fetch_array($getparty);

    //    $getdebac = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`= '$get[debitac]' and grpcode='004'") or die(mysqli_error($conn));
    //    $ldebitac = mysqli_fetch_array($getdebac);
    //
    //    $getgodown = mysqli_query($conn, "SELECT * FROM `godown` WHERE `code`= '$get[godown]'") or die(mysqli_error($conn));
    //    $getgd = mysqli_fetch_array($getgodown);

    $delcsh = $get['cashvouch'];

    $printdisabled = "none";
}


$senable = "";
$cenable = "";

if (isset($_GET["delete"])) {
    mysqli_query($conn, "LOCK TABLES `$maindb` WRITE, `$trandb` WRITE, `$accdb` WRITE, `cashpay` WRITE") or die(mysqli_error($conn));

    $delcond = " source = '$source' and vouchno = '$_GET[vouchno]' ";
    $delcond1 = " source = 'CP' and vouchno = '$delcsh' ";
    $delcond3 = " vouchno = '$delcsh'  ";
    $delcond2 = " vouchno = '$_GET[vouchno]' ";

    delnew($zdb, "$maindb", "$delcond2", "$file?mode=last$para");
    delnew($zdb, "$trandb", "$delcond2", "$file?mode=last$para");

    delnew($zdb, "$accdb", "$delcond", "$file?mode=last$para");
    delnew($zdb, "$accdb", "$delcond1", "$file?mode=last$para");

    delnew($zdb, "cashpay", "$delcond3", "$file?mode=last$para");
    mysqli_query($conn, "UNLOCK TABLES");
}

include("includes/linkshead.php");
?>

<script src="MyScript/purchase_exp.js?a=<?= mt_rand(); ?>" type="text/javascript"></script>
<script src="MyScript/purchase_exp_search.js?b=<?= mt_rand(); ?>" type="text/javascript"></script>
<script src="MyScript/checkdate.js" type="text/javascript"></script>

</head>

<body>
    <form action='' method='POST'>
        <div class="col-lg-3 pad text-center" id="overlay_form" style="display:none;z-index:999;">
            <button type="button" id="close_form" style="float: text-right;font-weight: bold;font-size: 18px;color:red;"><i class="fa fa-close"></i></button>
            <div style='width:100%;' id='browdata'>
            </div>
        </div>
        <!-- Default box -->
        <div>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12  pad">
                <div class="panel panel-default">
                    <div class="panel-heading" style="height:60px">
                        <div class="col-lg-6 col-md-10 col-sm-10  col-xs-10">
                            <h3 class="panel-title" style="color:#78909C"><a class="myPrint"><?php echo $formname; ?></a></h3>
                        </div>
                        <div class="col-lg-6 col-md-2 col-sm-2 text-right col-xs-2">
                            <input type="date" value="<?= $zStartDate ?>" style="width: 1px;border: none" class="zstdate">
                            <input type="date" value="<?= $zEndDate ?>" style="width: 1px;border: none" class="zenddate">
                            <input type="date" value="<?= $salelock ?>" style="width: 1px;border: none" class="salelock">
                        </div>
                    </div>
                </div>
                <div class="panel-body" style="padding: 1px;">
                    <div class="row">
                        <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                            <label class="label-control marg">Date</label>
                        </div>
                        <div class="col-lg-2 col-md-8 col-sm-8 col-xs-8 pad">
                            <input type="date" class="form-control form vouchdt focusfield" name="vouchdt" value="<?php echo ($addflag != 1) ? $get["vouchdt"] : date("Y-m-d") ?>" autofocus>
                            <input type="hidden" value="<?= $zStartDate ?>" style="display: none;border: none" class="zstdate">
                            <input type="hidden" value="<?= $zEndDate ?>" style="display: none;border: none" class="zenddate">
                            <input type="hidden" value="<?= $salelock ?>" style="width: 1px;border: none" class="salelock">

                        </div>
                        <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                            <label class="label-control marg">Voucher</label>
                        </div>
                        <div class="col-lg-1 col-md-8 col-sm-8 col-xs-8 pad">
                            <input type="text" name="vouchno" class="form-control form vouchno" value="<?php echo ($addflag != 1) ? $get['vouchno'] : $qvouch ?>">
                            <input type="hidden" class="form-control addflag" value="<?php echo $addflag ?>">
                            <input type="hidden" name="voucher" class="form-control form voucher" value="<?php echo ($addflag != 1) ? $get['voucher'] : '' ?>" tabindex="-1" readonly>
                            <input type="hidden" name="source" class="form-control form source" value="<?= $source; ?>" id="source">
                            <input type="hidden" name="monno" class="form-control form monno" value="<?php echo ($addflag != 1) ? $get['monno'] : '' ?>">
                            <input type="hidden" name="type" class="form-control form type gtype" value="<?php echo ($addflag != 1) ? $get['mattype'] : $gtype ?>">
                            <input type="hidden" class="form-control form" name="cashvouch" value="<?php echo ($addflag != 1) ? $get["cashvouch"] : ""; ?>">

                        </div>

                        <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                            <label class="label-control marg">Bill No.</label>
                        </div>
                        <div class="col-lg-1 col-md-8 col-sm-8 col-xs-8 pad">
                            <input type="text" id="invno" name="invno" class="form-control form invno" required="true" value="<?php echo ($addflag != 1) ? $get['invno'] : ''; ?>" />
                        </div>
                        <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                            <label class="label-control marg">Party</label>
                        </div>
                        <div class="col-lg-4 col-md-8 col-sm-8 col-xs-8 pad">
                            <select name="party" class="form-control form party cmbparty select2" style='width:90%' required>
                                <option value="<?php echo ($addflag != 1) ? $lparty['accode'] : ""; ?>"><?php echo ($addflag != 1) ? $lparty['name'] : " "; ?></option>
                                <?php
                                //                                do not remove this lock, talk to firoz sir. 
                                //                                if ($addflag == 1) {
                                $mown2 = mysqli_query($conn, "SELECT `accode`, `name` FROM `accmast` WHERE grpcode = '013' or  grpcode = '021' ORDER BY name") or die(mysqli_error($conn));
                                while ($trow2 = mysqli_fetch_array($mown2)) {
                                    echo "<option value='$trow2[accode]'>$trow2[name]</option>";
                                }
                                //                                }
                                ?>
                            </select>
                        </div>
                    </div>
                    <div class="row">
                        <!-- <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                            <label class="label-control marg">OMS</label>
                        </div>
                        <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                        <?php
                        $soms = '';
                        if ($get['oms'] == 1) {
                            $soms = 'Yes';
                        } else {
                            $soms = 'No';
                        }
                        ?>
                            <input type="hidden" class="form-control form oms" id="editoms" tabindex="-1" readonly value="<?= $get['oms'] ?>" name="oms">
                            <input type="text" class="form-control form  oms2" tabindex="-1" readonly value="<? echo ($addflag != 1) ? $soms : '' ?>">
                        </div> -->

                        <div class="col-lg-1 pad text-right">
                            <label class="label-control marg">Paid By</label>
                        </div>
                        <div class="col-lg-1 pad">
                            <select id="paidby" name="paidby" class="form-control form select2 paidby" required>
                                <option
                                <?php
                                if ($get['paidby'] == 'R') {
                                    echo "selected='selected'";
                                }
                                ?> value="R">Credit</option>
                                <option
                                <?php
                                if ($get['paidby'] == 'C') {
                                    echo "selected='selected'";
                                }
                                ?> value="C">Cash</option>
                            </select>
                        </div>
                        <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                            <label class="label-control marg">Out Of State</label>
                        </div>
                        <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                            <input type="checkbox" class="form-control form oms" <?php
                                if ($get['oms'] == "1") {
                                    echo "checked";
                                }
                                ?> value="1" name="oms"  onclick="return false;"/>
                        </div>

                    </div>

                </div>

                <div class="">
                    <table class="table-striped table-condensed table-bordered tab" width="100%">
                        <thead class="mySearchTr">
                            <tr>
                                <th style="width: 1%"></th>
                                <th style="width: 2%">Sr.</th>
                                <th style="width: 14%;">Expense</th>
                                <th style='width: 4%'>Hsncode</th>
                                <th style='width: 5%' class="text-right">Amount</th>
                                <th style='width: 2%' class="text-right">Disc. %</th>
                                <th style='width: 4%' class="text-right">Disc. Amt.</th>
                                <th style='width: 5%' class="text-right">Taxable value</th>
                                <th style='width: 2%' class="text-right">CGST Rate</th>
                                <th style='width: 4%' class="text-right">CGST Amt.</th>
                                <th style='width: 2%' class="text-right">SGST Rate</th>
                                <th style='width: 4%' class="text-right">SGST Amt.</th>
                                <th style='width: 2%' class="text-right">IGST Rate</th>
                                <th style='width: 4%' class="text-right">IGST Amt.</th>
                                <th style='width: 6%' class="text-right">Total</th>
                            </tr>
                        </thead>
                        <tbody class="tbody">
                            <?php
                            if ($addflag != 1) {
                                $qry = mysqli_query($conn, "SELECT * FROM  `$trandb` WHERE vouchno='$getvouch' ORDER BY srno") or die(mysqli_error($conn));
                                $ctr = 0;
                                while ($row = mysqli_fetch_array($qry)) {
                                    $getname = mysqli_query($conn, "SELECT accode, name FROM `accmast` WHERE accode = '$row[expense]'") or die(mysqli_error($conn));
                                    $getn = mysqli_fetch_array($getname);

                                    echo "<tr>";
                                    echo "<td><i class='fa fa-close remove' style='display:none;'></i></td>";
                                    echo "<td><input type='text' name='srno_$ctr' class='srno form-control  form'  value='$row[srno]'></td>";
                                    echo "<td>";
                                    echo "<select class='form-control select2 form expense' name='expense_$ctr'  style='width:100%' required>";
                                    echo "<option value='$getn[accode]'>$getn[name]</option>";
                                    $getname2 = mysqli_query($conn, "SELECT accode, name FROM `accmast` WHERE `grpcode` in (select grpcode from grpmast where (type = 'E' or subtype = 'FA') ) order by name") or die(mysqli_error($conn));
                                    while ($fetn = mysqli_fetch_array($getname2)) {
                                        echo "<option value='$fetn[accode]'>$fetn[name]</option>";
                                    }
                                    echo "</select>";
                                    echo "</td>";
                                    echo "<td><input type='text' name='hsncode_$ctr' class='hsncode form-control  form' value='$row[hsncode]'></td>";
                                    echo "<td><input type='number' step='any' name='amount_$ctr' id='amount_$ctr' class='amount form-control text-right  form'  value='$row[amount]' ></td>";
                                    echo "<td><input type='text' name='discperc_$ctr' class='discperc form-control text-right  form' value='$row[discperc]' ></td>";
                                    echo "<td><input type='text' name='discamt_$ctr' class='discamt form-control text-right  form' value='$row[discamt]' readonly></td>";
                                    echo "<td><input type='text' name='subtot_$ctr' class='subtot form-control text-right  form' tabindex='-1' value='$row[subtot]'readonly></td>";
                                    echo "<td><input type='text' name='cgstrate_$ctr' class='cgstrate form-control text-right  form' value='$row[cgstrate]'></td>";
                                    echo "<td><input type='text' name='cgstamt_$ctr' class='cgstamt form-control text-right  form' tabindex='-1' value='$row[cgstamt]'readonly></td>";
                                    echo "<td><input type='text' name='sgstrate_$ctr' class='sgstrate form-control text-right  form' value='$row[sgstrate]'></td>";
                                    echo "<td><input type='text' name='sgstamt_$ctr' class='sgstamt form-control text-right  form' tabindex='-1' value='$row[sgstamt]'readonly></td>";
                                    echo "<td><input type='text' name='igstrate_$ctr' class='igstrate form-control text-right  form' value='$row[igstrate]'></td>";
                                    echo "<td><input type='text' name='igstamt_$ctr' class='igstamt form-control text-right  form' tabindex='-1' value='$row[igstamt]' readonly></td>";
                                    echo "<td><input type='text' name='total_$ctr' class='total form-control text-right  form' tabindex='-1' value='$row[total]' readonly></td>";
                                    echo "</tr>";
                                    $ctr++;
                                }
                            } else {
                                ?>
                                <tr>
                                    <td><i class='fa fa-close remove'></i></td>
                                    <td><input type='text' name='srno_0' class='srno form-control form' value='1'></td>
                                    <td>
                                        <select class='form-control select2 form expense' name='expense_0' style="width:100%" required>
                                            <option value=''></option>
                                            <?php
                                            $getname2 = mysqli_query($conn, "SELECT accode, name FROM `accmast` WHERE `grpcode` in (select grpcode from grpmast where (type = 'E' or subtype = 'FA')) order by name") or die(mysqli_error($conn));
                                            while ($fetn = mysqli_fetch_array($getname2)) {
                                                echo "<option value='$fetn[accode]'>$fetn[name]</option>";
                                            }
                                            ?>
                                        </select>
                                    </td>
                                    <td><input type='text' name='hsncode_0' class='hsncode form-control form' value=''></td>
                                    <td><input type="number" step="any" name='amount_0' id="amount_0" class='amount text-right form-control form zero' value='0'></td>
                                    <td><input type='text' name='discperc_0' class='discperc text-right form-control form ' value='0.00'></td>
                                    <td><input type='text' name='discamt_0' class='discamt text-right form-control form  ' tabindex="-1" value='0.00' readonly></td>
                                    <td><input type='text' name='subtot_0' class='subtot text-right form-control form  ' tabindex='-1' value='0.00' readonly></td>
                                    <td><input type='text' name='cgstrate_0' class='cgstrate text-right form-control form  ' value='0.00'></td>
                                    <td><input type='text' name='cgstamt_0' class='cgstamt text-right form-control form  ' tabindex='-1' value='0.00' readonly></td>
                                    <td><input type='text' name='sgstrate_0' class='sgstrate text-right form-control form  ' value='0.00'></td>
                                    <td><input type='text' name='sgstamt_0' class='sgstamt text-right form-control form  ' tabindex='-1' value='0.00' readonly></td>
                                    <td><input type='text' name='igstrate_0' class='igstrate text-right form-control form  ' value='0.00'></td>
                                    <td><input type='text' name='igstamt_0' class='igstamt text-right form-control form  ' tabindex='-1' value='0.00' readonly></td>
                                    <td><input type='text' name='total_0' class='total text-right form-control form  ' tabindex='-1' value='0.00' readonly></td>
                                </tr>
                                <?php
                            }
                            ?>
                        </tbody>
                    </table>
                </div>
                <div class="col-lg-12 pad">
                    <button type="button" class="btn btn-primary btn-square form" id="addnew">
                        <i class="fa fa-plus" data-toggle='tooltip' title='Add Row'></i>
                    </button>
                    <input type="hidden" id="items" name="items" value="<?php echo ($addflag != 1) ? $ctr : 1; ?>">
                </div>

                <div class="col-lg-12 col-xs-12 pad">
                    
                    <div class="col-lg-6 col-xs-12 pad">
                        
                        <div class="col-lg-12 col-xs-12 pad">
                            <div class="col-lg-2 pad text-right">
                                <label class="label-control marg">Unclaimed GST</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="checkbox" style="accent-color:red" class="form-control form unclaimgst"  value="1" name="unclaimgst" <?= isset($get['unclaimgst']) && $get['unclaimgst'] == "1" ? "checked" : "" ?>>
                            </div>
                            <div class="col-lg-2 pad text-right">
                                <label class="label-control marg">G.S.T NO.</label>
                            </div>
                            <div class="col-lg-6 pad">
                                <input type="text" name="gstno" class="form-control form gstno" value="<? echo ($addflag != 1) ? $get["gstno"] : ""; ?>">
                            </div>
                        </div>
                        
                        <div class="col-lg-12 col-xs-12 pad">
                            <div class="col-lg-5 pad text-right">
                                <label class="label-control marg">Remarks</label>
                            </div>
                            <div class="col-lg-6 pad">
                                <input type="text" name="remark1" class="form-control form " value="<? echo ($addflag != 1) ? $get["rem1"] : ""; ?>" maxlength="50">
                            </div>
                        </div>
                        <div class="col-lg-12 col-xs-12 pad">
                            <div class="col-lg-5 pad text-right"></div>
                            <div class="col-lg-6 pad">
                                <input type="text" name="remark2" class="form-control form " value="<? echo ($addflag != 1) ? $get["rem2"] : ""; ?>">
                            </div>
                        </div>

                    </div>

                    <div class="col-lg-6 col-xs-12 pad">
                        <div class="col-lg-12 col-xs-12 pad">
                            <div class="col-lg-3 pad"></div>
                            <div class="col-lg-3 pad"></div>
                            <div class="col-lg-3 pad text-right">
                                <label class="label-control marg">Subtotal</label>
                            </div>
                            <div class="col-lg-3 pad">
                                <input type="number" step="any" name="grossamt" class="form-control form text-right grossamt" value="<?php echo ($addflag != 1) ? $get['grossamt'] : "0"; ?>" readonly tabindex="-1">
                            </div>
                        </div>
                        <div class="col-lg-12 col-xs-12 pad">
                            <div class="col-lg-3 pad"></div>
                            <div class="col-lg-3 pad"></div>
                            <div class="col-lg-3 pad text-right">
                                <label class="label-control marg">Disc. Amount</label>
                            </div>
                            <div class="col-lg-3 pad">
                                <input type="number" step="any" name="totdiscamt" class="form-control form text-right totdiscamt" value="<?php echo ($addflag != 1) ? $get['discamt'] : "0"; ?>" readonly tabindex="-1">
                            </div>
                        </div>
                        <div class="col-lg-12 col-xs-12 pad">
                            <div class="col-lg-3 pad"></div>
                            <div class="col-lg-3 pad"></div>
                            <div class="col-lg-3 pad text-right">
                                <label class="label-control marg">Taxable Amount</label>
                            </div>
                            <div class="col-lg-3 pad">
                                <input type="number" step="any" name="taxableamt" class="form-control form text-right taxableamt" value="<?php echo ($addflag != 1) ? $get['taxableamt'] : "0"; ?>" readonly tabindex="-1">
                            </div>
                        </div>
                        <div class="col-lg-12 col-xs-12 pad">
                            <div class="row">
                                <div class="col-lg-3 "></div>
                                <div class="col-lg-9 ">
                                    <div class="table-responsive">
                                        <table class="table table-striped table-condensed table-bordered" width="100%">
                                            <thead class="mySearchTr">
                                                <tr>
                                                    <th width="20%">Taxable Amt.</th>
                                                    <th width="10%"></th>
                                                    <th width="18%" class='text-right'>CGST</th>
                                                    <th width="18%" class='text-right'>SGST</th>
                                                    <th width="18%" class='text-right'>IGST</th>
                                                    <th width="35%"></th>
                                                </tr>
                                            </thead>
                                            <tbody class="">
                                                <?php
                                                if ($addflag != 1) {
                                                    echo "<tr>";
                                                    echo "<td class='text-right'><b><input type='number' class='form-control form text-right tottaxble0' style='color:red' name='tottaxble0' value='$get[tottaxble0]' readonly></b></td>";
                                                    echo "<td class='text-right'><b>0%</b></td>";
                                                    echo "<td><input type='number' class='form-control form text-right cgst0'     name='cgst0'       value='$get[cgst0]' readonly tabindex='-1'></td>";
                                                    echo "<td><input type='number' class='form-control form text-right sgst0'     name='sgst0'       value='$get[sgst0]' readonly tabindex='-1'></td>";
                                                    echo "<td><input type='number' class='form-control form text-right igst0'     name='igst0'       value='$get[igst0]' readonly tabindex='-1'></td>";
                                                    echo "<td><input type='number' class='form-control form text-right totgst0'     name='totgst0'       value='$get[totgst0]' readonly tabindex='-1'></td>";
                                                    echo "</tr>";
                                                    echo "<tr>";
                                                    echo "<td><input type='number' class='form-control form text-right tottaxble3'     name='tottaxble3' value='$get[tottaxble3]' readonly></td>";
                                                    echo "<td class='text-right'><b>3%</b></td>";
                                                    echo "<td><input type='number' class='form-control form text-right cgst3'     name='cgst3'       value='$get[cgst3]' readonly></td>";
                                                    echo "<td><input type='number' class='form-control form text-right sgst3'     name='sgst3'       value='$get[sgst3]' readonly></td>";
                                                    echo "<td><input type='number' class='form-control form text-right igst3'     name='igst3'       value='$get[igst3]' readonly></td>";
                                                    echo "<td><input type='number' class='form-control form text-right totgst3'     name='totgst3'       value='$get[totgst3]' readonly></td>";
                                                    echo "</tr>";
                                                    echo "<tr>";
                                                    echo "<td><input type='number' class='form-control form text-right tottaxble5'     name='tottaxble5'       value='$get[tottaxble5]' readonly></td>";
                                                    echo "<td class='text-right'><b>5%</b></td>";
                                                    echo "<td><input type='number' class='form-control form text-right cgst5'     name='cgst5'       value='$get[cgst5]' readonly></td>";
                                                    echo "<td><input type='number' class='form-control form text-right sgst5'     name='sgst5'       value='$get[sgst5]' readonly></td>";
                                                    echo "<td><input type='number' class='form-control form text-right igst5'     name='igst5'       value='$get[igst5]' readonly></td>";
                                                    echo "<td><input type='number' class='form-control form text-right totgst5'     name='totgst5'       value='$get[totgst5]' readonly></td>";
                                                    echo "</tr>";
                                                    echo "<tr>";
                                                    echo "<td><input type='number' class='form-control form text-right tottaxble12'     name='tottaxble12'       value='$get[tottaxble12]' readonly></td>";
                                                    echo "<td class='text-right'><b>12%</b></td>";
                                                    echo "<td><input type='number' class='form-control form text-right cgst12'     name='cgst12'       value='$get[cgst12]' readonly></td>";
                                                    echo "<td><input type='number' class='form-control form text-right sgst12'     name='sgst12'       value='$get[sgst12]' readonly></td>";
                                                    echo "<td><input type='number' class='form-control form text-right igst12'     name='igst12'       value='$get[igst12]' readonly></td>";
                                                    echo "<td><input type='number' class='form-control form text-right totgst12'     name='totgst12'       value='$get[totgst12]' readonly></td>";
                                                    echo "</tr>";
                                                    echo "<tr>";
                                                    echo "<td><input type='number' class='form-control form text-right tottaxble18'     name='tottaxble18'       value='$get[tottaxble18]' readonly></td>";
                                                    echo "<td class='text-right'><b>18%</b></td>";
                                                    echo "<td><input type='number' class='form-control form text-right cgst18'     name='cgst18'       value='$get[cgst18]' readonly></td>";
                                                    echo "<td><input type='number' class='form-control form text-right sgst18'     name='sgst18'       value='$get[sgst18]' readonly></td>";
                                                    echo "<td><input type='number' class='form-control form text-right igst18'     name='igst18'       value='$get[igst18]' readonly></td>";
                                                    echo "<td><input type='number' class='form-control form text-right totgst18'     name='totgst18'       value='$get[totgst18]' readonly></td>";

                                                    echo "</tr>";
                                                    echo "<tr>";
                                                    echo "<td><input type='number' class='form-control form text-right tottaxble28'     name='tottaxble28'       value='$get[tottaxble28]' readonly></td>";
                                                    echo "<td class='text-right'><b>28%</b></td>";
                                                    echo "<td><input type='number' class='form-control form text-right cgst28'     name='cgst28'       value='$get[cgst28]' readonly></td>";
                                                    echo "<td><input type='number' class='form-control form text-right sgst28'     name='sgst28'       value='$get[sgst28]' readonly></td>";
                                                    echo "<td><input type='number' class='form-control form text-right igst28'     name='igst28'       value='$get[igst28]' readonly></td>";
                                                    echo "<td><input type='number' class='form-control form text-right totgst28'     name='totgst28'       value='$get[totgst28]' readonly></td>";
                                                    echo "</tr>";
                                                } else {
                                                    ?>
                                                    <tr>
                                                        <td><input type='number' class='form-control form text-right tottaxble0' name='tottaxble0' value='0' readonly tabindex='-1'></td>
                                                        <td class='text-right'><b>0%</b></td>
                                                        <td><input type='number' class='form-control form text-right cgst0' name='cgst0' value='0' readonly tabindex='-1'></td>
                                                        <td><input type='number' class='form-control form text-right sgst0' name='sgst0' value='0' readonly tabindex='-1'></td>
                                                        <td><input type='number' class='form-control form text-right igst0' name='igst0' value='0' readonly tabindex='-1'></td>
                                                        <td><input type='number' class='form-control form text-right totgst0' name='totgst0' value='0' readonly tabindex='-1'></td>
                                                    </tr>
                                                    <tr>
                                                        <td><input type='number' class='form-control form text-right tottaxble3' name='tottaxble3' value='0' readonly></td>
                                                        <td class='text-right'><b>3%</b></td>
                                                        <td><input type='number' class='form-control form text-right cgst3' name='cgst3' value='0' readonly></td>
                                                        <td><input type='number' class='form-control form text-right sgst3' name='sgst3' value='0' readonly></td>
                                                        <td><input type='number' class='form-control form text-right igst3' name='igst3' value='0' readonly></td>
                                                        <td><input type='number' class='form-control form text-right totgst3' name='totgst3' value='0' readonly></td>
                                                    </tr>
                                                    <tr>
                                                        <td><input type='number' class='form-control form text-right tottaxble5' name='tottaxble5' value='0' readonly></td>
                                                        <td class='text-right'><b>5%</b></td>
                                                        <td><input type='number' class='form-control form text-right cgst5' name='cgst5' value='0' readonly></td>
                                                        <td><input type='number' class='form-control form text-right sgst5' name='sgst5' value='0' readonly></td>
                                                        <td><input type='number' class='form-control form text-right igst5' name='igst5' value='0' readonly></td>
                                                        <td><input type='number' class='form-control form text-right totgst5' name='totgst5' value='0' readonly></td>
                                                    </tr>
                                                    <tr>
                                                        <td><input type='number' class='form-control form text-right tottaxble12' name='tottaxble12' value='0' readonly></td>
                                                        <td class='text-right'><b>12%</b></td>
                                                        <td><input type='number' class='form-control form text-right cgst12' name='cgst12' value='0' readonly></td>
                                                        <td><input type='number' class='form-control form text-right sgst12' name='sgst12' value='0' readonly></td>
                                                        <td><input type='number' class='form-control form text-right igst12' name='igst12' value='0' readonly></td>
                                                        <td><input type='number' class='form-control form text-right totgst12' name='totgst12' value='0' readonly></td>
                                                    </tr>
                                                    <tr>
                                                        <td><input type='number' class='form-control form text-right tottaxble18' name='tottaxble18' value='0' readonly></td>
                                                        <td class='text-right'><b>18%</b></td>
                                                        <td><input type='number' class='form-control form text-right cgst18' name='cgst18' value='0' readonly></td>
                                                        <td><input type='number' class='form-control form text-right sgst18' name='sgst18' value='0' readonly></td>
                                                        <td><input type='number' class='form-control form text-right igst18' name='igst18' value='0' readonly></td>
                                                        <td><input type='number' class='form-control form text-right totgst18' name='totgst18' value='0' readonly></td>
                                                    </tr>
                                                    <tr>
                                                        <td><input type='number' class='form-control form text-right tottaxble28' name='tottaxble28' value='0' readonly></td>
                                                        <td class='text-right'><b>28%</b></td>
                                                        <td><input type='number' class='form-control form text-right cgst28' name='cgst28' value='0' readonly></td>
                                                        <td><input type='number' class='form-control form text-right sgst28' name='sgst28' value='0' readonly></td>
                                                        <td><input type='number' class='form-control form text-right igst28' name='igst28' value='0' readonly></td>
                                                        <td><input type='number' class='form-control form text-right totgst28' name='totgst28' value='0' readonly></td>
                                                    </tr>
                                                    <?
                                                }
                                                ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-12 col-xs-12 pad">
                            <div class="col-lg-3 pad"></div>
                            <div class="col-lg-3 pad"></div>
                            <div class="col-lg-3 pad text-right">
                                <label class="label-control marg">Round Off</label>
                            </div>
                            <div class="col-lg-3 pad">
                                <input type="text" name="roundoff" class="form-control form text-right roundoff" value="<?php echo ($addflag != 1) ? $get['roundoff'] : "0"; ?>">
                            </div>
                        </div>
                        <div class="col-lg-12 col-xs-12 pad">
                            <div class="col-lg-3 pad"></div>
                            <div class="col-lg-3 pad"></div>
                            <div class="col-lg-3 pad text-right">
                                <label class="label-control marg">Total</label>
                            </div>
                            <div class="col-lg-3 pad">
                                <input type="text" name="pretottcs" class="form-control form text-right pretottcs" readonly value="<?php echo ($addflag != 1) ? $get['pretottcs'] : "00.00"; ?>">
                            </div>
                        </div>
                        <div class="col-lg-12 col-xs-12 pad" style="display: none;">
                            <div class="col-lg-3 text-right pad " style="color: red;">T.C.S%</div>
                            <div class="col-lg-3 pad"><input type="number" step="any" id="tcsperc" name="tcsperc" class="tcsperc form-control text-right form" value="<?php echo ($addflag != 1) ? $get['tcsperc'] : "0.00"; ?>"></div>
                            <div class="col-lg-3 pad text-right">
                                <label class="label-control marg">TCS Amt</label>
                            </div>
                            <div class="col-lg-3 pad">
                                <input type="text" name="tcsamt" class="form-control form text-right tcsamt" value="<?php echo ($addflag != 1) ? $get['tcsamt'] : "00.00"; ?>">
                            </div>
                        </div>
                        <div class="col-lg-12 col-xs-12 pad">
                            <div class="col-lg-3 pad"></div>
                            <div class="col-lg-3 pad"></div>
                            <div class="col-lg-3 pad text-right">
                                <label class="label-control marg">Net Amount</label>
                            </div>
                            <div class="col-lg-3 pad">
                                <input type="text" name="totbillamt" required="true" class="form-control form text-right totbillamt" value="<?php echo ($addflag != 1) ? $get['billamt'] : "0"; ?>" readonly tabindex="-1">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 pad">
        <div class="panel panel-default">
            <div class="panel-body">
                <?php include("includes/buttons.php"); ?>
            </div>
        </div>
    </div>
</form>

<div class="modal fade searchModal bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
    <div class="modal-dialog modal-lg" style="margin-top: 15%">
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" data-dismiss="modal"><span>&times;</span></button>
                <h4 class="modal-title" id="myLargeModalLabel">Search <? echo $formname; ?></h4>
            </div>
            <div class="modal-body">
                <input type="hidden" value="<?php echo $fseries ?>" class="form-control series">
                <input type="hidden" value="<?php echo $get['vouchno']; ?>" class="form-control vouchno">
                <input type="hidden" value="<?php echo $file ?>" class="form-control file">
                <input type="hidden" value="<?php echo $gtype ?>" class="form-control para">
                <div class="row">
                    <div class="col-lg-2">
                        <select class="form-control sfield">
                            <option value="1">Voucher</option>
                            <option value="2">Date</option>
                            <option value="3">Bill No.</option>
                            <!--<option value="4">Godown</option>-->
                            <option value="5">Party</option>
                        </select>
                    </div>
                    <div class="col-lg-2">
                        <select class="form-control soperator">
                            <option value="">Type of Search</option>
                            <option value="%">Like</option>
                            <option value="=">Exactly</option>
                        </select>
                    </div>
                    <div class="col-lg-2">
                        <select class="form-control sortBy">
                            <option value="">Sort By</option>
                            <option value="1">Voucher</option>
                            <option value="2">Date</option>
                            <option value="3">Bill No.</option>
                            <!--<option value="4">Godown</option>-->
                            <option value="5">Party</option>
                        </select>
                    </div>
                    <div class="col-lg-2">
                        <select class="form-control orderAs">
                            <option value="desc">Desc</option>
                            <option value="asc">Asc</option>
                        </select>
                    </div>
                    <div class="col-lg-2">
                        <input type="text" value="" class="form-control ssearch" placeholder="Search Here">
                    </div>
                    <div class="col-lg-2">
                        <input type="button" class="btn btn-primary sload" value="Search">
                    </div>
                </div>
                <div class="col-lg-12 sloader text-center">
                    <!-- <img src="images/search.gif" alt="loading"> -->
                </div>
                <div class="col-lg-12 snoRecord text-center">
                    <h3>NO RECORDS FOUND</h3>
                </div>
                <div class="table-responsive" style="max-height: 400px;overflow: auto;">
                    <table id="" class="table table-striped table-condensed table-bordered" width="100%">
                        <thead>
                            <tr class="mySearchTr">
                                <th width="15%">Voucher</th>
                                <th width="15%">Bill No.</th>
                                <th width="15%">Date</th>
                                <!--<th width="15%">Godown</th>-->
                                <th width="30%">Party</th>
                                <th width="10%">Action</th>
                            </tr>
                        </thead>
                        <tbody class="sTbody">
                        </tbody>
                    </table>
                </div>
                <div class="row">
                    <div class="col-xs-12 text-right search-action-bar">
                        <input type="button" class="btn btn-primary sprevious" value="Previous">
                        <input type="button" class="btn btn-primary snext" value="Next">
                    </div>
                </div>
            </div>
            <div class="modal-footer"></div>
        </div>
    </div>
</div>

<?php include("includes/linksfoot.php"); ?>
</body>

</html>