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

// ini_set('display_errors', 1);
// error_reporting(E_ERROR);  

$formname = 'Purchase Return / Debit Note (Others)';
$maindb = 'debmain';
$trandb = 'deboth';
$accdb = 'actran';

$printfile = "deboth_print.php";
$file = 'debothgst.php';
$trandbexist = 1;
$keyfld = "vouchno";
if (isset($_GET['credtype']) != "") {
    $zcredtype = "$_GET[credtype]";
} else {
    $zcredtype = "O";
}

$source = "PRFP";

$keycond1 = " AND `credtype`='$zcredtype' ";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$username = $_SESSION["username_" . $dbname];

$myyear = $_SESSION[$myyear];

$zyear = right($zdb, 4);
$zStartDate = getzdates($zyear, 'S', $comp);
$zEndDate = getzdates($zyear, 'E', $comp);

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

if (isset($_POST["submit"])) {
    $a = 1;
    $vouchdt = $_POST["vouchdt"];
    $party = $_POST["party"];
    $invno = $_POST["invno"];
    $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"];
    $unclaimgst = $_POST["unclaimgst"];
    $oms = $_POST["oms"];
    $taxamt = $_POST["taxamt"];

    $totcgst = $_POST["totcgst"];
    $totsgst = $_POST["totsgst"];
    $totigst = $_POST["totigst"];

    $cgstperc = $_POST["cgstperc"];
    $sgstperc = $_POST["sgstperc"];
    $igstperc = $_POST["igstperc"];

    $gstperc = $_POST["gstperc"];
    $roundoff = $_POST["roundoff"];

    $count = $_POST["items"];

    $mvouch = $qvouch;

    $salecode = 12;

    if ($a == 1) {

        mysqli_query($conn, "LOCK TABLES `$maindb` WRITE,  $trandb WRITE,  $accdb WRITE,  accmast WRITE, billsett WRITE") or die(mysqli_error($conn));

        #################################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"];
            $descrip = $_POST["descrip_$i"];
            $amount = $_POST["amount_$i"];

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

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

        $billflag = $_POST['billflag'];

        if ($billflag == 1) {
            mysqli_query($conn, "DELETE FROM `billsett` WHERE `bnkvouch` = '$mvouch' AND `source` = '$source'   ") or die(mysqli_error($conn));
            $counter = $_POST["counter"];

            for ($i = 0; $i <= $counter; $i++) {
                $myearno = $_POST["yearno_" . $i];
                $mvouchno = $_POST["vouchno_" . $i];
                $mbillno = $_POST["billno_" . $i];
                $msetoff = $_POST["setoff_" . $i];
                $mdays = $_POST["days_" . $i];
                $mbillsrc = $_POST["billsrc_" . $i];

                if (!empty($msetoff)) {
                    mysqli_query($conn, "INSERT INTO `billsett`(`yearno`, `type`, `vouchno`, `billno`, `setoff`, `party`, `source`, `bnkvouch`, `bankinit`, nodays, billsrc,bnkdate)
                                VALUES('$myearno', 'P', '$mvouchno', '$mbillno', '$msetoff', '$party', '$source', '$mvouch', '$bankinit', '$mdays', '$mbillsrc','$vouchdt')") or die(mysqli_error($conn));
                }
            }
        }



        ############################## MAIN ######################################################
        if ($addflag == 1) {
            mysqli_query($conn, "INSERT INTO `$maindb`(`vouchno`, `vouchdt`, `party`,  invno, `totqty`, `subtotal`, `litemdisc`, 
                        `netamt`, `vatperc`, `vatamt` , `packing`, `unclaimgst`,
                        `remark1`, `remark2`, `credtype`, `oms`, `cgstperc`, `sgstperc`, `igstperc`, `totcgst`, `totsgst`, 
                                            `totigst`, `tottaxamt`, `gstperc`, `roundoff`, `adduser`) 
                        VALUES ('$qvouch', '$vouchdt', '$party',  '$invno', '$totqty', '$subtotal', '$litemdisc', 
                        '$netamt','$vatperc', '$vatamt', '$packing', '$unclaimgst', 
                        '$remark1', '$remark2', 'O','$oms', '$cgstperc', '$sgstperc', '$igstperc', '$totcgst', '$totsgst',
                                             '$totigst', '$taxamt', '$gstperc', '$roundoff', '$username')") or die(mysqli_error($conn));
            insmess();
            $mvouch = $qvouch; //1
        } else {
            $mvouch = $qvouch; //1

            mysqli_query($conn, "UPDATE `$maindb` SET `vouchdt`='$vouchdt', `party`='$party',  invno='$invno',
                    `totqty`='$totqty',`subtotal`='$subtotal', `vatperc`='$vatperc', `vatamt`='$vatamt', `packing`='$packing',
                    `litemdisc`='$litemdisc',
                    `netamt`='$netamt',`remark1`='$remark1', `unclaimgst`='$unclaimgst', 
                    `remark2`='$remark2', `credtype`='O',  `oms`='$oms',`cgstperc`='$cgstperc', `roundoff`='$roundoff',
                    `sgstperc`='$sgstperc', `igstperc`='$igstperc', `totcgst`='$totcgst', `totsgst`='$totsgst', 
                    `totigst`='$totigst', `tottaxamt`='$taxamt',`gstperc`='$gstperc', `edituser`='$username' WHERE `vouchno`='$qvouch'") or die(mysqli_error($conn));
        }



        ############################## Accounts Part ######################################################

        if ($unclaimgst != 1) {
            $cgst5code = 36;
            $sgst5code = 37;
            $igst5code = 38;

            $cgst12code = 39;
            $sgst12code = 40;
            $igst12code = 41;

            $cgst18code = 42;
            $sgst18code = 43;
            $igst18code = 44;

            $cgst28code = 45;
            $sgst28code = 46;
            $igst28code = 47;
        } else {
            $cgst5code = 26;
            $sgst5code = 27;
            $igst5code = 28;

            $cgst12code = 29;
            $sgst12code = 30;
            $igst12code = 31;

            $cgst18code = 32;
            $sgst18code = 33;
            $igst18code = 34;

            $cgst28code = 48;
            $sgst28code = 49;
            $igst28code = 50;
        }

        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', '004', '$taxamt', '$prodtype', '$taxamt')") 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', '009', '$minus_amt', '$prodtype', '$minus_amt')") or die(mysqli_error($conn));

            if ($roundoff != 0) {
                mysqli_query($conn, "INSERT INTO `$accdb`(`date`, `vouchno`, `source`, `trnno`, `accode`, `grpcode`, `amount`)
                                                                VALUES ('$vouchdt', '$mvouch', '$source', '004', '25', '012', '$roundoff')") or die(mysqli_error($conn));
            }


            if ($oms != 1) {
                if ($cgstperc == 2.5) {
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$cgst5code','020', '$totcgst')") or die(mysqli_error($conn));
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$sgst5code','020', '$totcgst')") or die(mysqli_error($conn));
                }
                if ($cgstperc == 6) {
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$cgst12code','020', '$totcgst')") or die(mysqli_error($conn));
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$sgst12code','020', '$totcgst')") or die(mysqli_error($conn));
                }
                if ($cgstperc == 9) {
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$cgst18code','020', '$totcgst')") or die(mysqli_error($conn));
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$sgst18code','020', '$totcgst')") or die(mysqli_error($conn));
                }
                if ($cgstperc == 14) {
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$cgst28code','020', '$totcgst')") or die(mysqli_error($conn));
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$sgst28code','020', '$totcgst')") or die(mysqli_error($conn));
                }
                
            } else {
                if ($igstperc == 5) {
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$igst5code','020', '$totigst')") or die(mysqli_error($conn));
                }
                if ($igstperc == 12) {
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$igst12code','020', '$totigst')") or die(mysqli_error($conn));
                }
                if ($igstperc == 18) {
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$igst18code','020', '$totigst')") or die(mysqli_error($conn));
                }
                if ($igstperc == 28) {
                    mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,source, trnno, accode, grpcode, amount)
                                           VALUES ('$vouchdt','$mvouch', '$source', '003', '$igst28code','020', '$totigst')") or die(mysqli_error($conn));
                }
            }
        }
        if ($addflag == 1) {
            header("refresh: 1; $file?mode=edit&$keyfld=$mvouch&form=$form");
        } else {
            //            updmess();
            header("refresh: 1; $file?mode=edit&$keyfld=$mvouch&form=$form");
        }
        mysqli_query($conn, "UNLOCK TABLES");
    }
}

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=O");
    delete($zdb, "$trandb", "$keyfld", $_GET[$keyfld], "$file?mode=last&credtype=O");
    $delcond = " source = '$source' and vouchno = '$_GET[vouchno]' ";

    delnew($zdb, "$accdb", "$delcond", "$file?mode=last&credtype=O");
}

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

