Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ const calculateBtn = document.getElementById('calculate');
+ const resultsDiv = document.querySelector('.results');
+ let salaryChart = null;
+
+ calculateBtn.addEventListener('click', calculateSalary);
+
+ function calculateSalary() {
+ const grossSalary = parseFloat(document.getElementById('grossSalary').value);
+
+ if (isNaN(grossSalary) || grossSalary < 0) {
+ alert('Please enter a valid salary amount');
+ return;
+ }
+
+ // Basic Israeli tax calculation (simplified)
+ let netSalary = calculateNetSalary(grossSalary);
+ let ratio = ((netSalary / grossSalary) * 100).toFixed(1);
+
+ updateUI(grossSalary, netSalary, ratio);
+ updateChart(grossSalary, netSalary);
+ updateDeductions(grossSalary, netSalary);
+
+ resultsDiv.classList.remove('hidden');
+ }
+
+ function calculateNetSalary(gross) {
+ // Simplified Israeli tax brackets (2023)
+ let tax = 0;
+ let remaining = gross;
+
+ if (remaining > 54300) {
+ tax += (remaining - 54300) * 0.47;
+ remaining = 54300;
+ }
+ if (remaining > 45180) {
+ tax += (remaining - 45180) * 0.35;
+ remaining = 45180;
+ }
+ if (remaining > 21711) {
+ tax += (remaining - 21711) * 0.31;
+ remaining = 21711;
+ }
+ if (remaining > 9975) {
+ tax += (remaining - 9975) * 0.20;
+ remaining = 9975;
+ }
+ if (remaining > 6790) {
+ tax += (remaining - 6790) * 0.14;
+ remaining = 6790;
+ }
+ tax += remaining * 0.10;
+
+ // Social security and health insurance (approximate)
+ const socialSecurity = gross * 0.12;
+
+ return gross - tax - socialSecurity;
+ }
+
+ function updateUI(gross, net, ratio) {
+ document.getElementById('grossAmount').textContent = gross.toLocaleString();
+ document.getElementById('netAmount').textContent = net.toLocaleString();
+ document.getElementById('ratioAmount').textContent = ratio;
+ }
+
+ function updateChart(gross, net) {
+ const ctx = document.getElementById('salaryChart').getContext('2d');
+
+ if (salaryChart) {
+ salaryChart.destroy();
+ }
+
+ salaryChart = new Chart(ctx, {
+ type: 'doughnut',
+ data: {
+ labels: ['Net Salary', 'Deductions'],
+ datasets: [{
+ data: [net, gross - net],
+ backgroundColor: ['#2d5bf0', '#8c54ff']
+ }]
+ },
+ options: {
+ responsive: true,
+ maintainAspectRatio: false
+ }
+ });
+ }
+
+ function updateDeductions(gross, net) {
+ const deductions = gross - net;
+ const list = document.getElementById('deductionsList');
+ list.innerHTML = `
+
Total Deductions₪${deductions.toLocaleString()}+
Income Tax₪${(deductions * 0.7).toLocaleString()}+
Social Security₪${(deductions * 0.3).toLocaleString()}+ `;
+ }
+ });