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

$maindb = 'purmain';
$trandb = 'purtran';
$accdb = 'actran';
$printfile = "purchase_print.php";
$file = 'purchasenew.php';

$trandbexist = 1;
$comp = $_SESSION["comp_" . $dbname];
$myyear = $_SESSION[$myyear];

$gtype = $_GET['type'];
$formname = 'Purchase Entry';
$source = "PUN";
$stkdb = 'transacn';

$para = "";
$keycond = "";
$keyfld = "vouchno";
$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$zyear = right($zdb, 4);
$comp = $_SESSION["comp_" . $dbname];
$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;

    $qvouch = $_POST["vouchno"];
    $vouchdt = $_POST["vouchdt"];
    $invno = $_POST["invno"];
    $party = $_POST["party"];
    $type = $_POST["type"];
    $bankname = $_POST["bankname"];
    $totalqty = $_POST["totalqty"];
    $subtotal = $_POST["subtotal"];
    $addpack = $_POST["addpack"];
    $netamt = $_POST["netamt"];

    $remark1 = trim($_POST["remark1"]);
    $remark2 = trim($_POST["remark2"]);


    $mvouch = $qvouch;

    if ($paidby == "R") {
        $purcode = '12';
    } else {
        $purcode = '11';
    }

    $oms = $_POST['oms'];

    $count = $_POST["items"];


    if ($a == 1) {

        mysqli_query($conn, "LOCK TABLES `$maindb` WRITE, `$trandb` WRITE, `product` WRITE, `$stkdb` WRITE, `$accdb` WRITE, `cashpay` WRITE, `accmast` WRITE");

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

        ######################## auto cash Entry Start ######################################

        $mcashvouch = $_POST["cashvouch"];

        if ($type != 'R') {
            if ($mcashvouch == '0' || $mcashvouch == '') {
                $gen1 = mysqli_query($conn, "SELECT MAX(vouchno+0) AS maxcode FROM `cashpay` where vouchno!=''  LIMIT 0,1 ") or die(mysqli_error($conn));
                if (mysqli_num_rows($gen1) > 0) {
                    $vvouch = mysqli_fetch_assoc($gen1);
                    $tcashvouch = $vvouch["maxcode"] + 1;
                } else {
                    $tcashvouch = '1';
                }
                $mcashvouch = $tcashvouch;
            }

            if ($type == "C") {
                $bankname = 3;
            }

            $getbankinit = mysqli_query($conn, "SELECT grpcode, bankinit FROM `accmast` WHERE `accode` = '$bankname'") or die(mysqli_error($conn));
            $bankinit = mysqli_fetch_array($getbankinit);
            $binit = $bankinit['bankinit'];
            $bgrp = $bankinit['grpcode'];

            mysqli_query($conn, "DELETE FROM `cashpay` WHERE `$keyfld`='$mcashvouch' ") or die(mysqli_error($conn));

            mysqli_query($conn, "DELETE FROM `$accdb` WHERE vouchno='$mcashvouch' AND `source`='CP' ") or die(mysqli_error($conn));

            $minus_amt = ($netamt * -1);

            // cash part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, bankinit, accode, grpcode, amount)
                                                VALUES ('$vouchdt', '$mcashvouch', 'CP', '001', '$binit', '$bankname', '$bgrp', '$netamt')") or die(mysqli_error($conn));

            // party part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount)
                                                VALUES ('$vouchdt', '$mcashvouch', 'CP', '002', '$party', '009', '$minus_amt')") or die(mysqli_error($conn));

            mysqli_query($conn, "INSERT INTO `cashpay`( vouchno ,`vouchdt`, `bankname`, `bankinit`, `party`, `type`, `amount`, `remark1`, `trnflag`)
                                           Values ('$mcashvouch', '$vouchdt', '$bankname', '$binit', '$party', '$type', '$netamt', 'Cash Paid For Purchase No.$mvouch', 'S')") or die(mysqli_error($conn));
        } else {
            mysqli_query($conn, "DELETE FROM `cashpay` WHERE `$keyfld`='$mcashvouch' ") or die(mysqli_error($conn));
            mysqli_query($conn, "DELETE FROM `actran` WHERE `$keyfld`='$mcashvouch' AND `source`='CP' ") or die(mysqli_error($conn));
            $mcashvouch = "";
        }

        ######################## auto cash Entry End ######################################


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


        $cnt = 0;
        $cntamt = 0;

        for ($i = 0; $i < $count; $i++) {
            $msrno = $_POST["srno_$i"];
            $mitem = mysqli_real_escape_string($conn, $_POST["itemname_$i"]);
            $cartqty = $_POST["cartqty_$i"];
            $loosepairs = $_POST["loosepairs_$i"];
            $qty = $_POST["qty_$i"];
            $totqty = $_POST["totqty_$i"];
            $cost = $_POST["cost_$i"];
            $amount = $_POST["amount_$i"];


            $mitemcode = mysqli_query($conn, "SELECT code,cost FROM `product` WHERE `name`='$mitem'") or die(mysqli_error($conn));
            $icode = mysqli_fetch_array($mitemcode);
            $itcode = $icode['code'];

            $cnt++;
            $group = $source . $mvouch;

            if (!empty($mitem)) {

                mysqli_query($conn, "INSERT INTO `$trandb`(`vouchno`, `vouchdt`, `srno`, `itemcode`, `itemname`, `cartqty`, `loosepairs`, `qty`, `totqty`, `cost`, `amount`)
                                                  VALUES('$mvouch', '$vouchdt', '$cnt', '$itcode', '$mitem', '$cartqty', '$loosepairs', '$qty', '$totqty', '$cost', '$amount')") or die(mysqli_error($conn));


                mysqli_query($conn, "INSERT INTO `$stkdb`(`srno`, `yearno`, `source`, `vouchno`, `vouchdt`, `itemcode`,  `cartqty`,
                                                          `qty`, `totqty`, `cost`, `amount`, `accode`)
                                                   VALUES('$cnt', '$myyear', '$source', '$mvouch', '$vouchdt', '$itcode',  '$cartqty',
                                                         '$qty',  '$totqty', '$cost', '$amount', '$party')") or die(mysqli_error($conn));
            }
        }

        mysqli_query($conn, "DELETE FROM `$accdb` WHERE `vouchno` = '$mvouch' AND `source` = '$source' ") OR die(mysqli_error($conn));
        if ($netamt > 0) {

            $minus_amt = $netamt * -1;

            // Purchase part
            mysqli_query($conn, "INSERT INTO `$accdb`(`date`, vouchno, source, trnno, accode, grpcode, amount)
                                              VALUES ('$vouchdt','$mvouch', '$source', '001', '$purcode','004', '$minus_amt')") or die(mysqli_error($conn));

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

        }


        ######################### STOCK PART ####################################################
        if ($addflag == 1) {
            $newvoucher = $mono . $mvouch;

            mysqli_query($conn, "INSERT INTO `$maindb`(`vouchno`, `vouchdt`, `invno`, `party`, `remark1`, `remark2`, 
                                                       `totalqty`, `subtotal`, `addpack`, `netamt`, `cashvouch`, `bankname`, `type`)
                                                VALUES('$mvouch', '$vouchdt', '$invno', '$party', '$remark1', '$remark2', 
                                                       '$totalqty', '$subtotal', '$addpack', '$netamt', '$mcashvouch', '$bankname', '$type')") or die(mysqli_error($conn));

            //            $_SESSION['print_voucher'] = $mvouch;
        } else {

            mysqli_query($conn, "UPDATE `$maindb` SET  `vouchdt`='$vouchdt', `invno`='$invno', `party`='$party',  
                                                       `remark1`='$remark1', `remark2`='$remark2', `totalqty`='$totalqty',
                                                       `cashvouch`='$mcashvouch', `bankname`='$bankname', `type`='$type'
                                                        WHERE `vouchno` = '$mvouch' ") or die(mysqli_error($conn));
        }
        mysqli_query($conn, "UNLOCK TABLES");
        if ($addflag == 1) {
            insmess();
            header("refresh: 1; $file?mode=edit&$keyfld=$mvouch");
        } else {
            updmess();
            header("refresh: 1; $file?mode=edit&$keyfld=$mvouch");
        }
    }
}
if ($addflag != 1) {

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

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

    $delcsh = $get['cashvouch'];

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

    $getbank = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode` = '$get[bankname]' ") or die(mysqli_error($conn));
    $banknm = mysqli_fetch_array($getbank);

    $printdisabled = "none";
}


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

if (isset($_GET["delete"])) {
    mysqli_query($conn, "LOCK TABLES `$maindb` WRITE, `$trandb` WRITE, `$stkdb` WRITE, `$accdb` WRITE, `cashpay` WRITE") or die(mysqli_error($conn));

    $delcond = " source = '$source' and vouchno = '$_GET[vouchno]' ";
    $delcond2 = " vouchno = '$_GET[vouchno]' ";
    $delcond3 = " vouchno = '$delcsh'  ";
    $delcond4 = " source = 'CP' and vouchno = '$delcsh'";

    delnew($zdb, "$maindb", "$delcond2", "$file?mode=last$para");
    delnew($zdb, "$trandb", "$delcond2", "$file?mode=last$para");
    delnew($zdb, "$accdb", "$delcond", "$file?mode=last$para");
    delnew($zdb, "$stkdb", "$delcond", "$file?mode=last$para");
    delnew($zdb, "cashpay", "$delcond3", "$file?mode=last");
    delnew($zdb, "$accdb", "$delcond4", "$file?mode=last");

    mysqli_query($conn, "UNLOCK TABLES");
}

include("includes/linkshead.php");
?>

<script src="MyScript/purchasenew.js?a=<?= mt_rand(); ?>" type="text/javascript"></script>
<script src="MyScript/purchasenew_search.js?b=<?= mt_rand(); ?>" type="text/javascript"></script>
<script src="MyScript/checkdate.js" type="text/javascript"></script>
<style>
    .button-29 {
        align-items: center;
        appearance: none;
        background-color: #c1c1c1;
        /* Filled by default */
        border: 2px solid #c1c1c1;
        border-radius: 6px;
        box-sizing: border-box;
        color: #ffffff;
        /* White text on filled background */
        cursor: pointer;
        display: inline-flex;
        font-family: "JetBrains Mono", monospace;
        font-size: 16px;
        height: 40px;
        padding: 0 20px;
        justify-content: center;
        line-height: 1.2;
        text-decoration: none;
        transition: all 0.2s ease;
        user-select: none;
        white-space: nowrap;
        will-change: box-shadow, transform;
        width: auto;
    }

    .button-29:hover {
        background-color: transparent;
        color: #c1c1c1;
        border: 2px solid #c1c1c1;
        box-shadow: none;
        transform: none;
    }

    .button-29:active {
        transform: scale(0.98);
        box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
    }
</style>
</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-9 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:#78909C"><a class="myPrint"><?php echo $formname; ?></a>
                        </h3>
                    </div>
                </div>
                <div class="panel-body">
                    <input type="date" value="<?= $zStartDate ?>" style="display: none;border: none" class="zstdate">
                    <input type="date" value="<?= $zEndDate ?>" style="display: none;border: none" class="zenddate">
                    <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-1 col-sm-2 col-xs-2 pad">
                            <input type="text" name="vouchno" class="form-control form vouchno"
                                value="<?php echo ($addflag != 1) ? $get['vouchno'] : $qvouch ?>" readonly
                                tabindex="-1">
                            <input type="hidden" class="form-control addflag" value="<?php echo $addflag ?>">
                            <input type="hidden" name="source" class="form-control form source" value="<?= $source; ?>"
                                id="source">
                        </div>

                        <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                            <label class="label-control marg">Date</label>
                        </div>
                        <div class="col-lg-1 col-md-1 col-sm-2 col-xs-2 pad">
                            <input type="date" class="form-control form vouchdt focusfield" name="vouchdt"
                                value="<?php echo ($addflag != 1) ? $get["vouchdt"] : date("Y-m-d") ?>" autofocus>
                        </div>

                        <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                            <label class="label-control marg">Invoice</label>
                        </div>
                        <div class="col-lg-1 col-md-1 col-sm-2 col-xs-2 pad">
                            <input type="number" class="form-control form invno" name="invno"
                                value="<?php echo ($addflag != 1) ? $get["invno"] : $qvouch ?>">
                        </div>

                        <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                            <label class="label-control marg">Party</label>
                        </div>
                        <div class="col-lg-4 col-md-4 col-sm-3 col-xs-3 pad">
                            <select name="party" class="form-control form party select2" id="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' order by name") or die(mysqli_error($conn));
                                while ($fparty = mysqli_fetch_array($gparty)) {
                                    echo "<option value='$fparty[accode]'>$fparty[name]</option>";
                                }
                                ?>
                            </select>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right pad ">
                            <label class="label-control marg">Mode</label>
                        </div>
                        <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                            <select id="type" name="type" class="select2 form-control form type" required>
                                <?php
                                $typeOptions = [
                                    'R' => 'Credit',
                                    'U' => 'UPI / Bank',
                                    'C' => 'Cash'
                                ];

                                foreach ($typeOptions as $value => $label) {
                                    $selected = ($get['type'] == $value) ? 'selected' : '';
                                    echo "<option value=\"$value\" $selected>$label</option>";
                                }
                                ?>
                            </select>
                        </div>
                        <div class="showcashbank">
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right pad">
                                <label class="label-control marg">Bank</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <select id="bankname" name="bankname" class="form-control form select2 bankname"
                                    style="width:100%">
                                    <option value="<?php echo ($addflag != 1) ? $banknm['accode'] : ""; ?>">
                                        <?php echo ($addflag != 1) ? $banknm['name'] : ""; ?>
                                    </option>
                                    <?php
                                    $mown1 = mysqli_query($conn, "SELECT accode, `name` FROM `accmast` WHERE accode != '3' AND (`grpcode` = '002' or grpcode = '001') ") or die(mysqli_error($conn));
                                    while ($trow1 = mysqli_fetch_array($mown1)) {
                                        echo "<option value='$trow1[accode]'>$trow1[name]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="table-responsive" style="overflow-y: scroll;height: 400px">
                        <table class="table-striped table-condensed table-bordered tab" width="100%">
                            <thead class="mySearchTr">
                                <tr>
                                    <th style="width: 1%"></th>
                                    <th style="width: 2%">Sr.</th>
                                    <th style="width: 25%;">Item Name</th>
                                    <th style='width: 6%' class="text-right">No. of Pairs</th>
                                    <th style='width: 6%' class="text-right">Qty.</th>
                                    <th style='width: 6%' class="text-right">Total Pairs</th>
                                    <th style='width: 6%' class="text-right">Cost</th>
                                    <th style='width: 8%' class="text-right">Amount</th>
                                </tr>
                            </thead>
                            <tbody class="tbody">
                                <?php

                                // Fetching distinct item names for the datalist
                                echo "<datalist id='ditems'>";
                                $gitem = mysqli_query($conn, "SELECT DISTINCT `name` FROM `product` ORDER BY `name`") or die(mysqli_error($conn));
                                while ($item = mysqli_fetch_assoc($gitem)) {
                                    echo "<option value='" . htmlspecialchars($item['name'], ENT_QUOTES) . "'>";
                                }
                                echo "</datalist>";

                                if ($addflag != 1) {

                                    $qry = mysqli_query($conn, "SELECT * FROM  `$trandb` WHERE vouchno='$getvouch' ORDER BY srno") or die(mysqli_error($conn));
                                    $ctr = 0;
                                    while ($row = mysqli_fetch_array($qry)) {

                                        $getitem = mysqli_query($conn, "SELECT code, name FROM `product` WHERE code = '$row[itemcode]'") or die(mysqli_error($conn));
                                        $geti = mysqli_fetch_array($getitem);

                                        if ($row['loosepairs'] == 1) {
                                            $rdtb = "";
                                            $rdtbqty = "tabindex='-1' readonly";
                                        } else {
                                            $rdtbqty = "";
                                            $rdtb = "tabindex='-1' readonly";
                                        }

                                        echo "<tr>";
                                        echo "<td><i class='fa fa-close remove' style='display:none;'></i></td>";
                                        echo "<td><input type='text' name='srno_$ctr' class='srno form-control  form'  value='$row[srno]'></td>";
                                        echo "<td><input list='ditems' name='itemname_$ctr' class='itemname form-control form' value='" . htmlspecialchars($geti['name'], ENT_QUOTES) . "' autocomplete='off' required></td>";
                                        echo "<td><input type='number' name='cartqty_$ctr' class='cartqty form-control text-right  form' value='$row[cartqty]' readonly tabindex='-1'>
                                                  <input type='hidden' name='loosepairs_$ctr' class='loosepairs form-control form' value='$row[loosepairs]' ></td>";
                                        echo "<td><input type='number' step='any' name='qty_$ctr' class='qty form-control  text-right form' value='$row[qty]' $rdtbqty></td>";
                                        echo "<td><input type='number' step='any' name='totqty_$ctr' class='totqty form-control text-right  form' value='$row[totqty]' $rdtb></td>";
                                        echo "<td><input type='number' step='any' name='cost_$ctr' class='cost form-control text-right  form' value='$row[cost]' ></td>";
                                        echo "<td><input type='number' step='any' name='amount_$ctr' id='amount_$ctr' class='amount form-control text-right  form'  value='$row[amount]' tabindex='-1' readonly></td>";
                                        echo "</tr>";
                                        $ctr++;
                                    }
                                } else {
                                    ?>
                                    <tr>
                                        <td><i class='fa fa-close remove'></i></td>
                                        <td><input type='text' name='srno_0' class='srno form-control form' value='1'></td>
                                        <td><input list='ditems' name='itemname_0' class='itemname form-control form'
                                                value='' autocomplete="off" required></td>
                                        <td><input type='number' name='cartqty_0'
                                                class='cartqty text-right form-control form' value='0' readonly
                                                tabindex='-1'>
                                            <input type='hidden' name='loosepairs_0' class='loosepairs form-control form'
                                                value=''>
                                        </td>
                                        <td><input type="number" step="any" name='qty_0'
                                                class='qty form-control text-right form zero' value='0'></td>
                                        <td><input type="number" step="any" name='totqty_0'
                                                class='totqty form-control text-right form zero' tabindex='-1' value='0'
                                                readonly></td>
                                        <td><input type="number" step="any" name='cost_0'
                                                class='cost form-control text-right form zero' value='0'></td>
                                        <td><input type="number" step="any" name='amount_0' id="amount_0"
                                                class='amount text-right form-control form zero' value='0' tabindex='-1'
                                                readonly></td>
                                    </tr>
                                    <?php
                                }
                                ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="col-lg-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-6 col-xs-12 pad">
                            <div class="col-lg-12 col-xs-12 pad">
                            </div>
                            <div class="col-lg-12 col-xs-12 pad">
                                <div class="col-lg-3 pad text-right">
                                    <label class="label-control marg">Remarks</label>
                                </div>
                                <div class="col-lg-9 pad">
                                    <input type="text" name="remark1" class="form-control form "
                                        value="<? echo ($addflag != 1) ? $get["remark1"] : ""; ?>">
                                </div>
                            </div>
                            <div class="col-lg-12 col-xs-12 pad">
                                <div class="col-lg-3 pad text-right"></div>
                                <div class="col-lg-9 pad">
                                    <input type="text" name="remark2" class="form-control form "
                                        value="<? echo ($addflag != 1) ? $get["remark2"] : ""; ?>">
                                </div>
                            </div>
                        </div>

                        <div class="col-lg-6 col-xs-12 pad">
                            <div class="col-lg-12 col-xs-12 pad">
                                <div class="col-lg-1 pad"></div>
                                <div class="col-lg-2 label-control marg text-right pad">Total Qty.</div>
                                <div class="col-lg-3 pad">
                                    <input type="number" step="any" name="totalqty"
                                        class="form-control form text-right totalqty"
                                        value="<?php echo ($addflag != 1) ? $get['totalqty'] : "0"; ?>" readonly
                                        tabindex="-1">
                                </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="number" step="any" name="subtotal"
                                        class="form-control form text-right totamt subtotal"
                                        value="<?php echo ($addflag != 1) ? $get['subtotal'] : "0"; ?>" readonly
                                        tabindex="-1">
                                </div>
                            </div>

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

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


                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-9 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>
    </form>


    <div class="modal fade PurchCreateModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-lg" style="margin-top: 5%;">
            <div class="modal-content" style="width: 550px;border-radius:10px;">
                <div class="modal-header">
                    <label class="label-control marg"><b style="color:red"> Add Product </b></label>
                </div>

                <div class="modal-body">

                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                            <label class="label-control marg">Name</label>
                        </div>
                        <div class="col-lg-6 col-md-6 col-sm-8 col-xs-8 pad">
                            <input type="text" class="form-control form mprodname" name="mprodname" maxlength="40"
                                value="" style="border: 1px solid #778da9;border-radius:4px" required>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                            <label class="label-control marg">Cost</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                            <input type="text" class="form-control form mcost text-right" name="mcost" value=""
                                style="border: 1px solid #778da9;border-radius:4px" required>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                            <label class="label-control marg">Rate</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                            <input type="text" class="form-control form mrate text-right" name="mrate" value=""
                                style="border: 1px solid #778da9;border-radius:4px">
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                            <label class="label-control marg">No. of Pairs</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                            <input type="text" class="form-control form mcartqty text-right" name="mcartqty" value=""
                                style="border: 1px solid #778da9;border-radius:4px">
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                            <label class="label-control marg">Loose Pairs</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                            <input type="checkbox" class="form-control form mloosepairs text-right" name="mloosepairs"
                                value="1" style="border: 1px solid #778da9;border-radius:4px">
                        </div>
                    </div>

                    <br>

                    <div class="row">
                        <div class="col-lg-3 text-center"></div>
                        <div class="col-lg-3 text-center">
                            <input type="button" class="btn button-29 saveent" value="Create">
                        </div>
                        <div class="col-lg-3 text-center">
                            <button class="button-29 close1" data-dismiss="modal">Close</button>
                        </div>
                    </div>

                    <div id="loadingIndicator" style="display: none;">
                        <div class="spinner"></div>
                        <span>Saving data, please wait...</span>
                    </div>

                </div>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>

    <div class="modal fade searchModal bs-example-modal-lg" tabindex="-1" role="dialog"
        aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-lg" style="margin-top: 15%">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span>&times;</span></button>
                    <h4 class="modal-title" id="myLargeModalLabel">Search <? echo $formname; ?></h4>
                </div>
                <div class="modal-body">
                    <input type="hidden" value="<?php echo $fseries ?>" class="form-control series">
                    <input type="hidden" value="<?php echo $get['vouchno']; ?>" class="form-control vouchno">
                    <input type="hidden" value="<?php echo $file ?>" class="form-control file">
                    <input type="hidden" value="<?php echo $gtype ?>" class="form-control para">
                    <div class="row">
                        <div class="col-lg-2">
                            <select class="form-control sfield">
                                <option value="1">Voucher</option>
                                <option value="2">Date</option>
                                <option value="3">Party</option>
                                <option value="4">Net Amount</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control soperator">
                                <option value="">Type of Search</option>
                                <option value="%">Like</option>
                                <option value="=">Exactly</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control sortBy">
                                <option value="">Sort By</option>
                                <option value="1">Voucher</option>
                                <option value="2">Date</option>
                                <option value="3">Party</option>
                                <option value="4">Net Amount</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control orderAs">
                                <option value="desc">Desc</option>
                                <option value="asc">Asc</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <input type="text" value="" class="form-control ssearch" placeholder="Search Here">
                        </div>
                        <div class="col-lg-2">
                            <input type="button" class="btn btn-primary sload" value="Search">
                        </div>
                    </div>
                    <div class="col-lg-12 sloader text-center">
                        <img src="images/search.gif" alt="loading">
                    </div>
                    <div class="col-lg-12 snoRecord text-center">
                        <h3>NO RECORDS FOUND</h3>
                    </div>
                    <div class="table-responsive" style="max-height: 400px;overflow: auto;">
                        <table id="" class="table table-striped table-condensed table-bordered" width="100%">
                            <thead>
                                <tr class="mySearchTr">
                                    <th width="10%">Voucher</th>
                                    <th width="10%">Date</th>
                                    <th width="20%">Party</th>
                                    <th width="10%" class="text-right">Net Amount</th>
                                    <th width="10%">Action</th>
                                </tr>
                            </thead>
                            <tbody class="sTbody">
                            </tbody>
                        </table>
                    </div>
                    <div class="row">
                        <div class="col-xs-12 text-right search-action-bar">
                            <input type="button" class="btn btn-primary sprevious" value="Previous">
                            <input type="button" class="btn btn-primary snext" value="Next">
                        </div>
                    </div>
                </div>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>

    <?php include("includes/linksfoot.php"); ?>
</body>

</html>