diff --git a/src/client/process/configurator/reactions/values.ts b/src/client/process/configurator/reactions/values.ts index 971f03c..ab6c85f 100644 --- a/src/client/process/configurator/reactions/values.ts +++ b/src/client/process/configurator/reactions/values.ts @@ -1,3 +1,4 @@ +import { pipe } from 'core/tools/func'; import { ICalculationStore } from 'core/types/Calculation/Store'; import { Process } from 'core/types/Calculation/Store/process'; import { reaction } from 'mobx'; @@ -5,46 +6,51 @@ import { reaction } from 'mobx'; export default function ($calculation: ICalculationStore) { reaction( () => { - const { - product, - leasingPeriod, - deliveryTime, - firstPaymentPerc, - lastPaymentPerc, - } = $calculation.values; return { - product_evo_id: product, - leasingPeriod, - deliveryTime, - firstPaymentPerc, - lastPaymentPerc, + product: $calculation.getOption('selectProduct'), + ...$calculation.getValues([ + 'leasingPeriod', + 'deliveryTime', + 'firstPaymentPerc', + 'lastPaymentPerc', + 'leaseObjectUsed', + ]), }; }, ({ - product_evo_id, + product, leasingPeriod, deliveryTime, firstPaymentPerc, lastPaymentPerc, + leaseObjectUsed, }) => { - if (product_evo_id && leasingPeriod && deliveryTime) { - const product = $calculation.getOption('selectProduct', { - evo_id: product_evo_id, - }); - if (product) { - const tarif = $calculation.options.selectTarif?.find( - x => - x.evo_baseproductid === product.evo_baseproductid && - x.evo_min_period <= leasingPeriod && - x.evo_max_period >= leasingPeriod && - x.evo_delivery_time?.includes(deliveryTime) && - x.evo_min_first_payment <= firstPaymentPerc && - x.evo_max_first_payment >= firstPaymentPerc && - x.evo_min_last_payment <= lastPaymentPerc && - x.evo_max_last_payment >= lastPaymentPerc, - ); - $calculation.setValue('tarif', tarif?.evo_tarifid); - } + if (product && leasingPeriod && deliveryTime) { + const target_tarif = $calculation.options.selectTarif?.find( + pipe( + tarif => + tarif.evo_baseproductid === product.evo_baseproductid && + tarif.evo_min_period <= leasingPeriod && + tarif.evo_max_period >= leasingPeriod && + tarif.evo_delivery_time?.includes(deliveryTime) && + tarif.evo_min_first_payment <= firstPaymentPerc && + tarif.evo_max_first_payment >= firstPaymentPerc && + tarif.evo_min_last_payment <= lastPaymentPerc && + tarif.evo_max_last_payment >= lastPaymentPerc && + tarif, + tarif => { + if (leaseObjectUsed === true) { + if (tarif.evo_used) { + return tarif; + } + } else { + return tarif; + } + }, + ), + ); + + $calculation.setValue('tarif', target_tarif?.evo_tarifid); } else { $calculation.setValue('tarif', null); } 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 b7f09e1..0a3c12b 100644 --- a/src/core/services/CrmService/graphql/query/options/main_options.graphql +++ b/src/core/services/CrmService/graphql/query/options/main_options.graphql @@ -190,6 +190,7 @@ query GetMainOptions( evo_max_last_payment evo_margin_min evo_cut_irr_with_bonus_coefficient + evo_used } selectRate: evo_rates( statecode: $statecode