-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
129 lines (107 loc) · 4.9 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
document.addEventListener('DOMContentLoaded', () => {
const executiveForm = document.getElementById('executiveForm');
const executiveList = document.getElementById('executiveList');
const totalInflows = document.getElementById('totalInflows');
const totalOutflows = document.getElementById('totalOutflows');
const totalBalance = document.getElementById('totalBalance');
const transactionType = document.getElementById('transactionType');
const isTreasurerCheckbox = document.getElementById('isTreasurer');
const searchName = document.getElementById('searchName');
let transactions = JSON.parse(localStorage.getItem('transactions')) || [];
let editingIndex = -1;
function updateSummary() {
let inflows = 0;
let outflows = 0;
transactions.forEach(transaction => {
if (transaction.type === 'inflow') {
inflows += transaction.amount;
} else {
outflows += transaction.amount;
}
});
const balance = inflows - outflows;
totalInflows.textContent = inflows;
totalOutflows.textContent = outflows;
totalBalance.textContent = balance;
}
function displayTransactions(filterName = '') {
executiveList.innerHTML = '';
transactions.forEach((transaction, index) => {
if (transaction.name.toLowerCase().includes(filterName.toLowerCase())) {
const li = document.createElement('li');
li.innerHTML = `
<strong>${transaction.name}</strong> (${transaction.role} - ${transaction.email})<br>
${transaction.date} - ${transaction.type} - $${transaction.amount}<br>
Remarks: ${transaction.remarks}
<button class="edit" data-index="${index}">Edit</button>
<button class="delete" data-index="${index}">Delete</button>
`;
executiveList.appendChild(li);
}
});
}
function toggleTransactionTypeOptions() {
if (isTreasurerCheckbox.checked) {
transactionType.querySelector('option[value="outflow"]').disabled = false;
} else {
transactionType.querySelector('option[value="outflow"]').disabled = true;
transactionType.value = 'inflow';
}
}
isTreasurerCheckbox.addEventListener('change', () => {
toggleTransactionTypeOptions();
});
executiveForm.addEventListener('submit', (event) => {
event.preventDefault();
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const role = document.getElementById('role').value;
const amount = parseFloat(document.getElementById('amount').value);
const type = document.getElementById('transactionType').value;
const date = document.getElementById('date').value;
const remarks = document.getElementById('remarks').value;
const transaction = { name, email, role, amount, type, date, remarks };
if (editingIndex > -1) {
transactions[editingIndex] = transaction;
editingIndex = -1;
} else {
transactions.push(transaction);
}
localStorage.setItem('transactions', JSON.stringify(transactions));
displayTransactions();
updateSummary();
executiveForm.reset();
toggleTransactionTypeOptions(); // Reset transaction type options after form submission
});
executiveList.addEventListener('click', (event) => {
const target = event.target;
const index = target.getAttribute('data-index');
if (target.classList.contains('edit')) {
const transaction = transactions[index];
document.getElementById('name').value = transaction.name;
document.getElementById('email').value = transaction.email;
document.getElementById('role').value = transaction.role;
document.getElementById('amount').value = transaction.amount;
document.getElementById('transactionType').value = transaction.type;
document.getElementById('date').value = transaction.date;
document.getElementById('remarks').value = transaction.remarks;
isTreasurerCheckbox.checked = transaction.type === 'outflow';
toggleTransactionTypeOptions();
editingIndex = index;
}
if (target.classList.contains('delete')) {
transactions.splice(index, 1);
localStorage.setItem('transactions', JSON.stringify(transactions));
displayTransactions();
updateSummary();
}
});
searchName.addEventListener('input', () => {
const filterName = searchName.value;
displayTransactions(filterName);
});
// Initialize
displayTransactions();
updateSummary();
toggleTransactionTypeOptions();
});