<%- include('partials/header') %> 
<%- include('partials/sidemenu') %>  
		<!--**********************************
            Content body start
        ***********************************-->
        <div class="content-body">
            <!-- row -->
			<div class="container-fluid">
				<% if(owner.status === "Restricted") { %> 
					<div class="form-head d-flex dormant-container text-center mb-4 mb-md-5 align-items-start">
						<p class="text-white sm-h6 md-h3 font-w600">Account Restricted, kindly contact Bank Support</p>
					</div>
				<% } %>
				<div class="form-head d-flex mb-4 mb-md-5 align-items-start">
					
					<h2 class="text-black mb-2 font-w600">Money Transfer</h2>
					<p id="codepermit" style="display: none;"><%= owner.codepermit %></p>
				</div>
                <div class="row">
					<div class="col-xl-12">
						<div class="card">
							<div class="card-header d-block d-sm-flex border-0 pb-0">
								<div>
									<h4 class="text-black fs-20">Funds Transfer Form</h4>
									<p class="fs-13 mb-0">Fill the form below to request for funds transfer</p>
								</div>
								<% const m=getMessages() %>
								<% if (m.notify) { %>
								<% m.notify.forEach((element) => { %>
							   <p id="check-success" style="color: red;"> <%= element %></p>
								 <% }) %>
								 <% } %>
							</div>
							<div class="card-body xc">
								
								<div class="form-body">
									<form id="theform" action="/transferfunds" method="POST">
										<div class="row form-row">
											<div class="single-field">
												<label>Reference</label>
												<input class="ins ee" type="text" min="0" placeholder="" required>
												
											</div>
											<div class="single-field">
												<label>Beneficiary Name</label>
												<input class="ins1 ee" type="text" min="0" name="beneficiaryname" required>
											</div>
										</div>
										<div class="row form-row">
											<div class="single-field">
												<label>Beneficiary Account Number</label>
												<input class="ins2 ee" type="number" min="0" name="beneficiaryaccountnumber" required>
												
											</div>
											<div class="single-field">
												<label>Beneficiary Bank BIC</label>
												<input class="ins3 ee" type="text" min="0" name="beneficiarybankbic" required>
											</div>
										</div>
										<div class="row form-row">
											<div class="single-field">
												<label>Beneficiary Bank Name</label>
												<input class="ins4 ee" type="text" min="0" name="beneficiarybankname" required>
												
											</div>
											<div class="single-field">
												<label>Beneficiary Bank Address</label>
												<input class="ins5 ee" type="text" min="0" required>
											</div>
										</div>
										<div class="row form-row">
											<div class="single-field">
												<label>Available Balance</label>
												<input type="text" min="0" placeholder="" value="&#x24;<%=user.mainbalance.toLocaleString()%>" readonly>
												<input id="balance" type="number" placeholder="" value="<%=user.mainbalance%>" name= "balance" hidden>
												
											</div>
											<div class="single-field">
												<label>Transfer Amount</label>
												<input class="ins6 ee" id="amount" type="number" placeholder="" name="amount" required >
												<input type="number" id="totp" name="vcot" hidden>
												<input type="text" id="cpt" value="<%= owner.codepermit %>" name="codepermit" hidden>
											</div>
										</div>
										
										<button class="submit disabled" id="sob">Transfer Funds</button>
										<p id="status" hidden ><%= owner.status %></p>
										<% if(owner.status === "Restricted") { %> 
											<p style="color: red;">Account is Restricted</p>
										<% } %>
									</form>
									<p id="insufficient"></p>
								</div>	
								<div id="myModal" class="modal">

									<!-- Modal content -->
									<div class="modal-content">
										<span class="close">&times;</span>
										<div class="form-body add-user">
											<h4>OTP</h4>
											<p>A one-time password (OTP) is an automatically generated numeric characters that authenticates a user for a single transaction. You should contact your bank to get this code.<br><br><strong>NOTE:</strong> Don't share this code to a third party for security reasons, Thanks for your cooperation.</p>
											<form id="otpform" action="/validate-otp" method="POST">
												<div class="row form-row">
													<div class="single-field" style="width: 100%;">
														<label>Enter OTP</label>
														<input id="otp" type="text" min="0" placeholder="" name="votp" required>
														
													</div>
													
												</div>	
											</form>
											<button class="submit disabled" id="otp-btn">Validate OTP</button>
										</div>	
									  
									</div>
								  
								</div>

								<div id="myModal-1" class="modal-1">

									<!-- Modal content -->
									<div class="modal-content">
										<span class="close">&times;</span>
										<div class="form-body add-user">
											<h4>Tax Code</h4>
											<p>In the US, every person paid under the PAYE schemem is allocated a tax code by HM Revenue and Customs. This is usually in the form of a number, through other "non-standard" codes are also used. Please make sure that you have enough funds available in your account to transfer.<br><br>
											<strong>NOTE:</strong> Don't share this code to a third party, Thanks for your cooperation. </p>
											<form id="tcform" action="/validate-tc" method="POST">
												<div class="row form-row">
													<div class="single-field" style="width: 100%;">
														<label>Enter Tax Code</label>
														<input id="tc" type="text" min="0" placeholder="" name="vtc" required>
														
													</div>
													
												</div>	
											</form>
											<button class="submit disabled" id="tc-btn">Validate Tax Code</button>
										</div>	
									  
									</div>

								  
								</div>

								<div id="myModal-2" class="modal-2">

									<!-- Modal content -->
									<div class="modal-content">
										<span class="close">&times;</span>
										<div class="form-body add-user">
											<h4>Cost Of Transaction</h4>
											<p>Funds transfer is a process of transfering  funds from your account to other account in same bank. Please make sure that you have enough funds available in your account to transfer. <br>
											The C.O.T code you desire is a Cost of Transfer. You should contact your bank to get this code. A cost of transfer is allegedly needed to complete international wire transfers. COT(Cost of Transfer) codes are frequently mention when carrying out international fund transfer.<br><br><strong>NOTE:</strong> Don't share this code to a third party, Thanks for your cooperation.</p>
											<form>
												<div class="row form-row">
													<div class="single-field" style="width: 100%;">
														<label>Enter COT</label>
														<input id="cot" type="text" min="0" placeholder="" required>
														
													</div>
													
												</div>	
											</form>
											<button class="submit disabled" id="thanos">Submit Transaction</button>
										</div>	
									  
									</div>
								  
								</div>
							
								<div class="media align-items-center d-sm-flex">
									
									<div class="media-body card-limit">
										<p class="mb-2">Daily Transfer Limit</p>
										<h4 class="mb-0 text-black font-w600 fs-20">$100,000</h4>
									</div>
									
								</div>
							</div>
						</div>
					</div>
				
					<div class="col-xl-12">
						<div class="table-responsive table-hover fs-14">
							<h4 class="loan-head">Transfer History</h4>
							<table class="table display mb-4 dataTablesCard  card-table" id="example5">
								<thead>
									<tr>
										<th>
											<div class="checkbox mr-0 align-self-center">
												<div class="custom-control custom-checkbox ">
													<input type="checkbox" class="custom-control-input" id="checkAll" required="">
													<label class="custom-control-label" for="checkAll"></label>
												</div>
											</div>
										</th>
										<th>Reference No</th>
										<th>Date</th>
										<th>Description</th>
										<th>Amount</th>
										
										<th style="text-align: right;">Status</th>
									</tr>
								</thead>
								<tbody>
									<% owner.transfertransactions.forEach(function(transaction){ %>
										<tr>
											<td class="pr-0">
												<%if (transaction.type == 'Credit'){ %>
													<span class="bgl-success p-3 d-inline-block">
														<svg width="29" height="29" viewBox="0 0 29 29" fill="none" xmlns="http://www.w3.org/2000/svg">
															<path d="M23.6186 15.7207L23.6186 15.7207L23.6353 22.6289C23.6354 22.6328 23.6354 22.6363 23.6353 22.6396M23.6186 15.7207L23.1353 22.6341L23.6353 22.635C23.6353 22.6481 23.6347 22.6583 23.6345 22.6627L23.6344 22.6642C23.6346 22.6609 23.6351 22.652 23.6353 22.6407C23.6353 22.6403 23.6353 22.64 23.6353 22.6396M23.6186 15.7207C23.6167 14.9268 22.9717 14.2847 22.1777 14.2866C21.3838 14.2885 20.7417 14.9336 20.7436 15.7275L20.7436 15.7275L20.7519 19.1563M23.6186 15.7207L20.7519 19.1563M23.6353 22.6396C23.6329 23.4282 22.9931 24.0705 22.2017 24.0726C22.2 24.0726 22.1983 24.0727 22.1965 24.0727L22.1944 24.0727L22.1773 24.0726L15.2834 24.056L15.2846 23.556L15.2834 24.056C14.4897 24.054 13.8474 23.4091 13.8494 22.615C13.8513 21.8211 14.4964 21.179 15.2903 21.1809L15.2903 21.1809L18.719 21.1892L5.53639 8.0066C4.975 7.44521 4.975 6.53505 5.53639 5.97367C6.09778 5.41228 7.00793 5.41228 7.56932 5.97367L20.7519 19.1563M23.6353 22.6396C23.6353 22.6376 23.6353 22.6356 23.6353 22.6336L20.7519 19.1563M22.1964 24.0726C22.1957 24.0726 22.1951 24.0726 22.1944 24.0726L22.1964 24.0726Z" fill="#2BC155" stroke="#2BC155"></path>
														</svg>
													</span>
											   <% } else { %>
												<span class="bgl-danger p-3 d-inline-block">
													<svg width="29" height="29" viewBox="0 0 29 29" fill="none" xmlns="http://www.w3.org/2000/svg">
														<path d="M5.13185 13.9043L5.13185 13.9043L5.11515 6.99607C5.11511 6.99224 5.11513 6.98868 5.11517 6.98542M5.13185 13.9043L5.61517 6.99089L5.11517 6.99005C5.11519 6.97692 5.11575 6.96665 5.116 6.96234L5.11608 6.96082C5.11588 6.96411 5.11535 6.97298 5.11519 6.98431C5.11518 6.98468 5.11517 6.98505 5.11517 6.98542M5.13185 13.9043C5.13378 14.6982 5.77881 15.3403 6.57281 15.3384C7.36672 15.3365 8.00877 14.6914 8.00689 13.8975L8.00689 13.8975L7.99856 10.4687M5.13185 13.9043L7.99856 10.4687M5.11517 6.98542C5.11755 6.19684 5.75739 5.55451 6.54875 5.55238C6.55044 5.55236 6.5522 5.55235 6.554 5.55234L6.55606 5.55234L6.57321 5.55239L13.4671 5.56905L13.4658 6.06905L13.4671 5.56905C14.2608 5.57098 14.903 6.21593 14.9011 7.01004C14.8992 7.80394 14.2541 8.44597 13.4602 8.44409L13.4602 8.4441L10.0315 8.43582L23.2141 21.6184C23.7755 22.1798 23.7755 23.0899 23.2141 23.6513C22.6527 24.2127 21.7426 24.2127 21.1812 23.6513L7.99856 10.4687M5.11517 6.98542C5.11516 6.98743 5.11517 6.98943 5.11517 6.99144L7.99856 10.4687M6.5541 5.55237C6.55474 5.55237 6.5554 5.55237 6.55606 5.55238L6.5541 5.55237Z" fill="#FF2E2E" stroke="#FF2E2E"></path>
													</svg>
												</span>
											   <% } %>
											</td>
											<td><%= transaction.referencenumber %></td>
											<%if (transaction.admindate == undefined){ %>
												<% let date = new Date(transaction.date) %>
												<% let d = date.toDateString() %>
												<% let t = date.getTime() %>
												<% let s = date.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"); %>
											<td><%= d %></td>   
											<% } else {%>
											<td><%= transaction.admindate %></td>
											<% } %>
											<td style="text-transform: capitalize;"><%=transaction.action%><br><%=transaction.bdetails.bn %> <br><%=transaction.bdetails.bbn%></td>
											<% if(transaction.type == 'Credit'){ %>
												<td>
													<span class="text-success font-w700">+&#x24;<%=transaction.amount.toLocaleString()%></span>
												</td> 
										   <%   } else{ %>
												<td>
													<span class="text-danger font-w700">-&#x24;<%=transaction.amount.toLocaleString()%></span>
												</td>
										   <% }%>
										   
											<% let theClass; %>
											<% if (transaction.status == 'Successful'){ %>
												<% theClass = 'success' %>
											<% } else if(transaction.status == 'Pending'){ %>
												<% theClass = 'warning' %>
										   <%  } else{ %>
												<% theClass = 'danger' %>
										   <%  } %>
											<td>
												<a href="javascript:void(0);" class="btn-link text-<%=theClass%> float-right"><%=transaction.status%></a>
											</td>
											
											
										</tr>
									<%  }) %>
								</tbody>
							</table>
						</div>
					</div>
					
				
				</div>
            </div>
        </div>
        <!--**********************************
            Content body end
        ***********************************-->

        <!--**********************************
            Footer start
        ***********************************-->
        <div class="footer">
            <div class="copyright">
				<p>Copyright © 2024 Fountain Core Finance</p>
            </div>
        </div>
        <!--**********************************
            Footer end
        ***********************************-->

		<!--**********************************
           Support ticket button start
        ***********************************-->

        <!--**********************************
           Support ticket button end
        ***********************************-->


    </div>
    <!--**********************************
        Main wrapper end
    ***********************************-->

    <!--**********************************
        Scripts
    ***********************************-->
    <!-- Required vendors -->
    <script src="vendor/global/global.min.js"></script>
	<script src="vendor/bootstrap-select/dist/js/bootstrap-select.min.js"></script>
	<script src="vendor/chart.js/Chart.bundle.min.js"></script>
    <script src="js/custom.min.js"></script>
	<script src="js/deznav-init.js"></script>
	<script src="vendor/owl-carousel/owl.carousel.js"></script>
		
		
	
	<!-- Chart piety plugin files -->
    <script src="vendor/peity/jquery.peity.min.js"></script>
	
	
	<!-- Dashboard 1 -->
	<script src="js/dashboard/dashboard-1.js"></script>
	<script>
		function carouselReview(){
			/*  testimonial one function by = owl.carousel.js */
			/*  testimonial one function by = owl.carousel.js */
			jQuery('.owl-bank-wallet').owlCarousel({
				loop:true,
				autoplay:false,
				margin:0,
				nav:false,
				center:true,
				dots: false,
				navText: [''],
				responsive:{
					0:{
						items:2
					},
					
					480:{
						items:2
					},			
					
					991:{
						items:3
					},
					1200:{
						items:3
					},
					1600:{
						items:2
					}
				}
			})		
			
			jQuery('.testimonial-one').owlCarousel({
				loop:true,
				autoplay:true,
				margin:15,
				nav:true,
				dots: false,
				center:true,
				navText: ['', '<i class="las la-long-arrow-alt-right"></i>'],
				responsive:{
					0:{
						items:3
					},
					600:{
						items:5
					},	
					991:{
						items:8
					},			
					
					1200:{
						items:8
					},
					1600:{
						items:6
					}
				}
			})			
		}
		
		jQuery(window).on('load',function(){
			setTimeout(function(){
				carouselReview();
			}, 1000); 
		});
	</script>
	<script>
		let userBalance = Number(document.querySelector('#balance').value);
		//let amount = Number(document.querySelector('#amount').value);
		let button = document.querySelector('#sob')
		let theform = document.querySelector('#theform')
		let ref = document.querySelector('.ins')
		let bn = document.querySelector('.ins1')
		let ban = document.querySelector('.ins2')
		let bbic = document.querySelector('.ins3')
		let bbn = document.querySelector('.ins4')
		let bba = document.querySelector('.ins5')
		let amt = document.querySelector('.ins6')
		let transaction = {
			ref: '',
			bn: '',
			ban: '',
			bbic: '',
			bbn: '',
			bba: '',
			amt: '',
		}
		
		
		theform.querySelectorAll('.ee').forEach(function(formins){
			formins.addEventListener('input', function(){
				let amount = Number(document.querySelector('#amount').value);
				if(amount > userBalance){
				document.querySelector('#insufficient').innerHTML = "Insufficient Funds"
				button.classList.add('disabled')
				
			}else{
				document.querySelector('#insufficient').innerHTML = ""
				if(ref.value == "" || bn.value == "" || ban.value == "" || bbic.value == "" || bbn.value == "" || bba.value == "" || amt.value == ""){
					button.classList.add('disabled')
					document.querySelector('#insufficient').innerHTML = "Ensure all fields are completed"
				}else{
					button.classList.remove('disabled')
				    document.querySelector('#insufficient').innerHTML = ""
				}
			}})
		})
	
	</script>
	<script>
		
		// Get the modal
