

<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", "#managebtnclaim", function()
        {
          var itemid3 = $(this).data('id');
		  $("#itemid3").val(itemid3); 
		     var mycode3 = $(this).data('code');
		  $("#mycode3").val(mycode3); 
		  
		   
        });
		
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
  
  		
		 $(document).on("click", "#managebtnreserve", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid2").val(itemid); 
		     var mycode = $(this).data('code');
		  $("#mycode").val(mycode); 
		  
		   
        });
		
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
		
		
		
    </script>   
  <style type="text/css">
  
  

    #printable { 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%; }
    }
    </style>
 
 <div class="row">
  
   	

   	<div class="col-md-12">

  <?php
  //
  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'];	
	 
  
  
  		   	   $viewcashiersales=$this->usermodel->populatuserpermissionsdataarray('cashiersales','cashiersales',$userid);
		  	      $viewmpesamessages=$this->usermodel->populatuserpermissionsdataarray('cashiersales','viewmpesamessages',$userid);

  
  
  
  
  
  
  ?>
		<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 money received</span>
                        <a  id="more"  class="btn btn-primary" href="<?php echo base_url();?>user/viewsales">Back  </a>
						
							 				
				<?php
 if( $viewcashiersales==true){
	 ?>
						                        <a  id="more"  class="btn btn-primary" href="<?php echo base_url();?>user/viewmympesa" >Back to MPESA sales </a>

	 <?php
 }
	 ?>
	  <a  id="more"  class="btn btn-primary" href="<?php echo base_url();?>user/mergempesa" >Merge Mpesa </a>
	  	 <a href="<?php echo base_url();?>user/viewtill" class="btn btn-default"> Till Collections </a>	

 	  	 <a href="<?php echo base_url();?>user/viewmympesa" class="btn btn-default"> Claimed Mpesa  </a>	

	 
	 

				 		 	<div class="pull-right"  >
							<?PHP
							 if( $viewmpesamessages==true){
 
 
								?>
				<a  id="more"  class="btn btn-success" href="<?php echo base_url();?>user/autoloadmpesa" target="_blank"  >Autoload MPESA  </a>
				
							 						                        <a  id="more"  class=" btn-warning" href="<?php echo base_url();?>mainsms.php">Load All MPESA  </a>||
																			  <a  id="more"  class=" btn-info" href="<?php echo base_url();?>sms.php">Load New MPESA  </a> ||
												  <a  id="more"  class=" btn-info" href="<?php echo base_url();?>equitympesa.php">Load EmpesaEquity </a>||
													 <a  id="more"  class=" btn-warning" href="<?php echo base_url();?>mainpaybillsms.php">Load Paybill </a>
											<a  id="more"  class="btn btn-success" href="<?php echo base_url();?>pushsmsadvanta.php" target="_blank"  >Autoload SMS  </a>

				<a  id="more"  class="btn btn-success" href="<?php echo base_url();?>printmpesa" target="_blank"  >Autoload Print  </a>


							<?PHP
							 }
 
 
								?>


<form name="print" method="post" action="">
 <!--<input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('sortable_table')" value="print receipt!" />-->

</form>


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

			
	<div>				
				<?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;
					}
 $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);
    $mpesabalance=$this->usermodel->populatuserpermissionsdataarray('sales','mpesabalance',$userid);
							    $reversempesa=$this->usermodel->populatuserpermissionsdataarray('cashiersales','reversempesa',$userid);
 $claimmpesacode=$this->usermodel->populatuserpermissionsdataarray('sales','claimmpesacode',$userid);

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

				echo $this->session->flashdata('msg'); 
								?>	
					<div class="row">
						<div class="widget-content nopadding table_holder table-responsive" >				

						<div class="col-md-12">
							
							<div class="panel-body">
		<div class="col-md-12">
        <?php 
		 echo $this->session->flashdata('msg'); 
        $attr = array("class" => "form-horizontal", "role" => "form", "id" => "search", "name" => "search");
        echo form_open("user/searchallpayment", $attr);?>
            <div class="form-group">
			
                <div class="col-md-4">
                    <input class="form-control" required id="searchterm" name="searchterm" placeholder="Search by number or Code.." type="text" value="<?php echo set_value('searchterm'); ?>" />
                </div>
				     <div class="col-md-4">
<select class="form-control" name="method" required >
	
	

	<option value=""  >---How do you want to search the code---</option>
	<option value="whole"   >Use the whole code</option>
		<option value="lastfour"  selected="selected" >Use the Last Four Letters</option>

	
	</select>		 
				               


			   </div>
                <div class="col-md-4">
                    <input id="btn_search" name="btn_search" type="submit" class="btn btn-success" value="Search" />
                    <a href="<?php echo base_url(). "user/viewprndingmoneyreceived"; ?>" class="btn btn-primary">Refresh</a>
                </div>
				 
            </div>
        <?php echo form_close(); ?>
        </div>
									
				<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

             <thead>
         <tr>
									<th> Phone</th>
                                        <th> Amount</th>
                                              <th> Code</th>  
                                              <th> First Name</th>   
											  <th> Last Name</th>   
  <th> Acc No</th>    
											                                                                 

                                              <th> Status</th>   
 											  
 <?php
  if($mpesabalance==true){
 ?>
 											  <th>Message</th>    

     <?php
  }
 ?> 											  



												<th>Date </th>
						<th>Branch </th>

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


                 </tr>
             </thead>
