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

$formname = 'Purchase Return / Debit Note (Others)';
$maindb = 'debmain';
$trandb = 'deboth';
//$stkdb = 'transacn';
$accdb = 'actran';
$printfile = "credoth_print.php";
$file = 'deboth.php';
$trandbexist = 1;
$keyfld = "vouchno";
IF (isset($_GET['debtype']) != "") {
    $zcredtype = "$_GET[debtype]";
} ELSE {
    $zcredtype = "O";
}
$source = "PU";
$keycond = " AND `debtype`='$zcredtype' ";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
$username = $_SESSION["username_" . $dbname];
$zyear = right($zdb, 4);
$comp = $_SESSION["comp_" . $dbname];
$zStartDate = getzdates($zyear, 'S', $comp);
$zEndDate = getzdates($zyear, 'E', $comp);
$salelock = $_SESSION["salelock"];

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

if (isset($_POST["submit"])) {
    $vouchdt = $_POST["vouchdt"];
    $qvouch = $_POST["vouchno"];
    
    $invdate = $_POST["invdate"];
    $invno = trim($_POST["invno"]);
    $voucher = trim($_POST["voucher"]);
    $party = trim($_POST["party"]);
    $packby = trim($_POST["packby"]);
    $addpack = trim($_POST["addpack"]);
    $godown = trim($_POST["godown"]);
    $remark1 = trim($_POST["remark1"]);
    $remark2 = trim($_POST["remark2"]);
    $grossamt = trim($_POST["grossamt"]);
    $ldiscperc = trim($_POST["ldiscperc"]);
    $totdiscamt = trim($_POST["totdisc"]);
    $taxableamt = trim($_POST["taxableamt"]);
    $totbillamt = trim($_POST["totbillamt"]);
    $roundoff = trim($_POST["roundoff"]);
    $oms = $_POST['oms'];

    $netamt = $totbillamt;
    $count = $_POST["items"];
    $gstamount = $cgstamt + $sgstamt + $igstamt;

    $mvouch = $qvouch;

    $salecode = 30;
    $a = 1;

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

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


        #################################TRAN PART #################################

        mysqli_query($conn, "DELETE FROM `$trandb` WHERE `$keyfld`='$mvouch'") or die(mysqli_error($conn));
        $group = $source . $mvouch;
        $srl = 0;
        for ($i = 0; $i < $count; $i++) {
            $msrno = $_POST["srno_$i"];
            $descrip = $_POST["descrip_$i"];
            $amount = $_POST["amount_$i"];

            if (!empty($descrip)) {
                $srl = $srl + 1;

                mysqli_query($conn, "INSERT INTO `$trandb`(`vouchno`, `vouchdt`, `srno`, `descrip`, `amount`) 
                    VALUES ('$qvouch', '$vouchdt', '$srl', '$descrip', '$amount')") or die(mysqli_error($conn));
            }
        }

############################## Accounts Part ######################################################
        mysqli_query($conn, "DELETE FROM `$accdb` WHERE `vouchno` = '$mvouch' AND `source` = '$source'") OR die(mysqli_error($conn));

        if ($netamt > 0) {
            $taxablemin = $taxableamt * -1;
            $gstmin = ($gstamount * -1);


            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount,prodtype,actamt)
                    VALUES ('$vouchdt','$mvouch', '$source', '001', '$salecode','005', '$taxablemin','$prodtype','$taxablemin')") OR die(mysqli_error($conn));
//browse(1);
            //            round off part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,`godown`, source, trnno, accode, grpcode, amount)
                            VALUES ('$vouchdt','$mvouch','$godown', '$source', '004', '25','012', '$roundoff')") or die(mysqli_error($conn));
//browse(2);


            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount,prodtype,actamt)
                     VALUES ('$vouchdt','$mvouch', '$source', '002', '$party','010', '$netamt','$prodtype','$netamt')") or die(mysqli_error($conn));

            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount,prodtype,actamt)
                            VALUES ('$vouchdt','$mvouch', '$source', '003', '5','020', '$gstmin','$prodtype','$gstmin')") or die(mysqli_error($conn));
        }
