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

         <script type="text/javascript">
  
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  //
		   
        });
		
		
		
    </script>   
  <style type="text/css">
  
  .invoice-box table tr.heading td {
        background: #eee;
        border-bottom: 1px solid #ddd;
        font-weight: bold;
		height:auto;
		
		
    }
  
  

    #myprint { display: none; }
#print{  	


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


}
#maintable tr { border-bottom:1px dashed #494949; padding:0px;}

#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
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;
					}
echo $this->session->flashdata('deletemsg'); 
	 $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'];	
	    $addproductaction=$this->usermodel->populatuserpermissionsdataarray('reports','add',$userid);

	 $updateaction=$this->usermodel->populatuserpermissionsdataarray('reports','update',$userid);
  $updatebuyingpriceaction=$this->usermodel->populatuserpermissionsdataarray('reports','update',$userid);
  $deleteaction=$this->usermodel->populatuserpermissionsdataarray('reports','delete',$userid);
	         		$configuration = $this->usermodel->populateallarray('smsconfig','id',$companyid);
					
					
					

    $mpesaaction=$this->usermodel->populatuserpermissionsdataarray('sales','mpesa',$userid);
	      $chequeaction=$this->usermodel->populatuserpermissionsdataarray('sales','cheque',$userid);
 $voucheraction=$this->usermodel->populatuserpermissionsdataarray('sales','voucher',$userid);
	      $creditaction=$this->usermodel->populatuserpermissionsdataarray('sales','credit',$userid);
		   $pointsaction=$this->usermodel->populatuserpermissionsdataarray('sales','points',$userid);
	      $cardaction=$this->usermodel->populatuserpermissionsdataarray('sales','card',$userid);
	      $orderaction=$this->usermodel->populatuserpermissionsdataarray('sales','order',$userid);
		  		    $cashaction=$this->usermodel->populatuserpermissionsdataarray('sales','cash',$userid);
		  	      $creditnoteeaction=$this->usermodel->populatuserpermissionsdataarray('sales','creditnote',$userid);





				echo $this->session->flashdata('msg'); 
								?>	
		<div class="panel panel-default" data-collapsed="0">
        	<div class="panel-heading" id="non-printable">
            	<div class="panel-title" id="redcolor" >
            		<i class="entypo-plus-circled"></i>
				 <span class="pull-right"> View salesreport</span>
				
						
						
								<?php	
		  $data['category'] = $session_data['category'];
	 $category = $data['category'];
	 	 if($category=="reseller"){
			 ?>
						                        <a  id="non-printable"  class="btn btn-primary" href="<?php echo base_url();?>user/payments">back  </a>

<?php
		 }else{
			?> 
			 
			                        <a  id="non-printable"  class="btn btn-primary" href="<?php echo base_url();?>user/startsales">back  </a>
 
			<?php 
		 }
		 ?>
						
						
						
						
						
						
						
						
				 		 	<div class="pull-right"  >
<form name="print" method="post" action="">
 <input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('printableArea')" value="print receipt!" />
</form></div>
            	</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 id="printableArea" style="width:100%" class="invoice-box">
									
  <table cellpadding="0" cellspacing="0" border="1" id="example3" style=" width:100%;"  >

             <thead>
			   <tr>
			 <th colspan="22"><center>
			 <?php  if(isset($configuration[0]['businessname'])) {echo   $configuration[0]['businessname']; }
			   $TIMEOFREPORT=date("d/m/Y H:i:s a");
			   
			   
		 	  $vat1=$configuration[0]['view'];	
		  		 	  $vat2=$configuration[0]['display1'];	

			 ?>
</BR>
			 <B><?PHP if(isset($reporttype)) {echo   $reporttype; } ?>
			 FROM  <?php  if(isset($finalfromdate)) {echo   date("d/m/Y H:i:s", strtotime($finalfromdate)); }?>  TO  <?php  if(isset($finaltodate)) {echo     date("d/m/Y H:i:s", strtotime($finaltodate));; }?>   </B><br>
			 Report was run on <?php echo  date("d/m/Y H:i:s a") ; ?>
									<br>Name----------------------Date--------------------Signature----------------</span>

			</th>
	
			 </center>
			 </tr>
      
							
						
							<tr  class="heading">
							
		 
									 <th> Rct No</th>
							
                                        <th>  Mode</th>
										   

														<th> Total</th> 
                                              <th> Bal</th>  
		  <th> Cash</th> 											  
											 
