ARCH: выровнять ответ с текущим смыслом оборота контрагента

This commit is contained in:
2026-04-19 21:48:01 +03:00
parent f75be32e41
commit f7b378ebc5
3 changed files with 115 additions and 1 deletions
@@ -20,6 +20,16 @@ function groupRowsByMarker(rows) {
function formatOptionalDate(value, formatDateRu) {
return value ? formatDateRu(value) : "дата не указана";
}
function findFocusedCounterpartyValuePoint(profileRows, counterpartyHint, deps) {
if (!counterpartyHint) {
return null;
}
const matched = profileRows.find((item) => deps.counterpartyLookupMatches(item.name, counterpartyHint));
if (matched) {
return matched;
}
return profileRows.length === 1 ? profileRows[0] : null;
}
function composeCounterpartyAnalyticsReply(intent, rows, options = {}, deps) {
if (intent === "counterparty_population_and_roles") {
const rowsByMarker = groupRowsByMarker(rows);
@@ -459,6 +469,31 @@ function composeCounterpartyAnalyticsReply(intent, rows, options = {}, deps) {
lines.push("По выбранному окну данных платежные строки не найдены.");
return (0, replyContracts_1.buildFactualSummaryReply)(lines);
}
const focusedCounterparty = focus === "top_by_total" || focus === "total_flow"
? findFocusedCounterpartyValuePoint(profileRows, options.counterpartyHint, deps)
: null;
if (focusedCounterparty) {
const periodLabel = options.periodFrom && options.periodTo
? `за период ${deps.formatDateRu(options.periodFrom)}..${deps.formatDateRu(options.periodTo)}`
: "за доступное время";
const directAnswerLine = isSupplier
? `Оборот по ${focusedCounterparty.name} ${periodLabel}: ${deps.formatMoneyRub(focusedCounterparty.total)} по ${focusedCounterparty.ops} подтвержденным исходящим операциям. Это денежный поток по поставщику, а не итоговая задолженность.`
: `Оборот по ${focusedCounterparty.name} ${periodLabel}: ${deps.formatMoneyRub(focusedCounterparty.total)} по ${focusedCounterparty.ops} подтвержденным входящим операциям. Это денежный поток от клиента, а не чистая прибыль.`;
const summaryLines = [
directAnswerLine,
"",
"Подтверждение:",
`- Контрагент в выборке: ${focusedCounterparty.name}.`,
`- Операций: ${focusedCounterparty.ops}.`
];
if (focusedCounterparty.lastPeriod) {
summaryLines.push(`- Последняя подтвержденная операция: ${deps.formatDateRu(focusedCounterparty.lastPeriod)}.`);
}
if (profileRows.length > 1) {
summaryLines.push(`- Всего контрагентов в срезе: ${profileRows.length}.`);
}
return (0, replyContracts_1.buildFactualSummaryReply)(summaryLines);
}
if (focus === "total_flow") {
const periodLine = options.periodFrom && options.periodTo
? `За период ${deps.formatDateRu(options.periodFrom)}..${deps.formatDateRu(options.periodTo)} подтверждено ${deps.formatMoneyRub(totalFlow)} ${isSupplier ? "исходящих выплат" : "входящих поступлений"}.`