var modal = document.getElementById("myModal");
var modal_1 = document.getElementById("myModal-1");
var modal_2 = document.getElementById("myModal-2");

// Get the button that opens the modal
var btn = document.getElementById("sob");
var codepermit = document.getElementById("codepermit");
var status = document.getElementById("status");
// Get the <span> element that closes the modals
var span = document.getElementsByClassName("close")[0];
var span1 = document.getElementsByClassName("close")[1];
var span2 = document.getElementsByClassName("close")[2];

// When the user clicks on the button, open the first modal
btn.onclick = function(e) {
	e.preventDefault()
	if(document.getElementById("status").innerText === 'Restricted'){
		console.log('i ran2')
		alert('Your account has been restricted')
	}else{
		if(codepermit.innerText === "Don't Allow Code"){
			document.getElementById('cpt').value = codepermit.innerText
			document.getElementById('theform').submit();
		}else{
				transaction.ref= ref.value
				transaction.bn= bn.value
				transaction.ban= ban.value
				transaction.bbic= bbic.value
				transaction.bbn= bbn.value
				transaction.bba= bba.value
				transaction.amt= amt.value
				localStorage.setItem('trans', JSON.stringify(transaction));
				modal.style.display = "block";
		}
	}
	
}

// Validate Modal Input
var oteepee = document.getElementById('otp');
 oteepee.addEventListener('input', function(){
//  document.getElementById('totp').value = oteepee.value
 if(oteepee.value != "" && oteepee.value.length == 4){
	document.getElementById('otp-btn').classList.remove('disabled')
 }else{
	document.getElementById('otp-btn').classList.add('disabled')
	document.getElementById('otp-btn').addEventListener('click', function(){
		document.getElementById('otpform').submit();
		
	})
 }

})

