<?php
session_start();
if(!isset ($_SESSION['user_id'])){
	header("Location:../login.php?msg=Log in first");
    exit();
}else{
	include('../Server/connection.php');
	include('includes/session.php');
?>

<!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">

	
	 <?php
  include 'title.php';
         ?>
	
	
	<link type = "image/png" rel="icon" href="images/kreen.png" />

    <!-- Bootstrap must-->
    <link href="../vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
	
    <!-- Font Awesome must-->
    <link href="../vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
	
	<!-- custom css -->
    <link rel="stylesheet" href="custom/css/custom.css">
	
    <!-- NProgress must-->
    <link href="../vendors/nprogress/nprogress.css" rel="stylesheet">
	
    <!-- Custom Theme Style must-->
    <link href="../build/css/custom.min.css" rel="stylesheet">
	
	<!-- must-->
	<script src="assests/jquery/jquery.min.js"></script>
	
  <!-- jquery ui -->  
  <link rel="stylesheet" href="assests/jquery-ui/jquery-ui.min.css">
  <script src="assests/jquery-ui/jquery-ui.min.js"></script>
	
  <!-- Must Bootstrap -->
    <script src="../vendors/bootstrap/dist/js/bootstrap.min.js"></script>
	
 <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;
			page-break-after: always;
        }
        .brand-section{
           background-color: #0059aa;
           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;
        }
		.wrd{
             text-align: left;
			font-size:10px;
        }
        .body-section{
            padding: 16px;
            border: 1px solid gray;
			background-color: #F6F6F6;
        }
        .heading{
            font-size:10px;
            margin-bottom: 08px;
        }
        .sub-heading{
            color: #262626;
            margin-bottom: 05px;
			padding-left:6px;
			font-size:8px;
			text-align:justify;
        }
		.sub-head{
            /*color: #3366ff;*/
            /*margin-bottom: 05px;*/
			padding-left:10px;
			font-size:10px;
			/*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;
        }
		.text-left{
            text-align: left;
        }
        .w-15{
            width: 15%;
			text-align: left;
			font-size:10px;
        }
		.w-45{
            width: 45%;
			text-align: left;
			font-size:10px;
        }
		.w-5{
            width: 5%;
			text-align: left;
			font-size:10px;
        }
        .float-right{
            float: right;
        }
    </style>
	
	<script language="javascript">
function Clickheretoprint()
{ 
  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
      disp_setting+="scrollbars=yes,width=1000, height=800, left=300, top=25"; 
  var content_vlue = document.getElementById("print_content").innerHTML; 
  
  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>Power System</title>'); 
   docprint.document.write('</head><body onLoad="self.print()" style="width: 100%; font-size:12px; font-family:arial;">');          
   docprint.document.write(content_vlue);          
   docprint.document.write('</body></html>'); 
   docprint.document.close(); 
   docprint.focus(); 
}
</script>
	
  </head>

  <body class="nav-md">
  
    <div class="container body">
	
      <div class="main_container">
        <div class="col-md-3 left_col">
          <div class="left_col scroll-view">
		  
             <?php  
		include 'includes/role.php';
               ?>

            <div class="clearfix"></div>
            
			
			<?php
            include 'includes/profile.php';
			print '</br></br>';
			include 'includes/menu.php';
			?>


           

        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
		  
			
			
            <div class="clearfix"></div>

            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
				  
                    <a href="viewInvoices.php">  <h2><span class="glyphicon glyphicon-step-backward"></span> Back</h2></a>
					
					<?php
				$inv_id = $_GET['i'];
				  $sql81 = "SELECT payment_mode.name,currency.currencyName,currency.bank_name,currency.bank_account,currency.swiftCode,currency.bank_code,currency.branch_code,invoices.inv_no,invoices.client_id,invoices.orderNo,clients.client_fname,clients.client_lname,clients.client_address,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,currency 	
					WHERE invoices.inv_id = {$inv_id} and clients.client_id=invoices.client_id and invoices.payment_mode_id=payment_mode.payment_mode_id and currency.currency_id=invoices.currency_id";

				$result81 = $conn->query($sql81);
				
				
				while($data81 = mysqli_fetch_array($result81))
							{
							$invNo = $data81['inv_no'];
							
							$client = $data81['client_fname'].'&nbsp&nbsp'.$data81['client_lname'];
							$inv_date = $data81['inv_date'];
							$due_date = $data81['due_date'];
							$phoneNumber = $data81['client_phone'];
							$clientAddress = $data81['client_address'];
							$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'];
							$currencyName = $data81['currencyName'];
							$bankName = $data81['bank_name'];
							$bankAccount = $data81['bank_account'];
							$swiftCode = $data81['swiftCode'];
							$bankCode = $data81['bank_code'];
							$branchCode = $data81['branch_code'];
				            }
							
							//echo $invNo;
							
							
							
			$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;	  
									  }								  
										 
									 }
									 
									 
									 
				$sql8136 = "SELECT * FROM vat_settings";
				$result8136 = $conn->query($sql8136);
				while($data8136 = mysqli_fetch_array($result8136))
							{
						$vat_rate = $data8136['rate'];		
							}
				?>
					
					
					
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                      </li>
                      
                     
                    </ul>
                    <div class="clearfix"></div>
                  </div>
				  
				
				<div class="x_content" style="overflow: auto;">
				
				<center><a class="specialeffects" href="javascript:Clickheretoprint()">PRINT <span class="glyphicon glyphicon-print"></span></a></center>
		<div id="print_content" style="width: 100%;">
				 
		<div class="container7">
        <div class="brand-section">
            <div class="row">
                <div class="col-6">
				
				<?php
			  //global $conn;
			  $sql362a = "SELECT company_details.logo FROM company_details";
              $result362a = $conn->query($sql362a);
			  $num362a = mysqli_num_rows($result362a);
			          if($num362a>0){
              while ($row362a = mysqli_fetch_array($result362a)){
						$image_urla = substr($row362a['logo'], 3);
						echo "<img src = ".$image_urla." width='40%' height='50px'>";
			                }
                            }
			  ?>	
				
                    <!--<h1 class="text-white">Kreen Logistics Co Ltd</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>
						<p class="text-white">P O Box 105087</p>
						<p class="text-white">Dar es Salaam</p>
						<p class="text-white">Tanzania</p>
						<p class="text-white">TIN: 142002477</p>
						<p class="text-white">VRN: 40046025X</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><u>INVOICE</u></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:68%">
                <div class="col-6">
                    <p class="sub-heading"><b>Name:</b>  <?php print $client; ?></p>
					<p class="sub-heading"><b>TIN No:</b>  <?php print $clientTin; ?></p>
					<p class="sub-heading"><b>Tel:</b>  <?php print $phone_number; ?> </p>
					<p class="sub-heading"><b>Email: </b> <?php print $clientEmail; ?>  </p>
					<p class="sub-heading"><b>Address: </b> <?php print $clientAddress; ?>  </p>
                </div>
				</td>
			   
			   
			   <td style="width:32%">
                <div class="col-6">
                    <p class="sub-heading"><b>Inv No:</b><?php print $invNo; ?></h2>
					<p class="sub-heading"><b>Order No:</b><?php print $orderNo; ?></h2>
                    <p class="sub-heading"><b>Date:</b> <?php print $invDate; ?> </p>
                    <p class="sub-heading"><b>Due Date:</b> <?php print $dueDate; ?> </p>
                </div>
				</td>
				
				</tr>
				</table>
            </div>
        </div>

        <div class="body-section">
            <h3 class="heading">Items Description</h3>
            <br>
          
            <table class="table-bordered">
                <thead>
                    <tr>
					    <th class="w-5">S/N</th>
                        <th class="w-45">Item Description</th>
                        <th class="w-15">Quantity</th>
						<th class="w-5">UoM</th>
                        <th class="w-15">Unit Price (<?php echo $currencyName; ?>)</th>
                        <th class="w-15">Total</th>
                    </tr>
                </thead>
                <tbody>
				
				<?php
  $procRequestSql = "SELECT invoices_items.qty,unit_measure.measure_name,invoices_items.services_desc,invoices_items.unit_price,invoices_items.amount FROM invoices_items,unit_measure WHERE unit_measure.measure_id=invoices_items.measure_id and invoices_items.inv_id = {$inv_id}";
  $procRequestResult = $conn->query($procRequestSql);
                    $x = 1;
					$no = 1;
    while($procRequestData = $procRequestResult->fetch_array()){ 

    ?>
				
                    <tr>
					    <td class="wrd"><?php print $no;  ?></td>
                        <td class="wrd"><?php print $procRequestData['services_desc'];  ?></td>
                        <td class="wrd"><?php print $procRequestData['qty'];?></td>
						<td class="wrd"><?php print $procRequestData['measure_name'];?></td>
                        <td class="wrd"><?php print number_format($procRequestData['unit_price'],2);  ?></td>
                        <td class="wrd"><?php print number_format($procRequestData['amount'],2);  ?></td>
                    </tr>
                    
					
				<?php
				$no++;
}
?>	
					
	<tr>
                        <td colspan="5" class="text-left">Total (Excluding VAT) - <?php echo $currencyName; ?> </td>
                        <td class="text-left"> <?php print number_format($total_amount,2); ?></td>
                    </tr>
                    <tr>
                        <td colspan="5" class="text-left">VAT <?php echo $vat_rate; ?>%</td>
                        <td class="text-left"> <?php print number_format($vat,2); ?></td>
                    </tr>
                    <tr>
                        <td colspan="5" class="text-left">Total (Including VAT) - <?php echo $currencyName; ?></td>
                        <td class="text-left"> <?php print number_format($grand_total_amount,2); ?></td>
                    </tr>				
					
					
                </tbody>
            </table>


			
			
			
            <br>
            <p class="heading">Payments must be done within: <?php print $age; ?></p>
            <p class="heading">Payment Mode: <?php print $payment_mode; ?></p>
			<p class="heading"><u>NOTE:</u></p>
			<p class="sub-head">
			Make all checks payable to Company Name:Kreen Logistics Company Limited</br> 
			<?php echo $currencyName;  ?> Account Number: <?php echo $bankAccount; ?> </br>
			Bank name: <?php echo $bankName;  ?>; Swift code:<?php echo $swiftCode;  ?></br>
			Bank code: <?php echo $bankCode;  ?>;Branch code:<?php echo $branchCode;  ?>
			</p>
			</br>
			<p class="heading">If you have any questions concerning this quote, use the following contact information:
			</br> Contact Name: Kreen Logistics Co Ltd, Phone Number: +255 764508508, Email: info@kreenlogistics.co.tz </br>
			Thank you for your business!
			
			</p>
			
			<hr/>
			
			
        </div>

          
    </div>	

    <div style="page-break-inside: avoid;">
	
	
	</div>
		

        </div>                        
					
				</div>  
               
				
				
				
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- /page content -->
		
		
		<?php
		include 'includes/footer.php';
		?>
		
        
      </div>
    </div>

   
	
    <!-- Must Custom Theme Scripts -->
    <script src="../build/js/custom.min.js"></script>
	
	<!-- file input -->
	<script src="assests/plugins/fileinput/js/plugins/canvas-to-blob.min.js'); ?>" type="text/javascript"></script>	
	<script src="assests/plugins/fileinput/js/plugins/sortable.min.js" type="text/javascript"></script>	
	<script src="assests/plugins/fileinput/js/plugins/purify.min.js" type="text/javascript"></script>
	<script src="assests/plugins/fileinput/js/fileinput.min.js"></script>	


	<!-- DataTables -->
	<script src="assests/plugins/datatables/jquery.dataTables.min.js"></script>

  </body>
</html>



<?php
}
?>