<?php
ob_start();
//echo "1";
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');
//browse(1);
$maindb = 'purmain';
$trandb = 'purtran';
$accdb = 'actran';
$stkdb = 'transacn';
$printfile = "purchgstmulti_print.php";
$file = 'purchgstmulti.php';
$trandbexist = 1;
$source = "PU";
$keyfld = "vouchno";
$myyear = $_SESSION["tit_" . $dbname];

date_default_timezone_set('Asia/Kolkata');
$time = date('H:i:s');

$paras = $_REQUEST["para"];

if ($paras) {
    $paras = $paras;
} else {
    $paras = "P";
}
$usertype = $_SESSION["usertype"];
$username = $_SESSION["username_" . $dbname];

//browse($username);
$formname = 'Purchase';

$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);

include("includes/vouchno_generate.php");
include("includes/prev&next.php");

if (isset($_POST["cancbtn"])) {
    $mcancvouch = $_POST['cancvouch'];
    $mcashvouch2 = $_POST['cashvouch2'];
    $cancdate = $_POST['cancdate'];

//    browse($cancdate);
    if ($cancdate != '' || $cancdate != '0000-00-00') {
//    browse($mcancvouch);
//    browse($mcashvouch2);
        mysqli_query($conn, "DELETE FROM `$accdb` WHERE `vouchno` = '$mcancvouch' AND `source` = '$source' ") OR die(mysqli_error($conn));
        mysqli_query($conn, "DELETE FROM `cashrecp` WHERE `$keyfld`='$mcashvouch2' ") or die(mysqli_error($conn));
        mysqli_query($conn, "DELETE FROM `$accdb` WHERE `$keyfld`='$mcashvouch2' and `source` = 'CR' $keycond") or die(mysqli_error($conn));
        mysqli_query($conn, "DELETE FROM `$stkdb` WHERE vouchno='$mcancvouch'  AND `source`='$source'") or die(mysqli_error($conn));


        mysqli_query($conn, "Update `$maindb` set `cancdate`='$cancdate', cancuser='$username', canc_flag='C' where vouchno = '$mcancvouch'") or die(mysqli_error($conn));
        mysqli_query($conn, "Update `$trandb` set cancdate='C' where vouchno = '$mcancvouch'") or die(mysqli_error($conn));
        browse('Bill Cancelled');
    }
    header("refresh: 1; $file?mode=edit&$keyfld=$mcancvouch");
}
if (isset($_POST["submit"])) {

    $a = 1;

    $invno = $_POST["invno"];

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

    $invdt = $_POST["invdt"];
    $party = $_POST["party"];
    $type = $_POST["type"];
    $prodtype = $_POST["prodtype"];
    $salesman = $_POST["salesman"];
    $stafcode = $_POST["stafcode"];
    $driver = $_POST["driver"];
    $dcperc = $_POST["dcperc"];
    $dcbperc = $_POST["dcbperc"];
    $dcamt = $_POST["dcamt"];
    $subtotal = $_POST["subtotal"];
    $litemdisc = $_POST["litemdisc"];
    $cdiscperc = $_POST["cdiscperc"];
    $cdiscamt = $_POST["cdiscamt"];
    $coukg = $_POST["coukg"];
    $courate = $_POST["courate"];
    $couamt = $_POST["couamt"];
    $netamt = $_POST["netamt"];
    $oldamt = $_POST["oldamt"];
    $cashamt = $_POST["cashamt"];
    $ccamt = $_POST["ccamt"];
    $upiamt = $_POST["upiamt"];
    $upiname = $_POST["upiname"];
    $upichk = $_POST["upichk"];
    $credamt = $_POST["credamt"];
    $cashchk = $_POST["cashchk"];
    $cardchk = $_POST["cardchk"];
    $bothchk = $_POST["bothchk"];
    $prnflag = $_POST["prnflag"];
    $lesother = $_POST["lesother"];
    $remark1 = $_POST["remark1"];
    $remark2 = $_POST["remark2"];
    $disctotp = $_POST["disctotp"];
    $bankname = $_POST["bankname"];

    $email = $_POST["email"];
    $gstno = $_POST["gstno"];

    $oms = $_POST["oms"];
    $taxamt = $_POST["taxamt"];
    $totcgst = $_POST["totcgst"];
    $totsgst = $_POST["totsgst"];
    $totigst = $_POST["totigst"];
    $sgstperc = $_POST["sgstperc"];
    $cgstperc = $_POST["cgstperc"];
    $igstperc = $_POST["igstperc"];
    $gstperc = $_POST["gstperc"];

    $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'];

    $totqty = $_POST['totqty'];
    $totgst5 = $_POST['totgst5'];
    $totgst12 = $_POST['totgst12'];
    $totgst18 = $_POST['totgst18'];
    $totgst28 = $_POST['totgst28'];
    $totalgst = $totgst5 + $totgst12 + $totgst18 + $totgst28;
    $nameprint = $_POST['nameprint'];
    $printmobile = $_POST['printmobile'];
    $refmobile = $_POST['refmobile'];
    $totalamount = $_POST['totalamount'];
    $roundoff = $_POST['roundoff'];
    $redeem = $_POST['redeem'];
    $redeempoint = $_POST['redeempoint'];
    $pointrate = $_POST['pointrate'];
    $stafcomm = $_POST['stafcomm'];
    $ewaybill = $_POST['ewaybill'];


    $lrno = $_POST["lrno"];
    $lrdate = $_POST["lrdate"];
    $transporter = $_POST["transporter"];
    $area = $_POST["area"];

    date_default_timezone_set("Asia/Dubai");
    $usertime = date("Y-m-d H:i:sa");

    $count = $_POST["items"];
    $mvouch = $qvouch;

    $paidby = $_POST["paidby"];
    if ($paidby == "R") {
        $purcode = '15';
    } else {
        $purcode = '14';
    }

    $accode = $party;
    $grpcode = '009';

    if ($vouchdt == '0000-00-00') {
        browse("Voucher Date Cannot Be Empty");
        $a = 0;
    }

    if ($vouchdt == '') {
        browse("Voucher Date Cannot Be Empty");
        $a = 0;
    }

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

    if ($a == 1) {
        mysqli_query($conn, "LOCK TABLES `$maindb` WRITE, `$trandb` WRITE, `product` WRITE, `$stkdb` WRITE, `$accdb` WRITE, `cashpay` WRITE, `accmast` WRITE ");

        if ($addflag == 1) {
            $gen1 = mysqli_query($conn, "SELECT MAX(vouchno+0) AS maxcode FROM `$maindb` where vouchno != '' $keycond 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;

            $time = strtotime($vouchdt);
            $month = date("m", $time);
            $intmonth = intval($month);
            if ($intmonth < 10) {
                $intmonth = '0' . $intmonth;
            }
            $voucher = $intmonth . $mvouch;
        }

        //**************************************************        auto cash Entry Start  ***************************************
        $mcashvouch = $_POST["cashvouch"];

        if ($paidby == 'C' || $totadv > 0) {
            if ($mcashvouch == '0' || $mcashvouch == '') {
                $gen1 = mysqli_query($conn, "SELECT MAX(vouchno+0) 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+0) AS maxcode FROM `cashpay` where bankname = '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;
            }
            if ($totadv > 0) {
                $recpamt = $totadv;
            } else {
                $recpamt = $totalamount;
            }

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

            mysqli_query($conn, "INSERT INTO `cashpay`( vouchno ,`vouchdt`, `bankname`, `bankinit`, `recpno`, `party`,`amount`,`remark1`,`remark2`,`trnflag`)
                                       Values ('$mcashvouch', '$vouchdt', '3', 'COH', '$mrecpno','$accode','$recpamt','Cash Recd. For','Sale No.$mvouch','S')") or die(mysqli_error($conn));


            // cash part  

            $minus_amt = ($recpamt * -1);


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


            mysqli_query($conn, "INSERT INTO `$accdb`(date,godown, vouchno, recpno, source, trnno, bankinit, accode, grpcode, amount, trnflag, monno)
                    VALUES ('$vouchdt','$godown','$mcashvouch', '$mrecpno', 'CP', '001', 'COH', '3','002', '$recpamt','S','$mono')") or die(mysqli_error($conn));


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


//**************************************************        auto cash Entry End    *************************************** 
        mysqli_query($conn, "DELETE FROM `$trandb` WHERE `$keyfld`='$mvouch' $keycond") or die(mysqli_error($conn));
        mysqli_query($conn, "DELETE FROM `$stkdb` WHERE `$keyfld`='$mvouch' AND `source`='$source' $keycond")or die(mysqli_error($conn));
        $group = $source . $mvouch;

        $srl = $tsint = $sintamt = $sint = 0;
        for ($i = 0; $i <= $count; $i++) {
            $msrno = $_POST["srno_$i"];
            $barcode = $_POST["barcode_$i"];
            $mitem = $_POST["item_$i"];
            $unit = $_POST["unit_$i"];
            $qty = $_POST["qty_$i"];
            $mrp = $_POST["mrp_$i"];
            $msp = $_POST["msp_$i"];
            $rate = $_POST["rate_$i"];
            $cost = $_POST["cost_$i"];
            $ratebfdisc = $_POST["ratebfdisc_$i"];
            $amount = $_POST["amount_$i"];

            $discperc = $_POST["discperc_$i"];
            $discamt = $_POST["discamt_$i"];
            $discperc2 = $_POST["discperc2_$i"];
            $discount2 = $_POST["discount2_$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"];
            $subtot = $_POST["subtot_$i"];

            $otprowsucs = $_POST["otprowsucs_$i"];
            $otpvalue = $_POST["otpvalue_$i"];
            $hsncode = $_POST["hsncode_$i"];

            $purvouch = $_POST["purvouch_$i"];
            $pursrno = $_POST["pursrno_$i"];
            $sintrate = $_POST["sintrate_$i"];
            $grp = $_POST["grp_$i"];
            $stkqt = $_POST["stkqty_$i"];

            $gstperc = $cgstperc + $sgstperc + $igstperc;

            $stkqty = $qty;


            if (!empty($mitem)) {
                $srl = $srl + 1;
                $sintamt = $sintrate * $qty;

                mysqli_query($conn, "INSERT INTO `$trandb`(`vouchno`, `series`, `vouchdt`, `srno`, `barcode`, `item`, `qty`, `unit`, 
                                   `mrp`, `msp`, `rate`, `amount`, `discperc`, `discount`, `discperc2`, `discount2`, `otprowsucs`, `otpvalue`,`hsncode`,
                                   `cgstrate` , `cgstamt`, `sgstrate`, `ratebfdisc`,stkqty,cost,
                                   `sgstamt`, `igstrate`, `igstamt`,`total`, `subtot`, `gstperc`,`sintrate`, `grp`) 
                    VALUES ('$qvouch', '$fseries', '$vouchdt', '$srl', '$barcode', '$mitem', '$qty', '$unit', 
                            '$mrp', '$msp', '$rate', '$amount', '$discperc', '$discamt', '$discperc2', '$discount2', '$otprowsucs', '$otpvalue','$hsncode',
                             '$cgstrate', '$cgstamt', '$sgstrate', '$ratebfdisc','$stkqt','$cost',
                            '$sgstamt', '$igstrate', '$igstamt', '$total', '$subtot', '$gstperc', '$sintrate', '$grp')") or die(mysqli_error($conn));

                ###########Stock Part############

                mysqli_query($conn, "INSERT INTO `$stkdb`(`vouchno`, `yearno`, `vouchdt`, `srno`, `barcode`, `itemcode`, `qty`, `unit`,  `source`,
                                `mrp`, `rate`, `amount`,cost) 
                    VALUES ('$qvouch', '$zyear', '$vouchdt', '$srl', '$barcode', '$mitem', '$stkqty', '$unit', '$source',
                                '$mrp', '$rate', '$amount','$cost')") or die(mysqli_error($conn));
            }
        }



//        browse(1);
############################### Accounts Part ######################################################
//        IF ($chkledg == 1) {
        mysqli_query($conn, "DELETE FROM `$accdb` WHERE `vouchno` = '$mvouch' AND `source` = '$source' ") OR die(mysqli_error($conn));
        if ($totalamount > 0) {
            $samtmin = $taxamt * -1;
            $gstmin = $totalgst * -1;
            $roff1 = $roundoff * -1;
            


            // purchase part
            mysqli_query($conn, "INSERT INTO `$accdb`(godown, date, vouchno, source, trnno, accode, grpcode, amount,monno)
                    VALUES ('$godown','$vouchdt','$mvouch', '$source', '001', '$purcode','004', '$samtmin','$mono')");
            // party part
            mysqli_query($conn, "INSERT INTO `$accdb`(godown, date, vouchno, source, trnno, accode, grpcode, amount)
                     VALUES ('$godown', '$vouchdt','$mvouch', '$source', '002', '$party','009', '$totalamount')");
            // round off part
            mysqli_query($conn, "INSERT INTO `$accdb`(godown, date, vouchno, source, trnno, accode, grpcode, amount)
                     VALUES ('$godown', '$vouchdt','$mvouch', '$source', '004', '25','012', '$roff1')");
            // GST part
            mysqli_query($conn, "INSERT INTO `$accdb`(godown, date, vouchno, source, trnno, accode, grpcode, amount)
                     VALUES ('$godown', '$vouchdt','$mvouch', '$source', '003', '36','020', '$gstmin')");
        }

        ############################## MAIN ######################################################
        if ($addflag == 1) {
            mysqli_query($conn, "INSERT INTO `$maindb`(`vouchno`, `series`, `enttime`, `username`, `invno`, `invdt`, `vouchdt`, `party`, `stafcode`, `stafcomm`,
                        `cashcred`, `prodtype`, `salesman`, `driver`, `dcperc`, `dcbperc`, `dcamt`, `totqty`, `subtotal`, `litemdisc`, `cashchk`, `cardchk`, `bothchk`, `prnflag`,
                        `cdiscperc`, `cdiscamt`, `coukg`, `courate`, `couamt`, `discperc`, `discount`, `netamt`, `cashamt`,`ccamt`,`credamt`, `lesother`,  `upichk`, `upiamt`,upiname,
                        `remark1`, `remark2`,`cashvouch`,`disctotp`,`purcono`,`purvouch`,`bankvouch`,`bankname`, `oms`, `cgstperc`, `sgstperc`, `igstperc`, 
                        `totcgst`, `totsgst`, `totigst`, `tottaxamt`,`gstperc`,`cgst5`,`sgst5`,`igst5`,`cgst12`,`sgst12`,`igst12`,`cgst18`,`sgst18`,`igst18`,`cgst28`,
                        `totalgst`,`sgst28`,`igst28`,`totgst5`,`totgst12`,`totgst18`,`totgst28`,`nameprint`,`printmobile`,`totalamount`,`roundoff`, `gstno`, `email`, 
                        `redeem`, `refmobile`, `pointrate`, redeempoint,incentive,`lrno`, `lrdate`, `transporter`, `area` , `ewaybill`) 
                        VALUES ('$qvouch', '$fseries', '$enttime', '$username', '$invno', '$vouchdt', '$vouchdt', '$party', '$stafcode', '$stafcomm',
                        '$paidby', '$prodtype', '$salesman', '$driver', '$dcperc', '$dcbperc', '$dcamt', '$totqty', '$subtotal', '$litemdisc',  '$cashchk', '$cardchk', '$bothchk', '$prnflag',
                        '$cdiscperc', '$cdiscamt', '$coukg', '$courate', '$couamt', '$discperc', '$discount', '$netamt', '$cashamt','$ccamt','$credamt', '$lesother', '$upichk', '$upiamt','$upiname',
                        '$remark1', '$remark2','$mcashvouch', '$disctotp','$purcono','$mpurvouch','$mbankvouch','$bankname', '$oms', '$cgstperc', '$sgstperc', '$igstperc',
                        '$totcgst', '$totsgst', '$totigst', '$taxamt','$gstperc','$cgst5','$sgst5','$igst5', '$cgst12','$sgst12','$igst12', '$cgst18', '$sgst18','$igst18','$cgst28',
                        '$totalgst','$sgst28','$igst28','$totgst5','$totgst12','$totgst18','$totgst28','$nameprint','$printmobile','$totalamount','$roundoff', '$gstno', '$email',
                        '$redeem', '$refmobile', '$pointrate', '$redeempoint','$tsint', '$lrno', '$lrdate', '$transporter', '$area','$ewaybill')") or die(mysqli_error($conn));
//            insmess();

            $mvouch = $qvouch; //1
//            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
        } else {
            $mvouch = $qvouch; //1

            mysqli_query($conn, "UPDATE `$maindb` SET `invno`='$invno',`username`='$username', `invdt`='$vouchdt',`vouchdt`='$vouchdt',
                       `nameprint`='$nameprint', `printmobile`='$printmobile',`party`='$party', upichk='$upichk', upiamt='$upiamt',
                       `cashcred`='$paidby',`prodtype`='$prodtype',`salesman`='$salesman',
                       `driver`='$driver',`dcperc`='$dcperc',`dcbperc`='$dcbperc',`dcamt`='$dcamt',`totqty`='$totqty',
                       `subtotal`='$subtotal', `stafcode`='$stafcode', `stafcomm`='$stafcomm', `litemdisc`='$litemdisc',
                       `cdiscperc`='$cdiscperc',`cdiscamt`='$cdiscamt',`coukg`='$coukg',`courate`='$courate',`couamt`='$couamt',
                       `discperc`='$discperc',`discount`='$discount',`netamt`='$netamt',`credamt`='$credamt',`ccamt`='$ccamt',
                       `cashamt`='$cashamt', `lesother`='$lesother',`remark1`='$remark1', `remark2`='$remark2', 
                       `cashvouch`='$mcashvouch',`disctotp`='$disctotp',`purcono`='$purcono',`purvouch`='$mpurvouch',
                       `bankvouch`='$mbankvouch',`bankname`='$bankname', `oms`='$oms',`cgstperc`='$cgstperc',`gstperc`='$gstperc',
                       `sgstperc`='$sgstperc', `igstperc`='$igstperc', `totcgst`='$totcgst', `totsgst`='$totsgst', 
                       `totigst`='$totigst', `tottaxamt`='$taxamt', `cgst5`='$cgst5',`sgst5`='$sgst5', `igst5`='$igst5',
                       `cgst12`='$cgst12',`sgst12`='$sgst12',`igst12`='$igst12', `cgst18`='$cgst18', `sgst18`='$sgst18', 
                       `igst18`='$igst18',`totalgst`='$totalgst', `cashchk`='$cashchk', upiname= '$upiname', `cardchk`='$cardchk', `bothchk`='$bothchk',
                       `cgst28`='$cgst28', `sgst28`='$sgst28',`igst28`='$igst28',`totalamount`='$totalamount',
                       `roundoff`='$roundoff', `prnflag`='$prnflag',`totgst5`='$totgst5',`totgst12`='$totgst12', 
                       `totgst18`='$totgst18',`totgst28`='$totgst28', `email`='$email', `gstno`='$gstno', `redeem`='$redeem', `refmobile`='$refmobile',
                       `pointrate`='$pointrate', redeempoint='$redeempoint',incentive='$tsint', lrno = '$lrno', lrdate = '$lrdate', transporter = '$transporter', 
                       `area` = '$area' , `ewaybill` = '$ewaybill' WHERE `vouchno`='$qvouch' and series='$fseries'") or die(mysqli_error($conn));


//            updmess();
        }

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

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);
    if ($get["oms"] == 1) {
        $ofs = "Out of State";
    } else {
        $ofs = "In State";
    }
    $getparty = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`= '$get[party]'") or die(mysqli_error($conn));
    $lparty = mysqli_fetch_array($getparty);

    $gettransp = mysqli_query($conn, "SELECT `code`,`name` FROM `transport` WHERE `code`= '$get[transporter]'") or die(mysqli_error($conn));
    $ltrans = mysqli_fetch_array($gettransp);


//    $getgodown = mysqli_query($conn, "SELECT * FROM `godown` WHERE `code`= '$get[godown]'") or die(mysqli_error($conn));
//    $getgd = mysqli_fetch_array($getgodown);
//    browse($getgd[code]);

    $delcsh = $get['cashvouch'];
}

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

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

    delnew($zdb, "$maindb", "$delcond2", "$file?mode=last");
    delnew($zdb, "$trandb", "$delcond2", "$file?mode=last");
    delnew($zdb, "$stkdb", "$delcond", "$file?mode=last");
    delnew($zdb, "$accdb", "$delcond", "$file?mode=last");
    delnew($zdb, "$accdb", "$delcond1", "$file?mode=last");
    delnew($zdb, "cashrecp", "$delcond3", "$file?mode=last");

    mysqli_query($conn, "UNLOCK TABLES");
}

include("includes/linkshead.php");
?>
<script src="MyScript/purchgstmulti.js?A=<?= mt_rand(); ?>" type="text/javascript"></script>
<!--<script src="MyScript/search_item_sale.js?A=<?= mt_rand(); ?>" type="text/javascript"></script>-->
<script src="MyScript/salegstmulti_search.js" 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: 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:40px">
                        <div class="col-lg-10 col-md-10 col-sm-10  col-xs-10">
                            <h3 class="panel-title" style="color:black"><a class="myPrint"><?php echo $formname; ?></a></h3>
                        </div>
                        <div class="col-lg-2 col-md-2 col-sm-2  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">
                            <h4 class="panel-title" style="float:right"><b><?php echo $get['username'] ?></b></h4>
                        </div>

                    </div>
                    <div class="panel-body">
                        <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" >Voucher</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" name="vouchno" class="form-control form vouchno" id="vouchno" value="<?php echo ($addflag != 1) ? $get['vouchno'] : $qvouch ?>" readonly>
                                <input type="hidden" name="voucher" class="form-control form voucher" value="<?php echo ($addflag != 1) ? $get['voucher'] : '' ?>" tabindex="-1" readonly required>
                                <input type="hidden" name="monno" class="form-control form monno" value="<?php echo ($addflag != 1) ? $get['monno'] : '' ?>" >
                                <input type="hidden" class="form-control addflag" value="<?php echo $addflag ?>" >
                                <input type="hidden" name="source" class="form-control form source" value="<?= $source; ?>" id="source">
                                <input type="hidden" class="form-control form" name="cashvouch" value="<?php Echo ($addflag != 1) ? $get["cashvouch"] : ""; ?>" >
                                <input type="hidden" class="form-control form canc_flag" name="" value="<?php Echo ($addflag != 1) ? $get["canc_flag"] : ""; ?>" >
                            </div>
                            <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-1 col-md-1 col-sm-1 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 required>
                            </div>
                            <!--                            <div class="col-lg-1 pad text-right">
                                                            &nbsp;
                                                        </div>-->


                            <div class="col-lg-1 pad text-right">
                                <label class="label-control marg">Supplier</label>
                            </div>
                            <div class="col-lg-3 pad">
                                <select class="form-control form cmbparty party select2" id="party" name="party" style="width: 100%" >
                                    <option value="<?php Echo ($addflag != 1) ? $lparty["accode"] : ""; ?>"><?php Echo ($addflag != 1) ? $lparty["name"] : ""; ?></option>
                                    <?php
                                    if ($addflag == 1) {

                                        $gparty = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `grpcode`='009' order by name")or die(mysqli_error($conn));
                                    } else {
                                        $gparty = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `grpcode`='009' and oms = '$get[oms]' order by name")or die(mysqli_error($conn));
                                    }
                                    while ($party = mysqli_fetch_array($gparty)) {
                                        Echo "<option value='$party[accode]'>$party[name]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                            <div class="col-lg-1 col-md-2 col-sm-7 col-xs-7 pad ">
                                <input type="hidden" class="form-control form oms" name="oms" value="<?= $get["oms"]; ?>" readonly="">

                                <label class="label-control marg  text-right ofs" style="color:red"><?= $ofs ?></label>
                            </div>

                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg" >Invoice</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" name="invno" class="form-control form invno" value="<?php echo ($addflag != 1) ? $get['invno'] : ""; ?>" >
                            </div>
                        </div>
                        <div class="row">

                            <!--                            <div class="col-lg-1 pad text-right">
                                                            <label class="label-control marg">Mobile</label>
                                                        </div>
                                                        <div class="col-lg-1 pad">
                                                            <input type="text" name="mobile" class="form-control form mobile" value="<?php echo ($addflag != 1) ? $get['mobile'] : ''; ?>"  >
                                                        </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" >

                                    <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-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">E-Way Bill No.</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" name="ewaybill" class="form-control form ewaybill" value="<?php echo ($addflag != 1) ? $get['ewaybill'] : ""; ?>" >
                            </div>

                        </div>

                        <!--                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                                        <label class="label-control marg" >Godown</label>
                                                    </div>
                                                    <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad ">
                                                        <select name="godown" class="form-control form  select2 godown" >
                                                            <option value="<?php echo ($addflag != 1) ? $getgd['code'] : ""; ?>"><?php echo ($addflag != 1) ? $getgd['gcode'] : ""; ?></option>
                        <?php
                        $mown = mysqli_query($conn, "SELECT * FROM `godown`") or die(mysqli_error($conn));
                        while ($trow = mysqli_fetch_array($mown)) {
//                                        browse($trow[code]);
                            echo "<option value='$trow[code]'>$trow[gcode]</option>";
                        }
                        ?>
                                                        </select>
                                                    </div>-->
                        <div class='col-lg-1 col-md-1 col-sm-1 col-xs-1'>
                        </div>
                        <div class='col-lg-1 col-md-1 col-sm-1 col-xs-1'>
                            <!--                                <button type='button' class='btn btn-primary lrtab form  btn-square' style="color: white">
                                                                LR. Detail
                                                            </button>-->
                        </div>
                    </div>
                    <div class="row">
                        <!--                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-3 text-right pad">
                                                        <label class="label-control marg">Free Sample</label>
                                                    </div>
                                                    <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                                        <input type="checkbox"  class="form-control form freeflag" <?php
                        if ($get['freeflag'] == "1") {
                            Echo "checked";
                        }
                        ?> value="1" name="freeflag" >                            
                                                    </div>-->


                        <div class='col-lg-2 col-md-2 col-sm-2 col-xs-2'>

                        </div>

                        <div class='col-lg-8 col-md-8 col-sm-8 col-xs-8 lrdetail'>
                            <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">LR No.</label>
                                </div>
                                <div class="col-lg-2 col-md-1 col-sm-1 col-xs-1 pad">
                                    <input type="text"  class="form-control form lrno" name="lrno" value="<?php Echo ($addflag != 1) ? $get["lrno"] : ""; ?>" >                            
                                </div>
                                <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                    &nbsp;
                                </div>
                                <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                                    <label class="label-control marg">LR Date</label>
                                </div>
                                <div class="col-lg-2 col-md-2 col-sm-1 col-xs-1 pad">
                                    <input type="date"  class="form-control form lrdate" name="lrdate" value="<?php Echo ($addflag != 1) ? $get["lrdate"] : ""; ?>">                            
                                </div>


                            </div>
                            <div class='row'>
                                <div class="col-lg-1 pad text-right">
                                    <label class="label-control marg">Transporter</label>
                                </div>
                                <div class="col-lg-3 col-md-3 col-sm-1 col-xs-1 pad">
                                    <select class="form-control form transporter select2" name="transporter" style="width: 100%">
                                        <option value="<?php Echo ($addflag != 1) ? $ltrans["code"] : ""; ?>"><?php Echo ($addflag != 1) ? $ltrans["name"] : ""; ?></option>
                                        <?php
                                        $gtrans = mysqli_query($conn, "SELECT `code`,`name` FROM `transport` order by name")or die(mysqli_error($conn));
                                        while ($ftrans = mysqli_fetch_array($gtrans)) {
                                            Echo "<option value='$ftrans[code]'>$ftrans[name]</option>";
                                        }
                                        ?>
                                    </select>
                                </div>
                                <div class="col-lg-1 pad text-right">
                                    <label class="label-control marg">Area</label>
                                </div>
                                <div class="col-lg-2 pad">
                                    <input type="text" name="area" class="form-control form area" value="<?php echo ($addflag != 1) ? $get['area'] : ''; ?>" tabindex="" >
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <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: 15%;">Item Name</th> 
                                    <th style='width: 4%' class='text-center'>Hsn Code</th>

<!--                                        <th style='width: 5%' class="text-right">Stk.</th>-->
                                    <th style='width: 5%' class="text-right">Qty.</th>
                                    <th style='width: 4%' class="text-right">Cost</th>
                                    <th style='width: 7%' class="text-right">Amount</th>
                                    <th style='width: 3%' class='text-center'>Disc. %</th>
                                    <th style='width: 5%' class='text-center'>Disc. Amt.</th>
                                    <th style='width: 5.5%' class='text-center'>Taxable value</th>
                                    <th style='width: 4%' class='text-center'>CGST Rate</th>
                                    <th style='width: 5%' class='text-center'>CGST Amt.</th>
                                    <th style='width: 4%' class='text-center'>SGST Rate</th>
                                    <th style='width: 5%' class='text-center'>SGST Amt.</th>
                                    <th style='width: 4%' class='text-center'>IGST Rate</th>
                                    <th style='width: 5%' class='text-center'>IGST Amt.</th>
                                    <th style='width: 5.5%' class='text-center'>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)) {
                                        $getitem = mysqli_query($conn, "SELECT code, name FROM `product` WHERE code = '$row[item]'") or die(mysqli_error($conn));


                                        $geti = mysqli_fetch_array($getitem);
                                        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 form item select2' name='item_$ctr' style='width:100%'>";
                                        Echo "<option value='$geti[code]'>$geti[name]</option>";
                                        $gitem = mysqli_query($conn, "SELECT `code`,`name` FROM `product`  order by name")or die(mysqli_error($conn));
                                        while ($item = mysqli_fetch_array($gitem)) {
                                            Echo "<option value='$item[code]'>$item[name]</option>";
                                        }
                                        Echo "</select>";
                                        Echo "</td>";
                                        Echo "<td><input type='text' class='form-control form hsncode'                name='hsncode_$ctr'     tabindex='-1'   value='$row[hsncode]'></td>";

//                                            Echo "<td><input type='text' step='any' name='stk_$ctr' class='stk form-control  text-right form' value='$row[stk]' tabindex='-1' style='background-color:lightgrey;color:blue'></td>";
                                        Echo "<td class='p1'><input type='text' step='any' name='qty_$ctr' id='qty_$ctr' class='qty form-control  text-right form' value='$row[qty]'></td>";
                                        Echo "<td class='p2'><input type='text' step='any' name='cost_$ctr' class='cost  form-control text-right  form' value='$row[cost]' >"
                                        . "<input type='hidden' step='any' name='rate_$ctr' id='rate_$ctr' class='rate  form-control text-right  form' value='$row[rate]'></td>";
                                        Echo "<td><input type='number' step='any' name='amount_$ctr' id='amount_$ctr' class='amount form-control text-right  form'  value='$row[amount]' tabindex='-1' readonly></td>";
                                        Echo "<td><input type='text' name='discperc_$ctr' class='discperc form-control text-right  form'  value='$row[discperc]' $rd></td>";
                                        Echo "<td><input type='text' name='discamt_$ctr' class='discamt form-control text-right  form' value='$row[discount]' $rd></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' tabindex='-1' value='$row[cgstrate]' readonly></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' tabindex='-1' value='$row[sgstrate]' readonly></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' tabindex='-1' value='$row[igstrate]' readonly></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 form item select2" id="item" name="item_0" style='width:100%'>
                                                <option value=""></option>
                                                <?php
                                                $gitem = mysqli_query($conn, "SELECT * FROM `product` order by name")or die(mysqli_error($conn));
                                                while ($item = mysqli_fetch_array($gitem)) {
                                                    Echo "<option value='$item[code]'>$item[name]</option>";
                                                }
                                                ?>
                                            </select>
                                        </td>
                                        <td><input type="text" class="form-control form text-left hsncode"     name="hsncode_0"      value=""  tabindex='-1'></td>

                                                                                                                <!--<td><input type='text' step='any' name='stk_0' class='stk form-control  text-right form' value='0' tabindex='-1' style='background-color:lightgrey;color:blue'></td>-->
                                        <td class='p1'><input type="text" step="any" name='qty_0' class='qty form-control text-right form zero' value='0' ></td> 
                                        <td class='p2'><input type="text" step="any" name='cost_0' class='cost form-control text-right form zero' value='0' >
                                            <input type="hidden" step="any" name='rate_0' class='rate form-control text-right form zero' value='0' >
                                        </td> 
                                        <td><input type="number" step="any" name='amount_0' id="amount_0" class='amount text-right form-control form zero' value='0' tabindex='-1' readonly></td> 
                                        <td><input type='text' name='discperc_0' class='discperc text-right form-control form ' value='0.00' <?= $rd ?>></td> 
                                        <td><input type='text' name='discamt_0' class='discamt text-right form-control form  ' value='0.00'  <?= $rd ?>></td> 
                                        <td><input type='text' name='subtot_0' class='subtot text-right form-control form  ' value='0.00' tabindex='-1' readonly></td> 
                                        <td><input type='text' name='cgstrate_0' class='cgstrate text-right form-control form  ' value='0.00' tabindex='-1' readonly></td> 
                                        <td><input type='text' name='cgstamt_0' class='cgstamt text-right form-control form  ' value='0.00' tabindex='-1' readonly></td> 
                                        <td><input type='text' name='sgstrate_0' class='sgstrate text-right form-control form  ' value='0.00' tabindex='-1' readonly></td> 
                                        <td><input type='text' name='sgstamt_0' class='sgstamt text-right form-control form  ' value='0.00' tabindex='-1' readonly></td> 
                                        <td><input type='text' name='igstrate_0' class='igstrate text-right form-control form  ' value='0.00' tabindex='-1' readonly></td> 
                                        <td><input type='text' name='igstamt_0' class='igstamt text-right form-control form  ' value='0.00' tabindex='-1' readonly></td> 
                                        <td><input type='text' name='total_0' class='total text-right form-control form  ' value='0.00' tabindex='-1' 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; ?>">  
                        <!--<input type="hidden" class="mandatoryId" name="manId" value="">-->  
                    </div>
                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12  pad">

                        <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-3 col-md-3 col-sm-3 col-xs-3 pad text-right">
                                        <label class="label-control marg">Remarks</label>
                                    </div>
                                    <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9 pad">
                                        <input type="text" name="remark1" class="form-control form remark1" value="<? Echo ($addflag != 1) ? $get["remark1"] : ""; ?>">
                                    </div>
                                </div>
                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3  pad text-right"></div>
                                    <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9 pad">
                                        <input type="text" name="remark2" class="form-control form remark2" value="<? Echo ($addflag != 1) ? $get["remark2"] : ""; ?>">
                                    </div>
                                </div>

                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="row">
                                        <div class="col-lg-3 pad"></div>
                                        <div class="col-lg-9 pad">
                                            <div class="table-responsive">
                                                <table class="table table-striped table-condensed table-bordered" width="100%">
                                                    <thead class="mySearchTr" style="color: white">
                                                        <tr>
                                                            <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="">

                                                        <tr>
                                                            <td class='text-right'><b>5%</b></td>
                                                            <td><input type='number' class='form-control form text-right cgst5'     name='cgst5'       value='<? Echo ($addflag != 1) ? $get["cgst5"] : "0"; ?>' readonly></td>
                                                            <td><input type='number' class='form-control form text-right sgst5'     name='sgst5'       value='<? Echo ($addflag != 1) ? $get["sgst5"] : "0"; ?>' readonly></td>
                                                            <td><input type='number' class='form-control form text-right igst5'     name='igst5'       value='<? Echo ($addflag != 1) ? $get["igst5"] : "0"; ?>' readonly></td>
                                                            <td><input type='number' class='form-control form text-right totgst5'     name='totgst5'       value='<? Echo ($addflag != 1) ? $get["totgst5"] : "0"; ?>' readonly></td>
                                                        </tr>
                                                        <tr>
                                                            <td class='text-right'><b>12%</b></td>
                                                            <td><input type='number' class='form-control form text-right cgst12'     name='cgst12'       value='<? Echo ($addflag != 1) ? $get["cgst12"] : "0"; ?>' readonly></td>
                                                            <td><input type='number' class='form-control form text-right sgst12'     name='sgst12'       value='<? Echo ($addflag != 1) ? $get["sgst12"] : "0"; ?>' readonly></td>
                                                            <td><input type='number' class='form-control form text-right igst12'     name='igst12'       value='<? Echo ($addflag != 1) ? $get["igst12"] : "0"; ?>' readonly></td>
                                                            <td><input type='number' class='form-control form text-right totgst12'     name='totgst12'       value='<? Echo ($addflag != 1) ? $get["totgst12"] : "0"; ?>' readonly></td>
                                                        </tr>
                                                        <tr>
                                                            <td class='text-right'><b>18%</b></td>
                                                            <td><input type='number' class='form-control form text-right cgst18'     name='cgst18'       value='<? Echo ($addflag != 1) ? $get["cgst18"] : "0"; ?>' readonly></td>
                                                            <td><input type='number' class='form-control form text-right sgst18'     name='sgst18'       value='<? Echo ($addflag != 1) ? $get["sgst18"] : "0"; ?>' readonly></td>
                                                            <td><input type='number' class='form-control form text-right igst18'     name='igst18'       value='<? Echo ($addflag != 1) ? $get["igst18"] : "0"; ?>' readonly></td>
                                                            <td><input type='number' class='form-control form text-right totgst18'     name='totgst18'       value='<? Echo ($addflag != 1) ? $get["totgst18"] : "0"; ?>' readonly></td>
                                                        </tr>
                                                        <tr>
                                                            <td class='text-right'><b>28%</b></td>
                                                            <td><input type='number' class='form-control form text-right cgst28'     name='cgst28'       value='<? Echo ($addflag != 1) ? $get["cgst28"] : "0"; ?>' readonly></td>
                                                            <td><input type='number' class='form-control form text-right sgst28'     name='sgst28'       value='<? Echo ($addflag != 1) ? $get["sgst28"] : "0"; ?>' readonly></td>
                                                            <td><input type='number' class='form-control form text-right igst28'     name='igst28'       value='<? Echo ($addflag != 1) ? $get["igst28"] : "0"; ?>' readonly></td>
                                                            <td><input type='number' class='form-control form text-right totgst28'     name='totgst28'       value='<? Echo ($addflag != 1) ? $get["totgst28"] : "0"; ?>' readonly></td>
                                                        </tr>

                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </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-4 col-md-4 col-sm-2 col-xs-2  pad text-right">
                                        <label class="label-control marg" style='color:#337AB7'>Total Qty. </label>
                                    </div>
                                    <div class="col-lg-2 pad col-md-3 col-sm-3 col-xs-3 ">
                                        <input type="text" name="totqty" class="form-control form text-right totqty"  value="<?php echo ($addflag != 1) ? $get['totqty'] : "0.00"; ?>" readonly>
                                    </div>
                                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3  pad text-right">
                                        <label class="label-control marg" style='color:#337AB7'>SubTotal</label>
                                    </div>
                                    <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4  pad">
                                        <input type="text" class="form-control form subtotal text-right" value="<? Echo ($addflag != 1) ? $get['subtotal'] : "0"; ?>" name="subtotal" readonly>
                                        <input type="hidden" class="form-control form msptotal text-right" value="<? Echo ($addflag != 1) ? $get['msptotal'] : "0"; ?>" name="msptotal" readonly>
                                    </div>
                                </div>
                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 pad"></div>
                                    <div class="col-lg-2 pad"></div>
                                    <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4  pad text-right">
                                        <label class="label-control marg">Less Item Discount</label>
                                    </div>
                                    <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4  pad">
                                        <input type="text" class="form-control form litemdisc text-right" value="<? Echo ($addflag != 1) ? $get['litemdisc'] : "0"; ?>" name="litemdisc" readonly>
                                    </div>
                                </div>
                                <!--                                <div class="col-lg-12 col-xs-12 pad">
                                                                    <div class="col-lg-3 pad">   
                                                                        <input type="button" name="gendsotp" class="form-control gendsotp form" style="color:red;border: none;" value="Generate Discount OTP">
                                                                    </div>
                                                                    <div class="col-lg-3 pad text-right">
                                                                        <label class="label-control marg">Less Cash Discount</label>
                                                                    </div>
                                                                    <div class="col-lg-2 pad">
                                                                        <input type="text" class="form-control form cdiscperc text-right" value="<? Echo ($addflag != 1) ? $get['cdiscperc'] : "0"; ?> "  name="cdiscperc">
                                                                    </div>
                                                                    <div class="col-lg-1 pad">
                                                                        <label class="label-control marg">%</label>
                                                                    </div>
                                                                    <div class="col-lg-3 pad">
                                                                        <input type="text" class="form-control form cdiscamt text-right" value="<? Echo ($addflag != 1) ? $get['cdiscamt'] : "0"; ?>" name="cdiscamt" readonly>
                                                                    </div>
                                                                </div>
                                -->         
                                <!--                                <div class="col-lg-12 col-md-12 col-xs-12 pad">
                                                                    <div class="col-lg-3 col-md-3 pad"></div>
                                                                    <div class="col-lg-3 col-md-3 text-right pad">
                                                                    </div>
                                                                    <div class="col-lg-3 col-md-3 text-right pad">      
                                                                        <label class="label-control marg">Less Other</label>
                                                                    </div>
                                                                    <div class="col-lg-3 col-md-3 pad">-->
                                <input type="hidden" class="form-control form lesother text-right" value="<? Echo ($addflag != 1) ? $get['lesother'] : "0"; ?>" name="lesother" readonly>
                                <input type="hidden" class="form-control form disctotp text-right" value="<? Echo ($addflag != 1) ? $get['disctotp'] : ""; ?>" name="disctotp" >
                                <!--                            </div>
                                                        </div>-->
                                <!--                                <div class="col-lg-12 col-xs-12 pad">
                                                                    <div class="col-lg-2 pad text-right">
                                                                        <label class="label-control marg">Add Courier</label>
                                                                    </div>
                                                                    <div class="col-lg-2 pad text-right">
                                                                        <input type="text" class="form-control form coukg text-right" value="<? Echo ($addflag != 1) ? $get['coukg'] : "0"; ?>" name="coukg" >
                                                                    </div>
                                                                    <div class="col-lg-1 pad text-left">
                                                                        <label class="label-control marg">/Kg</label>
                                                                    </div>
                                                                    <div class="col-lg-3 pad">
                                                                        <input type="text" class="form-control form courate text-right" value="<? Echo ($addflag != 1) ? $get['courate'] : "0"; ?>" name="courate">
                                                                    </div>
                                                                    <div class="col-lg-1 pad">
                                                                        <label class="label-control marg">Rate</label>
                                                                    </div>
                                                                    <div class="col-lg-3 pad">
                                                                        <input type="text" class="form-control form couamt text-right" value="<? Echo ($addflag != 1) ? $get['couamt'] : "0"; ?>" name="couamt" readonly>
                                                                    </div>
                                                                </div>-->
                                <div class="col-lg-12 col-md-12 col-xs-12 pad">
                                    <div class="col-lg-3 col-md-3 pad"></div>
                                    <div class="col-lg-3 col-md-3 text-right pad">
                                        <!--<label class="label-control marg">Less Other</label>-->
                                    </div>
                                    <div class="col-lg-3 col-md-3 col-sm-8 col-xs-8 pad text-right">
                                        <label class="label-control marg">Taxable Value</label>

                                    </div>
                                    <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4 pad">
                                        <input type="text" class="form-control form taxamt numeric text-right" value="<? Echo ($addflag != 1) ? $get['tottaxamt'] : "0"; ?>" name="taxamt" readonly>
                                    </div>
                                </div>


                                <div class="col-lg-12 col-md-12 col-xs-12 pad">
                                    <div class="col-lg-3 col-md-3 pad"></div>
                                    <div class="col-lg-3  text-right pad">
                                        <!--<label class="label-control marg">Less Other</label>-->
                                    </div>
                                    <div class="col-lg-3 col-md-3 col-sm-8 col-xs-8 pad text-right">
                                        <label class="label-control marg">Total Gst</label>

                                    </div>
                                    <div class="col-lg-3  col-md-3 col-sm-4 col-xs-4 pad">
                                        <input type="text" class="form-control form text-right totalgst" value="<? Echo ($addflag != 1) ? $get['totalgst'] : "0"; ?>" name="totalgst" readonly>
                                    </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  col-md-3 col-sm-8 col-xs-8 pad text-right">
                                        <label class="label-control marg">Round Off</label>
                                    </div>
                                    <div class="col-lg-3  col-md-3 col-sm-4 col-xs-4 pad">
                                        <input type="text" class="form-control form roundoff text-right " value="<? Echo ($addflag != 1) ? $get['roundoff'] : "0"; ?>" name="roundoff">
                                    </div>
                                </div>
                                <div class="col-lg-12 col-md-12 col-xs-12 pad">
                                    <div class="col-lg-3 col-md-3 pad"></div>
                                    <div class="col-lg-3  text-right pad">
                                        <!--<label class="label-control marg">Less Other</label>-->
                                    </div>
                                    <div class="col-lg-3 col-md-3 col-sm-8 col-xs-8 pad text-right">
                                        <label class="label-control marg">Total Amount</label>

                                    </div>
                                    <div class="col-lg-3  col-md-3 col-sm-4 col-xs-4 pad">
                                        <input type="text" class="form-control form netamt text-right totbillamt" value="<? Echo ($addflag != 1) ? $get['netamt'] : "0"; ?>" name="netamt" readonly>

                                        <input type="hidden" class="form-control form totalamount text-right numeric" value="<? Echo ($addflag != 1) ? $get['totalamount'] : "0"; ?>" name="totalamount" readonly>
                                    </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 col-md-3 col-sm-8 col-xs-8 pad text-right">
                                                                            <label class="label-control marg">Netamt (Rs.)</label>
                                                                        </div>
                                                                        <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4 pad">
                                                                            <input type="text" class="form-control form netamt text-right totbillamt" value="<? Echo ($addflag != 1) ? $get['netamt'] : "0"; ?>" name="netamt" readonly>
                                                                            <input type="hidden" class="form-control form oldamt text-right" value="<? Echo ($addflag != 1) ? $get['netamt'] : "0"; ?>" name="oldamt" readonly>
                                                                        </div>
                                                                    </div>-->

                                <!--                                <div class="col-lg-12 col-xs-12 pad">
                                                                    <div class="col-lg-3 pad text-right">
                                                                        <label class="label-control marg">DC On</label>
                                                                    </div>
                                                                    <div class="col-lg-2 pad text-right">
                                                                        <input type="text" class="form-control form dcperc text-right" value="<? Echo ($addflag != 1) ? $get['dcperc'] : "0"; ?>" name="dcperc" >
                                                                    </div>
                                                                    <div class="col-lg-1 pad text-left">
                                                                        <label class="label-control marg">%</label>
                                                                    </div>
                                                                    <div class="col-lg-2 pad">
                                                                        <input type="text" class="form-control form dcbperc text-right" value="<? Echo ($addflag != 1) ? $get['dcbperc'] : "0"; ?>" name="dcbperc">
                                                                    </div>
                                                                    <div class="col-lg-1 pad">
                                                                        <label class="label-control marg">On</label>
                                                                    </div>
                                                                    <div class="col-lg-3 pad">
                                                                        <input type="text" class="form-control form dcamt text-right" value="<? Echo ($addflag != 1) ? $get['dcamt'] : "0"; ?>" name="dcamt" readonly>
                                                                    </div>
                                                                </div>-->
                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 col-md-3 col-sm-3  col-xs-3 pad text-right">
                                    </div>
                                    <div class="col-lg-2 col-md-2 col-sm-2 col-xs-1 pad text-right">
                                    </div>
                                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-2 pad text-right" style="padding-right:1%">
                                        <!--<label class="label-control marg" style="color:red;font-size: 22px">Print</label>-->

                                    </div>

                                    <div class="col-lg-1 col-md-2 col-sm-2 col-xs-3 pad">
<!--                                        <input type="checkbox" style="height:30px;width:30px" class="form  prnflag" id="prnflag" name="prnflag" value="1" <?
                                        if ($get['prnflag'] == 1) {
                                            Echo "checked";
                                        }
                                        ?>>-->

                                    </div>
                                    <!--                                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                                                                <input type="button" id="finishTab" class="btn btn-primary pull-right form mySearchTr" style="color: #fff;" value="Check & Finish">
                                                                            </div>-->
                                    <input type="date" value="<?= $zStartDate ?>" style="width: 1px;border: none" class="zstdate">
                                    <input type="date" value="<?= $zEndDate ?>" style="width: 1px;border: none" class="zenddate">
                                </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"); ?>
                        <script>
                            $(document).ready(function () {
                                $("#hprint").hide();

                                var usertype = <?= $usertype ?>;
                                if (usertype == 3) {
                                    $("#hedit").hide();
                                }
                            });
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>

<div class="modal fade" id="cancmodel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="col-lg-11">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Cancel Bill</h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-lg-12 upload">
                            <form id="upload_form" method="post">

                                <div class="row pad">
                                    <input type="hidden" name="cancvouch" id="cancvouch" value='<?php Echo ($addflag != 1) ? $get['vouchno'] : "$qvouch"; ?>'>
                                    <input type="hidden" name="cashvouch2" id="cashvouch2" value='<?php Echo ($addflag != 1) ? $get['cashvouch'] : ""; ?>'>
                                    <div class="col-lg-4 col-md-4 col-sm-4 col-xs-5 text-right">
                                        <label class="label-control marg">Cancel Date</label>
                                    </div>
                                    <div class="col-lg-4 col-md-4 col-sm-6 col-xs-7">

                                        <input type="date" name="cancdate" value="<?php Echo ($addflag != 1) ? $get['cancdate'] : ""; ?>" class="form-control cancdate">
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-lg-6 col-md-6 col-sm-7 col-xs-8 text-right">
                                        <input type="submit" value="Cancel"  name="cancbtn" class="btn btn-square" style="background-color: #C0CA33; color: white">
                                    </div>
                                </div>

                            </form>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade itemModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
    <div class="modal-dialog modal-lg">
        <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 $paras ?>" class="form-control para">
                <div class="row">
                    <div class="col-lg-3">
                        <select class="form-control ifield">
                            <option value="1">Name</option>
                            <option value="2">Barcode</option>
                            <option value="3">Itemcode</option>
                            <!--                            <option value="4">Gram</option>
                                                        <option value="5">Unit</option>-->
                        </select>
                    </div>
                    <div class="col-lg-2">
                        <select class="form-control ioperator">
                            <option value=""></option>
                            <option value="%">Like</option>
                            <option value="=">Exactly</option>
                        </select>
                    </div>
                    <div class="col-lg-4">
                        <input type="text" value="" class="form-control isearch">
                    </div>
                    <div class="col-lg-3">
                        <input type="button" class="btn btn-primary iload" value="Search">
                    </div>
                </div>

                <div class="col-lg-12 iloader text-center">
                    <img src="images/search.gif" alt="loading">       
                </div>
                <div class="col-lg-12 inoRecord 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%">Itemcode</th>
                                <th width="49%">Name</th>
                                <th width="8%">Stock</th>
<!--                                <th width="17%">Barcode</th>
                                <th width="8%">Gram</th>
                                <th width="8%">Unit</th>-->
                                <th width="8%">Rate</th>
                            </tr>
                        </thead>
                        <tbody class="iTbody">
                        </tbody>
                    </table>
                </div>
                <div class="row">
                    <div class="col-xs-12 text-right search-action-bar">
                        <input type="button"  class="btn btn-primary iprevious" value="Previous">
                        <input type="button"  class="btn btn-primary inext" value="Next">
                    </div>
                </div>
            </div>
            <div class="modal-footer"></div>
        </div>
    </div>
</div>
<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="S" class="form-control parasrch">
                <div class="row">
                    <div class="col-lg-2">
                        <select class="form-control sfield">
                            <option value="1"> Party Name</option>
                            <option value="4">Voucher</option>
                            <option value="2">Invoice No.</option>
                            <option value="3">Date</option>
                            <!--<option value="5">Mobile</option>-->
                            <option value="6">Amount</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="4"> Party Name</option>
                            <option value="1">Voucher</option>
                            <option value="2">Invoice No.</option>
                            <option value="3">Date</option>
                            <!--<option value="5">Mobile</option>-->
                            <option value="6">Amount</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="5%">Voucher</th>
                                <th width="10%">Invoice No.</th>
                                <th width="15%">Date</th>
                                <th width="20%">Party Name</th>
                                <!--<th width="10%">Mobile</th>-->
                                <th width="5%">Paid By</th>
                                <th width="7%">Subtotal</th>
                                <th width="7%">Discount</th>
                                <th width="7%">Taxable</th>
                                <th width="7%">GST</th>
                                <th width="9%">Amount</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 sprev" 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>
