diff --git a/src/main/java/com/prospero/simulator/calculation/CalculationController.java b/src/main/java/com/prospero/simulator/calculation/CalculationController.java index a505561..fe12f89 100644 --- a/src/main/java/com/prospero/simulator/calculation/CalculationController.java +++ b/src/main/java/com/prospero/simulator/calculation/CalculationController.java @@ -52,11 +52,11 @@ public ResponseEntity> createCalculation(@RequestBody Calculation calculation) } -// @PutMapping("/update/{id}") -// public void updateCalculation(@PathVariable Integer id) { -// Calculation calculation = calculationService.getCalculation(id); -// calculation.setName("Updated name"); -// calculationService.updateCalculation(id, calculation); -// } + @PutMapping("/update/{id}") + public ResponseEntity> updateCalculation(@PathVariable Integer id, @RequestBody Calculation calculation) { + // Logic to save the calculation + Calculation savedCalculation = calculationService.updateCalculation(id, calculation); + return ResponseEntity.ok(savedCalculation); + } } diff --git a/src/main/java/com/prospero/simulator/calculation/CalculationService.java b/src/main/java/com/prospero/simulator/calculation/CalculationService.java index 31fd45c..251d7e9 100644 --- a/src/main/java/com/prospero/simulator/calculation/CalculationService.java +++ b/src/main/java/com/prospero/simulator/calculation/CalculationService.java @@ -41,12 +41,18 @@ public Calculation saveCalculation(Calculation calculation) { return calculation; } -// public void updateCalculation(Integer id, Calculation calculation) { -// Calculation calculationToUpdate = calculationRepository.findById(id).orElseThrow(); -// calculationToUpdate.setName(calculation.getName()); -// calculationToUpdate.setInitialAmount(calculation.getInitialAmount()); -// calculationToUpdate.setContributionAmount(calculation.getContributionAmount()); -// calculationToUpdate.setContributionFrequency(calculation.getContributionFrequency()); -// calculationRepository.save(calculationToUpdate); -// } + public Calculation updateCalculation(Integer id, Calculation calculation) { + Calculation calculationToUpdate = calculationRepository.findById(id).orElseThrow(); + calculationToUpdate.setName(calculation.getName()); + calculationToUpdate.setContributionAmount(calculation.getContributionAmount()); + calculationToUpdate.setContributionFrequency(calculation.getContributionFrequency()); + calculationToUpdate.setCapitalizationFrequency(calculation.getCapitalizationFrequency()); + calculationToUpdate.setInterestRate(calculation.getInterestRate()); + calculationToUpdate.setCreatedAt(calculation.getCreatedAt()); + calculationToUpdate.setIncomeTaxRate(calculation.getIncomeTaxRate()); + calculationToUpdate.setInflationRate(calculation.getInflationRate()); + calculationToUpdate.setInitialDeposit(calculation.getInitialDeposit()); + calculationRepository.save(calculationToUpdate); + return calculationToUpdate; + } } diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties index aa03535..492cf87 100644 --- a/src/main/resources/i18n/messages.properties +++ b/src/main/resources/i18n/messages.properties @@ -128,9 +128,10 @@ simulator.tax=Tax simulator.maxValueReached=Maximum value reached simulator.enterCalculationName=Enter calculation name simulator.alreadyExists=Already exists -simulator.Delete=Delete +simulator.delete=Delete simulator.calculationNameRequired=Calculation name is required simulator.inflation=Inflation +history.delete=Delete # History history.title=History diff --git a/src/main/resources/static/assets/css/simulator.css b/src/main/resources/static/assets/css/simulator.css index c46d605..2ce9072 100644 --- a/src/main/resources/static/assets/css/simulator.css +++ b/src/main/resources/static/assets/css/simulator.css @@ -39,7 +39,7 @@ label { } #sub-container-history { - width: 85%; + width: 100%; margin: auto; } @@ -50,10 +50,6 @@ label { margin-top: 1.5em; } -#btn-export-csv { - /*float: right;*/ -} - /*////////// Responsiveness /////////////////*/ /* Laptop */ @@ -108,13 +104,13 @@ label { margin: auto; } - #btn-export-csv { - margin-bottom: 2em; - } - .container-export { width: 100%; } + + .history-additional-info-tablet { + display: none; + } } /* Smartphones in landscape mode */ @@ -138,13 +134,13 @@ label { margin: auto; } - #btn-export-csv { - margin-bottom: 2em; - } - .container-export { width: 100%; } + + .history-additional-info-tablet { + display: none; + } } /* Smartphones in portrait mode */ @@ -182,7 +178,15 @@ label { width: 100%; } - .history-additional-info { + .history-additional-info-smartphone { + display: none; + } + + .history-additional-info-tablet { + display: none; + } + + .button-history-delete { display: none; } } \ No newline at end of file diff --git a/src/main/resources/static/assets/img/icon.png b/src/main/resources/static/assets/img/icon.png new file mode 100644 index 0000000..21c32be Binary files /dev/null and b/src/main/resources/static/assets/img/icon.png differ diff --git a/src/main/resources/static/assets/js/simulator.js b/src/main/resources/static/assets/js/simulator.js index 39de084..7f3f9ec 100644 --- a/src/main/resources/static/assets/js/simulator.js +++ b/src/main/resources/static/assets/js/simulator.js @@ -89,7 +89,8 @@ function initializeInvestmentSimulator() { // Update the descriptions updateDescriptions(_initial_deposit, _contribution_frequency, _contribution_amount, - _estimated_return * 100, _estimatedTax * 100, _estimatedInflation * 100, _investment_duration, balance.toFixed(2) + '€'); + _estimated_return * 100, _estimatedTax * 100, _estimatedInflation * 100, _investment_duration, balance.toFixed(2)); + console.log('After descriptions updated in getChartData()') return { labels: labels, @@ -115,21 +116,16 @@ function initializeInvestmentSimulator() { function updateDescriptions(principalAmount, contributionFrequency, contributionAmount, annualInterestRate, taxRate, inflationRate, investmentDuration, futureBalance) { - // Update text content of each div - document.getElementById('principal-amount').textContent = - `The base sum of your investment, initially set to ${principalAmount} with additional ${contributionFrequency} contributions of ${contributionAmount}. It represents the core capital on which interest is calculated.`; + console.log(`#{simulator.explanation.principalAmount("234", "234", "324")}`) - document.getElementById('interest-earned').textContent = - `Earnings on your investment, calculated at an ${annualInterestRate} annual return rate. This is the profit generated from your principal over time.`; + document.getElementById('simulator-results-explanation').innerHTML = ` +
+ + + + + `; - document.getElementById('tax-deduction').textContent = - `Deductions from your earnings at an estimated tax rate of ${taxRate}. It indicates the amount of interest earned that you'll pay as taxes.`; - - document.getElementById('inflation-effect').textContent = - `The decrease in purchasing power of your money, assuming a ${inflationRate} annual inflation rate. It reflects the cost of rising prices and its impact on the real value of your investment.`; - - document.getElementById('future-balance').textContent = - `After ${investmentDuration} years, your investment's future balance is projected to be ${futureBalance}. This includes your principal amount, the interest earned, and is adjusted for taxes and inflation.`; } @@ -422,9 +418,10 @@ function initializeInvestmentSimulator() { // Add this function to a button's click event document.getElementById('btn-export-csv').addEventListener('click', exportToCSV); -} -function initializeHistorySection() { + + + ////////////////////////////////////////////// HISTORY /////////////////////////////////////////////////// // Save calculation to history document.getElementById('button-save').addEventListener('click', function() { @@ -440,14 +437,14 @@ function initializeHistorySection() { const calculationData = { name: prompt(simulator.enterCalculationName), //description: prompt(simulator.enterCalculationName), - initialDeposit: document.getElementById('initial_deposit').value, - contributionAmount: document.getElementById('contribution_amount').value, + initialDeposit: document.getElementById('initial_deposit').dataset.value, + contributionAmount: document.getElementById('contribution_amount').dataset.value, contributionFrequency: contributionFrequency, durationYears: parseInt(document.getElementById('investment_timespan').value), - interestRate: document.getElementById('estimated_return').value, + interestRate: document.getElementById('estimated_return').dataset.value, capitalizationFrequency: capitalizationFrequency, - incomeTaxRate: document.getElementById('estimated_tax').value, - inflationRate: document.getElementById('estimated_inflation').value, + incomeTaxRate: document.getElementById('estimated_tax').dataset.value, + inflationRate: document.getElementById('estimated_inflation').dataset.value, finalAmount: parseFloat(document.getElementById('future_balance').innerHTML.replace(/€/, '').replace(/,/, '.')), createdAt: Date.now(), createdBy: {id: userDetails.userId, email: userDetails.userEmail} @@ -471,9 +468,10 @@ function initializeHistorySection() { 'Authorization': "Bearer " + authToken }, data: JSON.stringify(calculationData), - success: function(data) { + success: function (data) { console.log('Success calculation POST:', data); getCalculations(); + updateHistory(); }, error: function(error) { console.error('Error calculation POST:', error); @@ -492,7 +490,7 @@ function initializeHistorySection() { headers: { 'Authorization': "Bearer " + authToken }, - success: function(data) { + success: function (data) { console.log('Success:', data); replaceCalculationsLocally(data); }, @@ -514,58 +512,133 @@ function initializeHistorySection() { const history = JSON.parse(localStorage.getItem('calculationHistory')); // Get the history section - const historySection = document.getElementById('history-content-table-body'); + const tableContent = document.getElementById('history-content-table-body'); // Clear the history section - historySection.innerHTML = ''; + tableContent.innerHTML = ''; // If there are no calculations, hide the history section if (history.length === 0) { - historySection.style.display = 'none'; + document.getElementById('container-history').setAttribute("style", "display: none;") return; + } else { + document.getElementById('container-history').setAttribute("style", "display: block;") } // Show the history section - historySection.style.display = 'block'; + //historySection.style.display = 'block'; + var calculationNumber = 0; // Loop through the calculations history.forEach(function(calculation) { + // Increment the calculation number + calculationNumber++; + var date = new Date(calculation.createdAt).toLocaleDateString('en-GB'); // Create a row for each calculation var row = document.createElement('tr'); + row.style.cursor = 'pointer'; + //set class + row.setAttribute("class", "calculation-row"); + row.setAttribute("class", "align-middle"); + row.setAttribute("data-calculation-id", calculation.id); row.innerHTML = '# | +# | - | - | + | + |
---|