
<?php
session_start();
error_reporting(0);
@ini_set('display_errors', 0);
$id_user=$_SESSION['id'];
$branch=$_SESSION['branch_id'];
$business=$_SESSION['business_id'];
?>

<!DOCTYPE html>
<html>

<head>

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <?php
    include("../includes/add_licence.php");
    include("../includes/header-links.php");
$permissions = mysqli_fetch_array(mysqli_query($con,"SELECT * FROM  
  permissions,users WHERE  permissions.role_id = users.role 
  AND users.id='$id_user' AND users.business_id ='$business' AND users.branch_id ='$branch'"));

if($permissions['nav_settings_branch'] != 1){
?>
<script>window.location="../main/dashboard.php"</script>
<?php
}
?>

<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <link href="../bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
    <link href="../assets/styles.css" rel="stylesheet" media="screen">
    <link href="../assets/DT_bootstrap.css" rel="stylesheet" media="screen">
    <link rel="stylesheet" href="../data-table-css/bootstrap-table.css">
<link rel="stylesheet" href="../data-table-css/bootstrap-editable.css">
    <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="vendors/flot/excanvas.min.js"></script><![endif]-->
    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
        <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <script src="../vendors/modernizr-2.6.2-respond-1.1.0.min.js"></script>
</head>

<body>
    <script type="text/javascript">
function FormatCurrency(ctrl) {
              //Check if arrow keys are pressed - we want to allow navigation around textbox using arrow keys
              if (event.keyCode == 37 || event.keyCode == 38 || event.keyCode == 39 || event.keyCode == 40) {
                  return;
              }

              var val = ctrl.value;

              val = val.replace(/,/g, "")
              ctrl.value = "";
              val += '';
              x = val.split('.');
              x1 = x[0];
              x2 = x.length > 1 ? '.' + x[1] : '';

              var rgx = /(\d+)(\d{3})/;

              while (rgx.test(x1)) {
                  x1 = x1.replace(rgx, '$1' + ',' + '$2');
              }

              ctrl.value = x1 + x2;
          }

          function CheckNumeric() {
              return event.keyCode >= 48 && event.keyCode <= 57 || event.keyCode == 46;
          }
</script>
    <?php include '../includes/header.php'; ?>
    <div class="container-fluid">
        <div class="row-fluid">
            <?php include '../includes/sidebar.php'; ?>
            <!--/span-->
            <div class="span10" id="content">

                 <div class="row-fluid">
                    <!-- block -->
                    <div class="block">
                        <div class="navbar navbar-inner block-header">
                            <div class="muted pull-left">Business Profile</div>
                        </div>
                        <div class="block-content collapse in">
                            <div class="span10">
                            <form action="" method="POST">
                                        <div class="span6">
                                        <label>Select Busines</label>
                                          <select class="form-control" id="staf" name="bus" onchange="checkBystaff(this.value)">
                                            <option value="" selected="" disabled="">Business</option>
                                            
                                            <?php
                                            include '../includes/connection.php';
                                            $sqlbu = "SELECT * FROM business where status=1 ";
                              $resultbu = mysqli_query($conn, $sqlbu);

                              if (mysqli_num_rows($resultbu) > 0) {
                                  // output data of each row
                                  while($rowbu = mysqli_fetch_assoc($resultbu)) {
                                      ?>
                              <option value="<?php echo $rowbu['business_id']; ?>"><?php echo $rowbu['business_name']; ?></option>
                                      <?php
                                  }
                              } else {
                                  echo "0 results";
                              }
                              ?>
                                          </select>
                                          </div> 
                                          <div class="span3">
                                        <label>&nbsp;</label>
                                          <button type="submit" name="search" class="btn btn-primary"> Search</button>
                                          
                                        </div> 
                                        </form>
                               <?php
                               if(isset($_POST['search'])){
                               $businespro=$_POST['bus'];
                               $bb=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM business where business_id='$businespro' "));
                               $buss=$bb['business_name'];

                             }else{
                               $businespro=3;
                               $buss="Demo Account";

                             }
                               ?>
                               <br>
                               <br>
                  <h1 style="color: green;"><center><?php echo $buss; ?></center></h1>

                                  </div>

                               
                                    <!--Model Ends here -->
                              


      <div class="span12" style="border: 10px soilid blue;"> 
                  <h1><center>LAST 10 SALES</center></h1>
                    <table  id="table" data-toggle="table" data-pagination="true" data-search="true" data-show-columns="true" data-show-pagination-switch="true" data-show-refresh="false" data-key-events="true" data-show-toggle="false" data-resizable="false" data-cookie="true"data-cookie-id-table="saveId" data-show-export="true" data-click-to-select="true" data-toolbar="#toolbar" data-export-options='{"fileName": "Testing_filename"}'>
                                    <thead>
                                        <tr>
                                            <th>Date</th>
                                            <th> product</th>
                                            <th> quantity</th>
                                            <th> price</th>
                                            

                                      
                                            

                                        </tr>
                                    </thead>
                            <tbody>
                                    <?php
                                    $sql = "SELECT *, (select product_name from products where id=sales_details.product_id)as product_name, (select Symbol from units where UnitID=(select Units from products where id=sales_details.product_id ))as units  from sales_details where business_id='$businespro' order by id desc limit 10";
                                 $resultp = mysqli_query($conn, $sql);

                               if (mysqli_num_rows($resultp) > 0) {
                                  ?>
                                    
                                    <?php
                                    $no = 0;
                                    while($rown = mysqli_fetch_assoc($resultp)) {
                                        $no++;
                                            ?>
                              <td><?php echo $rown['date_time']; ?></td>

                                    <td><?php echo $rown['product_name']; ?></td>
                              <td><?php echo $rown['quantity']." ".$rown['units']; ?></td>
                              <td><?php echo $rown['selling_price']; ?></td>
                              
                            </tr>
                                        
                                        <?php


                                 }
                                  } else {
                                  echo "<h4 style='color:red;'>0 results</h4>";
                                  }




                                  ?>

                                    </tbody>
                                </table>

          </div>
                <div class="span12"> 
                  <h1><center>LAST 10 Purchases</center></h1>
                    <table  id="table" data-toggle="table" data-pagination="true" data-search="true" data-show-columns="true" data-show-pagination-switch="true" data-show-refresh="false" data-key-events="true" data-show-toggle="false" data-resizable="false" data-cookie="true"data-cookie-id-table="saveId" data-show-export="true" data-click-to-select="true" data-toolbar="#toolbar" data-export-options='{"fileName": "Testing_filename"}'>
                                    <thead>
                                        <tr>
                                            <th>Date</th>
                                            <th> product</th>
                                            <th> quantity</th>
                                            <th> price</th>
                                            

                                        </tr>
                                    </thead>
                            <tbody>
                                    <?php
                                    $sqlp = "SELECT *, (select product_name from products where id=purchases.product_id)as product_name, (select Symbol from units where UnitID=(select Units from products where id=purchases.product_id ))as units  from purchases where business_id='$businespro' order by id desc limit 10";
                                 $result = mysqli_query($conn, $sqlp);

                               if (mysqli_num_rows($resultp) > 0) {
                                  ?>
                                    
                                    <?php
                                    $no = 0;
                                    while($row = mysqli_fetch_assoc($result)) {
                                        $no++;
                                            ?>
                              <td><?php echo $row['date_time']; ?></td>

                                    <td><?php echo $row['product_name']; ?></td>
                              <td><?php echo $row['quantity']." ".$row['units']; ?></td>
                              <td><?php echo $row['unit_price']; ?></td>
                              
                            </tr>
                                        
                                        <?php


                                 }
                                  } else {
                                  echo "<h4 style='color:red;'>0 results</h4>";
                                  }




                                  ?>

                                    </tbody>
                                </table>

          </div>
               <div class="span12">
                                   
                                   <?php
include '../includes/connection.php';
                                   // Create connection
$sqllog = mysqli_query($con,"SELECT id, (select name from users where id=logs.user_id) as name, activity, date_time FROM logs where business_id='$businespro' order by id DESC limit 10");
//$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($sqllog) > 0) {
    // output data of each row
    


                                   ?>
                                    
                                    <h1>LAST 10 TRANSACTIONS</h1>
                                    <table  id="table" data-toggle="table" data-pagination="true" data-search="true" data-show-columns="false" data-show-pagination-switch="true" data-show-refresh="false" data-key-events="true" data-show-toggle="false" data-resizable="false" data-cookie="true"
                                        data-cookie-id-table="saveId" data-show-export="true" data-click-to-select="true" data-toolbar="#toolbar" data-export-options='{"fileName": "Testing_filename"}'>
                                        <thead>
                                            <tr>
                                                <th>S/NO</th>
                                                <th width="20%">User Name</th>
                                                <th>Activity</th>
                                                <th width="20%">Date/Time</th>
                                                

                                            </tr>
                                        </thead>
                                        <tbody>
                                        
                                        <?php
                    $no = 0;
                    while($rowlog = mysqli_fetch_assoc($sqllog)) {
                    $no++;
                        ?>
                    <tr class="gradeU">
                                                <td><?php echo $no; ?></td>
                                                <td><?php echo $rowlog['name']; ?></td>
                                                <td><?php echo $rowlog['activity']; ?></td>
                                                <td class="center"><?php echo $rowlog['date_time']; ?></td>
                                                
                                             
                                            </tr>
                                            
                                            <?php


  }
} else {
    echo "0 results";
}

mysqli_close($con);


                                        ?>
                                            
                                        </tbody>
                                    </table>
                                    
                                </div>
                  
                                 
                                
                                
                            </div>
                        </div>
                    </div>
                    <!-- /block -->
                </div>
            </div>
        </div>
        
        <hr>
        <?php include '../includes/footer.php'; ?>
    </div>
    <!--/.fluid-container-->

    <!--==========Footer js======-->
    <?php require_once("../includes/footerjs.php");?>
    <!--==========Footer js======-->
<script type = "text/javascript">
function confirmationDelete(anchor){
    var conf = confirm("Are you sure you want to delete this Branch?");
    if(conf){
        window.location = anchor.attr("href");
    }
} 
function confirmationSuspend(anchor){
    var conf1 = confirm("Are you sure you want to Deactivate this Branch?");
    if(conf1){
        window.location = anchor.attr("href");
    }
}  
function confirmationReturn(anchor){
    var conf2 = confirm("Are you sure you want to Activate this Branch?");
    if(conf2){
        window.location = anchor.attr("href");
    }
}      
</script>
<script src="../data-table-js/bootstrap-table.js"></script>
<script src="../data-table-js/tableExport.js"></script>
<script src="../data-table-js/data-table-active.js"></script>
<script src="../data-table-js/bootstrap-table-editable.js"></script>
<script src="../data-table-js/bootstrap-editable.js"></script>
<script src="../data-table-js/bootstrap-table-resizable.js"></script>
<script src="../data-table-js/colResizable-1.5.source.js"></script>
<script src="../data-table-js/bootstrap-table-export.js"></script>
</body>


</html>

