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

$formname = 'Sale Return / Credit Note (Goods Return)';
$maindb = 'credmain';
$trandb = 'credtran';
$stkdb = 'transacn';
$accdb = 'actran';
$printfile = "crednote_print.php";
$file = 'crednotegst.php';
$trandbexist = 1;
$keyfld = "vouchno";

IF (isset($_GET[credtype]) != "") {
    $zcredtype = "$_GET[credtype]";
} ELSE {
    $zcredtype = "G";
}

$source = "SR";
$keycond = " AND `credtype`='$zcredtype' ";

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

//$stkdb1 = 'tran';
$zroot = $_SESSION["zdir"];
//$combstkdb = $stkdb1 . $myyear;

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



if (isset($_POST["submit"])) {
    $a = 1;
    $vouchdt = $_POST["vouchdt"];
    $party = $_POST["party"];
    $subtotal = $_POST["subtotal"];
    $litemdisc = $_POST["litemdisc"];
    $cdiscperc = $_POST["cdiscperc"];
    $cdisamt = $_POST["cdisamt"];
    $netamt = $_POST["netamt"];
    $ladvance = $_POST["ladavnce"];
    $balance = $_POST["balance"];
    $remark1 = $_POST["remark1"];
    $remark2 = $_POST["remark2"];
    $lessoth = $_POST["lessoth"];
    $vatperc = $_POST["vatperc"];
    $vatamt = $_POST["vatamt"];
    $packing = $_POST["packing"];
    $prodtype = $_POST["prodtype"];

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

    $count = $_POST["items"];

    $mvouch = $qvouch;

    $salecode = 15;

    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));
//        mysqli_query($conn, "DELETE FROM $zroot.$combstkdb WHERE `$keyfld`='$mvouch' AND `source`='$source' and `compcode`='$compcd'")or die(mysqli_error($conn));

        $group = $source . $mvouch;

        $srl = 0;
        for ($i = 0; $i < $count; $i++) {
            $msrno = $_POST["srno_$i"];
            $barcode = $_POST["barcode_$i"];
            $color = $_POST["color_$i"];
            $mitem = $_POST["item_$i"];
            $qty = $_POST["qty_$i"];
            $mrp = $_POST["mrp_$i"];
            $rate = $_POST["rate_$i"];
            $unit = $_POST["unit_$i"];
            $amount = $_POST["amount_$i"];
            $discperc = $_POST["discperc_$i"];
            $discount = $_POST["discount_$i"];
            $total = $_POST["total_$i"];

//            browse($unit);
            if (!empty($mitem)) {
                $srl = $srl + 1;
                mysqli_query($conn, "INSERT INTO `$trandb`(`vouchno`, `vouchdt`, `srno`, `barcode`, `item`, `qty`, `unit`, color,
                                `mrp`, `rate`, `amount`, `discperc`, `discount`, `total`) 
                    VALUES ('$qvouch', '$vouchdt', '$srl', '$barcode', '$mitem', '$qty', '$unit', '$color',
                                '$mrp', '$rate', '$amount', '$discperc', '$discount', '$total')") or die(mysqli_error($conn));

                ############Stock Part #################
                mysqli_query($conn, "INSERT INTO `$stkdb`(`vouchno`, `compcode`, `yearno`,  `vouchdt`, `srno`, `barcode`, `itemcode`, `qty`, `unit`,  `source`,
                                `mrp`, `rate`, `amount`, `group`,color ) 
                                        VALUES ('$qvouch', '$compcd', '$myyear', '$vouchdt', '$srl', '$barcode', '$barcode', '$qty', '$unit', '$source',
                                '$mrp', '$rate', '$amount', '$group','$color')") 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);

            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount,prodtype,actamt)
                    VALUES ('$vouchdt','$mvouch', '$source', '001', '$salecode','005', '$minus_amt','$prodtype','$minus_amt')") OR die(mysqli_error($conn));

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

        ############################## MAIN ######################################################
        if ($addflag == 1) {
            mysqli_query($conn, "INSERT INTO `$maindb`(`vouchno`, `vouchdt`, `party`, `totqty`, `subtotal`, `litemdisc`, `cdiscperc`, `cdisamt`, `discperc`, 
                        `discount`, `netamt`, `ladvance`, `balance`, `lessoth`, `vatperc`, `vatamt` , `packing`, `prodtype`,
                        `remark1`, `remark2`, `credtype`, `oms`, `cgstperc`, `sgstperc`, `igstperc`, `totcgst`, `totsgst`, 
                                            `totigst`, `tottaxamt`, `gstperc`) 
                        VALUES ('$qvouch', '$vouchdt', '$party', '$totqty', '$subtotal', '$litemdisc', '$cdiscperc', '$cdisamt', '$discperc', 
                        '$discount', '$netamt', '$ladvance', '$balance', '$lessoth', '$vatperc', '$vatamt', '$packing', '$prodtype',
                        '$remark1', '$remark2', 'G', '$oms', '$cgstperc', '$sgstperc', '$igstperc', '$totcgst', '$totsgst',
                                             '$totigst', '$taxamt', '$gstperc')") or die(mysqli_error($conn));
            insmess();
            $mvouch = $qvouch; //1
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit&credtype=G");
        } else {
            $mvouch = $qvouch; //1

            mysqli_query($conn, "UPDATE `$maindb` SET `vouchdt`='$vouchdt', `party`='$party', `prodtype`='$prodtype',
                    `totqty`='$totqty',`subtotal`='$total', `lessoth`='$lessoth', `vatperc`='$vatperc', `vatamt`='$vatamt', `packing`='$packing',
                    `litemdisc`='$litemdisc',`cdiscperc`='$cdiscperc', `cdisamt`='$cdisamt',
                    `discperc`='$discperc',`discount`='$discount',`netamt`='$netamt',`ladvance`='$ladvance',`balance`='$balance',`remark1`='$remark1',
                    `remark2`='$remark2', `credtype`='G', `oms`='$oms',`cgstperc`='$cgstperc',
                    `sgstperc`='$sgstperc', `igstperc`='$igstperc', `totcgst`='$totcgst', `totsgst`='$totsgst', 
                    `totigst`='$totigst', `tottaxamt`='$taxamt',`gstperc`='$gstperc' WHERE `vouchno`='$qvouch'") or die(mysqli_error($conn));
            updmess();
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit&credtype=G");
        }
    }
}

