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

$formname = 'Sale';
$maindb = 'gstmain';
$trandb = 'gsttran';
$stkdb = 'transacn';
$accdb = 'actran';
$cashdb = 'cashpay';
$bankdb = 'bankpay';
$printfile = "sale_print.php";
$file = 'sale.php';
$trandbexist = 1;
$keyfld = "vouchno";
$source = "SLFP";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
$compcd = $_SESSION["comp_" . $dbname];
$usertype = $_SESSION["usertype_" . $dbname];
$username = $_SESSION["username_" . $dbname];

//$stkdb1 = 'tran';
$zroot = $_SESSION["zdir"];
//$combstkdb = $stkdb1 . $myyear;
$zroot1 = substr($zroot, 0, -4);
$currcono = $compcd;
$curryear = $myyear;

mysqli_select_db($conn, $zdb);
include("includes/vouchno_generate.php");
include("includes/prev&next.php");

if (isset($_POST["submit"])) {
    $a = 1;
    $invno = $_POST["invno"];
    $vouchdt = $_POST["vouchdt"];
    $invdt = $_POST["invdt"];
    $party = $_POST["party"];
    $broker = $_POST["broker"];
    $type = $_POST["paidby"];
    $paidby = $_POST["paidby"];
    $subtotal = $_POST["subtotal"];
    $litemdisc = $_POST["litemdisc"];
    $discperc = $_POST["discperc"];
    $discount = $_POST["discount"];
    $courate = $_POST["courate"];
    $couamt = $_POST["couamt"];
    $packing = $_POST["packing"];
    $vatamt = $_POST["vatamt"];
    $netamt = $_POST["netamt"];
    $oldamt = $_POST["oldamt"];
    $cashamt = $_POST["cashamt"];
    $ccamt = $_POST["ccamt"];
    $credamt = $_POST["credamt"];
    $lesother = $_POST["lesother"];
    $remark1 = $_POST["remark1"];
    $remark2 = $_POST["remark2"];
    $bankname = $_POST["bankname"];

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

    $totgst5 = $_POST['totgst5'];
    $totgst12 = $_POST['totgst12'];
    $totgst18 = $_POST['totgst18'];
    $totgst28 = $_POST['totgst28'];
    $nameprint = $_POST['nameprint'];
    $printmobile = $_POST['printmobile'];
    $totalamount = $_POST['totalamount'];
    $roundoff = $_POST['roundoff'];
    $logdate = $_POST['logdate'];
    $agentcc = $_POST['agentcc'];
    $packgtamt = $_POST['packgtamt'];
    $packgtperc = $_POST['packgtperc'];



    $count = $_POST["items"];

    if ($igstperc > 0) {
        $gstp = $igstperc;
    } else {
        $gstp = $cgstperc + $sgstperc;
    }

    $mvouch = $qvouch;
    if ($type == 'C') {
        $salecode = 11;
    } else {
        $salecode = 12;
    }


    if ($a == 1) {

        $mcashvouch = $_POST["cashvouch"];
        //        browse($mcashvouch);
        $qrygrp = mysqli_query($conn, "select `grpcode` from accmast where `accode` = '$broker'") or die(mysqli_error($conn));
        $fetgrp = mysqli_fetch_array($qrygrp);
        $pgrp = $fetgrp['grpcode'];
        if ($type == 'C') {
            if ($mcashvouch == '0' || $mcashvouch == '') {
//                browse("in");
                $gen1 = mysqli_query($conn, "SELECT MAX(vouchno) AS maxcode FROM `cashrecp`  LIMIT 0,1 ") or die(mysqli_error($conn));
                if (mysqli_num_rows($gen1) > 0) {
                    $vvouch = mysqli_fetch_assoc($gen1);
                    $mcashvouch = $vvouch["maxcode"] + 1;
                } else {
                    $mcashvouch = '1';
                }
            }


            $genrecp = mysqli_query($conn, "SELECT * FROM `cashrecp` 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 `cashrecp` where bankname = '3'  LIMIT 0,1 ") or die(mysqli_error($conn));
                if (mysqli_num_rows($gen2) > 0) {
                    $gvouch = mysqli_fetch_assoc($gen2);
                    $mrecpno = $gvouch["maxcode"] + 1;
                } else {
                    $mrecpno = '1';
                }
            }

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


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


            // cash part  

            $minus_amt = ($totalamount * -1);

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



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

            // party part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, recpno, trnno, bankinit, accode, grpcode, amount,prodtype,actamt)
                     VALUES ('$vouchdt','$mcashvouch', 'CR', '$mrecpno', '002', 'COH', '$broker',  '$pgrp', '$totalamount','$prodtype','$totalamount')");
        } else {
            //            browse("out");
            mysqli_query($conn, "DELETE FROM `cashrecp` WHERE `$keyfld`='$mcashvouch'") or die(mysqli_error($conn));
            mysqli_query($conn, "DELETE FROM `actran` WHERE `$keyfld`='$mcashvouch' AND `source`='CR'") or die(mysqli_error($conn));
            $mcashvouch = "";
        }
        //        #################################TRAN PART #################################
        mysqli_query($conn, "DELETE FROM `$trandb` WHERE `$keyfld`='$mvouch'") or die(mysqli_error($conn));
        mysqli_query($conn, "DELETE FROM `$stkdb` WHERE `$keyfld`='$mvouch' AND `source`='$source'") or die(mysqli_error($conn));

        $group = $source . $mvouch;

        $srl = 0;
        for ($i = 0; $i <= $count; $i++) {
            $msrno = $_POST["srno_$i"];
            $barcode = $_POST["barcode_$i"];
            $color = $_POST["color_$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"];
            $amount = $_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"];
            $subtot = $_POST["subtot_$i"];
            $hsncode = $_POST["hsncode_$i"];
            $purvouch = $_POST["purvouch_$i"];
            $pursrno = $_POST["pursrno_$i"];
            $size = $_POST["size_$i"];
            $stqty = $_POST["stqty_$i"];


            if (!empty($mitem)) {
                $srl = $srl + 1;
                $stkqty = $qty * -1;

//                mysqli_query($conn, "INSERT INTO `$trandb`(`vouchno`, `vouchdt`, `srno`, `barcode`, `itemcode`, `qty`, `unit`, size,
//                                                   `mrp`, `msp`, `rate`, `amount`, `discperc`, `discount`,`hsncode`,
//                                                   `cgstrate` , `cgstamt`, `sgstrate`, 
//                                                   `sgstamt`, `igstrate`, `igstamt`,`total`, `subtot`, `gstperc`,color) 
//                    VALUES ('$qvouch', '$vouchdt', '$srl', '$mitem', '$mitem', '$qty', '$unit', '$size',
//                            '$mrp', '$msp', '$rate', '$amount', '$discperc', '$discamt','$hsncode',
//                             '$cgstrate', '$cgstamt', '$sgstrate', 
//                            '$sgstamt', '$igstrate', '$igstamt', '$total', '$subtot', '$gstperc','$color')") or die(mysqli_error($conn));
                mysqli_query($conn, "INSERT INTO `$trandb`(`vouchno`, `vouchdt`, `srno`, `barcode`, `item`, `qty`, `unit`, size, stqty,
                                                   `mrp`, `msp`, `rate`, `amount`) 
                    VALUES ('$qvouch', '$vouchdt', '$srl', '$mitem', '$mitem', '$qty', '$unit', '$size', '$stqty',
                            '$mrp', '$msp', '$rate', '$amount')") or die(mysqli_error($conn));


                #################################STOCK PART #################################

                mysqli_query($conn, "INSERT INTO `$stkdb`(`srno`, size, `compcode`, `yearno`, `vouchno`, `vouchdt`, `source`, `barcode`, `itemcode`,  `qty`, `unit`, cost,  `mrp`, `rate`, `amount`,color,accode, `group`)
                                        VALUES( '$srl', '$size', '$compcd', '$myyear', '$qvouch', '$vouchdt', '$source', '$mitem', '$mitem', '$stkqty', '$unit', '$rate', '$mrp', '$rate', '$amount','$color', '$party', '$group')") or die(mysqli_error($conn));
            }
        }

        ############################### Accounts Part ######################################################
        //        $gstamt = $totbillamt - $taxableamt;
        $bsource = "SLFB";
        mysqli_query($conn, "DELETE FROM `$accdb` WHERE `vouchno` = '$mvouch' AND `source` = '$source'") or die(mysqli_error($conn));
        mysqli_query($conn, "DELETE FROM `$accdb` WHERE `vouchno` = '$mvouch' AND `source` = '$bsource'") or die(mysqli_error($conn));


        if ($agentcc > 0) {
            $actperc = $agentcc - $discperc;
            if ($actperc > 0) {
                $commamt = ($actperc * $netamt) / 100;
                $minus_comm = $commamt * -1;

                // purchase part
                mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount)
                    VALUES ('$vouchdt','$mvouch', '$bsource', '001', '$salecode','005', '$minus_comm')");
                // party part
                mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount)
                     VALUES ( '$vouchdt','$mvouch', '$bsource', '002', '$broker','$pgrp', '$commamt')");
                // round off part
            }
        }


