document.addEventListener('DOMContentLoaded', function () { const amountInput = document.getElementById('amount'); const rateInput = document.getElementById('rate'); const vatAmountOutput = document.getElementById('vatAmount'); const totalAmountOutput = document.getElementById('totalAmount'); const grossSalaryInput = document.getElementById('gross-salary'); const netSalaryOutput = document.getElementById('netSalary'); function calculateVAT() { const amount = parseFloat(amountInput.value) || 0; const rate = parseFloat(rateInput.value) || 0; if (amount > 0 && rate > 0) { const vatAmount = (amount * rate) / 100; const totalAmount = amount + vatAmount; vatAmountOutput.textContent = vatAmount.toFixed(2); totalAmountOutput.textContent = totalAmount.toFixed(2); } else { vatAmountOutput.textContent = '0.00'; totalAmountOutput.textContent = '0.00'; } } function calculateNetSalary() { const grossSalary = parseFloat(grossSalaryInput.value) || 0; let tax = 0; if (grossSalary > 0) { if (grossSalary <= 1000) { tax = grossSalary * 0.10; } else if (grossSalary <= 3000) { tax = (1000 * 0.10) + ((grossSalary - 1000) * 0.20); } else { tax = (1000 * 0.10) + (2000 * 0.20) + ((grossSalary - 3000) * 0.30); } const netSalary = grossSalary - tax; netSalaryOutput.textContent = netSalary.toFixed(2); } else { netSalaryOutput.textContent = '0.00'; } } window.setRate = function(rate) { rateInput.value = rate; calculateVAT(); } amountInput.addEventListener('input', calculateVAT); rateInput.addEventListener('input', calculateVAT); grossSalaryInput.addEventListener('input', calculateNetSalary); // Initial calculation calculateVAT(); calculateNetSalary(); });