fix(single-declaration): exclude income-tax-exempt amount before bracket
Apply gəlir vergisi brackets to (gross_pay − custom_vergi_amount), not raw gross. Slips marked azadolma drop to 0 contribution, matching how the formula editor fills the tax-base column. Affects bölmə 3 hissə 1 and əlavə 1 hissə 1 vergi məbləği. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
caedd576b1
commit
cecb6c255c
|
|
@ -93,12 +93,12 @@ def populate_declaration_tables(company, year, quarter):
|
|||
|
||||
# Fetch payroll data once, build hissə_1 and hissə_2 from it
|
||||
payroll = fetch_payroll_data(company, from_date, to_date)
|
||||
emp_monthly_gross = _per_employee_monthly_gross(payroll, quarter)
|
||||
hisse_1_data = build_hisse_1(payroll, emp_monthly_gross)
|
||||
emp_monthly_taxable = _per_employee_monthly_taxable(payroll, quarter)
|
||||
hisse_1_data = build_hisse_1(payroll, emp_monthly_taxable)
|
||||
hisse_2_data = build_hisse_2(payroll)
|
||||
hisse_3_data = get_absence_data(company, from_date, to_date)
|
||||
bolme2_hisse1_data = get_bolme2_hisse1_data(company, year, quarter)
|
||||
bolme_3_data = build_bolme_3(emp_monthly_gross)
|
||||
bolme_3_data = build_bolme_3(emp_monthly_taxable)
|
||||
elave4_data = build_elave4_tables(payroll)
|
||||
|
||||
return {
|
||||
|
|
@ -202,14 +202,14 @@ def fetch_payroll_data(company, from_date, to_date):
|
|||
}
|
||||
|
||||
|
||||
def build_hisse_1(payroll, emp_monthly_gross):
|
||||
def build_hisse_1(payroll, emp_monthly_taxable):
|
||||
"""Build hissə_1 rows from aggregated payroll data."""
|
||||
employee_map = payroll["employee_map"]
|
||||
fin_map = payroll["fin_map"]
|
||||
|
||||
emp_quarterly_tax = {}
|
||||
for (emp, _mi), gross in emp_monthly_gross.items():
|
||||
emp_quarterly_tax[emp] = emp_quarterly_tax.get(emp, 0.0) + _calc_income_tax(gross)
|
||||
for (emp, _mi), taxable in emp_monthly_taxable.items():
|
||||
emp_quarterly_tax[emp] = emp_quarterly_tax.get(emp, 0.0) + _calc_income_tax(taxable)
|
||||
|
||||
result = []
|
||||
for agg in employee_map.values():
|
||||
|
|
@ -305,8 +305,13 @@ def _calc_income_tax(gross):
|
|||
return 625 + (gross - 8000) * 0.14
|
||||
|
||||
|
||||
def _per_employee_monthly_gross(payroll, quarter):
|
||||
"""Group salary slips into {(employee, month_index_1to3): gross_pay_sum}."""
|
||||
def _per_employee_monthly_taxable(payroll, quarter):
|
||||
"""Group salary slips into {(employee, month_index_1to3): taxable_income_sum}.
|
||||
|
||||
Taxable = gross_pay − custom_vergi_amount per slip. Slips fully marked as
|
||||
income-tax-exempt (custom_vergi_indicator set, amount == gross_pay) drop to 0
|
||||
and don't contribute to the bracket.
|
||||
"""
|
||||
salary_slips = payroll["salary_slips"]
|
||||
currency = payroll["currency"]
|
||||
company_currency = payroll["company_currency"]
|
||||
|
|
@ -319,19 +324,20 @@ def _per_employee_monthly_gross(payroll, quarter):
|
|||
month_index = ss.start_date.month - start_month + 1
|
||||
if month_index not in (1, 2, 3):
|
||||
continue
|
||||
gp = flt(ss.gross_pay)
|
||||
if currency == company_currency:
|
||||
gp *= flt(ss.exchange_rate)
|
||||
rate = flt(ss.exchange_rate) if currency == company_currency else 1.0
|
||||
gp = flt(ss.gross_pay) * rate
|
||||
exempt = flt(ss.get("custom_vergi_amount") or 0) * rate
|
||||
taxable = max(gp - exempt, 0.0)
|
||||
key = (ss.employee, month_index)
|
||||
result[key] = result.get(key, 0.0) + gp
|
||||
result[key] = result.get(key, 0.0) + taxable
|
||||
return result
|
||||
|
||||
|
||||
def build_bolme_3(emp_monthly_gross):
|
||||
def build_bolme_3(emp_monthly_taxable):
|
||||
"""Income tax (gəlir vergisi) per month, computed per-employee then summed."""
|
||||
monthly_tax = {1: 0.0, 2: 0.0, 3: 0.0}
|
||||
for (_emp, mi), gross in emp_monthly_gross.items():
|
||||
monthly_tax[mi] += _calc_income_tax(gross)
|
||||
for (_emp, mi), taxable in emp_monthly_taxable.items():
|
||||
monthly_tax[mi] += _calc_income_tax(taxable)
|
||||
|
||||
return {
|
||||
"Muzdlu işlə əlaqədar hesablamalar": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue