<?php session_start(); ob_start(); ?>

<?php  include 'header.php'; ?>

<?php
	ini_set('display_errors', 0);
if(empty($_SESSION['LOGINID']) && empty($_SESSION['LOGINNM']) ){

	header("Location:index.php");
}


include("user.php");
	$date1 = $_GET["date1"];
	$date2 = $_GET["date2"];
	
?>


						  
	<?php
												  

$settingsSQL = mysqli_query($connection, "SELECT * FROM `settings` where name='address' ");
$settingsSQL = mysqli_fetch_object($settingsSQL);
									
$address = $settingsSQL->value;

$settingsSQL = mysqli_query($connection, "SELECT * FROM `settings` where name='mobile' ");
$settingsSQL = mysqli_fetch_object($settingsSQL);
									
$our_mobile = $settingsSQL->value;

$settingsSQL = mysqli_query($connection, "SELECT * FROM `settings` where name='email' ");
$settingsSQL = mysqli_fetch_object($settingsSQL);
									
$our_email = $settingsSQL->value;
								   
?>	

<html>

<style>
body {
  background: rgb(204,204,204); 
}
page {
  background: white;
  display: block;
  padding-top: 2cm;
  padding-left: 2cm;
  padding-right: 2cm;
  margin: auto;
  margin-bottom: 2.0cm;
}
page[size="A4"] {  
  width: 21cm;
  height: auto; 
}
page[size="A4"][layout="landscape"] {
  width: 29.7cm;
  height: 21cm;  
}

@media print {
  body, page {
    margin: 0;
    box-shadow: 0;
  }
}



</style>

  <head>
    <title>Booking Print</title>
	<meta http-equiv='content-type' content='text/html;charset=utf-8' />
  </head>
  
  <page size="A4">
  
  <body>
<center>
<table style="width:100%;border: 0px solid black;" cellpadding='0' height='' cellspacing='0'  >
 
  <tr align="center" >
    <td  style="width:100%; "  > <img src="assets/images/logo_wd.png" width="150" /> </br>
<?php echo "$address"; ?> </br>
<?php echo "$our_email"; ?> </br>
<?php echo "$our_mobile"; ?>  </br>
<b> Invoice Due List </b></br>
From Date : <?php echo "$date1"; ?> to  <?php echo "$date2"; ?>

	</td>
  
  </tr>
</table>

</br></br>

<table style="width:100%" cellpadding='' height='' cellspacing='0' border='0' align='center' valign= 'top' >
	<tr align="left" >
	
	
	
	
	  <td style="width:10%;border-bottom: 1px solid black;" > 
	   &nbsp;&nbsp; <b>ID </b>
      </td> 
	  <td style="width:15%;border-bottom: 1px solid black;" > 
	   <b>Customer ID</b>
      </td>
	  <td style="width:25%;border-bottom: 1px solid black;" > 
	   <b>Client Name</b>
      </td> 
	   
	    <td style="width:15%;border-bottom: 1px solid black;" > 
	   <b>Amount</b>
      </td> 
	    <td style="width:20%;border-bottom: 1px solid black;" > 
	  <b> Paid</b>
      </td> 
	   <td style="width:15%;border-bottom: 1px solid black;" > 
	  &nbsp;&nbsp; <b> Due</b>
      </td>
	</tr> 
	
	
	
	 <?php 
											
											$sl=0;
                                $sqlSelectedLG = "select t1.*,IFNULL(t4.paid,0) paid,(t1.inv_amount-t2.discount-IFNULL(t4.paid,0) ) as due, t2.id, t2.date, t2.customer_id,t2.notes,t2.discount, t2.added_at, t2.updated_at,t3.booking_id,t3.name c_name from (SELECT invoice_id, sum(total) inv_amount FROM `invoice_items` group by invoice_id order by invoice_id desc) as t1 left join invoices as t2 on t1.invoice_id=t2.inv_id left join bookings as t3 on t2.customer_id=t3.id left join (SELECT inv_id, sum(amount) paid FROM `transactions` where type=2 GROUP by inv_id) as t4 on t1.invoice_id=t4.inv_id where (date(t2.date) BETWEEN '$date1' AND '$date2' )";

                               $sqlSelectedLG = mysqli_query($connection, $sqlSelectedLG);

$tdue=0;
$ttotal_charge=0;
$tpaid=0;
                               while ($list = mysqli_fetch_object($sqlSelectedLG)) {

                                 
                                 $invoice_id = $list->invoice_id;
								 $inv_amount = $list->inv_amount;
								 $inv_discount = $list->discount;
								 $inv_amt=$inv_amount-$inv_discount;
								 
								 $ttotal_charge=$ttotal_charge+$inv_amt;
								 $paid_amount = $list->paid;
								 $tpaid=$tpaid+$paid_amount;
								 $due_amount = $list->due;
								 $tdue=$tdue+$due_amount;
								 $idn = $list->id;
								 $date = $list->date;
								 $date = date("d-m-Y", strtotime($date));
								 $booking_no = $list->booking_id;
								 $customer_name = $list->c_name;
								 $added_at = $list->added_at;
								 $updated_at = $list->updated_at;
								 
								 
								 $notes = $list->notes;
								
								 $inv_amt=IND_money_format($inv_amt);
									
									?>
	
	
	
	
	
	
	
	<tr align="left" >
	  <td style="width:10%;border-bottom: 1px solid black;" > 
	   &nbsp;&nbsp; <?php echo $invoice_id; ?>
      </td> 
	  <td style="width:15%;border-bottom: 1px solid black;" > 
	<?php echo $booking_no; ?>
      </td> 
	  <td style="width:25%;border-bottom: 1px solid black;" > 
	  <?php echo $customer_name; ?>
      </td> 
	  
	    <td style="width:15%;border-bottom: 1px solid black;" > 
	<?php echo $inv_amt; ?>
      </td> 
	    <td style="width:20%;border-bottom: 1px solid black;" > 
	  <?php echo $paid_amount; ?> 
      </td> 
	   <td style="width:15%;border-bottom: 1px solid black;" > 
	  &nbsp;&nbsp;  <?php echo $due_amount; ?>
      </td>
	</tr> 
	
	
							   <?php } ?>
							   
							   <tr align="left" >
	  <td style="width:10%;border-bottom: 1px solid black;" > 
	   &nbsp;&nbsp; 
      </td> 
	  <td style="width:25%;border-bottom: 1px solid black;" > 
	  
      </td> 
	  <td style="width:15%;border-bottom: 1px solid black;" > 
	 Total = 
      </td> 
	    <td style="width:15%;border-bottom: 1px solid black;" > 
	<?php echo $ttotal_charge; ?>
      </td> 
	    <td style="width:20%;border-bottom: 1px solid black;" > 
	  <?php echo $tpaid; ?> 
      </td> 
	   <td style="width:15%;border-bottom: 1px solid black;" > 
	  &nbsp;&nbsp;  <?php echo $tdue; ?>
      </td>
	</tr> 
</table>
</br></br>




 
 
 
 
 
 
 
 
 </center> 
 
 
  </body>
  
  </page>
  
</html>