


<script>
	function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

    // document.body.innerHTML = printContents.fontsize(12);
     window.print();

	 if( window.print()) {
         window.location.href = "../user/startsales";
		alert(" printing...........");
    }else {

	
		      return      window.location.href = "../user/startsales";

		    // document.body.innerHTML = originalContents;

	}
}
	</script>
 
   <style type="text/css">
  
  

    #myprint { display: none; }
#print{  	


    background-repeat: no-repeat;
	font-size;20px;
  
    width:100%; 


}

#sale{  	


    background-repeat: no-repeat;
  
    width:100px; height:50px;


}
    @media print
    {
    	#non-printable { display: none; }
    	#printableArea { display: block; font-size:16; width:100%; }
		    	#myprint { display: block; font-size:16; width:100%; }

    }
    </style>
 
 <div class="row">
  
   	

   	<div class="col-md-12">
	<?PHP
				$session_data = $this->session->userdata('logged_in');

    $session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];


				
				
				$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
 echo $this->session->flashdata('deletemsg'); 

				
					 
	    $addcomplain=$this->usermodel->populatuserpermissionsdataarray('complain','add',$userid);

	 $updatecomplain=$this->usermodel->populatuserpermissionsdataarray('complain','update',$userid);
  $deletecomplain=$this->usermodel->populatuserpermissionsdataarray('complain','delete',$userid);
	 
			    $viewcomplain=$this->usermodel->populatuserpermissionsdataarray('complain','view',$userid);
			    $readallcomplain=$this->usermodel->populatuserpermissionsdataarray('sales','allcompalin',$userid);
				
				
	   
								?>	
  
		<div class="panel panel-default" data-collapsed="0">
        	<div class="panel-heading">
            	<div class="panel-title"  id="non-printable" >
            		<i class="entypo-plus-circled"></i>
				 <span class="pull-right"> View VAT</span>
				 
							  <a href="<?php echo base_url();?>user/startsales" class="btn btn-primary"> Back</a>	 

				 <?php

function formatMoney($number, $fractional=false) {
						if ($fractional) {
							$number = sprintf('%.2f', $number);
						}
						while (true) {
							$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
							if ($replaced != $number) {
								$number = $replaced;
							} else {
								break;
							}
						}
						return $number;
					}
$EXEMPTED_SALES=0.0;
$VATABLE_SALES=0.0;
$ZERORATED_SALES=0.0;
$ttsales=0;
$allvat=0;
$ttsalesvat2=0;

$ttsalesvat=0;
$ttpurchases=0;
$ttpurchasesvat=0;


$EXEMPTED_SALEStax=0;
$VATABLE_SALEStax=0;
$ZERORATED_SALEStax=0;

$EXEMPTED_SALESp=0.0;
$VATABLE_SALESp=0.0;
$ZERORATED_SALESp=0.0;


$EXEMPTED_SALEStaxp=0;
$VATABLE_SALEStaxp=0;
$ZERORATED_SALEStaxp=0;

  $ttvatable=0;
      $ttexmp=0;

    $ttzero=0;
	
	
	$ZERORATED_EXPENSES=0;
$VATABLE_EXPENSE=0;
$EXEMPTED_EXPENSES=0;
?>

				 
										
            	</div>
            </div>
			<div class="panel-body">

			
	<div class="widget-content nopadding table_holder table-responsive" >				
			
					<div class="row">
						<div class="col-md-12">
							
							<div class="panel-body">
	  <div class="pull-right"  id="non-printable">
<form name="print" method="post" action="">
 <input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('alldata')" value="Print VAT" />
</form></div>
            						<div id="alldata">				
<?php
			 
			 if(isset($configuration[0]['businessname'])) {
				 ?>
			 	
								
								<center  >
								
						
									

										<?php $bussinessname=$configuration[0]['businessname']; if(isset($bussinessname)) {echo   $bussinessname; }
										
									
										
										?>
												<span id="mytitle"></br><b> VAT Report between  <?PHP echo $finalfromdate ?> and <?PHP echo $finaltodate ?></b>		
								
								<br>Name----------------------Date--------------------Signature----------------</span>

								</center>
								
								
							
							<?php
			 }
							?>
	
					
