<?php
	include("my_functions.php");
	$pagetitle = "Dept collection";
	require('includes/applicationtop.php');
	require('includes/applicationmenu.php');
	
	$err= "";

    $actual_link = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
		//$parts = explode('dothetopups' , $actual_link);
		
    $fromdate = false;
    $command = false;
	
	$startdatevalid = false;
    $collected =  array();
	
	 
		 
        if(!empty($_POST["dispatch"])    ){
 
            $date =  date('Y-m-d', strtotime($_POST["dispatch"]));  
            $collected = topup_reports($date);
           
			
			 
			
			 
			 
		 
	}else{

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

       
        

        
								 
								  
 
    }
?>
			<!-- Content Wrapper. Contains page content -->
			<div class="content-wrapper">
				 

				<!-- Main content -->
				<section class="content">
					<!-- Default card -->
					<div class="card card-primary">
						<?php
							if($_SESSION["connectedusergroup"] == 1 || $_SESSION["connectedusergroup"] == 4)
							{
						?>
						<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">
                            
                               
							
							 
								<?php
									if($err=="" )
									{

                                        //echo $command;

                                        

                                        // $topay = topay($command   );
								?>
                                
								   

                                 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
 
                                         
                                         <!-- form-group -->
										 <div class="row">
                  
                  
                 
				  <label for="to">Enter date to search from</label>

										 <div class="input-group">   
												<input type="date" name="dispatch"  id ='to' class="form-control" value='<?php  if(isset($_POST['barcode'])) { echo  $_POST['barcode'] ; } ?>'   />
												<span class="input-group-btn">
													<button class="btn btn-primary btn-flat" type="submit" name="getreceiptsbtn" id="getreceiptsbtn">Go!</button>
												</span>
											</div>
									</div>

									<br /><br /><br />

 
                                      

                                        

                                    

                                    </form>
                                    <table class="table table-striped table-bordered" id="receiptstable">
									<thead>
										<tr>
											<th>Bar code</th>
											<th class="text-center">Item</th>
											<th class="text-right">Date</th>
                                            <th class="text-center">Client</th>
											<th class="text-right">Contact</th>
                                            <th class="text-center">Bill</th>
											<th class="text-right">Balance</th>
                                            <th class="text-center">type</th>
											<th class="text-right">Owner</th>
                                            <th class="text-center">Status</th>
                                            <th class="text-center">Dispatch date</th> 
										</tr>
									</thead>
									<tbody>


                                    <?php 
                                   

                                    //$collected
                                    $total =0;

                                    foreach($collected as $row){
                                        $top_bal = $row['top_bar_code'];

                                        $total += $row['topup'];
                                        echo '<tr> <td   >'.$top_bal.' </td> <td> <h6   tyle="font-size:18px;"> Amount Paid: '.number_format($row['topup'], 2).' </h6> </td>
                                        <td>'.$row['top_up_date'].' </td>
                                        
                                        <td colspan="9">  </td> </tr>';
                                        barcode_jobs( $top_bal);
                                    }

                                    echo '<tr> <td> Total </td><td   >'.number_format($total, 2).' </td>  
                                    
                                    <td colspan="11">  </td> </tr>';

                                    
                                    
                                    ?>




                                    <?php } ?>
                                </tbody>

                                </table>
								  
								   
                                     

                                </div>
                            </div>
              <!-- /.card-body -->
            </div>
									 
								
								   
								 
										 
								
								
								
								</div>
							</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>