Skip to content

Commit 40c223a

Browse files
Merge pull request #1750 from AMRIT456/finance
Finance
2 parents 4f246c4 + db520b2 commit 40c223a

4 files changed

Lines changed: 509 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: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
<title>Personal Finance Tracker</title>
10+
</head>
11+
12+
13+
<body>
14+
<header>
15+
<img class="logo" src="https://i.pinimg.com/564x/61/ea/07/61ea07e06fa139ef7e4609c95f0ae8ed.jpg">
16+
<h1 class="hello-height">Personal Finance Tracker</h1>
17+
<p id="currentDateTime"></p>
18+
</header>
19+
20+
<main>
21+
<nav id="balanceSection">
22+
<div class="balance">
23+
<h2>Your Balance:</h2>
24+
<div id="balanceAmount">0.00</div>
25+
</div>
26+
<div class="balance">
27+
<h2>Income:</h2>
28+
<div id="incomeAmount">0.00</div>
29+
</div>
30+
<div class="balance">
31+
<h2>Expense:</h2>
32+
<div id="expenseAmount">0.00</div>
33+
</div>
34+
</nav>
35+
36+
<section id="transactionSection">
37+
<h2>Add Transaction</h2>
38+
<form id="transactionForm">
39+
<div>
40+
<label for="descriptionInput">Description:</label>
41+
<input type="text" id="descriptionInput" placeholder="Enter description" required>
42+
</div>
43+
<div>
44+
<label for="amountInput">Amount:</label>
45+
<input type="number" id="amountInput" placeholder="Enter amount" required>
46+
</div>
47+
<div>
48+
<label for="typeSelect">Type:</label>
49+
<select id="typeSelect">
50+
<option value="income">Income</option>
51+
<option value="expense">Expense</option>
52+
</select>
53+
</div>
54+
<button type="submit">Add Transaction</button>
55+
</form>
56+
</section>
57+
58+
<section id="transactionListSection">
59+
<h2>Transaction History</h2>
60+
<ul id="transactionList"></ul>
61+
<p id="noTransactionMessage">No transactions yet.</p>
62+
</section>
63+
<section id="bottom"></section>
64+
65+
</main>
66+
67+
<script src="index.js"></script>
68+
69+
</body>
70+
71+
</html>

Projects/Finance Tracker/index.js

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
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+
// Function to save transactions to Local Storage
90+
function saveTransactions() {
91+
localStorage.setItem("transactions", JSON.stringify(transactions));
92+
}
93+
94+
// Function to load transactions from Local Storage
95+
function loadTransactions() {
96+
const storedTransactions = localStorage.getItem("transactions");
97+
if (storedTransactions) {
98+
transactions = JSON.parse(storedTransactions);
99+
updateTransactions();
100+
updateBalance();
101+
}
102+
}
103+
104+
// Function to update the transaction list
105+
function updateTransactions() {
106+
transactionList.innerHTML = "";
107+
108+
if (transactions.length === 0) {
109+
noTransactionMessage.style.display = "block";
110+
} else {
111+
noTransactionMessage.style.display = "none";
112+
113+
transactions.forEach((transaction, index) => {
114+
const listItem = document.createElement("li");
115+
listItem.innerHTML = `
116+
<span>${transaction.description}</span>
117+
<span class="amount ${transaction.type}">${transaction.type === "income" ? "+" : "-"}${transaction.amount.toFixed(2)}</span>
118+
<div class="transaction-actions">
119+
<button onclick="editTransaction(${index})">Edit</button>
120+
<button onclick="deleteTransaction(${index})">Delete</button>
121+
</div>
122+
`;
123+
transactionList.appendChild(listItem);
124+
});
125+
}
126+
}
127+
// Function to edit a transaction
128+
function editTransaction(index) {
129+
const transaction = transactions[index];
130+
const updatedDescription = prompt("Enter the updated description:", transaction.description);
131+
const updatedAmount = parseFloat(prompt("Enter the updated amount:", transaction.amount));
132+
const updatedType = prompt("Enter the updated type (income or expense):", transaction.type);
133+
134+
if (updatedDescription && !isNaN(updatedAmount) && (updatedType === "income" || updatedType === "expense")) {
135+
const updatedTransaction = {
136+
description: updatedDescription,
137+
amount: updatedAmount,
138+
type: updatedType
139+
};
140+
if (transaction.type === "income") {
141+
totalIncome -= transaction.amount;
142+
totalIncome += updatedAmount;
143+
} else if (transaction.type === "expense") {
144+
totalExpense -= transaction.amount;
145+
totalExpense += updatedAmount;
146+
}
147+
transactions[index] = updatedTransaction;
148+
alert(`Transaction "${updatedTransaction.description}" updated successfully!`);
149+
updateTransactions();
150+
updateBalance();
151+
saveTransactions();
152+
} else {
153+
alert("Invalid input! Please try again.");
154+
}
155+
}
156+
157+
// Event listener for adding a transaction
158+
transactionForm.addEventListener("submit", addTransaction);
159+
function updateDateTime() {
160+
const currentDateTime = new Date();
161+
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric' };
162+
const formattedDateTime = currentDateTime.toLocaleDateString('en-US', options);
163+
document.getElementById('currentDateTime').textContent = formattedDateTime;
164+
}
165+
166+
// Update the date and time every second
167+
setInterval(updateDateTime, 1000);
168+
169+
// Initial update
170+
updateDateTime();
171+
172+
173+
// Load transactions on page load
174+
loadTransactions();

0 commit comments

Comments
 (0)