financeflow-wizard / index.html
cmbbombs's picture
<!DOCTYPE html>
3673a0d verified
Raw History Blame Contribute Delete
25.3 kB
<!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>