feat(single-declaration): fill vergi məbləği in əlavə 1 hissə 1
Per-employee quarterly income tax: brackets applied to each month's gross pay, then summed for the quarter. Reuses the same per-month gross helper as bölmə 3. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2e15e9dae4
commit
caedd576b1
|
|
@ -93,11 +93,12 @@ def populate_declaration_tables(company, year, quarter):
|
||||||
|
|
||||||
# Fetch payroll data once, build hissə_1 and hissə_2 from it
|
# Fetch payroll data once, build hissə_1 and hissə_2 from it
|
||||||
payroll = fetch_payroll_data(company, from_date, to_date)
|
payroll = fetch_payroll_data(company, from_date, to_date)
|
||||||
hisse_1_data = build_hisse_1(payroll)
|
emp_monthly_gross = _per_employee_monthly_gross(payroll, quarter)
|
||||||
|
hisse_1_data = build_hisse_1(payroll, emp_monthly_gross)
|
||||||
hisse_2_data = build_hisse_2(payroll)
|
hisse_2_data = build_hisse_2(payroll)
|
||||||
hisse_3_data = get_absence_data(company, from_date, to_date)
|
hisse_3_data = get_absence_data(company, from_date, to_date)
|
||||||
bolme2_hisse1_data = get_bolme2_hisse1_data(company, year, quarter)
|
bolme2_hisse1_data = get_bolme2_hisse1_data(company, year, quarter)
|
||||||
bolme_3_data = build_bolme_3(payroll, quarter)
|
bolme_3_data = build_bolme_3(emp_monthly_gross)
|
||||||
elave4_data = build_elave4_tables(payroll)
|
elave4_data = build_elave4_tables(payroll)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -201,18 +202,23 @@ def fetch_payroll_data(company, from_date, to_date):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def build_hisse_1(payroll):
|
def build_hisse_1(payroll, emp_monthly_gross):
|
||||||
"""Build hissə_1 rows from aggregated payroll data."""
|
"""Build hissə_1 rows from aggregated payroll data."""
|
||||||
employee_map = payroll["employee_map"]
|
employee_map = payroll["employee_map"]
|
||||||
fin_map = payroll["fin_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)
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
for agg in employee_map.values():
|
for agg in employee_map.values():
|
||||||
|
emp = agg["employee"]
|
||||||
child_row = {
|
child_row = {
|
||||||
"soyadadataadı": agg["employee_name"],
|
"soyadadataadı": agg["employee_name"],
|
||||||
"fin": fin_map.get(agg["employee"], ""),
|
"fin": fin_map.get(emp, ""),
|
||||||
"gəlirlərcəmi": agg.get(frappe.scrub("Əsas əmək haqqı"), 0),
|
"gəlirlərcəmi": agg.get(frappe.scrub("Əsas əmək haqqı"), 0),
|
||||||
# vergiməbləği intentionally not filled
|
"vergiməbləği": round(emp_quarterly_tax.get(emp, 0.0), 2),
|
||||||
"hesablanmışmdsshaqqı": flt(agg.get(_DSMF_ISCI, 0)) + flt(agg.get(_DSMF_SIRKET, 0)),
|
"hesablanmışmdsshaqqı": flt(agg.get(_DSMF_ISCI, 0)) + flt(agg.get(_DSMF_SIRKET, 0)),
|
||||||
"hesablanmışişsizlikdənsığortahaqqı": flt(agg.get(_ISSIZLIK_ISCI, 0)) + flt(agg.get(_ISSIZLIK_SIRKET, 0)),
|
"hesablanmışişsizlikdənsığortahaqqı": flt(agg.get(_ISSIZLIK_ISCI, 0)) + flt(agg.get(_ISSIZLIK_SIRKET, 0)),
|
||||||
"hesablanmışicbaritibbisığortahaqqı": flt(agg.get(_ITS_ISCI, 0)) + flt(agg.get(_ITS_SIRKET, 0)),
|
"hesablanmışicbaritibbisığortahaqqı": flt(agg.get(_ITS_ISCI, 0)) + flt(agg.get(_ITS_SIRKET, 0)),
|
||||||
|
|
@ -299,8 +305,8 @@ def _calc_income_tax(gross):
|
||||||
return 625 + (gross - 8000) * 0.14
|
return 625 + (gross - 8000) * 0.14
|
||||||
|
|
||||||
|
|
||||||
def build_bolme_3(payroll, quarter):
|
def _per_employee_monthly_gross(payroll, quarter):
|
||||||
"""Income tax (gəlir vergisi) per month, computed per-employee then summed."""
|
"""Group salary slips into {(employee, month_index_1to3): gross_pay_sum}."""
|
||||||
salary_slips = payroll["salary_slips"]
|
salary_slips = payroll["salary_slips"]
|
||||||
currency = payroll["currency"]
|
currency = payroll["currency"]
|
||||||
company_currency = payroll["company_currency"]
|
company_currency = payroll["company_currency"]
|
||||||
|
|
@ -308,7 +314,7 @@ def build_bolme_3(payroll, quarter):
|
||||||
quarter_num = int(quarter[0])
|
quarter_num = int(quarter[0])
|
||||||
start_month = (quarter_num - 1) * 3 + 1
|
start_month = (quarter_num - 1) * 3 + 1
|
||||||
|
|
||||||
per_emp_monthly_gross = {}
|
result = {}
|
||||||
for ss in salary_slips:
|
for ss in salary_slips:
|
||||||
month_index = ss.start_date.month - start_month + 1
|
month_index = ss.start_date.month - start_month + 1
|
||||||
if month_index not in (1, 2, 3):
|
if month_index not in (1, 2, 3):
|
||||||
|
|
@ -317,10 +323,14 @@ def build_bolme_3(payroll, quarter):
|
||||||
if currency == company_currency:
|
if currency == company_currency:
|
||||||
gp *= flt(ss.exchange_rate)
|
gp *= flt(ss.exchange_rate)
|
||||||
key = (ss.employee, month_index)
|
key = (ss.employee, month_index)
|
||||||
per_emp_monthly_gross[key] = per_emp_monthly_gross.get(key, 0.0) + gp
|
result[key] = result.get(key, 0.0) + gp
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def build_bolme_3(emp_monthly_gross):
|
||||||
|
"""Income tax (gəlir vergisi) per month, computed per-employee then summed."""
|
||||||
monthly_tax = {1: 0.0, 2: 0.0, 3: 0.0}
|
monthly_tax = {1: 0.0, 2: 0.0, 3: 0.0}
|
||||||
for (_emp, mi), gross in per_emp_monthly_gross.items():
|
for (_emp, mi), gross in emp_monthly_gross.items():
|
||||||
monthly_tax[mi] += _calc_income_tax(gross)
|
monthly_tax[mi] += _calc_income_tax(gross)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue