Skip to content

Commit 6319618

Browse files
committed
Finance Tracker
1 parent 7b05683 commit 6319618

4 files changed

Lines changed: 431 additions & 0 deletions

File tree

Projects/Finance Tracker/Readme.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# NAME AND INTRODUCTION OF THE PROJECT :
2+
## Finance Tracker-
3+
Its a basic Finance Tracker Website in JavaScript,Html,Css.
4+
User interface: We will use HTML and CSS to design and style the user interface for our Finance Tracker.
5+
6+
Input forms: We will use HTML forms to allow users to input their income and expenses.
7+
8+
Local storage: We will use a browser’s local storage to store the user’s budget data.
9+
10+
Calculation logic: We will use JavaScript to calculate the user’s total income, expenses, and budget balance.
11+
By adding these essential components, we will be able to create a functional Finance tracker that allows users to easily input, store, and view their Finance data. We will now go through the process of implementing each of these features in our Finance tracker application.
12+
13+
# TECH STACK :
14+
I have used HTML , CSS and Vanilla Javascript to build this Finance Tracker.
15+
16+
# SNAPSHOT OF THE WEBSITE:
17+
https://user-images.githubusercontent.com/67870234/246890899-eec73e8d-3e50-495d-a654-86907dbfd55b.png
18+
19+
https://user-images.githubusercontent.com/67870234/246890960-5a12aabc-71e0-4d45-9676-e0599c02e4b0.png
20+
21+
# CONTRIBUTED BY:
22+
Amrit Chattopadhyay
23+
24+
Give it a try .Hope it helps !!!!
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link rel="stylesheet" href="styles.css">
8+
9+
10+
<title>Personal Finance Tracker</title>
11+
</head>
12+
13+
14+
<body>
15+
<header>
16+
<img class="logo" src="https://i.pinimg.com/564x/61/ea/07/61ea07e06fa139ef7e4609c95f0ae8ed.jpg">
17+
<h1>Personal Finance Tracker</h1>
18+
<p id="currentDateTime"></p>
19+
</header>
20+
21+
<main>
22+
<nav id="balanceSection">
23+
<div class="balance">
24+
<h2>Your Balance:</h2>
25+
<div id="balanceAmount">0.00</div>
26+
</div>
27+
<div class="balance">
28+
<h2>Income:</h2>
29+
<div id="incomeAmount">0.00</div>
30+
</div>
31+
<div class="balance">
32+
<h2>Expense:</h2>
33+
<div id="expenseAmount">0.00</div>
34+
</div>
35+
</nav>
36+
37+
<section id="transactionSection">
38+
<h2>Add Transaction</h2>
39+
<form id="transactionForm">
40+
<div>
41+
<label for="descriptionInput">Description:</label>
42+
<input type="text" id="descriptionInput" placeholder="Enter description" required>
43+
</div>
44+
<div>
45+
<label for="amountInput">Amount:</label>
46+
<input type="number" id="amountInput" placeholder="Enter amount" required>
47+
</div>
48+
<div>
49+
<label for="typeSelect">Type:</label>
50+
<select id="typeSelect">
51+
<option value="income">Income</option>
52+
<option value="expense">Expense</option>
53+
</select>
54+
</div>
55+
<button type="submit">Add Transaction</button>
56+
</form>
57+
</section>
58+
59+
<section id="transactionListSection">
60+
<h2>Transaction History</h2>
61+
<ul id="transactionList"></ul>
62+
<p id="noTransactionMessage">No transactions yet.</p>
63+
</section>
64+
<section id="bottom"></section>
65+
66+
</main>
67+
68+
<script src="index.js"></script>
69+
70+
</body>
71+
72+
</html>

Projects/Finance Tracker/index.js

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
// let transactions = JSON.parse(localStorage.getItem("transactions")) || [];
2+
// let transactions = [];
3+
const balanceAmount = document.getElementById("balanceAmount");
4+
const incomeAmount = document.getElementById("incomeAmount");
5+
const expenseAmount = document.getElementById("expenseAmount");
6+
const transactionForm = document.getElementById("transactionForm");
7+
const descriptionInput = document.getElementById("descriptionInput");
8+
const amountInput = document.getElementById("amountInput");
9+
const typeSelect = document.getElementById("typeSelect");
10+
const transactionList = document.getElementById("transactionList");
11+
const noTransactionMessage = document.getElementById("noTransactionMessage");
12+
let transactions = [];
13+
let incomes=0;
14+
let expenses=0;
15+
let totalIncome = 0;
16+
let totalExpense = 0;
17+
// Check if transactions data exists in Local Storage
18+
if (localStorage.getItem("transactions")) {
19+
transactions = JSON.parse(localStorage.getItem("transactions"));
20+
}
21+
22+
// Function to update balance
23+
24+
function updateBalance() {
25+
const balance = transactions.reduce((acc, transaction) => {
26+
return transaction.type === "income" ? acc + transaction.amount : acc - transaction.amount;
27+
}, 0);
28+
29+
totalIncome = transactions.reduce((acc, transaction) => {
30+
return transaction.type === "income" ? acc + transaction.amount : acc;
31+
}, 0);
32+
33+
totalExpense = transactions.reduce((acc, transaction) => {
34+
return transaction.type === "expense" ? acc + transaction.amount : acc;
35+
}, 0);
36+
37+
balanceAmount.textContent = balance.toFixed(2);
38+
incomeAmount.textContent = totalIncome.toFixed(2);
39+
expenseAmount.textContent = totalExpense.toFixed(2);
40+
41+
}
42+
43+
// Function to add a transaction
44+
function addTransaction(event) {
45+
event.preventDefault();
46+
47+
const description = descriptionInput.value;
48+
const amount = +amountInput.value;
49+
const type = typeSelect.value;
50+
51+
const transaction = {
52+
description,
53+
amount,
54+
type
55+
};
56+
57+
58+
transactions.push(transaction);
59+
if(type==="income"){
60+
totalIncome+=amount;
61+
}
62+
else if(type==="expense"){
63+
totalExpense+=amount;
64+
}
65+
updateTransactions();
66+
updateBalance();
67+
saveTransactions();
68+
alert(`Transaction "${transaction.description}" added successfully!`);
69+
70+
descriptionInput.value = "";
71+
amountInput.value = "";
72+
typeSelect.value = "income";
73+
}
74+
75+
// Function to delete a transaction
76+
function deleteTransaction(index) {
77+
const deletedTransaction = transactions.splice(index, 1);
78+
if (deletedTransaction.type === "income") {
79+
totalIncome -= deletedTransaction.amount;
80+
} else if (deletedTransaction.type === "expense") {
81+
totalExpense -= deletedTransaction.amount;
82+
}
83+
alert(`Transaction deleted successfully!`);
84+
updateTransactions();
85+
updateBalance();
86+
saveTransactions();
87+
88+
}
89+
90+
// Function to save transactions to Local Storage
91+
function saveTransactions() {
92+
localStorage.setItem("transactions", JSON.stringify(transactions));
93+
}
94+
95+
// Function to load transactions from Local Storage
96+
function loadTransactions() {
97+
const storedTransactions = localStorage.getItem("transactions");
98+
if (storedTransactions) {
99+
transactions = JSON.parse(storedTransactions);
100+
updateTransactions();
101+
updateBalance();
102+
}
103+
}
104+
105+
// Function to update the transaction list
106+
function updateTransactions() {
107+
transactionList.innerHTML = "";
108+
109+
if (transactions.length === 0) {
110+
noTransactionMessage.style.display = "block";
111+
} else {
112+
noTransactionMessage.style.display = "none";
113+
114+
transactions.forEach((transaction, index) => {
115+
const listItem = document.createElement("li");
116+
listItem.innerHTML = `
117+
<span>${transaction.description}</span>
118+
<span class="amount ${transaction.type}">${transaction.type === "income" ? "+" : "-"}${transaction.amount.toFixed(2)}</span>
119+
<div class="transaction-actions">
120+
<button onclick="editTransaction(${index})">Edit</button>
121+
<button onclick="deleteTransaction(${index})">Delete</button>
122+
</div>
123+
`;
124+
transactionList.appendChild(listItem);
125+
});
126+
}
127+
}
128+
// Function to edit a transaction
129+
function editTransaction(index) {
130+
const transaction = transactions[index];
131+
const updatedDescription = prompt("Enter the updated description:", transaction.description);
132+
const updatedAmount = parseFloat(prompt("Enter the updated amount:", transaction.amount));
133+
const updatedType = prompt("Enter the updated type (income or expense):", transaction.type);
134+
135+
if (updatedDescription && !isNaN(updatedAmount) && (updatedType === "income" || updatedType === "expense")) {
136+
const updatedTransaction = {
137+
description: updatedDescription,
138+
amount: updatedAmount,
139+
type: updatedType
140+
};
141+
142+
if (transaction.type === "income") {
143+
totalIncome -= transaction.amount;
144+
totalIncome += updatedAmount;
145+
} else if (transaction.type === "expense") {
146+
totalExpense -= transaction.amount;
147+
totalExpense += updatedAmount;
148+
}
149+
150+
transactions[index] = updatedTransaction;
151+
alert(`Transaction "${updatedTransaction.description}" updated successfully!`);
152+
updateTransactions();
153+
updateBalance();
154+
saveTransactions();
155+
156+
} else {
157+
alert("Invalid input! Please try again.");
158+
}
159+
}
160+
161+
// Event listener for adding a transaction
162+
transactionForm.addEventListener("submit", addTransaction);
163+
function updateDateTime() {
164+
const currentDateTime = new Date();
165+
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric' };
166+
const formattedDateTime = currentDateTime.toLocaleDateString('en-US', options);
167+
document.getElementById('currentDateTime').textContent = formattedDateTime;
168+
}
169+
170+
// Update the date and time every second
171+
setInterval(updateDateTime, 1000);
172+
173+
// Initial update
174+
updateDateTime();
175+
176+
177+
// Load transactions on page load
178+
loadTransactions();

0 commit comments

Comments
 (0)