<?php



 
 if(!is_array($mpesareport)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='11'>";
    
       echo '<div class="alert alert-warning text-center">There is no new Mpesa message  found..</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
  $total=0; 
  		 
  	foreach ($mpesareport as $c): 

		      
$id=$c->id;
 $total=$total+$c->amount;
 
 $mycode=$c->code;
?>
         



             <tr>
                


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


    <td><?php echo $c->amount ; ?></td>
   <td><?php echo $c->code	 ; ?></td>
	  <td><?php echo $c->firstname ; ?></td>
	  <td><?php echo $c->lastname ; ?></td>
	  	  <td><?php echo $c->msisdn ; ?></td>

<td><?php 
 $status=$c->used;   
  if($status==1){
	  
	  	 	$smsdetails = $this->usermodel->populateallarray('mpesasales','code',$c->code);
 $myuserid=$smsdetails[0]['userid'];
 $myuser=$this->usermodel->geteuser($myuserid);
  	echo "Used BY: ". $myname=$myuser[0]['firstname']." ".$myuser[0]['surname'];

	

}else if($status==0){
	
	echo "Raw";
}else if($status==2){
	
	echo "New";
}else{
	echo "Used";
} 



 ?></td>
 <?php
  if($mpesabalance==true){
 ?>
  <td><?php echo $c->sms_text ; ?></td>
     <?php
  }
 ?> 
  
  
  
  
  
  
  
  <td><?php echo $c->exactime	 ; ?>
  	 
										 <a class="btn btn-warning managebtn" id="managebtnclaim"		 data-code='<?php echo  $c->code;?>'   data-id='<?php echo  $c->id;?>'    data-toggle='modal' data-target='#claimModel<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Claim Code
                                                </a>
                                                       
  
  </td>	
  <td><?php 
	  	 	$smsdetails = $this->usermodel->populateallarray('branch','id',$c->branchid);
 echo$smsdetails[0]['name'];



	?></td>
  

  
   <td  id="non-printable"> 

 
 
					<div class="btn-group">
                                    <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown">
                                        Action <span class="caret"></span>
                                    </button>

                                    <ul class="dropdown-menu dropdown-primary 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>
																Delete
                                                </a>
                                                        </li>
											<?php
										}
										?>
										
										
										  <li class="divider"></li>
                                    		  <li> 
											  
 <a  id="non-printable" class="btn btn-primary" target="_blank"  href="<?php echo base_url();?>printmpesacode?code=<?php   if(isset($mycode)) {echo $mycode; } ?>"> Print Code  </a>

                                                        </li>
                                        
									
                                        <li class="divider"></li>
												<?php
									 if( $reversempesa==true){
											
											?>
										
											  <li> 
										 <a class="btn btn-primary managebtn" id="managebtnreserve"		 data-code='<?php echo  $c->code;?>'   data-id='<?php echo  $c->id;?>'    data-toggle='modal' data-target='#reverseModel<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Reverse
                                                </a>
                                                        </li>
														
															<?php
										}
										?>
													<?php
									 if( $claimmpesacode==true){
											
											?>
                                               <li class="divider"></li>
                                    		  <li> 
										 <a class="btn btn-warning managebtn" id="managebtnclaim"		 data-code='<?php echo  $c->code;?>'   data-id='<?php echo  $c->id;?>'    data-toggle='modal' data-target='#claimModel<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Claim Code
                                                </a>
                                                        </li>
                                        					<?php
										}
										?>
											
                                    </ul>

                                </div>
</td> 
         
             </tr>

	<?php endforeach; ?>

								<tr border="1" background="green">
									<td><b>Total Amount</b></td>

	<td colspan="3"><h2><?php if(isset($total)) {echo $total;   }?></h2></td>	
	<td colspan="6"></td>								
</tr>
	
	
	
              <?php }?>

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

        
        </div>
   
	</div>
	
	
	
	
	
			<div id="reverseModel" 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">Cancel</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to reverse  this Peyment? </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="mpesasales">
 <input type="hidden" id="mycode"name="code" class="code" placeholder="code" value="">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="user/viewprndingmoneyreceived">
 <input type="hidden" id="itemid2"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"> Yes  </button>

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

  </div>

  </div>
	
	
	
	
	
			<div id="claimModel" 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">CLAIM/CLEAR PAYMENT</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to claim or clear  this pending payment? </h3>
      </div>
      <div class="modal-footer">
	  	

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

		
                 echo form_open('user/viewmympesa' , 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="sms_in">
 MPESA CODE:
 <input type="text"  readonly id="mycode3"name="code" class="code" placeholder="code" value="">
 <br>
<SPAN class="btn btn-warning" >NOTE: CLAIMING OTHER PEOPLE'S CODE WILL LEAD TO SAVERE PUNISHMENT.</span>

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="user/viewmympesa?code=">
 <input type="hidden" id="itemid3"name="itemid" class="itemid" placeholder="itemid" value=""><br>
 <button type="button" class="btn btn-warning" data-dismiss="modal">No /Cancel</button>
 		  	         <button type="submit" name="btn_delete" value="deletebyid" class="btn btn-success"> Yes  I want claim the code</button>

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

  </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="view" value="sms_in">

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

	
		
  

 
</div>


