//browse(3);

        ############################## MAIN ######################################################
        if ($addflag == 1) {
            $newvoucher = $mvouch;

            mysqli_query($conn, "INSERT INTO `$maindb`(`username`, vouchno, `vouchdt`, `voucher`, `invno`, `invdate`, `party`,  roundoff,
                                               `remark1`, `remark2`, `totdisc`,`grossamt`, `godown`,`debtype`,packby,addpack,ldiscperc,`totbillamt`)
                                      VALUES('$username','$mvouch', '$vouchdt', '$newvoucher', '$invno', '$invdate','$party','$roundoff',
                                              '$remark1', '$remark2', '$totdiscamt','$grossamt', '$godown', 'O','$packby','$addpack','$ldiscperc','$totbillamt')") or die(mysqli_error($conn));
            insmess();
            $mvouch = $qvouch; //1
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit&debtype=O");
        } else {
            $mvouch = $qvouch; //1

            mysqli_query($conn, "UPDATE `$maindb` SET  `vouchdt`='$vouchdt', `invno`='$invno', `invdate`='$invdate',`party`='$party',roundoff='$roundoff',
                                                `remark1`='$remark1', `remark2`='$remark2', `totdisc`='$totdiscamt',`packby`='$packby',`addpack`='$addpack',`ldiscperc`='$ldiscperc',`grossamt`='$grossamt', `godown`='$godown', 
                                                
                                                 `totbillamt`='$totbillamt', `username`='$username' WHERE `vouchno` = '$mvouch' ") or die(mysqli_error($conn));
            updmess();

            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit&debtype=O");
        }
    }
}

