<?php
	include("my_functions.php");
	$pagetitle = "Workshop jobs";
	require('includes/applicationtop.php');
	require('includes/applicationmenu.php');
	
	$err= "";
	
	$startdatevalid = false;

	$actual_link = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
	 
	
		$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-body table-responsive  ">
								 
								
								<div class="col-md-12" style="margin-top: 25px"></div>
								 
								<?php
                                 
                                $jobs = array();
									 
									
											
																	 
																	  
									$jobs =  DB::query("SELECT job_receipt.id, jobdata as item, customers.name,  created_date as receivedon, bill, amount as paid , bill-amount as balance , parent_bar_code as barcode FROM job_receipt join customers on customers.id = customer_id where bill > amount GROUP BY parent_bar_code order by created_date "  );

										 

                                         

                                

                                    if(!empty($jobs)){
                                        $count = 0;
 
								?>
								<table class="table table-striped table-bordered" id="receiptstable">
									<thead>
										<tr>
											<th>#</th>
											<th class="text-center">Item</th>
											<th class="text-right">Client</th> 
											<th class="text-right">Date</th>
                                            <th class="text-center">Bill</th>
											<th class="text-right">Paid</th>
                                            <th class="text-center">Balance</th>
											<th class="text-right">Barcode</th>
                                            
                                            <th class="text-center">Receipt</th> 
										</tr>
									</thead>
									<tbody>

                                    <?php
									 $bt = $p = $bal = 0;
                                     foreach($jobs as $row){
                                       $bill = $row['bill'];
									   $paid = $row['paid'];
									   $balance = $row['balance'];
									   $bt +=$bill;
									   $p  += $paid;
									   $bal += $balance;

                                        echo '<tr>  
										<td>'.$row['id'].' </td>
										<td>'.$row['item'].' </td>
										<td>'.$row['name'].' </td>
										<td>'.$row['receivedon'].' </td>
										<td>'.number_format($bill, 2).' </td>
										<td>'.number_format($paid, 2).' </td>
										<td>'.number_format($balance).' </td>
										<td>'.$row['barcode'].' </td>
                                        
										 
										  <td > <a class="btn btn-info" href="'.$GLOBALS['base_url'].'customreceipt/'.$row['barcode'].'" target="blank">  Receipt </a> </td>
                                        
                                        </tr>';
                                        

                                     }
									 
									  echo '<tr>  
										<td colspan="4">  </td> 
										<td>'.number_format($bt, 2).' </td>
										<td>'.number_format($p, 2).' </td>
										<td>'.number_format($bal).' </td>
										<td colspan="2">  </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>