<?php
 if( $cashaction==true){
?>
	 
										
 
<?php
}
?>

<?php
 if( $mpesaaction==true){
?>
												 <th> Mpesa </th>
 
	 
<?php
}
?>
	<?php
 if( $cardaction==true){
	 ?>
	 												<th> Card</th>  


 <?php
}
?>
	 
	 <?php
 if( $voucheraction==true){
	 ?>
	 
	 											 <th> Voucher</th> 

 <?php
}
?>
	 
	 	<?php
 if( $creditaction==true){
	 ?>
	 												<th>Credit</th> 											

	 
 <?php
}
?>

		<?php
 if( $pointsaction==true){
	 ?>
	 											  <th> Points</th>                       

	 
	 
	  <?php
}
?>



				<?php
 if( $chequeaction==true){
	 ?>

											  <th>Cheque</th> 

 <?php
}
?>

		<?php
 if( $creditnoteeaction==true){
	 ?>
											  	  <th>Cr.Note</th> 


	 
	  <?php
}
?>

												<th> Code</th>											  
											  <th>Customer</th>                            

											
											 

									       <th>Date sold</th>
										 
									
																	<th> Counter</th> 

										    <th> sold by</th>  
											  <th> Verified</th> 
	  <th> Agent</th>  											  
		                          <th id="non-printable"> More</th> 


                 </tr>
             </thead>
