diff --git a/src/client/stores/CalculationStore/Effects/lib/tools.js b/src/client/stores/CalculationStore/Effects/lib/tools.js new file mode 100644 index 0000000..a5c7415 --- /dev/null +++ b/src/client/stores/CalculationStore/Effects/lib/tools.js @@ -0,0 +1,12 @@ +export function calcSupplierPrice( + isocurrencycode, + leaseObjectPrice, + evo_currencychange, +) { + let price = leaseObjectPrice; + const isRUB = !isocurrencycode || isocurrencycode === 'RUB'; + if (!isRUB) { + price = leaseObjectPrice * evo_currencychange; + } + return price; +} diff --git a/src/client/stores/CalculationStore/Effects/reaction.ts b/src/client/stores/CalculationStore/Effects/reaction.ts index 60d49c0..8e73cc5 100644 --- a/src/client/stores/CalculationStore/Effects/reaction.ts +++ b/src/client/stores/CalculationStore/Effects/reaction.ts @@ -2,6 +2,7 @@ import { openNotification } from 'client/Elements/Notification'; import CalculationService from 'client/services/CalculationService'; import { IReactionEffect } from 'core/types/effect'; import { Status } from 'core/types/statuses'; +import { calcSupplierPrice } from './lib/tools'; const reactionEffects: IReactionEffect[] = [ calculationStore => ({ @@ -1536,6 +1537,70 @@ const reactionEffects: IReactionEffect[] = [ calculationStore.setValue('depreciationGroup', null); }, }), + + calculationStore => ({ + expression: () => { + const { + supplierCurrency, + leaseObjectPrice, + supplierDiscountRub, + } = calculationStore.values; + return [supplierCurrency, leaseObjectPrice, supplierDiscountRub]; + }, + effect: ([supplierCurrencyId, leaseObjectPrice, supplierDiscountRub]) => { + if (supplierDiscountRub === undefined) { + return; + } + // TODO: check evo_currecychange + const supplierCurrency = calculationStore + .getOptions('selectSupplierCurrency') + .find(x => x.transactioncurrencyid === supplierCurrencyId); + const evo_currencychange = calculationStore + .getStaticData('evo_currencychange') + ?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId); + const evo_currencychangeValue = + (evo_currencychange && evo_currencychange.evo_currencychange) || 0; + let price = calcSupplierPrice( + supplierCurrency?.isocurrencycode, + parseFloat(leaseObjectPrice), + evo_currencychangeValue, + ); + let perc = (supplierDiscountRub / price) * 100; + calculationStore.setValue('supplierDiscountPerc', perc); + }, + }), + + calculationStore => ({ + expression: () => { + const { + supplierCurrency, + leaseObjectPrice, + supplierDiscountPerc, + } = calculationStore.values; + return [supplierCurrency, leaseObjectPrice, supplierDiscountPerc]; + }, + effect: ([supplierCurrencyId, leaseObjectPrice, supplierDiscountPerc]) => { + if (supplierDiscountPerc === undefined) { + return; + } + // TODO: check evo_currecychange + const supplierCurrency = calculationStore + .getOptions('selectSupplierCurrency') + .find(x => x.transactioncurrencyid === supplierCurrencyId); + const evo_currencychange = calculationStore + .getStaticData('evo_currencychange') + ?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId); + const evo_currencychangeValue = + (evo_currencychange && evo_currencychange.evo_currencychange) || 0; + let price = calcSupplierPrice( + supplierCurrency?.isocurrencycode, + parseFloat(leaseObjectPrice), + evo_currencychangeValue, + ); + let rub = (supplierDiscountPerc * price) / 100; + calculationStore.setValue('supplierDiscountRub', rub); + }, + }), ]; export default reactionEffects; diff --git a/src/core/Data/staticEntitiesList.ts b/src/core/Data/staticEntitiesList.ts index 3fe308a..621c99d 100644 --- a/src/core/Data/staticEntitiesList.ts +++ b/src/core/Data/staticEntitiesList.ts @@ -3,6 +3,14 @@ import { IGetEntity } from '../types/Requests/Calculation'; const staticEntitiesList: IGetEntity[] = [ { entityName: 'evo_impairment_group', + where: { + statecode: 0, + }, + }, + { + entityName: 'evo_currencychange', + evo_coursedate: new Date(), + statecode: 0, }, ]; diff --git a/src/core/config/initialValues.ts b/src/core/config/initialValues.ts index ee17ab0..4de1d16 100644 --- a/src/core/config/initialValues.ts +++ b/src/core/config/initialValues.ts @@ -3,10 +3,10 @@ const initialValues: TValues = { recalcWithRevision: false, contactGender: 100000000, leaseObjectPrice: 1000000, - supplierCurrency: 'RUB', + // supplierCurrency: 'RUB', supplierDiscountRub: 0, supplierDiscountPerc: 0, - addEquipmentCurrency: 'RUB', + // addEquipmentCurrency: 'RUB', addEquipmentPrice: 0, addEquipmentPayer: 100000000, leasingPeriod: 12, diff --git a/src/core/fakeData/calculation.js b/src/core/fakeData/calculation.js deleted file mode 100644 index dad20b2..0000000 --- a/src/core/fakeData/calculation.js +++ /dev/null @@ -1,378 +0,0 @@ -import faker from 'faker'; - -const calculationFakeData = { - selectSupplier: [ - { - name: 'RENAULT (Престиж)', - value: faker.random.uuid(), - }, - { - name: 'MITSUBISHI (Рольф)', - value: faker.random.uuid(), - }, - { - name: 'Volkswagen (ФаворитАвто)', - value: faker.random.uuid(), - }, - ], - selectFinDepartment: [ - { - name: 'Финотдел1', - value: faker.random.uuid(), - }, - { - name: 'Финотдел2', - value: faker.random.uuid(), - }, - { - name: 'Финотдел3', - value: faker.random.uuid(), - }, - ], - selectAddEquipmentCurrency: [ - { - name: 'RUB', - value: 'rub', - }, - { - name: 'USD', - value: 'usd', - }, - { - name: 'EUR', - value: 'eur', - }, - ], - selectClientType: [ - { - name: 'Новый', - value: 'new', - }, - { - name: 'Повторный', - value: 'repeat', - }, - ], - selectClientRisk: [ - { - name: 'Низкий', - value: 'low', - }, - { - name: 'Средний', - value: 'mid', - }, - { - name: 'Высокий', - value: 'high', - }, - ], - selectProduct: [ - { - name: 'Такси', - value: 'Taxi', - }, - { - name: 'ЕвоХард', - value: 'EuroHard', - }, - ], - selectLeaseObjectType: [ - { - name: 'Легковой автомобиль', - value: 'lehkovoy', - }, - { - name: 'Грузовой автомобиль', - value: 'gruzovoy', - }, - { - name: 'Спецтехника', - value: 'special', - }, - { - name: 'Прицеп', - value: 'prizep', - }, - ], - selectBrand: [ - { - name: 'Audi', - value: 'audi', - }, - { - name: 'BMW', - value: 'bmw', - }, - { - name: 'Chevrolet', - value: 'chevrolet', - }, - { - name: 'Toyota', - value: 'toyota', - }, - ], - selectModel: [ - { - name: 'Q5', - value: 'q5', - brand: 'audi', - }, - { - name: 'A3', - value: 'a3', - brand: 'audi', - }, - ], - selectConfiguration: [ - { - name: 'Комплектация 1', - value: 'compl1', - }, - { - name: 'Комплектация 2', - value: 'compl2', - }, - ], - selectDealer: [ - { - name: 'RENAULT (Престиж)', - value: faker.random.uuid(), - }, - { - name: 'MITSUBISHI (Рольф)', - value: faker.random.uuid(), - }, - { - name: 'Volkswagen (ФаворитАвто)', - value: faker.random.uuid(), - }, - ], - selectDealerPerson: [ - { - name: 'ООО "Престиж-Авто"', - value: faker.random.uuid(), - }, - { - name: 'ООО "Рольф"', - value: faker.random.uuid(), - }, - { - name: 'ООО "Авто-Рус-Моторс', - value: faker.random.uuid(), - }, - ], - selectDealerRewardСondition: [ - { - name: 'АВ не более 3% ЮЛ Новый', - value: faker.random.uuid(), - }, - { - name: ' АВ не более 1,5% ЮЛ Новый', - value: faker.random.uuid(), - }, - { - name: 'АВ не более 1% ЮЛ Новый', - value: faker.random.uuid(), - }, - ], - selectDealerBroker: [ - { - name: 'ИП Иванов', - value: 'Ivanov', - }, - { - name: 'ИП Смирнов', - value: 'Smirnov', - }, - ], - selectDealerBrokerRewardСondition: [ - { - name: 'АВ не более 3% Брокер Новый', - value: faker.random.uuid(), - }, - { - name: ' АВ не более 1,5% Брокер Новый', - value: faker.random.uuid(), - }, - { - name: 'АВ не более 1% Брокер Новый', - value: faker.random.uuid(), - }, - ], - selectIndAgentRewardCondition: [ - { - name: 'АВ не более 3% ФЛ Новый', - value: faker.random.uuid(), - }, - { - name: ' АВ не более 1,5% ФЛ Новый', - value: faker.random.uuid(), - }, - { - name: 'АВ не более 1% ФЛ Новый', - value: faker.random.uuid(), - }, - ], - selectCalcBrokerRewardCondition: [ - { - name: 'АВ не более 3% Брокер Новый', - value: faker.random.uuid(), - }, - { - name: ' АВ не более 1,5% Брокер Новый', - value: faker.random.uuid(), - }, - { - name: 'АВ не более 1% Брокер Новый', - value: faker.random.uuid(), - }, - ], - selectFinDepartmentRewardCondtion: [ - { - name: 'АВ не более 3% ФиноФинотдел Новый', - value: faker.random.uuid(), - }, - { - name: ' АВ не более 1,5% Финотдел Новый', - value: faker.random.uuid(), - }, - { - name: 'АВ не более 1% Финотдел Новый', - value: faker.random.uuid(), - }, - ], - selectGPSBrand: [ - { name: 'Цезарь Сателлит', value: 'cezar' }, - { name: 'Аркан', value: 'arkan' }, - { name: 'КобраКоннекс', value: 'kobra' }, - ], - selectGPSModel: [ - { - name: 'OmegaX', - value: 'omegax', - }, - { - name: 'Platinum', - value: 'platinum', - }, - ], - selectRegionRegistration: [ - { - name: 'Московская', - value: 'moscow', - }, - { - name: 'Калининградская', - value: 'kaliningrad', - }, - ], - selectTownRegistration: [ - { - name: 'Калининградская', - value: 'kaliningrad', - }, - { - name: 'Рязань', - value: 'ryazan', - }, - ], - selectLead: [ - { - name: '100_ООО "Архимаг', - id: 'arhimagLead', - value: 'arhimagLead', - evo_opportunityid: 'arhimagOpportunity', - }, - { - name: '150_ООО "Некромант', - id: 'nekroLead', - value: 'nekroLead', - evo_opportunityid: 'nekroOpportunity', - }, - { - name: '200_ООО "Кардинал', - id: 'kardinalLead', - value: 'kardinalLead', - evo_opportunityid: 'kardinalOpportunity', - }, - ], - selectOpportunity: [ - { - name: '112345_ООО "Архимаг', - id: 'arhimagOpportunity', - value: 'arhimagOpportunity', - }, - { - name: '145678_ООО "Некромант', - id: 'nekroOpportunity', - value: 'nekroOpportunity', - }, - { - name: '243910_ООО Кардинал', - id: 'kardinalOpportunity', - value: 'kardinalOpportunity', - }, - ], - selectQuote: [ - { - name: '2345_ООО "Архимаг"', - id: 'arhimagQuote', - value: 'arhimagQuote', - evo_leadid: 'arhimagLead', - }, - { - name: '6789_ООО "Некромант"', - id: 'nekroQuote', - value: 'nekroQuote', - evo_leadid: 'nekroLead', - }, - { - name: '8765_ООО "Кардинал', - id: 'kardinalQuote', - value: 'kardinalQuote', - // evo_leadid: 'kardinalLead', - }, - ], - selectBroker: [ - { - name: 'ИП Иванов', - value: 'Ivanov', - }, - { - name: 'ИП Смирнов', - value: 'Smirnov', - }, - ], - selectAccount: [ - { - name: 'Архимаг', - value: faker.random.uuid(), - }, - { - name: 'Некромант', - value: faker.random.uuid(), - }, - { - name: 'Кардинал', - value: faker.random.uuid(), - }, - ], - selectContactClient: [ - { - name: 'Семенов Семен Семенович', - value: faker.random.uuid(), - }, - { - name: 'Иванова Александра Сергеевна', - value: faker.random.uuid(), - }, - { - name: 'Алексеев Алексей Алексеевич', - value: faker.random.uuid(), - }, - ], -}; - -export default calculationFakeData; diff --git a/src/core/fakeData/entityFakes.ts b/src/core/fakeData/entityFakes.ts index a01fb92..48aa0c3 100644 --- a/src/core/fakeData/entityFakes.ts +++ b/src/core/fakeData/entityFakes.ts @@ -35,6 +35,7 @@ const QUOTE_4_ID = faker.random.uuid(); const TRANSACTION_CURRENTCY_1_ID = faker.random.uuid(); const TRANSACTION_CURRENTCY_2_ID = faker.random.uuid(); +const TRANSACTION_CURRENTCY_3_ID = faker.random.uuid(); const EVO_CLIENT_1_ID = faker.random.uuid(); const EVO_CLIENT_2_ID = faker.random.uuid(); @@ -89,6 +90,9 @@ const EVO_EQUIPMENT_ID = Array.from({ length: 10 }, () => faker.random.uuid()); const EVO_IMPAIRMENT_GROUP_ID = Array.from({ length: 10 }, () => faker.random.uuid(), ); +const EVO_CURRENCY_CHANGE_ID = Array.from({ length: 5 }, () => + faker.random.uuid(), +); /** * Fake Consts @@ -205,6 +209,11 @@ const entityFakeData: { isocurrencycode: 'USD', statecode: 0, }, + { + transactioncurrencyid: TRANSACTION_CURRENTCY_3_ID, + isocurrencycode: 'EUR', + statecode: 0, + }, ], evo_client_type: [ { @@ -597,10 +606,30 @@ const entityFakeData: { { evo_name: 'Группа #1', evo_impairment_groupid: EVO_IMPAIRMENT_GROUP_ID[0], + statecode: 0, }, { evo_name: 'Группа #2', evo_impairment_groupid: EVO_IMPAIRMENT_GROUP_ID[1], + statecode: 0, + }, + ], + evo_currencychange: [ + { + evo_currencychangeid: EVO_CURRENCY_CHANGE_ID[0], + evo_name: 'Доллар на сегодня', + evo_ref_transactioncurrency: TRANSACTION_CURRENTCY_2_ID, + evo_currencychange: 100, + evo_coursedate: new Date(), + statecode: 0, + }, + { + evo_currencychangeid: EVO_CURRENCY_CHANGE_ID[1], + evo_name: 'Евро на сегодня', + evo_ref_transactioncurrency: TRANSACTION_CURRENTCY_3_ID, + evo_currencychange: 200, + evo_coursedate: new Date(), + statecode: 0, }, ], }; diff --git a/src/core/types/Entities/entityNames.ts b/src/core/types/Entities/entityNames.ts index c039010..8738b66 100644 --- a/src/core/types/Entities/entityNames.ts +++ b/src/core/types/Entities/entityNames.ts @@ -19,4 +19,5 @@ export type EntityNames = | 'evo_town' | 'connection' | 'evo_connection_role' - | 'evo_impairment_group'; + | 'evo_impairment_group' + | 'evo_currencychange'; diff --git a/src/core/types/Entities/index.ts b/src/core/types/Entities/index.ts index 3506f4e..d539652 100644 --- a/src/core/types/Entities/index.ts +++ b/src/core/types/Entities/index.ts @@ -145,6 +145,15 @@ export interface IEvoImpairmentGroup extends IBaseOption { evo_impairment_groupid?: string; } +export interface IEvoCurrencyChange extends IBaseOption { + evo_currencychangeid?: string; + evo_name?: string; + evo_ref_transactioncurrency?: string; + evo_currencychange?: number; + evo_coursedate?: Date; + statecode?: number; +} + export type TEntity = IAccount & ILead & IOpportunity & @@ -165,4 +174,5 @@ export type TEntity = IAccount & IEvoContact & IConnection & IEvoConnectionRole & - IEvoImpairmentGroup; + IEvoImpairmentGroup & + IEvoCurrencyChange; diff --git a/src/core/types/staticData.ts b/src/core/types/staticData.ts index 5c0d26f..75630f1 100644 --- a/src/core/types/staticData.ts +++ b/src/core/types/staticData.ts @@ -2,7 +2,7 @@ import { EntityNames } from 'core/types/Entities/entityNames'; import { IOption } from './Calculation/options'; import { TValue } from './values'; -export type StaticDataNames = 'evo_impairment_group'; +export type StaticDataNames = ''; export type TStaticData = { [dataName in StaticDataNames | EntityNames]?: IOption[] | TValue; diff --git a/src/core/types/stores.ts b/src/core/types/stores.ts index 024ef30..11518c6 100644 --- a/src/core/types/stores.ts +++ b/src/core/types/stores.ts @@ -1,6 +1,7 @@ import { TElementFilter } from 'core/types/Calculation/filters'; import { IBaseOption, IOption } from 'core/types/Calculation/options'; import { ElementsNames, TElements } from './elements'; +import { EntityNames } from './Entities/entityNames'; import { StaticDataNames, TStaticData } from './staticData'; import { Status } from './statuses'; import { @@ -14,7 +15,7 @@ import { TValue, TValues, ValuesNames } from './values'; export interface ICalculationStore { staticData: TStaticData; - getStaticData: (dataName: StaticDataNames) => IOption[]; + getStaticData: (dataName: StaticDataNames | EntityNames) => IOption[]; setStaticData: (data: TStaticData) => void; options: TElements;