<?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");

$temp_id = $_GET["id"];


$bookingtSQL = mysqli_query($connection, "select t1.*, t2.id, t2.date,t2.discount, t2.customer_id,t2.notes,t4.name invoice_by,t3.address,t3.cell_1,t3.cell_2, t2.added_at, t2.updated_at,t3.name c_name,t3.email 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 users as t4 on t2.added_by=t4.id where t2.id='$temp_id'");
$list= mysqli_fetch_object($bookingtSQL);
									
                                $idn = $list->id;
                                  $invoice_id = $list->invoice_id;
								 $inv_amount = $list->inv_amount;
								 $inv_discount = $list->discount;
								 $sub_total=$inv_amount-$inv_discount;
								 $idn = $list->id;
								 $date = $list->date;
								 $date = date("d-m-Y", strtotime($date));
								 $customer_id = $list->customer_id;
								 $customer_name = $list->c_name;
								 $invoice_by = $list->invoice_by;
								 $added_at = $list->added_at;
								 $updated_at = $list->updated_at;
								 
								 
								 $notes = $list->notes;
								 $address_1 = $list->address_1;
								 $c_email = $list->email;
								 $cell_1 = $list->cell_1;
								$cell_2 = $list->cell_2;
								
								$inv_amountc=IND_money_format($inv_amount);

	
?>



<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: 29.7cm; 
}
page[size="A4"][layout="landscape"] {
  width: 29.7cm;
  height: 21cm;  
}
.footer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 1rem;
  background-color: #efefef;
  text-align: center;
}
@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%;" cellpadding='0' height='' cellspacing='0'  >
 
  <tr align="left" >
    <td  style="width:30%; "  > <img src="assets/images/logo_wd.png" width="50%" /> </br>
<b>Address: </b><?php echo "$address"; ?> </br>
<b>Email: </b><?php echo "$email"; ?> </br>
<b>Phone: </b><?php echo "$contact_mobile"; ?> </br>
<b>Invoice By: </b><?php echo "$invoice_by"; ?> </br>
<b>Invoice ID: </b><?php echo "$invoice_id"; ?> </br>

	</td>
    <td style="width:60%;">  
	
	<table style="width:100%" cellpadding='1' height='' cellspacing='0' >
	<tr align="center" >
	<td style="border-bottom: 1px solid black;">
	
 </br>
    <img src='barcode.php?size=20&text=<?php echo $invoice_id;  ?>&print=true' alt='Trolltunga Norway' width='' height=''>
    
	
	</td>
	</tr>
	
	
	<tr align="left" >
	<td style="border-bottom: 1px solid black;">
	Date:  <?php echo $date;  ?> 
	</td>
	</tr>
	
	
	<tr align="left" >
	<td style="border-bottom: 1px solid black;">
	Invoiced To
	</td>
	</tr>
	
	
	<tr align="left" >
	<td style="border-bottom: 1px solid black;">
	
	 Client Name: <b> <?php echo $customer_name;  ?>   </b>
	
	</td>
	</tr>
	<tr align="left" >
	<td style="border-bottom: 1px solid black;">
	
	 Address:  <?php echo $address_1;  ?> 
	
	</td>
	</tr>
	
	<tr align="left" >
	<td style="border-bottom: 1px solid black;">
	
	 Phone:  <?php echo $cell_1;  ?> 
	
	</td>
	</tr>
	<tr align="left" >
	<td style="border-bottom: 1px solid black;">
	
	 Alternate Number:  <?php echo $cell_2;  ?>
	
	</td>
	</tr>
	
	<tr align="left" >
	<td style="border-bottom: 1px solid black;">
	
	 Email:  <?php echo $c_email;  ?>   
	
	</td>
	</tr>
	
	
	</table>
	
	</td> 
  </tr>
</table>

</br></br>


</br></br>






 <table style="width:100%;border: 1px solid black;" cellpadding='3' height='' cellspacing='0'  >
	<tr align="left" >
	  <td style="border-bottom: 1px solid black;border-right: 1px solid black;"> 
	   SL
      </td> 
	  <td style="border-bottom: 1px solid black;border-right: 1px solid black;"> 
	  Product
      </td> 
	 <td style="border-bottom: 1px solid black;border-right: 1px solid black;"> 
	  Description
      </td> 
	  <td style="border-bottom: 1px solid black;border-right: 1px solid black;"> 
	  QTY
      </td> 
	  <td style="border-bottom: 1px solid black;border-right: 1px solid black;"> 
	  Unit Price
      </td> 
	  <td style="border-bottom: 1px solid black;"> 
	  Amount
      </td> 
	 
	</tr> 
	 
	 	<?php
                      $pkg_charge=0;
						$sqlSelectedLG = "SELECT t1.*,t2.title p_name FROM `invoice_items` as t1 left join pos_products as t2 on t1.product_id=t2.id where t1.invoice_id='$invoice_id'";

