<?php
	include("my_functions.php");
	$pagetitle = "Today's Jobs report " .date('d-m-Y');
	require('includes/applicationtop.php');
	require('includes/applicationmenu.php');
	
	$err= "";
	
	$startdatevalid = false;

	$actual_link = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
	$parts = explode('todaysjobreport2' , $actual_link);
	
		$fromdate = false;
		$command = false;

		$startdatevalid = false;


		
	
 
?>
			<!-- Content Wrapper. Contains page content -->
			<div class="content-wrapper">
				<!-- Content Header (Page header) -->
				 

				<!-- Main content -->
				<section class="content">
					<!-- Default card -->
					<div class="card card-primary">
						<?php
							if($_SESSION["connectedusergroup"] == 1 || $_SESSION["connectedusergroup"] > 2)
							{
						?>
						<div class="card-body">
							<div id="servererrormessage">
							</div>
							
							<?php
								if($err!="")
								{
							?>
							<div class="alert alert-danger alert-dismissable">
								<i class="fa fa-ban"></i>
								<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button><br>
								<?php 
									echo $err; 
								?>
							</div>
							<?php
								}
							?>
							
							<div class="card card-info">
              <div class="card-header">
                <h6 class="card-title"><?= $pagetitle?></h6>
              </div>
              <div class="card-body">
			 
             		
						 
								 
								
								<div class="col-md-12" style="margin-top: 25px"></div>
								 
								<?php
                                 
                                $jobs = array();
                                $thedate=date('Y-m-d');
									 
                                $jobs2= minijobreport($thedate);
                                $k = 0;
									 

                                    if(!empty($jobs2)){
                                        $count = 0;
 
								?>
								<table class="table table-striped table-bordered"  >
									<thead>
										<tr>
											<th>Bar code</th>
											<th class="text-center">Receipt</th>
											<th class="text-right">Customer</th>
                                            <th class="text-center">Bill</th> 
                                            <th class="text-center">Paid</th>
											<th class="text-right">Balance</th>
                                            <th class="text-center">Payment Method</th> 
										</tr>
									</thead>
									<tbody>

                                    <?php
                                  

                                    $tbill = $tballance = $tpaid =0;
                                     foreach($jobs2 as $row){
                                        $tbill += $row['bill'];
                                        $tballance += $row['customer_change'];
                                        $tpaid     += $row['amount'];
                                        echo '<tr> 
                                        <td  > #'.( $k +=1).'   </td>
                                        <td> '.$row['receipt_number'].' </td>
                                        <td>'.$row['customer_name'].' </td>
                                        <td>'.number_format($row['bill']).' </td>
                                        <td>'.number_format($row['amount']).' </td>
                                        <td>'.number_format($row['customer_change']).' </td>
                                        
                                        <td> <a href="'.$GLOBALS['base_url'].'updatemodeofpayments/'.$row['id'].'">Update </a>'.$row['payment_name'].'  </td>
                                        
										   
                                        </tr>';



                                     }

                                     echo '<tr> 
                                     <td colspan="3" > Total  </td>
                                      
                                     <td>'.number_format($tbill).' </td>
                                     <td>'.number_format($tpaid).' </td>
                                     <td>'.number_format($tballance).' </td>
                                     
                                     <td>  </td>
                                     
                                        
                                     </tr>';


                                    
                                        

                                        ?>
										 
									</tbody>
								</table>

<h4> Top ups</h4>

                                <table class="table table-striped table-bordered"  >
									<thead>
										<tr>
											<th>Bar code</th>
											<th  >Receipt</th>
											<th  >Customer</th> 
											<th >Amount</th>
                                            <th  >Payment Method</th> 
										</tr>
									</thead>
									<tbody>

                                    <?php
                                    $thedate=date('Y-m-d');
                                    $topups= minitopups($thedate);
                                    
                                    
                                     $k = 0;

                                    $tbill = $tballance = $tpaid =0;

                                    $collected = topup_reports(date('Y-m-d') );

                                   

                                    foreach($collected as $job){

                                         
                                        $tbill += $job['topup']; 
                                        echo '<tr> 
                                        <td  > #'.( $k +=1).'   </td> 
                                        <td> '.$job['top_bar_code'].' </td>
                                        <td> '.Job_customer($job['top_bar_code']).' </td>
                                        <td>'.number_format($job['topup']).' </td> 
                                        
                                        <td> <a href="'.$GLOBALS['base_url'].'updatetopupmodeofpayment/'.$job['topid'].'">Update </a>'.payment_name($job['pmode']).'  </td>
                                        
										   
                                        </tr>';

                                    }
                                    

                                     echo '<tr> 
                                     <td colspan="3"  > Total  </td>
                                      
                                     <td>'.number_format($tbill).' </td> 
                                     
                                     <td>  </td>
                                     
                                        
                                     </tr>';


                                    
                                        

                                        ?>
										 
									</tbody>
								</table>
								<?php
                                    }else echo 'No data found';
								 
								?>
								 
							</div>
						</div><!-- /.card-body -->
						<?php
							}
							else
							{
						?>
						<div class="alert alert-danger alert-dismissable">
							<i class="fa fa-ban-circle"></i><br>
							Limited Access
						</div>
						<?php
							}
						?>
					</div><!-- /.card -->
				</section><!-- /.content -->
			</div><!-- /.content-wrapper -->

			 
		</div><!-- ./wrapper -->
		
		 

	 <?php include ('includes/general_footer.php')?> 
		 
	</body>
</html>