From d5362d8275d8bb24f69ad33d30a77a46ea20054b Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Mon, 3 Apr 2023 10:26:17 +0300 Subject: [PATCH] merge release/dyn-2664_technical-card-nsib --- .../Effects/actions/calculate/prepareData.ts | 18 +-- .../actions/calculate/validate/elements.ts | 6 +- .../Effects/reactions/otherReactions.ts | 138 ++++++++++++++---- .../query/options/main_options.graphql | 14 ++ 4 files changed, 135 insertions(+), 41 deletions(-) diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts index 2c92a19..5d7f643 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts @@ -116,9 +116,9 @@ export default function (this: ICalculationStore): PreparedData { preparedValues.subsidySum = parseInt(values.subsidySum) / (1 + valuesConstants.VAT); preparedValues.subsidyPaymentNumber = - this.getOption('selectSubsidy')?.evo_get_subsidy_payment; + this.getOption('selectSubsidy')?.evo_get_subsidy_payment || 0; preparedValues.fuelCardSum = - this.getOption('selectFuelCard')?.evo_graph_price_withoutnds; + this.getOption('selectFuelCard')?.evo_graph_price_withoutnds || 0; preparedValues.scheduleOfPayments = values.graphType; preparedValues.comissionRub = (values.comissionRub as number) / (1 + valuesConstants.VAT); @@ -846,19 +846,7 @@ export default function (this: ICalculationStore): PreparedData { // const nsibBaseValue = - ((preparedValues.plPrice || 0) - - (preparedValues.importProgramSum || 0) + - (preparedValues.insuranceContract + - (preparedValues.rats || 0) + - (preparedValues.registration || 0) + - (preparedValues.trackerCost || 0) + - (preparedValues.tLMCost || 0) + - (preparedValues.transportTaxGr || 0) + - (preparedValues.tlmCostPaymentSum || 0) + - (preparedValues.gpsCostPaymentSum || 0)) * - preparedValues.leasing0K - - preparedValues.firstPaymentSum - - (values.product === 'LEASING0' ? 0 : preparedValues.discount || 0)) * + ((preparedValues.plPrice || 0) - preparedValues.firstPaymentSum) * (1 + valuesConstants.VAT); if (nsibBaseValue > valuesConstants.NSIB_MAX) { diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts index 5d9d33c..9c5bc58 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts @@ -43,9 +43,13 @@ const customConditions: Partial> = { tbxVehicleTaxInYear: calculationStore => { const objectRegistration = calculationStore.getValue('objectRegistration'); const vehicleTaxInYear = calculationStore.getValue('vehicleTaxInYear'); + const vehicleTaxInLeasingPeriod = calculationStore.getValue( + 'vehicleTaxInLeasingPeriod', + ); if ( objectRegistration === 100000001 && - CONDITIONS.LESS_OR_EQUALS_ZERO(vehicleTaxInYear) + (CONDITIONS.LESS_OR_EQUALS_ZERO(vehicleTaxInLeasingPeriod) || + CONDITIONS.LESS_OR_EQUALS_ZERO(vehicleTaxInYear)) ) { return { isValid: false, diff --git a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts index bdd110e..864d1bb 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts @@ -404,17 +404,36 @@ const reactionEffects: IReactionEffect[] = [ calculationStore => ({ expression: () => { - const { leasingPeriod } = calculationStore.values; - return leasingPeriod; + const { leasingPeriod, leasingWithoutKasko } = calculationStore.values; + const kaskoInsured = + calculationStore.tables.tableInsurance.rows[1].insured?.value; + + const fingapInsured = + calculationStore.tables.tableInsurance.rows[4].insured?.value; + + return { + leasingPeriod, + leasingWithoutKasko, + kaskoInsured, + fingapInsured, + }; }, - effect: leasingPeriod => { - if (leasingPeriod) { - if (parseInt(leasingPeriod) < 12) { - calculationStore.setValue('insNSIB', null); - calculationStore.setStatus('selectInsNSIB', ElementStatus.Disabled); - } else { - calculationStore.setStatus('selectInsNSIB', ElementStatus.Default); - } + effect: ({ + leasingPeriod, + leasingWithoutKasko, + kaskoInsured, + fingapInsured, + }) => { + if ( + leasingPeriod < 12 || + leasingWithoutKasko || + kaskoInsured === 100_000_001 || + (fingapInsured === 100_000_001 && leasingPeriod < 36) + ) { + calculationStore.setValue('insNSIB', null); + calculationStore.setStatus('selectInsNSIB', ElementStatus.Disabled); + } else { + calculationStore.setStatus('selectInsNSIB', ElementStatus.Default); } }, options: { @@ -422,6 +441,69 @@ const reactionEffects: IReactionEffect[] = [ }, }), + calculationStore => ({ + expression: () => { + //@ts-ignore + const plPriceRub = calculationStore.plPriceRub(); + //@ts-ignore + const discountRub = calculationStore.discountRub(); + //@ts-ignore + const importProgramSum: number = calculationStore.importProgramSum(); + + const { + leasingPeriod, + leaseObjectType, + addEquipmentPrice, + firstPaymentPerc, + } = calculationStore.values; + return { + leasingPeriod, + leaseObjectType, + plPriceRub, + discountRub, + addEquipmentPrice, + importProgramSum, + firstPaymentPerc, + }; + }, + effect: ({ + leasingPeriod = 0, + leaseObjectType, + plPriceRub = 0, + discountRub = 0, + addEquipmentPrice = 0, + importProgramSum = 0, + firstPaymentPerc = 0, + }) => { + calculationStore.setFilter('selectInsNSIB', options => + options.filter( + x => + x?.evo_max_period !== undefined && + x?.evo_min_period !== undefined && + x.evo_max_period >= leasingPeriod && + x.evo_min_period <= leasingPeriod && + x?.evo_max_price !== undefined && + x?.evo_min_price !== undefined && + x.evo_max_price >= + plPriceRub - discountRub - importProgramSum + addEquipmentPrice && + x.evo_min_price <= + plPriceRub - discountRub - importProgramSum + addEquipmentPrice && + x.evo_leasingobject_types?.find( + x => x.evo_leasingobject_typeid === leaseObjectType, + ) && + x.evo_visible_calc && + x.evo_min_first_payment_perc !== undefined && + x.evo_min_first_payment_perc <= firstPaymentPerc && + x.evo_max_first_payment_perc !== undefined && + x.evo_max_first_payment_perc >= firstPaymentPerc, + ), + ); + }, + options: { + fireImmediately: true, + }, + }), + // calculationStore => ({ // expression: () => { // const { leasingPeriod } = calculationStore.values; @@ -800,22 +882,28 @@ const reactionEffects: IReactionEffect[] = [ calculationStore => ({ expression: () => { - const { leasingPeriod, leaseObjectType } = calculationStore.values; - return { leasingPeriod, leaseObjectType }; + const { leasingPeriod, leaseObjectType, maxMass } = + calculationStore.values; + return { leasingPeriod, leaseObjectType, maxMass }; }, - effect: ({ leasingPeriod, leaseObjectType }) => { - calculationStore.setFilter('selectTechnicalCard', options => - options.filter( - x => - x?.evo_max_period && - x?.evo_min_period && - x.evo_max_period >= leasingPeriod && - x.evo_min_period <= leasingPeriod && - x.evo_leasingobject_types?.find( - x => x.evo_leasingobject_typeid === leaseObjectType, - ), - ), - ); + effect: ({ leasingPeriod, leaseObjectType, maxMass }) => { + if (maxMass >= 40000) { + calculationStore.setFilter('selectTechnicalCard', () => []); + calculationStore.setValue('technicalCard', null); + } else { + calculationStore.setFilter('selectTechnicalCard', options => + options.filter( + x => + x?.evo_max_period && + x?.evo_min_period && + x.evo_max_period >= leasingPeriod && + x.evo_min_period <= leasingPeriod && + x.evo_leasingobject_types?.find( + x => x.evo_leasingobject_typeid === leaseObjectType, + ), + ), + ); + } }, options: { fireImmediately: true, diff --git a/src/core/services/CrmService/graphql/query/options/main_options.graphql b/src/core/services/CrmService/graphql/query/options/main_options.graphql index 30f9e65..9239ef8 100644 --- a/src/core/services/CrmService/graphql/query/options/main_options.graphql +++ b/src/core/services/CrmService/graphql/query/options/main_options.graphql @@ -116,6 +116,20 @@ query GetMainOptions( evo_dateto_param: { gte: $currentDate } ) { ...evo_addproduct_types_fields + evo_leasingobject_types { + evo_leasingobject_typeid + } + evo_visible_calc + evo_min_price + evo_max_price + evo_loss_kv + evo_min_first_payment_perc + evo_max_first_payment_perc + evo_models { + evo_modelid + } + evo_evokasko_calc_type + evo_price_service_provider_withoutnds } selectTracker: evo_addproduct_types( statecode: $statecode