chore(single-declaration): rewrite tax debug log as a single shareable block
Replaces the console.group/console.table layout with one structured text block per request: shows source fields (gross_pay, custom_vergi_amount), formula, per-slip breakdown with bracket explanation, and per-month sum arithmetic. Easy to select-all and forward to the bookkeeper. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
27cbad46a8
commit
dacbd980dd
|
|
@ -125,31 +125,82 @@ 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+(t−2500)×10%; t>8000 → 625+(t−8000)×14%');
|
||||
const fmt = n => Number(n).toFixed(2);
|
||||
const bracketExplain = t => {
|
||||
if (t <= 0) return `(Ə/h = 0) → налог = 0`;
|
||||
if (t <= 2500) return `(Ə/h ≤ 2500) → ${fmt(t)} × 3%`;
|
||||
if (t <= 8000) return `(2500 < Ə/h ≤ 8000) → 75 + (${fmt(t)} − 2500) × 10%`;
|
||||
return `(Ə/h > 8000) → 625 + (${fmt(t)} − 8000) × 14%`;
|
||||
};
|
||||
|
||||
if (dbg.slips && dbg.slips.length) {
|
||||
console.group(`Per-slip (${dbg.slips.length} слипов)`);
|
||||
console.table(dbg.slips);
|
||||
console.groupEnd();
|
||||
} else {
|
||||
console.log('Слипов нет.');
|
||||
const HR = '═'.repeat(72);
|
||||
const hr = '─'.repeat(72);
|
||||
|
||||
let out = '';
|
||||
out += `${HR}\n`;
|
||||
out += `GƏLİR VERGİSİ — детальный расчёт\n`;
|
||||
out += `${HR}\n\n`;
|
||||
out += `Источники данных (берутся напрямую из БД):\n`;
|
||||
out += ` • gross_pay — поле Gross Pay на Salary Slip\n`;
|
||||
out += ` • custom_vergi_amount — Salary Slip → таб Tax Free → Vergi → Amount\n\n`;
|
||||
out += `Формула:\n`;
|
||||
out += ` Ə/h = max(gross_pay − custom_vergi_amount, 0) ← per slip\n`;
|
||||
out += ` Налог по брекету (применяется отдельно к каждому слипу):\n`;
|
||||
out += ` • Ə/h ≤ 2500 → Ə/h × 3%\n`;
|
||||
out += ` • 2500 < Ə/h ≤ 8000 → 75 + (Ə/h − 2500) × 10%\n`;
|
||||
out += ` • Ə/h > 8000 → 625 + (Ə/h − 8000) × 14%\n\n`;
|
||||
|
||||
if (!dbg.slips || !dbg.slips.length) {
|
||||
out += `Слипов в выбранном квартале нет → налог 0.\n${HR}`;
|
||||
console.log(out);
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
const byMonth = {};
|
||||
for (const s of dbg.slips) {
|
||||
(byMonth[s.month] = byMonth[s.month] || []).push(s);
|
||||
}
|
||||
|
||||
if (dbg.monthly_tax_totals) {
|
||||
console.group('Итог: Bölmə 3 — Vergi məbləği');
|
||||
console.table([dbg.monthly_tax_totals]);
|
||||
console.groupEnd();
|
||||
out += `${hr}\nРАЗБОР ПО СОТРУДНИКАМ И СЛИПАМ:\n`;
|
||||
for (const m of [1, 2, 3]) {
|
||||
const slips = byMonth[m];
|
||||
if (!slips || !slips.length) continue;
|
||||
out += `\n[Месяц ${m}]\n`;
|
||||
for (const s of slips) {
|
||||
out += `\n ▸ ${s.employee_name} (${s.employee})\n`;
|
||||
out += ` Slip: ${s.slip}\n`;
|
||||
out += ` gross_pay = ${fmt(s.gross_pay)}\n`;
|
||||
out += ` custom_vergi_amount = ${fmt(s.custom_vergi_amount)} `;
|
||||
if (Number(s.custom_vergi_amount) === 0) {
|
||||
out += `(не помечен как azadolma)\n`;
|
||||
} else if (Number(s.custom_vergi_amount) >= Number(s.gross_pay)) {
|
||||
out += `(полностью azadolma → налог 0)\n`;
|
||||
} else {
|
||||
out += `(частично azadolma)\n`;
|
||||
}
|
||||
out += ` Ə/h = ${fmt(s.gross_pay)} − ${fmt(s.custom_vergi_amount)} = ${fmt(s.taxable)}\n`;
|
||||
out += ` Брекет: ${bracketExplain(s.taxable)} = ${fmt(s.slip_tax)}\n`;
|
||||
}
|
||||
}
|
||||
|
||||
console.groupEnd();
|
||||
out += `\n${hr}\nИТОГ ПО МЕСЯЦАМ:\n`;
|
||||
let qsum = 0;
|
||||
for (const m of [1, 2, 3]) {
|
||||
const slips = byMonth[m] || [];
|
||||
if (!slips.length) {
|
||||
out += ` Месяц ${m}: — (слипов нет)\n`;
|
||||
continue;
|
||||
}
|
||||
const parts = slips.map(s => fmt(s.slip_tax));
|
||||
const total = slips.reduce((a, s) => a + s.slip_tax, 0);
|
||||
qsum += total;
|
||||
out += ` Месяц ${m}: ${parts.join(' + ')} = ${fmt(total)}\n`;
|
||||
}
|
||||
out += ` ${'─'.repeat(40)}\n`;
|
||||
out += ` КВАРТАЛ: ${fmt(qsum)}\n`;
|
||||
out += `\n${HR}`;
|
||||
|
||||
console.log(out);
|
||||
}
|
||||
|
||||
function populate_hisse_1(frm, data) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue