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
@@ -105,6 +105,21 @@ function formatOptionalDate(value: string | null, formatDateRu: (isoDate: string
return value ? formatDateRu(value) : "дата не указана";
}
function findFocusedCounterpartyValuePoint(
profileRows: CounterpartyValuePoint[],
counterpartyHint: string | null | undefined,
deps: Pick<CounterpartyAnalyticsReplyDeps, "counterpartyLookupMatches">
): CounterpartyValuePoint | null {
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;
}
export function composeCounterpartyAnalyticsReply(
intent: AddressIntent,
rows: ComposeStageRow[],
@@ -605,6 +620,34 @@ export function composeCounterpartyAnalyticsReply(
return 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 buildFactualSummaryReply(summaryLines);
}
if (focus === "total_flow") {
const periodLine =
options.periodFrom && options.periodTo