<link href="<?php echo base_url(); ?>assets/autocomplete/jquery-ui.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/autocomplete/ui.theme.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/autocomplete/autocomplete.css" rel="stylesheet">
	 <script src="<?php echo base_url(); ?>assets/autocomplete/jquery.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/autocomplete/jquery-ui.min.js"></script>
	


 
            
        <script type="text/javascript">  
		
			   $(this).ready( function() {  
            $("#user2").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/customerSaleslookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
		
		$(this).ready( function() {  
            $("#user3").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/customerSaleslookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
		
		$(this).ready( function() {  
            $("#mysupplier").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/customerSaleslookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
		
		
		
		   $(this).ready( function() {  
            $("#id").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/purchaselookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
		
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
		
		
		
        </script>  


 
 <div class="row">
  
   	 
<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/cashflow";
		alert(" printing...........");
    }else {

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

		    // 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="col-md-12">

  
		<div class="panel panel-default" data-collapsed="0">
        	<div class="panel-heading">
            	<div class="panel-title" id="redcolor" >
            		<i class="entypo-plus-circled"></i>

 <a href="<?php echo base_url();?>user/startsales" class="btn btn-info" id="non-printable">  Go back</a>	



<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('printableArea')" value="Print" />
</form></div>
 

 

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

			
	<div class="widget-content nopadding table_holder table-responsive">				
			

<?PHP

 $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'];	


								$profile = $this->usermodel->populateallarray('smsconfig','id',$companyid);

									$photo=$profile[0]['logo'];
									$img=$profile[0]['logo'];
									$hscode=$profile[0]['hscode'];
																				$receiptlogo=$profile[0]['receiptlogo'];

									
									
									
									
									
									$symbol=$configuration[0]["currencysymbol"];
									$multicurrency=$configuration[0]["currency"];
	   $currentdate = date("d/m/Y");

									
 echo $this->session->flashdata('imagemsg1'); 
		 
		    


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

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

   $myuser=$this->usermodel->geteuser($userid);
   $myname=$myuser[0]['firstname'];
    $postedtime = date('Y-m-d');
		$currenttime = date('h:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;	

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;
					}	

 $displaycode=$this->usermodel->populatuserpermissionsdataarray('config','productcode',$userid);
  $displaydiscount=$this->usermodel->populatuserpermissionsdataarray('sales','discount',$userid);
  $displaypreviousbalance=$this->usermodel->populatuserpermissionsdataarray('sales','displaypreviousbalance',$userid);
    $displaybeforevat=$this->usermodel->populatuserpermissionsdataarray('income','displaybeforevat',$userid);


 $countbranch=$this->usermodel->countbranches($companyid);
				
?>

 
					<div class="row">
						<div class="col-md-12">
							
							<div class="panel-body">
	
									<div class="table-responsive" id="printableArea" style="width:100%" >

								<table border="0" width="100%">
						<!--
				<tr>
				<td colspan="6">
				
				<?php
$img1='uploads/';
	$url = base_url().$img1.$img;
	
if($photo!=""){
	
	?>
	
 <div>
<img class="img-circle" src="<?php echo $url ?>" height="150" width="100%" style="border-radius:4px;margin:0px  ">		 

</div>
<?php
 
 }
 ?>
				
				</td>
				
				</tr>
				-->
						<tr>
								<td  style="border-radius:4px;margin:0px ; width:20%" valign="top" valign="left">
					
<?php
$img1='uploads/';
	//$url = base_url().$img1.$img;
	
	if($receiptlogo=="yesbranch") {
					 $allbranches= $this->usermodel->populateallarray('branch','id',$branchid);
					$branchlogo=$allbranches[0]['logo']; 
											
				
					$url = base_url().$img1.$branchlogo;

			}else{
									$url = base_url().$img1.$img;


			}

	
if($photo!=""){

	
	
	
	
	
	
	
	
	
	
	
	?>
	
 <div>

<img class="img-circle" src="<?php echo $url ?>" height="150" width="200" style="border-radius:1px;margin:0px  ">		 

</div>
<?php
 
 }
 ?>

 
 </td>		
										<td colspan="2" style="margin:2px ; width:50%">
<?php 
										 if( $countbranch >1){
										 $mybranches= $this->usermodel->populateallarray('branch','id',$branchid);
										$branchdescription=$mybranches[0]['invoice']; if(isset($branchdescription)) {
											
											
											   echo ($branchdescription); }
											  // echo strtoupper($branchdescription); }


										}else{
 						$description=$configuration[0]['businessname']; if(isset($description)) {  echo $description; }

											 
										 }
										 $user=$this->usermodel->populateallarray('people','id', $userid);
						$donebynames=$user[0]['firstname'];
						
						
										?>
					
				
			
					
					
						</td>
				
						<td colspan="3"  style=" width:30%">
						<h2 style="margin:0px;"> Client Statement 	</h2>
				Printed Date:  <?php echo$currentdate;?><BR>
				Client  Id No: <?php echo$viewreceipt[0]['id'];?><BR>
				From: <?php echo$startdate;?><BR>
				To  : <?php echo$enddate;?><BR>

						
						Prepared by:  <?php 
						
							$user=$this->usermodel->populateallarray('people','id', $userid);
						echo$names=$user[0]['firstname']. " ".$user[0]['surname'] ;
						
						
						?><BR>
						</td>
						
						</tr>
						
					<TR >
					<td colspan="6">
					<hr style="border-top: 2px solid gray;margin:0px;padding:0px">

					</td>
					</TR>
						<tr >
						
					
						<td colspan="4" id="mytitle" style="valign:top">
						<B>Billing To:</B>
						<?php
						$alldetais="";
						 
						 if($viewreceipt[0]['company']!==""){
							 $alldetais.= $viewreceipt[0]['company']."<br>";
						 }
						  if($viewreceipt[0]['firstname']!==""){
							 $alldetais.= $viewreceipt[0]['firstname']." ". $viewreceipt[0]['surname']."<br>";
						 }
						  if($viewreceipt[0]['idno']!==""){
							 $alldetais.= $viewreceipt[0]['idno']."<br>";
						 }
						  if($viewreceipt[0]['phone']!==""){
							 $alldetais.= $viewreceipt[0]['phone']."<br>";
						 } if($viewreceipt[0]['email']!==""){
							 $alldetais.= $viewreceipt[0]['email']."<br>";
						 }
						  if($viewreceipt[0]['website']!==""){
							// $alldetais= $mysupplier[0]['website']."<br>";
						 }
						  if($viewreceipt[0]['zip']!==""){
							 $alldetais.= $viewreceipt[0]['zip']."<br>";
						 }
						   if($viewreceipt[0]['code']!==""){
							 $alldetais.= $viewreceipt[0]['code']."<br>";
						 }
						 
						  if($viewreceipt[0]['city']!==""){
							 $alldetais.= $viewreceipt[0]['city']."<br>";
						 }
						
						  if($viewreceipt[0]['comments']!==""){
							 $alldetais.= $viewreceipt[0]['comments']."<br>";
						 }
						 
						 
													echo "<br>".$alldetais;

						//echo "<br>".$comments=$mysupplier[0]['comments'];
							?>
						
						
						
						
						
						
						</td>
						
							<td colspan="2"  id="mytitle" valign="top" >
							<B>  	</B><br>
						
						
	
						</td>
						
						
						
							</tr>
																				
																				
								</table >
							
																			
																				
																				
																				</table >
							
												
  <table cellpadding="0" cellspacing="0" border="1" class="table  table-striped" id="example" style="border-color:#CCCCCC; width:100%;"  >

             <thead>

         <tr style="background:gray">
     <th> Date</th>
     <th  >Due Date</th>
     <th>Days</th>

 
	     <th>Invoice</th>
		     <th>Type</th>
	     <th>Debit</th>
<th>Credit</th>	

       <th>Balance</th>	
       <th id="non-printable">More</th>	

	   </tr>
             </thead><tbody>
			 
			   <tr  style="margin-bottom:0px;margin-top:0px;">;
      <td>
    
   </td>
    <td colspan='6'>
    <b> Balance brought forward:</b>
   </td>
    <td>
	<b>
    <?php
	$prebalance=0;
	$prebalance=$previousbalance;
	echo formatMoney($prebalance , true);
	?>
	</b>
   </td>
  </tr>
			 
<?php
	
 if(!is_array($cashflow)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='13'>";
    
       echo '<div class="alert alert-warning text-center">There is no record found. Try again.</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>

 
             <?php 
			  $balance=0;
			  			  $mybalance=0;
						  

  $totaldebt=0;
    $totalcredit=0;
  	foreach ($cashflow as $c): 

		

		  
             ?>



             <tr>
                
            <?php 
$id=$c->id;
  $totaldebt=$totaldebt+$c->finaldebit;
    $totalcredit= $totalcredit+$c->finalcredit;
			  			  $mybalance=$mybalance+$c->finaldebit-$c->finalcredit;
						   $view="";
 		$myinvoice = $c->code;
		$tt=$c->finaldebit+$c->finalcredit;
		if(trim($tt !=0)){

?>


       <td><?php  
	 
	   echo$newDate = date("d-m-Y", strtotime($c->crateddate));
	   ?></td>
          <td ><?php

	   echo$duedate = date("d-m-Y", strtotime($c->paiddate));
?> 
 </td>  
 <td><?php

 	$finaldate = strtotime(date($c->fromdate));
	$mycurrentdate = strtotime(date($c->paiddate));

									$secs = $mycurrentdate-$finaldate;// == <seconds between the two times>
									$days = $secs / 86400;
							echo $finaldays=round($days,0);
?> 
 </td>
 
 
 
 
 
 
 
 <td>
	
	
	
		   <a  id="non-printable" class=" btn-default" target="_blank"  href="<?php echo base_url();?>user/searchallmyinvoices?searchterm=<?php   if(isset($myinvoice)) {echo $myinvoice; } ?>&view=userdata/allinvoices"> 		
		   <?php //echo $c->mydescription;
   if($c->ordernumber!=""){
   echo "<BR>INV#".$c->ordernumber."-".$c->mytable;
   
   }
    ?>   </a>   </a>


						 <span id="myprint">
						 
						 <?php //echo $c->mydescription;
   if($c->ordernumber!=""){
   echo "<BR>INV#".$c->ordernumber."-".$c->mytable;
   
   }
    ?>
						 </span>
	
	
	
	
	</td>
 
 
 
  <td><?php 
  
  //$accountdata=$this->usermodel->populateallarray('glaccounts','number', $c->account);

//$accountname=$accountdata[0]['accountname'];
		echo  $c->mytype;
		if($c->transactioncode !=""){
				echo "Code: ".  $c->transactioncode;
			
		}
	
  $finaldebit=0;
  
  if($c->finaldebit==0){
	  
	    $finaldebit=0;
  }else{
	    $finaldebit  =$c->finaldebit;
	
	  
  }
  
    $finalcredit=0;
  
  if($c->finalcredit==0){
	  
	    $finalcredit=0;
  }else{
	    $finalcredit  =$c->finalcredit;
	
	  
  }
  ?></td>
   
      <td><?php echo formatMoney($finalcredit , true); ?></td>
    <td><?php echo formatMoney($finaldebit , true); ?></td>
	

	  <td><?php 

$balance= ($prebalance+($totalcredit-$totaldebt));
	echo formatMoney($balance , true);
	  ?></td>
	 
 <td id="non-printable"> 

 
 
					<div class="btn-group">
                                    <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown">
                                        More <span class="caret"></span>
                                    </button>
									
									
				
								
                                    <ul class="dropdown-menu dropdown-primary pull-right" role="menu">
                                        
                                        <!-- teacher EDITING LINK -->
                                      
											<?php
										if($usertype=="admin"){
											
											?>
                                        
                                     	  <li> 

	  	  	  	 <a  id="more" class="btn btn-info" target="_blank" href="<?php echo base_url();?>user/editjournalentry?randomitemidentifier=<?php   {echo  $id;}  ?>">

                                                <i class="glyphicon glyphicon-pencil"></i>
																Reconcile/Update
                                                </a>
                                                        </li>
										   <li class="divider"></li>

										
														
									
										<?php
										}
										?>
                                     
                                        
                                    </ul>
										
                                </div>
</td>
 
 
 <?PHP
		}
		
		
		?>
             </tr>

	<?php endforeach;} ?>
 <tr style="background:gray">
 <th colspan="5"><CENTER>TOTAL BALANCE</CENTER></th>
	  
	   <th> <h3><?php if(isset($totalcredit)) {echo formatMoney($totalcredit, true); }?></h3></th>
	    <th> <h3><?php if(isset($totaldebt)) {echo formatMoney($totaldebt, true); }?></h3></th>
	   	   <th> <h3><?php if(isset($balance)) {echo formatMoney($balance, true); }?></h3></th>
<th></th>
  
                 </tr>
          <tr>
		 
		 <td colspan="8">
		  </br> </br>
		 <b>
		 <center>
		 Name-------------------------Date----------------------------Signature----------------
		  </center>
		 </b>
		 </td>
		 </tr>


       <tbody> </table>
	   
       </div>
   
			
	
	
	</div>
						
									
						
			
			</div>
		</div>
  
  </div>
			
			
			
		
		
  

 
</div>


