<?php



 if(!is_array($salesreport)) {
				    echo '<div class="alert alert-danger text-center">No data found</div>';

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

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='1'>";
    
       echo '<div class="alert alert-warning text-center">There no records found..</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
  $total=0; 
  $mytotal=0; 
    $totalcash=0; 
		  $totaltax=0; 
$totalmpesa=0;		  
$cashmpesa=0;

$totalcredit=0;		  
$totalcheque=0;
$totalvoucher=0;		  
$totalpoints=0;
$totalcard=0;		  
$totalcreditnote=0;




  	foreach ($salesreport as $c): 


 $myinvoice=$c->invoice ; 
              
$id=$c->id;
 $total=$alltotals[0]["total"];


 $view="";
$salestype= $c->salestype;
$type=$c->type;
if ($salestype=="wholesale"){
		
	  $view="user/viewwholesales";
}else if ($salestype=="retail"){

	 $view="user/viewsales";

}else{
	 $view="user/viewsales";
	
}
 
?>



             <tr>
          <td>
		   <a  id="non-printable" target="_blank"   href="<?php echo base_url();?>user/searchinvoice?code=<?php   if(isset($myinvoice)) {echo $myinvoice; } ?>&view=<?php   {echo  $view;}  ?>"> <?php echo $c->id ; ?>   </a>


		  		 <a  id="non-printable" target="_blank"   href="<?php echo base_url();?>user/printinvoice?invoice=<?php   if(isset($myinvoice)) {echo $myinvoice; } ?>&view=<?php   {echo  $view;}  ?>"> Print    </a>
						 <span id="myprint"><?php echo $c->id ; ?></span>

		  </td>          



              
  <td><?php echo $c->type ; ?></td>

 <td>
 <a  id="non-printable" target="_blank"   href="<?php echo base_url();?>user/searchinvoice?code=<?php   if(isset($myinvoice)) {echo $myinvoice; } ?>&view=<?php   {echo  $view;}  ?>"> <?php echo $c->total ; ?>   </a>
 
 <span id="myprint"><?php echo $c->total ; ?></span>
 
 </td>
    <td><?php echo $c->balance ; ?></td>
 	 
   <td><?php echo $c->cash ; ?></td>
 
<?php
 if( $cashaction==true){
?>

<?php
}
?>

<?php
 if( $mpesaaction==true){
?>
      <td><?php echo $c->mpesa ; ?></td>
 
	 
<?php
}
?>
	<?php
 if( $cardaction==true){
	 ?>
			     <td><?php echo $c->card ; ?></td>


 <?php
}
?>
	 
	 <?php
 if( $voucheraction==true){
	 ?>
	 
											   <td><?php echo $c->voucher ; ?></td>

 <?php
}
?>
	 
	 	<?php
 if( $creditaction==true){
	 ?>
												  <td><?php echo $c->credit ; ?></td>

	 
 <?php
}
?>

		<?php
 if( $pointsaction==true){
	 ?>
												   <td><?php echo $c->points ; ?></td>

	 
	 
	  <?php
}
?>



				<?php
 if( $chequeaction==true){
	 ?>

											   <td><?php echo $c->cheque ; ?></td>

 <?php
}
?>

		<?php
 if( $creditnoteeaction==true){
	 ?>
											   	   <td><?php echo $c->creditnote ; ?></td>


	 
	  <?php
}
?>

											    <td><?php echo $c->cashier ; ?>

	 
	    <?php
	
		$totalcash=$alltotals[0]["cash"];
		$totalmpesa=$alltotals[0]["mpesa"];
		
		$totalcredit=$alltotals[0]["credit"];		  
$totalcheque=$alltotals[0]["cheque"];	
$totalvoucher=$alltotals[0]["voucher"];			  
$totalpoints=$alltotals[0]["points"];	
$totalcard=$alltotals[0]["card"];	
		$totalcreditnote=$alltotals[0]["creditnote"];;
		
		
		//$mytax=$this->usermodel->getVat($myinvoice,$companyid);
						$cashmpesa=	 $totalmpesa+$totalcash+$totalcheque+$totalcard;

				//$cashmpesa=	 $totalmpesa+$totalcash+$totalcredit+$totalcheque+$totalvoucher+$totalpoints+$totalcard;
	$mytotal=$totalmpesa+$totalcash+$totalcheque+$totalpoints+$totalcard;
$taxrate=0;


$totaltax= 0;
		
		
		?></td>

<td>
 
  <?php  $mycustomer= $c->customer ;
  
    if(($mycustomer!="") && ($mycustomer!="directly")){

$myuser=$this->usermodel->getpeople($mycustomer);
    $myname=$myuser[0]['company'];
	    $phone=$myuser[0]['phone'];

     $firstname=$myuser[0]['firstname'];
   if($myname!=""){
	   echo $myname."-".$phone;
	   
   }else{
	   
	   echo $firstname."-".$phone; 
	   
   }
	}else{
		echo $name= $c->name;
		
	}
	echo " ".$c->description ;
	
	 
    if(($mycustomer!="") && ($mycustomer!="directly")){
if($myuser[0]['idno']!=""){
									echo "</br> ID/PIN ".$myname=$myuser[0]['idno'];

				}
	}
  ?>
 
 
 </td>
 
 


 <td><?php 
 
 
 
 
  if($group=="no"){
	  echo $c->dateposted ;
  }else{
	   echo $c->mydateposted;
	  
  }
 
 
 
 
	  ?></td>	
      <td>
												 
	<?php 
					// $branch="";
					 $mybranch=$c->branch;

					 $allbranch= $this->usermodel->populateall('branch','id',$mybranch);



if(is_array($allbranch)) {

   foreach($allbranch as $branchrow){

   echo $branchrow->name;
 
 
}} else {
    echo 'General.';
}
	
?>
												 
	 </td>
 

 <td><?php  $userids= $c->userid ;

$myuser=$this->usermodel->geteuser($userids);
   echo $myname=$myuser[0]['firstname'];

  ?></td>  
  
     <td><?php 
	 
	
	 if($group=="no"){
	 
	 echo $c->paymentstatus ; 
	 
	 
	 					
	
	 if($c->maindiscount !=""){
		   echo "<br>";
	
		 ?>
		 <span style="color:red">
		<?php echo "Changed- ";
		   echo $c->maindiscount;
		    ?>
		   </span>
		<?php 
		
	
	 }
	
	

	 }




	?></td>
	 
	 
	 
	 
	 <td><?php  $salesperson=$c->salesperson ;

$mycustomer=$this->usermodel->populateallarray('people','id', $salesperson);


			
			if($salesperson !=""){
				if($mycustomer[0]['company']!=""){
									echo$myname=$mycustomer[0]['company'];

				}else{
									echo$myname=$mycustomer[0]['firstname'];

				}
			}


 ?></td>
	 
	 
	 
	 
	 
	 
	 
	 
   <td  id="non-printable"> 

 
 
					<div class="btn-group">
                                    <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
                                        More <span class="caret"></span>
                                    </button>
									
									
									
                                    <ul class="dropdown-menu dropdown-default pull-right" role="menu">
                                        
                                        <!-- teacher EDITING LINK -->
                                      <?php
										 if( $deleteaction==true){
											
											?>
										
											  <li> 
										 <a class="btn btn-danger managebtn" id="managebtndelete"		 data-id='<?php echo  $c->id;?>'    data-toggle='modal' data-target='#deleteModel<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Cancel Sale
                                                </a>
                                                        </li>
									
									<?php
										}
										?>
                                        
                                        <li class="divider"></li>
                                        <li> 
				<a  id="more" class=" btn-success" target="_blank"  href="<?php echo base_url();?>user/searchJE?searchterm=<?php   {echo  $myinvoice;}  ?> ">
								 
																							 

                                                <i class="glyphicon glyphicon-pencil"></i>
															View	GL Transactions
                                                </a>
																		
										</li>
                                           <li class="divider"></li>
                                        <li> 
				<a  id="more" class=" btn-primary" target="_blank"  href="<?php echo base_url();?>user/Reconcilesale?searchterm=<?php   {echo  $myinvoice;}  ?>&type=<?php   {echo  $type;}  ?>&branch=<?php   {echo  $c->branch;}  ?>">
								 
																							 

                                                <i class="glyphicon glyphicon-pencil"></i>
															Reconcile GL Transactions
                                                </a>
																		
										</li>
                                    </ul>
											
                                </div>
</td> 
         
             </tr>

	<?php endforeach;} ?>


