 <?php 
	include("my_functions.php");
 
	include('Aira_settings.php');
	
	$pagetitle = "Dashboard";
	require('includes/applicationtop.php');
	require('includes/applicationmenu.php');
	
	Level_negatives( 0);
	
	
	
	 
	
	function Level_negatives(  $no){
		 
		DB::query('UPDATE item_stock_level SET quantity='.$no.' WHERE quantity < 0 ');
			
		 
	}
	
	 
?>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
		
		<?php
		
		 $span = 30;
		 $time =1;
		 $auction = date('Y-m-d');
		 
		  $auction =  date('Y-m-d', strtotime($auction. ' + '.$time.' days'));
		  
		  Jobstatus_counts( $auction);
		
		?>
          <div class="col-sm-4">
            <h4 class="m-0 text-dark">Dashboard</h4> 
          </div><!-- /.col -->
		  
		  <div class="col-sm-4">
            <h4 class="m-1 text-green">  <a href="<?php echo $base_url; ?>jobstatuscheck"> Should be Ready: <?= Jobstatus_counts( );?> </a></h4> 
          </div><!-- /.col -->
		  
		  <div class="col-sm-4">
            <h4 class="m-1 text-warning"> To be ready Tommorow: <?= Jobstatus_counts($auction );?></h4> 
          </div><!-- /.col -->
       
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
	  <?php if($_SESSION["connectedusergroup"] < 5){
		  ?>
        <div class='card'>
          <div clas='card card-body'>
   <?php 

   
     
      $target =  intval(DB::queryFirstField("SELECT target  FROM  targets WHERE tperiod = CURRENT_DATE()  "));
	  IF($target < 1){
	  
	   $target =  intval(DB::queryFirstField("SELECT target FROM targets   ORDER BY  ta_id  DESC LIMIT 1  ")); 
	  }
	  $branch = $_SESSION["connecteduserbranch"];
	  $cash  = 0;
	  if($branch < 1){
		  
       $cash1  = intval( DB::queryFirstField("SELECT sum(bill) FROM  cash_receipt WHERE customer_change > -1 AND value_date = CURRENT_DATE()  AND is_cancelled = 0     "));
	   $cash2  = intval( DB::queryFirstField("SELECT sum(amount)  FROM  cash_receipt WHERE  customer_change < 0 AND value_date = CURRENT_DATE()  AND is_cancelled = 0     "));
	  $cash = $cash1+ $cash2;
	  }else {
	   								
		   $cash1  = intval( DB::queryFirstField("SELECT sum(bill) FROM  cash_receipt WHERE customer_change > -1 AND value_date = CURRENT_DATE()  AND is_cancelled = 0 and  shop =".$branch."   ")); 
	 
		  $cash2  = intval( DB::queryFirstField("SELECT sum(amount) FROM  cash_receipt WHERE customer_change < 0 AND value_date = CURRENT_DATE()  AND is_cancelled = 0 and  shop =".$branch."   ")); 
	     $cash = $cash1+ $cash2;
	 }

     $dept = InvoiceModeTopups2( DATE('Y-m-d'), DATE('Y-m-d') );
 
      $collected =   workshopcollected( ) + $dept    ;
      
      $topups= intval(todaystopups( date('Y-m-d')));

       $progress = 0;
       $collected = $cash + $collected + $topups;  
       $control = 100 - $progress;
       if($target > 0){

       $progress = 100*$collected /$target;
       }
	   
	   //get monly targets
	   
	   $mtarget =  intval(DB::queryFirstField("SELECT target  FROM  mtargets WHERE  MONTH(tperiod) = MONTH(now())  and  YEAR(tperiod) = YEAR(now())   "));
	  IF($mtarget < 1){
	  
	   $mtarget =  intval(DB::queryFirstField("SELECT target FROM mtargets   ORDER BY  ta_id  DESC LIMIT 1  ")); 
	  }
      $cashm  = intval( DB::queryFirstField("SELECT sum(bill) FROM  cash_receipt WHERE   customer_change > -1 AND  MONTH(value_date) = MONTH(now())  and  YEAR(value_date) = YEAR(now())    AND is_cancelled = 0  ")); 
      $cashm  += intval( DB::queryFirstField("SELECT sum(amount) FROM  cash_receipt WHERE  customer_change < 0 AND  MONTH(value_date) = MONTH(now())  and  YEAR(value_date) = YEAR(now())    AND is_cancelled = 0  ")); 
       
	  $collectedm =  periodic_workshop_collections();
        $topupsm= intval(mtodaystopups( date('Y-m')));

       $progressm = 0;
       $collectedm = $cashm + $collectedm + $topupsm;
       $controlm = 100 - $progressm;
       if($mtarget > 0){

       $progressm = 100*$collectedm /$mtarget;
       }
	   $color = $colorm = 'danger';
	   
	   if($progress < 41){
		   $color ='danger';
	   }else 
	   if($progress < 71){
		   $color ='warning';
	   }
	   else if($progress  < 91){
		   $color ='info';
	   }
	   else {
		   $color ='success';
	   }
	   
	    if($progressm < 41){
		   $colorm ='danger';
	   }else 
	   if($progress < 71){
		   $colorm ='warning';
	   }
	   else if($progress  < 91){
		   $colorm ='info';
	   }
	   else {
		   $colorm ='success';
	   }
	   
      
      ?>
      <h4>Daily Target <b> <?= number_format($target, 2) ?> </b> Collected <b> <?=  number_format($collected , 2)?>  </b></h4>

      <div class="progress" style="height: 60px;"> 
        <div class="progress-bar  bg-<?= $color?>" role="progressbar" style="width: <?= $progress?>%" aria-valuenow="<?= $progress?>" aria-valuemin="0" aria-valuemax="100"> </div>
          </div>
      <br />
	  
	   <h4>Monthly Target <b> <?= number_format($mtarget, 2) ?> </b> Collected <b> <?=  number_format($collectedm , 2)?>  </b></h4>

      <div class="progress" style="height: 60px;"> 
        <div class="progress-bar  bg-<?= $colorm?>" role="progressbar" style="width: <?= $progressm?>%" aria-valuenow="<?= $progressm?>" aria-valuemin="0" aria-valuemax="100"> </div>
          </div>
      <br />
</div>
</div>

     
 
 
      <?php
						
            if(isactive( 2) > 0)
						{
              $branch = 0;
			  

              if($_SESSION["connectedusergroup"]==4){
                $branch = $_SESSION["connecteduserbranch"];

              }
					?>
					
					
					<!-- Small boxes (Stat box) -->
					<div class="row">
					<!-- /.col -->

           <!-- fix for small devices only -->
           <div class="clearfix hidden-md-up"></div>

<div class="col-12 col-sm-6 col-md-2">
  <div class="info-box mb-3">
    <span class="info-box-icon bg-success elevation-1"><i class="fas fa-shopping-cart"></i></span>

    <div class="info-box-content">
      <span class="info-box-text"> <a href="<?php echo $base_url;?>jobsearch/today/0" class="small-box-footer">Todays Jobs<i class="fa fa-arrow-circle-right"></i></a></span>
      <span class="info-box-number">
      <?=   number_format( sizeof(distcinct_jobs_repost( false, date('Y-m-d') , $branch)) , 2)?> 
         
    
</span>  
    </div>
    <!-- /.info-box-content -->
  </div>
  <!-- /.info-box -->
</div>
<!-- /.col --> 

<div class="col-12 col-sm-6 col-md-2">
            <div class="info-box mb-3">
              <span class="info-box-icon bg-info elevation-1"><i class="fas fa-file"></i></span>

              <div class="info-box-content">
                <span class="info-box-text">Today's Tasks</span>
                <span class="info-box-number">
                <?php echo number_format(distcinct_tasks( FALSE, date('Y-m-d') , $branch ) , 2); ?> 
                   	</span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->


          <div class="col-12 col-sm-6 col-md-2">
            <div class="info-box mb-3">
              <span class="info-box-icon bg-danger elevation-1"><i class="fas fa-thumbs-up"></i></span>

              <div class="info-box-content">
                <span class="info-box-text"> <a href="<?php echo $base_url;?>jobsreport/waiting/5" class="small-box-footer">Waiting <i class="fa fa-arrow-circle-right"></i></a></span>
                <span class="info-box-number">
				<?php echo number_format(job_status( 5 , $branch ) , 2); ?> 
												
				
				</span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->

          <!-- fix for small devices only -->
          <div class="clearfix hidden-md-up"></div>

          <div class="col-12 col-sm-6 col-md-2">
            <div class="info-box mb-3">
              <span class="info-box-icon bg-info elevation-1"><i class="fas fa-shopping-cart"></i></span>

              <div class="info-box-content">
                <span class="info-box-text"> <a  href="<?php echo $base_url;?>shortsummaries/waiting/6" class="small-box-footer">For pickup<i class="fa fa-arrow-circle-right"></i></a></span>
                <span class="info-box-number">
                <?php echo number_format(job_status( 6 , $branch ) , 2); ?> 
				 					
							
				</span>  
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->
          
		  
		  <!-- fix for small devices only -->
      <div class="clearfix hidden-md-up"></div>

<div class="col-12 col-sm-6 col-md-2">
  <div class="info-box mb-3">
    <span class="info-box-icon bg-danger elevation-1"><i class="fas fa-money"></i></span>

    <div class="info-box-content">
      <span class="info-box-text"> <a href="<?php echo $base_url;?>notcleared/waiting/3" class="small-box-footer">Not Cleared<i class="fa fa-arrow-circle-right"></i></a></span>
      <span class="info-box-number">
      <?php echo  sizeof(notcleared ( false ,  false ,  false, $branch   )) ; ?> 
         
    
</span>  
    </div>
    <!-- /.info-box-content -->
  </div>
  <!-- /.info-box -->
</div>
<!-- /.col -->

<!-- fix for small devices only -->
<div class="clearfix hidden-md-up"></div>

<div class="col-12 col-sm-6 col-md-2">
  <div class="info-box mb-3">
    <span class="info-box-icon bg-success elevation-1"><i class="fas fa-car"></i></span>

    <div class="info-box-content">
      <span class="info-box-text"> <a href="<?php echo $base_url;?>shortsummaries/waiting/3" class="small-box-footer">Picked<i class="fa fa-arrow-circle-right"></i></a></span>
      <span class="info-box-number">
      <?= number_format(intval(job_dispatched( 3 , date('Y-m-d') ), $branch) , 2);  ?> 
         
    
</span>  
    </div>
    <!-- /.info-box-content -->
  </div>
  <!-- /.info-box -->
</div>
<!-- /.col -->

<!-- fix for small devices only -->
<div class="clearfix hidden-md-up"></div>

<div class="col-12 col-sm-6 col-md-3">
  <div class="info-box mb-3">
    <span class="info-box-icon bg-success elevation-1"><i class="fas fa-coins"></i></span>

    <div class="info-box-content">
      <span class="info-box-text"> <a href="#" class="small-box-footer">Workshop Collections<i class="fa fa-arrow-circle-right"></i></a></span>
      <span class="info-box-number">  
      <?= 
      number_format(intval(todayjobsales(date('Y-m-d'), $branch)), 2);
      
      ?> 
         
    
</span>  
    </div>
    <!-- /.info-box-content -->
  </div>
  <!-- /.info-box -->
</div>
<!-- /.col -->

<div class="clearfix hidden-md-up"></div>

<div class="col-12 col-sm-6 col-md-3">
  <div class="info-box mb-3">
    <span class="info-box-icon bg-success elevation-1"><i class="fas fa-coins"></i></span>

    <div class="info-box-content">
      <span class="info-box-text"> <a href="<?php echo $base_url;?>notcleared/waiting/3" class="small-box-footer">In Depts<i class="fa fa-arrow-circle-right"></i></a></span>
      <span class="info-box-number">  
      <?= 
      number_format(intval(amount_to_be_not_cleared(false, $branch)), 2);
      
      ?> 
         
    
</span>  
    </div>
    <!-- /.info-box-content -->
  </div>
  <!-- /.info-box -->
</div>
<!-- /.col -->

<!-- fix for small devices only -->
<div class="clearfix hidden-md-up"></div>

<div class="col-12 col-sm-6 col-md-3">
  <div class="info-box mb-3">
    <span class="info-box-icon bg-success elevation-1"><i class="fas fa-money"></i></span>

    <div class="info-box-content">
      <span class="info-box-text"> <a href="<?php echo $base_url;?>collecteddepts/waiting/3" class="small-box-footer">Debts Collected Today<i class="fa fa-arrow-circle-right"></i></a></span>
      <span class="info-box-number">
      <?= number_format(intval(todaystopups( date('Y-m-d') , $branch))  , 2);  ?> 
         
    
</span>  
    </div>
    <!-- /.info-box-content -->
  </div>
  <!-- /.info-box -->
</div>
<!-- /.col -->

<div class="clearfix hidden-md-up"></div>

<div class="col-12 col-sm-6 col-md-3">
  <div class="info-box mb-3">
    <span class="info-box-icon bg-success elevation-1"><i class="fas fa-money"></i></span>

    <div class="info-box-content">
      <span class="info-box-text"> <a href="#" class="small-box-footer">Expanses<i class="fa fa-arrow-circle-right"></i></a></span>
      <span class="info-box-number">
     <?php $date = '';  $expanses_total = todays_expanses($branch); echo number_format($expanses_total, 0); ?>
         
    
</span>  
    </div>
    <!-- /.info-box-content -->
  </div>
  <!-- /.info-box -->
</div>
<!-- /.col -->
	 


		  
		  
        </div>
        <!-- /.row -->
	</div><!-- /.row -->
					<?php
						}
            ?>
						
        
      
	  
	  
	  	<?php

          if(isactive( 1) > 0)
          {
						if($_SESSION["connectedusergroup"] == 1)
						{
					?>
					
					
					<!-- Info boxes -->
        <div class="row">
          <div class="col-12 col-sm-6 col-md-3">
            <div class="info-box">
              <span class="info-box-icon bg-info elevation-1"><i class="fas fa-cog"></i></span>

              <div class="info-box-content">
                <span class="info-box-text">Todays Sales</span>
                <span class="info-box-number">
                  <?php  echo $cash; ?>
							
                  
                </span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->
          <div class="col-12 col-sm-6 col-md-3">
            <div class="info-box mb-3">
              <span class="info-box-icon bg-danger elevation-1"><i class="fas fa-thumbs-up"></i></span>

              <div class="info-box-content">
                <span class="info-box-text">Sold Items</span>
                <span class="info-box-number">
				<?php   echo number_format( INTVAL(DB::queryFirstField('SELECT COALESCE(SUM(quantity), 0) FROM cash_sale_item WHERE created_date LIKE "'.date("Y-m-d").'%"  AND is_cancelled = 0'), 2)); ?>
							
				
				</span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->

          <!-- fix for small devices only -->
          <div class="clearfix hidden-md-up"></div>

          <div class="col-12 col-sm-6 col-md-3">
            <div class="info-box mb-3">
              <span class="info-box-icon bg-success elevation-1"><i class="fas fa-shopping-cart"></i></span>

              <div class="info-box-content">
                <span class="info-box-text">Transactions</span>
                <span class="info-box-number">
				<?php echo number_format(DB::queryFirstField("SELECT COUNT(id) FROM cash_receipt WHERE value_date = CURRENT_DATE() AND is_cancelled = 0"), 0); ?>
							
				</span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->
          <div class="col-12 col-sm-6 col-md-3">
            <div class="info-box mb-3">
              <span class="info-box-icon bg-warning elevation-1"><i class="fas fa-dollar"></i></span>

              <div class="info-box-content">
                <span class="info-box-text"> <a href='<?php echo $base_url;?>expanse_report.php'>Expenses </a></span> 
                <span class="info-box-number"> <?php $date = ''; echo number_format(DB::queryFirstField("SELECT ifnull(sum(examount) , 0) FROM expanses WHERE  exdate >= CURDATE()  "), 0); ?></span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
		
				
					<!-- Info boxes -->
        <div class="row">
          <div class="col-12 col-sm-6 col-md-3">
            <div class="info-box">
              <span class="info-box-icon bg-danger elevation-1"><i class="fas fa-cog"></i></span>

              <div class="info-box-content">
                <span class="info-box-text">Canceled Receipts</span>
                <span class="info-box-number">
                 <?php echo number_format(DB::queryFirstField("SELECT COUNT(id) FROM cash_receipt WHERE cancelled_date>=%s AND cancelled_date<=%s AND is_cancelled = 1", date("Y-m-d"), date("Y-m-d")), 0); ?>
													
                  
                </span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->
          <div class="col-12 col-sm-6 col-md-3">
            <div class="info-box mb-3">
              <span class="info-box-icon bg-danger elevation-1"><i class="fas fa-trash"></i></span>

              <div class="info-box-content">
                <span class="info-box-text"> <a href='<?php echo $base_url;?>detailed_sales.php'> Damaged </a></span>
                <span class="info-box-number">
				<?php echo (number_format(DB::queryFirstField("SELECT COALESCE(count(quantity), 0), DATE_FORMAT(created_date, '%Y-%m-%d') FROM special_sale_item   WHERE bounce_type =1 AND  DATE(created_date) = CURDATE()  ", $_SESSION["connecteduserid"]), 2)); ?> 
											
				
				</span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->

          <!-- fix for small devices only -->
          <div class="clearfix hidden-md-up"></div>

          <div class="col-12 col-sm-6 col-md-3">
            <div class="info-box mb-3">
              <span class="info-box-icon bg-danger elevation-1"><i class="fas fa-shopping-cart"></i></span>

              <div class="info-box-content">
                <span class="info-box-text">Returns</span>
                <span class="info-box-number">
				<?php echo (number_format(DB::queryFirstField("SELECT COALESCE(count(quantity), 0), DATE_FORMAT(created_date, '%Y-%m-%d') FROM special_sale_item   WHERE  bounce_type =1 AND DATE(created_date) = CURDATE()  ", $_SESSION["connecteduserid"]), 2)); ?> 
											
				</span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->
          <div class="col-12 col-sm-6 col-md-3">
            <div class="info-box mb-3">
              <span class="info-box-icon bg-warning elevation-1"><i class="fas fa-users"></i></span>

              <div class="info-box-content">
                <span class="info-box-text"> <a href="<?php echo $base_url;?>depleted.php" >Depleted </a></span>
                <span class="info-box-number">
				<?php echo (number_format(DB::queryFirstField("SELECT count(id)   FROM `item_stock_level` WHERE `shop` IS NULL AND `quantity` <= 5 AND `is_active` = 1"))); ?>  
								
				</span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->
        </div>
		
		  <?php }
		  }
		  ?>
		
		
		
		  
		  <?php

          if(isactive( 1) > 0)
          {
						if($_SESSION["connectedusergroup"] == 1)
						{
					?>
		
		<?php 
		
		$feedback = 0;
		if($feedback > 0){
			
			?>
		
		 <div class="row">
          <div class="col-md-12">
            <div class="card card-info">
              <div class="card-header">
                <h5 class="card-title">Monthly Recap Report</h5>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse">
                    <i class="fas fa-minus"></i>
                  </button>
                  
                  <button type="button" class="btn btn-tool" data-card-widget="remove">
                    <i class="fas fa-times"></i>
                  </button>
                </div>
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                <div class="row">
                  <div class="col-md-8">
                      <!-- TABLE: LATEST ORDERS -->
                       <?php
					   
					   
                   $local_orders = local_orders(0, 0);
           
               if($local_orders[0] >0   ){          
        
        ?>
        
            <div class="card card-danger">
              <div class="card-header border-transparent">
                <h3 class="card-title">Latest orders with their states</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse">
                    <i class="fas fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-card-widget="remove">
                    <i class="fas fa-times"></i>
                  </button>
                </div>
              </div>
              <!-- /.card-header -->
              <div class="card-body table-responsive p-0">
                
			 
			 <table class="table table-hover text-nowrap">
                    <thead>
                    <tr>
                      <th>Status</th>
                      <th>Customer</th>
					  <th>Charge</th>
					  <th>Order Status</th>
					  <th>Order Type</th>
					  <th>Delivered by</th>
                      
					  
					  <th>Order Date</th>
					  <th>Email</th>
					   
					   
                      
                    </tr>
                    </thead>
                    <tbody>
					 <?php 
					   
					    echo $local_orders[1] ;
					 ?>
                     
                     
                    </tbody>
                  </table>
			  
			  
			  
			  
			  
                 
                <!-- /.table-responsive -->
              </div>
              <!-- /.card-body -->
              
              <!-- /.card-footer -->
            </div>
             <?php } ?>
            <!-- /.card -->
                    <!-- /.chart-responsive -->

                  </div>
                  <!-- /.col -->
                  <div class="col-md-4">
				  
				   <div class="card card-info">
              <div class="card-header">
                <h3 class="card-title">Customer's Feedback  </h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-card-widget="remove"><i class="fas fa-times"></i>
                  </button>
                </div>
              </div>
              <!-- /.card-header -->
              <div class="card-body">
			  
                    <p class="text-center">
                      <strong>Customer's Feedback <a href='<?php echo $base_url;?>customersfeedback.php'  > View Details </a> </strong>
                    </p>
					<?php 
					 

					$quick_stat = $row  = DB::query("SELECT sum(service_rate) as service_rate ,   sum(prices) as prices, sum(timeliness) as timeliness,  sum(recommend) as recommend, count(fd_id) as fd_id  FROM  feedbackdata 
				 
					
					 WHERE   capture_date >= DATE(NOW()) - INTERVAL 7 DAY ");
					$s_rate  =  $comp =  $time=  $prices = $support =  $recommend =  $fd_id = 0;
					 function color_code($rate){
						 $code = $rate/5;
						 if($code <= 0.25){
							 return 'danger';
						 }else if($code <=0.5){
							 return 'warning';
						 }elseif($code <=0.75){
							 return 'info';
						 }else{
							 return 'success';
						 }
					 }
					 
					  
					  foreach($quick_stat as $row)
							 {
							 
								$fd_id  = $row['fd_id'];
								if($fd_id > 0){
								$s_rate  = number_format($row['service_rate'] /$fd_id);
								 
								$prices  = number_format($row['prices'] /$fd_id);
								$time  = number_format($row['timeliness'] /$fd_id);
								 
								$recommend  = number_format($row['recommend'] /$fd_id);
								}
								 
								
							 }
							
										 
					?>
					<div class="progress-group">
                      Product recomendation.
                      <span class="float-right"><b><?php  echo  ($recommend );?></b>/5</span>
                      <div class="progress progress-sm">
                        <div class="progress-bar bg-<?php echo color_code($recommend);?>" style="width: <?php  echo ($recommend /5)*100;?>%"></div>
                      </div>
                    </div>
					
					 
					
					
					 <div class="progress-group">
                      Delivery time.
                      <span class="float-right"><b><?php  echo  $time;?></b>/5</span>
                      <div class="progress progress-sm">
                        <div class="progress-bar bg-<?php echo color_code($time);?>" style="width: <?php  echo ($time /5)*100;?>%"></div>
                      </div>
                    </div>
					
					
					 <div class="progress-group">
                      Price Rate
                      <span class="float-right"><b><?php  echo  ($prices);?></b>/5</span>
                      <div class="progress progress-sm">
                        <div class="progress-bar bg-<?php echo color_code($prices);?>" style="width: <?php  echo ($prices /5)*100;?>%"></div>
                      </div>
                    </div>
					
					  

                    <div class="progress-group">
                      Service
                      <span class="float-right"><b><?php  echo  ($s_rate );?></b>/5</span>
                      <div class="progress progress-sm">
                        <div class="progress-bar bg-<?php echo color_code($s_rate);?>" style="width: <?php  echo ($s_rate /5)*100;?>%"></div>
                      </div>
                    </div>
                    <!-- /.progress-group -->

                     
					</div>
					</div>
					
					 
            <!-- /.card -->
                  </div>
                  <!-- /.col -->
                </div>
                <!-- /.row -->
              </div>
              <!-- ./card-body -->
              <div class="card-footer">
                <div class="row">
                  <div class="col-sm-3 col-6">
				  
				  <?php 
				  $all_orders = local_orders_count(0, 0);
				  $pending =  local_orders_count(1, 0);
				  $transit =  local_orders_count(2, 0);
				   $done = local_orders_count(2, 0);
				   
				  $week_orders =  This_week(0, 0);
				  $week_pending =  This_week(1, 0);
				  $transit_weekly =   This_week(2, 0);
				   $done_weekly =  This_week(2, 0);
				   $pending_rate = $transit_rate = $done_rate = $week_rate = 0;
				   if($all_orders >0){
					   $week_rate = number_format(($week_orders /$all_orders)*100, 2);
				   }
				   if($pending >0){
					   $pending_rate = number_format(($week_pending /$pending)*100, 2);
					   
				   }
				    if($transit >0){
					   $transit_rate = number_format(($transit_weekly /$transit)*100, 2);
					   
				   }
				    if($done >0){
					   $done_rate = number_format(($done_weekly /$done)*100, 2);
					   
				   }
				   
				   
				   
				  
				  ?>
                    <div class="description-block border-right">
					<span class="description-percentage text-warning"><i class="fas fa-caret-left"></i> <?php  echo $week_rate;?>%</span>
                       
                      <h5 class="description-header"><?php   echo  $all_orders ;?></h5>
                      <span class="description-text">TOTAL ORDERS</span>
                    </div>
                    <!-- /.description-block -->
                  </div>
                  <!-- /.col -->
                  <div class="col-sm-3 col-6">
                    <div class="description-block border-right">
                      <span class="description-percentage text-warning"><i class="fas fa-caret-left"></i> <?php echo $pending_rate; ?>%</span>
                      <h5 class="description-header"><?php   echo $pending ;?></h5>
                      <span class="description-text">PENDING</span>
                    </div>
                    <!-- /.description-block -->
                  </div>
                  <!-- /.col -->
                  <div class="col-sm-3 col-6">
                    <div class="description-block border-right">
                      <span class="description-percentage text-success"><i class="fas fa-caret-up"></i> <?php  echo $transit_rate;?>%</span>
                      <h5 class="description-header"><?php    echo $transit ;?></h5>
                      <span class="description-text">TRANSIT</span>
                    </div>
                    <!-- /.description-block -->
                  </div>
                  <!-- /.col -->
                  <div class="col-sm-3 col-6">
                    <div class="description-block">
                      <span class="description-percentage text-danger"><i class="fas fa-caret-down"></i> <?php  echo $done_rate;?>%</span>
                      <h5 class="description-header"><?php    echo $done ;?></h5>
                      <span class="description-text">DELIVERED</span>
                    </div>
                    <!-- /.description-block -->
                  </div>
                </div>
                <!-- /.row -->
              </div>
              <!-- /.card-footer -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
		
						<?php } ?>
		
		 
		
		
		<div class="container-fluid">
        <div class="row">
          <div class="col-lg-6">
            <div class="card card-info">
			 
              <div class="card-header border-0">
                <div class="d-flex justify-content-between">
                  <h3 class="card-title">Last 7 days</h3>
				  
                  
                </div>
              </div>
              <div class="card-body">
                

                <div class="position-relative mb-4">
                  <canvas id="visitors-chart" height="200"></canvas>
                </div>
                
                

                <div class="d-flex flex-row justify-content-end">
                  <span class="mr-2">
                    <i class="fas fa-square text-primary"></i> Sales
                  </span>

                  
                  <span>
                    <i class="fas fa-square text-yellow"></i> Expanse
                  </span>
                  <span>
                    <i class="fas fa-square text-red"></i> Loss
                  </span>
                </div>
              </div>
            </div>
            <!-- /.card -->

          </div>

          <div class="col-lg-6">
		  <?php //print_r(monthly_sales());?>
            <div class="card card-info">
              <div class="card-header border-0">
                <div class="d-flex justify-content-between">
                  <h3 class="card-title">Monthly Projections</h3>
                  
                </div>
              </div>
              <div class="card-body">
                

                <div class="position-relative mb-4">
                  <canvas id="sales-chart" height="200"></canvas>
                </div>

                <div class="d-flex flex-row justify-content-end">
                  <span class="mr-2">
                    <i class="fas fa-square text-primary"></i> Sales
                  </span>

                    <span>
                    <i class="fas fa-square text-yellow"></i> Expanse
                  </span>
                  <span>
                    <i class="fas fa-square text-red"></i> Loss
                  </span>
                </div>
              </div>
            </div>
            <!-- /.card -->
          </div>
        </div>
      </div>


		<?php if( $feedback > 0) { ?>
		       <!-- TABLE: LATEST ORDERS -->
            <div class="card card-info">
              <div class="card-header border-transparent">
                <h3 class="card-title">New orders from WEB</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse">
                    <i class="fas fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-card-widget="remove">
                    <i class="fas fa-times"></i>
                  </button>
                </div>
              </div>
              <!-- /.card-header -->
              <div class="card-body table-responsive p-0">
		
	  
                <table class="table table-striped">
                  <thead>
                    <tr>
                      <th  >#</th>
                      <th>Order Id</th>
                      <th>Email Address</th>
                      <th  >Customer </th>
					  <th>Billing Address</th> 
					  <th align='right'>Amount</th> 
                    </tr>
                  </thead>
                  <tbody>
				  
				  <?php 
						
						$web_orders = web_orders(0);
						if(!empty($web_orders)){
						if($web_orders[0] >0){
							 	 	
									  echo $web_orders[1];
									
						}}else echo 0; ?>
                     
                  </tbody>
                </table>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
			
						<?php } ?>
						 
		
	 
		
		
						 
					<?php
						}
					?>
					
					<?php
						if($_SESSION["connectedusergroup"] == 2)
						{
					?>
					<!-- Info boxes -->
					<div class="row">
						<div class="col-md-3 col-sm-6 col-xs-12">
							<div class="info-box">
								<span class="info-box-icon bg-red"><i class="fa fa-circle-o"></i></span>
								<div class="info-box-content">
									<span class="info-box-text">Zero Balance Items</span>
									<span class="info-box-number"><?php echo (number_format(DB::queryFirstField("SELECT COUNT(id) FROM item_stock_level WHERE quantity = 0 AND is_active = 1 AND shop IS NULL"), 0)); ?></span>
								</div><!-- /.info-box-content -->
							</div><!-- /.info-box -->
						</div><!-- /.col -->
						
						<div class="col-md-3 col-sm-6 col-xs-12">
							<div class="info-box">
								<span class="info-box-icon bg-yellow"><i class="fa fa-sort-by-attributes-alt"></i></span>
								<div class="info-box-content">
									<span class="info-box-text">Reorder Level Items</span>
									<span class="info-box-number"><?php echo (number_format(DB::queryFirstField("SELECT COUNT(item_stock_level.id) FROM item_stock_level, stock_item WHERE item_stock_level.is_active = 1 AND item_stock_level.shop IS NULL AND item_stock_level.item = stock_item.id AND item_stock_level.quantity <= stock_item.reorder_level"), 0)); ?></span>
								</div><!-- /.info-box-content -->
							</div><!-- /.info-box -->
						</div><!-- /.col -->

						<!-- fix for small devices only -->
						<div class="clearfix visible-sm-block"></div>

						<div class="col-md-3 col-sm-6 col-xs-12">
							<div class="info-box">
								<span class="info-box-icon bg-green"><i class="fa fa-ok"></i></span>
								<div class="info-box-content">
									<span class="info-box-text">Active Batches</span>
									<span class="info-box-number"><?php echo number_format(0, 0); ?></span>
								</div><!-- /.info-box-content -->
							</div><!-- /.info-box -->
						</div><!-- /.col -->
						
						<div class="col-md-3 col-sm-6 col-xs-12">
							<div class="info-box">
								<span class="info-box-icon bg-aqua"><i class="fa fa-arrow-left"></i></span>
								<div class="info-box-content">
									<span class="info-box-text">Inward Returns <br /> Done by Shop Personel</span>
									<span class="info-box-number"><a href="<?php echo $base_url;?>returnstostore.php"><?php echo number_format(DB::queryFirstField("SELECT COUNT(id) FROM stock_item_movement WHERE destination IS NULL AND is_complete = 0"), 0); ?></a></span>
								</div><!-- /.info-box-content -->
							</div><!-- /.info-box -->
						</div><!-- /.col -->
						
						<div class="col-md-3 col-sm-6 col-xs-12">
							<div class="info-box">
								<span class="info-box-icon bg-red"><i class="fa fa-chain-broken"></i></span>
								<div class="info-box-content">
									<span class="info-box-text">Damage / Faulty</span>
									<span class="info-box-number">
									
									
									<a href="<?php echo $base_url;?>returnstostore.php">
									 <?php echo (number_format(DB::queryFirstField("SELECT COALESCE(count(quantity), 0), DATE_FORMAT(created_date, '%Y-%m-%d') FROM special_sale_item   WHERE  bounce_type >0 AND DATE(created_date) = CURDATE()  ", $_SESSION["connecteduserid"]), 2)); ?> 
							
									
									</a></span>
								</div><!-- /.info-box-content -->
							</div><!-- /.info-box -->
						</div><!-- /.col -->
						
						<div class="col-md-3 col-sm-6 col-xs-12">
							<div class="info-box">
								<span class="info-box-icon bg-red"><i class="fa fa-warning"></i></span>
								<div class="info-box-content">
									<span class="info-box-text">Depleted Products</span>
									<span class="info-box-number">
									
									
									
									<?php echo (number_format(DB::queryFirstField("SELECT count(id)   FROM `item_stock_level` WHERE `shop` IS NULL AND `quantity` <= 5 AND `is_active` = 1"))); ?>  
	
									  <br /><a href="<?php echo $base_url;?>depleted.php"> Read More
									
									</a></span>
								</div><!-- /.info-box-content -->
							</div><!-- /.info-box -->
						</div><!-- /.col -->
						
						
						<div class="col-md-3 col-sm-6 col-xs-12">
							<div class="info-box">
								<span class="info-box-icon bg-red"><i class="fa fa-chain-broken"></i></span>
								<div class="info-box-content">
									<span class="info-box-text">Recall from Shop</span>
									<span class="info-box-number">
									
									
									<a href="<?php echo $base_url;?>returnstostore.php">
									 <?php echo (number_format(DB::queryFirstField("SELECT COALESCE(count(quantity), 0), DATE_FORMAT(created_date, '%Y-%m-%d') FROM special_sale_item   WHERE bounce_type > 0 AND DATE(created_date) = CURDATE()  ", $_SESSION["connecteduserid"]), 2)); ?> 
							
									
									</a></span>
								</div><!-- /.info-box-content -->
							</div><!-- /.info-box -->
						</div><!-- /.col -->
						
						
						 
						
						
					</div><!-- /.row -->
					<?php
						}
					?>
					
					<?php
						if($_SESSION["connectedusergroup"] == 3)
						{
					?>
					<!-- Info boxes -->
					<div class="row">
						<div class="col-md-3 col-sm-6 col-xs-12">
							<div class="info-box">
								<span class="info-box-icon bg-aqua"><i class="fa fa-money"></i></span>
								<div class="info-box-content">
									<span class="info-box-text">Shop Sales</span>
									<span class="info-box-number"><?php echo (number_format(DB::queryFirstField("SELECT COALESCE(SUM(bill), 0) FROM cash_receipt WHERE shop=%i AND value_date = CURRENT_DATE() AND is_cancelled = 0", $_SESSION["connecteduserbranch"]), 2)); ?></span>
								</div><!-- /.info-box-content -->
							</div><!-- /.info-box -->
						</div><!-- /.col -->
						
						<div class="col-md-3 col-sm-6 col-xs-12">
							<div class="info-box">
								<span class="info-box-icon bg-red"><i class="fa fa-shopping-cart"></i></span>
								<div class="info-box-content">
									<span class="info-box-text">Sold Items</span>
									<span class="info-box-number"><?php echo (number_format(DB::queryFirstField("SELECT COALESCE(SUM(quantity), 0) FROM cash_sale_item WHERE (created_date>=%s AND created_date<=%s) AND shop=%i AND is_cancelled = 0", date("Y-m-d"), date("Y-m-d"), $_SESSION["connecteduserbranch"]), 2)); ?></span>
								</div><!-- /.info-box-content -->
							</div><!-- /.info-box -->
						</div><!-- /.col -->

						<!-- fix for small devices only -->
						<div class="clearfix visible-sm-block"></div>

						<div class="col-md-3 col-sm-6 col-xs-12">
							<div class="info-box">
								<span class="info-box-icon bg-green"><i class="fa fa-signal"></i></span>
								<div class="info-box-content">
									<span class="info-box-text">Transactions</span>
									<span class="info-box-number"><?php echo (number_format(DB::queryFirstField("SELECT COUNT(id) FROM cash_receipt WHERE shop=%i AND value_date = CURRENT_DATE() AND is_cancelled = 0", $_SESSION["connecteduserbranch"]), 0)); ?></span>
								</div><!-- /.info-box-content -->
							</div><!-- /.info-box -->
						</div><!-- /.col -->
						
						<div class="col-md-3 col-sm-6 col-xs-12">
							<div class="info-box">
								<span class="info-box-icon bg-yellow"><i class="fa fa-remove"></i></span>
								<div class="info-box-content">
									<span class="info-box-text">Cancelled Transactions</span>
									<span class="info-box-number"><?php echo (number_format(DB::queryFirstField("SELECT COUNT(id) FROM cash_receipt WHERE shop=%i AND value_date = CURRENT_DATE() AND is_cancelled = 1", $_SESSION["connecteduserbranch"]), 0)); ?></span>
								</div><!-- /.info-box-content -->
							</div><!-- /.info-box -->
						</div><!-- /.col -->
					</div><!-- /.row -->
					
					<div class="box box-info">
						<div class="box-header with-border">
							<h3 class="card-title">Cashier Summary</h3>
							<div class="box-tools pull-right">
								<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
							</div>
						</div><!-- /.box-header -->
						<div class="card-title">
							<div class="table-responsive">
								<table class="table no-margin">
									<thead>
										<tr>
											<th>Personnel</th>
											<th class="text-right">Transactions</th>
											<th class="text-right">Cash Sales Total</th>
										</tr>
									</thead>
									<tbody>
									<?php
										$cashierdata = DB::query("SELECT COUNT(cash_receipt.id) AS transactions, personnel_details.display_name, SUM(cash_receipt.bill) AS sales_total FROM cash_receipt LEFT JOIN personnel_details ON cash_receipt.created_by =  personnel_details.id WHERE cash_receipt.value_date = CURRENT_DATE() AND cash_receipt.shop=%i AND is_cancelled = 0 GROUP BY cash_receipt.created_by", $_SESSION["connecteduserbranch"]);
										
										$trxns = 0;
										$shopsales = 0;
										
										foreach($cashierdata as $cashier)
										{
											$trxns += $cashier['transactions'];
											$shopsales += $cashier['sales_total'];
									?>
										<tr>
											<td><?php echo $cashier['display_name']; ?></td>
											<td class="text-right"><?php echo number_format($cashier['transactions'], 0); ?></td>
											<td class="text-right"><?php echo number_format($cashier['sales_total'], 2); ?></td>
										</tr>
									<?php
										}
									?>
									</tbody>
									<tfoot>
										<tr>
											<th>Totals</th>
											<th class="text-right"><?php echo number_format($trxns, 0); ?></th>
											<th class="text-right"><?php echo number_format($shopsales, 2); ?></th>
										</tr>
									</tfoot>
								</table>
							</div><!-- /.table-responsive -->
						</div><!-- /.card-title -->
					</div><!-- /.box -->
					
					
						 <div class="card card-info">
              <div class="card-header border-transparent">
                <h3 class="card-title">Damaged / faulty </h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse">
                    <i class="fas fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-card-widget="remove">
                    <i class="fas fa-times"></i>
                  </button>
                </div>
              </div>
              <!-- /.card-header -->
              <div class="card-body table-responsive p-0"> <a href='<?php echo $base_url;?>detailed_sales.php'> View Details </a>
								<table class="table no-margin">
									<thead>
										<tr>
											<th>Personnel</th>
											<th class="text-right">Items</th>
											<th class="text-right">Loss Total</th>
										</tr>
									</thead>
									<tbody>
									<?php
									
									 $cashierdata = DB::query("SELECT count(special_sale_item.quantity) AS transactions, personnel_details.display_name, SUM(special_sale_item.sell_price) AS sales_total FROM special_sale_item LEFT JOIN personnel_details ON special_sale_item.created_by =  personnel_details.id WHERE  bounce_type >0 AND DATE(special_sale_item.created_date) = CURDATE() AND special_sale_item.shop=%i AND is_cancelled = 0 GROUP BY special_sale_item.created_by", $_SESSION["connecteduserbranch"]);
										
										$trxns = 0;
										$shopsales = 0;
										
										foreach($cashierdata as $cashier)
										{
											$trxns += $cashier['transactions'];
											$shopsales += $cashier['sales_total'];
									?>
										<tr>
											<td><?php echo $cashier['display_name']; ?></td>
											<td class="text-right"><?php echo number_format($cashier['transactions'], 0); ?></td>
											<td class="text-right"><?php echo number_format($cashier['sales_total'], 2); ?></td>
										</tr>
									<?php
										}
									?>
									</tbody>
									<tfoot>
										<tr>
											<th>Totals</th>
											<th class="text-right"><?php echo number_format($trxns, 0); ?></th>
											<th class="text-right"><?php echo number_format($shopsales, 2); ?></th>
										</tr>
									</tfoot>
								</table>
							</div><!-- /.table-responsive -->
						</div><!-- /.card-title -->
					 
					<?php
						$trxns = $shopsales = 0;
						}
					?>
					
					
					
					
					<!-- Small boxes (Stat box) -->
					<div class="row">
					
					<?php
						if($_SESSION["connectedusergroup"] == 4)
						{
					?>
					<!-- /.col -->
          <div class="col-12 col-sm-6 col-md-3">
            <div class="info-box mb-3">
              <span class="info-box-icon bg-danger elevation-1"><i class="fas fa-thumbs-up"></i></span>

              <div class="info-box-content">
                <span class="info-box-text"> <a href="<?php echo $base_url;?>cashsalesregister.php" class="small-box-footer">Sold Items <i class="fa fa-arrow-circle-right"></i></a></span>
                <span class="info-box-number">
				<?php  echo Sold_items($branch); ?>							
				
				</span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->

          <!-- fix for small devices only -->
          <div class="clearfix hidden-md-up"></div>

          <div class="col-12 col-sm-6 col-md-3">
            <div class="info-box mb-3">
              <span class="info-box-icon bg-success elevation-1"><i class="fas fa-shopping-cart"></i></span>

              <div class="info-box-content">
                <span class="info-box-text"> <a href="<?php echo $base_url;?>cashsalesregister.php" class="small-box-footer">Transactions<i class="fa fa-arrow-circle-right"></i></a></span>
                <span class="info-box-number">
				<?php 
					 echo  Transactions($branch);?>
									
							
				</span>  
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->
          <div class="col-12 col-sm-6 col-md-3">
            <div class="info-box mb-3">
              <span class="info-box-icon bg-warning elevation-1"><i class="fas fa-coins"></i></span>

              <div class="info-box-content">
                <span class="info-box-text">Sales value</span>
                <span class="info-box-number"><?php 
                $tsales= Todays_sales($branch);
                 echo number_format(($tsales) ,2)
                ?>
									</span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->
		  
		  
		  
		  <div class="col-12 col-sm-6 col-md-3">
            <div class="info-box mb-3">
              <span class="info-box-icon bg-warning elevation-1"><i class="fas fa-book"></i></span>

              <div class="info-box-content">
                <span class="info-box-text">Invoice balance</span>
                <span class="info-box-number">
                  <a href="<?php echo $base_url; ?>invoicespending">
				
				<?php 
				  $debt   = theinvoicebalances($branch);
        echo number_format((  $debt) ,2)
        ?>
        </a>
														</span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
		  
		  
        </div>
		
						<?php } ?>
		
		
		<div class="container-fluid">
        <div class="row">
          <div class="col-lg-12">
            <div class="card card-info">
			 
              <div class="card-header border-0">
                <div class="d-flex justify-content-between">
                  <h3 class="card-title">Sales by type <a  class="btn btn-warning" href="<?= $base_url; ?>salesbreakdown"> More</a></h3>
				  
                  
                </div>
              </div>
              <div class="card-body">
			  
			  <?php
									  
								  $from =  DATE('Y-m-d') ; 
									  $to = DATE('Y-m-d') ; 
									  $shop = $_SESSION["connecteduserbranch"];
								 $pdata = payment_types($from, $to , $shop);
								 
								 if(!empty($pdata)){
								
								?>
								
								 
								<table class="table table-striped table-bordered" id="receiptstable">
								
								<thead>
										<tr>
											<th>Mode</th>
											<th  >Sales</th>
											<th  >Deposits</th>
											<th  >Workshop / Repairs</th>
											<th  >Top Ups</th>
                      <th  >Invoice Top ups</th>
											<th  >Total</th>
										</tr>
									</thead>
								
								
								 
								<?php
								 
								
								 echo $pdata ;
								
								
								
								?>
								</table>
								
								<?php
									}
									
									?>
                

                 
              </div>
            </div>
            <!-- /.card -->

          </div>
		  </div>
		  </div>
		  
		  
        <!-- /.row -->
	</div><!-- /.row -->
	
	
			<?php if($_SESSION["connectedusergroup"] == 1) { ?>
			
			 <div class="card card-info">
              <div class="card-header border-transparent">
                <h3 class="card-title">Quick summary</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse">
                    <i class="fas fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-card-widget="remove">
                    <i class="fas fa-times"></i>
                  </button>
                </div>
              </div>
              <!-- /.card-header -->
              <div class="card-body table-responsive p-3"> 
							<h5> Cash Sale</h5> 
							 
              <table class="table table-striped table-bordered" id="receiptstable">
									<thead>
										<tr>
											<th>Shop</th>
											<th class="text-right">Transactions</th>
											<th class="text-right">Cash Sales Total</th>
										</tr>
									</thead>
									<tbody>
									<?php
										$shopsalesdata = DB::query("SELECT COUNT(cash_receipt.id) AS transactions, shop.full_name, SUM(cash_receipt.bill) AS sales_total FROM cash_receipt LEFT JOIN shop ON cash_receipt.shop =  shop.id WHERE customer_change > -1 AND cash_receipt.value_date = CURRENT_DATE() GROUP BY cash_receipt.shop ORDER BY full_name");
										
										$trxns = 0;
										$shopsales = 0;
										
										foreach($shopsalesdata as $shopsalesrow)
										{
											$trxns += $shopsalesrow['transactions'];
											$shopsales += $shopsalesrow['sales_total'];
									?>
										<tr>
											<td><?php echo $shopsalesrow['full_name']; ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['transactions'], 0); ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['sales_total'], 2); ?></td>
										</tr>
									<?php
										}
									?>
									</tbody>
									<tfoot>
										<tr>
											<th>Totals</th>
											<th class="text-right"><?php echo number_format($trxns, 0); ?></th>
											<th class="text-right"><?php echo number_format($shopsales, 2); ?></th>
										</tr>
									</tfoot>
								</table>
								</div>
								
						 <div class="card-body table-responsive p-3"> 
							 <h5> Invoice Sale</h5> 
							 
              <table class="table table-striped table-bordered" id="receiptstable">
									<thead>
										<tr>
											<th>Shop</th>
											<th class="text-right">Transactions</th>
											<th class="text-right">Invoice Sales Total</th>
										</tr>
									</thead>
									<tbody>
									<?php
										$shopsalesdata = DB::query("SELECT COUNT(cash_receipt.id) AS transactions, shop.full_name, SUM(cash_receipt.amount) AS sales_total FROM cash_receipt LEFT JOIN shop ON cash_receipt.shop =  shop.id WHERE customer_change < 0 AND cash_receipt.value_date = CURRENT_DATE() GROUP BY cash_receipt.shop ORDER BY full_name");
										
										$trxns = 0;
										$shopsales = 0;
										
										foreach($shopsalesdata as $shopsalesrow)
										{
											$trxns += $shopsalesrow['transactions'];
											$shopsales += $shopsalesrow['sales_total'];
									?>
										<tr>
											<td><?php echo $shopsalesrow['full_name']; ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['transactions'], 0); ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['sales_total'], 2); ?></td>
										</tr>
									<?php
										}
									?>
									</tbody>
									<tfoot>
										<tr>
											<th>Totals</th>
											<th class="text-right"><?php echo number_format($trxns, 0); ?></th>
											<th class="text-right"><?php echo number_format($shopsales, 2); ?></th>
										</tr>
									</tfoot>
								</table>
								</div>
								</div>
								
								
								
								
								
								
								
								
								
								
								
								
								
													
								<div class="card card-info">
              <div class="card-header border-transparent">
                <h3 class="card-title">Cashiers Summary</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse">
                    <i class="fas fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-card-widget="remove">
                    <i class="fas fa-times"></i>
                  </button>
                </div>
              </div>
              <!-- /.card-header -->
              <div class="card-body table-responsive p-3">
			  <H5> Cash sale </H5>
							  <table class="table table-hoover table-bordered">
									<thead>
										<tr>
											<th>Shop</th>
											<th>Personnel</th>
											<th class="text-right">Transactions</th>
											<th class="text-right">Cash Sales Total</th>
										</tr>
									</thead>
									<tbody>
									<?php
										$shopsalesdata = DB::query("SELECT COUNT(cash_receipt.id) AS transactions, shop.full_name, personnel_details.display_name, SUM(cash_receipt.bill) AS sales_total FROM cash_receipt LEFT JOIN personnel_details ON cash_receipt.created_by =  personnel_details.id LEFT JOIN shop ON cash_receipt.shop = shop.id WHERE customer_change > -1  AND cash_receipt.value_date = CURRENT_DATE() GROUP BY cash_receipt.created_by ORDER BY full_name, display_name");
										
										$trxns = 0;
										$shopsales = 0;
										$useshop = "";
										foreach($shopsalesdata as $shopsalesrow)
										{
											$trxns += $shopsalesrow['transactions'];
											$shopsales += $shopsalesrow['sales_total'];
											
											if($useshop != $shopsalesrow['full_name'])
											{
									?>
										<tr>
											<td><?php echo $shopsalesrow['full_name']; ?></td>
											<td><?php echo $shopsalesrow['display_name']; ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['transactions'], 0); ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['sales_total'], 2); ?></td>
										</tr>
									<?php
											}
											else
											{
									?>
										<tr>
											<td></td>
											<td><?php echo $shopsalesrow['display_name']; ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['transactions'], 0); ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['sales_total'], 2); ?></td>
										</tr>
									<?php
											}
											$useshop = $shopsalesrow['full_name'];
										}
									?>
									</tbody>
									<tfoot>
										<tr>
											<th>Totals</th>
											<th></th>
											<th class="text-right"><?php echo number_format($trxns, 0); ?></th>
											<th class="text-right"><?php echo number_format($shopsales, 2); ?></th>
										</tr>
									</tfoot>
								</table>
								</div>
								
								
								  <div class="card-body table-responsive p-3">
								  <H5> Invoice sale </H5>
							  <table class="table table-hoover table-bordered">
									<thead>
										<tr>
											<th>Shop</th>
											<th>Personnel</th>
											<th class="text-right">Transactions</th>
											<th class="text-right">Cash Sales Total</th>
										</tr>
									</thead>
									<tbody>
									<?php
										$shopsalesdata = DB::query("SELECT COUNT(cash_receipt.id) AS transactions, shop.full_name, personnel_details.display_name, SUM(cash_receipt.amount) AS sales_total FROM cash_receipt LEFT JOIN personnel_details ON cash_receipt.created_by =  personnel_details.id LEFT JOIN shop ON cash_receipt.shop = shop.id WHERE  customer_change < 0 and  cash_receipt.value_date = CURRENT_DATE() GROUP BY cash_receipt.created_by ORDER BY full_name, display_name");
										
										$trxns = 0;
										$shopsales = 0;
										$useshop = "";
										foreach($shopsalesdata as $shopsalesrow)
										{
											$trxns += $shopsalesrow['transactions'];
											$shopsales += $shopsalesrow['sales_total'];
											
											if($useshop != $shopsalesrow['full_name'])
											{
									?>
										<tr>
											<td><?php echo $shopsalesrow['full_name']; ?></td>
											<td><?php echo $shopsalesrow['display_name']; ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['transactions'], 0); ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['sales_total'], 2); ?></td>
										</tr>
									<?php
											}
											else
											{
									?>
										<tr>
											<td></td>
											<td><?php echo $shopsalesrow['display_name']; ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['transactions'], 0); ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['sales_total'], 2); ?></td>
										</tr>
									<?php
											}
											$useshop = $shopsalesrow['full_name'];
										}
									?>
									</tbody>
									<tfoot>
										<tr>
											<th>Totals</th>
											<th></th>
											<th class="text-right"><?php echo number_format($trxns, 0); ?></th>
											<th class="text-right"><?php echo number_format($shopsales, 2); ?></th>
										</tr>
									</tfoot>
								</table>
								</div>
								</div>
								
								<div class="card card-info">
              <div class="card-header border-transparent">
                <h3 class="card-title">Damage / Faulty Summary</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse">
                    <i class="fas fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-card-widget="remove">
                    <i class="fas fa-times"></i>
                  </button>
                </div>
              </div>
              <!-- /.card-header -->
              <div class="card-body table-responsive p-0">
							 
					 
					 
						 
						 
						 
								<table class="table table-hoover table-bordered">
									<thead>
										<tr>
											<th>Shop</th>
											<th class="text-right">Transactions</th>
											<th class="text-right">Cash Sales Total</th>
										</tr>
									</thead>
									<tbody>
									<?php
										$shopsalesdata = DB::query("SELECT COUNT(special_receipt.id) AS transactions, shop.full_name, SUM(special_receipt.bill) AS sales_total FROM special_receipt LEFT JOIN shop ON special_receipt.shop =  shop.id WHERE  special_receipt.bounce_type > 0 AND  special_receipt.value_date = CURRENT_DATE() GROUP BY special_receipt.shop ORDER BY full_name");
										
										$trxns = 0;
										$shopsales = 0;
										
										foreach($shopsalesdata as $shopsalesrow)
										{
											$trxns += $shopsalesrow['transactions'];
											$shopsales += $shopsalesrow['sales_total'];
									?>
										<tr>
											<td><?php echo $shopsalesrow['full_name']; ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['transactions'], 0); ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['sales_total'], 2); ?></td>
										</tr>
									<?php
										}
									?>
									</tbody>
									<tfoot>
										<tr>
											<th>Totals</th>
											<th class="text-right"><?php echo number_format($trxns, 0); ?></th>
											<th class="text-right"><?php echo number_format($shopsales, 2); ?></th>
										</tr>
									</tfoot>
								</table>
								</div>
								</div>
								
								<div class="card card-info">
              <div class="card-header border-transparent">
                <h3 class="card-title">Damage / Faulty  Items as  reported by cashiers in  Summary</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse">
                    <i class="fas fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-card-widget="remove">
                    <i class="fas fa-times"></i>
                  </button>
                </div>
              </div>
              <!-- /.card-header -->
              <div class="card-body table-responsive p-0">
							 
					
					
					 
					 
							 	<table class="table table-hoover table-bordered">
									<thead>
										<tr>
											<th>Shop</th>
											<th>Personnel</th>
											<th class="text-right">Transactions</th>
											<th class="text-right">Cost Total</th>
										</tr>
									</thead>
									<tbody>
									<?php
										$shopsalesdata = DB::query("SELECT COUNT(special_receipt.id) AS transactions, shop.full_name, personnel_details.display_name, SUM(special_receipt.bill) AS sales_total FROM special_receipt LEFT JOIN personnel_details ON special_receipt.created_by =  personnel_details.id LEFT JOIN shop ON special_receipt.shop = shop.id WHERE  special_receipt.bounce_type > 0 AND special_receipt.value_date = CURRENT_DATE() GROUP BY special_receipt.created_by ORDER BY full_name, display_name");
										
										$trxns = 0;
										$shopsales = 0;
										$useshop = "";
										foreach($shopsalesdata as $shopsalesrow)
										{
											$trxns += $shopsalesrow['transactions'];
											$shopsales += $shopsalesrow['sales_total'];
											
											if($useshop != $shopsalesrow['full_name'])
											{
									?>
										<tr>
											<td><?php echo $shopsalesrow['full_name']; ?></td>
											<td><?php echo $shopsalesrow['display_name']; ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['transactions'], 0); ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['sales_total'], 2); ?></td>
										</tr>
									<?php
											}
											else
											{
									?>
										<tr>
											<td></td>
											<td><?php echo $shopsalesrow['display_name']; ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['transactions'], 0); ?></td>
											<td class="text-right"><?php echo number_format($shopsalesrow['sales_total'], 2); ?></td>
										</tr>
									<?php
											}
											$useshop = $shopsalesrow['full_name'];
										}
									?>
									</tbody>
									<tfoot>
										<tr>
											<th>Totals</th>
											<th></th>
											<th class="text-right"><?php echo number_format($trxns, 0); ?></th>
											<th class="text-right"><?php echo number_format($shopsales, 2); ?></th>
										</tr>
									</tfoot>
								</table>
								</div>
								</div>
								
		  <?php } ?>
			
		 
						
						
						<?php
						
						 
						if($_SESSION["connectedusergroup"] == 4) {
						
						
						 $web_orders = web_orders(0);
             if(empty($web_orders)) {}
             else 
						  if($web_orders[0] >0){
							 
					?>
					
					 
								
								<div class="card card-info">
              <div class="card-header border-transparent">
                <h3 class="card-title">New Web Orders</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse">
                    <i class="fas fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-card-widget="remove">
                    <i class="fas fa-times"></i>
                  </button>
                </div>
              </div>
              <!-- /.card-header -->
              <div class="card-body table-responsive p-0">
							 
								<table class="table no-margin">
									<thead>
										<tr>
											<th>#</th>
											<th>Order NO </th>
											<th  >Customer Email</th>
											<th  >Customer Name</th>
											<th  >Billing Address</th>
											<th  >Customer Contact</th>
											<th  >Order Value</th>
										</tr>
									</thead>
									<tbody>
									<?php 
									
									 echo $web_orders[1];
									
									?>
									 
									</tbody>
									 
								</table>
							 
			  
			  
			  
                 
                <!-- /.table-responsive -->
              </div>
              <!-- /.card-body -->
              
              <!-- /.card-footer -->
            </div>
            <!-- /.card -->
						  <?php }  ?>
               <?php
                   $local_orders = local_orders(0, 0);
           
               if($local_orders[0] >0){          
        
        ?>
					
			  <div class="card card-danger">
              <div class="card-header border-transparent">
                <h3 class="card-title">Latest orders with their states</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse">
                    <i class="fas fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-card-widget="remove">
                    <i class="fas fa-times"></i>
                  </button>
                </div>
              </div>
              <!-- /.card-header -->
              <div class="card-body table-responsive p-0">
                
			 
			  
			 <table class="table table-hover text-nowrap">
                    <thead>
                    <tr>
                      <th>Status</th>
                      <th>Customer</th>
					  <th>Charge</th>
					  <th>Order Status</th>
					  <th>Order Type</th>
					  <th>Delivered by</th>
                      
					  
					  <th>Order Date</th>
					  <th>Email</th>
					   
					   
                      
                    </tr>
                    </thead>
                    <tbody>
					 <?php
					   
					    echo $local_orders[1] ;
					 ?>
                     
                     
                    </tbody>
                  </table>
			   
			  
			  
			  
			  
                 
                <!-- /.table-responsive -->
              </div>
              <?php } ?>
              <!-- /.card-body -->
              
              <!-- /.card-footer -->
            </div>
            <!-- /.card -->
					
					
						<?php     } ?>

            <?php } 
            }
            ?>
    </section>
    <!-- /.content -->
  </div>
   

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->
  </aside>
  <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->