<div class="col-md-6">				
				<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

             <thead>
			  <tr>
			 <td colspan="3">
			 <CENTER><B>PURCHASES VAT</B></CENTER>
			 </td>
			 </tr>
         <tr>
     <th>Name</th>
	      <th>Invoice Amount</th>

     <th>Vat Amount</th>
	
	    




                 </tr>
             </thead>

<?php
$tttaxsales=0;
$tttaxexmppurchases=0;
$tttaxszeropurchases=0;
$ttamount=0;
 if(!is_array($VATABLEpurchases)) 
 {
 }else {


  	foreach ($VATABLEpurchases as $purchase)
	
	{
		
		$myinvoice=$purchase->invoice;
		$ttamount=$ttamount+$purchase->amount;
												$stock= $this->usermodel->populateall('newstock','invoice_number',$myinvoice);

 if(is_array($stock)) 
 {
			foreach ($stock as $purchasereportrow)
					
					{
						
			
			  
			  
						$vattype=$purchasereportrow->tax;
						
						if($vattype=="VATABLE"){
										$tttaxsales = (double)$tttaxsales+(double)$purchasereportrow->vat;

							 $ttvatable = (double)$ttvatable+((double)$purchasereportrow->total* (double)$purchasereportrow->buyingprice);
						}else  if($vattype=="EXEMPTED"){

																					  $tttaxexmppurchases = (double)$tttaxexmppurchases+(double)$purchasereportrow->vat;
															 $ttexmp = (double)$ttexmp+((double)$purchasereportrow->total*(double) $purchasereportrow->buyingprice);


						}else {
										$tttaxszeropurchases = (double)$tttaxszeropurchases+(double)$purchasereportrow->vat;
														$ttzero = (double)$ttzero+((double)$purchasereportrow->total* (double)$purchasereportrow->buyingprice);


						}
							
						
						
					}
					 
				
 }
		
		
		
	}
	}

		 

             ?>
			 
			 
			 
			 
			 
			 









             <tr>
   
      <td>EXEMPTED</td>
	      <td><?php 
		  
		 

				 
		  if(isset($ttexmp)){
			  $EXEMPTED_SALESp= $ttexmp;
				 echo formatMoney($ttexmp, true);
		  }else{
			 echo $EXEMPTED_SALESp= 0 ;

		  }

		  ?></td>

  <td><?php

	 if(($tttaxexmppurchases>0)){
			  $EXEMPTED_SALEStaxp=$tttaxexmppurchases;
	
			 			 echo formatMoney($EXEMPTED_SALEStaxp, true);

		  }else{
			 echo $EXEMPTED_SALEStaxp= 0 ;

		  }
  ?></td>
	  
	  
	  </tr>
	  
	      <tr>
   
      <td>VATABLE</td>
	      <td><?php
		  
		  			

 if(($ttvatable>0)){
			  $VATABLE_SALESp= $ttvatable ;
		 echo formatMoney($VATABLE_SALESp, true);

		  }else{
			 echo $VATABLE_SALESp= 0 ;

		  }
		  ?></td>

  <td><?php

 if(($tttaxsales>0)){
			  $VATABLE_SALEStaxp=$tttaxsales;
			 		 echo formatMoney($VATABLE_SALEStaxp, true);

		  }else{
			 echo $VATABLE_SALEStaxp= 0 ;

		  }

  ?></td>
	  
	  
	  </tr>
	     <tr>
   
      <td>ZERO RATED</td>
	      <td><?php 

	
 if(isset($ttzero)){
			  $ZERORATED_SALESp= $ttzero;
			 			 		 echo formatMoney($ZERORATED_SALESp, true);


		  }else{
			 			 echo $ZERORATED_SALESp= 0 ;
 
			  
		  }
		  ?></td>

  <td><?php 
