<?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];

$zroot = $_SESSION["zdir"];
//browse($zroot);

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

    ####################### TRANSACTION ##########################
    case "saleord";
        $src = "saleord.php?mode=last";
        break;

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

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

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

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

    case "debitnote";
        $src = "debnote.php?mode=last&credtype=G";
        break;

    case "creditnote";
        $src = "crednote.php?mode=last&credtype=G";
        break;

    case "credoth";
        $src = "credoth.php?mode=last&credtype=O";
        break;

    case "deboth";
        $src = "deboth.php?mode=last&credtype=O";
        break;

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

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

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

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

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

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

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

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

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

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

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

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

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

    ######################### REPORTS ###########################
    case "stock";
        $src = "stock.php";
        break;

    case "inwout";
        $src = "inwoutrep.php";
        break;

    case "vatrep";
        $src = "vatrep.php";
        break;

    case "ledger";
        $src = "ledger.php";
        break;

    case "labels";
        $src = "labels.php";
        break;

    case "chqrep";
        $src = "chqrep.php";
        break;

    case "amtrep";
        $src = "amtrep.php";
        break;

    case "itemwise";
        $src = "itemwise.php";
        break;

    case "itemwisesale";
        $src = "itemwise_sale.php";
        break;

    case "itemgrpwisesale";
//        $src = "itemgrpsale.php";
        $src = "saleitemgrp.php";
        break;

    case "partygrpwisesale";
        $src = "partgrp_sale.php";
        break;

    case "leadparty";
        $src = "leadparty.php";
        break;

    case "dailyreport";
        $src = "dailyrep.php";
        break;

    case "dailysalereport";
        $src = "dailysalereport.php";
        break;

    case "dailycashrp";
        $src = "dailyrepcash.php";
        break;

    case "checkstock";
        $src = "check_stock.php";
        break;

    case "brsale";
        $src = "brsale.php";
        break;

    case "bankbook";
        $src = "bankbook.php?para=B";
        break;

    case "cashbook";
        $src = "bankbook.php?para=C";
        break;

    case "jvbook";
        $src = "jvbook.php?para=C";
        break;

    case "stocknew";
        $src = "stock_new.php";
        break;

    case "stockold";
        $src = "stock_old.php";
        break;

    case "stockonlyshade";
        $src = "stock_shade.php";
        break;

    case "expenserep";
        $src = "expenserep.php";
        break;

    case "payablerep";
        $src = "osbill.php?para=P";
        break;

    case "receivable";
        $src = "osbill.php?para=R";
        break;

    ########################## REGISTERS ########################
   case "purreg";
        $src = "purreg.php";
        break;
    case "purreggst";
        $src = "purreggst.php";
        break;

    case "slgstreg";
        $src = "slgstreg.php";
        break;

    case "salereg";
        $src = "salereg.php";
        break;

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

    case "slmultireg";
        $src = "slmultireg.php";
        break;

    case "inwreg";
        $src = "inwreg.php";
        break;

    case "outreg";
        $src = "outreg.php";
        break;

    case "debreg";
        $src = "debreg.php";
        break;

    case "credreg";
        $src = "credreg.php";
        break;

    case "damreg";
        $src = "damreg.php";
        break;

    case "excessreg";
        $src = "excessreg.php";
        break;

    case "autoinw";
        $src = "trnfreg.php";
        break;

    case "transreg";
        $src = "intrnfreg.php";
        break;

    case "driverreg";
        $src = "driverreg.php";
        break;

    case "taxinvreg";
        $src = "taxinvreg.php";
        break;

    case "balancereg";
        $src = "balancereg.php";
        break;

    case "debntreg";
        $src = "debntreg.php";
        break;

    case "debothreg";
        $src = "debothreg.php";
        break;

    case "crdntreg";
        $src = "crdntreg.php";
        break;

    case "credothreg";
        $src = "crdothreg.php";
        break;

    ########################## FINAALIZATION ########################
    case "trbal";
        $src = "trbal.php";
        break;

    case "profit";
        $src = "profit.php";
        break;

    case "profshar";
        $src = "profshar.php";
        break;

    case "balsheet";
        $src = "balsheet.php";
        break;


##############Combine Stock##############
    case "combstock";
        $src = "combstock.php";
        break;

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

    case "profile";

        if ($usertype == 1) {
            $src = "user.php?mode=last";
        } else {
            $src = "user2.php?mode=last";
        }
        break;

    case "stock";
        $src = "default2.php";
        break;

    case "backup";
        $src = "backup.php";
        break;

    case "balsms";
        $src = "http://vas.gsmash.com/balance.php?username=ABDRAS&password=ABDRAS2017&route=1";
        break;

    case "yearend";
        $src = "yearend.php";
        break;

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

