Create scripts.js
Browse files- scripts.js +100 -0
scripts.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
let currentAction = '';
|
| 2 |
+
|
| 3 |
+
function enterApp() {
|
| 4 |
+
document.getElementById('splash').style.display = 'none';
|
| 5 |
+
document.getElementById('dashboard').style.display = 'block';
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
function showModal(action) {
|
| 9 |
+
currentAction = action;
|
| 10 |
+
document.getElementById('modal').style.display = 'flex';
|
| 11 |
+
document.getElementById('modalTitle').innerText =
|
| 12 |
+
action === 'pay' ? 'Send Payment' :
|
| 13 |
+
action === 'add' ? 'Add Cash' : 'Cash Out';
|
| 14 |
+
document.getElementById('input1').value = '';
|
| 15 |
+
document.getElementById('input2').value = '';
|
| 16 |
+
document.getElementById('input2').style.display = action === 'pay' ? 'block' : 'none';
|
| 17 |
+
document.getElementById('bankSelect').style.display = action === 'pay' ? 'none' : 'block';
|
| 18 |
+
document.getElementById('paymentStatus').style.display = action === 'pay' ? 'block' : 'none';
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
function closeModal() {
|
| 22 |
+
document.getElementById('modal').style.display = 'none';
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
function performAction() {
|
| 26 |
+
let amount = parseFloat(document.getElementById('input1').value);
|
| 27 |
+
let balance = parseFloat(document.getElementById('balance').innerText.replace('$','').replace(',',''));
|
| 28 |
+
let receiver = document.getElementById('input2').value;
|
| 29 |
+
let selectedBank = document.getElementById('bankSelect').value;
|
| 30 |
+
let status = document.getElementById('paymentStatus').value;
|
| 31 |
+
|
| 32 |
+
if (isNaN(amount) || amount <= 0) {
|
| 33 |
+
alert("Enter a valid amount.");
|
| 34 |
+
return;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
if ((currentAction === 'add' || currentAction === 'cashout') && !selectedBank) {
|
| 38 |
+
alert("Please select a bank.");
|
| 39 |
+
return;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
if (currentAction === 'add') {
|
| 43 |
+
balance += amount;
|
| 44 |
+
showReceipt(selectedBank, 'Bank', amount, 'Funds Added', 'Just now');
|
| 45 |
+
} else if (currentAction === 'cashout') {
|
| 46 |
+
if (amount <= balance) {
|
| 47 |
+
balance -= amount;
|
| 48 |
+
showReceipt(selectedBank, 'Bank', amount, 'Cash Out', 'Just now');
|
| 49 |
+
} else {
|
| 50 |
+
alert("Insufficient funds!");
|
| 51 |
+
return;
|
| 52 |
+
}
|
| 53 |
+
} else if (currentAction === 'pay') {
|
| 54 |
+
if (amount <= balance && receiver) {
|
| 55 |
+
if (status !== 'Rejected') balance -= amount;
|
| 56 |
+
const history = document.getElementById('history');
|
| 57 |
+
history.innerHTML += `
|
| 58 |
+
<div class="history-item" onclick="showReceipt('${receiver}', 'You', ${amount}, '${status}', 'Just now')">
|
| 59 |
+
Payment to ${receiver} — $${amount} (${status})
|
| 60 |
+
</div>`;
|
| 61 |
+
showReceipt(receiver, 'You', amount, status, 'Just now');
|
| 62 |
+
} else {
|
| 63 |
+
alert("Enter valid amount and receiver.");
|
| 64 |
+
return;
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
document.getElementById('balance').innerText = '$' + balance.toFixed(2);
|
| 69 |
+
closeModal();
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
function showReceipt(to, from, amount, status, time) {
|
| 73 |
+
document.querySelector('.receipt-content h2').innerText = to;
|
| 74 |
+
document.querySelector('.receipt-content p').innerHTML = `${status} with <strong>${to}</strong>`;
|
| 75 |
+
document.getElementById('receiptAmount').innerText = '$' + amount;
|
| 76 |
+
document.getElementById('receiptTime').innerText = time;
|
| 77 |
+
|
| 78 |
+
let checkEl = document.querySelector('.check');
|
| 79 |
+
if (status === 'Successful') {
|
| 80 |
+
checkEl.innerText = '✔️ Received';
|
| 81 |
+
checkEl.style.color = 'green';
|
| 82 |
+
} else if (status === 'Pending') {
|
| 83 |
+
checkEl.innerText = '⏳ Pending';
|
| 84 |
+
checkEl.style.color = 'orange';
|
| 85 |
+
} else {
|
| 86 |
+
checkEl.innerText = '❌ Rejected';
|
| 87 |
+
checkEl.style.color = 'red';
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
document.querySelector('.receipt-details').innerHTML = `
|
| 91 |
+
<p>Type: <span>${status}</span></p>
|
| 92 |
+
<p>Amount: <span>$${amount}</span></p>
|
| 93 |
+
<p>To: <span>${to}</span></p>
|
| 94 |
+
<p>From: <span>${from}</span></p>`;
|
| 95 |
+
document.getElementById('receipt').style.display = 'flex';
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
function closeReceipt() {
|
| 99 |
+
document.getElementById('receipt').style.display = 'none';
|
| 100 |
+
}
|