diff --git a/src/client/stores/CalculationStore/Data/tables.js b/src/client/stores/CalculationStore/Data/tables.js index 8c86b41..fcfeda5 100644 --- a/src/client/stores/CalculationStore/Data/tables.js +++ b/src/client/stores/CalculationStore/Data/tables.js @@ -37,9 +37,12 @@ const tablesActions = { } } } else { - this.tables[tableName].rows[i] = Object.assign({}, rows[j]); + this.tables[tableName].rows[i] = rows[j]; } } + if (override) { + this.tables[tableName].rows.length = rows.length; + } }; }, diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/index.js b/src/client/stores/CalculationStore/Effects/actions/calculate/index.js index c6e7050..6757142 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/index.js +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/index.js @@ -86,8 +86,6 @@ export default async () => { results.showResultsTable(preparedData, res); results.showResults(preparedData, res); - unlockButtons(); - return { ...res, ...preparedData }; }) .catch(err => { @@ -101,8 +99,9 @@ export default async () => { err.response.data), })(); - unlockButtons(); - throw err; + }) + .finally(() => { + unlockButtons(); }); }; diff --git a/src/client/stores/CalculationStore/Effects/actions/createKP.js b/src/client/stores/CalculationStore/Effects/actions/createKP.js index 117fad5..4451607 100644 --- a/src/client/stores/CalculationStore/Effects/actions/createKP.js +++ b/src/client/stores/CalculationStore/Effects/actions/createKP.js @@ -4,11 +4,15 @@ import CrmService from 'client/services/CrmService'; import { getUser } from 'client/tools/user'; import CalculationStore from '../..'; import customValues from '../lib/customValues'; -import calculate from './calculate'; +import { openNotification } from 'client/Elements/Notification'; export default async () => { - const { values, tables } = CalculationStore; - const calculationRes = await calculate(); + const { values, tables, actions } = CalculationStore; + const calculationRes = await actions.calculate(); + + if (!calculationRes) { + return; + } const insurances = tables.tableInsurance.rows.map(insuranceRow => { const resObj = {}; @@ -86,6 +90,13 @@ export default async () => { }); }) .catch(err => { - throw err; + openNotification({ + type: 'error', + title: 'Ошибка во время создания КП!', + description: + err.response.data && JSON.stringify(err.response.data.errors), + })(); + + throw err.response.data; }); }; diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts index dbbb156..d1c7853 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts @@ -1,5 +1,6 @@ //@ts-nocheck +import { message } from 'antd'; import { elementsValues } from 'client/Containers/Calculation/lib/elements/values'; import CrmService from 'client/services/CrmService'; import { calculationProcess } from 'client/stores/CalculationStore'; @@ -21,6 +22,23 @@ const map_add_product_types_to_values = { telematics: 100000004, }; +const tablePaymentsStatuses = (graphType, leasingPeriod) => { + switch (graphType) { + case 100000001: { + return Array.from({ length: leasingPeriod - 3 }, (_, i) => i + 2); + } + case 100000003: { + return Array.from({ length: 12 }, (_, i) => i + 1); + } + case 100000004: { + return [1, 2, 3]; + } + default: { + return []; + } + } +}; + const loadKpReaction: IReactionEffect = calculationStore => ({ expression: () => { const { quote } = calculationStore.values; @@ -146,56 +164,89 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ opportunity, quote: quoteId, }); + + calculationStore.setTableRows( + 'tableInsurance', + 0, + )([ + { + insuranceCompany: { + value: quote?.evo_osago_accountid, + }, + insured: { value: quote.evo_osago_payer }, + insCost: { value: quote.evo_osago_price }, + }, + { + insuranceCompany: { + value: quote.evo_kasko_accountid, + }, + insured: { value: quote.evo_kasko_payer }, + insCost: { value: quote.evo_kasko_price }, + insTerm: { value: quote.evo_insurance_period }, + }, + { + insuranceCompany: { + value: quote.evo_kasko_accountid, + }, + insured: { value: quote.evo_kasko_payer }, + insCost: { value: quote.evo_dgo_price }, + insTerm: { value: quote.evo_insurance_period }, + }, + { + insuranceCompany: { + value: quote.evo_kasko_accountid, + }, + insured: { value: quote.evo_kasko_payer }, + insCost: { value: quote.evo_ns_price }, + insTerm: { value: quote.evo_insurance_period }, + }, + ]); + + const evo_planpayments = quote.evo_graphs.sort( + (a, b) => b.createdon - a.createdon, + )[0].evo_planpayments; + const payments = evo_planpayments + .slice(1, evo_planpayments.length - 1) + .map((evo_planpayment, i) => ({ + paymentRelation: { + validation: undefined, + value: evo_planpayment.evo_payment_ratio, + status: tablePaymentsStatuses( + quote.evo_graph_type, + quote.evo_period, + )?.includes(i + 1) + ? ElementStatus.Default + : ElementStatus.Disabled, + }, + })); + calculationStore.setTableRows( + 'tablePayments', + 0, + true, + )([ + { + paymentRelation: { + value: quote.evo_first_payment_perc, + status: ElementStatus.Disabled, + }, + }, + ...payments, + { + paymentRelation: { + value: quote.evo_last_payment_perc, + status: ElementStatus.Disabled, + }, + }, + ]); + + message.success({ + content: `КП ${quote?.evo_quotename || ''} загружено!`, + duration: 5, + style: { + marginTop: '7vh', + }, + }); } - - calculationStore.setTableRows( - 'tableInsurance', - 0, - )([ - { - insuranceCompany: { - value: quote?.evo_osago_accountid, - }, - insured: { value: quote.evo_osago_payer }, - insCost: { value: quote.evo_osago_price }, - }, - { - insuranceCompany: { - value: quote.evo_kasko_accountid, - }, - insured: { value: quote.evo_kasko_payer }, - insCost: { value: quote.evo_kasko_price }, - insTerm: { value: quote.evo_insurance_period }, - }, - { - insuranceCompany: { - value: quote.evo_kasko_accountid, - }, - insured: { value: quote.evo_kasko_payer }, - insCost: { value: quote.evo_dgo_price }, - insTerm: { value: quote.evo_insurance_period }, - }, - { - insuranceCompany: { - value: quote.evo_kasko_accountid, - }, - insured: { value: quote.evo_kasko_payer }, - insCost: { value: quote.evo_ns_price }, - insTerm: { value: quote.evo_insurance_period }, - }, - ]); - - const evo_planpayments = quote.evo_graphs.sort( - (a, b) => b.createdon - a.createdon, - )[0].evo_planpayments; - const payments = evo_planpayments - .slice(1, evo_planpayments.length) - .map(evo_planpayment => ({ - paymentRelation: { - value: evo_planpayment.evo_payment_ratio, - }, - })); - calculationStore.setTableRows('tablePayments', 1)(payments); }) .finally(() => { calculationStore.setStatus('selectQuote', ElementStatus.Default); diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js index ffe63f2..9a9b3dc 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js @@ -24,6 +24,9 @@ export default gql` evo_payment_ratio } } + evo_first_payment_perc + evo_last_payment_perc + evo_quotename } } `; diff --git a/src/core/types/Entities/crmEntities.ts b/src/core/types/Entities/crmEntities.ts index 35e228b..767419f 100644 --- a/src/core/types/Entities/crmEntities.ts +++ b/src/core/types/Entities/crmEntities.ts @@ -65,6 +65,10 @@ export interface IQuote { evo_ns_price?: number; evo_insurance_period?: number; evo_graphs?: IEvoGraph[]; + evo_graph_type?: number; + evo_period?: number; + evo_first_payment_perc?: number; + evo_last_payment_perc?: number; } interface IEvoGraph {