From b3af7b3827595aefefa54d8c31e070a43161ce66 Mon Sep 17 00:00:00 2001 From: Chika Date: Thu, 9 Sep 2021 11:23:47 +0300 Subject: [PATCH] merge release/dyn-190_subsidy --- .../Calculation/Sections/sectionsList.ts | 3 + .../Calculation/lib/elements/components.ts | 3 + .../Calculation/lib/elements/elementsProps.ts | 5 +- .../Calculation/lib/elements/titles.ts | 3 + .../Calculation/lib/elements/values.ts | 3 + .../lib/fetchData/queries/optionsQuery.ts | 59 ++++- .../stores/CalculationStore/Data/values.js | 12 +- .../Effects/actions/calculate/prepareData.ts | 59 ++++- .../Effects/actions/calculate/results.ts | 19 +- .../actions/calculate/validate/elements.ts | 24 +- .../CalculationStore/Effects/autorun.ts | 43 ++++ .../CalculationStore/Effects/computed.js | 66 ----- .../CalculationStore/Effects/computed.ts | 44 ++++ .../CalculationStore/Effects/lib/tools.js | 10 +- .../Effects/reactions/loadKpReaction/index.ts | 3 +- .../reactions/loadKpReaction/mapKpToValues.ts | 6 +- .../Effects/reactions/otherReactions.ts | 226 +++++++++++++++--- .../reactions/recalcWoRevisionReactions.ts | 1 + .../CalculationStore/config/initialFilters.ts | 10 +- src/core/services/CalculationService/index.ts | 1 - src/core/services/CrmService/propsMap.ts | 4 + src/core/types/Calculation/Prepare.ts | 6 + src/core/types/Calculation/Store/elements.ts | 5 +- src/core/types/Calculation/Store/index.ts | 3 +- src/core/types/Calculation/Store/values.ts | 9 +- src/core/types/Entities/crmEntities.ts | 17 +- src/core/types/Entities/crmEntityNames.ts | 3 +- 27 files changed, 515 insertions(+), 132 deletions(-) delete mode 100644 src/client/stores/CalculationStore/Effects/computed.js create mode 100644 src/client/stores/CalculationStore/Effects/computed.ts diff --git a/src/client/Containers/Calculation/Sections/sectionsList.ts b/src/client/Containers/Calculation/Sections/sectionsList.ts index 6283dad..1757209 100644 --- a/src/client/Containers/Calculation/Sections/sectionsList.ts +++ b/src/client/Containers/Calculation/Sections/sectionsList.ts @@ -82,6 +82,7 @@ const sections: ISection[] = [ 'tbxSupplierDiscountPerc', 'radioBalanceHolder', 'tbxSaleBonus', + 'selectSubsidy', ], }, { @@ -93,6 +94,7 @@ const sections: ISection[] = [ 'tbxLastPaymentPerc', 'tbxLastPaymentRub', 'tbxLeasingPeriod', + 'labelSubsidySum', ], }, @@ -380,6 +382,7 @@ const sections: ISection[] = [ { elements: [ 'selectTechnicalCard', + // 'selectFuelCard', 'selectInsNSIB', 'radioRequirementTelematic', 'selectTracker', diff --git a/src/client/Containers/Calculation/lib/elements/components.ts b/src/client/Containers/Calculation/lib/elements/components.ts index 2740146..f68926e 100644 --- a/src/client/Containers/Calculation/lib/elements/components.ts +++ b/src/client/Containers/Calculation/lib/elements/components.ts @@ -171,6 +171,9 @@ const elementsComponents: TElements = { labelRegistrationDescription: Label, selectLegalClientRegion: Select, selectLegalClientTown: Select, + selectSubsidy: Select, + selectFuelCard: Select, + labelSubsidySum: Label, }; const tablesComponents: StoreTables = { diff --git a/src/client/Containers/Calculation/lib/elements/elementsProps.ts b/src/client/Containers/Calculation/lib/elements/elementsProps.ts index 4632372..05c8c35 100644 --- a/src/client/Containers/Calculation/lib/elements/elementsProps.ts +++ b/src/client/Containers/Calculation/lib/elements/elementsProps.ts @@ -450,7 +450,7 @@ const elementsProps: TElements = { }, }; -const resultElementsProps: TElements = Object.assign( +const labelElementsProps: TElements = Object.assign( {}, [ 'labelResultTotalGraphwithNDS', @@ -465,6 +465,7 @@ const resultElementsProps: TElements = Object.assign( 'labelResultBonusMPL', 'labelResultDopMPLLeasing', 'labelResultBonusDopProd', + 'labelSubsidySum', ].reduce( (ac, a) => ({ ...ac, @@ -486,4 +487,4 @@ const resultElementsProps: TElements = Object.assign( {}, ), ); -export default Object.assign(elementsProps, resultElementsProps); +export default Object.assign(elementsProps, labelElementsProps); diff --git a/src/client/Containers/Calculation/lib/elements/titles.ts b/src/client/Containers/Calculation/lib/elements/titles.ts index 7b80dd1..679814b 100644 --- a/src/client/Containers/Calculation/lib/elements/titles.ts +++ b/src/client/Containers/Calculation/lib/elements/titles.ts @@ -136,6 +136,9 @@ export const elementsTitles: TElements = { tbxINNForCalc: 'ИНН контрагента', selectLegalClientRegion: 'Регион по юр.адресу клиента', selectLegalClientTown: 'Город по юр.адресу клиента', + selectSubsidy: 'Субсидия', + labelSubsidySum: 'Сумма субсидии с НДС', + selectFuelCard: 'Топливная карта', }; const resultsTitles: TElements = { diff --git a/src/client/Containers/Calculation/lib/elements/values.ts b/src/client/Containers/Calculation/lib/elements/values.ts index bde3df9..c7e88fc 100644 --- a/src/client/Containers/Calculation/lib/elements/values.ts +++ b/src/client/Containers/Calculation/lib/elements/values.ts @@ -135,6 +135,9 @@ export const elementsValues: TElements = { radioTypePTS: 'typePTS', selectLegalClientRegion: 'legalClientRegion', selectLegalClientTown: 'legalClientTown', + selectSubsidy: 'subsidy', + labelSubsidySum: 'subsidySum', + selectFuelCard: 'fuelCard', }; const resultElementsValues: TElements = { diff --git a/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts b/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts index 14fc964..5e8a340 100644 --- a/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts +++ b/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts @@ -16,6 +16,7 @@ const query = gql` $nsib_product_type: Int $tracker_product_type: Int $telematic_product_type: Int + $fuelcard_product_type: Int $techcard_product_type: Int ) { selectSupplier: accounts( @@ -251,9 +252,10 @@ const query = gql` } selectRate: evo_rates( statecode: $statecode - ) # evo_datefrom_param: { lte: $currentDate } - # evo_dateto_param: { gte: $currentDate } - { + evo_datefrom_param: { lte: $currentDate } + evo_dateto_param: { gte: $currentDate } + ) { + createdon evo_id evo_rateid evo_name @@ -267,6 +269,7 @@ const query = gql` evo_tarifid evo_name } + evo_credit_period } selectLeaseObjectType: evo_leasingobject_types(statecode: $statecode) { evo_name @@ -292,6 +295,53 @@ const query = gql` accountid } } + selectSubsidy: evo_subsidies( + statecode: $statecode + evo_datefrom_param: { lte: $currentDate } + evo_dateto_param: { gte: $currentDate } + ) { + evo_name + evo_subsidyid + evo_percent_subsidy + evo_subsidy_summ + evo_max_subsidy_summ + evo_get_subsidy_payment + evo_brands { + evo_brandid + } + evo_models { + evo_modelid + } + evo_leasingobject_types { + evo_leasingobject_typeid + } + accounts { + accountid + } + } + selectFuelCard: evo_addproduct_types( + statecode: $statecode + evo_product_type: $fuelcard_product_type + evo_datefrom_param: { lte: $currentDate } + evo_dateto_param: { gte: $currentDate } + ) { + evo_id + evo_name + evo_addproduct_typeid + evo_accountid + evo_graph_price_withoutnds + evo_cost_service_provider_withoutnds + evo_retro_bonus_withoutnds + evo_prime_cost + evo_graph_price + evo_max_period + evo_min_period + evo_controls_program + evo_helpcard_type + evo_leasingobject_types { + evo_leasingobject_typeid + } + } } `; @@ -309,6 +359,7 @@ const variables = { tracker_product_type: 100000003, telematic_product_type: 100000004, techcard_product_type: 100000000, + fuelcard_product_type: 100000005, }; const toOptions = [ @@ -332,6 +383,8 @@ const toOptions = [ 'selectLeaseObjectType', 'selectObjectRegionRegistration', 'selectLegalClientRegion', + 'selectSubsidy', + 'selectFuelCard', ]; export default { diff --git a/src/client/stores/CalculationStore/Data/values.js b/src/client/stores/CalculationStore/Data/values.js index e890699..9cdaa9f 100644 --- a/src/client/stores/CalculationStore/Data/values.js +++ b/src/client/stores/CalculationStore/Data/values.js @@ -1,5 +1,7 @@ import { getValueName } from 'client/Containers/Calculation/lib/elements/tools'; -import initialFilters from 'client/stores/CalculationStore/config/initialFilters'; +import initialFilters, { + noResetValueElements, +} from 'client/stores/CalculationStore/config/initialFilters'; import initialStatuses from 'client/stores/CalculationStore/config/initialStatuses'; import { isNil, mergeWith, pick } from 'lodash'; @@ -39,6 +41,11 @@ const valuesActions = { this.statuses[elementName] = status; }, + setStatuses(statuses, override) { + if (override) this.statuses = statuses; + this.statuses = Object.assign(this.statuses, statuses); + }, + getValidation(elementName) { return this.validations[elementName]; }, @@ -101,7 +108,8 @@ const valuesActions = { const value = this.getValue(valueName); if ( filter && - !filter(this.getOptions(elementName)).some(x => x.value === value) + !filter(this.getOptions(elementName)).some(x => x.value === value) && + !noResetValueElements.includes(elementName) ) { this.setValue(valueName, null); } diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts index 5435402..75d593a 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts @@ -89,7 +89,7 @@ export default function (this: ICalculationStore): IPreparedData { preparedValues.calcType = values.calcType; preparedValues.irrExpected = (values.IRR_Perc as number) / 100; preparedValues.npvniExpected = 0; - preparedValues.totalExpected = values.totalPayments; + preparedValues.totalExpected = values.totalPayments + values.subsidySum; preparedValues.nmper = values.leasingPeriod; preparedValues.leasing0K = values.product === 'LEASING0' @@ -97,6 +97,9 @@ export default function (this: ICalculationStore): IPreparedData { (0.0234 / ((1 - 1 / 1.0234) ^ ((preparedValues.nmper as number) - 2))) : 1; preparedValues.loanRate = parseFloat(values.creditRate) / 100; + preparedValues.loanRatePeriod = this.getOption( + 'selectRate', + )?.evo_credit_period; preparedValues.balanceHolder = values.balanceHolder; preparedValues.dogDate = preparedValues.calcDate; preparedValues.paymentDateNew = undefined; @@ -107,6 +110,14 @@ export default function (this: ICalculationStore): IPreparedData { preparedValues.lastPayment = (values.lastPaymentPerc as number) / 100; preparedValues.lastPaymentSum = (values.lastPaymentRub as number) / (1 + valuesConstants.VAT); + preparedValues.subsidySum = + parseInt(values.subsidySum) / (1 + valuesConstants.VAT); + preparedValues.subsidyPaymentNumber = this.getOption( + 'selectSubsidy', + )?.evo_get_subsidy_payment; + preparedValues.fuelCardSum = this.getOption( + 'selectFuelCard', + )?.evo_graph_price_withoutnds; preparedValues.scheduleOfPayments = values.graphType; preparedValues.comissionRub = (values.comissionRub as number) / (1 + valuesConstants.VAT); @@ -426,6 +437,8 @@ export default function (this: ICalculationStore): IPreparedData { preparedValues.tLMCost = telematic.evo_graph_price_withoutnds || 0; } + // + const nsibBaseValue = ((preparedValues.plPrice || 0) + (preparedValues.insuranceContract + @@ -512,6 +525,50 @@ export default function (this: ICalculationStore): IPreparedData { } } + if ( + evo_coefficient_bonuses && + evo_coefficient_bonuses.length > 0 && + systemuser + ) { + const evo_sot_coefficient_type = this.getStaticData( + 'evo_sot_coefficient_type', + ).find(x => x.evo_id === 'DIRECTOR_BONUS_NSIB'); + + const evo_coefficient = evo_coefficient_bonuses.find( + x => + x.evo_sot_coefficient_typeid === + evo_sot_coefficient_type?.evo_sot_coefficient_typeid, + ); + + if (evo_coefficient) { + preparedValues.directorBonusNsib = + (evo_coefficient.evo_sot_coefficient || 0) * + (preparedValues.nsibBrutto || 0); + } + } + + if ( + evo_coefficient_bonuses && + evo_coefficient_bonuses.length > 0 && + systemuser + ) { + const evo_sot_coefficient_type = this.getStaticData( + 'evo_sot_coefficient_type', + ).find(x => x.evo_id === 'REGIONAL_DIRECTOR_BONUS_NSIB'); + + const evo_coefficient = evo_coefficient_bonuses.find( + x => + x.evo_sot_coefficient_typeid === + evo_sot_coefficient_type?.evo_sot_coefficient_typeid, + ); + + if (evo_coefficient) { + preparedValues.regionalDirectorBonusNsib = + (evo_coefficient.evo_sot_coefficient || 0) * + (preparedValues.nsibBrutto || 0); + } + } + if ( evo_coefficient_bonuses && evo_coefficient_bonuses.length > 0 && diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/results.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/results.ts index 112f565..2aa1046 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/results.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/results.ts @@ -23,6 +23,14 @@ export default { }, }); } + + const subdidySum = this.getValue('subsidySum') || 0; + if (results[0]?.paymentSum?.value) + results[0].paymentSum.value -= subdidySum; + if (results[0]?.ndsCompensation?.value) { + results[0].ndsCompensation.value -= subdidySum - subdidySum / 1.2; + } + //TODO: speed up table render this.setTableRows('tableResults', 0)(results); } @@ -33,7 +41,10 @@ export default { res: IGetCalculationResponse, ) { const { sumWithVatColumn } = res.columns; - this.setValue('resultTotalGraphwithNDS', sumWithVatColumn?.values[0] || 0); + this.setValue( + 'resultTotalGraphwithNDS', + (sumWithVatColumn?.values[0] || 0) - (this.getValue('subsidySum') || 0), + ); this.setValue( 'resultPlPrice', (preparedData?.preparedValues?.acceptSum || 0) * @@ -74,7 +85,8 @@ export default { this.setValue( 'resultFirstPayment', (preparedData?.preparedValues?.firstPaymentSum || 0) * - (1 + valuesConstants.VAT), + (1 + valuesConstants.VAT) - + this.getValue('subsidySum') || 0, ); this.setValue( 'resultLastPayment', @@ -133,7 +145,8 @@ export default { ); this.setValue( 'totalPayments', - res?.columns?.sumWithVatColumn?.values[0] || 0, + (res?.columns?.sumWithVatColumn?.values[0] || 0) - + (this.getValue('subsidySum') || 0), ); }, }; 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 1eed79c..bbb883f 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/validate/elements.ts @@ -81,7 +81,6 @@ const customConditions: TElements = { } return { isValid: true }; }, - radioRequirementTelematic: calculationStore => { const { telematic, @@ -107,6 +106,28 @@ const customConditions: TElements = { } return { isValid: true }; }, + selectTownRegistration: calculationStore => { + const { + townRegistration, + objectRegistration, + } = calculationStore.getValues(['townRegistration', 'objectRegistration']); + if (objectRegistration === 100000000 && !townRegistration) { + return { + isValid: false, + }; + } + return { + isValid: true, + }; + }, + tbxFirstPaymentRub: calculationStore => { + const { firstPaymentRub, subsidySum } = calculationStore.values; + return { + isValid: firstPaymentRub - subsidySum > 0, + message: + 'Первый платеж с учетом субсидии получается отрицательный, увеличьте первый платеж', + }; + }, }; const elementsValidations: TElements = { @@ -120,7 +141,6 @@ const elementsValidations: TElements = { selectDealer: CONDITIONS.IS_NULL, selectDealerPerson: CONDITIONS.IS_NULL, selectRegionRegistration: CONDITIONS.IS_NULL, - selectTownRegistration: CONDITIONS.IS_NULL, selectTarif: CONDITIONS.IS_NULL, // selectRate: VALIDATIONS.IS_NULL, selectRegistration: CONDITIONS.IS_NULL, diff --git a/src/client/stores/CalculationStore/Effects/autorun.ts b/src/client/stores/CalculationStore/Effects/autorun.ts index 7240949..0767a80 100644 --- a/src/client/stores/CalculationStore/Effects/autorun.ts +++ b/src/client/stores/CalculationStore/Effects/autorun.ts @@ -1,6 +1,7 @@ import { openNotification } from 'client/Elements/Notification'; import { IAutorunEffect } from 'core/types/Calculation/Store/effect'; import { ElementStatus } from 'core/types/statuses'; +import { convertPrice } from './lib/tools'; const autorunEffects: IAutorunEffect[] = [ calculationStore => () => { @@ -186,6 +187,48 @@ const autorunEffects: IAutorunEffect[] = [ } } }, + + calculationStore => () => { + const subsidy = calculationStore.getOption('selectSubsidy'); + if (subsidy?.evo_subsidy_summ && subsidy?.evo_subsidy_summ > 0) { + calculationStore.setValue('subsidySum', subsidy?.evo_subsidy_summ); + } else { + if (subsidy?.evo_max_subsidy_summ) { + const { + leaseObjectPrice, + supplierDiscountRub, + } = calculationStore.values; + const supplierCurrency = calculationStore.getOption( + 'selectSupplierCurrency', + ); + const evo_currencychanges = calculationStore.getStaticData( + 'evo_currencychange', + ); + const evo_currencychange = evo_currencychanges.find( + x => + x.evo_ref_transactioncurrency === + supplierCurrency?.transactioncurrencyid, + ); + const plPriceRub = convertPrice( + supplierCurrency?.isocurrencycode, + leaseObjectPrice - supplierDiscountRub, + evo_currencychange?.evo_currencychange, + ); + + const subsidySum = + (plPriceRub * (subsidy?.evo_percent_subsidy || 0)) / 100; + + const subsidySumValue = + subsidySum > subsidy?.evo_max_subsidy_summ + ? subsidy?.evo_max_subsidy_summ + : subsidySum; + + calculationStore.setValue('subsidySum', subsidySumValue); + } else { + calculationStore.setValue('subsidySum', 0); + } + } + }, ]; export default autorunEffects; diff --git a/src/client/stores/CalculationStore/Effects/computed.js b/src/client/stores/CalculationStore/Effects/computed.js deleted file mode 100644 index b87e7ea..0000000 --- a/src/client/stores/CalculationStore/Effects/computed.js +++ /dev/null @@ -1,66 +0,0 @@ -import customValues from './lib/customValues'; - -const LEASE_OBJECT_RISK = { - 100000000: 'Низкий', - 100000001: 'Средний', - 100000002: 'Высокий', -}; - -const computedEffects = { - // leadName() { - // const leadid = this.values.lead; - // if (this.options.selectLead && this.options.selectLead.length) { - // const lead = this.getOption('selectLead', { leadid }); - // if (lead) { - // return lead.name; - // } - // } - // }, - // opportunityName() { - // const opportunityid = this.values.opportunity; - // if ( - // this.options.selectOpportunity && - // this.options.selectOpportunity.length > 0 - // ) { - // const opportunity = this.getOption('selectOpportunity', { - // opportunityid, - // }); - // if (opportunity) { - // return opportunity.name; - // } - // } - // }, - leaseObjectRiskName() { - const configuration = this.getOption('selectConfiguration'); - if (configuration) { - if (configuration.evo_leasingobject_risk) { - const res = LEASE_OBJECT_RISK[configuration.evo_leasingobject_risk]; - return res; - } - } - - const model = this.getOption('selectModel'); - if (model) { - const evo_leasingobject_risk = model.evo_leasingobject_risk; - return LEASE_OBJECT_RISK[evo_leasingobject_risk]; - } - }, - insKaskoPriceLeasePeriod() { - return customValues.insKaskoPriceLeasePeriod.call(this).toFixed(2); - }, - irrInfo() { - const tarif = this.getOption('selectTarif'); - if (tarif && tarif.evo_min_irr && tarif.evo_max_irr) { - return `Min: ${tarif.evo_min_irr}% - Max: ${tarif.evo_max_irr}%`; - } - return '-'; - }, - registrationDescription() { - const registration = this.getOption('selectRegistration'); - if (registration && registration.evo_description) { - return registration.evo_description; - } - }, -}; - -export default computedEffects; diff --git a/src/client/stores/CalculationStore/Effects/computed.ts b/src/client/stores/CalculationStore/Effects/computed.ts new file mode 100644 index 0000000..1c1432a --- /dev/null +++ b/src/client/stores/CalculationStore/Effects/computed.ts @@ -0,0 +1,44 @@ +import { ICalculationStore } from 'core/types/Calculation/Store'; +import { TValues } from 'core/types/Calculation/Store/values'; +import customValues from './lib/customValues'; + +const LEASE_OBJECT_RISK = { + 100000000: 'Низкий', + 100000001: 'Средний', + 100000002: 'Высокий', +}; + +const computedEffects: TValues< + (this: ICalculationStore) => string | number | undefined +> = { + leaseObjectRiskName: function () { + const configuration = this.getOption('selectConfiguration'); + if (configuration) { + if (configuration.evo_leasingobject_risk) { + const res = LEASE_OBJECT_RISK[configuration.evo_leasingobject_risk]; + return res; + } + } + + const model = this.getOption('selectModel'); + const evo_leasingobject_risk = model?.evo_leasingobject_risk; + if (evo_leasingobject_risk) + return LEASE_OBJECT_RISK[evo_leasingobject_risk]; + }, + insKaskoPriceLeasePeriod: function () { + return customValues.insKaskoPriceLeasePeriod.call(this).toFixed(2); + }, + irrInfo: function () { + const tarif = this.getOption('selectTarif'); + if (tarif && tarif.evo_min_irr && tarif.evo_max_irr) { + return `Min: ${tarif.evo_min_irr}% - Max: ${tarif.evo_max_irr}%`; + } + return '-'; + }, + registrationDescription: function () { + const registration = this.getOption('selectRegistration'); + return registration?.evo_description; + }, +}; + +export default computedEffects; diff --git a/src/client/stores/CalculationStore/Effects/lib/tools.js b/src/client/stores/CalculationStore/Effects/lib/tools.js index 7e334b7..b30f3bf 100644 --- a/src/client/stores/CalculationStore/Effects/lib/tools.js +++ b/src/client/stores/CalculationStore/Effects/lib/tools.js @@ -1,12 +1,8 @@ -export function convertPrice( - isocurrencycode, - leaseObjectPrice, - evo_currencychange, -) { - let price = leaseObjectPrice; +export function convertPrice(isocurrencycode, targetPrice, evo_currencychange) { + let price = targetPrice; const isRUB = !isocurrencycode || isocurrencycode === 'RUB'; if (!isRUB) { - price = leaseObjectPrice * evo_currencychange; + price = targetPrice * evo_currencychange; } return price; } diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts index a9d463f..29d8451 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts @@ -24,7 +24,8 @@ const map_add_product_types_to_values = { registration: 100000001, insNSIB: 100000002, tracker: 100000003, - telematic: 100000004, + telematics: 100000004, + fuelCard: 100000005, }; const tablePaymentsStatuses = (graphType, leasingPeriod) => { diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/mapKpToValues.ts b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/mapKpToValues.ts index d6d1e8d..6149ece 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/mapKpToValues.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/mapKpToValues.ts @@ -1,7 +1,7 @@ import { TValues, ValuesNames } from 'core/types/Calculation/Store/values'; -// import { TCRMEntity } from 'core/types/Entities/crmEntities'; +import { IQuote } from 'core/types/Entities/crmEntities'; -const mapKPtoValues: TValues = { +const mapKPtoValues: TValues = { product: 'evo_baseproductid', clientType: 'evo_client_typeid', leaseObjectPrice: 'evo_supplier_currency_price', @@ -92,6 +92,8 @@ const mapKPtoValues: TValues = { objectCategoryTax: 'evo_category_tr', objectTypeTax: 'evo_vehicle_type_tax', typePTS: 'evo_pts_type', + subsidy: 'evo_subsidyid', + subsidySum: 'evo_subsidy_summ', }; export function getKpPropName(valueName: ValuesNames) { diff --git a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts index 734655b..9101930 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts @@ -1231,10 +1231,19 @@ const reactionEffects: IReactionEffect[] = [ }, effect: leaseObjectUsed => { if (leaseObjectUsed === true) { - calculationStore.setValue('deliveryTime', 100000000); - calculationStore.setStatus('radioDeliveryTime', ElementStatus.Disabled); + calculationStore.setValues({ + deliveryTime: 100000000, + subsidy: null, + }); + calculationStore.setStatuses({ + radioDeliveryTime: ElementStatus.Disabled, + selectSubsidy: ElementStatus.Disabled, + }); } else { - calculationStore.setStatus('radioDeliveryTime', ElementStatus.Default); + calculationStore.setStatuses({ + radioDeliveryTime: ElementStatus.Default, + selectSubsidy: ElementStatus.Default, + }); } }, options: { @@ -1419,9 +1428,32 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setFilter('selectTechnicalCard', options => options.filter( x => - x && - x.evo_max_period && - x.evo_min_period && + 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, + }, + }), + + calculationStore => ({ + expression: () => { + const { leasingPeriod, leaseObjectType } = calculationStore.values; + return { leasingPeriod, leaseObjectType }; + }, + effect: ({ leasingPeriod, leaseObjectType }) => { + calculationStore.setFilter('selectFuelCard', 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( @@ -1487,6 +1519,37 @@ const reactionEffects: IReactionEffect[] = [ }, }), + (calculationStore, calculationProcess) => ({ + expression: () => { + return calculationStore.getValue('leasingPeriod'); + }, + effect: () => { + if (calculationProcess.hasProcess(Process.LoadKp)) { + return; + } + + const fuelCard = calculationStore.getOption('selectFuelCard'); + if (fuelCard) { + const selectFuelCard_filter = calculationStore.getFilter( + 'selectFuelCard', + ); + const selectFueldCard_options = calculationStore.getOptions( + 'selectFuelCard', + ); + + if (selectFuelCard_filter && selectFueldCard_options) { + const filtered_technicalCards = selectFuelCard_filter( + selectFueldCard_options, + ); + calculationStore.setValue( + 'fuelCard', + filtered_technicalCards?.[0]?.evo_addproduct_typeid, + ); + } + } + }, + }), + calculationStore => ({ expression: () => { const { @@ -1679,38 +1742,39 @@ const reactionEffects: IReactionEffect[] = [ return { leaseObjectType: calculationStore.getOption('selectLeaseObjectType'), product: calculationStore.getOption('selectProduct'), + subsidy: calculationStore.getOption('selectSubsidy'), }; }, - effect: ({ leaseObjectType, product }) => { + effect: ({ leaseObjectType, product, subsidy }) => { calculationStore.setStatus( 'selectBrand', leaseObjectType ? ElementStatus.Default : ElementStatus.Disabled, ); - calculationStore.setFilter('selectBrand', options => - options.filter( + calculationStore.setFilter('selectBrand', brands => + brands.filter( pipe( - option => { - if ( - product && - product.evo_brands && - product.evo_brands.length > 0 - ) { - return ( - product.evo_brands - .map(x => x.evo_brandid) - .includes(option.evo_brandid) && option - ); - } - return option; - }, + brand => + (!product?.evo_brands?.length || + product.evo_brands.filter( + x => x.evo_brandid === brand?.evo_brandid, + )?.length) && + brand, - option => - option.evo_vehicle_type && + brand => + brand?.evo_vehicle_type && intersection( - option.evo_vehicle_type?.filter(x => x > 0), + brand.evo_vehicle_type?.filter(x => x > 0), leaseObjectType.evo_vehicle_type, - ).length > 0, + ).length > 0 && + brand, + + brand => + brand && + (!subsidy?.evo_brands || + subsidy?.evo_brands?.filter( + x => x.evo_brandid === brand.evo_brandid, + )?.length), ), ), ); @@ -1725,19 +1789,64 @@ const reactionEffects: IReactionEffect[] = [ return { selectBrandOptions: calculationStore.getOption('selectBrand'), selectBrandFilter: calculationStore.getFilter('selectBrand'), + subsidy: calculationStore.getOption('selectSubsidy'), }; }, - effect: () => { + effect: ({ subsidy }) => { const leaseObjectType = calculationStore.getOption( 'selectLeaseObjectType', ); calculationStore.setFilter('selectModel', options => options.filter( - model => - model.evo_vehicle_type && - leaseObjectType && - leaseObjectType.evo_vehicle_type && - leaseObjectType.evo_vehicle_type.includes(model.evo_vehicle_type), + pipe( + model => + model.evo_vehicle_type && + leaseObjectType?.evo_vehicle_type?.includes( + model.evo_vehicle_type, + ) && + model, + model => + model && + (!subsidy?.evo_models?.length || + subsidy?.evo_models?.filter( + x => x.evo_modelid === model.evo_modelid, + )?.length), + ), + ), + ); + }, + }), + + calculationStore => ({ + expression: () => { + return calculationStore.getOption('selectSubsidy'); + }, + effect: subsidy => { + calculationStore.setFilter('selectLeaseObjectType', types => + types.filter( + type => + !subsidy?.evo_leasingobject_types || + subsidy.evo_leasingobject_types.filter( + x => x.evo_leasingobject_typeid === type.evo_leasingobject_typeid, + )?.length, + ), + ); + + calculationStore.setFilter('selectDealer', dealers => + dealers.filter( + dealer => + !subsidy?.accounts || + subsidy.accounts.filter(x => x.accountid === dealer.accountid) + ?.length, + ), + ); + + calculationStore.setFilter('selectDealerPerson', dealerPersons => + dealerPersons.filter( + dealerPerson => + !subsidy?.accounts || + subsidy.accounts.filter(x => x.accountid === dealerPerson.accountid) + ?.length, ), ); }, @@ -1767,6 +1876,57 @@ const reactionEffects: IReactionEffect[] = [ ); }, }), + + calculationStore => ({ + expression: () => { + return calculationStore.getOption('selectTarif'); + }, + effect: tarif => { + const ratesOptions = calculationStore.getOptions('selectRate'); + if (!ratesOptions) { + return; + } + + let rates = ratesOptions.filter( + rate => + rate?.evo_tarifs?.filter( + evo_tarif => evo_tarif?.evo_tarifid === tarif?.evo_tarifid, + ).length, + ); + + if (!rates?.length) { + rates = ratesOptions.filter(rate => rate.evo_id === 'BASE'); + } + + calculationStore.setValue('rate', rates[0].evo_id); + }, + }), + + calculationStore => ({ + expression: () => { + return calculationStore.getOption('selectSubsidy'); + }, + effect: subsidy => { + if (subsidy) { + calculationStore.setValues({ + leaseObjectCount: 1, + leaseObjectUsed: false, + deliveryTime: 100000000, + }); + } + calculationStore.setStatuses({ + tbxLeaseObjectCount: subsidy + ? ElementStatus.Disabled + : ElementStatus.Default, + cbxLeaseObjectUsed: subsidy + ? ElementStatus.Disabled + : ElementStatus.Default, + radioDeliveryTime: subsidy + ? ElementStatus.Disabled + : ElementStatus.Default, + }); + }, + }), ]; export default reactionEffects; diff --git a/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts index c0595dd..0e60198 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts @@ -504,6 +504,7 @@ const elementsToDisable: (ElementsNames | TableNames)[] = [ 'selectTelematic', 'selectTracker', 'tbxMileage', + 'selectSubsidy', ]; export default reactionEffects; diff --git a/src/client/stores/CalculationStore/config/initialFilters.ts b/src/client/stores/CalculationStore/config/initialFilters.ts index 6b7dc45..a84cd75 100644 --- a/src/client/stores/CalculationStore/config/initialFilters.ts +++ b/src/client/stores/CalculationStore/config/initialFilters.ts @@ -1,6 +1,14 @@ +import { + ElementsNames, + TElements, +} from 'core/types/Calculation/Store/elements'; import { TElementFilter } from 'core/types/Calculation/Store/filters'; -import { TElements } from 'core/types/Calculation/Store/elements'; const initialFilters: TElements = {}; +export const noResetValueElements: ElementsNames[] = [ + 'selectTechnicalCard', + 'selectFuelCard', +]; + export default initialFilters; diff --git a/src/core/services/CalculationService/index.ts b/src/core/services/CalculationService/index.ts index 10e3464..95fe4be 100644 --- a/src/core/services/CalculationService/index.ts +++ b/src/core/services/CalculationService/index.ts @@ -13,7 +13,6 @@ export default class { String.prototype.concat( CORE_PROXY_URL, '/api', - '/v1', '/calculation', '/calculate', ), diff --git a/src/core/services/CrmService/propsMap.ts b/src/core/services/CrmService/propsMap.ts index aee3e70..1567b29 100644 --- a/src/core/services/CrmService/propsMap.ts +++ b/src/core/services/CrmService/propsMap.ts @@ -131,6 +131,10 @@ const propsMap: TEntities<{ name: 'evo_name', value: 'evo_id', }, + evo_subsidy: { + name: 'evo_name', + value: 'evo_subsidyid', + }, }; export default propsMap; diff --git a/src/core/types/Calculation/Prepare.ts b/src/core/types/Calculation/Prepare.ts index 26f878a..029a0c6 100644 --- a/src/core/types/Calculation/Prepare.ts +++ b/src/core/types/Calculation/Prepare.ts @@ -91,6 +91,12 @@ export interface PreparedValues { dogCreditLeasing?: number; tlmCostPaymentSum?: number; gpsCostPaymentSum?: number; + directorBonusNsib?: number; + regionalDirectorBonusNsib?: number; + loanRatePeriod?: number; + subsidySum?: number; + subsidyPaymentNumber?: number; + fuelCardSum?: number; } export interface PaymentRow { diff --git a/src/core/types/Calculation/Store/elements.ts b/src/core/types/Calculation/Store/elements.ts index 871fa14..0063a3d 100644 --- a/src/core/types/Calculation/Store/elements.ts +++ b/src/core/types/Calculation/Store/elements.ts @@ -145,7 +145,10 @@ export type ElementsNames = | 'radioTypePTS' | 'labelRegistrationDescription' | 'selectLegalClientRegion' - | 'selectLegalClientTown'; + | 'selectLegalClientTown' + | 'selectSubsidy' + | 'labelSubsidySum' + | 'selectFuelCard'; export type LinkElementsNames = 'linkDownloadKp'; diff --git a/src/core/types/Calculation/Store/index.ts b/src/core/types/Calculation/Store/index.ts index b8c3614..5fd6772 100644 --- a/src/core/types/Calculation/Store/index.ts +++ b/src/core/types/Calculation/Store/index.ts @@ -46,7 +46,7 @@ interface ICalculationValues { applyOptions: (options: TElements<(IBaseOption & TCRMEntity)[]>) => void; filters: TElements; - getFilter: (elementName: ElementsNames) => TElementFilter; + getFilter: (elementName: ElementsNames) => TElementFilter | undefined; setFilter: ( elementName: ElementsNames, filter: TElementFilter | undefined, @@ -65,6 +65,7 @@ interface ICalculationValues { statuses: TElements; getStatus: (elementName: ElementsNames) => ElementStatus; setStatus: (elementName: ElementsNames, status: ElementStatus) => void; + setStatuses: (statuses: TElements, override?: boolean) => void; validations: TElements; getValidation: (elementName: ElementsNames) => boolean; diff --git a/src/core/types/Calculation/Store/values.ts b/src/core/types/Calculation/Store/values.ts index a30b7b3..99680c4 100644 --- a/src/core/types/Calculation/Store/values.ts +++ b/src/core/types/Calculation/Store/values.ts @@ -131,11 +131,12 @@ export type ValuesNames = | 'objectTypeTax' | 'typePTS' | 'legalClientRegion' - | 'legalClientTown'; + | 'legalClientTown' + | 'subsidy' + | 'subsidySum' + | 'fuelCard'; export type ComputedValuesNames = - | 'leadName' - | 'opportunityName' | 'leaseObjectRiskName' | 'insKaskoPriceLeasePeriod' | 'irrInfo' @@ -163,7 +164,7 @@ type SuitTuple = typeof resultsValues; export type ResultValuesNames = SuitTuple[number]; export type TValues = { - [valueName in ValuesNames | ResultValuesNames]?: T; + [valueName in ValuesNames | ResultValuesNames | ComputedValuesNames]?: T; }; export type TValue = any; diff --git a/src/core/types/Entities/crmEntities.ts b/src/core/types/Entities/crmEntities.ts index ba4103f..1e0c603 100644 --- a/src/core/types/Entities/crmEntities.ts +++ b/src/core/types/Entities/crmEntities.ts @@ -371,6 +371,7 @@ export interface IEvoTarif { } export interface IEvoRate { + createdon?: Date; evo_id?: string; evo_name?: string; evo_rateid?: string; @@ -384,6 +385,8 @@ export interface IEvoRate { evo_dateto?: Date; statecode?: number; evo_brands?: IEvoBrand[]; + evo_credit_period?: number; + evo_tarifs?: IEvoTarif[]; } export interface IEvoPlanPayment { @@ -420,6 +423,17 @@ export interface IEvoJobTitle { evo_job_titleid?: string; } +export interface IEvoSubsidy { + evo_subsidy_summ?: number; + evo_percent_subsidy?: number; + evo_max_subsidy_summ?: number; + evo_subsidyid?: string; + evo_get_subsidy_payment?: number; + evo_brands?: IEvoBrand[]; + evo_models?: IEvoModel[]; + accounts?: IAccount[]; +} + type BaseEntity = { __typename?: CRMEntityNames; }; @@ -456,4 +470,5 @@ export type TCRMEntity = BaseEntity & IEvoPlanPayment & ISystemUser & IEvoJobTitle & - IEvoSotCoefficientType; + IEvoSotCoefficientType & + IEvoSubsidy; diff --git a/src/core/types/Entities/crmEntityNames.ts b/src/core/types/Entities/crmEntityNames.ts index be07889..17391c0 100644 --- a/src/core/types/Entities/crmEntityNames.ts +++ b/src/core/types/Entities/crmEntityNames.ts @@ -28,7 +28,8 @@ export type CRMEntityNames = | 'evo_rate' | 'evo_planpayment' | 'systemuser' - | 'evo_sot_coefficient_type'; + | 'evo_sot_coefficient_type' + | 'evo_subsidy'; //TODO: or string export type TEntities = {