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

$formname = 'Damaged';
$maindb = 'dammain';
$trandb = 'damtran';
$accdb = 'actran';
$stkdb = 'transacn';

$file = 'damaged.php';
$grid = '';
$keyfld = "vouchno";
$trandbexist = 1;
$focusfld = "party";
$printfile = 'damprin.php';
$source = "DM";
$append_file = 'damaged_add.php';
$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);

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

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

    $a = 1;
    $godown = trim($_POST["cmbgodown"]);
    $billdate = trim($_POST["vouchdt"]);
    $billamt = trim($_POST["netamt"]);
    $totqty = trim($_POST["totqty"]);

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

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

    if (empty($billdate)) {
        browse("VOUCHER DATE CANNOT BE EMPTY");
        $a = 0;
    }

    if (empty($totqty)) {
        browse("Total Qty. Cannot Be Zero");
        $a = 0;
    }


    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"];
            $qty = $_POST["qty_$i"];
            $rate = $_POST["rate_$i"];
            $sell = $_POST["selling_$i"];
            $mrp = $_POST["mrp_$i"];
            $amt = $_POST["amt_$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, srno, itemcode, `barcode`, qty, rate, mrp, amt )
                            VALUES('$mvouch', '$msrno', '$icode[code]', '$barcode', '$qty', '$rate', '$mrp', '$amt')") or die(mysqli_error($conn));
            }
        }

        ######################### STOCK PART ####################################################
//        IF ($chkstock == 1) {
        mysqli_query($conn, "DELETE FROM `$stkdb` WHERE vouchno='$mvouch' AND `source`='$source'") or die(mysqli_error($conn));

        for ($i = 0; $i < $count; $i++) {
            $msrno = $_POST["srno_$i"];
            $mitem = $_POST["item_$i"];
            $mqty = $_POST["qty_$i"] * -1;
            $mrate = $_POST["rate_$i"];
            $mamt = $_POST["amt_$i"];
            $mcost = $_POST["cost_$i"];
            $msell = $_POST["selling_$i"];
            $mmrp = $_POST["mrp_$i"];
            if (!empty($mitem)) {
                $mitemcode1 = mysqli_query($conn, "SELECT code FROM `item` WHERE name='$mitem'") or die(mysqli_error($conn));
                $icode1 = mysqli_fetch_array($mitemcode1);
                mysqli_query($conn, "INSERT INTO `$stkdb`(vouchno, `godown`, `vouchdt`, `source`,  srno, itemcode,  qty,
                                                    rate, amount,  mrp )
                            VALUES('$mvouch','$godown', '$billdate','$source',  '$msrno', '$icode1[code]', '$mqty',
                                   '$mrate', '$mamt', '$mmrp')") or die(mysqli_error($conn));
            }
        }
//        }
#######Main Part#####
        if ($addflag == 1) {
            mysqli_query($conn, "INSERT INTO `$maindb`(vouchno, `vouchdt`, godown, billamt, `rem1`, `rem2`, `totqty`)
                                          VALUES('$mvouch', '$billdate', '$godown', '$billamt', '$rem1', '$rem2', '$totqty')") 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 `vouchdt`='$billdate', godown='$godown', billamt='$billamt', `rem1`='$rem1', `rem2`='$rem2', `totqty`='$totqty'
                                                WHERE vouchno = '$mvouch' ") or die(mysqli_error($conn));
            updmess();
//            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
        }
    }
}

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

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


/* DELETE */
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]' ";
    delnew($zdb, "$stkdb", "$delcond", "$file?mode=last");
}
include("includes/files.php");
include("includes/combo2.php");
?>

