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


$formname = 'Purchase Return / Debit Note (Goods Return)';
$maindb = 'debmain';
$trandb = 'debtran';
$stkdb = 'transacn';
$accdb = 'actran';
$printfile = "debnote_print.php";
$file = 'debnote.php';
$trandbexist = 1;
$keyfld = "vouchno";

IF (isset($_GET[credtype]) != "") {
    $zcredtype = "$_GET[credtype]";
} ELSE {
    $zcredtype = "G";
}
$source = "PR";
$keycond = " AND `credtype`='$zcredtype' ";
$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$compcd = $_SESSION["comp_" . $dbname];

$myyear = $_SESSION[$myyear];

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

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"];
    $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"];

    $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"];
            $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"];

            $stkqty = $qty * -1;

//            browse($mitem);
            if (!empty($mitem)) {
                $srl = $srl + 1;

                mysqli_query($conn, "INSERT INTO `$trandb`(`vouchno`, `vouchdt`, `srno`, `barcode`, `item`, `qty`, `unit`, 
                                `mrp`, `rate`, `amount`, `discperc`, `discount`, `total`) 
                    VALUES ('$qvouch', '$vouchdt', '$srl', '$barcode', '$mitem', '$qty', '$unit', 
                                '$mrp', '$rate', '$amount', '$discperc', '$discount', '$total')") or die(mysqli_error($conn));

                ###############Stock Part############
                mysqli_query($conn, "INSERT INTO `$stkdb`(`vouchno`, `compcode`, `yearno`, `barcode`,  `vouchdt`, `srno`, `itemcode`, `qty`, `unit`,  `source`,
                                `mrp`, `rate`, `amount`, `group` ) 
                    VALUES ('$qvouch', '$compcd', '$myyear', '$barcode',  '$vouchdt', '$srl', '$barcode', '$stkqty', '$unit', '$source',
                                '$mrp', '$rate', '$amount', '$group')") or die(mysqli_error($conn));

                ###############Combine Stock Part############

                mysqli_query($conn, "INSERT INTO $zroot.$combstkdb(`vouchno`, `compcode`, `yearno`, `barcode`,  `vouchdt`, `srno`, `itemcode`, `qty`, `unit`,  `source`,
                                `mrp`, `rate`, `amount`, `group` ) 
                    VALUES ('$qvouch', '$compcd', '$myyear', '$barcode', '$vouchdt', '$srl', '$barcode', '$stkqty', '$unit', '$source',
                                '$mrp', '$rate', '$amount', '$group')") 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)
                    VALUES ('$vouchdt','$mvouch', '$source', '001', '$salecode','004', '$netamt')") OR die(mysqli_error($conn));

            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount)
                     VALUES ('$vouchdt','$mvouch', '$source', '002', '$party','009', '$minus_amt')") 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`) 
                        VALUES ('$qvouch', '$vouchdt', '$party', '$totqty', '$subtotal', '$litemdisc', '$cdiscperc', '$cdisamt', '$discperc', 
                        '$discount', '$netamt', '$ladvance', '$balance', '$lessoth', '$vatperc', '$vatamt', '$packing', '$prodtype',
                        '$remark1', '$remark2', 'G')") 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`='$subtotal', `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' 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);
}

$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/debnote.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`='009'")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>
                            <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>
                </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="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);

                                            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 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><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]'></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'   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' value='$tran[discount]' readonly></td>";
                                            Echo "<td><input type='number' step='any' class='form-control form text-right total'    name='total_$ctr'    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"></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 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><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_<?= $pctr ?>" 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=""></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></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></td>
                                            <td><input type='number' step='any' class="form-control form text-right total"    name="total_0"       value="0" readonly></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 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">
                                    <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 text-right">
                                        <label class="label-control marg">Add Vat</label>
                                    </div>
                                    <div class="col-lg-2 pad">
                                        <input type="text" class="form-control form vatperc text-right" value="<? Echo ($addflag != 1) ? $get[vatperc] : "0"; ?> "  name="vatperc">
                                    </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 vatamt text-right" value="<? Echo ($addflag != 1) ? $get[vatamt] : "0"; ?>" name="vatamt" 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">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-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 id="example1" class="table table-striped">
                            <thead>
                                <tr class="mySearchTr">
                                    <th style="text-align: center">Voucher</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 `vouchno`,`vouchdt`,`party`,`prodtype`,`netamt` FROM `$maindb` where `vouchno`!='' $keycond 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[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>
