<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title></title>
	
	 <style>
        
        h1,h2,h3,h4,h5,h6{
            margin: 0;
            padding: 0;
        }
        p{
            margin: 0;
            padding: 0;
        }
        .container7{
            width: 100%;
            margin-right: auto;
            margin-left: auto;
			background-color: #F6F6F6;
        }
        .brand-section{
           background-color: #0d1033;
           padding: 10px 40px;
		   border: 1px solid gray;
        }
		.brand-section1{
           background-color: #F6F6F6;
           padding: 10px 40px;
		   font-size:3px;
		   border: 1px solid gray;
        }
        .logo{
            width: 50%;
        }
		.tbl{
		background-color: #F6F6F6;	
		}

        .row{
            display: flex;
            flex-wrap: wrap;
        }
        .col-6{
            width: 50%;
            flex: 0 0 auto;
			/*background-color: #F6F6F6;*/
        }
        .text-white{
            color: #fff;
			font-size:10px;
        }
		.text-black{
			font-size:10px;
        }
        .company-details{
            float: right;
            text-align: right;
        }
        .body-section{
            padding: 16px;
            border: 1px solid gray;
			background-color: #F6F6F6;
        }
        .heading{
            font-size: 15px;
            margin-bottom: 08px;
        }
        .sub-heading{
            color: #262626;
            margin-bottom: 05px;
			padding-left:6px;
			font-size:12px;
			text-align:justify;
        }
        table{
            background-color: #fff;
            width: 100%;
            border-collapse: collapse;
        }
        table thead tr{
            border: 1px solid #111;
            background-color: #f2f2f2;
        }
        table td {
            vertical-align: middle !important;
            text-align: center;
        }
        table th, table td {
            padding-top: 08px;
            padding-bottom: 08px;
        }
        .table-bordered{
            box-shadow: 0px 0px 5px 0.5px gray;
        }
        .table-bordered td, .table-bordered th {
            border: 1px solid #dee2e6;
        }
        .text-right{
            text-align: end;
        }
        .w-20{
            width: 20%;
        }
        .float-right{
            float: right;
        }
    </style>

   </head>
   
   <body>
   
   <?php
   
  $sql81 = "SELECT payment_mode.name,invoices.inv_no,invoices.client_id,invoices.orderNo,clients.client_fname,clients.client_lname,clients.client_phone,invoices.inv_date,invoices.due_date,invoices.total_amount,invoices.vat,invoices.grand_total_amount,clients.client_email FROM invoices,invoices_items,payment_mode,clients 	
					WHERE invoices.inv_id = {$inv_id} and clients.client_id=invoices.client_id and invoices.payment_mode_id=payment_mode.payment_mode_id";

				$result81 = $conn->query($sql81);
   
 	
				
				while($data81 = mysqli_fetch_array($result81))
							{
							$invNo = $data81['inv_no'];
							$client = $data81['client_fname'].'&nbsp&nbsp'.$data81['client_lname'];
							$firstname = $data81['client_fname'];
							$inv_date = $data81['inv_date'];
							$due_date = $data81['due_date'];
							$phoneNumber = $data81['client_phone'];
							$total_amount = $data81['total_amount'];
							$vat = $data81['vat'];
							$vat_rate = $data81['vat_rate'];
							$orderNo = $data81['orderNo'];
							$clientId = $data81['client_id'];
							$grand_total_amount = $data81['grand_total_amount'];
							$clientEmail = $data81['client_email'];
							$payment_mode = $data81['name'];
							$mailto = $data81['client_email'];
				            }
							
			$sql813 = "SELECT * FROM clients WHERE client_id = {$clientId}";
				$result813 = $conn->query($sql813);
				while($data813 = mysqli_fetch_array($result813))
							{
						$clientTin = $data813['client_tin'];		
							}
							
				 $phone = substr($phoneNumber, 3);
	             $phone_number = '0'.$phone;
				 //$mailfrom = 'info@iws.co.tz';
				$mailfrom = 'jacalminja929@gmail.com';
		 
				//$m = $data8[6];
				//echo $m;
				$invDate = date('d-m-Y', strtotime($inv_date));
				$dueDate = date('d-m-Y', strtotime($due_date));
                //$delDate = date('d-m-Y', strtotime($delivery_date));	

                 $d1 = strtotime("$invDate");
                             $d2 = strtotime("$dueDate");
                             $min_date = min($d1, $d2);
                             $max_date = max($d1, $d2);
                                    $i = 0;
				while (($min_date = strtotime("+1 YEAR", $min_date)) <= $max_date) {
                                   $i++;
                                      }
									  $Year = $i;
									  $age=$Year;
									  
							if($age>0) {
									$age=$Year; 
										 
									 }else{
										 
						$d11 = strtotime("$invDate");
                             $d22 = strtotime("$dueDate");
                             $min_date = min($d11, $d22);
                             $max_date = max($d11, $d22);
                                    $i = 0;
				while (($min_date = strtotime("+1 MONTH", $min_date)) <= $max_date) {
                                   $i++;
                                      }					  
										  
								$Month = $i;		  
								$age1 = $Month.' '.'Months';
                                  
                                  if($Month>0){
									 $age =  $age1;
								      }else{
									$d111 = strtotime("$invDate");
                             $d222 = strtotime("$dueDate");
                             $min_date = min($d111, $d222);
                             $max_date = max($d111, $d222);
                                    $i = 0;
				while (($min_date = strtotime("+1 DAY", $min_date)) <= $max_date) {
                                   $i++;
                                      }	

                                $day = $i;		  
								$age1 = $day.' '.'Days';									  
								$age =  $age1;	  
									  }								  
										 
									 }
				
			
   ?>
   
   
   <div class="container7">
        <div class="brand-section">
            <div class="row">
                <div class="col-6">
                    <h1 class="text-white">Kreen Logistics</h1>
                </div>
                <div class="col-6">
                    <div class="company-details">
						<p class="text-white">+255764508508</p>
						<p class="text-white">info@kreenlogistics.co.tz</p>
                    </div>
                </div>
            </div>
        </div>
		
		<div class="brand-section1">
            <div class="row">
			<table border="0" class="tbl" style="width:100%">
			   <tr>
			   <td style="width:100%">
                <div class="col-12">
                    <h1 class="text-black"><center>INVOICE</center></h1>
                </div>
				</td>
			   </tr>
			</table>
            </div>
        </div>

        <div class="body-section">
		
		 
            <div class="row">
			
			   <table border="0" class="tbl" style="width:100%">
			   
			   <tr>
			   <td style="width:45%">
                <div class="col-6">
                    <p class="sub-heading"><b>Invoice No:</b><?php print $invNo; ?></h2>
					<p class="sub-heading"><b>Order No:</b><?php print $orderNo; ?></h2>
                    <p class="sub-heading"><b>Invoice Date:</b> <?php print $invDate; ?> </p>
                    <p class="sub-heading"><b>Due Date:</b> <?php print $dueDate; ?> </p>
                </div>
				</td>
				<td style="width:55%">
                <div class="col-6">
                    <p class="sub-heading"><b>Client:</b>  <?php print $client; ?></p>
					<p class="sub-heading"><b>Client TIN No:</b>  <?php print $clientTin; ?></p>
					<p class="sub-heading"><b>Phone Number:</b>  <?php print $phone_number; ?> </p>
					<p class="sub-heading"><b>Email: </b> <?php print $clientEmail; ?>  </p>
                </div>
				</td>
				</tr>
				</table>
            </div>
        </div>

        <div class="body-section">
            <h3 class="heading">Expenses</h3>
            <br>
          
            <table class="table-bordered">
                <thead>
                    <tr>
					    <th><center>S/N</center></th>
                        <th><center>Services</center></th>
                        <th class="w-20"><center>Quantity</center></th>
                        <th class="w-20"><center>Price</center></th>
                        <th class="w-20"><center>Total</center></th>
                    </tr>
                </thead>
                <tbody>
				
				<?php
  $procRequestSql = "SELECT invoices_items.qty,invoices_items.services_desc,invoices_items.unit_price,invoices_items.amount FROM invoices_items WHERE invoices_items.inv_id = {$inv_id}";
  $procRequestResult = $conn->query($procRequestSql);
                    $x = 1;
					$no = 1;
    while($procRequestData = $procRequestResult->fetch_array()){ 

    ?>
				
                    <tr>
					    <td><?php print $no;  ?></td>
                        <td><?php print $procRequestData['services_desc'];  ?></td>
                        <td><?php print $procRequestData['qty'];?></td>
                        <td><?php print number_format($procRequestData['unit_price'],2);  ?></td>
                        <td><?php print number_format($procRequestData['amount'],2);  ?></td>
                    </tr>
                    
					
				<?php
				$no++;
}
?>	
					
	<tr>
                        <td colspan="4" class="text-right">Sub Total </td>
                        <td> <?php print number_format($total_amount,2); ?></td>
                    </tr>
                    <tr>
                        <td colspan="4" class="text-right">VAT <?php echo $vat_rate; ?>%</td>
                        <td> <?php print number_format($vat,2); ?></td>
                    </tr>
                    <tr>
                        <td colspan="4" class="text-right">Grand Total</td>
                        <td> <?php print number_format($grand_total_amount,2); ?></td>
                    </tr>				
					
					
                </tbody>
            </table>


			
			
			
            <br>
            <h3 class="heading">Payments must be done within: <?php print $age; ?></h3>
            <h3 class="heading">Payment Mode: <?php print $payment_mode; ?></h3>
        </div>

        <div class="body-section">
			 <p>&copy; Copyright <?php print date("Y");  ?> - Kreen Logistics. All rights reserved.
        </div>      
    </div>
   
 		  
</body>
</html>	
			  
		
		
 
  
		
			  
			  
			  
			  
			  
			  
			  
			  
			  
  
		
			  
  
		
			  
			  
			  
		
		
 
  
		
			  
			  
			  
		
		
 
  
		
			  
			  
			  
			  
		
		
 
  
		
			  
			  
			  
			  
			 
			  
			  
			  
			 
 
		
			  
			  
			  
			  
		
 
  	  
			  
			  
			 
			  
			  
			  
			  
				 
				 
   
   