if ($addflag != 1) {

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

    $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE $keyfld='$getvouch' and `debtype`='O'") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);
//browse($get['totbillamt']);
    $findparty = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`='$get[party]'") or die(mysqli_error($conn));
    $lparty = mysqli_fetch_array($findparty);

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

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

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

if (isset($_GET["delete"])) {
    delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last&debtype=O");
    delete($zdb, "$trandb", "$keyfld", $_GET[$keyfld], "$file?mode=last&debtype=O");
    $delcond = " source = '$source' and vouchno = '$_GET[vouchno]' ";
    delnew($zdb, "$accdb", "$delcond", "$file?mode=last&debtype=O");
}

include("includes/linkshead.php");
?>
<script src="MyScript/credoth.js" type="text/javascript"></script>
<script src="MyScript/deboth_search.js" type="text/javascript"></script>
<script src="MyScript/checkdate.js" type="text/javascript"></script>

</head>
<body>
    <form action='' method='POST'>
        <div class="col-lg-3 pad text-center" id="overlay_form" style="display:none;z-index:999;">
            <button type="button" id="close_form" style="float: right;font-weight: bold;font-size: 18px;color:red;"><i class="fa fa-close"></i></button>
            <div style='width:100%;' id='browdata'>
            </div>
        </div>
        <!-- Default box -->
        <div>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12  pad">
                <div class="panel panel-default">
                    <div class="panel-heading" style="height:40px">
                        <div class="col-lg-10 col-md-10 col-sm-10  col-xs-10">
                            <h3 class="panel-title" style="color:#78909C"><a class="myPrint"><?php echo $formname; ?></a></h3>
                        </div>
                        <div class="col-lg-2 col-md-2 col-sm-2  col-xs-2">
                            <input type="date" value="<?= $zStartDate ?>" style="width: 1px;border: none" class="zstdate">
                            <input type="date" value="<?= $zEndDate ?>" style="width: 1px;border: none" class="zenddate">
                            <input type="date" value="<?= $salelock ?>" style="width: 1px;border: none" class="salelock">

                            <h4 class="panel-title" style="float:right"><b><?php echo $get['username'] ?></b></h4>
                        </div>
                    </div>
                    <div class="panel-body">
                        <div class="row">

                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Credit No.</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="hidden" name="voucher" class="form-control form voucher" value="<?php echo ($addflag != 1) ? $get['voucher'] : '' ?>" tabindex="-1" readonly>
                                <input type="hidden" name="monno" class="form-control form monno" value="<?php echo ($addflag != 1) ? $get['monno'] : '' ?>" >
                                <input type="text" name="vouchno" class="form-control form vouchno" value="<?php echo ($addflag != 1) ? $get['vouchno'] : $qvouch ?>" tabindex="-1" readonly>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Credit Date</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-1 col-xs-8 pad">
                                <input type="date" class="form-control form vouchdt" name="vouchdt"  value="<?php Echo ($addflag != 1) ? $get["vouchdt"] : date("Y-m-d"); ?>" autofocus>
                            </div>
                            <!-- <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Godown</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <select name="godown" class="form-control form godown select2">
                                    <option value="<?php echo ($addflag != 1) ? $getgd['code'] : " "; ?>"><?php echo ($addflag != 1) ? $getgd['gcode'] : " "; ?></option>
                                    <?php
                                    $mown = mysqli_query($conn, "SELECT * FROM `godown`") or die(mysqli_error($conn));
                                    while ($trow = mysqli_fetch_array($mown)) {
                                        echo "<option value=$trow[code]>$trow[gcode]</option>";
                                    }
                                    ?>
                                </select>
                            </div>  -->
                            <div class="col-lg-1 pad text-right">
                                <label class="label-control marg">Party</label>
                            </div>
                            <div class="col-lg-3 pad">
                                <select class="form-control form cmbparty select2" name="party" style="width: 100%" required>
                                    <option value="<?php Echo ($addflag != 1) ? $lparty["accode"] : ""; ?>"><?php Echo ($addflag != 1) ? $lparty["name"] : ""; ?></option>
                                    <?php
//                                do not remove this lock, talk to firoz sir. 
                                    if ($addflag == 1) {
                                        $gparty = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `grpcode`='010' order by name")or die(mysqli_error($conn));
                                        while ($party = mysqli_fetch_array($gparty)) {
                                            Echo "<option value='$party[accode]'>$party[name]</option>";
                                        }
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Invoice</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" name="invno" class="form-control form invno" value="<?php echo ($addflag != 1) ? $get['invno'] : ""; ?>" tabindex="-1" >
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Invoice Date</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-1 col-xs-8 pad">
                                <input type="date" class="form-control form invdate" name="invdate"  value="<?php Echo ($addflag != 1) ? $get["invdate"] : date("Y-m-d"); ?>">
                            </div>

<!--                            <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 numeric text-right pad">
                                <label class="label-control marg">GST %</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <select class="form-control form select2 gstperc" name="gsttype" style="width:100%" required>
                                    <option value="<?php echo ($addflag != 1) ? $fetgst['per'] : ""; ?>"><? echo ($addflag != 1) ? $fetgst['name'] : ""; ?></option>
                                    <?php
                                    $ggsttype = mysqli_query($conn, "SELECT * FROM `gsttype` order by per")or die(mysqli_error($conn));
                                    while ($fgsttype = mysqli_fetch_object($ggsttype)) {
                                        Echo "<option value='$fgsttype->per'>$fgsttype->name</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Oms</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad" tabindex="-1">
                                <input type="checkbox"  class="form-control form oms" <?php
                                if ($get['oms'] == "1") {
                                    Echo "checked";
                                }
                                ?> value="1" name="oms" style="background-color: yellowgreen; ">                            
                            </div>-->
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 pad">
                <div class="panel panel-default">
                    <div class="">

                    </div>
                    <div class="panel-body">
                        <div class="table-responsive">
                            <table class="table table-striped table-condensed table-bordered" width="100%">
                                <thead  class="mySearchTr">
                                    <tr>
                                        <th width="5%"></th>
                                        <th width="5%" class='text-right'>Sr.</th>
                                        <th width="70%" class='text-left'>Description</th>
                                        <th width="20%" class='text-right'>Amount</th>
                                    </tr>
                                </thead>
                                <tbody class="tbody">
                                    <?php
                                    if ($addflag != 1) {
                                        $ctr = 0;
                                        $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$get[vouchno]' ORDER BY `srno`")or die(mysqli_error($conn));
                                        while ($tran = mysqli_fetch_array($gettran)) {
                                            Echo "<tr>";
                                            Echo "<td><i class='fa fa-close remove' style='display:none;'></i></td>";
                                            Echo "<td><input type='text' class='form-control form text-right srno' name='srno_$ctr' value='$tran[srno]'></td>";
                                            Echo "<td>";
                                            Echo "<input type='text' class='form-control form descrip' name='descrip_$ctr' value='$tran[descrip]'>";
                                            Echo "</td>";
                                            Echo "<td>";
                                            Echo "<input type='number' step='any' class='form-control text-right form amount' name='amount_$ctr' value='$tran[amount]'>";
                                            Echo "</td>";
                                            Echo "</tr >";
                                            $ctr++;
                                        }
                                    } else {
                                        ?>
                                        <tr>
                                            <td><i class="fa fa-close remove"></i></td>
                                            <td><input type="text" class="form-control form text-right srno" name="srno_0" value="1"></td>
                                            <td><input type="text" class="form-control form itemcode barcode" name="descrip_0" name="descrip" required></td>
                                            <td><input type='number' step='any' class="form-control form text-right amount"   name="amount_0"  value="0" required></td>
                                        </tr>  
                                        <?
                                    }
                                    ?>
                                </tbody>
                            </table>
                        </div>
                        <div class="col-lg-12 pad">
                            <!--<input type="button" style="height: 30px; width: 30px; padding: 0px" id="addnew" class="btn btn-success btn-lg form" accode="addnew2" value="+" />-->
                            <button type="button" class="btn btn-primary btn-square form"  id="addnew">
                                <i class="fa fa-plus" data-toggle='tooltip' title='Add Row'></i>    
                            </button>
                            <input type="hidden" id="items" name="items" value="<?php echo ($addflag != 1) ? $ctr : 1; ?>" />  
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-lg-12 col-xs-12 pad">
                            <div class="col-lg-6 col-xs-12 pad">

                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 pad text-right">
                                        <label class="label-control marg">Packed By</label>
                                    </div>
                                    <div class="col-lg-4 pad">
                                        <input type="text" name="packby" class="form-control form packby" value="<? Echo ($addflag != 1) ? $get["packby"] : ""; ?>" tabindex="-1">
                                    </div>
                                </div>
                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 pad text-right">
                                        <label class="label-control marg">Remarks</label>
                                    </div>
                                    <div class="col-lg-9 pad">
                                        <input type="text" name="remark1" class="form-control form " value="<? Echo ($addflag != 1) ? $get["remark1"] : ""; ?>">
                                    </div>
                                </div>
                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 pad text-right"></div>
                                    <div class="col-lg-9 pad">
                                        <input type="text" name="remark2" class="form-control form " value="<? Echo ($addflag != 1) ? $get["remark2"] : ""; ?>">
                                    </div>
                                </div>
                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-9 pad">

                                        <?php
//                                        browse($get['canc_flag']);
                                        if ($get['canc_flag'] != '') {
                                            ?>
                                            <img src="images/cancel.jpg" alt="Cancelled Bill" style="width:100%;height:100%">
                                        <?php } ?>

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

                            <div class="col-lg-6 col-xs-12 pad">
                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 pad"></div>
<!--                                    <div class="col-lg-2 label-control marg">Total Qty.</div>
                                    <div class="col-lg-2 pad">
                                        <input type="number" step="any" name="totalqty" class="form-control form text-right totalqty" value="<?php Echo ($addflag != 1) ? $get['totalqty'] : "0"; ?>">
                                    </div>-->
                                    <div class="col-lg-6 pad text-right">
                                        <label class="label-control marg">Subtotal</label>
                                    </div>
                                    <div class="col-lg-3 pad">
                                        <input type="number" step="any" name="grossamt" class="form-control form text-right totamt grossamt" value="<?php Echo ($addflag != 1) ? $get['grossamt'] : "0"; ?>" readonly tabindex="-1">
                                    </div>
                                </div>
                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-4 pad"></div>
                                    <div class="col-lg-3 pad text-right">
                                        <label class="label-control marg">Less Discount</label>
                                    </div>
                                    <div class="col-lg-1 pad">
                                        <input type="number" step="any" name="ldiscperc" class="form-control form text-right ldiscperc" value="<?php Echo ($addflag != 1) ? $get['ldiscperc'] : "0"; ?>">

                                    </div>
                                    <div class="col-lg-1 pad text-center">
                                        <label class="label-control marg">%</label>
                                    </div>
                                    <div class="col-lg-3 pad">
                                        <input type="number" step="any" name="totdisc" class="form-control form text-right totdisc" value="<?php Echo ($addflag != 1) ? $get['totdisc'] : "0"; ?>">
                                    </div>
                                </div>
<!--                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-4 pad"></div>
                                    <div class="col-lg-3 pad text-right">
                                        <label class="label-control marg">Add VAT</label>
                                    </div>
                                    <div class="col-lg-1 pad">
                                        <input type="number" step="any" name="tvatperc" class="form-control form text-right tvatperc" value="<?php Echo ($addflag != 1) ? $get['tvatperc'] : "0"; ?>">

                                    </div>
                                    <div class="col-lg-1 pad text-center">
                                        <label class="label-control marg">%</label>
                                    </div>
                                    <div class="col-lg-3 pad">
                                        <input type="number" step="any" name="totvat" class="form-control form text-right totvat" value="<?php Echo ($addflag != 1) ? $get['totvat'] : "0"; ?>" readonly tabindex="-1">
                                    </div>
                                </div>-->
                                 <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 pad"></div>
                                    <div class="col-lg-3 pad"></div>
                                    <div class="col-lg-3 pad text-right">
                                        <label class="label-control marg">Add Packing</label>
                                    </div>
                                    <div class="col-lg-3 pad">
                                        <input type="number" step="any" name="addpack" required="true" class="form-control form text-right  addpack" value="<?php Echo ($addflag != 1) ? $get['addpack'] : "0"; ?>"  tabindex="-1">
                                    </div>
                                 </div><!-- comment -->
<!--                                  <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 pad"></div>
                                    <div class="col-lg-3 pad"></div>
                                    <div class="col-lg-3 pad text-right">
                                        <label class="label-control marg">Add Gst</label>
                                    </div>
                                    <div class="col-lg-3 pad">
                                        <input type="number" step="any" name="addgst" required="true" class="form-control form text-right addgst " value="<?php Echo ($addflag != 1) ? $get['addgst'] : "0"; ?>"  tabindex="-1">
                                    </div>
                                </div>-->

                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 pad"></div>
                                    <div class="col-lg-3 pad"></div>
                                    <div class="col-lg-3 pad text-right">
                                        <label class="label-control marg">Net Amount</label>
                                    </div>
                                    <div class="col-lg-3 pad">
                                        <input type="number" step="any" name="totbillamt" required="true" class="form-control form text-right tottotal totbillamt" value="<?php Echo ($addflag != 1) ? $get['totbillamt'] : "0"; ?>" readonly tabindex="-1">
                                    </div>
                                </div>

<!--                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 pad"></div>
                                    <div class="col-lg-3 pad"></div>
                                    <div class="col-lg-3 pad text-right">
                                        <label class="label-control marg">Advance</label>
                                    </div>

                                    <div class="col-lg-3 pad">
                                        <input type="number" step="any" name="totadv"  class="form-control  text-right totadv form" value="<?php Echo ($addflag != 1) ? $get['totadv'] : "0"; ?>" tabindex="-1">
                                    </div>
                                </div>
                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 pad"></div>
                                    <div class="col-lg-3 pad"></div>
                                    <div class="col-lg-3 pad text-right">
                                        <label class="label-control marg">Balance</label>
                                    </div>
                                    <div class="col-lg-3 pad">
                                        <input type="number" step="any" name="totbal" required="true" class="form-control form text-right totbal" value="<?php Echo ($addflag != 1) ? $get['totbal'] : "0"; ?>" readonly tabindex="-1">
                                    </div>
                                </div>-->
                            </div>
                        </div>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 pad">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <?php include("includes/buttons.php"); ?>
                    </div>
                </div>
            </div>
        </div>
    </form>

    <div class="modal fade bs-example-modal-lg searchModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span>&times;</span></button>
                    <h4 class="modal-title" id="myLargeModalLabel">Search <? Echo $formname; ?></h4>
                </div>
                <div class="modal-body">
                    <input type="hidden" value="<?php Echo $file ?>" class="form-control file">

                    <div class="row">
                        <div class="col-lg-2">
                            <select class="form-control sfield">
                               <option value="">Sort By</option>
                                <option value="1">Date</option>
                                <option value="2">Voucher</option>
                                <option value="3">Description</option>
                                <option value="4">Amount</option>
                                <option value="5">Action</option>

                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control soperator">
                                <option value="">Type of Search</option>
                                <option value="%">Like</option>
                                <option value="=">Exactly</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control sortBy">
                                <option value="">Sort By</option>
                                <option value="1">Voucher</option>
                                <option value="2">Date</option>
                                <option value="3">Description</option>
                                <option value="4">Amount</option>
                                <option value="5">Action</option>
                                <!--<option value="6">Net Amount</option>-->

                            </select> 
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control orderAs">
                                <option value="desc">Desc</option>
                                <option value="asc">Asc</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <input type="text" value="" class="form-control ssearch" placeholder="Search Here">
                        </div>
                        <div class="col-lg-2">
                            <input type="button" class="btn btn-primary sload" value="Search" >
                        </div>
                    </div>
                    <div class="col-lg-12 sloader text-center">
                        <img src="images/search.gif" alt="loading">       
                    </div>
                    <div class="col-lg-12 snoRecord text-center">
                        <h3>NO RECORDS FOUND</h3>
                    </div>
                    <div class="table-responsive" style="max-height: 400px;overflow: auto;">
                        <table id="" class="table table-striped table-condensed table-bordered" width="100%">
                            <thead>
                                <tr style="background-color:#1ABC9C;">
                                    <th width="10%">Voucher</th>
                                    <th width="15%">Date</th>
                                    <th width="20%">Description</th>
                                    <th width="10%">Amount</th>
<!--                                    <th width="10%">GST%</th>
                                    <th width="15%">Net Amount</th>-->
                                    <th width="10%">Action</th>
                                </tr>
                            </thead>
                            <tbody class="sTbody">
                            </tbody>
                        </table>
                    </div>
                    <div class="row">
                        <div class="col-xs-12 text-right search-action-bar">
                            <input type="button"  class="btn btn-primary sprev" value="Previous">
                            <input type="button"  class="btn btn-primary snext" value="Next">
                        </div>
                    </div>
                </div>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>
    <?php include("includes/linksfoot.php"); ?>
</body>
</html>
