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

$formname = 'Debit Note / Purchase Return GST';
$maindb = 'debmain';
$trandb = 'debtran';
$stkdb = 'transacn';
$accdb = 'actran';
$printfile = "debnotegst_print.php";
$file = 'debnotegst.php';
$trandbexist = 1;
$keyfld = "vouchno";
$source = "PR";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);
include("includes/vouchno_generate.php");
include("includes/prev&next.php");

if (isset($_POST["submit"])) {
    $a = 1;
    $invno = $_POST["invno"];
    $vouchdt = $_POST["vouchdt"];
    $party = $_POST["party"];
    $type = $_POST["type"];
    $godown = $_POST["godown"];
    $subtotal = $_POST["subtotal"];
    $discperc = $_POST["discperc"];
    $discount = $_POST["discount"];
    $frgperc = $_POST["frgperc"];
    $freight = $_POST["freight"];
    $netamt = $_POST["netamt"];
    $rem1 = $_POST["rem1"];
    $rem2 = $_POST["rem2"];

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

    $count = $_POST["items"];

    $mvouch = $qvouch;

    $salecode = 11;

    if (isset($_POST["name"])) {
        $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `name`= '$name' AND vouchno != '$qvouch'") or die(mysqli_error($conn));
        if (mysqli_num_rows($result) > 0) {
            $a = 0;
            browse("Name Already Exist");
            header("refresh: 1; $file?$keyfld=$qvouch&mode=last");
        }
    }

    if ($a == 1) {

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

        mysqli_query($conn, "DELETE FROM `$trandb` WHERE `$keyfld`='$mvouch'") or die(mysqli_error($conn));
        mysqli_query($conn, "DELETE FROM `$stkdb` WHERE `$keyfld`='$mvouch' AND `source`='$source'") or die(mysqli_error($conn));
        $group = $source . $mvouch;

        $srl = 0;
        for ($i = 0; $i < $count; $i++) {
            $msrno = $_POST["srno_$i"];
            $mbrand = $_POST["brand_$i"];
            $mitem = $_POST["item_$i"];
            $mbatch = $_POST["batch_$i"];
            $mactbatch = $_POST["actbatch_$i"];
            $mhsncode = $_POST["hsncode_$i"];
            $mtaka = $_POST["taka_$i"];
            $macttaka = $_POST["acttaka_$i"];
            $mqty = $_POST["qty_$i"];
            $mtotqty = $_POST["totqty_$i"];
            $mflag = $_POST["flag_$i"];
            $mflagqty = $_POST["flagqty_$i"];
            $minvqty = $_POST["invqty_$i"];
            $mrate = $_POST["rate_$i"];
            $mamount = $_POST["amount_$i"];
            // $mactbatch = $source . $mvouch . $mbatch;



            if (!empty($mitem)) {
                $getmitemname = mysqli_query($conn, "SELECT * FROM `item` WHERE `code`='$mitem'") or die(mysqli_error($conn));
                $gmitemname = mysqli_fetch_array($getmitemname);
                $mitemname = $gmitemname['name'];
                $mshade = $gmitemname['shade'];
                $srl = $srl + 1;

                mysqli_query($conn, "INSERT INTO `$trandb`(`vouchno`,`vouchdt`, `srno`, `brand`, `itemcode`,`batch`, `actbatch`, 
                                   `taka`,`acttaka`, `qty`, `totqty`, `flag`, `flagqty`, `invqty`, `rate`, `amount`,`hsncode`)
                            VALUES('$mvouch','$vouchdt', '$srl','$mbrand', '$mitem', '$mbatch', '$mactbatch', '$mtaka',
                                   '$macttaka', '$mqty', '$mtotqty', '$mflag', '$mflagqty','$minvqty', '$mrate', '$mamount','$mhsncode')") or die(mysqli_error($conn));

                $mtaka = $_POST["taka_$i"] * -1;
                $macttaka = $_POST["acttaka_$i"] * -1;
                $mqty = $_POST["qty_$i"] * -1;
                $mtotqty = $_POST["totqty_$i"] * -1;
                $mflag = $_POST["flag_$i"] * -1;
                $mflagqty = $_POST["flagqty_$i"] * -1;
                $minvqty = $_POST["invqty_$i"] * -1;
                mysqli_query($conn, "INSERT INTO `$stkdb`(`yearno`, `group`, `source`, `type`,`vouchno`,`vouchdt`,
                            `srno`, `brand`, `itemcode`,`itemname`,`batch`, `taka`, `qty`,
                            `totqty`, `flag`, `flagqty`, `actqty`, `godown`, `actbatch`,`ord`,`shade`)
                     VALUES('$yearno','$group','$source','$type','$qvouch','$vouchdt', '$srl','$mbrand',
                            '$mitem', '$mitemname', '$mbatch', '$mtaka', '$mqty', '$mtotqty', 
                            '$mflag', '$mflagqty','$minvqty', '$godown', '$mactbatch','$ord','$mshade')") 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) {
            $minus_amt = ($netamt * -1);

            // purchase part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount)
                    VALUES ('$vouchdt','$mvouch', '$source', '001', '$salecode','004', '$minus_amt')") or die(mysqli_error($conn));
            // party part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount)
                     VALUES ('$vouchdt','$mvouch', '$source', '002', '$party','009', '$netamt')") or die(mysqli_error($conn));
        }
        #################################STOCK PART #################################



        for ($i = 0; $i < $count; $i++) {
            $yearno = $myyear;
            $msrno = $_POST["srno_$i"];
            $mbrand = $_POST["brand_$i"];
            $mitem = $_POST["item_$i"];
            $mbatch = $_POST["batch_$i"];
            $mtaka = $_POST["taka_$i"];
            $macttaka = $_POST["acttaka_$i"];
            $mqty = $_POST["qty_$i"];
            $mtotqty = $_POST["totqty_$i"];
            $mflag = $_POST["flag_$i"];
            $mflagqty = $_POST["flagqty_$i"];
            $minvqty = $_POST["invqty_$i"];
            $ord = "2";

            if (!empty($mitem)) { }
        }

        ############################## MAIN ######################################################
        if ($addflag == 1) {
            mysqli_query($conn, "INSERT INTO `$maindb`(`vouchno`, `invno`, `vouchdt`, `party`, `type`, `godown`,
                                            `subtotal`,`discperc`,`discount`,`frgperc`,`freight`,`netamt`,
                                             `remark1`, `remark2`,`oms`, `cgstperc`, `sgstperc`, `igstperc`, 
                                               `totcgst`, `totsgst`, `totigst`, `tottaxamt`)
                                            VALUES($qvouch, '$invno', '$vouchdt', '$party', '$type', '$godown',
                                            '$subtotal','$discperc','$discount','$frgperc','$freight','$netamt',
                                             '$rem1', '$rem2', '$oms', '$cgstperc', '$sgstperc', '$igstperc',
                                               '$totcgst', '$totsgst', '$totigst', '$taxamt' )") or die(mysqli_error($conn));
            insmess();
            $mvouch = $qvouch; //1
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
        } else {
            $mvouch = $qvouch; //1

            mysqli_query($conn, "UPDATE `$maindb` SET `vouchno`='$mvouch',`vouchdt`='$vouchdt', `invno`='$invno', `party`='$party', `type`='$type',
                        `godown`='$godown',`subtotal`='$subtotal',`discperc`='$discperc',`discount`='$discount',
                        `frgperc`='$frgperc',`freight`='$freight',`netamt`='$netamt', `remark1`='$rem1', `remark2`='$rem2', `oms`='$oms',`cgstperc`='$cgstperc',
                        `sgstperc`='$sgstperc', `igstperc`='$igstperc', `totcgst`='$totcgst', `totsgst`='$totsgst', `totigst`='$totigst',
                        `tottaxamt`='$taxamt' 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);

    $findtype = mysqli_query($conn, "SELECT * FROM `type` WHERE `code`='$get[type]'") or die(mysqli_error($conn));
    $ltype = mysqli_fetch_array($findtype);

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

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

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");
    delnew($zdb, "$accdb", "$delcond", "$file?mode=last");
}
if (isset($_GET["cancel"])) {
    $delcond = " source = '$source' and vouchno = '$_GET[vouchno]' ";
    delnew($zdb, "dumstock", "$delcond", "$file?mode=last");
}


include("includes/linkshead.php");
?>
<script src="MyScript/debnotegst.js" type="text/javascript"></script>
<script src="MyScript/debnotegst_search.js" type="text/javascript"></script>
</head>

<body>
    <!--    <div id="preloader" class="col-lg-12 text-center">
            <h3 class="text-center">Loading</h3>
            <div id="status">&nbsp;</div>
        </div>-->
    <form action='' method='POST'>
        <!-- Default box -->
        <div class="col-lg-6 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>
        <div>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12  pad">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title" style="color:#1ABC9C"><?php echo $formname; ?></h3>
                        <div class="actions pull-right">
                            <i class="fa fa-chevron-down"></i>
                            <i class="fa fa-times"></i>
                        </div>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Voucher</label>
                            </div>
                            <div class="col-lg-1 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form vouchno" name="vouchno" value="<?php echo ($addflag != 1) ? $get["vouchno"] : " $qvouch"; ?>" required readonly>
                                <input type="hidden" class="form-control form source" name="source" value="<?php echo $source ?>">
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Invoice No.</label>
                            </div>
                            <div class="col-lg-1 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form focusfield" name="invno" value="<?php echo ($addflag != 1) ? $get["invno"] : " $qvouch"; ?>" autofocus>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Date</label>
                            </div>
                            <div class="col-lg-2 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="date" class="form-control form" name="vouchdt" value="<?php echo ($addflag != 1) ? $get["vouchdt"] : date("Y-m-d"); ?>">
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Party</label>
                            </div>
                            <div class="col-lg-4 col-md-8 col-sm-8 col-xs-8 pad">
                                <select class="form-control form  select2" name="party" style="width: 90%">
                                    <option value="<?php echo ($addflag != 1) ? $get["party"] : ""; ?>"><?php echo ($addflag != 1) ? $lparty["name"] : ""; ?></option>
                                    <?php
                                    $gparty = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `grpcode`='009'") 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">Type</label>
                            </div>
                            <div class="col-lg-1 col-md-8 col-sm-8 col-xs-8 pad">
                                <select class="form-control form select2" name="type">
                                    <option value="<?php echo ($addflag != 1) ? $get["type"] : ""; ?>"><?php echo ($addflag != 1) ? $ltype["name"] : ""; ?></option>
                                    <?php
                                    $gtype = mysqli_query($conn, "SELECT * FROM `type`") or die(mysqli_error($conn));
                                    while ($type = mysqli_fetch_array($gtype)) {
                                        echo "<option value='$type[code]'>$type[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">Godown</label>
                            </div>
                            <div class="col-lg-1 col-md-8 col-sm-8 col-xs-8 pad">
                                <select class="form-control form select2 godown" name="godown">
                                    <option value="<?php echo ($addflag != 1) ? $get["godown"] : ""; ?>"><?php echo ($addflag != 1) ? $get["godown"] : ""; ?></option>
                                    <?php
                                    $ggodown = mysqli_query($conn, "SELECT * FROM `godown`") or die(mysqli_error($conn));
                                    while ($godown = mysqli_fetch_array($ggodown)) {
                                        echo "<option value='$godown[gocode]'>$godown[gocode]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                            <div class="col-lg-4 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Out Of State</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="checkbox" class="form-control form oms" <?php
                                                                                        if ($get[oms] == "1") {
                                                                                            echo "checked";
                                                                                        }
                                                                                        ?> value="1" name="oms">
                            </div>
                        </div>
                    </div>
                </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-heading">
                        <!--                        <h3 class="panel-title">Item Details</h3>-->
                        <div class="actions pull-right">
                            <i class="fa fa-chevron-down"></i>
                        </div>
                    </div>
                    <div class="panel-body">
                        <div class="table-responsive">
                            <table class="table table-striped table-condensed table-bordered" width="100%">
                                <thead style="background: #1ABC9C;">
                                    <tr>
                                        <th width="1%"></th>
                                        <th width="3%" class='text-right'>Sr.</th>
                                        <th width="10%" class='text-left'>Brand</th>
                                        <th width="12%">Item</th>
                                        <th width="5%">Hsn Code</th>
                                        <th width="6%" class='text-right'>Batch</th>
                                        <th width="6%" class='text-right'>Act. Batch</th>
                                        <th width="4%" class='text-right'>Taka</th>
                                        <th width="4%" class='text-right'>Act Taka</th>
                                        <th width="4%" class='text-right'>Qty.</th>
                                        <th width="4%" class='text-right'>Tot. Qty.</th>
                                        <th width="4%" class='text-right'>Flag</th>
                                        <th width="4%" class='text-right'>Flag Qty.</th>
                                        <th width="4%" class='text-right'>Inv. Qty.</th>
                                        <th width="5%" class='text-right'>Rate</th>
                                        <th width="6%" 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)) {
                                            $finditem = mysqli_query($conn, "SELECT * FROM `item` WHERE `code`='$tran[itemcode]'") or die(mysqli_error($conn));
                                            $fitem = mysqli_fetch_array($finditem);
                                            $findbrand = mysqli_query($conn, "SELECT * FROM `brand` WHERE `code`='$tran[brand]'") or die(mysqli_error($conn));
                                            $lbrand = mysqli_fetch_array($findbrand);

                                            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 "<select class='form-control form brand select2' name='brand_$ctr' style='width:100%'>";
                                            echo "<option value='$lbrand[code]'>$lbrand[name]</option>";
                                            $gbrand = mysqli_query($conn, 'SELECT * FROM `brand`') or die(mysqli_error($conn));
                                            while ($brand = mysqli_fetch_array($gbrand)) {
                                                echo "<option value='$brand[code]'>$brand[name]</option>";
                                            }
                                            echo "</select>";
                                            echo "</td>";
                                            echo "<td>";
                                            echo "<select class='form-control form item select2' name='item_$ctr' style='width:100%'>";
                                            echo "<option value='$fitem[code]'>$fitem[name]</option>";
                                            $gitem = mysqli_query($conn, 'SELECT * FROM `item`') or die(mysqli_error($conn));
                                            while ($item = mysqli_fetch_array($gitem)) {
                                                echo "<option value='$item[code]'>$item[name]</option>";
                                            }
                                            echo "</select>";
                                            echo "</td>";
                                            echo "<td><input type='text' class='form-control form hsncode'                name='hsncode_$ctr'       value='$tran[hsncode]'></td>";
                                            echo "<td><input type='text' class='form-control form text-right batch'     name='batch_$ctr'       value='$tran[batch]'></td>";
                                            echo "<td><input type='text' class='form-control form text-right actbatch'  name='actbatch_$ctr'    value='$tran[actbatch]' readonly></td>";
                                            echo "<td><input type='text' class='form-control form text-right taka'      name='taka_$ctr'        value='$tran[taka]'></td>";
                                            echo "<td><input type='text' class='form-control form text-right acttaka'   name='acttaka_$ctr'     value='$tran[acttaka]'></td>";
                                            echo "<td><input type='text' class='form-control form text-right qty'       name='qty_$ctr'         value='$tran[qty]'></td>";
                                            echo "<td><input type='text' class='form-control form text-right totqty'    name='totqty_$ctr'      value='$tran[totqty]' readonly></td>";
                                            echo "<td><input type='text' class='form-control form text-right flag'      name='flag_$ctr'        value='$tran[flag]'></td>";
                                            echo "<td><input type='text' class='form-control form text-right flagqty'   name='flagqty_$ctr'     value='$tran[flagqty]' readonly></td>";
                                            echo "<td><input type='text' class='form-control form text-right invqty'    name='invqty_$ctr'      value='$tran[invqty]' readonly></td>";
                                            echo "<td><input type='text' class='form-control form text-right rate'      name='rate_$ctr'        value='$tran[rate]'></td>";
                                            echo "<td><input type='text' class='form-control form text-right amount'    name='amount_$ctr'      value='$tran[amount]'></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>
                                                <select class="form-control form brand select2" name="brand_0" style='width:100%'>
                                                    <option value=""></option>
                                                    <?php
                                                        $gbrand = mysqli_query($conn, "SELECT * FROM `brand`") or die(mysqli_error($conn));
                                                        while ($brand = mysqli_fetch_array($gbrand)) {
                                                            echo "<option value='$brand[code]'>$brand[name]</option>";
                                                        }
                                                        ?>
                                                </select>
                                            </td>
                                            <td>
                                                <select class="form-control form item select2" name="item_0" style='width:100%'>
                                                    <option value=""></option>
                                                    <?php
                                                        $gitem = mysqli_query($conn, "SELECT * FROM `item`") or die(mysqli_error($conn));
                                                        while ($item = mysqli_fetch_array($gitem)) {
                                                            echo "<option value='$item[code]'>$item[name]</option>";
                                                        }
                                                        ?>
                                                </select>
                                            </td>
                                            <td><input type="text" class="form-control form text-left hsncode" tabindex="15" name="hsncode_0" value=""></td>
                                            <td><input type="text" class="form-control form text-right batch" name="batch_0" value="0"></td>
                                            <td><input type="text" class="form-control form text-left actbatch" tabindex="16" name="actbatch_0" value="" readonly></td>
                                            <td><input type="text" class="form-control form text-right taka" name="taka_0" value="0"></td>
                                            <td><input type="text" class="form-control form text-right acttaka" name="acttaka_0" value="0"></td>
                                            <td><input type="text" class="form-control form text-right qty" name="qty_0" value="0"></td>
                                            <td><input type="text" class="form-control form text-right totqty" name="totqty_0" value="0" readonly></td>
                                            <td><input type="text" class="form-control form text-right flag" name="flag_0" value="0"></td>
                                            <td><input type="text" class="form-control form text-right flagqty" name="flagqty_0" value="0" readonly></td>
                                            <td><input type="text" class="form-control form text-right invqty" name="invqty_0" value="0" readonly></td>
                                            <td><input type="text" class="form-control form text-right rate" name="rate_0" value="0"></td>
                                            <td><input type="text" class="form-control form text-right amount" name="amount_0" value="0"></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-success btn-square form" id="addnew">
                                <i class="fa fa-plus" style="color:#ffffff" 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-md-12 col-sm-12 col-xs-12  pad">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <div class="actions pull-right">
                            <i class="fa fa-chevron-down"></i>
                        </div>
                    </div>
                    <div class="panel-body">
                        <div class="row text-right pad">
                            <div class="col-lg-1 col-xs-1 text-right pad">
                                <label class="label-control marg">Remark</label>
                            </div>
                            <div class="col-lg-5 col-xs-5 text-right pad">
                                <input type="text" name="rem1" class="form-control form" value="<? echo ($addflag != 1) ? $get[remark1] : ""; ?>">
                            </div>
                            <div class="col-lg-3 col-xs-3 text-right pad">
                                <label class="label-control marg">SubTotal</label>
                            </div>
                            <div class="col-lg-3 col-xs-3">
                                <input type="text" class="form-control form subtotal text-right" value="<? echo ($addflag != 1) ? $get[subtotal] : "0"; ?>" name="subtotal" readonly>
                            </div>
                        </div>
                        <div class="row text-right pad">
                            <div class="col-lg-1 col-xs-1 text-right pad"></div>
                            <div class="col-lg-5 col-xs-5 text-right pad">
                                <input type="text" name="rem2" class="form-control form" value="<? echo ($addflag != 1) ? $get[remark2] : ""; ?>">
                            </div>
                            <div class="col-lg-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Less Discount</label>
                            </div>
                            <div class="col-lg-3 col-xs-3 pad">
                                <div class="col-lg-6">
                                    <input type="text" class="form-control form discperc text-right" value="<? echo ($addflag != 1) ? $get[discperc] : "0"; ?> " name="discperc">
                                </div>
                                <div class="col-lg-6">
                                    <input type="text" class="form-control form discount text-right" value="<? echo ($addflag != 1) ? $get[discount] : "0"; ?>" name="discount" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="row text-right pad">
                            <div class="col-lg-1 col-xs-1 text-right pad"></div>
                            <div class="col-lg-5 col-xs-5 text-right pad">
                                <!--<input type="text" name="rem3" class="form-control form" value="<? echo ($addflag != 1) ? $get[rem3] : ""; ?>">-->
                            </div>
                            <div class="col-lg-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Add Freight</label>
                            </div>
                            <div class="col-lg-3 col-xs-3 pad">
                                <div class="col-lg-6">
                                    <!--<input type="text" class="form-control form frgperc" value="<? echo ($addflag != 1) ? $get[frgperc] : "0"; ?>"  name="frgperc">-->
                                </div>
                                <div class="col-lg-6">
                                    <input type="text" class="form-control form freight text-right" value="<? echo ($addflag != 1) ? $get[freight] : "0"; ?>" name="freight">
                                </div>
                            </div>
                        </div>
                        <div class="row text-right pad">
                            <div class="col-lg-1 col-xs-1 text-right pad">
                                <label class='label-control marg'>&nbsp;</label>
                            </div>
                            <div class="col-lg-5 col-xs-5 text-right pad">
                                <!--<input type="text" name="rem4" class="form-control form" value="<? echo ($addflag != 1) ? $get[rem4] : ""; ?>" >-->
                            </div>
                            <div class="col-lg-3 col-xs-2 text-right pad">
                                <label class="label-control marg">Taxable Value</label>
                            </div>
                            <div class="col-lg-3 col-xs-3">
                                <div class="col-lg-5 pad">
                                    <!--<input type="text" class="form-control form frgperc numeric" value="<? echo ($addflag != 1) ? $get[frgperc] : ""; ?>"  name="frgperc" style="width: 80%">-->
                                </div>
                                <div class="col-lg-1 pad text-left">
                                    <!--<label class="label-control marg">%</label>-->
                                </div>
                                <div class="col-lg-6 pad">
                                    <input type="text" tabindex="28" class="form-control form taxamt numeric" value="<? echo ($addflag != 1) ? $get[tottaxamt] : "0"; ?>" name="taxamt" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="row text-right pad">
                            <div class="col-lg-1 col-xs-1 text-right pad">
                                <label class='label-control marg'>&nbsp;</label>
                            </div>
                            <div class="col-lg-6 col-xs-6 text-right pad">
                            </div>
                            <div class="col-lg-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Add CGST</label>
                            </div>
                            <div class="col-lg-3 col-xs-3">
                                <div class="col-lg-5 pad">
                                    <input type="text" tabindex="27" class="form-control form cgstperc numeric" value="<? echo ($addflag != 1) ? $get[cgstperc] : "0"; ?> " name="cgstperc" style="width: 80%" readonly>
                                </div>
                                <div class="col-lg-1 pad text-left">
                                    <label class="label-control marg">%</label>
                                </div>
                                <div class="col-lg-6 pad">
                                    <input type="text" tabindex="28" class="form-control form cgstamt numeric" value="<? echo ($addflag != 1) ? $get[totcgst] : "0"; ?>" name="totcgst" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="row text-right pad">
                            <div class="col-lg-1 col-xs-1 text-right pad">
                                <label class='label-control marg'>&nbsp;</label>
                            </div>
                            <div class="col-lg-6 col-xs-6 text-right pad">
                            </div>
                            <div class="col-lg-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Add SGST</label>
                            </div>
                            <div class="col-lg-3 col-xs-3">
                                <div class="col-lg-5 pad">
                                    <input type="text" tabindex="27" class="form-control form sgstperc numeric" value="<? echo ($addflag != 1) ? $get[sgstperc] : "0"; ?> " name="sgstperc" style="width: 80%" readonly>
                                </div>
                                <div class="col-lg-1 pad text-left">
                                    <label class="label-control marg">%</label>
                                </div>
                                <div class="col-lg-6 pad">
                                    <input type="text" tabindex="28" class="form-control form sgstamt numeric" value="<? echo ($addflag != 1) ? $get[totsgst] : "0"; ?>" name="totsgst" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="row text-right pad">
                            <div class="col-lg-1 col-xs-1 text-right pad">
                                <label class='label-control marg'>&nbsp;</label>
                            </div>
                            <div class="col-lg-6 col-xs-6 text-right pad">
                            </div>
                            <div class="col-lg-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Add IGST</label>
                            </div>
                            <div class="col-lg-3 col-xs-3">
                                <div class="col-lg-5 pad">
                                    <input type="text" tabindex="27" class="form-control form igstperc numeric" value="<? echo ($addflag != 1) ? $get[igstperc] : "0"; ?> " name="igstperc" style="width: 80%" readonly>
                                </div>
                                <div class="col-lg-1 pad text-left">
                                    <label class="label-control marg">%</label>
                                </div>
                                <div class="col-lg-6 pad">
                                    <input type="text" tabindex="28" class="form-control form igstamt numeric" value="<? echo ($addflag != 1) ? $get[totigst] : "0"; ?>" name="totigst" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="row text-right pad">
                            <div class="col-lg-1 col-xs-1 text-right pad"></div>
                            <div class="col-lg-5 col-xs-5 text-right pad">

                            </div>
                            <div class="col-lg-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Net Amount(Rs.)</label>
                            </div>
                            <div class="col-lg-3 col-xs-3">
                                <input type="text" class="form-control form netamt text-right" value="<? echo ($addflag != 1) ? $get[netamt] : ""; ?>" name="netamt" readonly>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 pad">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <?php include("includes/buttons.php"); ?>
                    </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">
                    <div class="row">
                        <div class="col-lg-2">
                            <select class="form-control sfield">
                                <option value="1">Voucher</option>
                                <option value="2">Date</option>
                                <option value="3">Party</option>
                                <option value="4">Type</option>
                                <option value="5">Godown</option>
                                <option value="6">Discount</option>
                                <option value="7">Freight</option>
                                <option value="8">Net Amount</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control soperator">
                                <option value="">Type of Search</option>
                                <option value="%">Like</option>
                                <option value="=">Exactly</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control sortBy">
                                <option value="">Sort By</option>
                                <option value="1">Voucher</option>
                                <option value="2">Date</option>
                                <option value="3">Party</option>
                                <option value="4">Type</option>
                                <option value="5">Godown</option>
                                <option value="6">Discount</option>
                                <option value="7">Freight</option>
                                <option value="8">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="5%">Voucher</th>
                                    <th width="10%">Date</th>
                                    <th width="30%">Party</th>
                                    <th width="10%">Type</th>
                                    <th width="5%">Godown</th>
                                    <th width="10%">Discount</th>
                                    <th width="10%">Freight</th>
                                    <th width="17%">Net Amount</th>
                                    <th width="3%">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>
    <!--    <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal"><span>&times;</span></button>
                        <h4 class="modal-title" id="myLargeModalLabel">Search <? echo $formname; ?></h4>
                    </div>
                    <div class="modal-body">
                        <div class="">
                            <table id="example1" class="table table-striped">
                                <thead>
                                    <tr style="background-color: #1ABC9C;">
                                        <th>Voucher</th>
                                        <th>Date</th>
                                        <th>Party</th>
                                        <th>Type</th>
                                        <th>Godown</th>
                                        <th>Discount</th>
                                        <th>Freight</th>
                                        <th>Net Amount</th>
                                        <th>Action</th>
                                    </tr>
                                </thead>
                                <tbody>
    <?php
    if ($addflag != 1) {
        $srchresult = mysqli_query($conn, "SELECT * FROM `$maindb`") or die(mysqli_error($conn));
        while ($row = mysqli_fetch_array($srchresult)) {
            $getsparty = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`='$row[party]'") or die(mysqli_error($conn));
            $sparty = mysqli_fetch_array($getsparty);
            $getstype = mysqli_query($conn, "SELECT * FROM `type` WHERE `code`='$row[type]'") or die(mysqli_error($conn));
            $stype = mysqli_fetch_array($getstype);
            //                                        $getsgodown = mysqli_query($conn, "SELECT * FROM `godown` WHERE `gocode`='$row[godown]'")or die(mysqli_error($conn));
            //                                        $sgodown    = mysqli_fetch_array($getsgodown);
            echo "<tr class='clickable-row' data-href='$file?mode=edit&$keyfld=$row[$keyfld]'>";
            echo "<td align='right'>$row[vouchno]</td>";
            echo "<td align='right'>$row[vouchdt]</td>";
            echo "<td align='left'>$sparty[name]</td>";
            echo "<td align='left'>$stype[name]</td>";
            echo "<td align='left'>$row[godown]</td>";
            echo "<td align='right'>$row[discount]</td>";
            echo "<td align='right'>$row[freight]</td>";
            echo "<td align='right'>$row[netamt]</td>";
            echo "<td align='center'><a href=\"$file?mode=edit&$keyfld=$row[$keyfld]\"><i class='fa fa-pencil' style='font-size:1.3em;color:#00C0EF;cursor:pointer;'></i></a></td>";
            echo "</tr>";
        }
    }
    ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="modal-footer"></div>
                </div>
            </div>
        </div>-->
    <?php include("includes/linksfoot.php"); ?>
</body>

</html>