<!-- jQuery -->
<script src="<?php echo $base_url; ?>mod/plugins/jquery/jquery.min.js"></script>
<script src="<?php echo $base_url; ?>dist/js/jquery.min.js"></script>



<!-- jQuery UI 1.11.4 -->
<script src="<?php echo $base_url; ?>mod/plugins/jquery-ui/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
  $.widget.bridge('uibutton', $.ui.button)
</script>
<!-- Bootstrap 4 -->
<script src="<?php echo $base_url; ?>mod/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
 
<!-- Sparkline -->
<script src="<?php echo $base_url; ?>mod/plugins/sparklines/sparkline.js"></script>
 
<!-- daterangepicker -->
<script src="<?php echo $base_url; ?>mod/plugins/moment/moment.min.js"></script>
<script src="<?php echo $base_url; ?>mod/plugins/daterangepicker/daterangepicker.js"></script>
<!-- Tempusdominus Bootstrap 4 -->
<script src="<?php echo $base_url; ?>mod/plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
<!-- Summernote -->
<script src="<?php echo $base_url; ?>mod/plugins/summernote/summernote-bs4.min.js"></script>
<!-- overlayScrollbars -->
<script src="<?php echo $base_url; ?>mod/plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
<!-- AdminLTE App -->
<script src="<?php echo $base_url; ?>mod/dist/js/adminlte.js"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="<?php echo $base_url; ?>mod/dist/js/pages/dashboard.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="<?php echo $base_url; ?>mod/dist/js/demo.js"></script>
<script src="<?php echo $base_url; ?>mod/plugins/chart.js/Chart.min.js"></script>