if(($tttaxszeropurchases>0)){
				  $ZERORATED_SALEStaxp= $tttaxszeropurchases;

	;
			 echo formatMoney($ZERORATED_SALEStaxp, true);

		  }else{
			 echo $ZERORATED_SALEStaxp= 0 ;

		  }
  ?></td>
	  
	  
	  </tr>
      
  <tr>
	  <td>
	 <b> Total</b>
	  </td>
	  <td><b>
			<?php 
		 $ttpurchases=(double)$EXEMPTED_SALESp+(double)$VATABLE_SALESp+(double)$ZERORATED_SALESp;
		 echo formatMoney($ttpurchases, true);
			 ?>
	  </td>
	  <td>
	  <b>
	  <?php 
$ttpurchasesvat=(double)$EXEMPTED_SALEStaxp+(double)$VATABLE_SALEStaxp+(double)$ZERORATED_SALEStaxp;
		 echo formatMoney($ttpurchasesvat, true);
			 ?>
			 </b>
	  </td>
	  </tr>

         

        </table>
		 
	</div>
	
	<div class="col-md-6">				
				<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

             <thead>
			 <tr>
			 <td colspan="4">
			 <CENTER><B>SALES VAT</B></CENTER>
			 </td>
			 </tr>
         <tr>
     <th>Name</th>
	      <th>Invoice Amount</th>

     <th>Vat Amount</th>
	
	         <th>Levy (Vat2)</th>





                 </tr>
             </thead>

             <tr>
   
      <td>EXEMPTED</td>
	      <td><?php 
		  if(isset($EXEMPTED[0]["amount"])){
			  $EXEMPTED_SALES= $EXEMPTED[0]["amount"] ;
			 echo formatMoney($EXEMPTED_SALES, true);
		  }else{
			 echo $EXEMPTED_SALES= 0 ;

		  }

		  ?></td>

  <td><?php
if(isset($EXEMPTED[0]["tax"])){
			  $EXEMPTED_SALEStax= $EXEMPTED[0]["tax"] ;
			 			 echo formatMoney($EXEMPTED_SALEStax, true);

		  }else{
			 echo $EXEMPTED_SALEStax= 0 ;

		  }
  ?></td>
	  <td><?php
if(isset($EXEMPTED[0]["tax2"])){
			  $EXEMPTED_SALEStax2= $EXEMPTED[0]["tax2"] ;
			 			 echo formatMoney($EXEMPTED_SALEStax2, true);

		  }else{
			 echo $EXEMPTED_SALEStax2= 0 ;

		  }
  ?></td>  
	  
	  </tr>
	  
	      <tr>
   
      <td>VATABLE</td>
	      <td><?php
 if(isset($VATABLE[0]["amount"])){
			  $VATABLE_SALES= $VATABLE[0]["amount"] ;
		 echo formatMoney($VATABLE_SALES, true);

		  }else{
			 echo $VATABLE_SALES= 0 ;

		  }
		  ?></td>

  <td><?php

 if(isset($VATABLE[0]["tax"])){
			  $VATABLE_SALEStax= $VATABLE[0]["tax"] ;
			 		 echo formatMoney($VATABLE_SALEStax, true);

		  }else{
			 echo $VATABLE_SALEStax= 0 ;

		  }

  ?></td>
	    <td><?php

 if(isset($VATABLE[0]["tax2"])){
			  $VATABLE_SALEStax2= $VATABLE[0]["tax2"] ;
			 		 echo formatMoney($VATABLE_SALEStax2, true);

		  }else{
			 echo $VATABLE_SALEStax2= 0 ;

		  }

  ?></td>
	  
	  </tr>
	     <tr>
   
      <td>ZERO RATED</td>
	      <td><?php 

 if(isset($ZERORATED[0]["amount"])){
			  $ZERORATED_SALES= $ZERORATED[0]["amount"] ;
			 			 		 echo formatMoney($ZERORATED_SALES, true);


		  }else{
						 echo $ZERORATED_SALES= 0 ;
  
		  }
		  ?></td>

  <td><?php 
if(isset($ZERORATED[0]["tax"])){
			  $ZERORATED_SALEStax= $ZERORATED[0]["tax"] ;
			 echo formatMoney($ZERORATED_SALEStax, true);

		  }else{
			 echo $ZERORATED_SALEStax= 0 ;

		  }
  ?></td>
	    <td><?php 