<script type="text/javascript">
    $(document).ready(function () {
        $("body").on("keyup, blur", '.qty, .rate', calculateRow);
//        $("body").on("keyup, blur", '.subtotal, .discount, .vat, .packing', calculat)
        $("#main_container").on("click", '.remove', remove);
        $('#data').on('change', '.item', showdtl);
        $('#data').on('blur', '.mrp', addrow2);


        //getting rate from item
        function showdtl() {
            var $row = $(this).closest("tr");
            var name = $row.find('.item').val();
            $.ajax({
                type        : 'GET',
                dataType    : 'json',
                url         : "show_item_dtl.php",
                data        : {name: name},
                success: function (response) {
                    var barcode = response.barcode;
                    var rate    = response.rate;
                    $($row.find('.barcode')).val(barcode);
                    $($row.find('.rate')).val(rate);
                },
                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");

            var qty = parseFloat($row.find('.qty').val());
            var rate = parseFloat($row.find('.rate').val());
            var mrp = parseFloat($row.find('.mrp').val());

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

            parseFloat($row.find('.amt').val(totamt));


            fintot = totamt;


            if (isNaN(fintot)) {
                $row.find('.amt').val("0");
            } else {
                $row.find('.amt').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************/

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

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

//            calculat();
            calculateQty();
        }

//        $("#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 calculateQty() {
            var qty = 0;
            var val1 = 0;

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

//        function calculat() {
//            var mamt = parseFloat($("#subtotal").val());
//
////            $('#discount').removeAttr("readonly");
//
//
//
//            var mnet = mamt;
//            $('#netamt').val(mnet.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;
            }

            $.post('damaged_add.php', {ctr: ctr, hide: hide_check}, function (data) {
                $(data).appendTo('#data');
                ctr++;
                $('#items').val(ctr);
            });
        }

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

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


    });
</script>
</head>
<body onLoad="document.boq.vouchdt.focus()" id="main_container">
    <form name="purchase" action="" method="POST">

        <div class="row" style="">
            <div class="col-lg-12" style=''>
                <div class="box dark">
                    <header>
                        <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"  readonly>
                                </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" >
                                </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>
                            </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 = '#d59fcaff';
                                            ?>
                                            <th width="4%" style="font-family: arial-regular;background-color: <?= $dtlbkcol; ?>; " align="center"><label class="control-label">Sr.</label></th>
                                            <th width="20%" style="font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;" align="center"><label class="control-label">Barcode</label></th>
                                            <th width="35%" style="font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;" align="center"><label class="control-label">Item Name</label></th>
                                            <th width="10%" align="right" style="text-align:right;font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;"><label class="control-label">Qty.</label></th>
                                            <th width="10%" align="right" style="text-align:right;font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;"><label class="control-label">Rate</label></th>
                                            <th width="10%" align="right" style="text-align:right;color:#008BEE;font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;"><label class="control-label">Total</label></th>
                                            <th width="9%" align="right" style="text-align:right;font-family: arial-regular;background-color: <?= $dtlbkcol; ?>;"><label class="control-label">MRP</label></th>
                                        </tr>
                                    </thead>
                                    <?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='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='mrp_$ctr' class='mrp form-control form' style='height:29px;text-align:right;' value='$row[mrp]'/></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='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='mrp_$pctr' class='mrp form-control form' style='height:29px;text-align:right;' value='0'/></td>";
                                            echo "</tr>";
                                            $pctr++;
                                        }
                                    }
                                    ?>
                                </table>
                                <!--                        <label class="control-label col-lg-3"></label>
                                                        <div class="col-lg-8">
                                                            <button class="btn btn-lg btn-success form" data-toggle="modal" data-target=".slacker-modal" style="width: 100%;">Detail</button>
                                                        </div>-->
                            </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 : $pctr; ?>" />  
                                <!--<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-5">Total Qty.</label>
                                <div class="col-lg-2">
                                    <input type="number" step="any" name="totqty" id='totqty' autofocus="" placeholder="" value="<?php echo ($addflag != 1) ? $get['totqty'] : ''; ?>" style="text-align: right;" class="form-control form" readonly>
                                </div>
                            </div>

                            <!--                            <div class="form-group">
                                                            <label class="control-label col-lg-5"></label>
                                                            <label class="control-label col-lg-5" style="color:green;">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['netamt'] : ''; ?>" style="text-align: right;" class="form-control form" readonly>
                                                            </div>
                                                        </div>-->
                            <!--                            <div class="form-group">
                                                            <label class="control-label col-lg-4"></label>
                                                            <label class="control-label col-lg-5">Add VAT</label> 
                                                            <div class="col-md-1" style="width: 82px;">
                                                                <input type="number" step="any" name="percvat" id="percvat" autofocus="" placeholder="" value="<?php echo ($addflag != 1) ? $get['percvat'] : ''; ?>" style="text-align: right;width: 67px;" class="form-control form" disabled="disabled">
                                                            </div>
                                                            <label style="width:10px;" class="control-label col-lg-1">%</label>
                                                            <div class="col-lg-2">
                                                                <input type="number" step="any" name="vat" id="vat" autofocus="" placeholder="" value="<?php echo ($addflag != 1) ? $get['vat'] : ''; ?>" style="text-align: right;" class="form-control form" readonly="" disabled="disabled">
                                                            </div>
                                                        </div>-->
                            <!--                            <div class="form-group">
                                                            <label class="control-label col-lg-3"></label>
                                                            <label class="control-label col-lg-5">Add Vat</label> 
                                                            <div class="col-md-1" style="width: 25px;">
                                                                <input type="number" step="any" name="percvat" id='percvat' autofocus="" placeholder="" value="<?php echo ($addflag != 1) ? $get['percvat'] : ''; ?>" style="text-align: right;width:20px;" class="form-control form">
                                                            </div>
                                                            <div class="col-lg-2">
                                                                <input type="number" step="any" name="vat" id='vat' autofocus="" placeholder="" value="<?php echo ($addflag != 1) ? $get['vat'] : ''; ?>" style="text-align: right;" class="form-control form" readonly>
                                                            </div>
                                                        </div>-->
                            <!--                            <div class="form-group">
                            
                                                            <label class="control-label col-lg-5"></label>
                                                            <label class="control-label col-lg-5">Add Packing</label>
                                                            <div class="col-lg-2">
                                                                <input type="number" step="any" name="packing" id='packing' autofocus="" placeholder="" value="<?php echo ($addflag != 1) ? $get['packing'] : '0'; ?>" style="text-align: right;" class="form-control form">
                                                            </div>
                                                        </div>-->
                            <div class="form-group">
                                <label class="control-label col-lg-5"></label>
                                <label class="control-label col-lg-5" 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 class="form-group">
                                                    <label class="control-label col-lg-2"  style="width: 150px;font-family: cipher-regular,helvetica;"></label>
                                                    <div class="col-lg-8">
                                                        <textarea rows="3" cols="50" name="word" class="form-control form" id="word"  ><?php rsword($get['netamt']); ?></textarea>
                                                    </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="example1" class="table table-bordered table-condensed table-hover table-striped">
                                                <thead>
                                                    <tr>
                                                        <th align='left'>Voucher No.</th>
                                                        <th align='left'>Date</th>
                                                        <th align='left'>Godown</th>
                                                        <th align='left'>Total Qty</th>
                                                        <th align='left'>Action</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php
                                                    $srchresult = mysqli_query($conn, "SELECT * 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);
                                                        
                                                        
                                                        echo "<tr>";
                                                        echo "<td align='left'>$row[vouchno]</td>";
                                                        echo "<td align='left'>$row[vouchdt]</td>";
                                                        echo "<td align='left'>$go[gdcode]</td>"; 
                                                        echo "<td align='left'>$get[totqty]</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>

</html>        

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