From cbc5941e7d67b70bb101fc437cbf4fbe482595d8 Mon Sep 17 00:00:00 2001 From: Chika Date: Fri, 22 Jan 2021 18:07:53 +0300 Subject: [PATCH] change leaseObjectCount filling from kp --- .../Effects/reactions/loadKpReaction/index.ts | 15 +++-- .../reactions/loadKpReaction/quoteQuery.js | 2 - .../reactions/recalcWoRevisionReactions.ts | 55 ++++++++++++++++++- .../Effects/reactions/requestReactions.ts | 1 + 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts index 7f1f146..c438d9e 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts @@ -49,7 +49,12 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ if (!quoteId) { return; } - const { lead, opportunity, recalcWithRevision } = calculationStore.values; + const { + lead, + opportunity, + recalcWithRevision, + leaseObjectCount, + } = calculationStore.values; calculationStore.setStatus('selectQuote', ElementStatus.Disabled); calculationStore.setStatus('btnCalculate', ElementStatus.Disabled); @@ -209,12 +214,6 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ }), ); - const tbxLeaseObjectCount = { - leaseObjectCount: calculationStore.values.recalcWithRevision - ? quote.evo_recalc_limit - : quote.evo_object_count, - }; - const rate = calculationStore.getOptions('selectRate'); const target_rate = rate.find(x => x.evo_rateid === quote.evo_rateid); @@ -223,12 +222,12 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ ...newValues, product: base_product?.evo_id, ...addProducts, - ...tbxLeaseObjectCount, rate: target_rate?.evo_id, lead, opportunity, quote: quoteId, recalcWithRevision, + leaseObjectCount, }); message.success({ diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js index 999d4d3..963ce66 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js @@ -27,8 +27,6 @@ export default gql` evo_first_payment_perc evo_last_payment_perc evo_quotename - evo_recalc_limit - evo_object_count evo_rateid } } diff --git a/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts index d4fca26..0d133cc 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts @@ -170,7 +170,7 @@ const reactionEffects: IReactionEffect[] = [ } }, }), - + calculationStore => ({ expression: () => { const { firstPaymentPerc, recalcWithRevision } = calculationStore.values; @@ -201,6 +201,59 @@ const reactionEffects: IReactionEffect[] = [ } }, }), + + calculationStore => ({ + expression: () => { + const { leaseObjectCount, recalcWithRevision } = calculationStore.values; + return { leaseObjectCount, recalcWithRevision }; + }, + effect: ({ leaseObjectCount, recalcWithRevision }) => { + if (!recalcWithRevision) { + calculationStore.setValidation('tbxLeaseObjectCount', undefined); + return; + } + + const { quote: quoteId } = calculationStore.values; + const quote = calculationStore.options.selectQuote?.find( + x => x.quoteid === quoteId, + ); + + if (quote && quote.evo_recalc_limit) { + if (leaseObjectCount > quote.evo_recalc_limit) { + calculationStore.setValidation('tbxLeaseObjectCount', false); + openNotification({ + type: 'error', + title: 'Ошибка', + description: + 'Количество ПЛ превышает лимит пересчета без пересмотра', + })(); + } else { + calculationStore.setValidation('tbxLeaseObjectCount', undefined); + } + } + }, + }), + + calculationStore => ({ + expression: () => { + const { quote, recalcWithRevision } = calculationStore.values; + return [quote, recalcWithRevision]; + }, + effect: ([quoteId, recalcWithRevision]) => { + const quote = calculationStore.options.selectQuote?.find( + x => x.quoteid === quoteId, + ); + if (recalcWithRevision) { + if (quote && quote.evo_recalc_limit) { + calculationStore.setValue('leaseObjectCount', quote.evo_recalc_limit); + } + } else { + if (quote && quote.evo_object_count) { + calculationStore.setValue('leaseObjectCount', quote.evo_object_count); + } + } + }, + }), ]; export default reactionEffects; diff --git a/src/client/stores/CalculationStore/Effects/reactions/requestReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/requestReactions.ts index 001b9e0..c283096 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/requestReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/requestReactions.ts @@ -57,6 +57,7 @@ export default [ evo_quotename quotenumber evo_recalc_limit + evo_object_count evo_approved_first_payment evo_statuscode: evo_statuscodeidData { evo_id