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

$formname = 'Sale GST';
$maindb = 'gstmain';
$trandb = 'gsttran';
$accdb = '';
$stkdb = '';

$file = 'salegst.php';
$grid = '';
$keyfld = "vouchno";
$trandbexist = 1;
$focusfld = "party";
$printfile = 'salegst_prin.php';
$source = "SL";
//$append_file = 'sale_add.php';

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

$gen1 = mysqli_query($conn, "SELECT MAX(billno) AS maxbill FROM `$maindb`  LIMIT 0,1 ") or die(mysqli_error($conn));

if (mysqli_num_rows($gen1) > 0) {
    $vbill = mysqli_fetch_assoc($gen1);
    $qbill = $vbill["maxbill"] + 1;
} else {
    $qbill = '1';
}

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

    $a = 1;
    $party = trim($_POST["cmbparty"]);
    $godown = trim($_POST["cmbgodown"]);
    $billdate = trim($_POST["vouchdt"]);
    $type = trim($_POST["type"]);
    $billtype = trim($_POST["billtype"]);
    $billno = trim($_POST["invno"]);
    $billdt = trim($_POST["invdt"]);
    $cashcred = trim($_POST["cashcred"]);
    $subtotal = trim($_POST["subtotal"]);
    $vatperc = trim($_POST["vatperc"]);
    $vat = trim($_POST["vat"]);
    $chkstock = trim($_POST["chkstock"]);
    $chkledg = trim($_POST["chkledg"]);
    $discperc = trim($_POST["discperc"]);
    $discount = trim($_POST["discamt"]);
    $billamt = trim($_POST["netamt"]);
    $packing = trim($_POST["packing"]);
    $advance = trim($_POST["advance"]);
    $balance = trim($_POST["balance"]);
    $saletype = trim($_POST["saletype"]);
    $nobox = trim($_POST["nobox"]);
    $tottaxable = trim($_POST["tottaxable"]);
    $subqty = trim($_POST["subqty"]);
    $paydate = trim($_POST["paydate"]);

    $oms = $_POST["oms"];
    $taxamt = $_POST["taxamt"];
    $totcgst = $_POST["cgstamt"];
    $totsgst = $_POST["sgstamt"];
    $totigst = $_POST["igstamt"];
    $sgstperc = $_POST["sgstperc"];
    $cgstperc = $_POST["cgstperc"];
    $igstperc = $_POST["igstperc"];


    $rem1 = trim($_POST["rem1"]);
    $rem2 = trim($_POST["rem2"]);
    $cutperc = $_POST["cutperc"];
    $gsttype = $_POST["gsttype"];
    $autovouch = $_POST["autovouch"];
    $count = $_POST["items"];
    $mvouch = $qvouch;

    $salecode = '';
    if ($type == 1) {
        $salecode = 14;
    } else {
        $salecode = 15;
    }

    if ($a == 1) {



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

        $cnt = 0;
        $cntamt = 0;

        for ($i = 0; $i < $count; $i++) {
            $msrno = $_POST["srno_$i"];
            $mitem = $_POST["item_$i"];
//            $barcode = $_POST["barcode_$i"];
            $descrip = $_POST["descrip_$i"];
            $mhsncode = $_POST["hsncode_$i"];
            $qty = $_POST["qty_$i"];
            $rate = $_POST["rate_$i"];
            $sell = $_POST["selling_$i"];
            $mrp = $_POST["mrp_$i"];
            $amt = $_POST["amt_$i"];
            $mdiscperc = $_POST["discperc_$i"];
            $mdiscamt = $_POST["discamt_$i"];
            $vatperc = $_POST["vatperc_$i"];
            $vatamt = $_POST["vatamt_$i"];
            $final = $_POST["final_$i"];
            $taxval = $_POST["taxval_$i"];

            if (!empty($mitem)) {
                $mitemcode = mysqli_query($conn, "SELECT code FROM `item` WHERE name='$mitem'") or die(mysqli_error($conn));
                $icode = mysqli_fetch_array($mitemcode);
//                browse('1');
                mysqli_query($conn, "INSERT INTO `$trandb`(vouchno, vouchdt, srno, itemcode, `barcode`, qty, rate, mrp, amt, discperc, discamt, vatperc,
                                                    vatamt, totamt, `hsncode`,`taxval`,`descrip`)
                            VALUES('$mvouch', '$billdate', '$msrno', '$icode[code]', '$barcode', '$qty', '$rate', '$mrp', '$amt', '$mdiscperc', '$mdiscamt',  
                                    '$vatperc', '$vatamt', '$final','$mhsncode','$taxval','$descrip')") or die(mysqli_error($conn));
            }
        }

        if ($addflag == 1) {
            mysqli_query($conn, "INSERT INTO `$maindb`(vouchno, `vouchdt`, `accode`, godown, `type`, `billtype`, `billno`, `billdt` ,`cutperc`, `gsttype`, `autovouch`,
                                                    `cashcred`, subtotal, subqty, discount, discperc, vat,  billamt, `rem1`, `rem2`, `nobox`, `packing`, `tottaxable`,
                                                    `oms`, `cgstperc`, `sgstperc`, `igstperc`,  `totcgst`, `totsgst`, `totigst`, `tottaxamt`, `paydate`)
                                          VALUES('$mvouch', '$billdate', '$party', '$godown', '$type', '$billtype', '$billno', '$billdt', '$cutperc', '$gsttype', '$autovouch',
                                              '$cashcred', '$subtotal', '$subqty', '$discount', '$discperc', '$vat', '$billamt', '$rem1', '$rem2',  '$nobox', '$packing', '$tottaxable',
                                               '$oms', '$cgstperc', '$sgstperc', '$igstperc', '$totcgst', '$totsgst', '$totigst', '$taxamt', '$paydate')") or die(mysqli_error($conn));
//            insmess();
//            $mvouch = $qvouch;
//            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
        } else {
            $mvouch = $qvouch;
            mysqli_query($conn, "UPDATE `$maindb` SET `accode`='$party', `type`='$type', `billtype`='$billtype',`billno`='$billno', `vouchdt`='$billdate', `billdt`='$billdt', 
                        godown='$godown', cashcred='$cashcred', subtotal='$subtotal', subqty='$subqty', discount='$discount', discperc='$discperc',
                        billamt='$billamt', `rem1`='$rem1', `rem2`='$rem2',  `nobox`='$nobox', `packing`='$packing', `tottaxable`='$tottaxable',
                        `oms`='$oms',`cgstperc`='$cgstperc', `cutperc`='$cutperc', `gsttype`='$gsttype', `autovouch`='$autovouch',
                        `sgstperc`='$sgstperc', `igstperc`='$igstperc', `totcgst`='$totcgst', `totsgst`='$totsgst', 
                        `totigst`='$totigst', `tottaxamt`='$taxamt', `paydate` ='$paydate' WHERE vouchno = '$mvouch' ") or die(mysqli_error($conn));
//            updmess();
//            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
        }
    }
    if ($addflag == 1) {
        insmess();
        header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
    } else {
        updmess();
        header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
    }
}

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


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

    $getpaccode = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`= '$get[accode]'") or die(mysqli_error($conn));
    $getp = mysqli_fetch_array($getpaccode);

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

    $getgstype = mysqli_query($conn, "SELECT * FROM `gsttype` WHERE `code`= '$get[gsttype]'") or die(mysqli_error($conn));
    $fetgst = mysqli_fetch_array($getgstype);


    if ($get['billtype'] == 'RT') {
        $biltype = 'RTGS';
    } elseif ($get['billtype'] == 'CR') {
        $biltype = 'CREDIT';
    } elseif ($get['billtype'] == 'CH') {
        $biltype = 'CASH';
    } elseif ($get['billtype'] == 'NF') {
        $biltype = 'NEFT';
    } elseif ($get['billtype'] == 'CQ') {
        $biltype = 'CHEQUE';
    }
}


/* DELETE */
if (isset($_GET["delete"])) {
    delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
    delete($zdb, "$trandb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
}
include("includes/files.php");
include("includes/combo2.php");
?>
<script src="MyScript/checkdate.js" type="text/javascript"></script>


<script type="text/javascript">
    $(document).ready(function () {
        $("body").on("keyup blur change", '.qty, .rate, .discperc,.oms', calculateRow);
        $("body").on("keyup blur change", '.subtotal, .discperc, .packing, .oms', calculat);
        $("#main_container").on("click", '.remove', remove);
        $('body').on('change blur ', '.item', showdtl);
        $('#data').on('blur', '.mrp', addrow2);
        $('#data').on('keyup change blur', '.qty,.autovouch', totqty);
        $('#data').on('keyup focus', '.taxval,.qty,.rate,.oms', calculateTot);
        $('body').on('change click', '.gsttype, .oms', getGST);
        $('body').on('blur', '.autovouch', getSaleDtl);
        $('body').on('blur', '.autovouch', getSaleMain);

        $('.cutperc').keyup(function () {
            var cutperc = $('.cutperc').val();
            if (parseFloat(cutperc) > 100) {
                alert('Percent Cannot be greater than 100');
                $('.cutperc').val('');
                $('.cutperc').focus();
            }
        });

        function getSaleMain() {
            var autovouch = $(".autovouch").val();
            var addflg = $(".addflg").val();
            if (addflg == "1") {
                if (autovouch != 0 || autovouch != '') {
                    $.post('getSaleMain.php', {autovouch: autovouch}, function (data) {
                        $(".party").html(data).trigger('change');
                    });
                }
            }
//            $('.taxval').focus();
            totqty();
            calculateRow();
            calculateTot();
            calculat();

        }

        function getSaleDtl() {
            var autovouch = $(".autovouch").val();
            var addflg = $(".addflg").val();
            var cutperc = $(".cutperc").val();
            if (addflg == "1") {
                if (autovouch != 0 || autovouch != '') {
                    $.post('getSaleDtl.php', {autovouch: autovouch, cutperc: cutperc}, function (data) {
                        $(".tbody").html("");
                        $(data).appendTo('.tbody');
                    });
                    $(".taxval").focus();
                }
            }
            totqty();
            calculateRow();
            calculateTot();
            calculat();
        }

        function getGST() {
            var gsttype = $(".gsttype").val();
            var oms = $(".oms").val();
            $.ajax({
                type: 'GET',
                dataType: 'json',
                url: "get_Gstperc.php",
                data: {gsttype: gsttype},
                success: function (response) {
                    var gstperc = response.per;
                    var cgstperc = gstperc / 2;
                    if ($(".oms").prop('checked')) {
                        $('.igstperc').val(gstperc);
                        $('.cgstperc').val(0);
                        $('.sgstperc').val(0);
                    } else {
                        $('.igstperc').val(0);
                        $('.cgstperc').val(cgstperc);
                        $('.sgstperc').val(cgstperc);
                    }

                },
                error: function (request, textStatus, errorThrown) {
                    alert(errorThrown);
                }
            });
            calculateRow();
            calculateTot();
            calculat();

        }

//       search voucher auto 
        $("body").on("keyup", ".isearch", getSearchData);
        $("body").on("click", ".iload", getSearchData);
        $("body").on("click", "#newsearch", getSearchData);
        $("body").on("click", ".getitemdtl", fetchitem);

        function fetchitem() {
            var tr = $(this).closest('tr'),
                    itemcode = tr.find('.itemcode').val(),
                    itemname = tr.find('.itemname').val();

            $('.itemcode').val(itemcode);
            $('.itemname').val(itemcode).trigger("change");
            $(".searchModali").hide();
        }

        $(".inoRecord").hide();
        $(".iloader").hide();

        $(".searchModali").on('shown.bs.modal', function () {
            $(".isearch").focus();
            $(".isearch").val("");
            $(".sfield").val("1");
            getSearchData();
        });

        var imrangeFrom = 0,
                imrangeTo = 40;

        function getSearchData(pagination) {

            $(".iloader").show();

            if (pagination == 'prev') {
                if (imrangeFrom > 0) {
                    imrangeFrom = (imrangeFrom - 40);
                    imrangeTo = (imrangeTo - 40);
                }
            }
            if (pagination == 'next') {
                imrangeFrom = (imrangeFrom + 40);
                imrangeTo = (imrangeTo + 40);
            }

            var series = $(".series").val(),
                    vouchno = $(".vouchno").val(),
                    isearch = $(".isearch").val(),
                    ifield = $(".ifield").val(),
                    sortBy = $(".sortBy").val(),
                    orderAs = $(".orderAs").val(),
                    ioperator = $(".ioperator").val(),
                    data = {isearch: isearch, ifield: ifield, sortBy: sortBy, orderAs: orderAs, ioperator: ioperator,
                        series: series, vouchno: vouchno, rangeFrom: imrangeFrom, rangeTo: imrangeTo},
            values = "";
            $.ajax({
                type: 'GET',
                dataType: 'json',
                url: "slvouch_search.php",
                data: data,
                success: function (response) {
                    $.each(response, function () {
                        values += "<tr class='getitemdtl'>" +
//                                "<td align='left'><input type='text' class='form-control itemname' value='" + this.name + "' readonly>\n\
//                                                  <input type='hidden' class='form-control itemcode' value='" + this.code + "' readonly>                                                                                    </td>" +
                                "<td align='left'>" + this.vouchno + "</td>" +
                                "<td align='left'>" + this.vouchdt + "</td>" +
                                "<td align='left'>" + this.party + " </td>" +
                                "<td align='left'>" + this.billamt + "</td>" +
                                "</tr>";
                    });
                    $(".iloader").hide();
                    $(".iTbody").empty();
                    $(".iTbody").html(values);
                    if (response) {
                        $(".search-action-bar").show();
                    }
                },
                error: function (request, textStatus, errorThrown) {

                }
            });
        }
        $("#isearch").click(function () {
            getSearchData();
        });
        $(".iprevious").click(function () {
            getSearchData('prev');
        });
        $(".inext").click(function () {
            getSearchData('next');
        });
//end search voucher auto 


        //getting rate from item
        function showdtl() {
            var $row = $(this).closest("tr");
            var name = $row.find('.item').val();
            var cutperc = $(".cutperc").val();
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: "show_item_dtl.php",
                data: {name: name, cutperc: cutperc},
                success: function (response) {
                    var barcode = response.barcode;
                    var rate = response.rate;
                    var hsncode = response.hsncode;
                    $($row.find('.barcode')).val(barcode);
                    $($row.find('.rate')).val(rate);
                    $($row.find('.hsncode')).val(hsncode);
                },
                error: function (request, textStatus, errorThrown) {
                    alert(errorThrown);
                }
            });
        }

//for calculating Row values                
        function calculateRow() {
            var fintot = 0;

            var $row = $(this).closest("tr");
//            $row.find('.total').val("0");
//            $row.find('.amt').val("0");
//            $row.find('.discamt').val("0");
//            $row.find('.vatamt').val("0");
//            $row.find('.final').val("0");

            var qty = parseFloat($row.find('.qty').val());
            var rate = parseFloat($row.find('.rate').val());
            var mrp = parseFloat($row.find('.mrp').val());
//            var taxval = parseFloat($row.find('.taxval').val());
            var discperc = parseFloat($row.find('.discperc').val());
//            var discamt = parseFloat($row.find('.discamt').val());
//            var packamt = parseFloat($row.find('.packing').val());

            var totamt = qty * rate;
            $row.find('.amt').val(totamt);

            $row.find('.final').val(totamt);
            //            var final = parseFloat($row.find('.final').val());
            var mamt = $row.find('.amt').val();

            var discamt = mamt * discperc / 100;
            $row.find('.discamt').val(discamt);
            var tdisc = parseInt($row.find('.discamt').val());

            var taxval = mamt - discamt;
            $row.find('.taxval').val(totamt);

            var totdisc = mamt - tdisc;

            fintot = totamt;


            if (isNaN(fintot)) {
                $row.find('.taxval').val("0");
            } else {
                $row.find('.taxval').val(fintot);
                /*$row.find('.final').val(fintot.toFixed(2));-*/
            }
            calculateTot();
        }

        function calculateTot() {
            var amt = 0;
            var val = 0;
            var val1 = 0;
            var val2 = 0;
            var disc = 0;
            var vata = 0;
            /*********Total Part************/

            $(".taxval").each(function () {
                if (!isNaN(this.value) && this.value.length != 0) {
                    val += parseFloat(this.value);
                }
            });
            amt = parseFloat(val);

            $("#subtotal").val(amt.toFixed(2));

//            $(".discamt").each(function () {
//                if (!isNaN(this.value) && this.value.length != 0) {
//                    val1 += parseFloat(this.value);
//                }
//            });
//            disc = parseFloat(val1);

//            $("#discount").val(0);

            calculat();
        }

//        $("#packing").keyup(function () {
//            var value = parseFloat($("#netamt").val());
//            var value2 = parseFloat($("#packing").val());
//
//            if (value2 === 0) {
//                calculat();
//            } else {
//                var tot = value + value2;
//                $('#netamt').val(tot.toFixed(2));
//            }
//        });

        function calculat() {
            var mamt = parseFloat($("#subtotal").val());
            var discperc = $(".discperc").val(),
                    discamt = (discperc * mamt) / 100;
            var mpack = parseFloat($("#packing").val());
            var taxable = parseFloat(mamt) + parseFloat(mpack) - parseFloat(discamt);

            $(".tottaxable").val(taxable);

            var cgstperc = $(".cgstperc").val(),
                    cgstamt = (cgstperc * taxable) / 100,
                    sgstperc = $(".sgstperc").val(),
                    sgstamt = (sgstperc * taxable) / 100,
                    igstperc = $(".igstperc").val(),
                    igstamt = (igstperc * taxable) / 100;


//            $('#discount').removeAttr("readonly");



//                    var mnet = mamt - mdisc + mpack + cgstamt + sgstamt + igstamt;
            var mnet = taxable + cgstamt + sgstamt + igstamt;
            $('#netamt').val(mnet.toFixed(2));
            $(".cgstamt").val(cgstamt.toFixed(2));
            $(".sgstamt").val(sgstamt.toFixed(2));
            $(".igstamt").val(igstamt.toFixed(2));
            $(".taxamt").val(taxable.toFixed(2));
            $(".discamt").val(discamt.toFixed(2));

        }

        //        for deleting single row
        function remove() {
            $(this).closest("tr").remove();
        }

        /*Hidind delte part*/
        function show_hide_delete() {
            if ($("#del_all").prop("checked")) {
                $(".remove").hide();
            } else {
                $(".remove").show();
            }

        }

        $("#del_all").attr("checked", true);
        show_hide_delete();
        $("#del_all").click(function () {
            show_hide_delete();
        });

        //                for adding new rows
        function addrows() {
            var ctr = $('#items').val();
            var hide_check = "";
            if ($("#del_all").prop("checked")) {
                hide_check = 0;
            } else {
                hide_check = 1;
            }
            var detail = ".fetchpart_" + ctr;


            $.post('salegst_add.php', {ctr: ctr, hide: hide_check}, function (data) {
                $(data).appendTo('#data');
                ctr++;
                $('#items').val(ctr);
                $(detail).select2().trigger("change");


            });
        }

        $('#addnew').click(function () {
            addrows();
        });

        function addrow2() {
            if ($(this).closest("tr").is(":last-child")) {
                addrows();
            }
        }


        function totqty() {
            var val = 0;
            var amt = 0;
            $(".qty").each(function () {
                if (!isNaN(this.value) && this.value.length != 0) {
                    val += parseFloat(this.value);
                }
            });
            amt = parseFloat(val);
            $("#subqty").val(amt.toFixed(2));
        }

        $(".hidvouch").hide();


        $(document).keydown(function (e) {
            if (e.ctrlKey && (String.fromCharCode(e.which).toLowerCase() === 'm')) {
//                rajEvent = new Event('CTR+M');
//                document.dispatchEvent(rajEvent);
//                $('<input/>').attr({ type: 'text', id: 'test', name: 'test' }).appendTo('.newinput');
                $('.lperc').text('Percent');
                $('.lvouch').text('Sale Voucher');
                var newinput = "<label class = 'control-label col-sm-1 hidvouch'  style = 'width:135px;font-family: cipher-regular,helvetica;' >Percent</label>" +
                        "<div class = 'col-lg-1' >" +
                        "</div>" +
                        "<label class = 'control-label col-sm-1 hidvouch'  style = 'width:135px;font-family: cipher-regular,helvetica;' > Sale Voucher < /label>" +
                        "<div class = 'col-lg-1'>" +
                        +
                        "</div>";
                var cperc = "<input type = 'text' name = 'cutperc' id = 'cutperc' value = '<?php echo ($addflag != 1) ? $get['cutperc'] : ''; ?>' style = 'width:100px;text-align: right' class = 'cutperc hidvouch form-control form' >";
                var slvouch = "<input type = 'text' name = 'autovouch' id = 'autovouch' value = '<?php echo ($addflag != 1) ? $get['autovouch'] : ''; ?>' style = 'width:140px;' class = 'form-control form autovouch' >";
                $('.cperc').html(cperc);
                $('.slvouch').html(slvouch);
//                $('.newinput').html(newinput);
//            $(".hidvouch").show();
            }
        });
        $(document).keydown(function (e) {
            if (e.ctrlKey && (String.fromCharCode(e.which).toLowerCase() === 'q')) {
//                rajEvent = new Event('CTR+M');
//                document.dispatchEvent(rajEvent);
                $('.lperc').hide();
                $('.lvouch').hide();
                $('.cperc').hide();
                $('.slvouch').hide();
            }
        });


    });
</script>
</head> 
<body onLoad="" id="main_container">
    <form name="outraw" action="" method="POST">

        <div class="row" style="">
            <div class="col-lg-12" style=''>
                <div class="box dark">
                    <header style="border:1px solid #96B6F0">
                        <div class="icons"><i class="fa fa-edit"></i></div>
                        <h5 style="font-family: cipher-regular,helvetica; "><?= $formname ?></h5>
                        <!-- .toolbar -->
                        <div class="toolbar">
                            <ul class="nav">
                                <li>
                                    <a class="accordion-toggle minimize-box" data-toggle="collapse" href="#div-1">
                                        <i class="fa fa-chevron-up"></i>
                                    </a>
                                </li>
                            </ul>
                        </div>
                        <!-- /.toolbar --> 
                    </header>
                    <div id="div-1" class="accordion-body collapse in body" style="font-family: cipher-regular,helvetica;">
                        <div class="form-horizontal">
                            <div class="form-group">
                                <label class="control-label col-lg-1"  style="font-family: cipher-regular,helvetica;">Voucher</label>
                                <div class="col-lg-1">
                                    <input type="text" name="vouchno" id='vouchno' autofocus="" placeholder="" value="<?php echo ($addflag != 1) ? $get['vouchno'] : $qvouch; ?>" style="width:150px;" class="form-control form vouchno"  readonly>
                                    <input type="hidden" name="addflg" id='addflg' value="<?php echo ($addflag != 1) ? $addflag : $addflag; ?>" class="addflg form-control form "  >
                                </div>
                                <label class="control-label col-lg-1"  style="width:135px;font-family: cipher-regular,helvetica;">Date</label>
                                <div class="col-lg-2">
                                    <input type="date" name="vouchdt" id='vouchdt' placeholder="" value="<?php echo ($addflag != 1) ? $get['vouchdt'] : date("Y-m-d"); ?>" style="width:175px;" class="form-control form vouchdt" >
                                    <input type="date" value="<?= $zStartDate ?>" style="display: none" class="zstdate">
                                    <input type="date" value="<?= $zEndDate ?>" style="display: none" class="zenddate">
                                </div> 
                                <label class="control-label col-lg-1"  style="font-family: cipher-regular,helvetica;">Invoice No.</label>
                                <div class="col-lg-1">
                                    <input type="text" name="invno" id='invno' placeholder="" value="<?php echo ($addflag != 1) ? $get['billno'] : $qbill; ?>" style="width:150px;" class="form-control form" readonly>                                    
                                </div>
                                <label class="control-label col-lg-1 text-right"  style="text-align: right; padding-left: 50px;; padding-right: 0px; width:135px;font-family: cipher-regular,helvetica;">Payment Date</label>
                                <div class="col-lg-2">
                                    <input type="date" name="paydate" id='paydate' placeholder="" value="<?php echo ($addflag != 1) ? $get['paydate'] : date("Y-m-d"); ?>" style="width:175px;" class="form-control form paydate" >
                                </div>                                 
                                <label class='control-label col-sm-1 lperc'  style='width:135px;font-family: cipher-regular,helvetica;'></label>
                                <div class='col-lg-1 cperc'>
                                    <!--<input type='text' name='cutperc' id='cutperc ' value='<?php echo ($addflag != 1) ? $get['cutperc'] : ''; ?>' style='width:100px;text-align: right' class='cutperc hidvouch form-control form'>-->                                    
                                </div>
                                <label class='control-label col-sm-1 lvouch'  style='width:135px;font-family: cipher-regular,helvetica;'></label>
                                <div class="col-lg-1 slvouch">
                                    <!--<input type='text' name='autovouch' id='autovouch ' value='<?php echo ($addflag != 1) ? $get['autovouch'] : ''; ?>' style='width:140px;' class='form-control form autovouch hidvouch'>-->                                    
                                </div>
                                <div class="col-lg-4 newinput">

                                </div>

                                <!--                                <div class="col-lg-1" style="">
                                                                    <button id="newsearch" type="button" class="btn btn-pad btn-square form " style="height: 27px;padding-top: 3px;background-color:#809FD9;border-radius: 5px" data-toggle="modal" data-target=".bs-example-modal-lg">
                                                                        <i class="fa fa-search" style="color:#ffffff"></i>
                                                                    </button>
                                                                </div>-->
                            </div> 
                            <div class="form-group">
                                <label class="control-label col-lg-1"  style="font-family: cipher-regular,helvetica;">Party Name</label>
                                <div class="col-lg-3">
                                    <select id="party" name="cmbparty" class="form-control form party" style='height:33px;' required>
                                        <option value="<?php echo ($addflag != 1) ? $getp['accode'] : " "; ?>"><?php echo ($addflag != 1) ? $getp['name'] : " "; ?></option>
                                        <?php
                                        $mown = mysqli_query($conn, "SELECT accode, `name` FROM `accmast` WHERE grpcode='010' ORDER BY name") or die(mysqli_error($conn));
                                        while ($trow = mysqli_fetch_array($mown)) {
                                            echo "<option value=$trow[accode]>$trow[name]</option>";
                                        }
                                        ?>
                                    </select> 
                                </div>
                                <!--                                <label class="control-label col-sm-1"  style="width:134px;font-family: cipher-regular,helvetica;">Godown</label>
                                                                <div class="col-lg-1">
                                                                    <select id="godown" name="cmbgodown" class="form-control form" style='height:33px;'>
                                                                        <option value="<?php echo ($addflag != 1) ? $getgd['code'] : " "; ?>"><?php echo ($addflag != 1) ? $getgd['gdcode'] : " "; ?></option>
                                <?php
                                $mown1 = mysqli_query($conn, "SELECT code, `gdcode` FROM `godown` ORDER BY name") or die(mysqli_error($conn));
                                while ($trow1 = mysqli_fetch_array($mown1)) {
                                    echo "<option value=$trow1[code]>$trow1[gdcode]</option>";
                                }
                                ?>
                                                                    </select> 
                                                                </div>-->
                                <label class="control-label col-sm-1"  style="width:134px;font-family: cipher-regular,helvetica;">GST Type</label>
                                <div class="col-lg-1">
                                    <select id="gsttype" name="gsttype" class="form-control form gsttype" style='height:33px;width:150px;' required>
                                        <option value="<?php echo ($addflag != 1) ? $fetgst['code'] : " "; ?>"><?php echo ($addflag != 1) ? $fetgst['name'] : " "; ?></option>
                                        <?php
                                        $mown11 = mysqli_query($conn, "SELECT code, `name` FROM `gsttype` ORDER BY per") or die(mysqli_error($conn));
                                        while ($trow11 = mysqli_fetch_array($mown11)) {
                                            echo "<option value=$trow11[code]>$trow11[name]</option>";
                                        }
                                        ?>
                                    </select> 
                                </div>
                                <!--                                <label class="control-label col-lg-1"  style="width:135px;font-family: cipher-regular,helvetica;">Type</label>
                                                                <div class="col-lg-1">
                                                                    <select name='cashcred' id="cashcred"  class="form-control form" style='height:33px;width:150px;'>
                                                                        <option value='R'<?php
                                if ($addflag != 1) {
                                    if ($get["cashcred"] == "R") {
                                        echo "selected='selected'";
                                    }
                                }
                                ?> >CREDIT</option>
                                                                        <option value='C'<?php
                                if ($addflag != 1) {
                                    if ($get["cashcred"] == "C") {
                                        echo "selected='selected'";
                                    }
                                }
                                ?>>CASH</option>
                                                                    </select> 
                                                                </div>-->
                                <label class="control-label col-lg-1"  style="width:135px;font-family: cipher-regular,helvetica;">OFS</label>
                                <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>
                                <label class="control-label col-lg-1"  style="width:135px;font-family: cipher-regular,helvetica;">Bill Type</label>
                                <select id="billtype" name="billtype" class="form-control form billtype" style='height:33px;width:150px;' required>
                                    <option value="<?php echo ($addflag != 1) ? $get['billtype'] : " "; ?>"><?php echo ($addflag != 1) ? $biltype : " "; ?></option>
                                    <option value=''></option>
                                    <option value='RT'>RTGS</option>
                                    <option value='CR'>CREDIT</option>
                                    <option value='CH'>CASH</option>
                                    <option value='CQ'>CHEQUE</option>
                                    <option value='NF'>NEFT</option>
                                </select> 
                            </div> 

                            <div class="table-responsive">
                                <table id="data" align="center" border="1px" width="100%" class="table-bordered">
                                    <thead>
                                        <tr>
                                            <th width="2%"  valign="center" style="padding-left: 15px;padding-bottom: 5px;"> <label class="control-label"><input type="checkbox" id="del_all" class=" form"></label>
                                            </th>
                                            <?php
                                            $dtlbkcol = '#fda9b6ff';
                                            ?>
                                            <th width="4%" style="font-family: arial-regular;background-color: <?= $dtlbkcol; ?>; " align="center"><label class="control-label">Sr.</label></th>
<!--                                            <th width="15%" style="font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;" align="center"><label class="control-label">Barcode</label></th>-->
                                            <th width="25%" style="font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;" align="center"><label class="control-label">Item Name</label></th>
                                            <th width="25%" style="font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;" align="center"><label class="control-label">Description</label></th>
                                            <th width="7%" style="font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;"><label class="control-label">HSN Code</label></th>
                                            <th width="7%" align="right" style="text-align:right;font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;"><label class="control-label">Qty.</label></th>
                                            <th width="7%" align="right" style="text-align:right;font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;"><label class="control-label">Rate</label></th>
                                            <!--<th width="8%" align="right" style="text-align:right;font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;"><label class="control-label">Amount</label></th>-->
<!--                                            <th width="6%" align="right" style="text-align:right;font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;"><label class="control-label">Disc. %</label></th>
                                            <th width="9%" align="right" style="text-align:right;font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;"><label class="control-label">Discount</label></th>-->
                                            <!--<th width="10%" align="right" style="text-align:right;color:#CA195A;font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;"><label class="control-label">Total</label></th>-->
                                            <!--<th width="10%" align="right" style="text-align:right;font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;"><label class="control-label">MRP</label></th>-->
                                            <th width="10%" align="right" style="text-align:right;font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;"><label class="control-label">Taxable Value</label></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 * FROM `item` WHERE code = '$row[itemcode]'") or die(mysqli_error($conn));
                                                $geti = mysqli_fetch_array($getitem);

                                                echo "<tr>";
                                                echo '<td style="height:30px;" align="center" valign="top"><input type="image" src="delbut.png" name="remove"  value="remove" class="remove"/></td>';
                                                echo "<td style='height:30px;' align='left' valign='center'><input type='text' size='6' maxlength='6' name='srno_" . $ctr . "' class='srno form-control form' style='height:29px;' value='$row[srno]'/></td>";
//                                                echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='barcode_$ctr' class='barcode form-control  form' style='height:29px;text-align:left;' value='$row[barcode]'/></td>";

                                                echo "<td style='height:30px;' align='left' valign='center'>";
                                                echo "<select name='item_$ctr' style='height:29px;width:100%' class='item form-control form'>";
                                                echo "<option value='$geti[name]'>$geti[name]</option>";
                                                $mitem = mysqli_query($conn, "SELECT * FROM `item` ORDER BY `name`") or die(mysqli_error($conn));
                                                while ($trow1 = mysqli_fetch_array($mitem)) {
                                                    echo "<option value='$trow1[name]' >$trow1[name]</option>";
                                                }
                                                echo "</select>";
                                                echo "</td>";
                                                echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='descrip_$ctr' class='descrip form-control form' style='height:29px;' value='$row[descrip]'/></td>";
                                                echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='hsncode_$ctr' class='hsncode form-control form' style='height:29px;' value='$row[hsncode]'/></td>";
                                                echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='qty_$ctr' class='qty form-control form' style='height:29px;text-align:right;' value='$row[qty]'/></td>";
                                                echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='rate_$ctr' class='rate form-control form' style='height:29px;text-align:right;' value='$row[rate]'/></td>";
//                                                echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='amt_$ctr' class='amt form-control form' style='height:29px;text-align:right;' value='$row[amt]'  readonly/></td>";
//                                                echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='discperc_$ctr' class='discperc form-control form' style='height:29px;text-align:right;' value='$row[discperc]'/></td>";
//                                                echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='discamt_$ctr' class='discamt form-control form' style='height:29px;text-align:right;' value='$row[discamt]' readonly/></td>";
//                                            echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='final_$ctr' class='final form-control form' style='height:29px;text-align:right;' value='$row[totamt]'  readonly/></td>";
//                                            echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='mrp_$ctr' class='mrp form-control form' style='height:29px;text-align:right;' value='$row[mrp]'/></td>";
                                                echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='taxval_$ctr' class='taxval form-control form' style='height:29px;text-align:right;' value='$row[taxval]'/></td>";
                                                echo "</tr>";
                                                $ctr++;
                                            }
                                            //browse($ctr);
                                        } else {
                                            $pctr = 0;
                                            $yctr = 0;
                                            for ($i = $pctr; $i < 10; $i++) {
                                                $yctr++;
                                                echo "<tr>";
                                                echo '<td align="center" style="height:30px;" valign="center"><input type="image" src="delbut.png" name="remove"  value="remove" class="remove"/></td>';
                                                echo "<td style='height:30px;' align='left' valign='center'><input type='text' size='6' maxlength='6' name='srno_$pctr' class='sno form-control form' style='height:29px;' value='$yctr'/></td>";

//                                                echo "<td align='center' style='height:30px;' valign='center'><input type='text' size=''  name='barcode_$pctr' class='barcode form-control form' style='height:29px;text-align:left;' value='' /></td>";
                                                echo "<td align='left' style='height:30px;'>";
                                                ?>
                                            <select name = "item_<?= $pctr ?>" class = "item form-control form" style = 'height:29px;width:100%;'>
                                                <option value = ""></option>
                                                <?php
                                                $mitem = mysqli_query($conn, "SELECT * FROM `item` ORDER BY `name`") or die(mysqli_error($conn));
                                                while ($trow1 = mysqli_fetch_array($mitem)) {
                                                    echo "<option value='$trow1[name]' >$trow1[name]</option>";
                                                }
                                                ?>
                                            </select>
                                            <?php
                                            echo "</td>";
                                            echo "<td align='center' style='height:30px;' valign='center'><input type='text' size=''  name='descrip_$pctr' class='descrip form-control form' style='height:29px;' value='' /></td>";
                                            echo "<td align='center' style='height:30px;' valign='center'><input type='text' size=''  name='hsncode_$pctr' class='hsncode form-control form' style='height:29px;' value='' /></td>";
                                            echo "<td align='center' style='height:30px;' valign='center'><input type='text' size=''  name='qty_$pctr' class='qty form-control form' style='height:29px;text-align:right;' value='0' /></td>";
                                            echo "<td align='center' style='height:30px;' valign='center'><input type='text' size=''  name='rate_$pctr' class='rate form-control form' style='height:29px;text-align:right;' value='0'/></td>";
//                                            echo "<td align='center' style='height:30px;' valign='center'><input type='text' size=''  name='amt_$pctr' class='amt form-control form' style='height:29px;text-align:right;' value='0'  readonly/></td>";
//                                            echo "<td align='center' style='height:30px;' valign='center'><input type='text' size=''  name='discperc_$pctr' class='discperc form-control form' style='height:29px;text-align:right;' value='0'  /></td>";
//                                            echo "<td align='center' style='height:30px;' valign='center'><input type='text' size=''  name='discamt_$pctr' class='discamt form-control form' style='height:29px;text-align:right;' value='0'  readonly/></td>";
                                            echo "<td align='center' style='height:30px;' valign='center'><input type='text' size=''  name='taxval_$pctr' class='taxval form-control form' style='height:29px;text-align:right;' value='0'  readonly/></td>";
                                            echo "</tr>";
                                            $pctr++;
                                        }
                                    }
                                    ?>
                                    <input type="hidden" id="items" name="items" value="<?php echo ($addflag != 1) ? $ctr : $pctr; ?>" />  

                                    </tbody>
                                </table>
                            </div>
                            <div class="form-group" style="padding-left: 13px;">
                                <input type="button" style="height: 30px; width: 30px; padding: 0px" id="addnew" class="btn btn-success btn-lg form" accode="addnew2" value="+" />

                                <!--<input type="hidden" id="items" name="items" value="<?php // echo ($addflag != 1) ? $ctr : 1;                                                              ?>" />-->  

                            </div>
                            <div class="form-group">
                                <!--<label class="control-label col-lg-5"></label>-->
                                <label class="control-label col-lg-8" style="color:green;">Total Qty</label>
                                <div class="col-lg-1">
                                    <input type="number" step="any" name="subqty" id='subqty' autofocus="" placeholder="" value="<?php echo ($addflag != 1) ? $get['subqty'] : ''; ?>" style="text-align: right;width:100" class="form-control form" readonly>
                                </div>
                                <label class="control-label col-lg-1" style="color:blue;">Sub Total</label>
                                <div class="col-lg-2">
                                    <input type="number" step="any" name="subtotal" id='subtotal' autofocus="" placeholder="" value="<?php echo ($addflag != 1) ? $get['subtotal'] : ''; ?>" style="text-align: right;" class="form-control form" readonly>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-lg-5" style="width: 48%"></label>
                                <label class="control-label col-lg-3">Discount</label> 
                                <div class="col-md-1" style="width: 112px;">
                                    <input type="number" step="any" name="discperc"  value="<?php echo ($addflag != 1) ? $get['discperc'] : ''; ?>" style="text-align: right;width: 67px;" class="discperc form-control form" >
                                </div>
                                <label style="width:15px;" class="control-label col-lg-1">%</label>
                                <div class="col-lg-2">
                                    <input type="number" step="any" name="discamt" id="discamt" value="<?php echo ($addflag != 1) ? $get['discount'] : ''; ?>" style="text-align: right; margin-left:4px" class="form-control discamt form" readonly>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-lg-6"></label>
                                <label class="control-label col-lg-2">No. of Boxes</label>
                                <div class="col-lg-1">
                                    <input type="number" step="any" name="nobox" id="nobox" value="<?php echo ($addflag != 1) ? $get['nobox'] : '0'; ?>" style="text-align: right;width:100" class="form-control form" >
                                </div>
                                <label class="control-label col-lg-1">Packing</label>
                                <div class="col-lg-2">
                                    <input type="number" step="any" name="packing" id="packing" value="<?php echo ($addflag != 1) ? $get['packing'] : '0'; ?>" style="text-align: right;" class="packing form-control form">
                                </div>
                            </div>
                            <div class="form-group">
                                <!--<label class="control-label col-lg-5"></label>-->
                                <label class="control-label col-lg-6" style="color:green;"></label>
                                <div class="col-lg-3">

                                </div>
                                <label class="control-label col-lg-1" style="color:green;">Taxable</label>
                                <div class="col-lg-2">
                                    <input type="number" step="any" name="tottaxable" id='tottaxable' value="<?php echo ($addflag != 1) ? $get['tottaxable'] : ''; ?>" style="text-align: right;" class="form-control form tottaxable" readonly>
                                </div>
                            </div>


                            <!--    </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-lg-5"></label>
                                <label class="control-label col-lg-5">Tot Taxable Value</label>
                                <div class="col-lg-2">-->
                            <input type="hidden" step="any" tabindex="28" class="form-control form taxamt " value="<? Echo ($addflag != 1) ? $get['tottaxamt'] : "0"; ?>" name="taxamt" style="text-align: right;" readonly>
                            <!--                                </div>
                                                        </div>-->

                            <div class="form-group">
                                <label class="control-label col-lg-5" style="width: 48%"></label>
                                <label class="control-label col-lg-3">Add CGST</label> 
                                <div class="col-md-1" style="width: 112px;">
                                    <input type="number" step="any" name="cgstperc"  autofocus="" placeholder="" value="<?php echo ($addflag != 1) ? $get['cgstperc'] : ''; ?>" style="text-align: right;width: 67px;" class="cgstperc form-control form" readonly>
                                </div>
                                <label style="width:15px;" class="control-label col-lg-1">%</label>
                                <div class="col-lg-2">
                                    <input type="number" step="any" name="cgstamt" id="cgstamt" autofocus="" placeholder="" value="<?php echo ($addflag != 1) ? $get['totcgst'] : ''; ?>" style="text-align: right; margin-left:4px" class="form-control cgstamt form" readonly>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-lg-5" style="width: 48%"></label>
                                <label class="control-label col-lg-3">Add SGST</label> 
                                <div class="col-md-1" style="width: 112px;">
                                    <input type="number" step="any" name="sgstperc"  autofocus="" placeholder="" value="<?php echo ($addflag != 1) ? $get['sgstperc'] : ''; ?>" style="text-align: right;width: 67px;" class="sgstperc form-control form" readonly>
                                </div>
                                <label style="width:10px;" class="control-label col-lg-1">%</label>
                                <div class="col-lg-2">
                                    <input type="number" step="any" name="sgstamt" id="sgstamt" autofocus="" placeholder="" value="<?php echo ($addflag != 1) ? $get['totsgst'] : ''; ?>" style="text-align: right;  margin-left:4px" class="form-control sgstamt form" readonly>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-lg-5" style="width: 48%"></label>
                                <label class="control-label col-lg-3">Add IGST</label> 
                                <div class="col-md-1" style="width: 112px;">
                                    <input type="number" step="any" name="igstperc"  autofocus="" placeholder="" value="<?php echo ($addflag != 1) ? $get['igstperc'] : ''; ?>" style="text-align: right;width: 67px;" class="igstperc form-control form" readonly>
                                </div>
                                <label style="width:10px;" class="control-label col-lg-1">%</label>
                                <div class="col-lg-2">
                                    <input type="number" step="any" name="igstamt" id="igstamt" autofocus="" placeholder="" value="<?php echo ($addflag != 1) ? $get['totigst'] : ''; ?>" style="text-align: right; margin-left:4px " class="form-control igstamt form" readonly>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-lg-4"></label>
                                <label class="control-label col-lg-6" style="color:red;">Net Amount</label>
                                <div class="col-lg-2">
                                    <input type="number" step="any" name="netamt" id='netamt' autofocus="" placeholder="" value="<?php echo ($addflag != 1) ? $get['billamt'] : ''; ?>" style="text-align: right;" class="form-control form" readonly>
                                </div>
                            </div>
                            <div style="" class="form-group">
                                <label class="control-label col-lg-2"  style="width: 150px;font-family: cipher-regular,helvetica;">Remarks</label>
                                <div class="col-lg-4">
                                    <input type="text" name="rem1" id="rem1" value="<?php echo ($addflag != 1) ? $get['rem1'] : ''; ?>" class="form-control form">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-lg-2"  style="width: 150px;font-family: cipher-regular,helvetica;"></label>
                                <div class="col-lg-4">
                                    <input type="text" name="rem2" id="rem2" value="<?php echo ($addflag != 1) ? $get['rem2'] : ''; ?>" class="form-control form">
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="box-footer" style=""> 
                        <?php include("includes/buttons.php"); ?>
                    </div>
                    <!--/box-end--> 


                </div>
            </div>
        </div>
    </form>
</body>
<!--SEARCH PART-->
<div class="modal fade in slacker-modal" id="searchModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="false">
    <div class="modal-dialog modal-slacker">
        <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="myLargeModalLabel"></h4>
            </div>
            <div class="modal-body" style="height: 100%;white-space: nowrap;">
                <div class="row">

                    <div class="col-md-12">

                        <div class="col-lg-12">

                            <div class="box">
                                <div id="collapse4" class="body">
                                    <table ID="dataTable"  class="table table-bordered table-condensed table-hover table-striped">
                                        <thead>
                                            <tr>
                                                <th align='left'>Voucher</th>
                                                <th align='left'>Date</th>
                                                <th align='left'>Party</th>
                                                <th align='left'>Payment Date</th>
                                                <th align='left'>Bill Type</th>
                                                <th align='right'>Bill Amount</th>
                                                <th align='left'>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
                                            $srchresult = mysqli_query($conn, "SELECT *, date_format(vouchdt,'%d-%m-%Y') as mydt, date_format(paydate,'%d-%m-%Y') as paymdt FROM `$maindb` WHERE $keyfld!=''") or die(mysqli_error($conn));
                                            while ($row = mysqli_fetch_array($srchresult)) {
                                                $getgo = mysqli_query($conn, "SELECT * FROM `godown` where `code`='$row[godown]'")or die(mysqli_error($conn));
                                                $go = mysqli_fetch_array($getgo);
                                                $getparty = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`='$row[accode]'")or die(mysqli_error($conn));
                                                $party = mysqli_fetch_array($getparty);

                                                $bill = "";

                                                if ($row['billtype'] == 'RT') {
                                                    $bill = "RTGS";
                                                } elseif ($row['billtype'] == 'CR') {
                                                    $bill = "CREDIT";
                                                } elseif ($row['billtype'] == 'CH') {
                                                    $bill = "CASH";
                                                } elseif ($row['billtype'] == 'CQ') {
                                                    $bill = "CHEQUE";
                                                } elseif ($row['billtype'] == 'NF') {
                                                    $bill = "NEFT";
                                                } else {
                                                    $bill = "";
                                                }
                                                echo "<tr>";
                                                echo "<td align='left'>$row[vouchno]</td>";
                                                echo "<td align='left'>$row[mydt]</td>";
                                                echo "<td align='left'>$party[name]</td>";
                                                echo "<td align='left'>$row[paymdt]</td>";
                                                echo "<td align='left'>$bill</td>";
                                                echo "<td align='left'>$row[billamt]</td>";
                                                echo "<td align='left'><a href=\"$file?mode=edit&$keyfld=$row[$keyfld]\"><img src='images/edit.png'></a></td>";
                                                echo "</tr>";
                                            }
                                            ?>
                                        </tbody>
                                    </table>
                                    <script>
                                        $(function () {
                                            metisTable();
                                            metisSortable();
                                        });
                                    </script>

                                </div>

                            </div>

                        </div>

                    </div><!-- /.row -->

                </div>
            </div>  
            <div class="modal-footer" style="bottom: 0px;position: absolute;padding:0px;">
                <!--"This is where i want to load my salemain.php"-->
            </div>
        </div>
    </div>
