Расширить proof matrix маржинальности follow-up replay

This commit is contained in:
2026-05-24 18:23:04 +03:00
parent f69393a887
commit 7cc65e808e
6 changed files with 436 additions and 8 deletions
@@ -188,6 +188,11 @@ function asksInventoryMarginFromPaymentOrBank(userMessage: string | null | undef
);
}
function asksInventoryMarginAccount41Not01(userMessage: string | null | undefined): boolean {
const text = String(userMessage ?? "").toLowerCase();
return /(?:\b41\b|41\s*сч|сч[её]т[ау]?\s*41)/iu.test(text) && /(?:\b01\b|не\s+ос|основн)/iu.test(text);
}
interface InventoryMarginRankingEntry {
item: string;
revenue: number;
@@ -659,6 +664,9 @@ export function composeInventoryReply(
const topMarginEntry = highMargin[0] ?? null;
const marginBasisRequested = asksForInventoryMarginBasis(options.userMessage);
const paymentOrBankFalseSourceRequested = asksInventoryMarginFromPaymentOrBank(options.userMessage);
const account41Not01Requested = asksInventoryMarginAccount41Not01(options.userMessage);
const withAccountScopePrefix = (line: string): string =>
account41Not01Requested ? `По счету 41, не по 01/ОС: ${line}` : line;
if (paymentOrBankFalseSourceRequested) {
const lines = [
"По оплатам и банку такой показатель нельзя честно подтвердить: платежи показывают денежный поток и факт оплаты, а не связь реализации с себестоимостью по номенклатуре."
@@ -681,9 +689,11 @@ export function composeInventoryReply(
if (confirmedEntries.length === 0) {
const costBaseRowsRequested = asksForInventoryCostBaseRows(options.userMessage);
const lines: string[] = [
costBaseRowsRequested && purchasesWithoutSales.length === 0
? `За период ${periodLabel} подтвержденных строк себестоимостной базы по реализованной номенклатуре не найдено.`
: `За период ${periodLabel} рейтинг прибыльности номенклатуры построить нельзя.`
withAccountScopePrefix(
costBaseRowsRequested && purchasesWithoutSales.length === 0
? `За период ${periodLabel} подтвержденных строк себестоимостной базы по реализованной номенклатуре не найдено.`
: `За период ${periodLabel} рейтинг прибыльности номенклатуры построить нельзя.`
)
];
const findings: string[] = [];
if (salesWithoutCost.length > 0) {
@@ -754,7 +764,7 @@ export function composeInventoryReply(
topMarginEntry.costProxy
)}, валовая разница ${deps.formatMoneyRub(topMarginEntry.spread)}.`
: `За период ${periodLabel} не удалось подтвердить рейтинг прибыльности номенклатуры: нужны одновременно строки реализации и закупочного/себестоимостного следа по товарам.`;
const lines: string[] = [directAnswerLine];
const lines: string[] = [withAccountScopePrefix(directAnswerLine)];
if (marginBasisRequested) {
appendInventoryBulletSection(lines, "База расчета:", [