chore(single-declaration): log gəlir vergisi breakdown to browser console

Server returns a tax_debug payload (per-slip, per (employee, month), and
monthly totals) and the client logs it via console.group + console.table
when payroll data is loaded. Temporary aid for the bookkeeper review —
will be removed once formulas are signed off.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ali 2026-05-08 18:36:32 +00:00
parent cecb6c255c
commit 27cbad46a8
2 changed files with 71 additions and 2 deletions

View File

@ -87,6 +87,7 @@ function reload_hisse_1_data(frm) {
frappe.dom.unfreeze();
if (r.message && r.message.success) {
log_tax_debug(r.message.tax_debug);
populate_hisse_1(frm, r.message.hisse_1_data || []);
populate_child_table(frm, 'hissə_2', r.message.hisse_2_data || []);
populate_child_table(frm, 'hissə_3', r.message.hisse_3_data || []);
@ -122,6 +123,35 @@ function reload_hisse_1_data(frm) {
});
}
function log_tax_debug(dbg) {
if (!dbg) return;
console.group('%cGəlir vergisi — расчёт', 'font-weight: bold; color: #2563eb');
console.log('Формула: tax = bracket(gross_pay custom_vergi_amount), per (employee, month), затем сумма');
console.log('Брекет: t≤2500 → t×3%; 2500<t≤8000 → 75+(t2500)×10%; t>8000 → 625+(t8000)×14%');
if (dbg.slips && dbg.slips.length) {
console.group(`Per-slip (${dbg.slips.length} слипов)`);
console.table(dbg.slips);
console.groupEnd();
} else {
console.log('Слипов нет.');
}
if (dbg.per_employee_per_month && dbg.per_employee_per_month.length) {
console.group('Per-employee × month (taxable агрегирован, брекет применён)');
console.table(dbg.per_employee_per_month);
console.groupEnd();
}
if (dbg.monthly_tax_totals) {
console.group('Итог: Bölmə 3 — Vergi məbləği');
console.table([dbg.monthly_tax_totals]);
console.groupEnd();
}
console.groupEnd();
}
function populate_hisse_1(frm, data) {
populate_child_table(frm, 'hissə_1', data);
}

View File

@ -93,7 +93,7 @@ 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_taxable = _per_employee_monthly_taxable(payroll, quarter)
emp_monthly_taxable, tax_debug_slips = _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)
@ -101,6 +101,29 @@ def populate_declaration_tables(company, year, quarter):
bolme_3_data = build_bolme_3(emp_monthly_taxable)
elave4_data = build_elave4_tables(payroll)
# Build debug breakdown for client-side console logging.
emp_month_summary = []
for (emp, mi), taxable in sorted(emp_monthly_taxable.items()):
emp_month_summary.append({
"employee": emp,
"month": mi,
"taxable_total": round(taxable, 2),
"tax": round(_calc_income_tax(taxable), 2),
})
monthly_totals = {1: 0.0, 2: 0.0, 3: 0.0}
for row in emp_month_summary:
monthly_totals[row["month"]] += row["tax"]
tax_debug = {
"slips": tax_debug_slips,
"per_employee_per_month": emp_month_summary,
"monthly_tax_totals": {
"m1": round(monthly_totals[1], 2),
"m2": round(monthly_totals[2], 2),
"m3": round(monthly_totals[3], 2),
"quarter": round(sum(monthly_totals.values()), 2),
},
}
return {
"success": True,
"hisse_1_data": hisse_1_data,
@ -108,6 +131,7 @@ def populate_declaration_tables(company, year, quarter):
"hisse_3_data": hisse_3_data,
"bolme2_hisse1_data": bolme2_hisse1_data,
"bolme_3_data": bolme_3_data,
"tax_debug": tax_debug,
**elave4_data,
}
@ -311,6 +335,9 @@ def _per_employee_monthly_taxable(payroll, quarter):
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.
Returns (taxable_dict, debug_rows) debug_rows is a per-slip breakdown for
client-side console logging.
"""
salary_slips = payroll["salary_slips"]
currency = payroll["currency"]
@ -320,6 +347,7 @@ def _per_employee_monthly_taxable(payroll, quarter):
start_month = (quarter_num - 1) * 3 + 1
result = {}
debug_rows = []
for ss in salary_slips:
month_index = ss.start_date.month - start_month + 1
if month_index not in (1, 2, 3):
@ -330,7 +358,18 @@ def _per_employee_monthly_taxable(payroll, quarter):
taxable = max(gp - exempt, 0.0)
key = (ss.employee, month_index)
result[key] = result.get(key, 0.0) + taxable
return result
debug_rows.append({
"slip": ss.name,
"employee": ss.employee,
"employee_name": ss.employee_name,
"month": month_index,
"start_date": str(ss.start_date),
"gross_pay": round(gp, 2),
"custom_vergi_amount": round(exempt, 2),
"taxable": round(taxable, 2),
"slip_tax": round(_calc_income_tax(taxable), 2),
})
return result, debug_rows
def build_bolme_3(emp_monthly_taxable):