Сжать долговые ответы и техничность net-flow
This commit is contained in:
@@ -2093,36 +2093,31 @@ function formatPayablesEvidenceSuffix(item) {
|
||||
const suffix = item.documents.length > 1 ? ` (+${item.documents.length - 1})` : "";
|
||||
parts.push(`документ: ${item.documents[0]}${suffix}`);
|
||||
}
|
||||
if (item.sourceRefs.length > 0) {
|
||||
parts.push(`source refs: ${item.sourceRefs.slice(0, 2).join("; ")}`);
|
||||
}
|
||||
return parts.length > 0 ? ` | ${parts.join(" | ")}` : "";
|
||||
}
|
||||
function formatDebtMirrorGroupLine(item) {
|
||||
const details = [
|
||||
item.account ? `счет ${item.account}` : null,
|
||||
item.contract ? `договор/аналитика: ${item.contract}` : null,
|
||||
item.organization ? `организация: ${item.organization}` : null
|
||||
].filter((part) => Boolean(part));
|
||||
const netText = Math.abs(item.netAmount) <= 0.005
|
||||
? "чисто: 0 ₽"
|
||||
: item.netAmount > 0
|
||||
? `чисто к получению: ${formatMoneyRub(item.netAmount)}`
|
||||
: `чисто к оплате: ${formatMoneyRub(Math.abs(item.netAmount))}`;
|
||||
return `${item.name}${details.length > 0 ? ` (${details.join(", ")})` : ""}: дебет ${formatMoneyRub(item.debitAmount)} / кредит ${formatMoneyRub(item.creditAmount)}, ${netText}.`;
|
||||
return `${item.name}: встречная часть ${formatMoneyRub(Math.min(item.debitAmount, item.creditAmount))}, ${netText}.`;
|
||||
}
|
||||
function debtMirrorCleanScopeLabel(kind) {
|
||||
return kind === "payables" ? "чистый долг к оплате" : "чистую дебиторку к получению";
|
||||
function debtMirrorCleanScopeLabel(kind, grammaticalCase) {
|
||||
if (kind === "payables") {
|
||||
return grammaticalCase === "genitive" ? "чистого долга к оплате" : "чистый долг к оплате";
|
||||
}
|
||||
return grammaticalCase === "genitive" ? "чистой дебиторки к получению" : "чистую дебиторку к получению";
|
||||
}
|
||||
function appendDebtMirrorCompactDisclosure(lines, snapshot, kind) {
|
||||
if (snapshot.mirroredOffsetAmount <= 0.005) {
|
||||
return;
|
||||
}
|
||||
lines.push("", "Для сверки:");
|
||||
lines.push(`- Отдельно сверено встречных остатков: ${formatMoneyRub(snapshot.mirroredOffsetAmount)}; они не включены в ${debtMirrorCleanScopeLabel(kind)}.`);
|
||||
lines.push(`- Встречная часть: ${formatMoneyRub(snapshot.mirroredOffsetAmount)}; она не включена в ${debtMirrorCleanScopeLabel(kind, "accusative")}.`);
|
||||
const leadingMirror = snapshot.mirrorGroups[0] ?? null;
|
||||
if (leadingMirror) {
|
||||
lines.push(`- Крупнейший встречный хвост: ${formatDebtMirrorGroupLine(leadingMirror)}`);
|
||||
lines.push(`- Крупнейший встречный контрагент: ${formatDebtMirrorGroupLine(leadingMirror)}`);
|
||||
}
|
||||
}
|
||||
function appendDebtMirrorDisclosure(lines, snapshot, kind) {
|
||||
@@ -2131,8 +2126,11 @@ function appendDebtMirrorDisclosure(lines, snapshot, kind) {
|
||||
}
|
||||
lines.push("");
|
||||
lines.push("Встречные остатки к сверке");
|
||||
lines.push(`- Встречная часть: ${formatMoneyRub(snapshot.mirroredOffsetAmount)}; она исключена из ${debtMirrorCleanScopeLabel(kind)}.`);
|
||||
lines.push(...snapshot.mirrorGroups.slice(0, 3).map((item, index) => `${index + 1}. ${formatDebtMirrorGroupLine(item)}`));
|
||||
lines.push(`- Встречная часть: ${formatMoneyRub(snapshot.mirroredOffsetAmount)}; она исключена из ${debtMirrorCleanScopeLabel(kind, "genitive")}.`);
|
||||
const leadingMirror = snapshot.mirrorGroups[0] ?? null;
|
||||
if (leadingMirror) {
|
||||
lines.push(`- Крупнейший встречный контрагент: ${formatDebtMirrorGroupLine(leadingMirror)}`);
|
||||
}
|
||||
}
|
||||
function deriveOperationalYearWindow(yearDocs, yearOps) {
|
||||
const docsSeries = [...yearDocs].sort((a, b) => a.year - b.year);
|
||||
@@ -3381,8 +3379,7 @@ function composeFactualReplyBody(intent, rows, options = {}) {
|
||||
: [`Коротко: на ${formatDateRu(payablesAsOfDate)} подтвержденных обязательств к оплате не найдено.`];
|
||||
if (leading) {
|
||||
compactLines.push(...confirmedBalances.slice(0, 5).map((item, index) => {
|
||||
const lastPeriod = item.lastPeriod ? `, последнее движение: ${item.lastPeriod}` : "";
|
||||
return `${index + 1}. ${item.name} — ${formatMoneyRub(item.outstandingAmount)} (${formatNumberWithDots(item.operations)} опер.${lastPeriod}).`;
|
||||
return `${index + 1}. ${item.name} — ${formatMoneyRub(item.outstandingAmount)} (${formatNumberWithDots(item.operations)} опер.).`;
|
||||
}));
|
||||
if (confirmedBalances.length > 5) {
|
||||
compactLines.push(`Показаны первые 5 из ${formatNumberWithDots(confirmedBalances.length)} подтвержденных позиций.`);
|
||||
@@ -3429,7 +3426,7 @@ function composeFactualReplyBody(intent, rows, options = {}) {
|
||||
lines.push("Подтвержденные позиции к оплате");
|
||||
if (confirmedBalances.length > 0) {
|
||||
lines.push(...confirmedBalances.slice(0, 10).flatMap((item, index) => [
|
||||
`${index + 1}. ${item.name} | категория: ${liabilityCategoryLabel(item.category)} | остаток: ${formatMoneyRub(item.outstandingAmount)} | операций: ${formatNumberWithDots(item.operations)}${item.lastPeriod ? ` | последнее движение: ${item.lastPeriod}` : ""}${item.categoryReasons.length > 0 ? ` | основание: ${item.categoryReasons.join(", ")}` : ""}${formatPayablesEvidenceSuffix(item)}`,
|
||||
`${index + 1}. ${item.name} | категория: ${liabilityCategoryLabel(item.category)} | остаток: ${formatMoneyRub(item.outstandingAmount)} | операций: ${formatNumberWithDots(item.operations)}${item.categoryReasons.length > 0 ? ` | основание: ${item.categoryReasons.join(", ")}` : ""}${formatPayablesEvidenceSuffix(item)}`,
|
||||
""
|
||||
]));
|
||||
if (lines[lines.length - 1] === "") {
|
||||
@@ -3477,8 +3474,7 @@ function composeFactualReplyBody(intent, rows, options = {}) {
|
||||
: [`Коротко: на ${formatDateRu(receivablesAsOfDate)} подтвержденной дебиторской задолженности не найдено.`];
|
||||
if (leading) {
|
||||
compactLines.push(...confirmedBalances.slice(0, 5).map((item, index) => {
|
||||
const lastPeriod = item.lastPeriod ? `, последнее движение: ${item.lastPeriod}` : "";
|
||||
return `${index + 1}. ${item.name} — ${formatMoneyRub(item.outstandingAmount)} (${formatNumberWithDots(item.operations)} опер.${lastPeriod}).`;
|
||||
return `${index + 1}. ${item.name} — ${formatMoneyRub(item.outstandingAmount)} (${formatNumberWithDots(item.operations)} опер.).`;
|
||||
}));
|
||||
if (confirmedBalances.length > 5) {
|
||||
compactLines.push(`Показаны первые 5 из ${formatNumberWithDots(confirmedBalances.length)} подтвержденных позиций.`);
|
||||
@@ -3525,7 +3521,7 @@ function composeFactualReplyBody(intent, rows, options = {}) {
|
||||
lines.push("Подтвержденные позиции к получению");
|
||||
if (confirmedBalances.length > 0) {
|
||||
lines.push(...confirmedBalances.slice(0, 10).flatMap((item, index) => [
|
||||
`${index + 1}. ${item.name} | категория: ${receivablesCategoryLabel(item.category)} | остаток к получению: ${formatMoneyRub(item.outstandingAmount)} | операций: ${formatNumberWithDots(item.operations)}${item.lastPeriod ? ` | последнее движение: ${item.lastPeriod}` : ""}${item.categoryReasons.length > 0 ? ` | основание: ${item.categoryReasons.join(", ")}` : ""}${formatPayablesEvidenceSuffix(item)}`,
|
||||
`${index + 1}. ${item.name} | категория: ${receivablesCategoryLabel(item.category)} | остаток к получению: ${formatMoneyRub(item.outstandingAmount)} | операций: ${formatNumberWithDots(item.operations)}${item.categoryReasons.length > 0 ? ` | основание: ${item.categoryReasons.join(", ")}` : ""}${formatPayablesEvidenceSuffix(item)}`,
|
||||
""
|
||||
]));
|
||||
if (lines[lines.length - 1] === "") {
|
||||
@@ -3559,7 +3555,7 @@ function composeFactualReplyBody(intent, rows, options = {}) {
|
||||
const carryoverLine = asOfDate || periodFrom || periodTo
|
||||
? "- В список могут попадать обязательства, возникшие раньше выбранного периода, если они потенциально оставались открытыми на дату среза."
|
||||
: null;
|
||||
const formatHeuristicItem = (item, index) => `${index + 1}. ${item.name} | сумма к проверке: ${formatMoneyRub(item.totalAmount)} | операций: ${formatNumberWithDots(item.operations)}${item.lastPeriod ? ` | последнее движение: ${item.lastPeriod}` : ""}${item.categoryReasons.length > 0 ? ` | основание: ${item.categoryReasons.join(", ")}` : ""}`;
|
||||
const formatHeuristicItem = (item, index) => `${index + 1}. ${item.name} | сумма к проверке: ${formatMoneyRub(item.totalAmount)} | операций: ${formatNumberWithDots(item.operations)}${item.categoryReasons.length > 0 ? ` | основание: ${item.categoryReasons.join(", ")}` : ""}`;
|
||||
const pushCategorySlice = (lines, title, items, limit) => {
|
||||
if (items.length === 0) {
|
||||
return;
|
||||
@@ -3656,7 +3652,7 @@ function composeFactualReplyBody(intent, rows, options = {}) {
|
||||
`- ${liabilityCategoryLabel("other")}: ${formatNumberWithDots(categoryCounts.other)}`,
|
||||
"",
|
||||
"Блок 5. Крупнейшие подтвержденные позиции к оплате (по сумме остатка):",
|
||||
...confirmedBalances.slice(0, 10).map((item, index) => `${index + 1}. ${item.name} | категория: ${liabilityCategoryLabel(item.category)} | остаток к оплате: ${formatMoneyRub(item.outstandingAmount)} | операций в срезе: ${formatNumberWithDots(item.operations)}${item.lastPeriod ? ` | последнее движение: ${item.lastPeriod}` : ""}${item.categoryReasons.length > 0 ? ` | основание: ${item.categoryReasons.join(", ")}` : ""}${formatPayablesEvidenceSuffix(item)}`)
|
||||
...confirmedBalances.slice(0, 10).map((item, index) => `${index + 1}. ${item.name} | категория: ${liabilityCategoryLabel(item.category)} | остаток к оплате: ${formatMoneyRub(item.outstandingAmount)} | операций в срезе: ${formatNumberWithDots(item.operations)}${item.categoryReasons.length > 0 ? ` | основание: ${item.categoryReasons.join(", ")}` : ""}${formatPayablesEvidenceSuffix(item)}`)
|
||||
];
|
||||
appendDebtMirrorDisclosure(lines, balanceSnapshot, "payables");
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user