diff --git a/src/client/stores/CalculationStore/Data/tables.js b/src/client/stores/CalculationStore/Data/tables.js index d1e8e8e..f1d028f 100644 --- a/src/client/stores/CalculationStore/Data/tables.js +++ b/src/client/stores/CalculationStore/Data/tables.js @@ -1,5 +1,5 @@ import initialTables from 'client/stores/CalculationStore/config/initialTables'; -import { merge } from 'lodash'; +import { merge, mergeWith } from 'lodash'; const tablesData = { tables: initialTables, @@ -29,21 +29,29 @@ const tablesActions = { return values; }, + replaceTableRows(tableName) { + return rows => { + this.tables[tableName].rows.replace(rows); + }; + }, + setTableRows(tableName, startIndex, override) { return rows => { - if (override) { - this.tables[tableName].rows.replace(rows); - return; - } if (this.tables[tableName] && this.tables[tableName].rows) for ( let i = startIndex, j = 0; i < startIndex + rows.length; i++, j++ ) { - this.tables[tableName].rows[i] = merge( + this.tables[tableName].rows[i] = mergeWith( this.tables[tableName].rows[i], rows[j], + (obj, src, key) => { + if (override) { + return src; + } + return merge(obj, src); + }, ); } }; diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts index 8f7f46e..12d0d8b 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts @@ -221,11 +221,7 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ : ElementStatus.Disabled, }, })); - calculationStore.setTableRows( - 'tablePayments', - 0, - true, - )([ + calculationStore.replaceTableRows('tablePayments')([ { paymentRelation: { value: quote.evo_first_payment_perc, diff --git a/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts index d846153..d94e240 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts @@ -741,11 +741,7 @@ export default [ } } - calculationStore.setTableRows( - 'tablePayments', - 0, - true, - )([ + calculationStore.replaceTableRows('tablePayments')([ ...payments, { paymentRelation: { @@ -780,4 +776,59 @@ export default [ fireImmediately: true, }, }), + + calculationStore => ({ + expression: () => { + const { leaseObjectCategory } = calculationStore.values; + return leaseObjectCategory; + }, + effect: leaseObjectCategory => { + const isTrailer = leaseObjectCategory === 100000004; + + if (isTrailer) { + const otherInsuranceCompany = calculationStore.tables.tableInsurance.options?.insuranceCompany?.find( + x => x.name?.includes('ПРОЧИЕ'), + ); + if (otherInsuranceCompany) + calculationStore.setTableRow( + 'tableInsurance', + 0, + true, + )({ + insuranceCompany: { + filter: options => + options.filter(x => x.value === otherInsuranceCompany.value), + value: otherInsuranceCompany.value, + status: ElementStatus.Disabled, + }, + insCost: { + value: 0, + status: ElementStatus.Disabled, + }, + insured: { + value: 100000000, + status: ElementStatus.Disabled, + }, + }); + } else { + calculationStore.setTableRow( + 'tableInsurance', + 0, + true, + )({ + insuranceCompany: { + filter: undefined, + value: null, + status: ElementStatus.Default, + }, + insCost: { + status: ElementStatus.Default, + }, + insured: { + status: ElementStatus.Default, + }, + }); + } + }, + }), ] as IReactionEffect[]; diff --git a/src/core/types/Calculation/Store/index.ts b/src/core/types/Calculation/Store/index.ts index 9830d7b..aca0b28 100644 --- a/src/core/types/Calculation/Store/index.ts +++ b/src/core/types/Calculation/Store/index.ts @@ -15,7 +15,12 @@ import { } from './tables'; import { TValue, TValues, ValuesNames, ResultValuesNames } from './values'; -export type ElementParam = 'value' | 'status' | 'options' | 'filter' | 'validation'; +export type ElementParam = + | 'value' + | 'status' + | 'options' + | 'filter' + | 'validation'; interface ICalculationValues { staticData: TStaticData; @@ -72,6 +77,10 @@ interface ICalculationTables { paramName: ElementParam, ) => { values: TableProps }; + replaceTableRows: ( + tableName: TableNames, + ) => (rows: TableProps[]) => void; + setTableRows: ( tableName: TableNames, startIndex: number,