<tfoot>

							<tr  class="heading">
							
		 
									 <th> Rct No</th>
                                        <th>  Mode</th>
										   

														<th> Total</th> 
                                              <th> Bal</th>  
		  <th> Cash</th> 											  
											 
<?php
 if( $cashaction==true){
?>
	 
										
 
<?php
}
?>

<?php
 if( $mpesaaction==true){
?>
												 <th> Mpesa </th>
 
	 
<?php
}
?>
	<?php
 if( $cardaction==true){
	 ?>
	 												<th> Card</th>  


 <?php
}
?>
	 
	 <?php
 if( $voucheraction==true){
	 ?>
	 
	 											 <th> Voucher</th> 

 <?php
}
?>
	 
	 	<?php
 if( $creditaction==true){
	 ?>
	 												<th>Credit</th> 											

	 
 <?php
}
?>

		<?php
 if( $pointsaction==true){
	 ?>
	 											  <th> Points</th>                       

	 
	 
	  <?php
}
?>



				<?php
 if( $chequeaction==true){
	 ?>

											  <th>Cheque</th> 

 <?php
}
?>

		<?php
 if( $creditnoteeaction==true){
	 ?>
											  	  <th>Cr.Note</th> 


	 
	  <?php
}
?>

												<th> Code</th>											  
											  <th>Customer</th>                            

											
											 

									       <th>Date sold</th>
										 
									
																	<th> Counter</th> 

										    <th> sold by</th>  
											  <th> Verified</th>  
		                          <th id="non-printable"> More</th> 


                 </tr>
								<tr border="1" background="green">
									<td colspan="4"><center><b>Expected  Amount:
		<?php if(isset($total)) {echo formatMoney($total, true);  }?><b></center></td>
		<td>  <b><?php if(isset($totalcash)) {echo formatMoney($totalcash, true);  }?><b></td>

<?php
 if( $cashaction==true){
?>
	 
 
<?php
}
?>

