<section class="content">
   <div class="box">	
	<style>.fa-usd{font-size:13px; padding-right:1px;} th{vertical-align:top !important;}</style> 	
	<div class="box-header with-border">
		  <h3 class="box-title">Listing</h3>
		  <div class="box-tools pull-right">
			<a href="<?php echo base_url().$this->config->item('admin_directory_name').'/transactions/vectra_beneficiary';?>" class="btn btn-default" style="padding:4px 15px;"> Beneficiary Accounts</a>
			<a href="<?php echo base_url().$this->config->item('admin_directory_name').'/transactions/vectra_add';?>" class="btn btn-primary" style="padding:4px 15px; margin-left:3px;"> Add Transaction</a>
		  </div>
		</div>		   
  <div class="box-body row">
	<div class="col-xs-12 table-responsive">
	 <table class="table table-striped" id="table_recordtbl" style="font-size:15px;">
		<thead>
			<tr>
			  <th width="1%">#</th>
			  <th>Txn Id &amp; Date</th>
			  <th>Beneficiary</th>
			  <th>Amount</th>
			  <th>Sender Name</th>
			  <th>Status</th>
			  <th>Action</th>
			</tr>
		</thead>
		<tbody>
		<?php $i=1; foreach($admin_vectra_transactions_listing as $row) { ?>
			<tr>
				<td><?php echo $i;?></td>
				<td nowrap="nowrap" style="font-weight:600;"><span id="td_txn_id_<?php echo $row->id;?>"><?php echo $row->txn_id;?></span><small><?php echo date('d M Y',$row->trans_occur_date);?></small></td>
				<td><?php echo $row->beneficiary_account_name;?><small><?php echo $row->beneficiary_account_no;?></small></td> 
				<td><?php echo $this->config->item('amt_currencies_array_config')[$row->account_cur]['ad_csign'].$row->trans_amt;?></td> 
				<td><?php echo $row->sender_user_name;?> <small><?php echo $row->sender_acct_no;?></small>
				
				<?php /*$res = filter_array($user_bank_accounts_listing,$row->from_account_id,'account_id');
					if(count($res)>0){
						echo $res[0]['account_no'];
					}*/
					
					?>
					
					</td> 
					
					<td>
				
				<?php if($row->action_sts==1){?>				
					<label class="mstus accepted">Success</label>
				<?php }else if($row->action_sts==2){?>
					<label class="mstus rejected">Refund</label>				
				<?php }else{ ?>
					<label class="mstus pending">Pending</label>	
				<?php } ?> &nbsp;
				
				
				
				<a data-toggle="tooltip" data-placement="top" title="Change Status" id="ch_sts_<?php echo $row->id;?>" onclick="return change_status_model('<?php echo $row->id;?>','<?php echo $row->action_sts;?>');"> <i class="fa fa-pencil-square-o"></i> </a>
				</td>
				 
				<td>
				<a class="btn btn-danger btn-sm" href="<?php echo base_url().$this->config->item('admin_directory_name');?>/transactions/delete_vectra?id=<?php echo $row->id; ?>" onclick="return confirm('Are you sure you want to delete it?');"><i class="fa fa-trash"></i></a>
				</td>	
			</tr>
		<?php  $i++; } ?>          
		</tbody>                  
	</table>
</div>      
</div>    
</div>
<script>
function change_status_model(id,action_sts){
	if(id!=''){ 
		var txnId = $('#td_txn_id_'+id).html();
		$.ajax({url: "<?php echo $this->config->item('ajax_base_url').$this->config->item('admin_directory_name').'/';?>transactions/update_vectra_status?id="+id+"&action_sts="+action_sts, 
			beforeSend: function(){ 
				$('#ch_sts_'+id).html('<i class="fa fa-spinner fa-spin"></i>');
				$('#csPopTxnId').html(txnId);
				$('#h_id').val(id);
			},
			success: function(result){ //alert(result);
				if(result!=''){
					$('#popup_update_sts_body').html(result);	
					jQuery("#update_status_modal").modal('show');
					$('#ch_sts_'+id).html('<i class="fa fa-pencil-square-o"></i>');
				}
			}
		});
	}
}
$(document).ready(function(){
	$('#updateStsFrm').validate({
		ignore: [], 
		highlight: function(element) {
			$(element).closest('.form-group').removeClass('has-success').addClass('has-error'); 
		},
		success: function(element) {
			element.closest('.form-group').removeClass('has-error').addClass('has-success');
			element.remove();
		},
		submitHandler: function(form){
			var site_base_url = $('#h_base_url').val();
			var form = $('#updateStsFrm');
			var url = site_base_url+form.attr('action');
			$.ajax({
				type: "POST",
				url: url,
				data: form.serialize(), // serializes the form's elements.
				beforeSend: function(){
					$('#updateBtn').html('Please Wait <i class="fa fa-spinner fa-spin"></i>');
				},
				success: function(result, status, xhr){//alert(result);
					if(result=='success'){
						window.location=site_base_url+'transactions/vectra';
					}else{
						$('#result_display').html('<div class="alert alert-danger">'+result+'</div>');
						$('#updateBtn').html('Update Now!');
					}
				},
				error: function(xhr, status, error_desc){
					$('#result_display').html('<div class="alert alert-danger">'+error_desc+'</div>');
					$('#updateBtn').html('Update Now!');
				}
			});		
			return false;
		}
	});
});
</script>
<div class="modal fade" id="update_status_modal" tabindex="-1" role="dialog">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<form method="post" id="updateStsFrm" action="transactions/update_vectra_sts_entry">
				<input type="hidden" id="h_base_url" name="h_base_url" value="<?php echo base_url().$this->config->item('admin_directory_name').'/';?>" />
				<input type="hidden" id="h_id" name="h_id" value="0" />
				<div class="modal-header">
					<h4 class="modal-title" style="display: inline-block;">Change Status for <span id="csPopTxnId"></span></h4>
					<button type="button" class="close" data-dismiss="modal">&times;</button>
				  </div>
				<div class="modal-body" id="popup_update_sts_body"></div>
				<div class="modal-footer">
					<button type="submit" id="updateBtn" class="btn btn-primary">Update Now!</button>
				</div>
			</form>
		</div>
	</div>
</div>
<div class="clearfix"></div>
</section>
