stores: clarified values types
add default-values
This commit is contained in:
parent
8f0ac2cf40
commit
63ac9958f1
@ -1,4 +1,4 @@
|
||||
import type { Values, ValuesTypes } from 'stores/calculation/values/types';
|
||||
import type { CalculationValues, Values } from 'stores/calculation/values/types';
|
||||
|
||||
function wrapElementsMap<T extends Record<string, Values>>(arg: T) {
|
||||
return arg;
|
||||
@ -156,7 +156,7 @@ const elementsToValues = wrapElementsMap({
|
||||
type ElementsValues = typeof elementsToValues;
|
||||
|
||||
export type ElementsTypes = {
|
||||
[Key in keyof ElementsValues]: ValuesTypes[ElementsValues[Key]];
|
||||
[Key in keyof ElementsValues]: CalculationValues[ElementsValues[Key]];
|
||||
};
|
||||
|
||||
export type Elements = keyof ElementsValues;
|
||||
|
||||
151
config/default-values.ts
Normal file
151
config/default-values.ts
Normal file
@ -0,0 +1,151 @@
|
||||
import { RATE } from 'constants/values';
|
||||
import type { CalculationValues } from 'stores/calculation/values/types';
|
||||
import date from 'tools/date';
|
||||
|
||||
const defaultValues: CalculationValues = {
|
||||
lead: null,
|
||||
opportunity: null,
|
||||
quote: null,
|
||||
recalcWithRevision: false,
|
||||
leaseObjectPrice: 1000000,
|
||||
VATInLeaseObjectPrice: 0,
|
||||
leaseObjectPriceWthtVAT: 0,
|
||||
engineHours: 0,
|
||||
supplierCurrency: 'RUB',
|
||||
supplierDiscountRub: 0,
|
||||
supplierDiscountPerc: 0,
|
||||
leasingPeriod: 13,
|
||||
firstPaymentPerc: 25,
|
||||
firstPaymentRub: 0,
|
||||
lastPaymentPerc: 1,
|
||||
lastPaymentRule: 100000001,
|
||||
redemptionPaymentSum: 1000,
|
||||
balanceHolder: 100000001,
|
||||
graphType: 100000000,
|
||||
parmentsDecreasePercent: 94,
|
||||
seasonType: 100000000,
|
||||
highSeasonStart: 100000000,
|
||||
comissionPerc: 0,
|
||||
comissionRub: 0,
|
||||
saleBonus: 1.3,
|
||||
IRR_Perc: 20,
|
||||
brand: null,
|
||||
model: null,
|
||||
configuration: null,
|
||||
deliveryTime: 100000000,
|
||||
leaseObjectCount: 1,
|
||||
withTrailer: false,
|
||||
leaseObjectUsed: false,
|
||||
maxMass: 0,
|
||||
countSeats: 0,
|
||||
maxSpeed: 0,
|
||||
leaseObjectYear: date().year(),
|
||||
engineType: 100000000,
|
||||
leaseObjectCategory: null,
|
||||
leaseObjectMotorPower: 0,
|
||||
engineVolume: 0,
|
||||
dealerRewardSumm: 0,
|
||||
dealerBrokerRewardSumm: 0,
|
||||
indAgent: null,
|
||||
calcDoubleAgent: null,
|
||||
calcBroker: null,
|
||||
calcFinDepartment: null,
|
||||
dealerPerson: null,
|
||||
dealerBroker: null,
|
||||
dealer: null,
|
||||
indAgentRewardSumm: 0,
|
||||
calcDoubleAgentRewardSumm: 0,
|
||||
calcBrokerRewardSum: 0,
|
||||
finDepartmentRewardSumm: 0,
|
||||
insKaskoType: 100000000,
|
||||
insDecentral: false,
|
||||
insUnlimitDrivers: true,
|
||||
insAgeDrivers: 0,
|
||||
insExpDrivers: 0,
|
||||
lastPaymentRedemption: true,
|
||||
priceWithDiscount: false,
|
||||
fullPriceWithDiscount: false,
|
||||
costIncrease: true,
|
||||
insurance: true,
|
||||
registrationQuote: true,
|
||||
technicalCardQuote: true,
|
||||
NSIB: true,
|
||||
quoteContactGender: 100000000,
|
||||
quoteRedemptionGraph: true,
|
||||
showFinGAP: true,
|
||||
creditRate: RATE,
|
||||
requirementTelematic: 100000000,
|
||||
maxPriceChange: 0,
|
||||
importerRewardPerc: 0,
|
||||
importerRewardRub: 0,
|
||||
disableChecks: false,
|
||||
insFranchise: 0,
|
||||
rate: 'BASE',
|
||||
calcType: 100000000,
|
||||
totalPayments: 0,
|
||||
vehicleTaxInYear: 0,
|
||||
vehicleTaxInLeasingPeriod: 0,
|
||||
objectRegistration: 100000000,
|
||||
typePTS: 100000001,
|
||||
insNSIB: null,
|
||||
regionRegistration: null,
|
||||
legalClientRegion: null,
|
||||
legalClientTown: null,
|
||||
infuranceOPF: null,
|
||||
|
||||
GPSBrand: null,
|
||||
GPSModel: null,
|
||||
INNForCalc: 0,
|
||||
calcBrokerRewardCondition: null,
|
||||
calcDoubleAgentRewardCondition: null,
|
||||
clientRisk: null,
|
||||
clientType: null,
|
||||
dealerBrokerRewardCondition: null,
|
||||
dealerRewardCondition: null,
|
||||
depreciationGroup: null,
|
||||
finDepartmentRewardCondtion: null,
|
||||
fuelCard: null,
|
||||
indAgentRewardCondition: null,
|
||||
kpUrl: null,
|
||||
lastPaymentRub: 0,
|
||||
leadUrl: null,
|
||||
leaseObjectType: null,
|
||||
leaseObjectUseFor: null,
|
||||
mileage: 0,
|
||||
minPriceChange: 0,
|
||||
objectCategoryTax: null,
|
||||
objectRegionRegistration: null,
|
||||
objectTypeTax: null,
|
||||
opportunityUrl: null,
|
||||
product: null,
|
||||
quoteName: null,
|
||||
quoteUrl: null,
|
||||
registration: null,
|
||||
subsidy: null,
|
||||
subsidySum: 0,
|
||||
tarif: null,
|
||||
technicalCard: null,
|
||||
telematic: null,
|
||||
townRegistration: null,
|
||||
tracker: null,
|
||||
resultAB_FL: 0,
|
||||
resultAB_UL: 0,
|
||||
resultBonusDopProd: 0,
|
||||
resultBonusMPL: 0,
|
||||
resultBonusSafeFinance: 0,
|
||||
resultDopMPLLeasing: 0,
|
||||
resultDopProdSum: 0,
|
||||
resultFirstPayment: 0,
|
||||
resultFirstPaymentRiskPolicy: 0,
|
||||
resultIRRGraphPerc: 0,
|
||||
resultIRRNominalPerc: 0,
|
||||
resultInsKasko: 0,
|
||||
resultInsOsago: 0,
|
||||
resultLastPayment: 0,
|
||||
resultPlPrice: 0,
|
||||
resultPriceUpPr: 0,
|
||||
resultTerm: 0,
|
||||
resultTotalGraphwithNDS: 0,
|
||||
};
|
||||
|
||||
export default defaultValues;
|
||||
@ -1,3 +1,5 @@
|
||||
export const MAX_FRANCHISE = 75000;
|
||||
export const MAX_INSURANCE = 2500000;
|
||||
export const MIN_INSURANCE = 3000;
|
||||
|
||||
export const RATE = 7.75;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* eslint-disable import/no-cycle */
|
||||
import { makeAutoObservable } from 'mobx';
|
||||
import RootStore from 'stores/root';
|
||||
import type RootStore from 'stores/root';
|
||||
|
||||
export default class Computed {
|
||||
root: RootStore;
|
||||
|
||||
@ -3,14 +3,15 @@
|
||||
/* eslint-disable import/no-cycle */
|
||||
import type { Elements, ElementsTypes } from 'Components/Calculation/config/map-values';
|
||||
import { getValueName } from 'Components/Calculation/config/map-values';
|
||||
import defaultValues from 'config/default-values';
|
||||
import { makeAutoObservable } from 'mobx';
|
||||
import RootStore from '../../root';
|
||||
import type RootStore from '../../root';
|
||||
import Computed from './computed';
|
||||
import type { CalculationValues, Values, ValuesTypes } from './types';
|
||||
import type { CalculationValues, Values } from './types';
|
||||
|
||||
export default class ValuesStore {
|
||||
root: RootStore;
|
||||
values: CalculationValues = {};
|
||||
values = defaultValues;
|
||||
$computed: Computed;
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
@ -29,18 +30,20 @@ export default class ValuesStore {
|
||||
|
||||
getValueByElement<E extends Elements>(elementName: E) {
|
||||
const valueName = getValueName(elementName);
|
||||
return this.getValue(valueName) as ElementsTypes[E] | undefined;
|
||||
|
||||
return this.getValue(valueName) as ElementsTypes[E];
|
||||
}
|
||||
|
||||
getValues<V extends Values>(valuesNames: readonly V[]) {
|
||||
return valuesNames.reduce((values, valueName) => {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
values[valueName] = this.getValue(valueName);
|
||||
|
||||
return values;
|
||||
}, {} as Pick<CalculationValues, typeof valuesNames[number]>);
|
||||
}
|
||||
|
||||
setValue = <V extends Values>(valueName: V, value: ValuesTypes[V]) => {
|
||||
setValue = <V extends Values>(valueName: V, value: CalculationValues[V]) => {
|
||||
this.values[valueName] = value;
|
||||
};
|
||||
|
||||
@ -49,9 +52,27 @@ export default class ValuesStore {
|
||||
this.setValue(valueName, value);
|
||||
};
|
||||
|
||||
setValues = (values: CalculationValues, settings: { replace?: boolean }) => {
|
||||
if (settings?.replace) this.values = values;
|
||||
this.values = Object.assign(this.values, values);
|
||||
resetValues = (valuesNames: readonly Values[]) => {
|
||||
valuesNames.forEach((valueName) => {
|
||||
this.setValue(valueName, defaultValues[valueName]);
|
||||
});
|
||||
};
|
||||
|
||||
setValues = (
|
||||
values: Partial<CalculationValues>,
|
||||
settings?: { reset: boolean; exclude: Values[] }
|
||||
) => {
|
||||
if (settings?.reset) {
|
||||
this.resetValues(
|
||||
(Object.keys(defaultValues) as Values[]).filter(
|
||||
(valueName) => !settings?.exclude.includes(valueName)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
(Object.keys(values) as Values[]).forEach((valueName) => {
|
||||
this.setValue(valueName, values[valueName]!);
|
||||
});
|
||||
};
|
||||
|
||||
clearValue = (valueName: Values) => {
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
interface Types {
|
||||
lead: string;
|
||||
opportunity: string;
|
||||
quote: string;
|
||||
export type CalculationValues = {
|
||||
lead: string | null;
|
||||
opportunity: string | null;
|
||||
quote: string | null;
|
||||
recalcWithRevision: boolean;
|
||||
product: string;
|
||||
clientRisk: string;
|
||||
clientType: string;
|
||||
product: string | null;
|
||||
clientRisk: string | null;
|
||||
clientType: string | null;
|
||||
leaseObjectPrice: number;
|
||||
supplierCurrency: string;
|
||||
supplierCurrency: string | null;
|
||||
supplierDiscountRub: number;
|
||||
supplierDiscountPerc: number;
|
||||
leasingPeriod: number;
|
||||
@ -15,10 +15,10 @@ interface Types {
|
||||
firstPaymentRub: number;
|
||||
lastPaymentPerc: number;
|
||||
lastPaymentRub: number;
|
||||
lastPaymentRule: 100_000_000 | 100_000_001 | 100_000_002;
|
||||
lastPaymentRule: 100_000_000 | 100_000_001 | 100_000_002 | null;
|
||||
redemptionPaymentSum: number;
|
||||
balanceHolder: 100_000_000 | 100_000_001;
|
||||
graphType: 100_000_000 | 100_000_001 | 100_000_002 | 100_000_003 | 100_000_004;
|
||||
balanceHolder: 100_000_000 | 100_000_001 | null;
|
||||
graphType: 100_000_000 | 100_000_001 | 100_000_002 | 100_000_003 | 100_000_004 | null;
|
||||
|
||||
parmentsDecreasePercent: number;
|
||||
seasonType:
|
||||
@ -29,7 +29,8 @@ interface Types {
|
||||
| 100_000_004
|
||||
| 100_000_005
|
||||
| 100_000_006
|
||||
| 100_000_007;
|
||||
| 100_000_007
|
||||
| null;
|
||||
highSeasonStart:
|
||||
| 100_000_000
|
||||
| 100_000_001
|
||||
@ -43,12 +44,13 @@ interface Types {
|
||||
| 100_000_009
|
||||
| 100_000_010
|
||||
| 100_000_011
|
||||
| 100_000_012;
|
||||
| 100_000_012
|
||||
| null;
|
||||
comissionPerc: number;
|
||||
comissionRub: number;
|
||||
saleBonus: number;
|
||||
IRR_Perc: number;
|
||||
leaseObjectType: string;
|
||||
leaseObjectType: string | null;
|
||||
deliveryTime:
|
||||
| 100_000_000
|
||||
| 100_000_001
|
||||
@ -62,20 +64,21 @@ interface Types {
|
||||
| 100_000_009
|
||||
| 100_000_010
|
||||
| 100_000_011
|
||||
| 100_000_012;
|
||||
depreciationGroup: string;
|
||||
| 100_000_012
|
||||
| null;
|
||||
depreciationGroup: string | null;
|
||||
leaseObjectCount: number;
|
||||
withTrailer: boolean;
|
||||
leaseObjectUsed: boolean;
|
||||
maxMass: number;
|
||||
countSeats: number;
|
||||
maxSpeed: number;
|
||||
brand: string;
|
||||
model: string;
|
||||
configuration: string;
|
||||
brand: string | null;
|
||||
model: string | null;
|
||||
configuration: string | null;
|
||||
leaseObjectYear: number;
|
||||
engineType: 100_000_000 | 100_000_001 | 100_000_002 | 100_000_003 | 100_000_004;
|
||||
leaseObjectCategory: 100_000_000 | 100_000_001 | 100_000_002 | 100_000_003 | 100_000_004;
|
||||
engineType: 100_000_000 | 100_000_001 | 100_000_002 | 100_000_003 | 100_000_004 | null;
|
||||
leaseObjectCategory: 100_000_000 | 100_000_001 | 100_000_002 | 100_000_003 | 100_000_004 | null;
|
||||
leaseObjectMotorPower: number;
|
||||
engineVolume: number;
|
||||
leaseObjectUseFor:
|
||||
@ -98,32 +101,33 @@ interface Types {
|
||||
| 100_000_016
|
||||
| 100_000_017
|
||||
| 100_000_018
|
||||
| 100_000_019;
|
||||
dealer: string;
|
||||
dealerPerson: string;
|
||||
dealerRewardCondition: string;
|
||||
| 100_000_019
|
||||
| null;
|
||||
dealer: string | null;
|
||||
dealerPerson: string | null;
|
||||
dealerRewardCondition: string | null;
|
||||
dealerRewardSumm: number;
|
||||
dealerBroker: string;
|
||||
dealerBrokerRewardCondition: string;
|
||||
dealerBroker: string | null;
|
||||
dealerBrokerRewardCondition: string | null;
|
||||
dealerBrokerRewardSumm: number;
|
||||
indAgent: string;
|
||||
indAgentRewardCondition: string;
|
||||
indAgent: string | null;
|
||||
indAgentRewardCondition: string | null;
|
||||
indAgentRewardSumm: number;
|
||||
calcDoubleAgent: string;
|
||||
calcDoubleAgentRewardCondition: string;
|
||||
calcDoubleAgent: string | null;
|
||||
calcDoubleAgentRewardCondition: string | null;
|
||||
calcDoubleAgentRewardSumm: number;
|
||||
calcBroker: string;
|
||||
calcBrokerRewardCondition: string;
|
||||
calcBroker: string | null;
|
||||
calcBrokerRewardCondition: string | null;
|
||||
calcBrokerRewardSum: number;
|
||||
calcFinDepartment: string;
|
||||
finDepartmentRewardCondtion: string;
|
||||
calcFinDepartment: string | null;
|
||||
finDepartmentRewardCondtion: string | null;
|
||||
finDepartmentRewardSumm: number;
|
||||
GPSBrand: string;
|
||||
GPSModel: string;
|
||||
regionRegistration: string;
|
||||
townRegistration: string;
|
||||
infuranceOPF: 100_000_000 | 100_000_001;
|
||||
insKaskoType: 100_000_000 | 100_000_001;
|
||||
GPSBrand: string | null;
|
||||
GPSModel: string | null;
|
||||
regionRegistration: string | null;
|
||||
townRegistration: string | null;
|
||||
infuranceOPF: 100_000_000 | 100_000_001 | null;
|
||||
insKaskoType: 100_000_000 | 100_000_001 | null;
|
||||
insDecentral: boolean;
|
||||
insFranchise: number;
|
||||
insUnlimitDrivers: boolean;
|
||||
@ -138,13 +142,13 @@ interface Types {
|
||||
registrationQuote: boolean;
|
||||
technicalCardQuote: boolean;
|
||||
NSIB: boolean;
|
||||
quoteName: string;
|
||||
quoteContactGender: 100_000_000 | 100_000_001;
|
||||
quoteName: string | null;
|
||||
quoteContactGender: 100_000_000 | 100_000_001 | null;
|
||||
quoteRedemptionGraph: boolean;
|
||||
showFinGAP: boolean;
|
||||
tarif: string;
|
||||
tarif: string | null;
|
||||
creditRate: number;
|
||||
rate: string;
|
||||
rate: string | null;
|
||||
requirementTelematic:
|
||||
| 100_000_000
|
||||
| 100_000_001
|
||||
@ -153,22 +157,23 @@ interface Types {
|
||||
| 100_000_004
|
||||
| 100_000_005
|
||||
| 100_000_006
|
||||
| 100_000_007;
|
||||
| 100_000_007
|
||||
| null;
|
||||
minPriceChange: number;
|
||||
maxPriceChange: number;
|
||||
importerRewardPerc: number;
|
||||
importerRewardRub: number;
|
||||
disableChecks: boolean;
|
||||
registration: string;
|
||||
insNSIB: string;
|
||||
technicalCard: string;
|
||||
telematic: string;
|
||||
tracker: string;
|
||||
registration: string | null;
|
||||
insNSIB: string | null;
|
||||
technicalCard: string | null;
|
||||
telematic: string | null;
|
||||
tracker: string | null;
|
||||
mileage: number;
|
||||
calcType: 100_000_000 | 100_000_001;
|
||||
calcType: 100_000_000 | 100_000_001 | null;
|
||||
totalPayments: number;
|
||||
objectRegistration: 100_000_000 | 100_000_001;
|
||||
objectRegionRegistration: string;
|
||||
objectRegistration: 100_000_000 | 100_000_001 | null;
|
||||
objectRegionRegistration: string | null;
|
||||
vehicleTaxInYear: number;
|
||||
vehicleTaxInLeasingPeriod: number;
|
||||
objectCategoryTax:
|
||||
@ -192,14 +197,22 @@ interface Types {
|
||||
| 100_000_017
|
||||
| 100_000_018
|
||||
| 100_000_019
|
||||
| 100_000_020;
|
||||
objectTypeTax: 100_000_000 | 100_000_001 | 100_000_002 | 100_000_003 | 100_000_004 | 100_000_005;
|
||||
typePTS: 100_000_000 | 100_000_001;
|
||||
legalClientRegion: string;
|
||||
legalClientTown: string;
|
||||
subsidy: string;
|
||||
| 100_000_020
|
||||
| null;
|
||||
objectTypeTax:
|
||||
| 100_000_000
|
||||
| 100_000_001
|
||||
| 100_000_002
|
||||
| 100_000_003
|
||||
| 100_000_004
|
||||
| 100_000_005
|
||||
| null;
|
||||
typePTS: 100_000_000 | 100_000_001 | null;
|
||||
legalClientRegion: string | null;
|
||||
legalClientTown: string | null;
|
||||
subsidy: string | null;
|
||||
subsidySum: number;
|
||||
fuelCard: string;
|
||||
fuelCard: string | null;
|
||||
leaseObjectPriceWthtVAT: number;
|
||||
VATInLeaseObjectPrice: number;
|
||||
engineHours: number;
|
||||
@ -225,16 +238,10 @@ interface Types {
|
||||
resultFirstPaymentRiskPolicy: number;
|
||||
|
||||
/** Link Values */
|
||||
kpUrl: string;
|
||||
leadUrl: string;
|
||||
opportunityUrl: string;
|
||||
quoteUrl: string;
|
||||
}
|
||||
|
||||
export type ValuesTypes = {
|
||||
[Key in keyof Types]: Types[Key] | null;
|
||||
kpUrl: string | null;
|
||||
leadUrl: string | null;
|
||||
opportunityUrl: string | null;
|
||||
quoteUrl: string | null;
|
||||
};
|
||||
|
||||
export type CalculationValues = Partial<ValuesTypes>;
|
||||
|
||||
export type Values = keyof ValuesTypes;
|
||||
export type Values = keyof CalculationValues;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user