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

$admin = $_SESSION["admin_" . $dbname];
$usertype = $_SESSION["usertype_" . $dbname];

$src = "";
$action = isset($_GET["action"]) ? $_GET["action"] : "";
switch ($action) {

####################### MASTERS ##########################
    case "customer";
        $src = "customer.php?mode=last";
        break;

    case "itemgrp";
        $src = "itemgrp.php?mode=last";
        break;

    case "item";
        $src = "item.php?mode=last";
        break;

    case "delvcomp";
        $src = "delvcomp.php?mode=last";
        break;

    case "tablemast";
        $src = "tablemast.php?mode=last";
        break;

    case "paytype";
        $src = "paytype.php?mode=last";
        break;

    case "kotinhouse";
        $src = "kotent.php?mode=last";
        break;

    case "bill";
        $src = "bill.php?mode=last";
        break;

    case "pendbill";
        $src = "billmain.php?mode=last";
        break;

    case "pendkot";
        $src = "pendkot.php?mode=last";
        break;

    case "compkot";
        $src = "compkot.php?mode=last";
        break;

    case "company";
        $src = "company.php?mode=last";
        break;

    case "user";
        if ($admin == '1') {
            $src = "user.php?mode=last";
        } else {
            $src = "user2.php?mode=last";
        }
        break;
######################## REGISTERS ###############################


    case "salereg";
        $src = "salereg.php?mode=last";
        break;

    case "dailyrep";
        $src = "dailyrep.php?mode=last";
        break;

    case "tabletrans";
        $src = "tabletrans.php?mode=last";
        break;

    case "salegrp";
        $src = "salegrp.php?mode=last";
        break;

    case "saleitem";
        $src = "saleitem.php?mode=last";
        break;

    case "saletable";
        $src = "saletable.php?mode=last";
        break;

    case "cardsum";
        $src = "cardsum.php?mode=last";
        break;

    case "discsale";
        $src = "discsale.php?mode=last";
        break;

    case "online";
        $src = "online.php?mode=last";
        break;

    case "supdash";
        $src = "supdash.php?mode=last";
        break;

    default :
        $head = "Home";
        $src = "default.php?mode=last";
}





include("includes/linkshead.php");
$zdb = $_SESSION["zdbyear_" . $dbname];

$getbills = mysqli_query($conn, "Select vouchno from $zdb.`kotmain` where `billdone` != 'Y'") or die(mysqli_error($conn));
if (!empty($getbills)) {
    $billnum = mysqli_num_rows($getbills);
} else {
    $billnum = 0;
}
$getckot = mysqli_query($conn, "Select vouchno from $zdb.`kotmain` where `billdone` = 'Y'") or die(mysqli_error($conn));
if (!empty($getckot)) {
    $compkot = mysqli_num_rows($getckot);
} else {
    $compkot = 0;
}
?>

</head>
<body class="off-canvas">
    <div id="container" class="sidebar-mini">
        <header id="header">
            <!--logo start-->
            <div class="brand"><a href="menu.php" class="logo"><?php Echo $project_name; ?></a></div>
            <!--logo end-->
            <div class="toggle-navigation toggle-left">
                <button type="button" class="btn btn-default" id="toggle-left" data-toggle="tooltip" data-placement="right" title="Toggle Navigation">
                    <i class="fa fa-bars"></i>
                </button>
                <?php
                if ($usertype == 'K' || $usertype == "") {
                    if ($billnum > 0) {
                        ?>
                        <!--<li class="dropdown settings">-->
                        <a href="?action=pendkot" style="font-size: 15px;color: red"><i class="fa fa-bill"></i>Pending KOT ( <?= $billnum ?> )</a>
                        <!--</li>-->
                    <?php }
                    ?>
                    &nbsp;&nbsp;&nbsp;
                    <?php
                    if ($compkot > 0) {
                        ?>
                        <!--<li class="dropdown settings">-->
                        <a href="?action=compkot" style="font-size: 15px;color: green"><i class="fa fa-bill"></i>Completed KOT ( <?= $compkot ?> )</a>
                        <!--</li>-->
                        <?php
                    }
                }
                ?>
            </div>


            <div class = "user-nav">
                <ul>
                    <?php