//        browse($totalamount);
//        browse($netamt);
        if ($netamt > 0) {
            $minusamt = $netamt * -1;
            // purchase part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount)
                    VALUES ('$vouchdt','$mvouch', '$source', '001', '$salecode','005', '$netamt')");
            // party part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount)
                     VALUES ( '$vouchdt','$mvouch', '$source', '002', '$broker','$pgrp', '$minusamt')");
            // round off part
        }



        //        ############################## MAIN ######################################################
        if ($addflag == 1) {
            mysqli_query($conn, "INSERT INTO `$maindb`(`vouchno`, `invno`, `invdt`, `vouchdt`, `party`, `broker`, `cashcred`,
                                               `subtotal`, `cdiscperc`, `cdiscamt`, `cashvouch`, vatamt, packing,
                                               `discperc`, `discount`, `netamt`, `cashamt`,`ccamt`,`credamt`, `lesother`, 
                                               `remark1`, `remark2`,dcperc,
                                               `bankname`, `oms`, `cgstperc`, `sgstperc`, `igstperc`, 
                                               `totcgst`, `totsgst`, `totigst`, `tottaxamt`,`gstperc`,`cgst5`,
                                               `sgst5`,`igst5`,`cgst12`, `sgst12`,`igst12`,`cgst18`,`sgst18`,
                                               `igst18`,`cgst28`, `sgst28`,`igst28`,`totgst5`,`totgst12`,
                                               `totgst18`,`totgst28`,`totalamount`, `packgtamt`,`packgtperc`,`roundoff`) 
                                      VALUES ('$qvouch', '$invno', '$invdt', '$vouchdt', '$party', '$broker', '$paidby', 
                                              '$subtotal', '$cdiscperc', '$cdiscamt',  '$mcashvouch', '$vatamt', '$packing',
                                              '$discperc', '$discount', '$netamt', '$cashamt','$ccamt','$credamt', '$lesother', 
                                              '$remark1', '$remark2', '$agentcc',
                                              '$bankname', '$oms', '$cgstperc', '$sgstperc', '$igstperc',
                                              '$totcgst', '$totsgst', '$totigst', '$taxamt','$gstperc','$cgst5',
                                              '$sgst5','$igst5', '$cgst12','$sgst12','$igst12', '$cgst18', '$sgst18',
                                              '$igst18','$cgst28', '$sgst28','$igst28','$totgst5','$totgst12',
                                              '$totgst18','$totgst28','$totalamount','$packgtamt','$packgtperc','$roundoff')") or die(mysqli_error($conn));

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

            mysqli_query($conn, "UPDATE `$maindb` SET `invno`='$invno',`invdt`='$invdt',`vouchdt`='$vouchdt',
                                              `party`='$party', `broker`='$broker', `cashcred`='$paidby',
                                              `subtotal`='$subtotal',`cdiscperc`='$cdiscperc',`cdiscamt`='$cdiscamt',
                                              `discperc`='$discperc',`discount`='$discount',`netamt`='$netamt',
                                              `credamt`='$credamt',`ccamt`='$ccamt',`cashamt`='$cashamt', 
                                              `lesother`='$lesother',`remark1`='$remark1',`remark2`='$remark2',
                                              `bankname`='$bankname', `cashvouch`='$mcashvouch',dcperc='$agentcc',
                                              `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',`cgst28`='$cgst28', 
                                              `sgst28`='$sgst28',`igst28`='$igst28', `totalamount`='$totalamount',
                                              `roundoff`='$roundoff',`totgst5`='$totgst5',`totgst12`='$totgst12',
                                              `totgst18`='$totgst18',`totgst28`='$totgst28', vatamt='$vatamt',
                                              `packgtamt`='$packgtamt',`packgtperc`='$packgtperc', packing='$packing' WHERE `vouchno`='$qvouch'") or die(mysqli_error($conn));
        }
    }
}

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);
    $delcsh = $get['cashvouch'];
    $delbnk = $get['bankvouch'];
    $delpurcono = $get['purcono'];
    $delpurvch = $get['purvouch'];

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

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


//    $getbank = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode` = '$get[bankname]'");
//    $banknm = mysqli_fetch_array($getbank);
//    $getgst = mysqli_query($conn, "SELECT * FROM `saletype` WHERE code='$get[gstperc]'") or die(mysqli_error($conn));
//    $fetgst = mysqli_fetch_array($getgst);
}
if (isset($_GET["delete"])) {
    delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
    delete($zdb, "$trandb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
    $delcond = " source = '$source' and vouchno = '$_GET[vouchno]' ";
    $delcond2 = " source = '$source' and vouchno = '$_GET[vouchno]' and `compcode` = '$compcd' ";
    $delcond1 = " source = 'CP' and vouchno = '$delcsh' ";
    $delcond3 = " source = 'PU' and vouchno =  '$_GET[vouchno]' and `compcode` = '$compcd'";
    $delcondbr = " source = 'SLFB' and vouchno = '$_GET[vouchno]' ";


    delnew($zdb, "$stkdb", "$delcond", "$file?mode=last");
    delnew($zdb, "$accdb", "$delcond", "$file?mode=last");
    delnew($zdb, "$accdb", "$delcond1", "$file?mode=last");
    delnew($zdb, "$accdb", "$delcondbr", "$file?mode=last");
    delete($zdb, "cashpay", "$keyfld", $delcsh, "$file?mode=last");
}
include("includes/linkshead.php");
?>
<script src="MyScript/shortkeys.js" type="text/javascript"></script>
<script src="MyScript/sale.js?A=<?= mt_rand(); ?>" type="text/javascript"></script>
</head>

<body>
    <form action='' method='POST'>
        <input type="hidden" class="logdate" name="logdate" value="<?php echo ($addflag != 1) ? $get["logdate"] : ""; ?>" readonly style="">


        <!-- 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">
                        <h3 class="panel-title" style="color:#78909C"><a class="myPrint"><?php echo $formname; ?></a></h3>
                        <div class="actions pull-right">
                            <i class="fa fa-chevron-down"></i>
                            <i class="fa fa-times"></i>
                        </div>
                    </div>
                    <div class="panel-body">
                        <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">Voucher</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form vouchno" name="vouchno" value="<?php echo ($addflag != 1) ? $get["vouchno"] : " $qvouch"; ?>" readonly required>
                                <input type="hidden" class="form-control form" name="cashvouch" value="<?php echo ($addflag != 1) ? $get["cashvouch"] : ""; ?>" readonly>
                                <input type="hidden" class="form-control form agentcc" name="agentcc" value="<?php echo ($addflag != 1) ? $get["dcperc"] : ""; ?>" readonly>
                                <input type="hidden" class="form-control form par" value="S" readonly>
                                <input type="hidden" class="form-control form source" value="<?= $source ?>" readonly>

                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Date</label>
                            </div>
                            <div class="col-lg-1 col-md-2 col-sm-8 col-xs-8 pad">
                                <input type="date" class="form-control form focusfield" name="vouchdt" value="<?php echo ($addflag != 1) ? $get["vouchdt"] : date("Y-m-d"); ?>" autofocus required>
                            </div>

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

                            <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Invoice Date</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-8 col-xs-8 pad">
                                <input type="date" class="form-control form invdt" name="invdt" value="<?php echo ($addflag != 1) ? $get["invdt"] : date("Y-m-d"); ?>">
                            </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['cashcred'] == 'R') {
                                        echo "selected='selected'";
                                    }
                                    ?> value="R">Credit</option>
                                    <option <?php
                                    if ($get['cashcred'] == 'C') {
                                        echo "selected='selected'";
                                    }
                                    ?> value="C">Cash</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">Buyer<span style="font-size: 10px;">(Bill To)</span></label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-8 col-xs-8 pad">
                                <select class="form-control form  select2 broker" name="broker" style="width: 100%" required>
                                    <option value="<?php echo ($addflag != 1) ? $get["broker"] : ""; ?>"><?php echo ($addflag != 1) ? $lbroker["name"] : ""; ?></option>
                                    <?php
                                    $gbrk = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE (`grpcode`='010' OR `grpcode`='006')  ORDER by name") or die(mysqli_error($conn));
                                    while ($pbrk = mysqli_fetch_array($gbrk)) {
                                        echo "<option value='$pbrk[accode]'>$pbrk[name]</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">Consignee <span style="font-size: 10px;">(Ship To)</span></label>
                            </div>
                            <div class="col-lg-3 col-md-4 col-sm-8 col-xs-8 pad">
                                <select class="form-control form  select2" name="party" style="width: 100%" required>
                                    <option value="<?php echo ($addflag != 1) ? $get["party"] : ""; ?>"><?php echo ($addflag != 1) ? $lparty["name"] : ""; ?></option>
                                    <?php
                                    $gparty = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `grpcode`='010' and brokflag != '1' 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-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">
                                                        </div>-->
                        </div>


                        <div class="table-responsive">
                            <table class="table table-striped table-condensed table-bordered tab" width="100%">


                                <thead class="mySearchTr">
                                    <tr>
                                        <th style='width: 1%'></th>
                                        <th style='width: 3%' class='text-right'>Sr.</th>
                                        <!--<th style='width: 4%' class='text-left'>Barcode</th>-->
                                        <th style='width: 25%'>Item</th>
                                        <th style='width: 10%'>Size</th> 
                                        <!--<th style='width: 5%'>Hsn Code</th>-->
                                        <th style='width: 5%' class='text-right'>Qty.</th>
                                        <!--<th style='width: 4%'>Unit</th>-->
                                        <!--<th style='width: 4%' class='text-right'>Mrp</th>-->
                                        <th style='width: 5%' class='text-right'>Rate</th>
                                        <!--<th style='width: 4%' class="text-right">Rate Disc.</th>-->
                                        <!--<th style='width: 4%' class="text-right">Act. Rate</th>-->
                                        <th style='width: 6%' class='text-right'>Amount</th>
<!--                                        <th style='width: 3%' class="text-right">Disc. %</th>
                                        <th style='width: 5%' class="text-right">Disc. Amt.</th>-->
                                        <!--<th style='width: 6%' class="text-right">Taxable value</th>-->
                                        <!-- <th style='width: 4%' class="text-right">CGST Rate</th>
                                        <th style='width: 5%' class="text-right">CGST Amt.</th>
                                        <th style='width: 4%' class="text-right">SGST Rate</th>
                                        <th style='width: 5%' class="text-right">SGST Amt.</th>
                                        <th style='width: 4%' class="text-right">IGST Rate</th>
                                        <th style='width: 5%' class="text-right">IGST Amt.</th> -->
                                        <!--<th style='width: 8%' class="text-right">Total</th>-->
                                    </tr>
                                </thead>
                                <tbody class="tbody" id="saledtltab">
                                    <?php
                                    if ($addflag != 1) {
                                        $ctr = 0;
                                        $gettran = mysqli_query($conn, "SELECT a.*,b.name FROM `$trandb` a, item b WHERE a.`vouchno`='$get[vouchno]' and a.item=b.code ORDER BY a.`srno`") or die(mysqli_error($conn));
                                        while ($tran = mysqli_fetch_array($gettran)) {
//                                            $finditem = mysqli_query($conn, "SELECT `code`,`name` FROM `item` WHERE `code`='$tran[item]'") or die(mysqli_error($conn));
//                                            $fitem = mysqli_fetch_array($finditem);

                                            echo "<tr>";
                                            echo "<td><i class='fa fa-close remove' style='display:none;'></i></td>";
                                            echo "<td><input type='text' class='form-control form text-right srno' name='srno_$ctr' value='$tran[srno]'>
                                                      <input type='hidden' class='form-control form text-right purvouch' name='purvouch_$sctr' value='$fetquery[purvouch]'>
                                                      <input type='hidden' class='form-control form text-right pursrno' name='pursrno_$sctr' value='$fetquery[pursrno]'></td>";
                                            echo "<td>";
                                            echo "<select class='form-control form item select2' name='item_$ctr' style='width:100%'>";
                                            echo "<option value='$tran[item]'>$tran[name]</option>";
                                            $gitem = mysqli_query($conn, "SELECT `code`,`name` FROM `item` 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 "<input type='hidden' class='msp' name='msp_$ctr' value='$tran[msp]' >";
                                            echo "<input type='hidden' class='otprowsucs' name='otprowsucs_$ctr' value='$tran[otprowsucs]' >";
                                            echo "</td>";
                                            echo "<td>";
                                            echo "<select class='form-control form size select2' name='size_$ctr' style='width:100%'>";
                                            echo "<option value='$tran[size]'>$tran[size]</option>";
                                            $gcolor = mysqli_query($conn, "SELECT `size` FROM `prodsize` where code ='$tran[itemcode]' order by size") or die(mysqli_error($conn));
                                            while ($color = mysqli_fetch_array($gcolor)) {
                                                echo "<option value='$color[size]'>$color[size]</option>";
                                            }
                                            echo "</select>";
                                            echo "</td>";
//                                            echo "<td><input type='text' class='form-control form hsncode'                name='hsncode_$ctr'       value='$tran[hsncode]' tabindex='-1'></td>";
                                            echo "<td><input type='text' class='form-control form text-right trqty qty'      name='qty_$ctr'      value='$tran[qty]'></td>";
                                            echo "<input type='hidden' class='msp' name='msp_$ctr' >";
                                            echo "<input type='hidden' class='otpvalue' id='otpvalue_$ctr' name='otpvalue_$ctr' value='$tran[otpvalue]'>";
                                            echo "</td>";

                                            echo "<td><input type='text' class='form-control form text-right rate'     name='rate_$ctr'     value='$tran[rate]' ></td>";
                                            echo "<td><input type='text' class='form-control form text-right amount'   name='amount_$ctr'   value='$tran[amount]' readonly>
                                            <input type='hidden' class='form-control form text-right stqty'   name='stqty_$ctr'   value='$tran[stqty]' readonly>
                                            <input type='hidden' class='form-control form text-right mspamount'   name='mspamount_$ctr'   value='$tran[mspamount]' readonly>
                                            <input type='hidden' name='discperc_$ctr' class='discperc form-control text-right  form'  value='$tran[discperc]' ></td>
                                            <input type='hidden' name='discamt_$ctr' class='discamt form-control text-right  form' tabindex='-1' value='$tran[discount]' readonly>
                                            <input type='hidden' name='subtot_$ctr' class='subtot form-control text-right  form' tabindex='-1' value='$tran[subtot]' readonly>
                                                      <input type='hidden' name='cgstrate_$ctr' class='cgstrate form-control text-right  form' tabindex='-1' value='$tran[cgstrate]' readonly>
                                                      <input type='hidden' name='cgstamt_$ctr' class='cgstamt form-control text-right  form' tabindex='-1' value='$tran[cgstamt]' readonly>
                                                      <input type='hidden' name='sgstrate_$ctr' class='sgstrate form-control text-right  form' tabindex='-1' value='$tran[sgstrate]' readonly>
                                                      <input type='hidden' name='sgstamt_$ctr' class='sgstamt form-control text-right  form' tabindex='-1' value='$tran[sgstamt]' readonly>
                                                      <input type='hidden' name='igstrate_$ctr' class='igstrate form-control text-right  form' tabindex='-1' value='$tran[igstrate]' readonly>
                                                      <input type='hidden' name='igstamt_$ctr' class='igstamt form-control text-right  form' tabindex='-1' value='$tran[igstamt]' readonly>
                                                      <input type='hidden' name='total_$ctr' class='total form-control text-right  form' tabindex='-1' value='$tran[total]' readonly></td>";
                                            echo "</tr >";
                                            $ctr++;
                                        }
                                    } else {
                                        $pctr = 0;
                                        ?>
                                        <tr>
                                            <td><i class="fa fa-close remove"></i></td>
                                            <td><input type="text" class="form-control form text-right srno" name="srno_0" value="1">
                                                <input type="hidden" class="form-control form text-right purvouch" name="purvouch_0" value="">
                                                <input type="hidden" class="form-control form text-right pursrno" name="pursrno_0" value="">
                                            </td>
                                            <!--<td><input type="text" class="form-control form barcode" name="barcode_0" name="barcode"></td>-->
                                            <td>
                                                <select class="form-control form item select2" name="item_0" style='width:100%' required>
                                                    <option value=""></option>
                                                    <?php
                                                    $gitem = mysqli_query($conn, "SELECT * FROM `item` order by name") or die(mysqli_error($conn));
                                                    while ($item = mysqli_fetch_array($gitem)) {
                                                        echo "<option value='$item[code]'>$item[name]</option>";
                                                    }
                                                    ?>
                                                </select>
                                                <input type='hidden' class='msp' name='msp_0'>
                                                <input type='hidden' class='otprowsucs' name='otprowsucs_0'>
                                                <input type='hidden' class='otpvalue' name='otpvalue_0'>
                                                <input type='hidden' class='stqty' name='stqty_0' value="0">
                                            </td>
                                            <td>
                                                <select class="form-control form size select2" name="size_0" style='width:100%' required>
                                                    <option value=""></option>
                                                    <?php
//                                                    $gcolor = mysqli_query($conn, "SELECT * FROM `prodsize` order by size") or die(mysqli_error($conn));
//                                                    while ($color = mysqli_fetch_array($gcolor)) {
//                                                        echo "<option value='$color[size]'>$color[size]</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" class="form-control form text-right trqty qty" name="qty_0" value=""></td>

                                            <td><input type="text" class="form-control form text-right rate" id="rate_<?= $pctr ?>" name="rate_0" value=""></td>
                                            <td><input type="text" class="form-control form text-right amount" name="amount_0" value="0" readonly>
                                                <input type="hidden" class="form-control form text-right mspamount" name="mspamount_0" value="0" readonly>

                                                <input type='hidden' name='discperc_0' class='discperc text-right form-control form ' value='0.00'>
                                                <input type='hidden' name='discamt_0' class='discamt text-right form-control form  ' value='0.00' tabindex='-1' readonly>
                                                <input type='hidden' name='subtot_0' class='subtot text-right form-control form  ' value='0.00' tabindex='-1' readonly>
                                                <input type='hidden' name='cgstrate_0' class='cgstrate text-right form-control form  ' value='0.00' tabindex='-1' readonly>
                                                <input type='hidden' name='cgstamt_0' class='cgstamt text-right form-control form  ' value='0.00' tabindex='-1' readonly>
                                                <input type='hidden' name='sgstrate_0' class='sgstrate text-right form-control form  ' value='0.00' tabindex='-1' readonly>
                                                <input type='hidden' name='sgstamt_0' class='sgstamt text-right form-control form  ' value='0.00' tabindex='-1' readonly>
                                                <input type='hidden' name='igstrate_0' class='igstrate text-right form-control form  ' value='0.00' tabindex='-1' readonly>
                                                <input type='hidden' name='igstamt_0' class='igstamt text-right form-control form  ' value='0.00' tabindex='-1' readonly>
                                                <input type='hidden' name='total_0' class='total text-right form-control form  ' value='0.00' tabindex='-1' readonly></td>
                                        </tr>
                                        <?
                                        $pctr++;
                                    }
                                    ?>
                                <input type="hidden" id="items" name="items" value="<?php echo ($addflag != 1) ? $ctr : 1; ?>" />

                                </tbody>
                            </table>
                        </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">
                                    <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>
                                    <!--                                    <div class="col-lg-3 pad text-right">
                                                                            <label class="label-control marg">Salesman</label>
                                                                        </div>
                                                                        <div class="col-lg-6 pad">
                                                                            <select class="form-control form  select2" name="salesman" style="width: 100%">
                                                                                <option value="<?php // Echo ($addflag != 1) ? $get["salesman"] : "";                                              
                                    ?>"><?php // Echo ($addflag != 1) ? $lsalem["name"] : "";                                              
                                    ?></option>
                                    <?php
                                    //                                            $gsales = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `grpcode`='040'")or die(mysqli_error($conn));
                                    //                                            while ($sales = mysqli_fetch_array($gsales)) {
                                    //                                                Echo "<option value='$sales[accode]'>$sales[name]</option>";
                                    //                                            }
                                    ?>
                                                                            </select>
                                                                        </div>-->
                                </div>
                                <!--                                <div class="col-lg-12 col-xs-12 pad">
                                                                    <div class="col-lg-3 pad text-right">
                                                                        <label class="label-control marg">Driver</label>
                                                                    </div>
                                                                    <div class="col-lg-6 pad">
                                                                        <select class="form-control form driver select2" name="driver" style="width: 100%">
                                                                            <option value="<?php // Echo ($addflag != 1) ? $get["driver"] : "";                       
                                    ?>"><?php // Echo ($addflag != 1) ? $ldriver["name"] : "";                       
                                    ?></option>
                                                                            <option value=""></option>
                                <?php
                                //                                            $gdriver = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` where grpcode = '028' ORDER BY `name`")or die(mysqli_error($conn));
                                //                                            while ($driver = mysqli_fetch_array($gdriver)) {
                                //                                                Echo "<option value='$driver[code]'>$driver[name]</option>";
                                //                                            }
                                ?>
                                                                        </select>
                                                                    </div>
                                                                </div>-->

                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="row" style="visibility:hidden">
                                        <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%" class='text-right'>Total</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody class="">
                                                        <?php
                                                        if ($addflag != 1) {

                                                            echo "<tr>";
                                                            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 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 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 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 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 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 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 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-1 pad text-right">
                                        <label class="label-control marg">Remarks</label>
                                    </div>
                                    <div class="col-lg-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-1 pad text-right"></div>
                                    <div class="col-lg-9 pad">
                                        <input type="text" name="remark2" class="form-control form remark2" value="<? echo ($addflag != 1) ? $get["remark2"] : ""; ?>">
                                    </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="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-4 pad text-right">
                                        <label class="label-control marg">Less Discount</label>
                                    </div>
                                    <div class="col-lg-1 pad">
                                        <input type="text" class="form-control form cdiscperc text-right" value="<? echo ($addflag != 1) ? $get['discperc'] : "0"; ?>" name="discperc">
                                    </div>    
                                    <div class="col-lg-1 text-center pad">
                                        <label class="label-control marg">%</label>

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

                                    </div>
                                    <div class="col-lg-3 col-md-3 pad">
                                        <input type="text" class="form-control form packing numeric" value="<? echo ($addflag != 1) ? $get['packing'] : "0"; ?>" name="packing" >
                                    </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 pad text-right">
                                        <label class="label-control marg">Add GT Amount</label>

                                    </div>
                                    <div class="col-lg-3 col-md-3 pad">
                                        <input type="hidden" class="form-control form taxamt numeric" value="<? echo ($addflag != 1) ? $get['tottaxamt'] : "0"; ?>" name="taxamt" readonly>
                                        <input type="text" class="form-control form vatamt numeric" value="<? echo ($addflag != 1) ? $get['vatamt'] : "0"; ?>" name="vatamt" >
                                    </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">GST On Packing</label>
                                    </div>
                                    <div class="col-lg-2 pad">
                                        <input type="text" class="form-control form packgtperc text-right" value="<? Echo ($addflag != 1) ? $get['packgtperc'] : "5"; ?> "  name="packgtperc">
                                    </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 packgtamt text-right" value="<? Echo ($addflag != 1) ? $get['packgtamt'] : "0"; ?>" name="packgtamt" 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 pad text-right">
                                        <label class="label-control marg">Total Amount</label>

                                    </div>
                                    <div class="col-lg-3 col-md-3 pad">
                                        <input type="text" class="form-control form totalamount 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 pad text-right">
                                        <label class="label-control marg">Round Off</label>
                                    </div>
                                    <div class="col-lg-3 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-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">Netamt (Rs.)</label>
                                    </div>
                                    <div class="col-lg-3 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"></div>
                                                                    <div class="col-lg-3 pad"></div>
                                                                    <div class="col-lg-3 pad text-right" style="border : 1px solid black;padding-right: 10%">
                                                                        <label class="label-control marg">Cash</label>
                                                                    </div>
                                                                    <div class="col-lg-3 pad" style="border : 1px solid black;border-left: none">
                                                                        <input type="text" class="form-control form cashamt text-right" value="<? echo ($addflag != 1) ? $get[cashamt] : "0"; ?>" name="cashamt">
                                                                    </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-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                                                        <label class="label-control marg">Bank Name</label>
                                                                    </div>
                                                                    <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad">
                                                                        <select class="form-control form select2" id="bankname" name="bankname" style='width:100%'>
                                                                            <option value="<?php echo ($addflag != 1) ? $banknm[accode] : " "; ?>"><?php echo ($addflag != 1) ? $banknm[name] : " "; ?></option>
                                <?php
                                $mown = mysqli_query($conn, "SELECT * FROM `accmast` where `grpcode` = '001' ") or die(mysqli_error($conn));
                                while ($trow = mysqli_fetch_array($mown)) {
                                    echo "<option value=$trow[accode]>$trow[name]</option>";
                                }
                                ?>
                                                                        </select>
                                                                    </div>
                                                                    <div class="col-lg-3 pad text-right" style="border : 1px solid black;padding-right: 10%">
                                                                        <label class="label-control marg">CC</label>
                                                                    </div>
                                                                    <div class="col-lg-3 pad" style="border : 1px solid black;border-left: none">
                                                                        <input type="text" class="form-control form ccamt text-right" value="<? echo ($addflag != 1) ? $get[ccamt] : "0"; ?>" name="ccamt">
                                                                    </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" style="border : 1px solid black;padding-right: 10%">
                                                                        <label class="label-control marg">Credit</label>
                                                                    </div>
                                                                    <div class="col-lg-3 pad" style="border : 1px solid black;border-left: none">
                                                                        <input type="text" class="form-control form credamt text-right" value="<? echo ($addflag != 1) ? $get[credamt] : "0"; ?>" name="credamt">
                                                                    </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 pad text-right">
                                                                    </div>
                                                                    <div class="col-lg-2 pad text-right">
                                                                    </div>
                                                                    <div class="col-lg-1 pad text-left">
                                                                    </div>
                                                                    <div class="col-lg-2 pad">
                                                                    </div>
                                                                    <div class="col-lg-1 pad">
                                                                    </div>
                                                                    <div class="col-lg-3 pad">
                                                                        <input type="button" id="finishTab" class="btn btn-primary pull-right form mySearchTr" style="color: #fff;" value="Check & Finish">
                                                                    </div>
                                                                </div>-->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="col-lg-1">
                    </div>
                    <div class="col-lg-9 col-md-9 col-sm-11 col-xs-11 text-center pad">
                        <?php include("includes/buttons.php"); ?>
                    </div>
                    <div class="col-lg-1 pad">
                        <input type="button" id="finishTab" class="btn btn-primary pull-right form mySearchTr" style="color: #fff;" value="Check & Finish">
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<div class="modal fade bs-example-modal-lg" 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">
                <div class="">
                    <table id="example1" class="table table-striped">
                        <thead>
                            <tr class="mySearchTr">
                                <th style="text-align:center">Voucher</th>
                                <th style="text-align:center">Invoice</th>
                                <th style="text-align:center">Date</th>
                                <th style="text-align:center">Party</th>
                                <th style="text-align:center">Type</th>
                                <!--<th style="text-align:center">Prod. Type</th>-->
                                <th style="text-align:center">Discount</th>
                                <th style="text-align:center">Net Amount</th>
                                <th style="text-align:center">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            if ($addflag != 1) {
                                $csh = 0;
                                $cred = 0;
                                $cc = 0;

                                $srchresult = mysqli_query($conn, "SELECT *,date_format(vouchdt,'%d-%m-%Y') as mydt FROM `$maindb`  ORDER BY `vouchdt` DESC") or die(mysqli_error($conn));
                                while ($row = mysqli_fetch_array($srchresult)) {
                                    $getsparty = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`='$row[party]'") or die(mysqli_error($conn));
                                    $sparty = mysqli_fetch_array($getsparty);
                                    $newtype = 'Credit';
                                    if ($row['cashcred'] != 'R') {
                                        $newtype = 'Cash';
                                    }



                                    $discount = $row[cdiscamt] + $row[lesother];
                                    echo "<tr class='clickable-row' data-href='$file?mode=edit&$keyfld=$row[$keyfld]'>";
                                    echo "<td align='center'>$row[vouchno]</td>";
                                    echo "<td align='center'>$row[invno]</td>";
                                    echo "<td align='center'>$row[mydt]</td>";
                                    echo "<td align='center'>$sparty[name]</td>";
                                    echo "<td align='center'>$newtype</td>";
//                                    echo "<td align='center'>$row[prodtype]</td>";
                                    echo "<td align='center'>$row[discount]</td>";
                                    echo "<td align='center'>$row[netamt]</td>";
                                    echo "<td align='center'><a href=\"$file?mode=edit&$keyfld=$row[$keyfld]\"><i class='fa fa-pencil' style='font-size:1.3em;color:#00C0EF;cursor:pointer;'></i></a></td>";
                                    echo "</tr>";
                                }
                            }
                            ?> 
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="modal-footer"></div>
        </div>
    </div>
</div>
<?php include("includes/linksfoot.php"); ?>
</body>

</html>