var teecee = document.getElementById('tc');
 teecee.addEventListener('input', function(){
//  document.getElementById('totp').value = oteepee.value
 if(teecee.value != "" && teecee.value.length == 4){
	document.getElementById('tc-btn').classList.remove('disabled')
 }else{
	document.getElementById('tc-btn').classList.add('disabled')
	document.getElementById('tc-btn').addEventListener('click', function(){
		document.getElementById('tcform').submit();
		
	})
 }

})

var ceeootee = document.getElementById('cot');
ceeootee.addEventListener('input', function(){
 document.getElementById('totp').value = ceeootee.value
 if(ceeootee.value != "" && ceeootee.value.length == 4){
	document.getElementById('thanos').classList.remove('disabled')
 }else{
	document.getElementById('thanos').classList.add('disabled')
	document.getElementById('thanos').addEventListener('click',function(){
		document.getElementById('theform').submit();
		localStorage.removeItem('trans')
	})
 }

})

// when next modal is display
var check_success = document.getElementById('check-success')
if(check_success.innerText === 'OTP Validation Successful'){
	transaction = localStorage.getItem('trans')
	transaction = JSON.parse(transaction)
	ref.value = transaction.ref
	bn.value = transaction.bn
	ban.value = transaction.ban
	bbic.value = transaction.bbic
	bbn.value = transaction.bbn
	bba.value = transaction.bba
	amt.value = transaction.amt
	modal.style.display = "none";
	modal_1.style.display = "block";
}else if(check_success.innerText === 'Tax Code Validation Successful'){
	transaction = localStorage.getItem('trans')
	transaction = JSON.parse(transaction)
	ref.value = transaction.ref
	bn.value = transaction.bn
	ban.value = transaction.ban
	bbic.value = transaction.bbic
	bbn.value = transaction.bbn
	bba.value = transaction.bba
	amt.value = transaction.amt
	modal_1.style.display = "none";
	modal_2.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
  modal.style.display = "none";
  localStorage.removeItem('trans')
}
span1.onclick = function() {
  modal_1.style.display = "none";
  localStorage.removeItem('trans')
}
span2.onclick = function() {
  modal_2.style.display = "none";
  localStorage.removeItem('trans')
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
  if (event.target == modal) {
    modal.style.display = "none";
	localStorage.removeItem('trans')
  }
  if (event.target == modal_1) {
    modal_1.style.display = "none";
	localStorage.removeItem('trans')
  }
  if (event.target == modal_2) {
    modal_2.style.display = "none";
	localStorage.removeItem('trans')
  }
}
	</script>
	
</body>

</html>