$sqlSelectedLG = mysqli_query($connection, $sqlSelectedLG);
$rowcount = mysqli_num_rows($sqlSelectedLG);
$td_style="border-bottom: 1px solid black;border-right: 1px solid black;";
$td_style1="border-bottom: 1px solid black;";
$sl=0;
while ($list = mysqli_fetch_object($sqlSelectedLG)) {

                                    
                                   $sl=$sl+1;
								   if($sl==$rowcount){
									   $td_style="border-right: 1px solid black;";
									   $td_style1="";
									   }
                                    $product = $list->p_name;
									$qty = $list->qty;
									$description = $list->description;
									$unit_price = $list->unit_price;
									$total = $list->total;
									
                                    
                                ?>
	 
	 
	<tr align="left" >
	    <td style="<?php echo $td_style; ?>"> 
	   <?php echo $sl;  ?>
      </td> 
	 <td style="<?php echo $td_style; ?>"> 
	   <?php echo $product;  ?>
      </td> 
	  <td style="<?php echo $td_style; ?>"> 
	   <?php echo $description;  ?>
      </td> 
	  <td style="<?php echo $td_style; ?>"> 
	   <?php echo $qty;  ?>
      </td> 
	  <td style="<?php echo $td_style; ?>"> 
	   <?php echo $unit_price;  ?>
      </td> 
	  <td style="<?php echo $td_style1; ?>"> 
	   <?php echo $total;  ?>
      </td> 
	  
	  
	</tr> 
	<?php } ?>
</table>

</br>


 <table style="width:60%;border: 1px solid black;" cellpadding='3' height='' cellspacing='0' align='right' >
 
 
 <tr align="left" >
	  <td style="border-bottom: 1px solid black;;border-right: 1px solid black;"> 
	   Total
      </td> 
	  <td style="border-bottom: 1px solid black;"> 
	   <?php echo $inv_amount;  ?> 
      </td> 
	  
	  
	</tr>
 
  <tr align="left" >
	  <td style="border-bottom: 1px solid black;;border-right: 1px solid black;"> 
	   Discount
      </td> 
	  <td style="border-bottom: 1px solid black;"> 
	   <?php echo $inv_discount;  ?> 
      </td> 
	  
	  
	</tr>
 
 
	<tr align="left" >
	  <td style="border-bottom: 1px solid black;;border-right: 1px solid black;"> 
	   Sub Total
      </td> 
	  <td style="border-bottom: 1px solid black;"> 
	   <?php echo $sub_total;  ?>.00
      </td> 
	  
	<?php

$number = $sub_total;

   $no = round($number);
   $point = round($number - $no, 2) * 100;
   $hundred = null;
   $digits_1 = strlen($no);
   $i = 0;
   $str = array();
   $words = array('0' => '', '1' => 'One', '2' => 'Two',
    '3' => 'Three', '4' => 'Four', '5' => 'Five', '6' => 'Six',
    '7' => 'Seven', '8' => 'Eight', '9' => 'Nine',
    '10' => 'Ten', '11' => 'Eleven', '12' => 'Twelve',
    '13' => 'Thirteen', '14' => 'Fourteen',
    '15' => 'Fifteen', '16' => 'Sixteen', '17' => 'Seventeen',
    '18' => 'Eighteen', '19' =>'Nineteen', '20' => 'Twenty',
    '30' => 'Thirty', '40' => 'Forty', '50' => 'Fifty',
    '60' => 'sixty', '70' => 'seventy',
    '80' => 'Eighty', '90' => 'Ninety');
   $digits = array('', 'Hundred', 'Thousand', 'Lakh', 'Crore');
   while ($i < $digits_1) {
     $divider = ($i == 2) ? 10 : 100;
     $number = floor($no % $divider);
     $no = floor($no / $divider);
     $i += ($divider == 10) ? 1 : 2;
     if ($number) {
        $plural = (($counter = count($str)) && $number > 9) ? 's' : null;
        $hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
        $str [] = ($number < 21) ? $words[$number] .
            " " . $digits[$counter] . $plural . " " . $hundred
            :
            $words[floor($number / 10) * 10]
            . " " . $words[$number % 10] . " "
            . $digits[$counter] . $plural . " " . $hundred;
     } else $str[] = null;
  }
  $str = array_reverse($str);
  $result = implode('', $str);
  $points = ($point) ?
    "." . $words[$point / 10] . " " . 
          $words[$point = $point % 10] : '';
  $in_words = $result . "Taka Only";

?>	
	</tr> 
	

	
	<tr align="left" >
	  <td style=";border-right: 1px solid black;"> 
	   In Words
      </td> 
	  <td> 
	   <?php echo $in_words;  ?> 
      </td> 
	  
	  
	</tr>
	
</table>

 </br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br>
  <div id="footer">
 
   <table style="width:100%;height:100px;" cellpadding='3' height='' cellspacing='0' align='center' >
	<tr align="center" >
	<td style="" valign="top"> 
	   
      </td>
	  <td style="" valign="bottom"> 
	 ( This is Software Generated Bill. No Need additional Signature. )   </br>

      </td> 
	 
	  <td style="" valign="top"> 
	   
      </td>
	  </tr>
 </table>
 </div>
 

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