<?php
 if( $mpesaaction==true){
?>
			<td>  <b><?php if(isset($totalmpesa)) {echo formatMoney($totalmpesa, true);  }?><b></td>
 
	 
<?php
}
?>
	<?php
 if( $cardaction==true){
	 ?>
			<td>  <b><?php if(isset($totalcard)) {echo formatMoney($totalcard, true);  }?><b></td>


 <?php
}
?>
	 
	 <?php
 if( $voucheraction==true){
	 ?>
	 
			<td>  <b><?php if(isset($totalvoucher)) {echo formatMoney($totalvoucher, true);  }?><b></td>

 <?php
}
?>
	 
	 	<?php
 if( $creditaction==true){
	 ?>
	<td>  <b><?php if(isset($totalcredit)) {echo formatMoney($totalcredit, true);  }?><b></td>

	 
 <?php
}
?>

		<?php
 if( $pointsaction==true){
	 ?>
				<td>  <b><?php if(isset($totalpoints)) {echo formatMoney($totalpoints, true);  }?><b></td>

	 
	 
	  <?php
}
?>



				<?php
 if( $chequeaction==true){
	 ?>

			<td>  <b><?php if(isset($totalcheque)) {echo formatMoney($totalcheque, true);  }?><b></td>

 <?php
}
?>

		<?php
 if( $creditnoteeaction==true){
	 ?>
											   	   
			<td>  <b><?php if(isset($totalcreditnote)) {echo formatMoney($totalcreditnote, true);  }?><b></td>


	 
	  <?php
}
?>

<td>
</td>

		
			<td colspan="6">  <b>Total for all Receipts : <?php if(isset($cashmpesa)) {echo formatMoney($cashmpesa, true);  }?><b></td>
	<td id="non-printable"></td>
</tr>
	</tfoot>
	
	
              <?php }?>

        </table>
			 <div class="col-md-12 text-center">    <?php echo $links; ?>
					   		<span style="color:red; font-size:20px"><?php  echo $total_rows. "   Sales. " ;?>    </span>

        
        </div>
		
		<br></br>
		
		
		
		
		
							
				<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

           
		
          
<?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'];	
$ttcollections=0;
	 $ttcollectionsbalance=0;
 if(!is_array($allcollections)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='10'>";
    
				 echo '<div class="alert alert-warning text-center">There is no data found in the system</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    	 <tr>
			        <th colspan="10"><CENTER>DAILY DEPOSITS COLLECTIONS
					
										  		   <a  id="non-printable" class=" btn-default" target="_blank"  href="<?php echo base_url();?>user/collections?finaltodate=<?php   if(isset($finaltodate )) {echo $finaltodate ; } ?>&finalfromdate=<?php   if(isset($finalfromdate )) {echo $finalfromdate ; } ?>&branch=<?php   if(isset($branch )) {echo $branch ; } ?>&category=payment"> <span style="color:red">(Click  to View All)</span>	</a>	

					</CENTER>
					
					

					
					
					
					
					
					</th>
			     </tr>
         <tr>
     <th>Name / Receipt No</th>
     <th>Invoice No</th>
	  <th>Amount</th>
	   <th>Balance</th>
	   <th>Remarks</th>
	    	   <th>Method</th>

<th>Date</th>	
 
		   <th>Added by</th>

		
 

                 </tr>
             <?php 
   $mytotals=0;
   
  	foreach ($allcollections as $c): 


 $mybalance=0;
$mycash=0;
	
             ?>



             <tr>
                
            <?php 
$id=$c->id;
$myinvoice=$c->id ;

?>

     <td><?php 
	 
	  $mysupplier=$c->supplier ;

$mycustomer=$this->usermodel->populateallarray('people','id', $mysupplier);


			
			if($mysupplier !=""){
				if($mycustomer[0]['company']!=""){
									echo$myname=$mycustomer[0]['company'];

				}else{
									echo$myname=$mycustomer[0]['firstname'];

				}
			}

	 
	 
	 
	 
	 
	 
	 
	 
	 echo " (RS-".$myinvoice.")"; ?></td>           
  <td>
  
  		   <a  id="non-printable" class=" btn-default" target="_blank"  href="<?php echo base_url();?>user/searchallmyinvoices?searchterm=<?php   if(isset($c->invoice )) {echo $c->invoice ; } ?>&view=userdata/allinvoices"> 		

  <?php echo $c->invoice ; ?>
  </a>
  
   <span id="myprint">
<?php echo $c->invoice ; ?>
						 </span>
  
  </td>
  
    <td><?php  
	
	echo formatMoney($c->amount, true);

	$ttcollections=$ttcollections+$c->amount;
	$ttcollectionsbalance=$ttcollectionsbalance+$c->balance;
	?></td>
	<td><?php 	echo formatMoney($c->balance, true); ?></td>
   <td><?php echo $c->remarks ; ?></td>
	  
	
	   
	   <td>
			 <?php  $paymentmethodesid= $c->paymentmethodes ;
	 $mypaymentmethodes = $this->usermodel->populateallarray('glaccounts','number',$paymentmethodesid);

   echo $mypaymentmethodes[0]['accountname'];
			  ?>
			</td>

	  <td><?php 


	
	
	   
  if($group=="no"){
	  echo $c->paiddate ;
  }else{
	   echo $c->mydateposted;
	  
  }
 
 

	  ?></td>
	   <td><?php  $userids= $c->userid ;

$myuser=$this->usermodel->geteuser($userids);
   echo $myname=$myuser[0]['firstname'];

  ?></td>

                 
				 

             </tr>

	<?php endforeach;} ?>

            
			  	</tr>
							
								

								
								
								<th colspan="2" >
								
								
								
								 Total Money Paid In:<br>
								
								
								
								</th>
								
														<th >