if(isset($ZERORATED[0]["tax2"])){
			  $ZERORATED_SALEStax2= $ZERORATED[0]["tax2"] ;
			 echo formatMoney($ZERORATED_SALEStax2, true);

		  }else{
			 echo $ZERORATED_SALEStax2= 0 ;

		  }
  ?></td>
	  
	  </tr>
      <tr>
	  <td>
	  	 <b> Total</b>

	  </td>
	  <td><b>
			<?php 
		 $ttsales=$EXEMPTED_SALES+$VATABLE_SALES+$ZERORATED_SALES;
		 echo formatMoney($ttsales, true);
			 ?>
	  </td>
	  <td>
	  <b>
	  <?php 
$ttsalesvat=$EXEMPTED_SALEStax+$VATABLE_SALEStax+$ZERORATED_SALEStax;
		 echo formatMoney($ttsalesvat, true);
			 ?>
			 </b>
	  </td>
	  
	  
	   <td>
	  <b>
	  <?php 
$ttsalesvat2=$EXEMPTED_SALEStax2+$VATABLE_SALEStax2+$ZERORATED_SALEStax2;
		 echo formatMoney($ttsalesvat2, true);
			 ?>
			 </b>
	  </td>
	  
	  
	  
	  
	  </tr>

	  
	  
	  
	  
	  
	  
	  

         

        </table>
		 
	</div>
	<div class="col-md-6">				
				<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

             <thead>
			  <tr>
			 <td colspan="3">
			 <CENTER><B>GENERAL EXPENSES VAT</B></CENTER>
			 </td>
			 </tr>
         <tr>
     <th>Name</th>
	      <th>Invoice Amount</th>

     <th>Vat Amount</th>
	
	    




                 </tr>
             </thead>

<?php
$tttaxexpense=0;
$tttaxexmpexpenses=0;
$tttaxszeroexpenses=0;


$vatexmpexpenses=0;
$vatexpenses=0;

$vatzeroexpenses=0;


 if(!is_array($VATABLEexpenses)) 
 {
 }else {


  	foreach ($VATABLEexpenses as $expenses)
	
	{
		
		$stinvoice=$expenses->invoice;
												$statement= $this->usermodel->populateall('statement','invoice',$stinvoice);

 if(is_array($statement)) 
 {
			foreach ($statement as $statementrow)
					
					{
						
			
			  
			  
						$statementrowvattype=$statementrow->tax;
						
						if($statementrowvattype=="VATABLE"){
						$tttaxexpense = $tttaxexpense+$statementrow->amount;

							 $vatexpenses = $vatexpenses+$statementrow->vat;
						}else  if($statementrowvattype=="EXEMPTED"){
							


																					  $tttaxexmpexpenses = $tttaxexmpexpenses+$statementrow->amount;

															 $vatexmpexpenses = $vatexmpexpenses+$statementrow->vat;

						}else {
										$tttaxszeroexpenses = $tttaxszeroexpenses+$statementrow->amount;
																								$vatzeroexpenses = $vatzeroexpenses+$statementrow->vat;



						}
							
					
						
					}
					 
				
 }
		
		
		
	}
	}

		 

             ?>
			 
			 
			 
			 
			 
			 









             <tr>
   
      <td>EXEMPTED</td>
	      <td><?php 
		  
		 

				 
		  if(isset($tttaxexmpexpenses)){
			  $EXEMPTED_EXPENSES= $tttaxexmpexpenses;
				 echo formatMoney($tttaxexmpexpenses, true);
		  }else{
			 echo $EXEMPTED_EXPENSES= 0 ;

		  }

		  ?></td>

  <td><?php

	 if(($vatexmpexpenses>0)){
			  $EXEMPTED_EXPENSESvat=$vatexmpexpenses;
	
			 			 echo formatMoney($EXEMPTED_EXPENSESvat, true);

		  }else{
			 echo $EXEMPTED_EXPENSESvat= 0 ;

		  }
  ?></td>
	  
	  
	  </tr>
	  
	      <tr>
   
      <td>VATABLE</td>
	      <td><?php
		  
		  			

 if(($tttaxexpense>0)){
			  $VATABLE_EXPENSE= $tttaxexpense ;
		 echo formatMoney($VATABLE_EXPENSE, true);

		  }else{
			 echo $VATABLE_EXPENSE= 0 ;

		  }
		  ?></td>

  <td><?php

 if(($vatexpenses>0)){
			  $VATABLE_EXPENSEvatable=$vatexpenses;
			 		 echo formatMoney($VATABLE_EXPENSEvatable, true);

		  }else{
			 echo $VATABLE_EXPENSEvatable= 0 ;

		  }

  ?></td>
	  
	  
	  </tr>
	     <tr>
   
      <td>ZERO RATED</td>
	      <td><?php 

	
 if(isset($tttaxszeroexpenses)){
			  $ZERORATED_EXPENSES= $tttaxszeroexpenses;
			 			 		 echo formatMoney($ZERORATED_EXPENSES, true);


		  }else{
			 			 echo $ZERORATED_EXPENSES= 0 ;
 
			  
		  }
		  ?></td>

  <td><?php 
