diff --git a/src/app/sections/tariffs/components/shops-tariffs/shops-tariffs.component.html b/src/app/sections/tariffs/components/shops-tariffs/shops-tariffs.component.html index 0d5d860b..f82c3cf5 100644 --- a/src/app/sections/tariffs/components/shops-tariffs/shops-tariffs.component.html +++ b/src/app/sections/tariffs/components/shops-tariffs/shops-tariffs.component.html @@ -19,7 +19,10 @@ ( .map((v) => formatLevelPredicate(v)), }, { - field: 'fee', + field: 'feeShare', + header: 'Fee, %', formatter: (d) => getInlineDecisions(getFees(d), filterFee) .filter(filterDecisions(d)) - .map((v) => v.value), + .map((v) => v.parts?.share), + }, + { + field: 'feeFixed', + header: 'Fee, fix', + formatter: (d) => + getInlineDecisions(getFees(d), filterFee) + .filter(filterDecisions(d)) + .map((v) => v.parts?.fixed), + }, + { + field: 'feeMin', + header: 'Fee, min', + formatter: (d) => + getInlineDecisions(getFees(d), filterFee) + .filter(filterDecisions(d)) + .map((v) => v.parts?.min), + }, + { + field: 'feeMax', + header: 'Fee, max', + formatter: (d) => + getInlineDecisions(getFees(d), filterFee) + .filter(filterDecisions(d)) + .map((v) => v.parts?.max), }, { field: 'other', diff --git a/src/app/sections/tariffs/utils/get-inline-decisions.ts b/src/app/sections/tariffs/utils/get-inline-decisions.ts index 12eb62ad..36af4715 100644 --- a/src/app/sections/tariffs/utils/get-inline-decisions.ts +++ b/src/app/sections/tariffs/utils/get-inline-decisions.ts @@ -7,11 +7,18 @@ import type { Predicate, } from '@vality/dominator-proto/internal/proto/domain'; -import { formatPredicate, formatCashVolumes, compareCashVolumes } from '@cc/app/shared'; +import { + formatPredicate, + formatCashVolumes, + compareCashVolumes, + getCashVolumeParts, + CashVolumeParts, +} from '@cc/app/shared'; export interface InlineCashFlowSelector { if?: Predicate; value?: string; + parts?: CashVolumeParts; parent?: InlineCashFlowSelector; description?: string; level: number; @@ -72,6 +79,7 @@ export function getInlineDecisions( const value = c.value.filter(filterValue); acc.push({ value: formatCashVolumes(value.map((v) => v.volume)), + parts: getCashVolumeParts(value.map((v) => v.volume)), level, description: value .sort((a, b) => compareCashVolumes(a.volume, b.volume)) diff --git a/src/app/shared/utils/table/format-cash-volume.ts b/src/app/shared/utils/table/format-cash-volume.ts index 8ffc580a..2e3de126 100644 --- a/src/app/shared/utils/table/format-cash-volume.ts +++ b/src/app/shared/utils/table/format-cash-volume.ts @@ -5,8 +5,8 @@ import { getUnionKey, getUnionValue } from '@vality/ng-thrift'; import { formatRational } from './format-rational'; const CASH_VOLUME_PRIORITY: Record = { - fixed: 0, - share: 1, + share: 0, + fixed: 1, product: 2, }; diff --git a/src/app/shared/utils/table/format-predicate.ts b/src/app/shared/utils/table/format-predicate.ts index b3be49a7..cbc161f4 100644 --- a/src/app/shared/utils/table/format-predicate.ts +++ b/src/app/shared/utils/table/format-predicate.ts @@ -3,14 +3,15 @@ import { formatCurrency, inlineJson } from '@vality/ng-core'; import { getUnionKey, getUnionValue, toJson } from '@vality/ng-thrift'; import startCase from 'lodash-es/startCase'; -export function formatPredicate(predicate: Predicate, level = 0) { +export function formatPredicate(predicate: Predicate, level = 0, not = false) { if (!predicate) { return ''; } const type = getUnionKey(predicate); + const equalSymbol = not ? '≠' : '='; switch (type) { case 'constant': - return startCase(String(predicate.constant)); + return startCase(String(not ? !predicate.constant : predicate.constant)); case 'any_of': case 'all_of': { const predicatesSet = getUnionValue(predicate) as @@ -22,19 +23,22 @@ export function formatPredicate(predicate: Predicate, level = 0) { const res = Array.from(predicatesSet) .map((p) => formatPredicate(p, level + 1)) .join(type === 'all_of' ? ' & ' : ' ∨ '); - return level === 0 ? `(${res})` : res; + return `${not ? 'NOT ' : ''}${level === 0 ? `(${res})` : res}`; } case 'condition': { const condition = predicate.condition; switch (getUnionKey(condition)) { case 'currency_is': - return `currency = ${condition.currency_is.symbolic_code}`; + return `currency ${equalSymbol} ${condition.currency_is.symbolic_code}`; case 'bin_data': - return `bin_data = ${inlineJson(toJson(condition.bin_data), Infinity)}`; + return `bin_data ${equalSymbol} ${inlineJson( + toJson(condition.bin_data), + Infinity, + )}`; case 'category_is': - return `category = #${condition.category_is.id}`; + return `category ${equalSymbol} #${condition.category_is.id}`; case 'cost_in': - return `cost = ${ + return `cost ${equalSymbol} ${ getUnionKey(condition.cost_in.lower) === 'inclusive' ? '[' : '(' }${formatCurrency( getUnionValue(condition.cost_in.lower)?.amount, @@ -44,34 +48,42 @@ export function formatPredicate(predicate: Predicate, level = 0) { getUnionValue(condition.cost_in.upper)?.currency?.symbolic_code, )}${getUnionKey(condition.cost_in.upper) === 'inclusive' ? ']' : ')'}`; case 'cost_is_multiple_of': - return `cost_is_multiple = ${formatCurrency( + return `cost_is_multiple ${equalSymbol} ${formatCurrency( condition.cost_is_multiple_of.amount, condition.cost_is_multiple_of.currency.symbolic_code, )}`; case 'identification_level_is': - return `identification_level = ${condition.identification_level_is}`; // TODO: fix enum value + return `identification_level ${equalSymbol} ${condition.identification_level_is}`; // TODO: fix enum value case 'p2p_tool': - return `p2p_tool = ${inlineJson(toJson(condition.p2p_tool), Infinity)}`; + return `p2p_tool ${equalSymbol} ${inlineJson( + toJson(condition.p2p_tool), + Infinity, + )}`; case 'party': - return `party = (#${condition.party.id}${ + return `party ${equalSymbol} (#${condition.party.id}${ condition.party?.definition ? ' & ' + inlineJson(toJson(condition.party?.definition), Infinity) : '' })`; case 'payment_tool': - return `payment_tool = ${inlineJson(toJson(condition.payment_tool), Infinity)}`; + return `payment_tool ${equalSymbol} ${inlineJson( + toJson(condition.payment_tool), + Infinity, + )}`; case 'payout_method_is': - return `payout_method = ${condition.payout_method_is.id}`; // TODO: fix enum value + return `payout_method ${equalSymbol} ${condition.payout_method_is.id}`; // TODO: fix enum value case 'shop_location_is': - return `shop_url = ${condition.shop_location_is.url}`; + return `shop_url ${equalSymbol} ${condition.shop_location_is.url}`; } return ''; } case 'criterion': - return `${startCase(getUnionKey(predicate))} #${predicate.criterion.id}`; + return `${startCase(getUnionKey(predicate))}${not ? ` ${equalSymbol}` : ''} #${ + predicate.criterion.id + }`; case 'is_not': { if (getUnionKey(getUnionValue(predicate) as Predicate) !== 'is_not') { - return `NOT ${formatPredicate(predicate.is_not, level + 1)}`; + return formatPredicate(predicate.is_not, level + 1, !not); } return ''; } diff --git a/src/app/shared/utils/table/get-cash-volume-parts.ts b/src/app/shared/utils/table/get-cash-volume-parts.ts new file mode 100644 index 00000000..6c691862 --- /dev/null +++ b/src/app/shared/utils/table/get-cash-volume-parts.ts @@ -0,0 +1,112 @@ +import { CashVolume } from '@vality/domain-proto/domain'; +import { getUnionKey, getUnionValue } from '@vality/ng-thrift'; +import isNil from 'lodash-es/isNil'; + +import { formatCashVolumes, formatCashVolume } from './format-cash-volume'; + +export interface CashVolumeParts { + fixed?: string; + share?: string; + min?: string; + max?: string; +} + +export function getCashVolumeParts(c: CashVolume[]): CashVolumeParts { + const res: CashVolumeParts = {}; + const def: CashVolumeParts = { share: formatCashVolumes(c) }; + for (const part of c) { + switch (getUnionKey(part)) { + case 'fixed': { + if (!isNil(res.fixed)) { + return def; + } + res.fixed = formatCashVolume(part); + break; + } + case 'share': { + if (!isNil(res.share)) { + return def; + } + res.share = formatCashVolume(part); + break; + } + case 'product': { + if (!isNil(res.fixed) && !isNil(res.share)) { + return def; + } + const products = Array.from(getUnionValue(part.product)); + if (products.length > 2) { + return def; + } + let fixedProduct: CashVolume; + let shareProduct: CashVolume; + if ( + getUnionKey(products[0]) === 'fixed' && + (products.length === 1 || getUnionKey(products[1]) === 'share') + ) { + fixedProduct = products[0]; + shareProduct = products[1]; + } else if ( + getUnionKey(products[0]) === 'share' && + (products.length === 1 || getUnionKey(products[1]) === 'fixed') + ) { + shareProduct = products[0]; + fixedProduct = products[1]; + } else { + return def; + } + if (products.length === 1) { + if (shareProduct && isNil(res.share)) { + res.share = formatCashVolume(shareProduct); + } else if (fixedProduct && isNil(res.fixed)) { + res.fixed = formatCashVolume(fixedProduct); + } else { + return def; + } + } else { + switch (getUnionKey(part.product)) { + case 'min_of': { + if (!isNil(res.min)) { + return def; + } + if (isNil(res.fixed)) { + res.fixed = formatCashVolume(fixedProduct); + res.min = formatCashVolume(shareProduct); + } else if (isNil(res.share)) { + res.share = formatCashVolume(shareProduct); + res.min = formatCashVolume(fixedProduct); + } else { + return def; + } + break; + } + case 'max_of': { + if (!isNil(res.max)) { + return def; + } + if (isNil(res.fixed)) { + res.fixed = formatCashVolume(fixedProduct); + res.max = formatCashVolume(shareProduct); + } else if (isNil(res.share)) { + res.share = formatCashVolume(shareProduct); + res.max = formatCashVolume(fixedProduct); + } else { + return def; + } + break; + } + case 'sum_of': { + if (!isNil(res.fixed) || !isNil(res.share)) { + return def; + } + res.fixed = formatCashVolume(fixedProduct); + res.share = formatCashVolume(shareProduct); + break; + } + } + } + } + } + } + return res; +} diff --git a/src/app/shared/utils/table/index.ts b/src/app/shared/utils/table/index.ts index c8a42f9f..942e3896 100644 --- a/src/app/shared/utils/table/index.ts +++ b/src/app/shared/utils/table/index.ts @@ -8,3 +8,4 @@ export * from './format-cash-volume'; export * from './format-rational'; export * from './format-predicate'; export * from './create-wallet-column'; +export * from './get-cash-volume-parts';