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

$formname = "K.O.T.";

$maindb = 'kotmain';
$trandb = 'kottran';
$file = 'kotent.php';
$keyfld = "vouchno";

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

include("includes/linkshead.php");
$curdate = date("Y-m-d");
?>
<script src="MyScript/dashboard.js" type="text/javascript"></script>
</head>
<body>
    <form method='POST'>
        <!-- Default box -->
        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 pad">
            <div class="panel panel-default">
                <h4 style="margin: 0px; background-color: #ff9999"><?php Echo "Pending Orders"; ?>
                    <!--<span style="font-size: 10px;color:white">&nbsp;&nbsp;&nbsp;(Note: For Detail Click on Table No.)</span>-->
                </h4>
                <div class="panel-body">
                    <div class="row">
                        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                            <table id="" class="table table-bordered">
                                <?php
                                $ctr2 = 0;
                                $grpctr = 0;
                                $getkotmain = mysqli_query($conn, "SELECT * FROM `kotmain` WHERE vouchdt = '$curdate' and user = '$username' and billdone = '' ORDER BY `vouchno` asc")or die(mysqli_error($conn));
                                while ($kotmain = mysqli_fetch_array($getkotmain)) {

                                    $gettable = mysqli_query($conn, "SELECT * FROM `tablemast` WHERE code = '$kotmain[tableno]'")or die(mysqli_error($conn));
                                    $ftable = mysqli_fetch_array($gettable);
                                    ?>
                                    <thead class="thead2">
                                        <tr class="mySearchTr">
                                            <th colspan="3" class="text-center"><?= $ftable['name']; ?></th>
                                        </tr>
                                    </thead>
                                    <tbody class="tbody2">
                                        <?php
                                        $gettran = mysqli_query($conn, "SELECT * FROM `kottran` WHERE vouchno = '$kotmain[vouchno]' order by subvouch,srno")or die(mysqli_error($conn));
                                        while ($tran = mysqli_fetch_array($gettran)) {


                                            $getitem = mysqli_query($conn, "SELECT * FROM `item` WHERE `code` = '$tran[item]' ORDER BY `code`")or die(mysqli_error($conn));
                                            $item = mysqli_fetch_array($getitem);

                                            Echo "<tr class='item_$grpctr'>";
                                            Echo "<td><label class='label-control'>$item[name]</label></td>";
                                            Echo "<td class='text-right'><label class='label-control'>$item[rate]</label></td>";
                                            Echo "<td><label class='label-control'>" . round($tran[qty]) . "</label></td>";
                                            Echo "</tr>";
                                            $ctr2++;
                                        }


                                        $grpctr++;
                                        ?>
                                        <tr> 
                                            <td class="text-center" colspan="3">
                                                <!--<a href="kotent.php?mode=edit&vouchno=<?= $kotmain['vouchno'] ?>">-->
                                                <a onclick="window.top.location.href='kotent.php?mode=edit&vouchno=<?= $kotmain['vouchno'] ?>'">
                                                    <button type="button" name="continue" class="btn btn-primary">Continue</button>
                                                </a>
                                            </td>
<!--                                            <td class="text-center" colspan="2">
                                                <a href="pendkot_print.php?vouchno=<?=$kotmain['vouchno']?>" target="_blank">
                                                    <button type="button" name="continue" class="btn btn-primary mySearchTr" style="color: white;">Print</button>
                                                </a>
                                            </td>-->
                                        </tr>
                                    </tbody>
                                <?php } ?>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="panel-footer">
                </div>
            </div>
        </div>
        <!---------------------------Completed Orders---------------------------------->
        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 pad">
            <div class="panel panel-default">
                <!--<div class="panel-heading" style="padding: 0px; background-color: #99ff99">-->
                <h4 style="margin: 0px;background-color: #ccffcc"><?php Echo "Completed Orders"; ?>
                    <!--<span style="font-size: 10px;color:white">&nbsp;&nbsp;&nbsp;(Note: For Detail Click on Table No.)</span>-->
                </h4>
                <!--</div>-->
                <div class="panel-body">
                    <div class="row">
                        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                            <table id="" class="table table-bordered">
                                <?php
                                $ctr2c = 0;
                                $grpctrc = 0;
                                $getkotmainc = mysqli_query($conn, "SELECT * FROM `kotmain` WHERE vouchdt = '$curdate' and user = '$username' and billdone = 'Y' ORDER BY `vouchno` asc")or die(mysqli_error($conn));
                                while ($kotmainc = mysqli_fetch_array($getkotmainc)) {

                                    $gettablec = mysqli_query($conn, "SELECT * FROM `tablemast` WHERE code = '$kotmainc[tableno]'")or die(mysqli_error($conn));
                                    $ftablec = mysqli_fetch_array($gettablec);
                                    ?>
                                    <thead class="thead2">
                                        <tr class="mySearchTr">
                                            <th colspan="3" class="text-center"><?= $ftablec['name']; ?></th>
                                        </tr>
                                    </thead>
                                    <tbody class="tbody2">
                                        <?php
                                        $gettranc = mysqli_query($conn, "SELECT * FROM `kottran` WHERE vouchno = '$kotmainc[vouchno]'  order by subvouch,srno")or die(mysqli_error($conn));
                                        while ($tranc = mysqli_fetch_array($gettranc)) {


                                            $getitemc = mysqli_query($conn, "SELECT * FROM `item` WHERE `code` = '$tranc[item]' ORDER BY `code`")or die(mysqli_error($conn));
                                            $itemc = mysqli_fetch_array($getitemc);

                                            Echo "<tr class='item_$grpctrc'>";
                                            Echo "<td><label class='label-control'>$itemc[name]</label></td>";
                                            Echo "<td class='text-right'><label class='label-control'>$itemc[rate]</label></td>";
                                            Echo "<td><label class='label-control'>" . round($tranc[qty]) . "</label></td>";
                                            Echo "</tr>";
                                            $ctr2++;
                                        }
                                        $grpctrc++;
                                        ?>
                                    </tbody>
                                <?php } ?>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="panel-footer">
                </div>
            </div>
        </div>
    </form>
    <?php include("includes/linksfoot.php"); ?>
</body>
</html>