Changed around line 1
+ function calculateNetSalary(gross) {
+ // Simplified Israeli tax calculation
+ const taxBrackets = [
+ { min: 0, max: 6790, rate: 0.10 },
+ { min: 6791, max: 9730, rate: 0.14 },
+ { min: 9731, max: 15620, rate: 0.20 },
+ { min: 15621, max: 21710, rate: 0.31 },
+ { min: 21711, max: 45180, rate: 0.35 },
+ { min: 45181, max: Infinity, rate: 0.47 }
+ ];
+
+ let tax = 0;
+ for (const bracket of taxBrackets) {
+ if (gross > bracket.min) {
+ const taxableAmount = Math.min(gross, bracket.max) - bracket.min;
+ tax += taxableAmount * bracket.rate;
+ }
+ }
+
+ // Social security and health tax (12%)
+ const socialTax = gross * 0.12;
+
+ const net = gross - tax - socialTax;
+ return Math.max(0, net);
+ }
+
+ function updateChart(gross, net) {
+ const ctx = document.getElementById('salaryChart').getContext('2d');
+
+ if (window.myChart) {
+ window.myChart.destroy();
+ }
+
+ window.myChart = new Chart(ctx, {
+ type: 'doughnut',
+ data: {
+ labels: ['Gross Salary', 'Net Salary'],
+ datasets: [{
+ data: [gross, net],
+ backgroundColor: [
+ 'rgba(52, 152, 219, 0.8)',
+ 'rgba(46, 204, 113, 0.8)'
+ ],
+ borderWidth: 0
+ }]
+ },
+ options: {
+ responsive: true,
+ maintainAspectRatio: false,
+ plugins: {
+ legend: {
+ position: 'bottom',
+ labels: {
+ font: {
+ size: 14
+ }
+ }
+ },
+ tooltip: {
+ callbacks: {
+ label: function(context) {
+ return `${context.label}: ₪${context.raw.toLocaleString()}`;
+ }
+ }
+ }
+ }
+ }
+ });
+ }
+
+ document.getElementById('calculateBtn').addEventListener('click', function() {
+ const gross = parseFloat(document.getElementById('grossSalary').value);
+ if (isNaN(gross) || gross <= 0) {
+ alert('Please enter a valid gross salary');
+ return;
+ }
+
+ const net = calculateNetSalary(gross);
+ const ratio = (net / gross).toFixed(2);
+
+ document.getElementById('ratioValue').textContent = ratio;
+ updateChart(gross, net);
+ });