if(($vatzeroexpenses>0)){
				  $ZERORATED_EXPENSESvat= $vatzeroexpenses;

	
			 echo formatMoney($ZERORATED_EXPENSESvat, true);

		  }else{
			 echo $ZERORATED_EXPENSESvat= 0 ;

		  }
  ?></td>
	  
	  
	  </tr>
      
  <tr>
	  <td>
	 <b> Total</b>
	  </td>
	  <td><b>
			<?php 
		 $ttexpenses=$VATABLE_EXPENSE+$EXEMPTED_EXPENSES+$ZERORATED_EXPENSES;
		 echo formatMoney($ttexpenses, true);
			 ?>
	  </td>
	  <td>
	  <b>
	  <?php 
$ttexpsesvat=$VATABLE_EXPENSEvatable+$EXEMPTED_EXPENSESvat+$ZERORATED_EXPENSESvat;
		 echo formatMoney($ttexpsesvat, true);
			 ?>
			 </b>
	  </td>
	  </tr>

         <tr>
		 <td colspan="2">
		 	 <b> <center> Total Purchases+Expenses</center>
		
		 </b>
		 </td>
		 </tr>
		 
		       <tr>
	  <td>
	  	 <b> Total 
		
		 </b>

	  </td>
	  <td><b>
			<?php 
		 $allexpenses=$ttexpenses+$ttpurchases;
		 echo formatMoney($allexpenses, true);
			 ?>
	  </td>
	  <td>
	  <b>
	  <?php 
$allvat=$ttexpsesvat+$ttpurchasesvat;
		 echo formatMoney($allvat, true);
			 ?>
			 </b>
	  </td>
	  </tr>

        </table>
		 
	</div>
	<div class="col-md-6">				
				<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

             <thead>
			  <tr>
			 <td colspan="2">
			 <CENTER><B> VAT SUMMARIES</B></CENTER>
			 </td>
			 </tr>
         <tr>
     <th>Description</th>
	      <th>Amount</th>

	  </tr>
	   <tr>
     <th> Output Vat(Sales)</th>
	      <th>
		   <?php 
		 echo formatMoney($ttsalesvat, true);
			 ?>
		  </th>

	  </tr>
	   <tr>
     <th> Input Vat(Purchases)</th>
	      <th>
		   <?php 
		 echo formatMoney($allvat, true);
			 ?>
		  </th>

	  </tr>
	    <tr>
     <th> VAT To Pay</th>
	      <th>
		   <?php 
		 echo formatMoney($ttsalesvat-$allvat, true);
			 ?>
		  </th>

	  </tr>
	
 </table>
		 
	</div>

	
									
									
					</div>				
									
									
									
									
							</div>
						</div>
				

			
			</div>
		</div>
  
  </div>
			
			
			
		
		
  

 
</div>




			
									
							</div>
						</div>
				

			
			</div>
		</div>
  
  </div>
			
			
			
		
		
  

 
</div>


















