Spaces:
Running
Running
undefined - Initial Deployment
Browse files- README.md +7 -5
- index.html +516 -19
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: tracking-page
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: yellow
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,516 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Advanced Expense Tracker</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 9 |
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 10 |
+
<style>
|
| 11 |
+
.fade-in {
|
| 12 |
+
animation: fadeIn 0.3s ease-in-out;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
@keyframes fadeIn {
|
| 16 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 17 |
+
to { opacity: 1; transform: translateY(0); }
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
.shake {
|
| 21 |
+
animation: shake 0.5s ease-in-out;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
@keyframes shake {
|
| 25 |
+
0%, 100% { transform: translateX(0); }
|
| 26 |
+
20%, 60% { transform: translateX(-5px); }
|
| 27 |
+
40%, 80% { transform: translateX(5px); }
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.chart-container {
|
| 31 |
+
position: relative;
|
| 32 |
+
height: 300px;
|
| 33 |
+
width: 100%;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
@media (max-width: 640px) {
|
| 37 |
+
.chart-container {
|
| 38 |
+
height: 250px;
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
</style>
|
| 42 |
+
</head>
|
| 43 |
+
<body class="bg-gray-50 min-h-screen">
|
| 44 |
+
<div class="container mx-auto px-4 py-8">
|
| 45 |
+
<!-- Header -->
|
| 46 |
+
<header class="mb-8 text-center">
|
| 47 |
+
<h1 class="text-3xl md:text-4xl font-bold text-indigo-700 mb-2">Expense Tracker</h1>
|
| 48 |
+
<p class="text-gray-600">Track your spending and stay within budget</p>
|
| 49 |
+
</header>
|
| 50 |
+
|
| 51 |
+
<!-- Budget Display and Edit -->
|
| 52 |
+
<div class="bg-white rounded-lg shadow-md p-6 mb-6">
|
| 53 |
+
<div class="flex flex-col md:flex-row md:items-center md:justify-between">
|
| 54 |
+
<div class="mb-4 md:mb-0">
|
| 55 |
+
<h2 class="text-xl font-semibold text-gray-800">Monthly Budget</h2>
|
| 56 |
+
<div id="budget-display" class="text-2xl font-bold text-indigo-600 mt-1"></div>
|
| 57 |
+
</div>
|
| 58 |
+
<button id="edit-budget-btn" class="bg-indigo-100 text-indigo-700 px-4 py-2 rounded-lg hover:bg-indigo-200 transition flex items-center">
|
| 59 |
+
<i class="fas fa-edit mr-2"></i> Edit Budget
|
| 60 |
+
</button>
|
| 61 |
+
</div>
|
| 62 |
+
|
| 63 |
+
<!-- Budget Edit Form (Hidden by default) -->
|
| 64 |
+
<div id="budget-edit-form" class="hidden mt-4 fade-in">
|
| 65 |
+
<div class="flex flex-col md:flex-row gap-4">
|
| 66 |
+
<input type="number" id="new-budget" placeholder="Enter new budget" class="flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
|
| 67 |
+
<button id="save-budget-btn" class="bg-indigo-600 text-white px-4 py-2 rounded-lg hover:bg-indigo-700 transition">Save</button>
|
| 68 |
+
<button id="cancel-budget-btn" class="bg-gray-200 text-gray-700 px-4 py-2 rounded-lg hover:bg-gray-300 transition">Cancel</button>
|
| 69 |
+
</div>
|
| 70 |
+
</div>
|
| 71 |
+
</div>
|
| 72 |
+
|
| 73 |
+
<!-- Summary Cards -->
|
| 74 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
|
| 75 |
+
<div class="bg-white rounded-lg shadow-md p-4">
|
| 76 |
+
<div class="flex items-center justify-between">
|
| 77 |
+
<div>
|
| 78 |
+
<p class="text-gray-600">Total Spent</p>
|
| 79 |
+
<p id="total-spent" class="text-2xl font-bold text-gray-800">$0</p>
|
| 80 |
+
</div>
|
| 81 |
+
<div class="bg-indigo-100 p-3 rounded-full">
|
| 82 |
+
<i class="fas fa-wallet text-indigo-600"></i>
|
| 83 |
+
</div>
|
| 84 |
+
</div>
|
| 85 |
+
</div>
|
| 86 |
+
|
| 87 |
+
<div class="bg-white rounded-lg shadow-md p-4">
|
| 88 |
+
<div class="flex items-center justify-between">
|
| 89 |
+
<div>
|
| 90 |
+
<p class="text-gray-600">Remaining</p>
|
| 91 |
+
<p id="remaining-budget" class="text-2xl font-bold text-green-600">$0</p>
|
| 92 |
+
</div>
|
| 93 |
+
<div class="bg-green-100 p-3 rounded-full">
|
| 94 |
+
<i class="fas fa-piggy-bank text-green-600"></i>
|
| 95 |
+
</div>
|
| 96 |
+
</div>
|
| 97 |
+
</div>
|
| 98 |
+
|
| 99 |
+
<div class="bg-white rounded-lg shadow-md p-4">
|
| 100 |
+
<div class="flex items-center justify-between">
|
| 101 |
+
<div>
|
| 102 |
+
<p class="text-gray-600">Expense Count</p>
|
| 103 |
+
<p id="expense-count" class="text-2xl font-bold text-gray-800">0</p>
|
| 104 |
+
</div>
|
| 105 |
+
<div class="bg-blue-100 p-3 rounded-full">
|
| 106 |
+
<i class="fas fa-receipt text-blue-600"></i>
|
| 107 |
+
</div>
|
| 108 |
+
</div>
|
| 109 |
+
</div>
|
| 110 |
+
</div>
|
| 111 |
+
|
| 112 |
+
<!-- Budget Alert -->
|
| 113 |
+
<div id="budget-alert" class="hidden mb-6 fade-in">
|
| 114 |
+
<div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 rounded-lg">
|
| 115 |
+
<div class="flex items-center">
|
| 116 |
+
<i class="fas fa-exclamation-circle mr-3 text-xl"></i>
|
| 117 |
+
<div>
|
| 118 |
+
<p class="font-bold">Budget Exceeded!</p>
|
| 119 |
+
<p>You've spent more than your budget. Consider reviewing your expenses.</p>
|
| 120 |
+
</div>
|
| 121 |
+
</div>
|
| 122 |
+
</div>
|
| 123 |
+
</div>
|
| 124 |
+
|
| 125 |
+
<!-- Chart Section -->
|
| 126 |
+
<div class="bg-white rounded-lg shadow-md p-6 mb-6">
|
| 127 |
+
<h2 class="text-xl font-semibold text-gray-800 mb-4">Expense Breakdown</h2>
|
| 128 |
+
<div class="chart-container">
|
| 129 |
+
<canvas id="expense-chart"></canvas>
|
| 130 |
+
</div>
|
| 131 |
+
</div>
|
| 132 |
+
|
| 133 |
+
<!-- Add Expense Form -->
|
| 134 |
+
<div class="bg-white rounded-lg shadow-md p-6 mb-6">
|
| 135 |
+
<h2 class="text-xl font-semibold text-gray-800 mb-4">Add New Expense</h2>
|
| 136 |
+
<form id="expense-form" class="space-y-4">
|
| 137 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
| 138 |
+
<div>
|
| 139 |
+
<label for="expense-name" class="block text-sm font-medium text-gray-700 mb-1">Expense Name</label>
|
| 140 |
+
<input type="text" id="expense-name" required class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
|
| 141 |
+
</div>
|
| 142 |
+
|
| 143 |
+
<div>
|
| 144 |
+
<label for="expense-amount" class="block text-sm font-medium text-gray-700 mb-1">Amount ($)</label>
|
| 145 |
+
<input type="number" id="expense-amount" min="0.01" step="0.01" required class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
|
| 146 |
+
</div>
|
| 147 |
+
|
| 148 |
+
<div>
|
| 149 |
+
<label for="expense-category" class="block text-sm font-medium text-gray-700 mb-1">Category</label>
|
| 150 |
+
<select id="expense-category" required class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
|
| 151 |
+
<option value="">Select a category</option>
|
| 152 |
+
<option value="Food">Food</option>
|
| 153 |
+
<option value="Transportation">Transportation</option>
|
| 154 |
+
<option value="Housing">Housing</option>
|
| 155 |
+
<option value="Entertainment">Entertainment</option>
|
| 156 |
+
<option value="Utilities">Utilities</option>
|
| 157 |
+
<option value="Healthcare">Healthcare</option>
|
| 158 |
+
<option value="Shopping">Shopping</option>
|
| 159 |
+
<option value="Other">Other</option>
|
| 160 |
+
</select>
|
| 161 |
+
</div>
|
| 162 |
+
</div>
|
| 163 |
+
|
| 164 |
+
<div class="flex justify-end">
|
| 165 |
+
<button type="submit" class="bg-indigo-600 text-white px-6 py-2 rounded-lg hover:bg-indigo-700 transition flex items-center">
|
| 166 |
+
<i class="fas fa-plus mr-2"></i> Add Expense
|
| 167 |
+
</button>
|
| 168 |
+
</div>
|
| 169 |
+
</form>
|
| 170 |
+
</div>
|
| 171 |
+
|
| 172 |
+
<!-- Expense History -->
|
| 173 |
+
<div class="bg-white rounded-lg shadow-md p-6">
|
| 174 |
+
<div class="flex justify-between items-center mb-4">
|
| 175 |
+
<h2 class="text-xl font-semibold text-gray-800">Expense History</h2>
|
| 176 |
+
<button id="clear-all-btn" class="text-red-600 hover:text-red-800 text-sm font-medium flex items-center">
|
| 177 |
+
<i class="fas fa-trash-alt mr-1"></i> Clear All
|
| 178 |
+
</button>
|
| 179 |
+
</div>
|
| 180 |
+
|
| 181 |
+
<div class="overflow-x-auto">
|
| 182 |
+
<table class="min-w-full divide-y divide-gray-200">
|
| 183 |
+
<thead class="bg-gray-50">
|
| 184 |
+
<tr>
|
| 185 |
+
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
|
| 186 |
+
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Amount</th>
|
| 187 |
+
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Category</th>
|
| 188 |
+
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Date</th>
|
| 189 |
+
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
|
| 190 |
+
</tr>
|
| 191 |
+
</thead>
|
| 192 |
+
<tbody id="expense-table-body" class="bg-white divide-y divide-gray-200">
|
| 193 |
+
<!-- Expenses will be added here dynamically -->
|
| 194 |
+
</tbody>
|
| 195 |
+
</table>
|
| 196 |
+
|
| 197 |
+
<div id="no-expenses-message" class="text-center py-8 text-gray-500">
|
| 198 |
+
<i class="fas fa-receipt text-4xl mb-2 opacity-30"></i>
|
| 199 |
+
<p>No expenses added yet. Start by adding your first expense!</p>
|
| 200 |
+
</div>
|
| 201 |
+
</div>
|
| 202 |
+
</div>
|
| 203 |
+
</div>
|
| 204 |
+
|
| 205 |
+
<script>
|
| 206 |
+
// DOM Elements
|
| 207 |
+
const budgetDisplay = document.getElementById('budget-display');
|
| 208 |
+
const editBudgetBtn = document.getElementById('edit-budget-btn');
|
| 209 |
+
const budgetEditForm = document.getElementById('budget-edit-form');
|
| 210 |
+
const newBudgetInput = document.getElementById('new-budget');
|
| 211 |
+
const saveBudgetBtn = document.getElementById('save-budget-btn');
|
| 212 |
+
const cancelBudgetBtn = document.getElementById('cancel-budget-btn');
|
| 213 |
+
const totalSpentDisplay = document.getElementById('total-spent');
|
| 214 |
+
const remainingBudgetDisplay = document.getElementById('remaining-budget');
|
| 215 |
+
const expenseCountDisplay = document.getElementById('expense-count');
|
| 216 |
+
const budgetAlert = document.getElementById('budget-alert');
|
| 217 |
+
const expenseForm = document.getElementById('expense-form');
|
| 218 |
+
const expenseTableBody = document.getElementById('expense-table-body');
|
| 219 |
+
const noExpensesMessage = document.getElementById('no-expenses-message');
|
| 220 |
+
const clearAllBtn = document.getElementById('clear-all-btn');
|
| 221 |
+
|
| 222 |
+
// Chart setup
|
| 223 |
+
let expenseChart;
|
| 224 |
+
const chartCtx = document.getElementById('expense-chart').getContext('2d');
|
| 225 |
+
|
| 226 |
+
// Initial Data
|
| 227 |
+
let budget = 1000;
|
| 228 |
+
let expenses = [];
|
| 229 |
+
let categories = ['Food', 'Transportation', 'Housing', 'Entertainment', 'Utilities', 'Healthcare', 'Shopping', 'Other'];
|
| 230 |
+
|
| 231 |
+
// Initialize the app
|
| 232 |
+
function init() {
|
| 233 |
+
loadFromLocalStorage();
|
| 234 |
+
updateBudgetDisplay();
|
| 235 |
+
updateSummary();
|
| 236 |
+
renderExpenseTable();
|
| 237 |
+
renderChart();
|
| 238 |
+
|
| 239 |
+
// Set up event listeners
|
| 240 |
+
editBudgetBtn.addEventListener('click', showBudgetEditForm);
|
| 241 |
+
saveBudgetBtn.addEventListener('click', saveBudget);
|
| 242 |
+
cancelBudgetBtn.addEventListener('click', hideBudgetEditForm);
|
| 243 |
+
expenseForm.addEventListener('submit', addExpense);
|
| 244 |
+
clearAllBtn.addEventListener('click', clearAllExpenses);
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
// Load data from localStorage
|
| 248 |
+
function loadFromLocalStorage() {
|
| 249 |
+
const savedBudget = localStorage.getItem('expenseTracker_budget');
|
| 250 |
+
const savedExpenses = localStorage.getItem('expenseTracker_expenses');
|
| 251 |
+
|
| 252 |
+
if (savedBudget) {
|
| 253 |
+
budget = parseFloat(savedBudget);
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
if (savedExpenses) {
|
| 257 |
+
expenses = JSON.parse(savedExpenses);
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
// Save data to localStorage
|
| 262 |
+
function saveToLocalStorage() {
|
| 263 |
+
localStorage.setItem('expenseTracker_budget', budget.toString());
|
| 264 |
+
localStorage.setItem('expenseTracker_expenses', JSON.stringify(expenses));
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
// Update budget display
|
| 268 |
+
function updateBudgetDisplay() {
|
| 269 |
+
budgetDisplay.textContent = `$${budget.toFixed(2)}`;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
// Show budget edit form
|
| 273 |
+
function showBudgetEditForm() {
|
| 274 |
+
newBudgetInput.value = budget;
|
| 275 |
+
budgetEditForm.classList.remove('hidden');
|
| 276 |
+
editBudgetBtn.classList.add('hidden');
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
// Hide budget edit form
|
| 280 |
+
function hideBudgetEditForm() {
|
| 281 |
+
budgetEditForm.classList.add('hidden');
|
| 282 |
+
editBudgetBtn.classList.remove('hidden');
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
// Save new budget
|
| 286 |
+
function saveBudget() {
|
| 287 |
+
const newBudget = parseFloat(newBudgetInput.value);
|
| 288 |
+
|
| 289 |
+
if (isNaN(newBudget) || newBudget <= 0) {
|
| 290 |
+
alert('Please enter a valid budget amount');
|
| 291 |
+
newBudgetInput.classList.add('shake');
|
| 292 |
+
setTimeout(() => newBudgetInput.classList.remove('shake'), 500);
|
| 293 |
+
return;
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
budget = newBudget;
|
| 297 |
+
updateBudgetDisplay();
|
| 298 |
+
updateSummary();
|
| 299 |
+
hideBudgetEditForm();
|
| 300 |
+
saveToLocalStorage();
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
// Update summary cards
|
| 304 |
+
function updateSummary() {
|
| 305 |
+
const totalSpent = expenses.reduce((sum, expense) => sum + expense.amount, 0);
|
| 306 |
+
const remaining = budget - totalSpent;
|
| 307 |
+
const expenseCount = expenses.length;
|
| 308 |
+
|
| 309 |
+
totalSpentDisplay.textContent = `$${totalSpent.toFixed(2)}`;
|
| 310 |
+
remainingBudgetDisplay.textContent = `$${remaining.toFixed(2)}`;
|
| 311 |
+
expenseCountDisplay.textContent = expenseCount;
|
| 312 |
+
|
| 313 |
+
// Update colors based on budget status
|
| 314 |
+
if (remaining < 0) {
|
| 315 |
+
remainingBudgetDisplay.classList.remove('text-green-600');
|
| 316 |
+
remainingBudgetDisplay.classList.add('text-red-600');
|
| 317 |
+
budgetAlert.classList.remove('hidden');
|
| 318 |
+
} else {
|
| 319 |
+
remainingBudgetDisplay.classList.remove('text-red-600');
|
| 320 |
+
remainingBudgetDisplay.classList.add('text-green-600');
|
| 321 |
+
budgetAlert.classList.add('hidden');
|
| 322 |
+
}
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
// Add new expense
|
| 326 |
+
function addExpense(e) {
|
| 327 |
+
e.preventDefault();
|
| 328 |
+
|
| 329 |
+
const name = document.getElementById('expense-name').value.trim();
|
| 330 |
+
const amount = parseFloat(document.getElementById('expense-amount').value);
|
| 331 |
+
const category = document.getElementById('expense-category').value;
|
| 332 |
+
|
| 333 |
+
if (!name || isNaN(amount) || amount <= 0 || !category) {
|
| 334 |
+
alert('Please fill in all fields with valid values');
|
| 335 |
+
return;
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
const newExpense = {
|
| 339 |
+
id: Date.now(),
|
| 340 |
+
name,
|
| 341 |
+
amount,
|
| 342 |
+
category,
|
| 343 |
+
date: new Date().toLocaleDateString()
|
| 344 |
+
};
|
| 345 |
+
|
| 346 |
+
expenses.push(newExpense);
|
| 347 |
+
saveToLocalStorage();
|
| 348 |
+
updateSummary();
|
| 349 |
+
renderExpenseTable();
|
| 350 |
+
renderChart();
|
| 351 |
+
|
| 352 |
+
// Reset form
|
| 353 |
+
expenseForm.reset();
|
| 354 |
+
|
| 355 |
+
// Show success animation
|
| 356 |
+
const submitBtn = expenseForm.querySelector('button[type="submit"]');
|
| 357 |
+
submitBtn.innerHTML = '<i class="fas fa-check mr-2"></i> Added!';
|
| 358 |
+
submitBtn.classList.remove('bg-indigo-600');
|
| 359 |
+
submitBtn.classList.add('bg-green-500');
|
| 360 |
+
|
| 361 |
+
setTimeout(() => {
|
| 362 |
+
submitBtn.innerHTML = '<i class="fas fa-plus mr-2"></i> Add Expense';
|
| 363 |
+
submitBtn.classList.remove('bg-green-500');
|
| 364 |
+
submitBtn.classList.add('bg-indigo-600');
|
| 365 |
+
}, 1500);
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
// Delete expense
|
| 369 |
+
function deleteExpense(id) {
|
| 370 |
+
expenses = expenses.filter(expense => expense.id !== id);
|
| 371 |
+
saveToLocalStorage();
|
| 372 |
+
updateSummary();
|
| 373 |
+
renderExpenseTable();
|
| 374 |
+
renderChart();
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
// Clear all expenses
|
| 378 |
+
function clearAllExpenses() {
|
| 379 |
+
if (expenses.length === 0 || !confirm('Are you sure you want to delete all expenses?')) {
|
| 380 |
+
return;
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
expenses = [];
|
| 384 |
+
saveToLocalStorage();
|
| 385 |
+
updateSummary();
|
| 386 |
+
renderExpenseTable();
|
| 387 |
+
renderChart();
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
// Render expense table
|
| 391 |
+
function renderExpenseTable() {
|
| 392 |
+
if (expenses.length === 0) {
|
| 393 |
+
expenseTableBody.innerHTML = '';
|
| 394 |
+
noExpensesMessage.classList.remove('hidden');
|
| 395 |
+
return;
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
noExpensesMessage.classList.add('hidden');
|
| 399 |
+
|
| 400 |
+
expenseTableBody.innerHTML = expenses.map(expense => `
|
| 401 |
+
<tr class="hover:bg-gray-50 fade-in">
|
| 402 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${expense.name}</td>
|
| 403 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">$${expense.amount.toFixed(2)}</td>
|
| 404 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
| 405 |
+
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${getCategoryColorClass(expense.category)}">
|
| 406 |
+
${expense.category}
|
| 407 |
+
</span>
|
| 408 |
+
</td>
|
| 409 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${expense.date}</td>
|
| 410 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
| 411 |
+
<button onclick="deleteExpense(${expense.id})" class="text-red-600 hover:text-red-900">
|
| 412 |
+
<i class="fas fa-trash-alt"></i>
|
| 413 |
+
</button>
|
| 414 |
+
</td>
|
| 415 |
+
</tr>
|
| 416 |
+
`).join('');
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
// Get color class for category badge
|
| 420 |
+
function getCategoryColorClass(category) {
|
| 421 |
+
const colors = {
|
| 422 |
+
'Food': 'bg-green-100 text-green-800',
|
| 423 |
+
'Transportation': 'bg-blue-100 text-blue-800',
|
| 424 |
+
'Housing': 'bg-purple-100 text-purple-800',
|
| 425 |
+
'Entertainment': 'bg-yellow-100 text-yellow-800',
|
| 426 |
+
'Utilities': 'bg-indigo-100 text-indigo-800',
|
| 427 |
+
'Healthcare': 'bg-pink-100 text-pink-800',
|
| 428 |
+
'Shopping': 'bg-red-100 text-red-800',
|
| 429 |
+
'Other': 'bg-gray-100 text-gray-800'
|
| 430 |
+
};
|
| 431 |
+
|
| 432 |
+
return colors[category] || 'bg-gray-100 text-gray-800';
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
// Render chart
|
| 436 |
+
function renderChart() {
|
| 437 |
+
// Calculate category totals
|
| 438 |
+
const categoryTotals = {};
|
| 439 |
+
categories.forEach(cat => {
|
| 440 |
+
categoryTotals[cat] = 0;
|
| 441 |
+
});
|
| 442 |
+
|
| 443 |
+
expenses.forEach(expense => {
|
| 444 |
+
categoryTotals[expense.category] += expense.amount;
|
| 445 |
+
});
|
| 446 |
+
|
| 447 |
+
// Prepare data for chart
|
| 448 |
+
const labels = categories;
|
| 449 |
+
const data = categories.map(cat => categoryTotals[cat]);
|
| 450 |
+
const backgroundColors = [
|
| 451 |
+
'rgba(16, 185, 129, 0.6)', // Food - green
|
| 452 |
+
'rgba(59, 130, 246, 0.6)', // Transportation - blue
|
| 453 |
+
'rgba(168, 85, 247, 0.6)', // Housing - purple
|
| 454 |
+
'rgba(234, 179, 8, 0.6)', // Entertainment - yellow
|
| 455 |
+
'rgba(99, 102, 241, 0.6)', // Utilities - indigo
|
| 456 |
+
'rgba(236, 72, 153, 0.6)', // Healthcare - pink
|
| 457 |
+
'rgba(239, 68, 68, 0.6)', // Shopping - red
|
| 458 |
+
'rgba(156, 163, 175, 0.6)' // Other - gray
|
| 459 |
+
];
|
| 460 |
+
|
| 461 |
+
// Destroy previous chart if it exists
|
| 462 |
+
if (expenseChart) {
|
| 463 |
+
expenseChart.destroy();
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
// Create new chart
|
| 467 |
+
expenseChart = new Chart(chartCtx, {
|
| 468 |
+
type: 'doughnut',
|
| 469 |
+
data: {
|
| 470 |
+
labels: labels,
|
| 471 |
+
datasets: [{
|
| 472 |
+
data: data,
|
| 473 |
+
backgroundColor: backgroundColors,
|
| 474 |
+
borderWidth: 1,
|
| 475 |
+
hoverOffset: 10
|
| 476 |
+
}]
|
| 477 |
+
},
|
| 478 |
+
options: {
|
| 479 |
+
responsive: true,
|
| 480 |
+
maintainAspectRatio: false,
|
| 481 |
+
plugins: {
|
| 482 |
+
legend: {
|
| 483 |
+
position: 'right',
|
| 484 |
+
labels: {
|
| 485 |
+
boxWidth: 12,
|
| 486 |
+
padding: 20,
|
| 487 |
+
usePointStyle: true,
|
| 488 |
+
pointStyle: 'circle'
|
| 489 |
+
}
|
| 490 |
+
},
|
| 491 |
+
tooltip: {
|
| 492 |
+
callbacks: {
|
| 493 |
+
label: function(context) {
|
| 494 |
+
const label = context.label || '';
|
| 495 |
+
const value = context.raw || 0;
|
| 496 |
+
const total = context.dataset.data.reduce((acc, curr) => acc + curr, 0);
|
| 497 |
+
const percentage = total > 0 ? Math.round((value / total) * 100) : 0;
|
| 498 |
+
return `${label}: $${value.toFixed(2)} (${percentage}%)`;
|
| 499 |
+
}
|
| 500 |
+
}
|
| 501 |
+
}
|
| 502 |
+
},
|
| 503 |
+
cutout: '65%',
|
| 504 |
+
animation: {
|
| 505 |
+
animateScale: true,
|
| 506 |
+
animateRotate: true
|
| 507 |
+
}
|
| 508 |
+
}
|
| 509 |
+
});
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
// Initialize the app when DOM is loaded
|
| 513 |
+
document.addEventListener('DOMContentLoaded', init);
|
| 514 |
+
</script>
|
| 515 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=binneht3/tracking-page" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 516 |
+
</html>
|