</div>

<!--voucher search-->
<div class="modal fade bs-example-modal-lg searchModali"  tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
    <div class="modal-dialog modal-lg" style="width: 80%">
        <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['code']; ?>" class="form-control vouchno">
                <input type="hidden" value="<?php Echo $file ?>" class="form-control file">
                <input type="hidden" value="<?php Echo $para ?>" class="form-control para">
                <div class="row">
                    <div class="col-lg-2">
                        <select class="form-control ifield">
                            <option value="1">Voucher</option>
                            <option value="2">Date</option>
                            <option value="3">Party</option>
                        </select>
                    </div>
                    <div class="col-lg-2">
                        <select class="form-control ioperator">
                            <option value="">Type Of Search</option>
                            <option value="%">Like</option>
                            <option value="=">Exactly</option>
                        </select>
                    </div>
                    <div class="col-lg-2">
                        <select class="form-control sortBy">
                            <option value="">Sort By</option>
                            <option value="1">Voucher</option>
                            <option value="2">Date</option>
                            <option value="3">Party</option>
                        </select>
                    </div>
                    <div class="col-lg-1">
                        <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 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="" 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="20%">Voucher</th>
                                <th width="20%">Date</th>
                                <th width="45%">Party</th>
                                <th width="15%">Bill Amount</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>

</html>        

<?php // include("includes/footlinks.php");              ?>
<!--<script>
    $(function() {
        formGeneral();
    });
</script>-->