if ($addflag != 1) {

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

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

    $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 `saletype` WHERE code='$get[gstperc]'") or die(mysqli_error($conn));
    $fetgst = mysqli_fetch_array($getgst);
}

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

if (isset($_GET["delete"])) {
    delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last&credtype=G");
    delete($zdb, "$trandb", "$keyfld", $_GET[$keyfld], "$file?mode=last&credtype=G");
    $delcond = " source = '$source' and vouchno = '$_GET[vouchno]' ";
    delnew($zdb, "$stkdb", "$delcond", "$file?mode=last&credtype=G");
    delnew($zdb, "$accdb", "$delcond", "$file?mode=last&credtype=G");
//    delnew($zroot, "$combstkdb", "$delcond", "$file?mode=last&credtype=G");
}

include("includes/linkshead.php");
?>
<!--<script src="MyScript/debnotegstcrd.js" type="text/javascript"></script>-->
<script src="MyScript/crednotegst.js" type="text/javascript"></script>

<!--<script src="MyScript/crednotegst.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">
                        <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" name="vouchno" value="<?php Echo ($addflag != 1) ? $get["vouchno"] : " $qvouch"; ?>" required readonly>
                            </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-3 col-md-5 col-sm-5 col-xs-5 pad">
                                <select class="form-control form  select2" name="party" style="width: 100%" required>
                                    <option value="<?php Echo ($addflag != 1) ? $get["party"] : ""; ?>"><?php Echo ($addflag != 1) ? $lparty["name"] : ""; ?></option>
                                    <?php
                                    $gparty = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `grpcode`='010'")or die(mysqli_error($conn));
                                    while ($party = mysqli_fetch_array($gparty)) {
                                        Echo "<option value='$party[accode]'>$party[name]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                            <!--                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                                            <label class="label-control marg">Product Type</label>
                                                        </div>-->
                            <input type="hidden" name="prodtype" class="prodtype" value="O">
                            <!--                            <div class="col-lg-1 col-md-8 col-sm-8 col-xs-8 pad">
                                                            <select class="form-control form prodtype select2" name="prodtype" style="width: 100%" required>
                            
                                                                <option value=""></option>
                                                                <option value='P'<?php
//                                    if ($addflag != 1) {
//                                        if ($get["prodtype"] == "P") {
//                                            echo "selected='selected'";
//                                        }
//                                    }
                            ?>>Perfumes</option>
                                                                <option value='O'<?php
//                                    if ($addflag != 1) {
//                                        if ($get["prodtype"] == "O") {
//                                            echo "selected='selected'";
//                                        }
//                                    }
                            ?>>Others</option>
                                                            </select>
                                                        </div>-->
                        </div>
                        <div clsss="row">
                            <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Out Of State</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="checkbox"  class="form-control form oms" <?php
                                if ($get[oms] == "1") {
                                    Echo "checked";
                                }
                                ?> value="1" name="oms">                            
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-2 text-right pad">
                                <label class="label-control marg" style="color: #78909C">GST %</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-2 pad">
                                <select name="gstperc" class="form-control form gstperc ">
                                    <option value="<?php Echo ($addflag != 1) ? $fetgst["code"] : ""; ?>"><?php Echo ($addflag != 1) ? $fetgst["name"] : ""; ?></option>
                                    <?
                                    $getgst = mysqli_query($conn, "SELECT * FROM `saletype` where `code`!='' ORDER BY per")or die(mysqli_error($conn));
                                    while ($fetgst = mysqli_fetch_array($getgst)) {
                                        Echo "<option value='$fetgst[code]'>$fetgst[name]</option>";
                                    }
                                    ?>
                                </select>
                            </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="">
                                                                            <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  class="mySearchTr">
                                        <tr>
                                            <th width="3%"></th>
                                            <th width="4%" class='text-right'>Sr.</th>
                                            <th width="7%" class='text-left'>Barcode</th>
                                            <th width="20%">Item</th>
                                            <th width="10%">Color</th>
                                            <th width="7%" class='text-right'>Qty.</th>
    <!--                                            <th width="7%" >Unit</th>
                                            <th width="8%" class='text-right'>Mrp</th>-->
                                            <th width="8%" class='text-right'>Rate(P.A.D)</th>
                                            <th width="10%" class='text-right'>Amount</th>
                                            <th width="7%" class='text-right'>Discperc</th>
                                            <th width="8%" class='text-right'>Discount</th>
                                            <th width="10%" class='text-right'>Total</th>
    <!--                                        <th width="1%" style="display: none;" class='text-right'>Msp</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 `code`,`name` FROM `item` WHERE `code`='$tran[item]'") or die(mysqli_error($conn));
                                                $fitem = mysqli_fetch_array($finditem);

                                                $findcolor = mysqli_query($conn, "SELECT `code`,`name` FROM `color` WHERE `code`='$tran[color]'") or die(mysqli_error($conn));
                                                $fcolor = mysqli_fetch_array($findcolor);

                                                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]' tabindex='-1'></td>";
                                                Echo "<td>";
                                                Echo "<input type='text' class='form-control form itemcode' name='barcode_$ctr' value='$tran[barcode]'>";
                                                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` order by name')or die(mysqli_error($conn));
                                                while ($item = mysqli_fetch_array($gitem)) {
                                                    Echo "<option value='$item[code]'>$item[name]</option>";
                                                }
                                                Echo "</select>";
                                                Echo "</td>";
                                                Echo "<td>";
                                                Echo "<select class='form-control form color select2' name='color_$ctr' style='width:100%'>";
                                                Echo "<option value='$fcolor[code]'>$fcolor[name]</option>";
                                                $gcolor = mysqli_query($conn, "SELECT `code`,`name` FROM `item` order by name")or die(mysqli_error($conn));
                                                while ($color = mysqli_fetch_array($gcolor)) {
                                                    Echo "<option value='$color[code]'>$color[name]</option>";
                                                }
                                                Echo "</select>";
                                                Echo "</td>";
                                                Echo "<td><input type='number' step='any' class='form-control form text-right qty'      name='qty_$ctr'      value='$tran[qty]'></td>";
//                                                Echo "<td>";
//                                                Echo "<select class='form-control form fetchpart_$ctr select2 unit' name='unit_$ctr' style='width:100%'>";
//                                                Echo "<option value='$tran[unit]'>$tran[unit]</option>";
//                                                $gunit = mysqli_query($conn, 'SELECT * FROM `unit` order by name')or die(mysqli_error($conn));
//                                                while ($unit = mysqli_fetch_array($gunit)) {
//                                                    Echo "<option value='$unit[name]'>$unit[name]</option>";
//                                                }
//                                                Echo "</select>";
//                                                Echo "</td>";
//                                            Echo "<td><input type='text'  class='form-control form unit'                name='unit_$ctr'     value='$tran[unit]' readonly></td>";
//                                                Echo "<td><input type='number' step='any' class='form-control form text-right mrp'      name='mrp_$ctr'      value='$tran[mrp]'>
//                                                 <input type='number' step='any' class='form-control form text-right msp'      name='msp_$ctr'      value='$tran[msp]' style='display:none;' readonly>
//                                                    </td>";
                                                Echo "<td><input type='number' step='any' class='form-control form text-right rate'     name='rate_$ctr'     value='$tran[rate]'></td>";
                                                Echo "<td><input type='number' step='any' class='form-control form text-right amount'   name='amount_$ctr' tabindex='-1'  value='$tran[amount]' readonly></td>";
                                                Echo "<td><input type='number' step='any' class='form-control form text-right discperc' name='discperc_$ctr' value='$tran[discperc]'></td>";
                                                Echo "<td><input type='number' step='any' class='form-control form text-right discount' name='discount_$ctr' tabindex='-1' value='$tran[discount]' readonly></td>";
                                                Echo "<td><input type='number' step='any' class='form-control form text-right total'    name='total_$ctr'  tabindex='-1'   value='$tran[total]' readonly></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" tabindex='-1'></td>
                                                <td><input type="text" class="form-control form itemcode barcode" name="barcode_0" name="barcode"></td>
                                                <td>
                                                    <select name="item_0" class="form-control form select2 item ">
                                                        <option value=""></option>
                                                        <?
                                                        $getitem = mysqli_query($conn, "SELECT * FROM `item` ORDER BY name")or die(mysqli_error($conn));
                                                        while ($item1 = mysqli_fetch_array($getitem)) {
                                                            Echo "<option value='$item1[code]'>$item1[name]</option>";
                                                        }
                                                        ?>
                                                    </select>
                                                </td>
                                                <td>
                                                    <select class="form-control form color select2" name="color_0" style='width:100%'>
                                                        <option value=""></option>
                                                        <?php
                                                        $gcolor = mysqli_query($conn, "SELECT * FROM `color` order by name")or die(mysqli_error($conn));
                                                        while ($color = mysqli_fetch_array($gcolor)) {
                                                            Echo "<option value='$color[code]'>$color[name]</option>";
                                                        }
                                                        ?>
                                                    </select>
                                                </td>
                                                <td><input type='number' step='any' class="form-control form text-right qty"      name="qty_0"         value="0"></td>
        <!--                                                <td>
                                                    <select class='form-control form select2 unit' name="unit_0" style='width:100%'>
                                                        <option value=""></option>
                                                <?php
//                                                        $gunit = mysqli_query($conn, 'SELECT * FROM `unit` order by name')or die(mysqli_error($conn));
//                                                        while ($unit = mysqli_fetch_array($gunit)) {
//                                                            Echo "<option value='$unit[name]'>$unit[name]</option>";
//                                                        }
                                                ?>
                                                    </select>
                                                </td>-->
                                                <!--<td><input type="text" class="form-control form unit"                name="unit_0"        value="" readonly></td>-->
        <!--                                                <td><input type='number' step='any' class="form-control form text-right mrp"      name="mrp_0"         value="0">
                                                    <input type="hidden" class="form-control form text-right msp"      name="msp_0"         value="0" readonly>
                                                </td>-->
                                                <td><input type='number' step='any' class="form-control form text-right rate"     name="rate_0"        value="0"></td>
                                                <td><input type='number' step='any' class="form-control form text-right amount"   name="amount_0"      value="0" readonly  tabindex="-1"></td>
                                                <td><input type='number' step='any' class="form-control form text-right discperc" name="discperc_0"    value="0"></td>
                                                <td><input type='number' step='any' class="form-control form text-right discount" name="discount_0"    value="0" readonly  tabindex="-1"></td>
                                                <td><input type='number' step='any' class="form-control form text-right total"    name="total_0"       value="0" readonly tabindex="-1"></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="+" />-->

                            </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 class="actions pull-right">
                                                                                <i class="fa fa-chevron-down"></i>
                                                                            </div>
                                                </div>
                                                <div class="panel-body">-->
                            <div class="col-lg-12 col-xs-12 pad">
                                <div class="col-lg-6 col-xs-12 pad">
                                    <div class="col-lg-12 col-xs-12 pad">
                                        <button type="button" class="btn btn-primary btn-square form"  id="addnew">
                                            <i class="fa fa-plus" data-toggle='tooltip' title='Add Row'></i>    
                                        </button>
                                        <input type="hidden" id="items" name="items" value="<?php echo ($addflag != 1) ? $ctr : 1; ?>" />  
                                    </div>
                                    <div class="col-lg-12 col-xs-12 pad">
                                        <div class="col-lg-3 pad text-right">
                                        </div>
                                        <div class="col-lg-6 pad">
                                        </div>
                                    </div>
                                    <div class="col-lg-12 col-xs-12 pad">
                                        <div class="col-lg-3 pad text-right">
                                        </div>
                                        <div class="col-lg-2 pad text-right">
                                        </div>
                                        <div class="col-lg-1 pad text-left">
                                        </div>
                                        <div class="col-lg-2 pad">
                                        </div>
                                        <div class="col-lg-1 pad">
                                        </div>
                                        <div class="col-lg-3 pad">
                                        </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 remark1" 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 remark2" value="<? Echo ($addflag != 1) ? $get["remark2"] : ""; ?>">
                                        </div>
                                    </div>

                                </div>

                                <div class="col-lg-6 col-xs-12 pad">
                                    <div class="col-lg-12 col-xs-12 pad">
                                        <div class="col-lg-3 pad">

                                        </div>
                                        <div class="col-lg-3 pad"></div>
                                        <div class="col-lg-3 pad text-right">
                                            <label class="label-control marg">SubTotal</label>
                                        </div>
                                        <div class="col-lg-3 pad">
                                            <input type="text" class="form-control form subtotal text-right" value="<? Echo ($addflag != 1) ? $get[subtotal] : "0"; ?>" name="subtotal" readonly>
                                        </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">Less Item Discount</label>
                                        </div>
                                        <div class="col-lg-3 pad">
                                            <input type="text" class="form-control form litemdisc text-right" value="<? Echo ($addflag != 1) ? $get[litemdisc] : "0"; ?>" name="litemdisc" readonly>
                                        </div>
                                    </div>
                                    <div class="col-lg-12 col-xs-12 pad">
                                        <div class="col-lg-3 pad"></div>
                                        <div class="col-lg-3 pad text-right">
                                            <label class="label-control marg">Less Cash Discount</label>
                                        </div>
                                        <div class="col-lg-2 pad">
                                            <input type="text" class="form-control form cdicsperc text-right" value="<? Echo ($addflag != 1) ? $get[cdiscperc] : "0"; ?> "  name="cdiscperc">
                                        </div>
                                        <div class="col-lg-1 pad">
                                            <label class="label-control marg">%</label>
                                        </div>
                                        <div class="col-lg-3 pad">
                                            <input type="text" class="form-control form cdiscamt text-right" value="<? Echo ($addflag != 1) ? $get[cdisamt] : "0"; ?>" name="cdisamt" readonly>
                                        </div>
                                    </div>
                                    <div class="col-lg-12 col-xs-12 pad">
                                        <div class="col-lg-5 pad text-right">
                                            <label class="label-control marg">Less Other</label>
                                        </div>
                                        <div class="col-lg-2 pad text-right">

                                        </div>

                                        <div class="col-lg-2 pad">
                                        </div>
                                        <div class="col-lg-3 pad">
                                            <input type="text" class="form-control form lessoth text-right" value="<? Echo ($addflag != 1) ? $get[lessoth] : "0"; ?>" name="lessoth">
                                        </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="text" class="form-control form packing text-right" value="<? Echo ($addflag != 1) ? $get[packing] : "0"; ?>" name="packing">
                                        </div>
                                    </div>-->
                                    <div class="col-lg-12 col-md-12 col-xs-12 pad">
                                        <div class="col-lg-4 col-md-3 pad"></div>
                                        <div class="col-lg-5 col-md-3  pad">
                                            <label class="label-control marg">Taxable Value</label>
                                            <!--<label class="label-control marg">Less Other</label>-->
                                        </div>
                                        <div class="col-lg-3 col-md-3 pad"></div>
                                        <div class="col-lg-3 col-md-3 pad">
                                            <input type="text" class="form-control form taxamt numeric" value="<? Echo ($addflag != 1) ? $get[tottaxamt] : "0"; ?>" name="taxamt" readonly>
                                        </div>
                                    </div>
                                    <div class="col-lg-12 col-xs-12 pad">
                                        <div class="col-lg-4 pad">   
                                            <!--<input type="button" name="gendsotp" class="form-control gendsotp form" style="color:red;border: none;" value="Generate Discount OTP">-->
                                        </div>
                                        <div class="col-lg-2 pad ">
                                            <label class="label-control marg">Add CGST</label>
                                        </div>
                                        <div class="col-lg-2 pad">
                                            <input type="text" class="form-control form cgstperc numeric" value="<? Echo ($addflag != 1) ? $get[cgstperc] : "$gstperc"; ?> "  name="cgstperc" readonly>
                                        </div>
                                        <div class="col-lg-1 pad">
                                            <label class="label-control marg">%</label>
                                        </div>
                                        <div class="col-lg-3 pad">
                                            <input type="text" class="form-control form cgstamt numeric" value="<? Echo ($addflag != 1) ? $get[totcgst] : "0"; ?>" name="totcgst" readonly>
                                        </div>
                                    </div>
                                    <div class="col-lg-12 col-xs-12 pad">
                                        <div class="col-lg-4 pad">   
                                            <!--<input type="button" name="gendsotp" class="form-control gendsotp form" style="color:red;border: none;" value="Generate Discount OTP">-->
                                        </div>
                                        <div class="col-lg-2 pad ">
                                            <label class="label-control marg">Add SGST</label>
                                        </div>
                                        <div class="col-lg-2 pad">
                                            <input type="text" class="form-control form sgstperc numeric" value="<? Echo ($addflag != 1) ? $get[sgstperc] : "$gstperc"; ?> "  name="sgstperc" readonly>
                                        </div>
                                        <div class="col-lg-1 pad">
                                            <label class="label-control marg">%</label>
                                        </div>
                                        <div class="col-lg-3 pad">
                                            <input type="text" class="form-control form sgstamt numeric" value="<? Echo ($addflag != 1) ? $get[totsgst] : "0"; ?>" name="totsgst" readonly>
                                        </div>
                                    </div>
                                    <div class="col-lg-12 col-xs-12 pad">
                                        <div class="col-lg-4 pad">   
                                            <!--<input type="button" name="gendsotp" class="form-control gendsotp form" style="color:red;border: none;" value="Generate Discount OTP">-->
                                        </div>
                                        <div class="col-lg-2 pad">
                                            <label class="label-control marg">Add IGST</label>
                                        </div>
                                        <div class="col-lg-2 pad">
                                            <input type="text" class="form-control form igstperc numeric" value="<? Echo ($addflag != 1) ? $get[igstperc] : "$gstperc"; ?> "  name="igstperc" readonly>
                                        </div>
                                        <div class="col-lg-1 pad">
                                            <label class="label-control marg">%</label>
                                        </div>
                                        <div class="col-lg-3 pad">
                                            <input type="text" class="form-control form igstamt numeric" value="<? Echo ($addflag != 1) ? $get[totigst] : "0"; ?>" name="totigst" readonly>
                                        </div>
                                    </div>
                                    <div class="col-lg-12 col-xs-12 pad">
                                        <div class="col-lg-3 pad"></div>
                                        <div class="col-lg-3 pad"></div>
                                        <div class="col-lg-3 pad text-right">
                                            <label class="label-control marg">Netamt (Rs.)</label>
                                        </div>
                                        <div class="col-lg-3 pad">
                                            <input type="text" class="form-control form netamt text-right" value="<? Echo ($addflag != 1) ? $get[netamt] : "0"; ?>" name="netamt" readonly> 
                                        </div>
                                    </div>
                                </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" 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-responsive">
                        <table id="example1" class="table table-striped">
                            <thead>
                                <tr class="mySearchTr" style="background-color: #78909C;">
                                    <th>Voucher</th>
                                    <th>Date</th>
                                    <th>Party</th>
                                    <!--<th>Product Type</th>-->
                                    <th>Net Amount</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                if ($addflag != 1) {
                                    $srchresult = mysqli_query($conn, "SELECT * FROM `$maindb` where `vouchno`!='' $keycond")or die(mysqli_error($conn));
                                    while ($row = mysqli_fetch_array($srchresult)) {
                                        $getsparty = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`='$row[party]'")or die(mysqli_error($conn));
                                        $sparty = mysqli_fetch_array($getsparty);
                                        echo "<tr class='clickable-row' data-href='$file?mode=edit&$keyfld=$row[$keyfld]'>";
                                        echo "<td align='left'>$row[vouchno]</td>";
                                        echo "<td align='left'>$row[vouchdt]</td>";
                                        echo "<td align='left'>$sparty[name]</td>";
//                                        echo "<td align='left'>$row[prodtype]</td>";
                                        echo "<td align='left'>$row[netamt]</td>";
                                        echo "<td align='left'><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>