<?php if(isset($ttcollections)) {

		echo formatMoney($ttcollections, true);


 }?>
								
														</th>
														
																								
														<th >
<?php if(isset($ttcollectionsbalance)) {

		echo formatMoney($ttcollectionsbalance, true);


 }?>
					</th>		
									
														<th colspan="4" ></th>
							</tr>

        </table>
		
		
		
		
					
				<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

           
		
          
<?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'];	
 $ttpurchases=0;
  
 if(!is_array($paidpurchase)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='10'>";
    
				 echo '<div class="alert alert-warning text-center">There is no data found in the system</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    	 <tr>
			        <th colspan="10"><CENTER>DAILY PAID PURCHASES 
					
															  		   <a  id="non-printable" class=" btn-default" target="_blank"  href="<?php echo base_url();?>user/collections?finaltodate=<?php   if(isset($finaltodate )) {echo $finaltodate ; } ?>&finalfromdate=<?php   if(isset($finalfromdate )) {echo $finalfromdate ; } ?>&branch=<?php   if(isset($branch )) {echo $branch ; } ?>&category=paid"> <span style="color:red">(Click  to View All)</span>	</a>	

					
					
					
					
					</CENTER></th>
			     </tr>
         <tr>
   <th>Name / Receipt No</th>
     <th>Invoice No</th>
	  <th>Amount</th>
	   <th>Balance</th>
	   <th>Remarks</th>
	    	   <th>Method</th>

<th>Date</th>	
 
		   <th>Added by</th>

		
 

                 </tr>
             <?php 
	  $ttpurchasesbalance=0;
  	foreach ($paidpurchase as $row): 
	
 $mybalance=0;
$mycash=0;

             ?>



             <tr>
                
            <?php 
$id=$row->id;
$myinvoice=$row->id ;

?>

  <td><?php 
	 
	  $mysupplier=$row->supplier ;

$mycustomer=$this->usermodel->populateallarray('people','id', $mysupplier);


			
			if($mysupplier !=""){
				if($mycustomer[0]['company']!=""){
									echo$myname=$mycustomer[0]['company'];

				}else{
									echo$myname=$mycustomer[0]['firstname'];

				}
			}

	 
	 
	 
	 
	 
	 
	 
	 
	 echo " (RS-".$myinvoice.")"; ?></td>           
  </td>
    <td>
  
  		   <a  id="non-printable" class=" btn-default" target="_blank"  href="<?php echo base_url();?>user/searchallmysalesorder?searchterm=<?php   if(isset($row->invoice )) {echo $row->invoice ; } ?>&view=userdata/allinvoices"> 		

  <?php echo $row->invoice ; ?>
   </a>
  
   <span id="myprint">
<?php echo $row->invoice ; ?>
						 </span>
  
 
     </td>
  
    <td><?php
	 $ttpurchases=$ttpurchases+$row->amount ;
	 $ttpurchasesbalance=$ttpurchasesbalance+$row->balance ;

		echo formatMoney($row->amount, true);

	
	?></td>
	<td><?php echo $row->balance ; ?></td>
   <td><?php echo $row->remarks ; ?></td>
	  
	
	   
	   <td>
			 <?php  $paymentmethodesid= $row->paymentmethodes ;
	 $mypaymentmethodes = $this->usermodel->populateallarray('glaccounts','number',$paymentmethodesid);

   echo $mypaymentmethodes[0]['accountname'];
			  ?>
			</td>

	  <td><?php
	  
	  
	  
	  	   
  if($group=="no"){
	  echo $row->paiddate ;
  }else{
	   echo $row->mydateposted;
	  
  }
 
	  
	  
	  
	  
	  
	  ; ?></td>
	   <td><?php  $userids= $row->userid ;

$myuser=$this->usermodel->geteuser($userids);
   echo $myname=$myuser[0]['firstname'];

  ?></td>

                 
				 

             </tr>

	<?php endforeach;
	
	} ?>

            
							
								

							<tr>	
								
								<th colspan="2" >
								
								
								
								 Total Money Paid out:<br>
								
								
								
								</th>
								
														<th >