//$mdeb = "";
//if ($guser[debnote] != "1" && $guser[deboth] != "1") {
//    $mdeb = "style='display:none'";
//}
//
//$mcred = "";
//if ($guser[crednote] != "1" && $guser[credoth] != "1") {
//    $mcred = "style='display:none'";
//}
//
//$mbank = "";
//if ($guser[bankrecp] != "1" && $guser[bankpay] != "1") {
//    $mbank = "style='display:none'";
//}
//
//$mcash = "";
//if ($guser[cashrecp] != "1" && $guser[cashpay] != "1") {
//    $mcash = "style='display:none'";
//}
//
//$rpquery = "";
//if ($guser[chqrep] != "1" && $guser[amtrep] != "1") {
//    $rpquery = "style='display:none'";
//}
//
//$rpoutstanding = "";
//if ($guser[payablerep] != "1" && $guser[receivable] != "1") {
//    $rpoutstanding = "style='display:none'";
//}
//
//
//$rgdebitnote = "";
//if ($guser[debnotreg] != "1" && $guser[debothreg] != "1") {
//    $rgdebitnote = "style='display:none'";
//}
//
//$rgcreditnote = "";
//if ($guser[crednotreg] != "1" && $guser[credothreg] != "1") {
//    $rgcreditnote = "style='display:none'";
//}
//
//


include("includes/linkshead.php");
$dispyear = right(($_SESSION["zdbyear_" . $dbname]), 4);

$zdb = $_SESSION["zdbyear_" . $dbname];

$compcd = $_SESSION["comp_" . $dbname];

$getcomp = mysqli_query($conn, "SELECT code, name FROM `company` where `code`= '$compcd'") or die(mysqli_error($conn));
$fetcomp = mysqli_fetch_array($getcomp);
$cmpname = $fetcomp[name];
mysqli_select_db($conn, $zdb);

if (!empty($srchresult)) {
    $srcinst = mysqli_num_rows($srchresult);
} else {
    $srcinst = 0;
}
?>
<script>
    $(document).ready(function () {

        document.addEventListener("keydown", function (zEvent) {
            if (zEvent.ctrlKey && zEvent.altKey && zEvent.code === "KeyE") {
//                alert('Invalid key Nagvigate Through Menu');

                $(window).keydown(function (event) {
                    if (event.ctrlKey && event.keyCode == 52) {
                        var href = $('#crlink').attr('href');
                        window.location.href = href;
                    }
                });
            }
            if (zEvent.ctrlKey && zEvent.altKey && zEvent.code === "KeyR") {

                $(window).keydown(function (event) {
                    if (event.ctrlKey && event.keyCode == 55) {
                        var href = $('#dclink').attr('href');
                        window.location.href = href;
                    }
                });
            }
        });

    });
</script>
</head>
<body class="off-canvas">
    <div id="container" class="sidebar-mini">
        <header id="header">
            <!--logo start-->
            <div class="brand"><a href="mainmenu.php" class="logo"><?php Echo $cmpname; ?></a></div>
            <!--<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>
            </div>

            <div class="user-nav">
                <ul>
                    <li class="dropdown settings"><a href="<?
                        if ($usertype == 1) {
                            Echo "comp.php";
                        } else {
                            Echo "#";
                        }
                        ?>"><label class="label-control" style="font-size: 12px;color: #337ab7;"> Company : <?php echo $cmpname; ?></label></a></li>
                    <li class="dropdown settings">
                        <a class="dropdown-toggle" href="year.php">
                            <label class="label-control" style="font-size: 13px"><i class="fa fa-calendar" aria-hidden="true"></i> <?php echo 'Financial Year : ' . $dispyear; ?></label>
                        </a>
                    </li>


                    <!--<li <?= $dcombstock; ?> class="dropdown settings"><label class="label-control" style="font-size: 18px;"><i class="fa fa-list"></i>  <a href="?action=combstock">Combined Stock</a></label></li>-->

                    <?php if ($srcinst > 0) {
                        ?>
                        <li class="dropdown settings">
                            <a class="dropdown-toggle" href="?action=autotran">
                                <label class="label-control" style="font-size: 15px;color: red;"><i class="fa fa-"></i>Transfer (<?= $srcinst ?>)</label>
                            </a>
                        </li>
                        <?php
                    }
                    ?>
