effect: supplier currency

This commit is contained in:
Chika 2020-09-29 16:37:44 +03:00
parent 30b2458be7
commit 6cb0bda37d
10 changed files with 132 additions and 384 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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,
},
];

View File

@ -3,10 +3,10 @@ const initialValues: TValues<TValue> = {
recalcWithRevision: false,
contactGender: 100000000,
leaseObjectPrice: 1000000,
supplierCurrency: 'RUB',
// supplierCurrency: 'RUB',
supplierDiscountRub: 0,
supplierDiscountPerc: 0,
addEquipmentCurrency: 'RUB',
// addEquipmentCurrency: 'RUB',
addEquipmentPrice: 0,
addEquipmentPayer: 100000000,
leasingPeriod: 12,

View File

@ -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;

View File

@ -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,
},
],
};

View File

@ -19,4 +19,5 @@ export type EntityNames =
| 'evo_town'
| 'connection'
| 'evo_connection_role'
| 'evo_impairment_group';
| 'evo_impairment_group'
| 'evo_currencychange';

View File

@ -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;

View File

@ -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;

View File

@ -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<IOption[]>;