</head>

<body>
    <form action='' method='POST'>
        <div class="col-lg-3 pad text-center" id="overlay_form" style="display:none;z-index:999;">
            <button type="button" id="close_form" style="float: right;font-weight: bold;font-size: 18px;color:red;"><i class="fa fa-close"></i></button>
            <div style='width:100%;' id='browdata'>
            </div>
        </div>
        <!-- Default box -->
        <div>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12  pad">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <input type="hidden" value="<?= $zStartDate ?>" style="width: 1px;border: none" class="zstdate">
                        <input type="hidden" value="<?= $zEndDate ?>" style="width: 1px;border: none" class="zenddate">
                        <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 billflag" name="billflag" value="0">

                            </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 vouchdt" 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 party  select2" name="party" style="width: 100%" required>
                                    <option value="<?php echo ($addflag != 1) ? $get["party"] : ""; ?>"><?php echo ($addflag != 1) ? $lparty["name"] : ""; ?></option>
                                    <?php
                                    $gbrk = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE (`grpcode`='009' OR `grpcode`='006')  ORDER by name") or die(mysqli_error($conn));
                                    while ($pbrk = mysqli_fetch_array($gbrk)) {
                                        echo "<option value='$pbrk[accode]'>$pbrk[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>
                                                        <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 class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Against Invoice</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" class="form-control form invno" value="<?php echo ($addflag != 1) ? $get["invno"] : ""; ?>" name="invno">
                            </div>
                        </div>
                        <div class="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 code") 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="panel-body">
                        <div class="table-responsive">
                            <table class="table table-striped table-condensed table-bordered" width="100%">
                                <thead class="mySearchTr">
                                    <tr>
                                        <th width="5%"></th>
                                        <th width="5%" class='text-right'>Sr.</th>
                                        <th width="70%" class='text-left'>Description</th>
                                        <th width="20%" class='text-right'>Amount</th>
                                    </tr>
                                </thead>
                                <tbody class="tbody">
                                    <?php
                                    if ($addflag != 1) {
                                        $ctr = 0;
                                        $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$get[vouchno]' ORDER BY `srno`") or die(mysqli_error($conn));
                                        while ($tran = mysqli_fetch_array($gettran)) {
                                            echo "<tr>";
                                            echo "<td><i class='fa fa-close remove' style='display:none;'></i></td>";
                                            echo "<td><input type='text' class='form-control form text-right srno' name='srno_$ctr' value='$tran[srno]'></td>";
                                            echo "<td>";
                                            echo "<input type='text' class='form-control form descrip' name='descrip_$ctr' value='$tran[descrip]'>";
                                            echo "</td>";
                                            echo "<td>";
                                            echo "<input type='number' step='any' class='form-control text-right form amount' name='amount_$ctr' value='$tran[amount]'>";
                                            echo "</td>";
                                            echo "</tr >";
                                            $ctr++;
                                        }
                                    } else {
                                    ?>
                                        <tr>
                                            <td><i class="fa fa-close remove"></i></td>
                                            <td><input type="text" class="form-control form text-right srno" name="srno_0" value="1"></td>
                                            <td><input type="text" class="form-control form itemcode barcode" name="descrip_0" name="descrip"></td>
                                            <td><input type='number' step='any' 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-primary btn-square form" id="addnew">
                                <i class="fa fa-plus" data-toggle='tooltip' title='Add Row'></i>
                            </button>
                            <input type="hidden" id="items" name="items" value="<?php echo ($addflag != 1) ? $ctr : 1; ?>" />
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12  pad">
                <div class="panel panel-default">
                    <div class="">
                    </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">
                                    <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-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'] : "0"; ?> " 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'] : "0"; ?> " 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'] : "0"; ?> " 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">Round Off</label>
                                    </div>
                                    <div class="col-lg-3 pad">
                                        <input type="text" class="form-control form roundoff text-right " value="<? echo ($addflag != 1) ? $get['roundoff'] : "0"; ?>" name="roundoff">
                                    </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="panel panel-default">
                <div class="panel-body">
                    <div class="col-lg-1">
                    </div>
                    <div class="col-lg-9 col-md-9 col-sm-11 col-xs-11 pad">
                        <?php include("includes/buttons.php"); ?>
                    </div>
                    <div class="col-lg-2 pad">
                        <input type="button" id="finishTab" class="btn btn-primary pull-right form mySearchTr" style="color: #fff;" value="Check & Finish">
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade " tabindex="" id="settmodal" 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">Bill Settlement</h4>
                    </div>
                    <div class="modal-body">
                        <div class=" table-responsive">
                            <div class="toolbar">
                                <div class="row">
                                    <div class="col-lg-2"><label class="label-control marg" style="color:red">Total Remain</label></div>
                                    <div class="col-lg-2"><input type="text" id="remain" name="remain" class="form-control" readonly style=""></div>
                                    <div class="col-lg-2"><label class="label-control marg" style="color:blue">Total Setoff</label></div>
                                    <div class="col-lg-2"><input type="text" id="totsetoff" name="totsetoff" class="form-control" readonly style=""></div>
                                    <!--<div class="col-lg-2"><input id="submit" type='submit' name='submit' value='<?php // echo ($addflag == 0) ? "Update" : "Save";                                   
                                                                                                                    ?>' class="btn btn-primary"></div>-->
                                    <?php
                                    //                                    if (!isset($_GET["method"])) {
                                    ?>
                                    <!--<div class="col-lg-2"><input type='button' name='exit' value='Exit' class="btn btn-danger" onClick="window.location.href = '<?php echo $grid; ?>'"></div>-->
                                    <?php // }      
                                    ?>
                                </div>
                            </div>
                            </header>
                            <div id="div-2" class="accordion-body collapse in body">
                                <div style="max-height:300px;overflow: auto; border: 0px solid;">
                                    <div id="data"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer"></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 id="example1" class="table table-striped">
                            <thead>
                                <tr class="mySearchTr">
                                    <th style="text-align: center">Voucher</th>
                                    <th style="text-align: center">Invoice No.</th>
                                    <th style="text-align: center">Date</th>
                                    <th style="text-align: center">Party</th>
                                    <th style="text-align: center">Product Type</th>
                                    <th style="text-align: center">Net Amount</th>
                                    <th style="text-align: center">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                if ($addflag != 1) {
                                    $srchresult = mysqli_query($conn, "SELECT * FROM `$maindb` where `vouchno`!='' $keycond1 ORDER BY `vouchdt` DESC") 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);
                                        //                                        $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='center'>$row[vouchno]</td>";
                                        echo "<td align='center'>$row[invno]</td>";
                                        echo "<td align='center'>$row[vouchdt]</td>";
                                        echo "<td align='center'>$sparty[name]</td>";
                                        echo "<td align='center'>$row[prodtype]</td>";
                                        echo "<td align='center'>$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>