
<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">
	
 <link href="<?php echo base_url(); ?>assets/select/chosen.min.css" rel="stylesheet" media="screen">
	
		   
		   		   <script src="<?php echo base_url(); ?>assets/select/chosen.jquery.min.js"></script>

				   
         <script type="text/javascript">
  	
	 $(document).ready(function() { 
				$("#baddebt").hide();
               $("#bankname").show();
        	$("#transactioncode").hide();

					});
					
			
		         $(function () {
        $("#name").change(function () {
            if ($(this).val() == "payment") {
            
			$("#baddebt").hide();
               $("#bankname").show();
              		 
              

            } else if ($(this).val() == "baddebt") {
            
		 $("#baddebt").show();
               $("#bankname").hide();
		 
              

            }
			
			else {
               
			$("#baddebt").hide();

            
			
            }
        });
    });
		
		
	
		
		
		
		
		         $(function () {
        $("#method").change(function () {
            if ($(this).val() == "mpesa") {
            			$("#transactioncode").show();

        
		
            } else if ($(this).val() == "cheque") {
            
            			$("#transactioncode").show();

              

            }  else if ($(this).val() == "card") {
            
            			$("#transactioncode").show();

              

            }
			
			else {
               
			$("#transactioncode").hide();

            
			
            }
        });
    });
			
		
			
		 $(document).on("click", "#addgl", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid2").val(itemid); 
		  
		   var invoice = $(this).data('invoice');
		  $("#invoice2").val(invoice); 
		   
        });
			
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		   var mybalance = $(this).data('balance');
		  $("#mybalance").val(mybalance); 
		   
        });
				
 $(this).ready( function() {  
            $("#phone").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/branchlookupmpesadebts",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });  
		
		var util = { };

document.addEventListener('keydown', function(e){

    var key = util.key[e.which];
    if( key ){
        e.preventDefault();
    }
  if( key === 'F1' ){        
      $("#id").focus();
    }
    if( key === 'F2' ){        
      $("#qty").focus();
	   $("#qty").focus().value = "";
	  document.getElementById("qty").value = "";
    }
	 if( key === 'F3' ){        
      $("#cash").focus();
	   $("#cash").focus().value = "";
	  document.getElementById("cash").value = "";
    }
	 if( key === 'F4' ){        
      $("#mpesa").focus();
    }
	 if( key === 'F5' ){        
      $("#card").focus();
    }
	 if( key === 'F6' ){        
      $("#credit").focus();
    }
	 if( key === 'F7' ){        
      $("#voucher").focus();
    }
	 if( key === 'F8' ){        
      $("#cheque").focus();
    }
	 if( key === 'F9' ){        
      $("#points").focus();
    }
	if( key === 'F10' ){        
      	  	  document.getElementById("phone").value = "";
$("#phone").focus();

	  	  document.getElementById("phone").value = "2547";

    }
		 if( key === 'right' ){        
      $("#btn_dontprint").focus();
    }
		 if( key === 'left' ){        
      $("#btn_savesales").focus();
    }
	
	if( key === 'alt' ){        
      $("#cardnumber").focus();
    }
	
	
	

	 if( key === 'enter' ){        
return true;
    }
	
})


  
util.key = { 
  9: "tab",
  //13: "enter",
  16: "shift",
  18: "alt",
  27: "esc",
  33: "rePag",
  34: "avPag",
  35: "end",
  36: "home",
  37: "left",
  38: "up",
  39: "right",
  40: "down",
  112: "F1",
  113: "F2",
  114: "F3",
  115: "F4",
  116: "F5",
  117: "F6",
  118: "F7",
  119: "F8",
  120: "F9",
  121: "F10",
  122: "F11",
  123: "F12"
}
		
    </script>   

 
 <div class="row">
  
   	

   	<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>
				 <span class="pull-right"> View all collections</span>
				 <?PHP
				 	 $session_data = $this->session->userdata('logged_in');
 echo $this->session->flashdata('deletemsg'); 

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
	   $data['branchid'] = $session_data['branchid'];
	 $branchid = $data['branchid'];	
	 
	 
				  $view="";
				      $mpesaaction=$this->usermodel->populatuserpermissionsdataarray('sales','mpesa',$userid);

				 ?>
				 
				 				 <a  class="btn btn-info"  id="non-printable" target="_blank"  href="<?php echo base_url();?>user/printinvoice?invoice=<?php   if(isset($itemid)) {echo $itemid; } ?>&view=<?php   {echo  $view;}  ?>"> Print Invoice   </a>

				 									<a  id="more" class="btn btn-info" href="<?php echo base_url();?>user/viewsales"> Back to sales  </a>

	  <a data-toggle='modal' data-target='#addModal' class="btn btn-primary">Receive Payment </a>
	  	  <a data-toggle='modal' data-target='#cancelModal' class="btn btn-primary">Reverse Payment </a>
									<a  id="more" class="btn btn-info" href="<?php echo base_url();?>user/changepayment?invoice=<?php   if(isset($itemid)) {echo $itemid; } ?>"> Update payments  </a>

									<a  id="more" class="btn btn-info" href="<?php echo base_url();?>user/searchallmyinvoices?searchterm=<?php   if(isset($itemid)) {echo $itemid; } ?>"> Go back  </a>
									
									<a  id="more" class="btn btn-info" href="<?php echo base_url();?>user/mysales"> Back to cashier sales  </a>

									<a  id="more" class="btn btn-info" href="<?php echo base_url();?>user/allcreditors"> All Creditors  </a>
									<a  id="more" class="btn btn-info" href="<?php echo base_url();?>user/allinvoices"> All Invoice  </a>

   </br>   

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

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


				echo $this->session->flashdata('msg'); 
								?>	
					<div class="row">
						<div class="col-md-12">
								

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

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Receive new Payment</h4>
      
	    <div class="col-sm-4">


      <form name ="mpesa" id="sales"action="getpaymentDebtors" method="post">

					  		<input type="hidden" name="invoice" value="<?php echo set_value('type',$itemid); ?>" class="form-control" required placeholder="Enter invoice">
							
													<?php
 if( $mpesaaction==true){
	 

	 ?>
<input type="text" name="phone" style="width:40%" id="phone" placeholder="Enter Phone No/Name" style="margin-bottom:0: "value="" class="form-control" />
	
			
			
	 	<?php	
		
		}
  ?>

 <input type="hidden" id="myview"name="myview" class="view" placeholder="view" value="user/viewbalance?invoice=<?php echo$itemid ;?>&">





	</form>
</div>
	    <div class="col-sm-4">
	
	
	
	<form name ="mpesa" id="sales"action="getpaymentsdkpush" method="post">

				<input type="hidden" name="invoice" value="<?php echo set_value('type',$itemid); ?>" class="form-control" required placeholder="Enter invoice">
	
													<?php
													      $allbalance=($allsalesmain[0]["balance"]* -1);

 if( $mpesaaction==true){
	 

	 ?>
<input type="text" name="phone" id="sdkphone" placeholder="Enter Phone No to verify" style="margin-bottom:0: "value="<?php if(isset($_GET['sdkphone'])) {echo $_GET['sdkphone']; }else{ echo "254";}?>"" class="form-control" />
								SDK Push<input type="hidden" name="finaltotals"     placeholder="Cash" value="<?php if(isset($allbalance)) {echo $allbalance; }else{ echo "1";}?>" />

			
			
	 	<?php	
		
		}
  ?>
 <input type="hidden" id="myview"name="myview" class="view" placeholder="view" value="user/viewbalance?invoice=<?php echo$itemid ;?>&">


								<input type="hidden" name="total"  id="myfinaltotal"   placeholder="Cash" value="<?php if(isset($allbalance)) {echo ($allbalance); }?>" />




	</form>
	
	
	
	
	
	
	
	
	
	
	</div>
</br>
	  </br></br>
	  </div>
      <div class="modal-body">
	  	
  
	  	

				<?PHP
//$session_data = $this->session->userdata('logged_in');
      $mydate=date("Y-m-d H:i:s");



		
                 echo form_open('user/addpayment' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>
		  		<input type="hidden" name="itemid" value="<?php echo$itemid ;?>" class="form-control"  placeholder="Enter itemid">

	 <div class="form-group">
    <label for="inputname" class="col-sm-2 control-label">Payment type</label>
    <div class="col-sm-4">
	<select class="form-control" id="name" name="name" required required>
	
	<option value=""  >---Select Payment type---</option>
			<option value="payment" selected="selected" >I want Receive payment</option>

		<option value="baddebt"  >I want Write off bad debt</option>

		

</select>
</div>

    <label for="inputpaiddate" class="col-sm-1 control-label">Payment Date</label>
    <div class="col-sm-5">
	
		  		<input type="text" name="paiddate" value="<?php echo set_value('paiddate',$mydate); ?>" class="form-control" required placeholder="Enter Banking Date">
		 
				
		<span class="text-danger"> <?php echo form_error('paiddate'); ?>
		
		</span>
	</div>
  </div>
	
	 <div class="form-group">
    <label for="inputmethod" class="col-sm-2 control-label">Payment method</label>
    <div class="col-sm-4">
	<select class="form-control" name="method" id="method"  required>
	
	
	<?PHP
	if(isset($_GET['mpesaamount'])) {
		?>
		<option value="mpesa" selected="selected" >---MPESA---</option>

	<?PHP	
	}
	?>
	
	
	
	
	
	
	
	
	
	<option value=""  >---Select Payment method---</option>
			<option value="cheque"  >---BANK/CHEQUE---</option>

		<option value="cash"  >---CASH---</option>
		<option value="mpesa"  >---MPESA---</option>

		
		
		<option value="card"  >---CARD---</option>
		<option value="voucher"  >---VOUCHER---</option>

		
		<option value="credit"  >---CREDIT---</option>
				<option value="creditnote"  >---CREDIT NOTE---</option>

		<option value="points"  >---POINTS---</option>
		<option value="baddebt"  >---BAD DEBT---</option>
	<option value="advance"  >---ADVANCE---</option>
		

</select>
		

	</div>



  <label for="inputremarks" class="col-sm-2 control-label">	Remarks / Description</label>
    <div class="col-sm-4">

				<textarea name="remarks" value="<?php echo set_value('remarks'); ?>"  class="form-control"  placeholder="Enter remarks if any"></textarea>
			
		<span class="text-danger"> <?php echo form_error('remarks'); ?>
		
		</span>
	</div>
	
    <label for="inputamount" class="col-sm-2 control-label">	Amount </label>
    <div class="col-sm-4">
	<?PHP
	if(isset($_GET['mpesaamount'])) {
		?>
		 		<input type="text" readonly  class="form-control" name="amount" value="<?php if(isset($_GET['mpesaamount'])) {echo $_GET['mpesaamount']; }else{echo "0";}?>" placeholder="enter amount" onkeyup='OnChange(this.value)' onkeypress="return isNumberKey(event)" autocomplete="off"  required="required"/>

	<?PHP	
	}else{
	?>
				<input type="text"  class="form-control" name="amount" value="<?php if(isset($_GET['mpesaamount'])) {echo $_GET['mpesaamount']; }else{echo "0";}?>" placeholder="enter amount" onkeyup='OnChange(this.value)' onkeypress="return isNumberKey(event)" autocomplete="off"  required="required"/>


	<?PHP
	}
?>
			 <?php if(isset($_GET['transactioncode'])) {echo "<b>Transaction code: ". $_GET['transactioncode']."</b>"; }?>	
		<span class="text-danger"> <?php echo form_error('amount'); ?>
		
		</span>
		
	</div>
	
	
		
	
	
	
	
	
	
	
	
	
	
	
  </div>
  <div class="form-group">
 
		<div id="transactioncode">
    <label for="inputtransactioncode" class="col-sm-2 control-label">	Transaction code </label>
    <div class="col-sm-4">

		 			<input type="text" name="transactioncode"  id="phone" value="<?php if(isset($_GET['transactioncode'])) {echo $_GET['transactioncode']; }?>" placeholder="Enter reference code" class="form-control" />

				
		<span class="text-danger">Transaction code / Chq No, Rct No <?php echo form_error('transactioncode'); ?>
		
		</span>
	</div>
	</br>
		Sms Alert   : <select class="form-control2" name="sendsms" id="sendsms"  required>
	
	<option value=""  >-Send SMS?---</option>
			<option value="yes"  >Yes</option>

		<option value="no" selected="selected"   >No</option>

		

</select>	
				  Sms description:		<input type="text" name="smsdescription" value="<?php echo set_value('smsdescription'); ?>" class="form-control2"  placeholder="Enter sms description">

</div>
  
  </div>
		
 
	
	
	    <div class="form-group">

	
	      <div id="bankname">
    <label for="inputbankname" class="col-sm-2 control-label">Bank name?</label>
    <div class="col-sm-4">
	<select class="form-control" name="bankname"  >
	
	<option value=""  >---Select bank name---</option>
	
	<?php 
	$session_data = $this->session->userdata('logged_in');

  
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
		 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
					 
										//$banking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype','1');
										$banking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype','1');
//

	
if(is_array($banking)) {

   foreach($banking as $bankingrow){

   //echo $courserow->coursename;
    ?>

<?PHP
	if(isset($_GET['mpesaamount'])) {
		?>
		<option value="1010" selected>Mpesa Account</option>

	<?PHP	
	}
	?>
	
					<option value="<?=  $bankingrow->number;   ?>"><?=  $bankingrow->accountname ."(Acc No:". $bankingrow->number .")"; ?></option>


	<?php

}} else {
    echo 'No bank available.';
}
	
$allbanking="";
	//$allbanking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype<>','1');
	//$allbanking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype','1');
									//	$allbanking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype','1');

										
if(is_array($allbanking)) {

   foreach($allbanking as $allbankingrow){

   //echo $courserow->coursename;
    ?>
		<option value="<?=  $allbankingrow->number;   ?>"><?=  $allbankingrow->accountname ."(Acc No:". $bankingrow->number ."-Acc Name: ".$bankingrow->accountname.") "; ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	
	
	
	
	
	
?>
</select>
		
						<span class="text-danger"><?php echo form_error('bankname'); ?>

	</div>
	</div>
	
	
	      <div id="baddebt">
    <label for="inputbaddebt" class="col-sm-2 control-label">Bad debt Account name?</label>
    <div class="col-sm-4">
	<select class="form-control" name="baddebt" >
	
	<option value=""  >---Select account name---</option>
	
	<?php 
	$session_data = $this->session->userdata('logged_in');

  
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
		 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
					 
										$banking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype','1');


	
if(is_array($banking)) {

   foreach($banking as $bankingrow){

   //echo $courserow->coursename;
    ?>
				<option value="<?=  $bankingrow->number;   ?>"><?=  $bankingrow->accountname ."(Acc No:". $bankingrow->number .")-Balance: ".$bankingrow->amount.""; ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	
?>
</select>
		
						<span class="text-danger"><?php echo form_error('baddebt'); ?>

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

	
	
	
	
	
	
	
	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-4">
     
	         <button type="submit"  value="payment" name="btn_payment" class="btn btn-primary"> Add Payment   </button>

    </div> 
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

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

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

             <thead>
         <tr>
     <th>Receipt No</th>
     <th>Invoice No</th>
	  <th>Amount</th>
	   <th>Balance</th>
	   <th>Remarks</th>
	    	   <th>Method</th>
	    	   <th>Type</th>
	   <th>Code</th>
<th>Date</th>	
 
		   <th>Added by</th>

		
  <th>More</th> 
		<th>Print</th>

                 </tr>
             </thead>
<?php
$session_data = $this->session->userdata('logged_in');
$myuserids= "";  
	 
 	$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 '<div class="alert alert-danger text-center">There is no data found in the system</div>';
$mybalance=0;
$mycash=0;
				  if(is_array($allsales)) 

 {
	
foreach ($allsales as $myrow){
	
	
  $myuserids= $myrow->customer ;  
   
	    $mycash=$myrow->cash;
		 $mybalance=$myrow->balance;
	    $mytotals=$myrow->total;
	
}
    }
		
			 }else{
 if(!is_array($allcollections)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='1'>";
    
				 echo '<div class="alert alert-danger text-center">There is no data found in the system</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
   $totalcost=0;
  	foreach ($allcollections as $c): 

 $mybalance=0;
$mycash=0;
				  if(is_array($allsales)) 

 {
	
foreach ($allsales as $myrow){
	
	

     $myuserids= $myrow->customer ;  

	    $mycash=$myrow->cash;
		 $mybalance=$myrow->balance;
	    $mytotals=$myrow->total;
	
}
    }
	
	//

             ?>

				<?php
					
		
                 echo form_open('user/editcustomerpayment' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>	
	<input type="hidden" name="id" id="id" value="<?php echo set_value('id',$c->id); ?>" class="form-control" required placeholder="invoice " >

  					<input type="hidden" name="invoice" id="invoice" value="<?php echo set_value('invoice',$c->invoice); ?>" class="form-control" required placeholder="invoice " >

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

?>

     <td><?php echo "RS-".$myinvoice; ?></td>           
  <td><?php echo $c->invoice ; ?></td>
  
    <td><?php 
	$totalcost=$totalcost+$c->amount ;
	
	?>
	 					<input type="text" name="amount" id="amount" value="<?php echo set_value('amount',$c->amount); ?>" class="form-control" required placeholder=" amount" >

	
	</td>
	 <td>
 					<input type="text" name="balance" id="balance" value="<?php echo set_value('balance',$c->balance); ?>" class="form-control" required placeholder=" balance" >
</td>

 <td>
 					<input type="text" name="remarks" id="remarks" value="<?php echo set_value('remarks',$c->remarks); ?>" class="form-control" required placeholder=" remarks" >
</td>

	
<td>
			 <?php  $paymentmethodesid= $c->paymentmethodes ;
	 $mypaymentmethodes = $this->usermodel->populateallarray('glaccounts','number',$paymentmethodesid);

   //echo $mypaymentmethodes[0]['accountname'];
			  ?>
			  
			  
			  <select class="form-control" name="bankid" required>
	
	<option value=""  >---Select bank ---</option>
	
	<?php 
	
			$banking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'number',$paymentmethodesid);

										
if(is_array($banking)) {

   foreach($banking as $bankingrow){

   //echo $courserow->coursename;
    ?>
		<option selected="selected" value="<?=  $bankingrow->number;   ?>"><?=  $bankingrow->accountname ."(Acc No:". $bankingrow->number.")"; ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	
	
	
	
	$banking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype','1');


	
if(is_array($banking)) {

   foreach($banking as $bankingrow){

   //echo $courserow->coursename;
    ?>
				<option value="<?=  $bankingrow->number;   ?>"><?=  $bankingrow->accountname ."(Acc No:". $bankingrow->number .")-Balance: ".$bankingrow->amount.""; ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	

	$allbanking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype<>','1');

										
if(is_array($allbanking)) {

   foreach($allbanking as $allbankingrow){

   //echo $courserow->coursename;
    ?>
		<option value="<?=  $allbankingrow->number;   ?>"><?=  $allbankingrow->accountname ."(Acc No:". $bankingrow->number ."-Acc Name: ".$bankingrow->accountname.")  Balance ".$bankingrow->amount; ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	
	
	

	
	
	
	
	$allbanking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype<>','1');

										
if(is_array($allbanking)) {

   foreach($allbanking as $allbankingrow){

   //echo $courserow->coursename;
    ?>
		<option value="<?=  $allbankingrow->number;   ?>"><?=  $allbankingrow->accountname ."(Acc No:". $allbankingrow->number .")"; ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	
	
	
	
	
	
?>
</select>
		
			  
			  
			  
			  
			  
			  
			  
			  
			</td>
			 <td>
 					<input type="text" name="name" id="name" value="<?php echo set_value('name',$c->name); ?>" class="form-control" required placeholder=" name" >
</td>
	  	 
	 <td>
 					<input type="text" name="transactioncode" id="transactioncode" value="<?php echo set_value('transactioncode',$c->transactioncode); ?>" class="form-control"  placeholder=" transaction code" >
</td>
 <td>
 					<input type="text" name="paiddate" id="paiddate" value="<?php echo set_value('paiddate',$c->paiddate); ?>" class="form-control" required placeholder=" paiddate" >
</td>



	   <td>
	   
	   
	   
	   <?php  $userids= $c->userid ;
 
$myuser=$this->usermodel->geteuser($userids);
   echo $myname=$myuser[0]['firstname'];

  ?>
  

  
  </td>

                  <td> 

 
 
					<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">
									<?php
										if($usertype=="admin"){
											
											?>
                                 
                                        
                                        <!-- 
                                      
										
											  <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>
													teacher EDITING LINK -->	

										<?php
										}
										?>
									
                                        <li class="divider"></li>
                                        
                                     <button type="submit"  value="myedit" name="btn_editcustomerpayment" class="btn btn-info"> <span class="glyphicon glyphicon-pencil"></span> </a>  Update </button>
                                        <li class="divider"></li>

                                            <li> 
				<a  id="more" class=" btn-success"  href="<?php echo base_url();?>user/searchJE?searchterm=<?php   {echo  $c->invoice;}  ?> ">
								 
																							 

                                                <i class="glyphicon glyphicon-pencil"></i>
															View	GL Transactions
                                                </a>
																		
										</li>
										
										                                        <li class="divider"></li>

										
										
														  <li> 
										 <a class="btn btn-warning addgl" id="addgl"		 data-id='<?php echo  $c->id;?>'   data-invoice='<?php echo  $c->invoice;?>'   data-toggle='modal' data-target='#addglModel<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Crete New GL For this payment
                                                </a>
                                                        </li>

                                    </ul>
										
                                </div>
</td> 
 <td>
	  	  	  	 <a  id="more" class="btn btn-primary"  href="<?php echo base_url();?>user/printreceivedpayments?randomitemidentifier=<?php   {echo  $c->invoice;}  ?>&myid=<?php   {echo  $id;}  ?>">Print  </a>
 
  
  </td>

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

	<?php endforeach;} ?>

              <?php }?>
			  	</tr>
						<tr>		
								

								
								<th colspan="1" >
								
								
                     <a  id="more"  class="btn btn-warning" href="<?php echo base_url();?>user/getinvoivebysupplier?randomitemidentifier=<?php   {echo  $myuserids;}  ?>">Go back to Pending Invoices  </a>


								
								
								<th>
								<th colspan="3" >
								Exp Grand Total:<?php if(isset($mytotals)) {echo $mytotals; }?><br>
								Cash Paid     :<?php if(isset($mytotals)) {echo $mytotals+$mybalance; }?><br>
								Balance Due    : <?php if(isset($mybalance)) {echo (-1*$mybalance); }?>
								
								
								</th>
						
							</tr>

        </table>
		
	</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="collection">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="user/viewbalance?invoice=<?php echo$itemid ;?>">
 <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 id="addglModel" 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">Create New Gl</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to pass new Journal Entry for this payment? </h3>
      </div>
      <div class="modal-footer">
	  	

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

		
                 echo form_open('user/createnewpaymentgl' , 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="invoice2"name="invoice" class="invoice" placeholder="invoice" value="collection">
 <input type="hidden" id="category"name="category" class="category" placeholder="category" value="payment"><br>

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="user/viewbalance?invoice=<?php echo$itemid ;?>">
 <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-warning"> Yes  </button>

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

  </div>

  </div>		
	
						
									
									
					
	
	<div id="cancelModal" 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">Reverse old Payment</h4>
      </div>
      <div class="modal-body">
      
	  	

				<?PHP
//$session_data = $this->session->userdata('logged_in');
      $mydate=date("Y-m-d H:i:s");



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/cancelpayment' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>
		  		<input type="hidden" name="itemid" value="<?php echo$itemid ;?>" class="form-control"  placeholder="Enter itemid">

	 <div class="form-group">
    <label for="inputname" class="col-sm-2 control-label">Payment type</label>
    <div class="col-sm-10">
	<select class="form-control"  name="name" required required>
	
	<option value=""  >---Select Payment type---</option>
			<option value="cancel" selected="selected" >I want reverse payment made</option>


		

</select>
		

	</div>
  </div>
	
	<div class="form-group">
    <label for="inputpaiddate" class="col-sm-2 control-label">Payment Date</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="paiddate" value="<?php echo set_value('paiddate',$mydate); ?>" class="form-control" required placeholder="Enter Banking Date">
		 
				
		<span class="text-danger"> <?php echo form_error('paiddate'); ?>
		
		</span>
	</div>
  </div>
	
	<div class="form-group">
    <label for="inputamount" class="col-sm-2 control-label">	Amount to reverse </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="amount" value="<?php echo set_value('amount'); ?>" class="form-control"  placeholder="Enter amount to pay">
		 
				
		<span class="text-danger"> <?php echo form_error('amount'); ?>
		
		</span>
	</div>
  </div>
  
	
  
	<div class="form-group">
    <label for="inputremarks" class="col-sm-2 control-label">	Remarks
	/Comments</label>
    <div class="col-sm-10">

				<textarea name="remarks" value="<?php echo set_value('remarks'); ?>"  class="form-control"  placeholder="Enter remarks if any"></textarea>
			
		<span class="text-danger"> <?php echo form_error('remarks'); ?>
		
		</span>
	</div>
  </div>
		
 
	
	
	
	 <div class="form-group">
    <label for="inputmethod" class="col-sm-2 control-label">Payment method</label>
    <div class="col-sm-10">
	<select class="form-control" name="method" required>
	
	<option value=""  >---Select Payment method to reverse---</option>
			<option value="cheque"  >---BANK/CHEQUE---</option>

		<option value="cash"  >---CASH---</option>
		<option value="mpesa"  >---MPESA---</option>

		
		
		<option value="card"  >---CARD---</option>
		<option value="voucher"  >---VOUCHER---</option>

		
		<option value="credit"  >---CREDIT---</option>
				<option value="creditnote"  >---CREDIT NOTE---</option>

		<option value="points"  >---POINTS---</option>
		<option value="baddebt"  >---BAD DEBT---</option>

		
		

</select>
		

	</div>
  </div>
	

	
	      <div class="form-group" id="bankname">
    <label for="inputbankname" class="col-sm-2 control-label">From Which Bank ?</label>
    <div class="col-sm-10">
	<select class="form-control" name="bankname" required >
	
	<option value=""  >---Select bank name to cancel from---</option>
	
	<?php 
	$session_data = $this->session->userdata('logged_in');

  
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
		 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
					 
										$banking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype','1');


	
if(is_array($banking)) {

   foreach($banking as $bankingrow){

   //echo $courserow->coursename;
    ?>
				<option value="<?=  $bankingrow->number;   ?>"><?=  $bankingrow->accountname ."(Acc No:". $bankingrow->number .")-Balance: ".$bankingrow->amount.""; ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	

	$allbanking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype<>','1');

										
if(is_array($allbanking)) {

   foreach($allbanking as $allbankingrow){

   //echo $courserow->coursename;
    ?>
		<option value="<?=  $allbankingrow->number;   ?>"><?=  $allbankingrow->accountname ."(Acc No:". $bankingrow->number ."-Acc Name: ".$bankingrow->accountname.")  Balance ".$bankingrow->amount; ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	
	
	
	
	
	
?>
</select>
		
						<span class="text-danger"><?php echo form_error('bankname'); ?>

	</div>
  </div>

  
  
	
	
	
	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="payment" name="btn_cancelpayment" class="btn btn-primary"> Cancel Payment   </button>

    </div>
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

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

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

 
</div>


















