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

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

  
		<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>
				
                        <a  id="non-printable"  class="btn btn-primary" href="<?php echo base_url();?>user/startsales">back  </a>
				 		 	<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">				
				<?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);


				echo $this->session->flashdata('msg'); 
								?>	
					<div class="row">
						<div class="col-md-12">
							
							<div class="panel-body">
	<div id="printableArea" style="width:100%" >
									
				<table border="1"  width="100%">			

             <thead>
         <tr>
									 <th> Rct No</th>
									<th id="non-printable"> Ref No</th>
                                        <th>  Mode</th>
										   

                                              <th> Sale Type</th> 
														<th> Total</th> 
                                              <th> Bal</th>   
											  <th> Cash</th>  
											 <th> Mpesa</th>
												<th> Card</th>  
											 <th> Voucher</th> 
												<th> Credit</th> 											
											  <th> Points</th>                       
											  <th>Cheque</th> 
												<th> Code</th>											  
												<th> Tax</th> 											
											  <th> Due date</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>
             </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;		  




  	foreach ($salesreport as $c): 

 $myinvoice=$c->invoice ; 
             ?>



             <tr>
          <td><?php echo $c->id ; ?>
		  
		  			    <a id="non-printable" class=" btn-primary" href="<?php echo base_url();?>user/printdelivery?invoice=<?php   if(isset($myinvoice)) {echo $myinvoice; } ?>">Delivery   </a>

		  
		  </td>          
            <?php 
$id=$c->id;
 $total=$total+$c->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";
	
}
 
?>

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


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

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

  	  <td><?php echo $c->salestype ; ?></td>
 <td>
 <a  id="non-printable"  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>
      <td><?php echo $c->mpesa ; ?></td>
			     <td><?php echo $c->card ; ?></td>
											   <td><?php echo $c->voucher ; ?></td>
												  <td><?php echo $c->credit ; ?></td>
												   <td><?php echo $c->points ; ?></td>
											   <td><?php echo $c->cheque ; ?></td>
											    <td><?php echo $c->cashier ; ?></td>

	 
	    <td><?php
	
		$totalcash=$totalcash+$c->cash;
		$totalmpesa=$totalmpesa+$c->mpesa;
		
		$totalcredit=$totalcredit+$c->credit;		  
$totalcheque=$totalcheque+$c->cheque;	
$totalvoucher=$totalvoucher+$c->voucher;			  
$totalpoints=$totalpoints+$c->points;	
$totalcard=$totalcard+$c->card;	
		
		
		
		
		$mytax=$this->usermodel->populateall('sales_order','invoice', $myinvoice);
				$cashmpesa=	 $totalmpesa+$totalcash+$totalcredit+$totalcheque+$totalvoucher+$totalpoints+$totalcard;
	$mytotal=$totalmpesa+$totalcash+$totalcheque+$totalpoints+$totalcard;
$taxrate=0;

if(is_array($mytax)) {

   foreach($mytax as $myrow){
    $myrow->tax;
$taxrate=$taxrate+$myrow->tax;

}
}
$totaltax= $totaltax+$taxrate;
			echo$taxrate;
		
		?></td>
	  <td><?php echo $c->due_date ; ?></td>


<td><?php  $customer=$c->customer ;

$mycustomer=$this->usermodel->populateallarray('people','id', $customer);
if($customer ==FALSE){
	echo  $customer=$c->name;
}else{
	
	
if($customer !=""){
				echo$myname=$mycustomer[0]['company'];

}else{
		echo  $customer=$c->name;

}
}

 ?></td>

 <td><?php echo $c->dateposted	 ; ?></td>	
      <td>
												 
	<?php 
					// $branch="";
					 $branch=$c->branch;

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



if(is_array($branch)) {

   foreach($branch 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 echo $c->paymentstatus ; ?></td>
   <td  id="non-printable"> 

 
 
					<div class="btn-group">
                                    <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown">
                                        Delete <span class="caret"></span>
                                    </button>
									
									
									<?php
										 if( $deleteaction==true){
											
											?>
                                    <ul class="dropdown-menu dropdown-primary pull-right" role="menu">
                                        
                                        <!-- teacher EDITING LINK -->
                                      
										
											  <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>
																Delete
                                                </a>
                                                        </li>
									
									
                                        <li class="divider"></li>
                                        
                                        <!-- teacher DELETION LINK -->
                                        
                                    </ul>
											<?php
										}
										?>
                                </div>
</td> 
         
             </tr>

	<?php endforeach;} ?>

								<tr border="1" background="green">
									<td colspan="6"><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>
			<td>  <b><?php if(isset($totalmpesa)) {echo formatMoney($totalmpesa, true);  }?><b></td>

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

			<td>  <b><?php if(isset($totalvoucher)) {echo formatMoney($totalvoucher, true);  }?><b></td>
	<td>  <b><?php if(isset($totalcredit)) {echo formatMoney($totalcredit, true);  }?><b></td>
				<td>  <b><?php if(isset($totalpoints)) {echo formatMoney($totalpoints, true);  }?><b></td>
			<td colspan="2">  <b><?php if(isset($totalcheque)) {echo formatMoney($totalcheque, true);  }?><b></td>

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

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

        </table>
		
		<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'];	

 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</CENTER></th>
			     </tr>
         <tr>
     <th>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 echo "RS-".$myinvoice; ?></td>           
  <td><?php echo $c->invoice ; ?></td>
  
    <td><?php echo $c->amount ; 
	$mytotals=$mytotals+$c->amount ;
	
	?></td>
	<td><?php echo $c->balance ; ?></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 echo $c->paiddate ; ?></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:<br>
								
								
								
								</th>
								
														<th >
<?php if(isset($mytotals)) {echo $mytotals; }?>
								
														</th>
														<th colspan="5" ></th>
							</tr>

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

             <thead>
			   <tr>
			        <th colspan="6"><CENTER>DAILY 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 echo $c->datespent; ?></td>

  <td><?php echo $c->amount ; ?></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 if(isset($totalamount)) {echo $totalamount;   }?></b>		</td>

			
									
</tr>
	
									<tr border="1" background="green">
									<?php if(isset($total)) {$finalbalance=$mytotal-$totalamount;  }
									
									?>
									<td colspan="1"><b>Total Money Rendered</b></td>
		<td colspan="6">
<b><?php if(isset($finalbalance)) {echo $finalbalance;   }?></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>


















