Post-F: закрыть ручные провалы НДС, выручки и item-flow

This commit is contained in:
2026-04-24 20:36:34 +03:00
parent 7262603a26
commit 739e8b808f
16 changed files with 695 additions and 37 deletions
@@ -987,7 +987,12 @@ function extractShipmentCounterpartyValue(text: string): string | undefined {
}
function extractInstrumentalCounterpartyValue(text: string): string | undefined {
const match = String(text ?? "").match(
const source = String(text ?? "");
const match =
source.match(
/(?:\u043a\u043e\u043d\u0442\u0440\u0430\u0433\u0435\u043d\u0442\u043e\u043c|\u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u043e\u043c|\u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c|\u0437\u0430\u043a\u0430\u0437\u0447\u0438\u043a\u043e\u043c)\s+([\p{L}][\p{L}\p{N}._-]{1,})(?=[\s,.;:!?)]|$)/iu
) ??
source.match(
/(?:контрагентом|поставщиком|клиентом|заказчиком)\s+([\p{L}][\p{L}\p{N}._-]{1,})(?=[\s,.;:!?)]|$)/iu
);
if (!match) {
@@ -2031,6 +2031,43 @@ function resolveUnicodeAddressIntentBridge(text: string): AddressIntentResolutio
normalized
);
const hasOpenItemsAccountCue =
/(?:хвост|долг|незакрыт|вис)/iu.test(normalized) &&
/(?:сч(?:е|ё)т(?:а|у|ом|е|ов)?\s*(?:|#)?\s*(?:60|62|76)(?:[.,]\d{1,2})?|\b(?:60|62|76)(?:[.,]\d{1,2})?\b\s*сч(?:е|ё)т)/iu.test(
normalized
);
if (hasOpenItemsAccountCue) {
return unicodeBridgeResolution(
"open_items_by_counterparty_or_contract",
"medium",
"open_items_signal_detected"
);
}
const hasCounterpartyShipmentItemFlowCue =
/(?:отгруж(?:ал|али|ен[аоы]?|енн(?:ый|ая|ое|ые)?))/iu.test(normalized) &&
/(?:товар|услуг|позици|номенклатур)/iu.test(normalized) &&
!/(?:выбранн(?:ый|ому)\s+объект|selected\s+object)/iu.test(normalized);
if (hasCounterpartyShipmentItemFlowCue) {
return unicodeBridgeResolution(
"list_documents_by_counterparty",
"medium",
"counterparty_item_flow_signal_detected"
);
}
const hasHighestValueCustomerCue =
/(?:сам(?:ый|ые|ая|ое)|топ|кто|какой|какие|больше\s+всего|наибольш)/iu.test(normalized) &&
/(?:доходн|выручк|денег|деньг|оборот|поступлен|прин[её]с)/iu.test(normalized) &&
/(?:клиент|покупател|заказчик|контрагент)/iu.test(normalized);
if (!hasContractCue && hasHighestValueCustomerCue) {
return unicodeBridgeResolution(
"customer_revenue_and_payments",
"high",
"unicode_customer_revenue_bridge_signal_detected"
);
}
if (hasBidirectionalValueFlowComparisonSignal(normalized)) {
return unicodeBridgeResolution(
"unknown",
@@ -2419,14 +2456,21 @@ function resolveUnicodeAddressIntentBridge(text: string): AddressIntentResolutio
if (/(?:ндс|vat)/iu.test(normalized)) {
const hasVatDebtCue = /(?:долг|должн|подтвержд)/iu.test(normalized);
const hasTaxPeriodCue = /(?:налогов|налоговую|бюджет|декларац|квартал|\b[1-4]\s*кв)/iu.test(normalized);
const hasVatMonthPeriodCue =
/(?:за|на|в)\s+(?:январ|феврал|март|апрел|ма[йя]|июн|июл|август|сентябр|октябр|ноябр|декабр)\S*(?:\s+(?:19|20)\d{2})?/iu.test(
normalized
) &&
!/\b\d{1,2}\s+(?:январ|феврал|март|апрел|ма[йя]|июн|июл|август|сентябр|октябр|ноябр|декабр)\S*(?:\s+(?:19|20)\d{2})?/iu.test(
normalized
);
if (
hasTaxPeriodCue &&
(hasTaxPeriodCue || (hasVatMonthPeriodCue && !hasVatDebtCue)) &&
/(?:скольк|скока|надо|нужно|заплат|уплат|оплат|прикин)/iu.test(normalized)
) {
return unicodeBridgeResolution(
"vat_liability_confirmed_for_tax_period",
"high",
"vat_tax_period_confirmed_signal_detected"
"vat_liability_confirmed_tax_period_signal_detected"
);
}
if (
@@ -608,7 +608,7 @@ const CONTRACTS_BY_COUNTERPARTY_QUERY_TEMPLATE = `
const VAT_PAYABLE_FORECAST_QUERY_TEMPLATE = `
ВЫБРАТЬ
ДАТАВРЕМЯ(2000, 1, 1, 0, 0, 0) КАК Период,
__PERIOD_EXPR__ КАК Период,
"VAT_68_CREDIT" КАК Регистратор,
"68" КАК СчетДт,
"" КАК СчетКт,
@@ -622,7 +622,7 @@ const VAT_PAYABLE_FORECAST_QUERY_TEMPLATE = `
__WHERE_CLAUSE__
ОБЪЕДИНИТЬ ВСЕ
ВЫБРАТЬ
ДАТАВРЕМЯ(2000, 1, 1, 0, 0, 0) КАК Период,
__PERIOD_EXPR__ КАК Период,
"VAT_68_DEBIT" КАК Регистратор,
"68" КАК СчетДт,
"" КАК СчетКт,
@@ -636,7 +636,7 @@ __WHERE_CLAUSE__
__WHERE_CLAUSE__
ОБЪЕДИНИТЬ ВСЕ
ВЫБРАТЬ
ДАТАВРЕМЯ(2000, 1, 1, 0, 0, 0) КАК Период,
__PERIOD_EXPR__ КАК Период,
"VAT_19_DEBIT" КАК Регистратор,
"19" КАК СчетДт,
"" КАК СчетКт,
@@ -650,7 +650,7 @@ __WHERE_CLAUSE__
__WHERE_CLAUSE__
ОБЪЕДИНИТЬ ВСЕ
ВЫБРАТЬ
ДАТАВРЕМЯ(2000, 1, 1, 0, 0, 0) КАК Период,
__PERIOD_EXPR__ КАК Период,
"VAT_19_CREDIT" КАК Регистратор,
"19" КАК СчетДт,
"" КАК СчетКт,
@@ -1546,12 +1546,26 @@ export function buildAddressRecipePlan(
)
.replaceAll("__ORDER_DIRECTION__", resolveOrderDirection(filters.sort))
: recipe.query_template === "vat_payable_forecast_profile"
? VAT_PAYABLE_FORECAST_QUERY_TEMPLATE
.replaceAll("__WHERE_CLAUSE__", buildManagementWhereClause(filters, "Движения.Период"))
.replaceAll("__VAT68_KT_MATCH__", buildAccountPrefixPredicate("Движения.СчетКт", VAT_PAYABLE_68_PREFIXES))
.replaceAll("__VAT68_DT_MATCH__", buildAccountPrefixPredicate("Движения.СчетДт", VAT_PAYABLE_68_PREFIXES))
.replaceAll("__VAT19_DT_MATCH__", buildAccountPrefixPredicate("Движения.СчетДт", VAT_PAYABLE_19_PREFIXES))
.replaceAll("__VAT19_KT_MATCH__", buildAccountPrefixPredicate("Движения.СчетКт", VAT_PAYABLE_19_PREFIXES))
? (() => {
const periodExpr =
(typeof filters.period_to === "string" && filters.period_to.trim().length > 0
? toDateTimeExpr(filters.period_to, true)
: null) ??
(typeof filters.as_of_date === "string" && filters.as_of_date.trim().length > 0
? toDateTimeExpr(filters.as_of_date, true)
: null) ??
(typeof filters.period_from === "string" && filters.period_from.trim().length > 0
? toDateTimeExpr(filters.period_from, true)
: null) ??
"ДАТАВРЕМЯ(2000, 1, 1, 0, 0, 0)";
return VAT_PAYABLE_FORECAST_QUERY_TEMPLATE
.replaceAll("__WHERE_CLAUSE__", buildManagementWhereClause(filters, "Движения.Период"))
.replaceAll("__PERIOD_EXPR__", periodExpr)
.replaceAll("__VAT68_KT_MATCH__", buildAccountPrefixPredicate("Движения.СчетКт", VAT_PAYABLE_68_PREFIXES))
.replaceAll("__VAT68_DT_MATCH__", buildAccountPrefixPredicate("Движения.СчетДт", VAT_PAYABLE_68_PREFIXES))
.replaceAll("__VAT19_DT_MATCH__", buildAccountPrefixPredicate("Движения.СчетДт", VAT_PAYABLE_19_PREFIXES))
.replaceAll("__VAT19_KT_MATCH__", buildAccountPrefixPredicate("Движения.СчетКт", VAT_PAYABLE_19_PREFIXES));
})()
: recipe.query_template === "vat_liability_confirmed_tax_period_profile"
? (() => {
const periodToExpr =
@@ -1439,6 +1439,8 @@ function deriveIntentWithFollowupContext(
return detectedIntent;
}
const previousFilters = followupContext.previous_filters ?? {};
const previousPeriodFrom = toNonEmptyString(previousFilters.period_from);
const previousPeriodTo = toNonEmptyString(previousFilters.period_to);
const previousContract = toNonEmptyString(previousFilters.contract);
const previousCounterparty = toNonEmptyString(previousFilters.counterparty);
const previousContractFromAnchor =
@@ -1449,6 +1451,10 @@ function deriveIntentWithFollowupContext(
const hasPreviousCounterparty = Boolean(previousCounterparty ?? previousCounterpartyFromAnchor);
const hasAnyPartyAnchor = hasPreviousContract || hasPreviousCounterparty;
const isVatFollowup = hasVatCue(normalizedMessage);
const samePeriodVatFollowup =
isVatFollowup &&
hasSamePeriodHint(normalizedMessage) &&
Boolean(previousPeriodFrom || previousPeriodTo);
const previousIsInventoryFamily = isInventoryIntent(sourceIntent ?? undefined);
const rootIsInventoryFamily = isInventoryIntent(followupContext.root_intent ?? undefined);
const inventoryLineageActive =
@@ -1472,7 +1478,8 @@ function deriveIntentWithFollowupContext(
inventoryPurchaseDateVatBridge &&
(detectedIntent.intent === "unknown" ||
detectedIntent.intent === sourceIntent ||
detectedIntent.intent === "vat_payable_confirmed_as_of_date")
detectedIntent.intent === "vat_payable_confirmed_as_of_date" ||
detectedIntent.intent === "vat_payable_forecast")
) {
return {
intent: "vat_liability_confirmed_for_tax_period",
@@ -1481,6 +1488,19 @@ function deriveIntentWithFollowupContext(
};
}
if (
samePeriodVatFollowup &&
(detectedIntent.intent === "vat_payable_confirmed_as_of_date" ||
detectedIntent.intent === "vat_payable_forecast" ||
detectedIntent.intent === "unknown")
) {
return {
intent: "vat_liability_confirmed_for_tax_period",
confidence: "low",
reasons: [...detectedIntent.reasons, "intent_adjusted_to_vat_same_period_followup"]
};
}
if (detectedIntent.intent === "unknown" && isVatFollowup) {
const vatIntent: AddressIntent = hasVatTaxPaymentCue(normalizedMessage)
? "vat_liability_confirmed_for_tax_period"