<script>
		 
		
		$(".web_orders").click(function() {
			 
			
			 //var order = $('#Control').val();
			 var order = $(this).val();
			  //$('#Success').modal('hide');
			  
			 
			 
			    $.ajax({
				type: "POST",
				url: "process_web_order_start.php",
				data: {itemcode: order },
				 
				success: function(data){  
					 
					window.location.href = "display_order_items.php";
					 
					  
				}
		});
			 
		 });
		
		 $(".process_receipt").click(function() {
			 
			
			 //var order = $('#Control').val();
			 var order = $(this).val();
			  //$('#Success').modal('hide');
			 
			 
			    $.ajax({
				type: "POST",
				url: "process_web_order_start.php",
				data: {receipt: order },
				 
				success: function(data){  
					 
					window.location.href = "display_receipt_items.php";
					 
					  
				}
		});
			 
		 });


     /* global Chart:false */
     <?php 
     if($_SESSION["connectedusergroup"] ==1){
     $monthly = monthly_sales();

     $daily = daily_sales();  
   

    

     ?>

$(function () {
  'use strict'

  var ticksStyle = {
    fontColor: '#495057',
    fontStyle: 'bold'
  }

  var mode = 'index'
  var intersect = true

  var $salesChart = $('#sales-chart')
  // eslint-disable-next-line no-unused-vars
  var salesChart = new Chart($salesChart, {
    type: 'bar',
    data: {
      labels: <?php  echo json_encode($monthly[0]);?>,
      datasets: [
        {
          backgroundColor: '#007bff',
          borderColor: '#007bff',
          data: <?php  echo json_encode($monthly[1]);?>
        },
        {
          backgroundColor: '#FFFF00',
          borderColor: '#FFFF00',
          data: <?php  echo json_encode($monthly[2]);?>
        },
        {
          backgroundColor: '#FF0000',
          borderColor: '#FF0000',
          data: <?php  echo json_encode($monthly[3]);?>
        }
      ]
    },
    options: {
      maintainAspectRatio: false,
      tooltips: {
        mode: mode,
        intersect: intersect
      },
      hover: {
        mode: mode,
        intersect: intersect
      },
      legend: {
        display: false
      },
      scales: {
        yAxes: [{
          display: true,
          gridLines: {
            display: true,
           /* lineWidth: '4px',
            color: 'rgba(0, 0, 0, .2)',
            zeroLineColor: 'transparent'
            */
          },
          ticks: $.extend({
            beginAtZero: true,

            // Include a dollar sign in the ticks
            callback: function (value) {
              if (value >= 1000) {
                value /= 1000
                value += 'k'
              }

              return 'UGX.  ' + value 
            }
          }, ticksStyle)
        }],
        xAxes: [{
          display: true,
          gridLines: {
            display: true
          },
          ticks: ticksStyle
        }]
      }
    }
  })

  var $visitorsChart = $('#visitors-chart')
  // eslint-disable-next-line no-unused-vars
  var visitorsChart = new Chart($visitorsChart, {
    data: {
      labels: <?php  echo json_encode($daily[0]);?>,
      datasets: [{
        type: 'line',
        data: <?php  echo json_encode($daily[1]);?>,
        backgroundColor: 'transparent',
        borderColor: '#007bff',
        pointBorderColor: '#007bff',
        pointBackgroundColor: '#007bff',
        fill: false
        // pointHoverBackgroundColor: '#007bff',
        // pointHoverBorderColor    : '#007bff'
      },
      {
        type: 'line',
        data: <?php  echo json_encode($daily[2]);?>,
        backgroundColor: 'tansparent',
        borderColor: '#FFFF00',
        pointBorderColor: '#FFFF00',
        pointBackgroundColor: '#FFFF00',
        fill: false
        // pointHoverBackgroundColor: '#ced4da',
        // pointHoverBorderColor    : '#ced4da'
      },
      {
        type: 'line',
        data: <?php  echo json_encode($daily[3]);?>,
        backgroundColor: 'tansparent',
        borderColor: '#FF0000',
        pointBorderColor: '#FF0000',
        pointBackgroundColor: '#ced4da',
        fill: false
        // pointHoverBackgroundColor: '#ced4da',
        // pointHoverBorderColor    : '#ced4da'
      }]
    },
    options: {
      maintainAspectRatio: false,
      tooltips: {
        mode: mode,
        intersect: intersect
      },
      hover: {
        mode: mode,
        intersect: intersect
      },
      legend: {
        display: false
      },
      scales: {
        yAxes: [{
          display: true,
          gridLines: {
            display: true,
            lineWidth: '4px',
            color: 'rgba(0, 0, 0, .2)',
            zeroLineColor: 'transparent'
          },
          ticks: $.extend({
            beginAtZero: false,
            suggestedMax: 200,
             callback: function (value) {
              if (value >= 1000) {
                value /= 1000
                value += 'k'
              }

              return 'UGX.  ' + value 
            }
          
          },



           ticksStyle)
        }],
        xAxes: [{
          display: true,
          gridLines: {
            display: true
          },
          ticks: ticksStyle
        }]
      }
    }
  })
})

<?php } ?>
 
		
		 
		</script>


</body>
</html>
