Spaces:
Running
Running
File size: 25,286 Bytes
3673a0d c5d2866 | 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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | <!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Planejador Financeiro Inteligente</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<script src="https://unpkg.com/feather-icons"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
.goal-card {
transition: all 0.3s ease;
}
.goal-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}
.progress-bar {
height: 6px;
border-radius: 3px;
background-color: #e5e7eb;
}
.progress-fill {
height: 100%;
border-radius: 3px;
background-color: #3b82f6;
transition: width 0.5s ease;
}
.modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}
.modal-content {
background: white;
border-radius: 0.5rem;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
width: 90%;
max-width: 500px;
padding: 2rem;
animation: modalFadeIn 0.3s ease-out;
}
@keyframes modalFadeIn {
from { opacity: 0; transform: translateY(-20px); }
to { opacity: 1; transform: translateY(0); }
}
</style>
</head>
<body>
<!-- Modal de boas-vindas -->
<div id="welcomeModal" class="modal-overlay">
<div class="modal-content">
<div class="text-center mb-6">
<h2 class="text-2xl font-bold text-blue-600 mb-2">Bem-vindo ao Planejador Financeiro</h2>
<p class="text-gray-600">Antes de começar, precisamos de algumas informações básicas</p>
</div>
<form id="userInfoForm" class="space-y-4">
<div>
<label for="userName" class="block text-sm font-medium text-gray-700 mb-1">Nome Completo</label>
<input type="text" id="userName" required class="w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500" placeholder="Seu nome">
</div>
<div>
<label for="userEmail" class="block text-sm font-medium text-gray-700 mb-1">E-mail</label>
<input type="email" id="userEmail" required class="w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500" placeholder="seu@email.com">
</div>
<div>
<label for="userPhone" class="block text-sm font-medium text-gray-700 mb-1">Celular</label>
<input type="tel" id="userPhone" required class="w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500" placeholder="(00) 00000-0000">
</div>
<div class="pt-4">
<button type="submit" class="w-full py-2 px-4 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors font-medium">
Concluir e Começar
</button>
</div>
</form>
</div>
</div>
<!-- Main App (Hidden Initially) -->
<div id="mainApp" class="min-h-screen hidden">
<!-- Header -->
<header class="bg-white shadow-sm">
<div class="container mx-auto px-4 py-6">
<div class="flex justify-between items-center">
<h1 class="text-2xl font-bold text-blue-600">Planejador Financeiro</h1>
<div class="flex items-center space-x-4">
<span class="text-gray-600"><i data-feather="user" class="inline-block mr-1"></i> <span id="displayUserName"></span></span>
</div>
</div>
</div>
</header>
<!-- Main Content -->
<main class="container mx-auto px-4 py-8">
<div class="max-w-4xl mx-auto">
<!-- Step 1: Current Value -->
<div class="bg-white rounded-xl shadow-md p-6 mb-8" data-aos="fade-up">
<h2 class="text-xl font-semibold text-gray-800 mb-4">1. Valor Disponível Atual</h2>
<div class="flex flex-col md:flex-row md:items-center gap-4">
<div class="flex-1">
<label for="currentValue" class="block text-sm font-medium text-gray-700 mb-1">Quanto você tem disponível hoje?</label>
<div class="relative rounded-md shadow-sm">
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<span class="text-gray-500 sm:text-sm">R$</span>
</div>
<input type="number" id="currentValue" class="focus:ring-blue-500 focus:border-blue-500 block w-full pl-10 pr-12 py-3 border-gray-300 rounded-md" placeholder="0,00">
</div>
</div>
<div class="md:mt-6">
<button id="saveCurrentValue" class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors">
Salvar Valor
</button>
</div>
</div>
</div>
<!-- Step 2: Goals -->
<div class="bg-white rounded-xl shadow-md p-6 mb-8" data-aos="fade-up" data-aos-delay="100">
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-semibold text-gray-800">2. Seus Objetivos Financeiros</h2>
<button id="addGoalBtn" class="px-4 py-2 bg-green-600 text-white rounded-md hover:bg-green-700 transition-colors flex items-center">
<i data-feather="plus" class="mr-2"></i> Adicionar Objetivo
</button>
</div>
<div id="goalsContainer" class="space-y-4">
<!-- Goals will be added here dynamically -->
</div>
</div>
<!-- Step 3: Results -->
<div id="resultsSection" class="bg-white rounded-xl shadow-md p-6 hidden" data-aos="fade-up" data-aos-delay="200">
<h2 class="text-xl font-semibold text-gray-800 mb-6">3. Resultados do Planejamento</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
<div class="bg-blue-50 rounded-lg p-5">
<h3 class="text-lg font-medium text-blue-800 mb-3">Resumo Financeiro</h3>
<div class="space-y-3">
<div class="flex justify-between">
<span class="text-gray-600">Valor Disponível:</span>
<span id="summaryCurrentValue" class="font-medium">R$ 0,00</span>
</div>
<div class="flex justify-between">
<span class="text-gray-600">Total em Objetivos:</span>
<span id="summaryTotalGoals" class="font-medium">R$ 0,00</span>
</div>
<div class="flex justify-between">
<span class="text-gray-600">Investimento Mensal Total:</span>
<span id="summaryMonthlyInvestment" class="font-medium">R$ 0,00</span>
</div>
</div>
</div>
<div class="bg-blue-50 rounded-lg p-5">
<h3 class="text-lg font-medium text-blue-800 mb-3">Distribuição por Objetivo</h3>
<canvas id="goalsChart" height="200"></canvas>
</div>
</div>
<h3 class="text-lg font-medium text-gray-800 mb-4">Detalhes dos Objetivos</h3>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Objetivo</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Valor</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Prazo</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Investimento Inicial</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Investimento Mensal</th>
</tr>
</thead>
<tbody id="resultsTableBody" class="bg-white divide-y divide-gray-200">
<!-- Results will be added here dynamically -->
</tbody>
</table>
</div>
</div>
<!-- Calculate Button -->
<div class="mt-8 text-center" data-aos="fade-up" data-aos-delay="300">
<button id="calculateBtn" class="px-8 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors text-lg font-medium shadow-lg">
Calcular Meu Planejamento
</button>
</div>
</div>
</main>
</div>
<!-- Goal Template (Hidden) -->
<template id="goalTemplate">
<div class="goal-card bg-white border border-gray-200 rounded-lg p-5 shadow-sm">
<div class="flex justify-between items-start mb-3">
<h3 class="text-lg font-medium text-gray-800">Novo Objetivo</h3>
<button class="text-red-500 hover:text-red-700 delete-goal">
<i data-feather="trash-2" class="w-5 h-5"></i>
</button>
</div>
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Nome do Objetivo</label>
<input type="text" class="goal-name focus:ring-blue-500 focus:border-blue-500 block w-full px-3 py-2 border border-gray-300 rounded-md" placeholder="Ex: Compra de Carro">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Valor do Objetivo (R$)</label>
<input type="number" class="goal-value focus:ring-blue-500 focus:border-blue-500 block w-full px-3 py-2 border border-gray-300 rounded-md" placeholder="0,00">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Prazo (meses)</label>
<input type="number" class="goal-deadline focus:ring-blue-500 focus:border-blue-500 block w-full px-3 py-2 border border-gray-300 rounded-md" placeholder="12">
</div>
</div>
</div>
</template>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Initialize AOS and Feather Icons
AOS.init({
duration: 800,
easing: 'ease-in-out'
});
feather.replace();
// Modal and user info handling
const mainApp = document.getElementById('mainApp');
const welcomeModal = document.getElementById('welcomeModal');
const displayUserName = document.getElementById('displayUserName');
const userInfoForm = document.getElementById('userInfoForm');
// Show modal by default (initially hidden)
setTimeout(() => {
welcomeModal.style.display = 'flex';
}, 100);
// Check for existing user info
const userInfo = JSON.parse(localStorage.getItem('userInfo'));
if (userInfo) {
welcomeModal.style.display = 'none';
mainApp.classList.remove('hidden');
displayUserName.textContent = userInfo.name.split(' ')[0];
}
// Handle form submission
userInfoForm.addEventListener('submit', function(e) {
e.preventDefault();
const name = document.getElementById('userName').value;
const email = document.getElementById('userEmail').value;
const phone = document.getElementById('userPhone').value;
if (!name || !email || !phone) {
alert('Por favor, preencha todas as informações.');
return;
}
const userInfo = { name, email, phone };
localStorage.setItem('userInfo', JSON.stringify(userInfo));
welcomeModal.style.display = 'none';
mainApp.classList.remove('hidden');
displayUserName.textContent = name.split(' ')[0];
});
// Rest of your existing JavaScript code...
// Variables
let currentValue = 0;
let goals = [];
let chart = null;
// DOM Elements
const currentValueInput = document.getElementById('currentValue');
const saveCurrentValueBtn = document.getElementById('saveCurrentValue');
const addGoalBtn = document.getElementById('addGoalBtn');
const goalsContainer = document.getElementById('goalsContainer');
const goalTemplate = document.getElementById('goalTemplate');
const calculateBtn = document.getElementById('calculateBtn');
const resultsSection = document.getElementById('resultsSection');
const resultsTableBody = document.getElementById('resultsTableBody');
const summaryCurrentValue = document.getElementById('summaryCurrentValue');
const summaryTotalGoals = document.getElementById('summaryTotalGoals');
const summaryMonthlyInvestment = document.getElementById('summaryMonthlyInvestment');
// Event Listeners
saveCurrentValueBtn.addEventListener('click', saveCurrentValue);
addGoalBtn.addEventListener('click', addGoal);
calculateBtn.addEventListener('click', calculateResults);
// Functions
function saveCurrentValue() {
const value = parseFloat(currentValueInput.value);
if (isNaN(value) || value <= 0) {
alert('Por favor, insira um valor válido maior que zero.');
return;
}
currentValue = value;
alert(`Valor atual salvo: R$ ${value.toFixed(2)}`);
}
function addGoal() {
const goalClone = goalTemplate.content.cloneNode(true);
goalsContainer.appendChild(goalClone);
// Add event listener to delete button
const deleteBtn = goalsContainer.lastElementChild.querySelector('.delete-goal');
deleteBtn.addEventListener('click', function() {
goalsContainer.removeChild(deleteBtn.closest('.goal-card'));
});
// Scroll to the new goal
goalsContainer.lastElementChild.scrollIntoView({ behavior: 'smooth' });
}
function calculateResults() {
// Validate current value
if (currentValue <= 0) {
alert('Por favor, insira e salve seu valor disponível antes de calcular.');
return;
}
// Get all goals
const goalCards = goalsContainer.querySelectorAll('.goal-card');
if (goalCards.length === 0) {
alert('Por favor, adicione pelo menos um objetivo antes de calcular.');
return;
}
// Process goals
goals = [];
let totalGoalsValue = 0;
goalCards.forEach((card, index) => {
const name = card.querySelector('.goal-name').value || `Objetivo ${index + 1}`;
const value = parseFloat(card.querySelector('.goal-value').value) || 0;
const deadline = parseInt(card.querySelector('.goal-deadline').value) || 12;
if (value > 0) {
goals.push({
name,
value,
deadline
});
totalGoalsValue += value;
}
});
if (goals.length === 0) {
alert('Por favor, insira valores válidos para pelo menos um objetivo.');
return;
}
// Simulate calculation (in a real app, this would be done server-side)
const results = simulateCalculation(currentValue, goals);
// Display results
displayResults(results, totalGoalsValue);
// Show results section
resultsSection.classList.remove('hidden');
resultsSection.scrollIntoView({ behavior: 'smooth' });
}
function simulateCalculation(currentValue, goals) {
// This is a simplified simulation of the Python calculation
// In a real application, this would be done server-side with the actual LP solver
const results = [];
const totalValue = goals.reduce((sum, goal) => sum + goal.value, 0);
const proportion = currentValue / totalValue;
let totalMonthlyInvestment = 0;
goals.forEach(goal => {
// Simplified calculation - real implementation would use the LP solver
const initialInvestment = Math.min(goal.value * proportion, goal.value * 0.7);
const remainingValue = goal.value - initialInvestment;
// Calculate monthly investment (simplified)
const monthlyInvestment = remainingValue / goal.deadline;
totalMonthlyInvestment += monthlyInvestment;
results.push({
name: goal.name,
value: goal.value,
deadline: goal.deadline,
initialInvestment: initialInvestment,
monthlyInvestment: monthlyInvestment
});
});
return {
results,
totalMonthlyInvestment
};
}
function displayResults(data, totalGoalsValue) {
const { results, totalMonthlyInvestment } = data;
// Update summary
summaryCurrentValue.textContent = `R$ ${currentValue.toFixed(2)}`;
summaryTotalGoals.textContent = `R$ ${totalGoalsValue.toFixed(2)}`;
summaryMonthlyInvestment.textContent = `R$ ${totalMonthlyInvestment.toFixed(2)}`;
// Clear previous results
resultsTableBody.innerHTML = '';
// Add results to table
results.forEach(result => {
const row = document.createElement('tr');
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${result.name}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">R$ ${result.value.toFixed(2)}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${result.deadline} meses</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">R$ ${result.initialInvestment.toFixed(2)}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">R$ ${result.monthlyInvestment.toFixed(2)}</td>
`;
resultsTableBody.appendChild(row);
});
// Update chart
updateChart(results);
}
function updateChart(results) {
const ctx = document.getElementById('goalsChart').getContext('2d');
// Destroy previous chart if exists
if (chart) {
chart.destroy();
}
// Prepare data for chart
const labels = results.map(result => result.name);
const initialData = results.map(result => result.initialInvestment);
const monthlyData = results.map(result => result.monthlyInvestment * result.deadline);
chart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [
{
label: 'Investimento Inicial',
data: initialData,
backgroundColor: 'rgba(59, 130, 246, 0.7)',
borderColor: 'rgba(59, 130, 246, 1)',
borderWidth: 1
},
{
label: 'Investimento Mensal Total',
data: monthlyData,
backgroundColor: 'rgba(16, 185, 129, 0.7)',
borderColor: 'rgba(16, 185, 129, 1)',
borderWidth: 1
}
]
},
options: {
responsive: true,
scales: {
x: {
stacked: false,
},
y: {
stacked: false,
beginAtZero: true,
ticks: {
callback: function(value) {
return 'R$ ' + value.toLocaleString('pt-BR');
}
}
}
},
plugins: {
tooltip: {
callbacks: {
label: function(context) {
let label = context.dataset.label || '';
if (label) {
label += ': ';
}
if (context.parsed.y !== null) {
label += 'R$ ' + context.parsed.y.toFixed(2).replace('.', ',');
}
return label;
}
}
},
legend: {
position: 'bottom',
}
}
}
});
}
});
</script>
</body>
</html>
|