<!--                    <li class="profile-photo"><img src="assets/img/avatar.png" alt="" class="img-circle"></li>-->
                    <li class="dropdown settings">
                        <a class="dropdown-toggle balsms" data-toggle="dropdown" href="#">
                            <b style="font-size: 20px;"><?php echo $_SESSION["username_" . $dbname]; ?></b> <i class="fa fa-angle-down"></i>
                        </a>
                        <ul class="dropdown-menu animated fadeInDown">
                            <li <?= $tlcompany; ?>><a href="?action=company"><i class="fa fa-building-o"></i> Company SetUp</a></li>
                            <li <?= $tlbackup; ?>><a href="backup.php"><i class="fa fa-cloud-download"></i> Backup</a></li>
                            <li <?= $tlprofile; ?>><a href="?action=profile"><i class="fa fa-user"></i> Profile</a></li>
                            <!--<li <?= $tlyearend; ?>><a href="?action=yearend"><i class="fa fa-calendar"></i>Year End</a></li>-->
                            <li><a href="logout.php"><i class="fa fa-power-off"></i> Logout</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </header>


        <!-- AUTO LINKS-->
        <a href="ch_recd.php?mode=last" id="crlink" ></a>
        <a href="dailycash.php" id="dclink" ></a>


        <!--sidebar left start-->
        <nav class="sidebar sidebar-left">
            <h5 class="sidebar-header">Navigation</h5>
            <ul class="nav nav-pills nav-stacked">
                <li class="nav-dropdown">
                    <a href="#" title="UI Elements"><i class="fa fa-graduation-cap"></i>Masters</a>
                    <ul class="nav-sub">
                       <li <?= $customer; ?>><a href="?action=customer">Customer</a></li>
                        <li <?= $supplier; ?>><a href="?action=supplier">Supplier</a></li>
                        <li <?= $supplier; ?>><a href="?action=colour">Colour</a></li>
                        <li <?= $itemgrp; ?>><a href="?action=itemgrp">Item Group</a></li>
                        <li <?= $item; ?>><a href="?action=item">Item</a></li>
                        <li <?= $chrateop; ?>><a href="?action=chrateop">Change of Rates/Opening Stock</a></li>
                        <li <?= $openbal; ?>><a href="?action=openbal">Opening Balance</a></li>
                        <hr>
                        <li <?= $group; ?>><a href="?action=group">Group</a></li>
                        <li <?= $cash; ?>><a href="?action=cash">Cash</a></li>
                        <li <?= $bank; ?>><a href="?action=bank">Bank</a></li>
                        <li <?= $otherac; ?>><a href="?action=otherac">Other A/C</a></li>
                    </ul>
                </li>
                <li class="nav-dropdown">
                    <a href="#" title="Transaction"><i class="fa fa-usd"></i>Transaction</a>
                    <ul class='nav-sub'>
                        <li <?= $purchase; ?>><a href="?action=saleord">Sale Order</a></li>
                        <li <?= $sale; ?>><a href="?action=sale">Sale</a></li>
                        <li <?= $mcred; ?> class="nav-dropdown">
                            <a href="#">Sale Return/Credit Note</a>
                            <ul class="nav-sub">
                                <li <?= $crednote; ?> ><a href="?action=creditnote">Goods Return</a></li>
                                <li <?= $credoth; ?> ><a href="?action=credoth">Others</a></li>
                            </ul>
                        </li>
                        <li <?= $purchase; ?>><a href="?action=purchase">Purchase</a></li>
                        <li <?= $repair; ?>><a href="?action=repair">Reminder</a></li>
                        <li <?= $mdeb; ?> class="nav-dropdown">
                            <a href="#">Purchase Return/Debit Note</a>
                            <ul class="nav-sub">
                                <li <?= $debnote; ?> ><a href="?action=debitnote">Goods Return</a></li>
                                <li <?= $deboth; ?> ><a href="?action=deboth">Others</a></li>
                            </ul>
                        </li>
                        <li <?= $inward; ?>><a href="?action=inward">Inward</a></li>
                        <li <?= $outward; ?>><a href="?action=outward">Outward</a></li>
                        <li <?= $damaged; ?>><a href="?action=damaged">Damaged</a></li>
                        <hr>
                        <li <?= $mbank; ?> class="nav-dropdown">
                            <a href="#">Bank<i></i></a>  
                            <ul class="nav-sub">
                                <li <?= $bankrecp; ?> ><a href="?action=bankrecp">Receipt</a></li>
                                <li <?= $bankpay; ?> ><a href="?action=bankpay">Payment</a></li>
                            </ul>
                        </li>
                        <li <?= $mcash; ?> class="nav-dropdown">
                            <a href="#">Cash<i></i></a>
                            <ul class="nav-sub">
                                <li <?= $cashrecp; ?> ><a href="?action=cashrecp">Receipt</a></li>
                                <li <?= $cashpay; ?> ><a href="?action=cashpay">Payment</a></li>
                            </ul>
                        </li>
                        <li <?= $contra; ?>><a href="?action=contra">Contra</a></li>
                        <li <?= $journal; ?>><a href="?action=journal">Journal</a></li>
                        <li <?= $mcash; ?> class="nav-dropdown">
                            <a href="#">Discount<i></i></a>
                            <ul class="nav-sub">
                                <li <?= $discrecd; ?> ><a href="?action=discrecd">Received</a></li>
                                <li <?= $discgvn; ?> ><a href="?action=discgvn">Given</a></li>
                            </ul>
                        </li>
                    </ul>
                </li>
                <li class="nav-dropdown">
                    <a href='#'><i class="fa fa-file"></i>Reports</a>
                    <ul class='nav-sub'>
                        <li <?= $stock; ?>><a href="?action=stock">Stock</a></li>
                        <li <?= $ledger; ?>><a href="?action=ledger">Ledger</a></li>
                        <li <?= $inwout; ?>><a href="?action=inwout"> Inward/Outward History</a></li>
                        <li <?= $itemwisesale; ?>><a href="?action=itemwisesale">Itemwise Sale</a></li>
                        <li <?= $dailyreport; ?>><a href="?action=dailyreport">Daily Report</a></li>
                        <li <?= $labels; ?>><a href="?action=labels">Box Labels</a></li>
                        <hr>
                        <li <?= $bankbook; ?>><a href="?action=bankbook">Bank Book</a></li>
                        <li <?= $cashbook; ?>><a href="?action=cashbook">Cash Book</a></li>
                        <li <?= $jvbook; ?>><a href="?action=jvbook">Journal Book</a></li>
                        <li <?= $rpoutstanding; ?> class="nav-dropdown">
                            <a href="#">Outstanding<i></i></a>
                            <ul class="nav-sub">
                                <li <?= $payablerep; ?> ><a href="?action=payablerep">Payable</a></li>
                                <li <?= $receivable; ?> ><a href="?action=receivable">Receivable</a></li>
                            </ul>
                        </li>
                        <li <?= $rpquery; ?> class="nav-dropdown">
                            <a href="#">Moving Items<i></i></a>
                            <ul class="nav-sub">
                                <li <?= $fast; ?> ><a href="?action=fast">Fast</a></li>
                                <li <?= $slow; ?> ><a href="?action=slow">Slow</a></li>
                            </ul>
                        </li>
                    </ul>
                </li> 

                <li class="nav-dropdown">
                    <a href='#'><i class="fa fa-registered"></i>Registers</a>
                    <ul class='nav-sub'>
                        <li <?= $ordreg; ?>><a href="?action=ordreg">Sale Order</a></li>
                        <li <?= $salereg; ?>><a href="?action=salereg">Sale</a></li>
                        <li <?= $purreg; ?>><a href="?action=purreg">Purchase</a></li>
                        <li <?= $rgdebitnote; ?> class="nav-dropdown"> 
                            <a href="#">Purchase Return / Debit Note<i></i></a>
                            <ul class="nav-sub">
                                <li <?= $debntreg; ?> ><a href="?action=debntreg">Goods Return</a></li>
                                <li <?= $debothreg; ?> ><a href="?action=debothreg">Others</a></li>
                            </ul>
                        </li>
                            <li <?= $rgcreditnote; ?> class="nav-dropdown">
                            <a href="#">Sale Return / Credit Note<i></i></a>
                            <ul class="nav-sub">
                                <li <?= $crdntreg; ?> ><a href="?action=crdntreg">Goods Return</a></li>
                                <li <?= $credothreg; ?> ><a href="?action=credothreg">Others</a></li>
                            </ul>
                        </li>
                        <li <?= $inwreg; ?>><a href="?action=inwreg">Inward</a></li>
                        <li <?= $outreg; ?>><a href="?action=outreg">Outward</a></li>
                        <li <?= $damreg; ?>><a href="?action=damreg">Damaged</a></li>
                    </ul>
                </li>
<!--                
                <li class="nav-dropdown">
                    <a href='#'><i class="fa fa-archive"></i>Finalization</a>
                    <ul class='nav-sub'>
                        <li <?= $fnbalance; ?>><a href="?action=trbal">Trial Balance</a></li>
                        <li <?= $fnprofit; ?>><a href="?action=profit">Profit / Loss</a></li>
                        <li <?= $fnprofshar; ?>><a href="?action=profshar">Profit Sharing</a></li>
                        <li <?= $fnbalsheet; ?>><a href="?action=balsheet">Balance Sheet</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>
            </section>
        </section>
    </div>
    <!--main content end-->
    <?php include("includes/linksfoot.php") ?>
</body>
</html>