<?php if(isset($ttpurchases)) {

		echo formatMoney($ttpurchases, true);


 }?>
								
														</th>
												
														<th >
<?php if(isset($ttpurchasesbalance)) {

		echo formatMoney($ttpurchasesbalance, true);


 }?>
					</th>		
														
														
														
														
														
														
														
														
														
														
														<th colspan="4" ></th>
							</tr>

        </table>
		
		
			<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

           
		
          
<?php
$ttbillsbalance=0;
 if(!is_array($paidbills)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='10'>";
    
				 echo '<div class="alert alert-warning text-center">There is no data found in the system</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    	 <tr>
			        <th colspan="10"><CENTER>DAILY PAID BILLS 
					
					
																				  		   <a  id="non-printable" class=" btn-default" target="_blank"  href="<?php echo base_url();?>user/collections?finaltodate=<?php   if(isset($finaltodate )) {echo $finaltodate ; } ?>&finalfromdate=<?php   if(isset($finalfromdate )) {echo $finalfromdate ; } ?>&branch=<?php   if(isset($branch )) {echo $branch ; } ?>&category=bill"> <span style="color:red">(Click  to View All)</span>	</a>	

					
					</CENTER></th>
			     </tr>
         <tr>
   <th>Name / Receipt No</th>
     <th>Invoice No</th>
	  <th>Amount</th>
	   <th>Balance</th>
	   <th>Remarks</th>
	    	   <th>Method</th>

<th>Date</th>	
 
		   <th>Added by</th>

		
 

                 </tr>
             <?php 
	  
	   $totalbillsbalance=0;
  	foreach ($paidbills as $row): 
	
 $mybalance=0;
$mycash=0;

             ?>



             <tr>
                
            <?php 
$id=$row->id;
$myinvoice=$row->id ;

?>

  <td><?php 
	 
	  $mysupplier=$row->supplier ;

$mycustomer=$this->usermodel->populateallarray('people','id', $mysupplier);


			
			if($mysupplier !=""){
				if($mycustomer[0]['company']!=""){
									echo$myname=$mycustomer[0]['company'];

				}else{
									echo$myname=$mycustomer[0]['firstname'];

				}
			}

	 
	 
	 
	 
	 
	 
	 
	 
	 echo " (RS-".$myinvoice.")"; ?></td>           
  </td>
    <td>
  
  		   <a  id="non-printable" class=" btn-default" target="_blank"  href="<?php echo base_url();?>user/searchallmysalesorder?searchterm=<?php   if(isset($row->invoice )) {echo $row->invoice ; } ?>&view=userdata/allinvoices"> 		

  <?php echo $row->invoice ; ?>
   </a>
  
   <span id="myprint">
<?php echo $row->invoice ; ?>
						 </span>
  
 
     </td>
  
    <td><?php
	 $ttbillsbalance=$ttbillsbalance+$row->amount ;
	 $totalbillsbalance=$totalbillsbalance+$row->balance ;

		echo formatMoney($row->amount, true);

	
	?></td>
	<td><?php echo $row->balance ; ?></td>
   <td><?php echo $row->remarks ; ?></td>
	  
	
	   
	   <td>
			 <?php  $paymentmethodesid= $row->paymentmethodes ;
	 $mypaymentmethodes = $this->usermodel->populateallarray('glaccounts','number',$paymentmethodesid);

   echo $mypaymentmethodes[0]['accountname'];
			  ?>
			</td>

	  <td><?php
	  
	  
	  
	  	   
  if($group=="no"){
	  echo $row->paiddate ;
  }else{
	   echo $row->mydateposted;
	  
  }
 
	  
	  
	  
	  
	  
	  ; ?></td>
	   <td><?php  $userids= $row->userid ;

$myuser=$this->usermodel->geteuser($userids);
   echo $myname=$myuser[0]['firstname'];

  ?></td>

                 
				 

             </tr>

	<?php endforeach;
	
	} ?>

            
							
								

							<tr>	
								
								<th colspan="2" >
								
								
								
								 Total Money Paid out:<br>
								
								
								
								</th>
								
														<th >
