
<?php 
session_start(); 
date_default_timezone_set("Africa/Kampala");
$myid=$_SESSION['id'];
$id_user=$_SESSION['id'];
$branch=$_SESSION['branch_id'];

$business=$_SESSION['business_id'];


//Permissions
include '../includes/connection.php';


$permissions = mysqli_fetch_array(mysqli_query($con,"SELECT * FROM  permissions WHERE  permissions.role_id = users.role AND users.id='$id_user' AND users.business_id ='$business' AND users.branch_id ='$branch'"));


        //end permissionms

if($_SESSION['id']==0){

   ?>
<script>
  window.location="../index.php";
  </script>
   <?php
}

// include '../includes/zhizhao.php';
include '../includes/connection.php';
include '../includes/stockvalue_query.php';
include '../settings/check_business_settings.php';

$sql_businesstype=mysqli_fetch_array(mysqli_query($con,"SELECT * from business where business_id='$business'"));
$business_type=$sql_businesstype['type'];
$store=$sql_businesstype['store'];
$empties=$sql_businesstype['empties'];
$receipt_type=$sql_businesstype['receipt_type'];

//if ($_SESSION['role']=='Super Admin') {
//if( $permissions['view_business_details'] == 1){
if($permissions['business_id'] != 0 && $permissions['branch_id']==0){
    $sql = "SELECT * FROM business where business_id='$business'";
}else{
$sql = "SELECT *,(select branch_name from branches where branch_id='$branch') as braa FROM business where business_id='$business'";
}

$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
        
   //if ($_SESSION['role']=='Super Admin') {
//if( $permissions['view_business_details'] == 1){
if($permissions['business_id'] != 0 && $permissions['branch_id']==0){
    $bra="";
   }else{
        $bra=$row['braa'];
   }
   $buziness_name=$row['business_name']."  ".$bra;
    
} else {
   $buziness_name='Point Of Sales System';
}



?>
<?php
$check_rec=mysqli_query($conn,"SELECT * from receipt_settings where branch_id='$branch'");

if (mysqli_num_rows($check_rec)<1) {
   $inrec=mysqli_query($con,"INSERT INTO receipt_settings(print_after_sale, print_after_purchase,branch_id) VALUES('1','1','$branch')");
}
 
?>


<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">


<div class="navbar navbar-fixed-top" >
            <div class="navbar-inner">
                <div class="container-fluid">
                    <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span>
                     <span class="icon-bar"></span>
                     <span class="icon-bar"></span>
                    </a>
                    <a class="brand" href="#"><strong><?php echo $buziness_name; ?></strong></a>
                 
                     <div class="nav-collapse collapse">
                        <ul class="nav pull-right">
                            <li class="dropdown">
                                <a href="#" role="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="icon-user"></i> <?php echo $_SESSION['fullname']; ?> <i class="caret"></i>

                                </a>
                                <ul class="dropdown-menu">
                                    <li>
                                        <a tabindex="-1" href="../account/myacount.php">Account</a>
                                    </li>
                                    <li class="divider"></li>
                                    <li>
                                        <a tabindex="-1" href="../main/logout.php">Logout</a>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                        
                    </div>
                    <?php
                        include '../includes/connection.php';
                        $poduct_number="0";
