FIN-45: Filter unused term fee (#364)

This commit is contained in:
Rinat Arsaev 2024-06-10 14:07:18 +05:00 committed by GitHub
parent 98e7ca9262
commit 310572e799
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 74 additions and 44 deletions

View File

@ -104,14 +104,17 @@ export class ShopsTariffsComponent implements OnInit {
createDomainObjectColumn('term_set_hierarchy', (d) => d.current_term_set.ref, {
header: 'Term Set',
}),
...createShopFeesColumn<ShopTermSet>((d) => d?.current_term_set),
...createShopFeesColumn<ShopTermSet>(
(d) => d?.current_term_set,
(d) => d.owner_id,
(d) => d.shop_id,
(d) => d.currency,
),
{
field: 'term_set_history',
formatter: (d) => d.term_set_history?.length || '',
click: (d) =>
this.sidenavInfoService.open(ShopsTermSetHistoryCardComponent, {
data: d?.term_set_history?.reverse(),
}),
this.sidenavInfoService.open(ShopsTermSetHistoryCardComponent, { data: d }),
},
];
active$ = getValueChanges(this.filtersForm).pipe(

View File

@ -1,6 +1,13 @@
import type { TermSetHierarchyObject } from '@vality/dominator-proto/internal/proto/domain';
import type {
TermSetHierarchyObject,
CashFlowPosting,
} from '@vality/dominator-proto/internal/proto/domain';
import { createFeesColumns } from '../../../utils/create-fees-columns';
import {
getInlineDecisions,
type InlineCashFlowSelector,
} from '../../../utils/get-inline-decisions';
export function getViewedCashFlowSelectors(d: TermSetHierarchyObject) {
return d?.data?.term_sets?.map?.((t) => t?.terms?.payments?.fees)?.filter?.(Boolean) ?? [];
@ -8,10 +15,34 @@ export function getViewedCashFlowSelectors(d: TermSetHierarchyObject) {
export function createShopFeesColumn<T extends object = TermSetHierarchyObject>(
fn: (d: T) => TermSetHierarchyObject = (d) => d as never,
getPartyId: (d: T) => string,
getShopId: (d: T) => string,
getCurrency: (d: T) => string,
) {
return createFeesColumns<T>(
const filterRreserve = (v: CashFlowPosting) =>
v?.source?.merchant === 0 && v?.destination?.merchant === 1;
const cols = createFeesColumns<T>(
(d) => getViewedCashFlowSelectors(fn(d)),
(v) => v?.source?.merchant === 0 && v?.destination?.system === 0,
(v) => v?.source?.merchant === 0 && v?.destination?.merchant === 1,
(v) => !filterRreserve(v),
(d: T) => (v: InlineCashFlowSelector) =>
(!v?.if?.condition?.party?.definition?.shop_is ||
(v?.if?.condition?.party?.id === getPartyId(d) &&
v?.if?.condition?.party?.definition?.shop_is === getShopId(d))) &&
(!getCurrency(d) ||
!v?.if?.condition?.currency_is?.symbolic_code ||
v?.if?.condition?.currency_is?.symbolic_code === getCurrency(d)),
);
return [
...cols.slice(0, -1),
{
field: 'rreserve',
header: 'RReserve',
formatter: (d) =>
getInlineDecisions(getViewedCashFlowSelectors(fn(d)), filterRreserve).map(
(v) => v.value,
),
},
cols.at(-1),
];
}

View File

@ -7,7 +7,7 @@
other: arrayColumnTemplate
}"
[columns]="columns"
[data]="data()"
[data]="historyData()"
></v-table>
<ng-template #arrayColumnTemplate let-colDef="colDef" let-rowData="rowData" let-value="value">

View File

@ -1,9 +1,9 @@
import { CommonModule } from '@angular/common';
import { Component, input } from '@angular/core';
import { Component, input, computed } from '@angular/core';
import { MatTooltip } from '@angular/material/tooltip';
import { TableModule, type Column, VSelectPipe } from '@vality/ng-core';
import type { TermSetHistory } from '@vality/dominator-proto/internal/dominator';
import type { TermSetHistory, ShopTermSet } from '@vality/dominator-proto/internal/dominator';
import { SidenavInfoModule } from '../../../../shared/components/sidenav-info';
import { getDomainObjectDetails } from '../../../../shared/components/thrift-api-crud';
@ -17,7 +17,9 @@ import { createShopFeesColumn } from '../shops-tariffs/utils/create-shop-fees-co
styles: ``,
})
export class ShopsTermSetHistoryCardComponent {
data = input<TermSetHistory[]>();
data = input<ShopTermSet>();
historyData = computed(() => this.data()?.term_set_history?.reverse?.());
columns: Column<TermSetHistory>[] = [
{ field: 'applied_at', type: 'datetime' },
{
@ -26,6 +28,11 @@ export class ShopsTermSetHistoryCardComponent {
description: (d) =>
getDomainObjectDetails({ term_set_hierarchy: d?.term_set })?.description,
},
...createShopFeesColumn<TermSetHistory>((d) => d.term_set),
...createShopFeesColumn<TermSetHistory>(
(d) => d.term_set,
() => this.data().owner_id,
() => this.data().shop_id,
() => this.data().currency,
),
];
}

View File

@ -1,6 +1,6 @@
import type { InlineCashFlowSelector } from '../../../utils/get-inline-decisions';
import type { TermSetHierarchyObject } from '@vality/dominator-proto/internal/proto/domain';
import { formatCashVolume } from '../../../../../shared';
import { createFeesColumns } from '../../../utils/create-fees-columns';
export function getViewedCashFlowSelectors(d: TermSetHierarchyObject) {
@ -14,15 +14,17 @@ export function getViewedCashFlowSelectors(d: TermSetHierarchyObject) {
export function createWalletFeesColumn<T extends object = TermSetHierarchyObject>(
fn: (d: T) => TermSetHierarchyObject = (d) => d as never,
getWalletId: (d: T) => string,
getCurrency: (d: T) => string,
) {
return createFeesColumns<T>(
(d) => getViewedCashFlowSelectors(fn(d)),
(v) => v?.source?.wallet === 1 && v?.destination?.system === 0,
undefined,
(v) =>
v?.source?.wallet === 1 &&
v?.destination?.wallet === 3 &&
formatCashVolume(v?.volume) === '100%',
getWalletId,
(d: T) => (v: InlineCashFlowSelector) =>
(!v?.if?.condition?.party?.definition?.wallet_is ||
v?.if?.condition?.party?.definition?.wallet_is === getWalletId(d)) &&
(!getCurrency(d) ||
!v?.if?.condition?.currency_is?.symbolic_code ||
v?.if?.condition?.currency_is?.symbolic_code === getCurrency(d)),
);
}

View File

@ -107,6 +107,7 @@ export class WalletsTariffsComponent implements OnInit {
...createWalletFeesColumn<WalletTermSet>(
(d) => d.current_term_set,
(d) => d.wallet_id,
(d) => d.currency,
),
{
field: 'term_set_history',
@ -115,6 +116,7 @@ export class WalletsTariffsComponent implements OnInit {
this.sidenavInfoService.open(WalletsTermSetHistoryCardComponent, {
data: d?.term_set_history?.reverse(),
walletId: d?.wallet_id,
currency: d?.currency,
}),
},
];

View File

@ -19,6 +19,7 @@ import { createWalletFeesColumn } from '../wallets-tariffs/utils/create-wallet-f
export class WalletsTermSetHistoryCardComponent {
data = input<TermSetHistory[]>();
walletId = input<string>();
currency = input<string>();
columns: Column<TermSetHistory>[] = [
{ field: 'applied_at', type: 'datetime' },
{
@ -30,6 +31,7 @@ export class WalletsTermSetHistoryCardComponent {
...createWalletFeesColumn<TermSetHistory>(
(d) => d.term_set,
() => this.walletId(),
() => this.currency(),
),
];
}

View File

@ -13,54 +13,37 @@ import {
export function createFeesColumns<T extends object>(
getFees: (d: T) => CashFlowSelector[],
filterFee: (v: CashFlowPosting) => boolean,
filterRreserve?: (v: CashFlowPosting) => boolean,
filterOther?: (v: CashFlowPosting) => boolean,
walletId?: (d: T) => string,
filterOther: (v: CashFlowPosting) => boolean = () => true,
filterDecisions: (d: T) => (v: InlineCashFlowSelector) => boolean = () => () => true,
): Column<T>[] {
const filterOtherFn: (v: CashFlowPosting) => boolean = (v) =>
!(
filterFee(v) ||
(filterRreserve ? filterRreserve(v) : false) ||
(filterOther ? filterOther(v) : false)
);
const filterFn = (d: T) => (v: InlineCashFlowSelector) =>
!v?.if?.condition?.party || v?.if?.condition?.party?.definition?.wallet_is === walletId(d);
!filterFee(v) &&
filterOther(v) &&
!(v?.volume?.share?.parts?.p === 1 && v?.volume?.share?.parts?.q === 1);
return [
{
field: 'condition',
formatter: (d) =>
getInlineDecisions(getFees(d))
.filter(filterFn(d))
.filter(filterDecisions(d))
.map((v) => formatLevelPredicate(v)),
},
{
field: 'fee',
formatter: (d) =>
getInlineDecisions(getFees(d), filterFee)
.filter(filterFn(d))
.filter(filterDecisions(d))
.map((v) => v.value),
},
...(filterRreserve
? [
{
field: 'rreserve',
header: 'RReserve',
formatter: (d) =>
getInlineDecisions(getFees(d), filterRreserve)
.filter(filterFn(d))
.map((v) => v.value),
},
]
: []),
{
field: 'other',
formatter: (d) =>
getInlineDecisions(getFees(d), filterOtherFn)
.filter(filterFn(d))
.filter(filterDecisions(d))
.map((v) => v.value),
tooltip: (d) =>
getInlineDecisions(getFees(d), filterOtherFn)
.filter(filterFn(d))
.filter(filterDecisions(d))
.map((v) => v.description),
},
];