<?php if(isset($ttbillsbalance)) {

		echo formatMoney($ttbillsbalance, true);


 }?>
								
														</th>
												
														<th >

					</th>		
														
														
														
														
														
														
														
														
														
														
														<th colspan="4" ></th>
							</tr>

        </table>
		
		
		
		
				<table border="1"  width="100%">			

             <thead>
			   <tr>
			        <th colspan="6"><CENTER>DAILY DIRECT EXPENDITURE</CENTER></th>
			     </tr>
         <tr>
    
     <th>Date</th>

	 <th>Amount</th>
		   <th>Name</th>
		      <th>Approved by?</th>
	     <th>Description</th>
			<th>Status</th>		 
		
		

                 </tr>
             </thead>
<?php

 if(!is_array($viewexpenses)) 

 {


   
    }else {
?>
    
             <?php 
  $totalamount=0;
  	foreach ($viewexpenses as $c): 

		 

             ?>



             <tr>
                
            <?php 
$id=$c->id;
$img_id=$c->img_id;

$totalamount=$totalamount+$c->amount ;

?>

              

  <td><?php 
  
   
  if($group=="no"){
	  echo $c->datespent ;
  }else{
	   echo $c->mydateposted;
	  
  }
 
 
 
 ?></td>

  <td><?php 
  		echo formatMoney($c->amount, true);

  
  ?></td>
	   <td><?php echo $c->user ; ?></td>
	   <td><?php echo $c->controller ; ?></td>
	    <td><?php echo $c->description ; ?></td>
		  <td><?php echo $c->status ; ?></td>
		
	
             </tr>

	<?php endforeach; ?>

	
									<tr border="1" background="green">
									<td colspan="1"><b>Total Expenditure</b></td>
		<td colspan="6">
<b><?php
$totalamount=$totalamount+$ttpurchases+$ttbillsbalance;
 if(isset($totalamount)) {
  		echo formatMoney($totalamount, true);



 }?></b>		</td>

			
									
</tr>
	
									<tr border="1" background="green">
									<?php if(isset($total)) {$finalbalance=(($mytotal+$ttcollections)-$totalamount);  }
									
									?>
									<td colspan="1"><b>Total Money Rendered</b></td>
		<td colspan="6">
<b><?php if(isset($finalbalance)) {
  		echo formatMoney($finalbalance, true);


   }?></b>		</td>

			
									
</tr>
	
	
	
	
	
	
	
              <?php }?>

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

			<div id="deleteModel" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Delete</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to delete this item? </h3>
      </div>
      <div class="modal-footer">
	  	

     
		<?PHP
				$session_data = $this->session->userdata('logged_in');
 echo $this->session->flashdata('deletemsg'); 

		
                 echo form_open('user/deletebyid' , array('class' => 'form-horizontal ', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>
 <input type="hidden" id="table"name="table" class="table" placeholder="table" value="sales">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="user/startsales">
 <input type="hidden" id="itemid1"name="itemid" class="itemid" placeholder="itemid" value=""><br>
 <button type="button" class="btn btn-success" data-dismiss="modal">No</button>
 		  	         <button type="submit" name="btn_delete" value="deletebyid" class="btn btn-danger"> Delete  </button>

	<?php echo form_close();?>
      </div>
    </div>

  </div>

  </div>		
	
	
	
	
	
	
	
	
	
	

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

 
</div>


















