final
This commit is contained in:
1 parent
398fca9265
commit
f4f6e5c618
6 files changed
+207
-71
No files matched your search
@@ -164,6 +164,12 @@ const toStoredDetailRowsState = <TRow = unknown>(state: { detailRows?: TRow[] }
|
||||
const hasOwn = (obj: unknown, key: string) =>
|
||||
Object.prototype.hasOwnProperty.call(obj || {}, key)
|
||||
|
||||
const isGroupScaleRow = (row: unknown) =>
|
||||
Boolean(row && typeof row === 'object' && (row as Record<string, unknown>).isGroupRow === true)
|
||||
|
||||
const stripGroupScaleRows = <TRow>(rows: TRow[] | undefined): TRow[] =>
|
||||
(rows || []).filter(row => !isGroupScaleRow(row))
|
||||
|
||||
const getRowNumberOrFallback = (
|
||||
row: Record<string, unknown> | undefined,
|
||||
key: string,
|
||||
@@ -306,8 +312,9 @@ const mergeScaleRows = (
|
||||
consultCategoryFactorMap?: Map<string, number | null>,
|
||||
majorFactorMap?: Map<string, number | null>
|
||||
): ScaleRow[] => {
|
||||
const dbValueMap = toRowMap(rowsFromDb)
|
||||
for (const row of rowsFromDb || []) {
|
||||
const sourceRows = stripGroupScaleRows(rowsFromDb)
|
||||
const dbValueMap = toRowMap(sourceRows)
|
||||
for (const row of sourceRows) {
|
||||
const rowId = String(row.id)
|
||||
const nextId = majorIdAliasMap.get(rowId)
|
||||
if (nextId && !dbValueMap.has(nextId)) {
|
||||
@@ -370,7 +377,7 @@ const getOnlyCostScaleBudgetFee = (
|
||||
industryId?: string | null
|
||||
) => {
|
||||
const industryMajorEntry = getIndustryMajorEntryByIndustryId(industryId)
|
||||
const sourceRows = rowsFromDb || []
|
||||
const sourceRows = stripGroupScaleRows(rowsFromDb)
|
||||
const defaultConsultCategoryFactor =
|
||||
consultCategoryFactorMap?.get(String(serviceId)) ?? getDefaultConsultCategoryFactor(serviceId)
|
||||
const defaultMajorFactor =
|
||||
@@ -426,14 +433,15 @@ const buildOnlyCostScaleDetailRows = (
|
||||
majorFactorMap?: Map<string, number | null>,
|
||||
industryId?: string | null
|
||||
) => {
|
||||
const totalAmount = sumByNumberNullable(rowsFromDb || [], row =>
|
||||
const sourceRows = stripGroupScaleRows(rowsFromDb)
|
||||
const totalAmount = sumByNumberNullable(sourceRows, row =>
|
||||
typeof row?.amount === 'number' && Number.isFinite(row.amount) ? row.amount : null
|
||||
)
|
||||
const industryMajorEntry = getIndustryMajorEntryByIndustryId(industryId)
|
||||
const onlyCostRowId = industryMajorEntry?.id || ONLY_COST_SCALE_ROW_ID
|
||||
const onlyRow =
|
||||
(rowsFromDb || []).find(row => String(row?.id || '') === ONLY_COST_SCALE_ROW_ID) ||
|
||||
(rowsFromDb || []).find(row => String(row?.id || '') === onlyCostRowId)
|
||||
sourceRows.find(row => String(row?.id || '') === ONLY_COST_SCALE_ROW_ID) ||
|
||||
sourceRows.find(row => String(row?.id || '') === onlyCostRowId)
|
||||
const consultCategoryFactor = getRowNumberOrFallback(
|
||||
onlyRow,
|
||||
'consultCategoryFactor',
|
||||
@@ -598,7 +606,7 @@ const resolveScaleRows = (
|
||||
if (htData?.detailRows != null) {
|
||||
return mergeScaleRows(
|
||||
serviceId,
|
||||
htData.detailRows as any,
|
||||
stripGroupScaleRows(htData.detailRows as any),
|
||||
consultCategoryFactorMap,
|
||||
majorFactorMap
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user