//                    if ($admin == '1') {
                    if ($usertype == "") {
                        if ($billnum > 0) {
                            ?>
                            <!--<li class="dropdown settings">-->
                            <a href="?action=pendbill">Pending Bills ( <?= $billnum ?> )</a>
                            <!--</li>-->
                            <?php
                        }
                    }
//                    }
                    ?>
                    <li class="dropdown settings">
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            <?php echo $_SESSION["username_" . $dbname]; ?> <i class="fa fa-angle-down"></i>
                        </a>
                        <ul class="dropdown-menu">
                            <li ><a href="?action=company"><i class="fa fa-desktop"></i>  Company</a></li>
                            <li <?= $profile; ?>><a href="?action=user"><i class="fa fa-user"></i>  Profile</a></li>
                            <li <?= $logout; ?>><a href="logout.php?"><i class="fa fa-power-off"></i>  Logout</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </header>
        <!--sidebar left start-->
        <nav class="sidebar sidebar-left">
            <h5 class="sidebar-header">Navigation</h5>
            <ul class="nav nav-pills nav-stacked" id="navmas">
                <li <?= $master; ?> class="nav-dropdown">
                    <a href="#" title="Masters"><i class="fa fa-graduation-cap"></i>Masters</a>
                    <ul class="nav-sub">
                        <li <?= $customer; ?>><a href="?action=customer">Customer</a></li>
                        <li <?= $itemgrp; ?>><a href="?action=itemgrp">Item Group</a></li>
                        <li <?= $item; ?>><a href="?action=item">Item</a></li>
                        <li <?= $delvcomp; ?>><a href="?action=delvcomp">Delivery Company</a></li>
                        <li <?= $paytype; ?>><a href="?action=paytype">Payment Type</a></li>
                        <li <?= $tablemast; ?>><a href="?action=tablemast">Table</a></li>
                        <!--<li><a href="?action=waiter">Waiter</a></li>-->
                    </ul>
                </li>
                <li <?= $transaction; ?> class="nav-dropdown">
                    <a href="#" title="Transactions"><i class="fa fa-money"></i>Transactions</a>
                    <ul class="nav-sub">
                        <li <?= $kotent; ?>><a href="kotent.php?mode=true">KOT In House</a></li>
                        <li <?= $kotpent; ?>><a href="kotpent.php?mode=true">KOT Parcel</a></li>
                        <li <?= $bill; ?>><a href="?action=bill">Bill</a></li>
                        <li <?= $tabletrans; ?>><a href="?action=tabletrans">Table Transfer</a></li>
                    </ul>
                </li>
                <li <?= $report; ?> class="nav-dropdown">
                    <a href="#" title="Reports"><i class="fa fa-registered"></i>Reports</a>
                    <ul class="nav-sub">
                        <li <?= $salereg; ?>><a href="?action=salereg">Sale Register</a></li>
                        <li <?= $dailyrep; ?>><a href="?action=dailyrep">Daily Report</a></li>
                        <li <?= $online; ?>><a href="?action=online">Online Delivery</a></li>
                        <!--<li <?= $bestofd; ?>><a href="?action=bestofd">Best OFD</a></li>-->
                        <li <?= $saleitem; ?>><a href="?action=saleitem">Sale Itemwise</a></li>
                        <li <?= $salegrp; ?>><a href="?action=salegrp">Sale Groupwise</a></li>
                        <li <?= $saletable; ?>><a href="?action=saletable">Sale Tablewise</a></li>
                        <li <?= $cardsum; ?>><a href="?action=cardsum">Card Payment</a></li>
                        <li <?= $discsale; ?>><a href="?action=discsale">Discount Sale</a></li>
                    </ul>
                </li>
            </ul>
        </nav>
        <!--sidebar left end-->
        <!--main content start-->
        <section class="main-content-wrapper">
            <section id="main-content">
                <div class="col-md-12 pad">
                    <iframe src="<?php echo $src; ?>" name="frame1" style="width: 100%; height:5000px;"  frameBorder="0" scrolling="no"></iframe>
                    <div id='result'></div>
                </div>
            </section>
        </section>
    </div>
    <!--main content end-->
    <?php include("includes/linksfoot.php") ?>
</body>
</html>
