<!DOCTYPE html>
<html>
    
    <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<?php
		include("../includes/header-links.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">Cash At hand Analysis</div>
                            </div>
                            <div class="block-content collapse in">
                                <div class="span12">
                                
                           
										
                                   <?php

include '../includes/connection.php';
//if($_SESSION['role']=="Super Admin") {
  $sql = mysqli_query($con,"SELECT sum(total_price)as totalsales,sum(paid)as totalpaid ,(select sum(amount) from cash_out where business_id=$business) as totalcashout,(select sum(amount) from expenses where business_id=$business) as totalexpenses  FROM sales where business_id='$business'");

//}else{
  $sql = mysqli_query($con,"SELECT sum(total_price)as totalsales,sum(paid)as totalpaid ,(select sum(amount) from cash_out where branch_id=$branch) as totalcashout,(select sum(amount) from expenses where branch_id=$branch) as totalexpenses  FROM sales where branch_id='$branch'");
//}
        
        if (mysqli_num_rows($sql)>0) {
          $row=mysqli_fetch_array($sql);
          $totalsales=$row['totalsales'];
          $totalpaid=$row['totalpaid'];
          $totalcashout=$row['totalcashout'];
          $totalexpenses=$row['totalexpenses'];

        }else{

          $totalsales=0;
          $totalpaid=0;
          $totalcashout=0;
          $totalexpenses=0;
        }
       $totaldebts=$totalsales-$totalpaid;
       $cash_at_hand=$totalsales-($totalexpenses+$totaldebts+$totalcashout);
      
    


                                   ?>
                                   <?php
                                               // if($_SESSION['role']=="Super Admin"){
                                                if( $permissions['export_cash_at_hand'] == 1){            
                                                  ?>
                                    
                                    <div id="toolbar">
                                        <select class="form-control">
                                                <option value="">Export Basic</option>
                                                <option value="all">Export All</option>
                                                <option value="selected">Export Selected</option>
                                            </select>
                                    </div>
                                    <?php 
                                                }?>
                                    <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>#</th>
                                                <th>Total Sales</th>
                                                <th>Total Expenses</th>
                                                <th>Total Debts</th>
                                                <th>Total Cashout</th>
                                                <th>Cash At Hand</th>
                                                
                                            </tr>
                                        </thead>
                                        <tbody>
                                        
                                        
										
										<tr class="gradeU">
                                                <td><?php echo "#"; ?></td>
                                               
                                                <td><?php echo number_format($totalsales); ?></td>
                                                <td><?php echo number_format($totalexpenses); ?></td>
                                                <td><?php echo number_format($totaldebts); ?></td>
                                                <td><?php echo number_format($totalcashout); ?></td>
                                                <td><?php echo number_format($cash_at_hand); ?></td>
                                                
                                                
                                                
												

                                        
                                            
                                        </tbody>
                                    </table>
                                    
                                </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 record?");
        if(conf){
            window.location = anchor.attr("href");
        }
    } 
    function confirmationSuspend(anchor){
        var conf1 = confirm("Are you sure you want to Suspend this supplier?");
        if(conf1){
            window.location = anchor.attr("href");
        }
    }  
    function confirmationReturn(anchor){
        var conf2 = confirm("Are you sure you want to Return this Supplier?");
        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>

