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

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$admin = $_SESSION["admin_" . $dbname];

$formname = 'Inward';
$msource = "IN";

$maindb = 'inwmain';
$trandb = 'inwtran';
$stkdb = 'transacn';

$file = 'inward.php';
$grid = 'inwdmain.php';
?>

<!DOCTYPE HTML>
<html lang="en-US">

    <head>
        <meta charset="UTF-8">
        <title><?= $formname ?></title>
        <meta name="msapplication-TileColor" content="#5bc0de"/>
        <meta name="msapplication-TileImage" content="assets/img/metis-tile.png"/>

        <link rel="stylesheet" href="../../library/assets/lib/bootstrap/css/bootstrap.css">
        <link rel="stylesheet" href="../../library/assets/css/main.css"/>
        <link rel="stylesheet" href="../../library/assets/lib/Font-Awesome/css/font-awesome.css"/>

        <link rel="stylesheet" href="../../library/assets/css/theme.css">


        <link rel="stylesheet" href="../../library/assets/lib/uniform/themes/default/css/uniform.default.css">
        <link rel="stylesheet" href="../../library/assets/lib/inputlimiter/jquery.inputlimiter.1.0.css">
        <link rel="stylesheet" href="../../library/assets/lib/chosen/chosen.min.css">
        <link rel="stylesheet" href="../../library/assets/lib/colorpicker/css/colorpicker.css">
        <link rel="stylesheet" href="../../library/assets/lib/tagsinput/jquery.tagsinput.css">
        <link rel="stylesheet" href="../../library/assets/lib/daterangepicker/daterangepicker-bs3.css">
        <link rel="stylesheet" href="../../library/assets/lib/datepicker/css/datepicker.css">
        <link rel="stylesheet" href="../../library/assets/lib/timepicker/css/bootstrap-timepicker.min.css">

        <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/flick/jquery-ui.css">


        <script>
            (function(i, s, o, g, r, a, m) {
                i['GoogleAnalyticsObject'] = r;
                i[r] = i[r] || function() {
                    (i[r].q = i[r].q || []).push(arguments)
                }, i[r].l = 1 * new Date();
                a = s.createElement(o),
                        m = s.getElementsByTagName(o)[0];
                a.async = 1;
                a.src = g;
                m.parentNode.insertBefore(a, m)
            })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

            ga('create', 'UA-1669764-16', 'onokumus.com');
            ga('send', 'pageview');

        </script>

        <script src="assets/lib/modernizr-build.min.js"></script>
        <script type="text/javascript" src="../js/jquery.js"></script>


        <!--Begin Datatables-->
    <div class="row">
        <div class="col-lg-12">
            <div class="box">
                <header>
                    <div class="icons">
                        <i class="fa fa-table"></i>
                    </div>
                    <h5><a href='<?= $file ?>?mode=true'><i class='fa fa-edit'></i> Add <?= $formname ?></a></h5>
                </header>
                <div id="collapse4" class="body">
                    <table id="dataTable" class="table table-bordered table-condensed table-hover table-striped">
                        <thead>
                            <tr>
                                <th align='left'>Voucher</th>
                                <th align='left'>Voucher Date</th>
                                <th align='left'>Name</th>
                                <th align='left'>Bill Amount</th>
                                <th align='left'>Action</th>

                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $result = mysqli_query($conn, "SELECT * FROM inwmain  where vouchno != '' ORDER BY vouchno") or die(mysqli_error($conn));
                    
                            if (isset($_GET["vouchno"])) {
                                delete($zdb, "$maindb", "vouchno", $_GET["vouchno"], "$grid?vouchno=$_GET[vouchno]");
                                delete($zdb, "$trandb", "vouchno", $_GET["vouchno"], "$grid?vouchno=$_GET[vouchno]");
                              
                                $delcond = " source = '$msource' and vouchno = '$_GET[vouchno]' ";
                                delnew($zdb, "$stkdb", "$delcond", "$grid?vouchno=$_GET[vouchno]");
                             }
                            while ($row = mysqli_fetch_array($result)) {
                                $getparty = mysqli_query($conn, "SELECT `name` FROM `accmast` WHERE accode='$row[name]'") or die(mysqli_error($conn));
                                $party = mysqli_fetch_array($getparty);
                                echo "<tr>";
                                echo "<td align='left'>$row[vouchno]</td>";
                                echo "<td align='left'>$row[invdt]</td>";
                                echo "<td align='left'>$party[name]</td>";
                                echo "<td align='left'>$row[netamt]</td>";
                                echo "<td align='left'><a href=\"$file?vouchno=$row[vouchno]\"><img src='images/edit.png'></a>&nbsp;&nbsp;&nbsp;&nbsp;";
                                echo "<a href=\"?vouchno=$row[vouchno]\" onClick=\"return confirm('Confrim Delete?');\"><img src='images/delete.png'></a>";
                                echo "</td>";
                                echo "</tr>";
                            }
                            ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div><!-- /.row -->

    <!--End Datatables-->


    <script src="../../library/assets/lib/jquery.min.js"></script>
    <script src="../../library/assets/lib/bootstrap/js/bootstrap.min.js"></script>

    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
    <script src="../../library/assets/lib/datatables/jquery.dataTables.js"></script>
    <script src="../../library/assets/lib/datatables/DT_bootstrap.js"></script>
    <script src="../../library/assets/lib/tablesorter/js/jquery.tablesorter.min.js"></script>
    <script src="../../library/assets/lib/touch-punch/jquery.ui.touch-punch.min.js"></script>
    <script src="../../library/assets/js/main.min.js"></script>
    <script>
        $(function() {
            metisTable();
            metisSortable();
        });
    </script>
</body>
</html>                      