// Create connection
$sql = mysqli_query($con,"SELECT count(id)as num, (select count(id) from sales where branch_id='$branch') as sales, (select count(id) from users where branch_id='$branch')as users, (select count(id) from staff where branch_id='$branch') as staff,(select count(branch_id) from branches) as brancs FROM products where branch_id='$branch'");



    // output data of each row
    while($row = mysqli_fetch_assoc($sql)) {
       $poduct_number=$row['num'];
       $sales_number=$row['sales'];
       $users=$row['users'];
       $stafxp=$row['staff'];
       $brancs=$row['brancs'];
    }







                        ?>
                        <?php
                    //if($_SESSION['role']=="General Admin" || $_SESSION['role']=="admin"|| $_SESSION['role']=="Super Admin"){
                        if( $permissions['view_advanced'] == 1){
                            ?>
                            <div class="nav-collapse collapse">
                        <ul class="nav pull-right">
                        <li class="dropdown">
                                     <a href="#" data-toggle="dropdown"  ><i class="icon-list" ></i>Advanced <i class="caret"></i></a>
                                        
                                           
                                            <ul class="dropdown-menu">
                                                 
                                             <li class="divider"></li>
                                                <?php
                 
                        if( $permissions['view_product_arrangment'] == 1){
                            ?>
                                              
                                                 <li>
                                                <a href="../settings/products_arrangement.php"><i class="fa fa-balance-scale"></i> &nbsp; Products arrangement</a>
                                                 </li>
                                                 <?php
                         }
                             ?>
                                                <li class="divider"></li>
                                                  <?php
                 
                        if( $permissions['other_settings'] == 1){
                            ?>
                                                <li>
                                                <a href="../settings/general_settings.php"><i class="fa fa-balance-scale"></i> &nbsp; Other settings</a>
                                                 </li>
                                                 <?php
                         }
                             ?>
                                                </ul>
                                         
                             </li>
                        </ul>
                        </div>
                        <?php
                         }
                             ?>
                    <!--/.nav-collapse -->
                       <div class="nav-collapse collapse">
                        <ul class="nav pull-right">
                          <?php
                          // if($_SESSION['role']=="General Admin"){
                          if( $permissions['view_settings'] == 1){
                                    ?>
                            <li class="dropdown">
                                <a href="#" role="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="icon-asterisk"></i> Settings <i class="caret"></i>

                                </a>

                                <ul class="dropdown-menu">
                                <?php
                                 //if($_SESSION['role']=="General Admin"){
                                //if( $permissions['nav_settings_business'] == 1){
                                if($permissions['business_id'] == 0){
                                    ?>
                                    <li>
                            <a href="../business/business.php"><span class="badge badge-important pull-right"><?php $countbss=mysqli_fetch_array(mysqli_query($con,"select count(business_id) as countbss from business ")); echo $countbss['countbss']; ?></span><i class="fa fa-balance-scale"></i> Businesses</a>
                        </li>
                        <?php }
                        ?>
                        <li class="divider"></li>
                                  <?php
                                  //if($_SESSION['role']=="Super Admin"){
                                  if( $permissions['nav_settings_branch'] == 1 AND $_SESSION['branch_id']==0){
                                  ?>
                                <li>
                            <a href="../branches/branches.php"><span class="badge badge-important pull-right"><?php $count=mysqli_fetch_array(mysqli_query($con,"select count(branch_id) as count from branches where business_id='$business' ")); echo $count['count']; ?></span><i class="fa fa-balance-scale"></i> &nbsp; Branches</a>
                        </li>
                        <?php
                           }
                        ?>
                        <li class="divider"></li>
                        
                        <?php
                                  //if($_SESSION['role']=="Super Admin"){
                                  if( $permissions['nav_users'] == 1){
                                  ?>
                         <li>
                            <a href="../users/users.php"><span class="badge badge-warning pull-right"><?php //echo $users; ?></span><i class="fa fa-users"></i> &nbsp; Users</a>
                        </li>
                        <?php
                           }
                        ?>

                        <?php
                        if( $permissions['view_permissions'] == 1){
                                  ?>
                        <li class="divider"></li>

                         <li>
                            <a href="../permissions/permissions.php"><span class="badge badge-warning pull-right"></span><i class="fa fa-lock"></i> &nbsp; User Permissions</a>
                        </li>
                        <?php
                           }
                        ?>

                        <li class="divider"></li>
                        <?php
                        //if($_SESSION['role']=="admin"|| $_SESSION['role']=="Super Admin"){
                        if( $permissions['nav_suppliers'] == 1){
                        ?>
                                   <li>
                                   
                            <a href="../stock/suppliers.php"><span class="badge badge-important pull-right"><?php $count=mysqli_fetch_array(mysqli_query($con,"select count(supplier_id) as count from suppliers where branch_id='$branch'")); //echo $count['count']; ?></span><i class="fa fa-balance-scale"></i> &nbsp; Suppliers</a>
                        </li>
                        <?php
                         }
                     //
                             ?>
                        <li class="divider"></li>
                        <?php
                        if( $permissions['nav_products'] == 1){
                            ?>
                        <li>
                        
                            <a <?php
                             //if($_SESSION['role']=="Super Admin"){
                            if( $_SESSION['branch_id'] == 0){
                              ?>
                              href="../stock/product_admin.php"<?php 
                            }else{?>href="../stock/products.php"<?php }?>><span class="badge badge-success pull-right"> <?php //echo $poduct_number;?></span> <i class="fa fa-shopping-cart"></i> Products</a>
                        
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="../consumables/consumables.php"><i class="fa fa-balance-scale"></i> &nbsp; Consumables</a>
                        </li>
                        
                        
                        <?php }?>
                        <li class="divider"></li>

                        <?php
                             //if($_SESSION['role']=="Super Admin"){
                            if( $permissions['nav_units'] == 1){
                              ?>
                        <li>
                            <a href="../stock/units.php"><i class="fa fa-balance-scale"></i> &nbsp; Units</a>
                        </li>
                        <?php }?>
                        <li class="divider"></li>
                       <?php
                             //if($_SESSION['role']=="Super Admin"){
                            if( $permissions['view_staff'] == 1){
                              ?>
                        <li>
                            <a href="../staff/staff.php"><span class="badge badge-warning pull-right"><?php //echo $stafxp; ?></span> <i class="fa fa-address-book-o"></i> &nbsp;Staff</a>
                        </li>
                        <?php }?>

                                <li class="divider"></li>
                                <?php
                             //if($_SESSION['role']=="Super Admin"){
                            if( $permissions['nav_reciepts'] == 1){
                              ?>
                        <li>
                            <a href="../receipt/receipt_settings.php"><span class="badge badge-warning pull-right"></span> <i class="fa fa-print"></i> &nbsp;Receipts</a>
                        </li>
                        <?php }?>
                        <li class="divider"></li>
                        
                        <?php 
                        if( $permissions['nav_settings_store'] == 1){
                            ?>
                        <?php
                        if ($store==1) {
                           ?>
                           <li>
                            <a href="../store/load_products.php"> <i class="fa fa-plus"></i> &nbsp;Store</a>
                        </li>
                           <?php
                        }
                        ?>
                         <?php
                        }
                        ?>
                        <li class="divider"></li>
                        <?php

                        if ($empties==1) {
                           ?>
                        <?php 
                        if( $permissions['nav_settings_empties'] == 1){
                            ?>
                           <li>
                            <a href="../empties/crates.php"> <i class="fa fa-plus"></i> &nbsp;Empties</a>
                        </li>
                        <?php
                         }
                     //     
                             ?>
                        <li class="divider"></li>
                        <?php 
                        if( $permissions['nav_settings_exchange_rate'] == 1){
                            ?>
                        <li>
                            <a href="../exchangerates/exchanges.php"> <i class="fa fa-plus"></i> &nbsp;Exchange rates</a>
                        </li>
                        <?php
                         }
                     //     
                             ?>
                           <?php
                        }
                        ?>
                        <li class="divider"></li>
                        <?php }?>

                                   
                                </ul>
                            </li>
                           
                        </ul>
                        
                    </div>
                    <div class="nav-collapse collapse">
                        <ul class="nav pull-right">  <li class="dropdown">
                        <a href="#" data-toggle="dropdown"  ><i class="icon-list" ></i>Reports<span ></span><i class="caret"></i>
                        </a>
                                        
                                           
                            <ul class="dropdown-menu">
                            <li class="divider"></li>
                        
                           <li>
                            <a href="../reports/income_statement.php"> <i class="fa fa-money"></i> &nbsp;Income statement</a>
                            </li>
                              <li class="divider"></li>
                            <li>
                            <a href="../stock/stock_values.php"><i class="fa fa-balance-scale"></i> &nbsp; Stock Value</a>
                             </li>
                          </ul>
                       
                                
                        </ul>
                    </div>
                     <div class="nav-collapse collapse">
                        <ul class="nav pull-right">
                            
                            <?php
                          $sql = mysqli_query($con,"SELECT * from notifications where status='1' && branch_id='$branch' order by id DESC LIMIT 4");
                    
                                    $sql0 = mysqli_query($con,"select * from notifications where status='1' && branch_id='$branch'");
                                    $num = mysqli_num_rows($sql0);
                                    ?>
                                    <?php
                                                        //if($_SESSION['role']!="General Admin"){
                                    if( $permissions['view_notification'] == 1){
                        ?>
                    <li class="dropdown">
                        <a href="#" data-toggle="dropdown"  ><i class="icon-bell" ></i>Notifications(<strong style="color: red;"><?php echo$num;?></strong>)<span ></span><i class="caret"></i>
                        </a>
                                        
                                           
                                            <ul class="dropdown-menu">
                                                 <div class="notification-single-top">
                                                <h4 style="text-align: center;">Notifications</h4>
                                            </div>
                                                <?php
                                                        while($roww=mysqli_fetch_array($sql)){
                                                ?> 
                                                <li>
                                                    
                                                      
                                                        
                                                        <div><i class="icon-bell" aria-hidden="true"></i>
                                                            <span ><?php echo$roww['AddedOn'];?></span><hr style="margin: 0px;">
                                                           
                                                        </div>
                                                        
                                                            <div style="margin-left: 2px; text-align: left; padding-left: 10px;"><p>&nbsp; &nbsp; <?php echo$roww['shortmessage'];?>&nbsp; &nbsp; &nbsp;  <a href="../stock/newnotication.php?id=<?php echo$roww['id'];?>">
                                                                More
                                                            </a></p>                </div>

                                                                                                 
                                                    </a>
                                                </li>
                                                <?php
                                                }
                                                ?>
                           
                                            <div class="notification-view" style="padding-left: 10px; text-align: center;">
                                                <a href="../stock/allnotifications.php">All Notification</a>
                                            </div>
                                        </div>
                                    </li>
                                
                                    <?php
                                }
                  
                            ?>

                        </ul>
                    </li>
                        
                        
                    </div>
                    
                    
                </div>
            </div>
        </div>
