fix NaN
This commit is contained in:
parent
4723c54a32
commit
360c20f402
@ -77,17 +77,20 @@ const elementsProps: TElements<ElementProps> = {
|
||||
min: '10000',
|
||||
max: '1000000000',
|
||||
step: '10000.00',
|
||||
precision: 2,
|
||||
},
|
||||
tbxSupplierDiscountRub: {
|
||||
// TODO formatter + rub, parser
|
||||
min: '0',
|
||||
max: '1000000000',
|
||||
step: '10000.00',
|
||||
precision: 2,
|
||||
},
|
||||
tbxSupplierDiscountPerc: {
|
||||
// TODO formatter + %, parser
|
||||
min: '0',
|
||||
max: '100',
|
||||
precision: 2,
|
||||
},
|
||||
radioBalanceHolder: {
|
||||
style: 'button',
|
||||
@ -101,11 +104,13 @@ const elementsProps: TElements<ElementProps> = {
|
||||
tbxFirstPaymentPerc: {
|
||||
min: '0',
|
||||
max: '50',
|
||||
precision: 2,
|
||||
},
|
||||
tbxFirstPaymentRub: {
|
||||
min: '0',
|
||||
max: '1000000000',
|
||||
step: '10000.00',
|
||||
precision: 2,
|
||||
},
|
||||
radioLastPaymentRule: {
|
||||
style: 'button',
|
||||
|
||||
@ -16,7 +16,9 @@ const InputNumber = ({
|
||||
{...props}
|
||||
disabled={status === ElementStatus.Disabled}
|
||||
style={styles}
|
||||
onChange={value => setCurrentValue(value)}
|
||||
onChange={value => {
|
||||
setCurrentValue(typeof value !== 'string' ? value : 0);
|
||||
}}
|
||||
value={value}
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
@ -15,7 +15,6 @@ export const calculatePerc = calculationStore => (
|
||||
supplierCurrencyId,
|
||||
leaseObjectPrice,
|
||||
rubSum,
|
||||
percFieldName,
|
||||
) => {
|
||||
const supplierCurrency = calculationStore
|
||||
.getOptions('selectSupplierCurrency')
|
||||
@ -30,15 +29,13 @@ export const calculatePerc = calculationStore => (
|
||||
parseFloat(leaseObjectPrice),
|
||||
evo_currencychangeValue,
|
||||
);
|
||||
let perc = (rubSum / price) * 100;
|
||||
calculationStore.setValue(percFieldName, perc);
|
||||
return (rubSum / price) * 100;
|
||||
};
|
||||
|
||||
export const calculateRub = calculationStore => (
|
||||
supplierCurrencyId,
|
||||
leaseObjectPrice,
|
||||
perc,
|
||||
rubFieldName,
|
||||
) => {
|
||||
const supplierCurrency = calculationStore
|
||||
.getOptions('selectSupplierCurrency')
|
||||
@ -53,6 +50,5 @@ export const calculateRub = calculationStore => (
|
||||
parseFloat(leaseObjectPrice),
|
||||
evo_currencychangeValue,
|
||||
);
|
||||
let rub = (perc * price) / 100;
|
||||
calculationStore.setValue(rubFieldName, rub);
|
||||
return (perc * price) / 100;
|
||||
};
|
||||
|
||||
@ -1184,14 +1184,10 @@ const reactionEffects: IReactionEffect[] = [
|
||||
const { leaseObjectPrice, supplierDiscountRub } = calculationStore.values;
|
||||
return [leaseObjectPrice, supplierDiscountRub];
|
||||
},
|
||||
effect: ([leaseObjectPrice, supplierDiscountRub]) => {
|
||||
if (supplierDiscountRub === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
effect: ([leaseObjectPrice, supplierDiscountRub = 0]) => {
|
||||
calculationStore.setValue(
|
||||
'supplierDiscountPerc',
|
||||
(supplierDiscountRub / leaseObjectPrice) * 100,
|
||||
leaseObjectPrice ? (supplierDiscountRub / leaseObjectPrice) * 100 : 0,
|
||||
);
|
||||
},
|
||||
options: {
|
||||
@ -1207,11 +1203,7 @@ const reactionEffects: IReactionEffect[] = [
|
||||
} = calculationStore.values;
|
||||
return [leaseObjectPrice, supplierDiscountPerc];
|
||||
},
|
||||
effect: ([leaseObjectPrice, supplierDiscountPerc]) => {
|
||||
if (supplierDiscountPerc === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
effect: ([leaseObjectPrice = 0, supplierDiscountPerc = 0]) => {
|
||||
calculationStore.setValue(
|
||||
'supplierDiscountRub',
|
||||
(supplierDiscountPerc * leaseObjectPrice) / 100,
|
||||
@ -1228,16 +1220,17 @@ const reactionEffects: IReactionEffect[] = [
|
||||
return firstPaymentRub;
|
||||
},
|
||||
effect: firstPaymentRub => {
|
||||
if (firstPaymentRub === undefined) {
|
||||
return;
|
||||
}
|
||||
const { supplierCurrency, leaseObjectPrice } = calculationStore.values;
|
||||
calculatePerc(calculationStore)(
|
||||
supplierCurrency,
|
||||
leaseObjectPrice,
|
||||
firstPaymentRub,
|
||||
'firstPaymentPerc',
|
||||
);
|
||||
if (leaseObjectPrice) {
|
||||
const perc = calculatePerc(calculationStore)(
|
||||
supplierCurrency,
|
||||
leaseObjectPrice,
|
||||
firstPaymentRub,
|
||||
);
|
||||
calculationStore.setValue('firstPaymentPerc', perc);
|
||||
} else {
|
||||
calculationStore.setValue('firstPaymentPerc', 0);
|
||||
}
|
||||
},
|
||||
options: {
|
||||
fireImmediately: true,
|
||||
@ -1253,16 +1246,21 @@ const reactionEffects: IReactionEffect[] = [
|
||||
} = calculationStore.values;
|
||||
return [supplierCurrency, leaseObjectPrice, firstPaymentPerc];
|
||||
},
|
||||
effect: ([supplierCurrencyId, leaseObjectPrice, firstPaymentPerc]) => {
|
||||
if (firstPaymentPerc === undefined) {
|
||||
effect: ([
|
||||
supplierCurrencyId,
|
||||
leaseObjectPrice = 0,
|
||||
firstPaymentPerc = 0,
|
||||
]) => {
|
||||
if (!firstPaymentPerc) {
|
||||
return;
|
||||
}
|
||||
calculateRub(calculationStore)(
|
||||
const rub = calculateRub(calculationStore)(
|
||||
supplierCurrencyId,
|
||||
leaseObjectPrice,
|
||||
firstPaymentPerc,
|
||||
'firstPaymentRub',
|
||||
);
|
||||
|
||||
calculationStore.setValue('firstPaymentRub', rub);
|
||||
},
|
||||
options: {
|
||||
fireImmediately: true,
|
||||
@ -1278,37 +1276,36 @@ const reactionEffects: IReactionEffect[] = [
|
||||
} = calculationStore.values;
|
||||
return [supplierCurrency, leaseObjectPrice, comissionPerc];
|
||||
},
|
||||
effect: ([supplierCurrencyId, leaseObjectPrice, comissionPerc]) => {
|
||||
if (comissionPerc === undefined) {
|
||||
return;
|
||||
}
|
||||
calculateRub(calculationStore)(
|
||||
effect: ([supplierCurrencyId, leaseObjectPrice = 0, comissionPerc = 0]) => {
|
||||
const rub = calculateRub(calculationStore)(
|
||||
supplierCurrencyId,
|
||||
leaseObjectPrice,
|
||||
comissionPerc,
|
||||
'comissionRub',
|
||||
);
|
||||
calculationStore.setValue('comissionRub', rub);
|
||||
},
|
||||
options: {
|
||||
fireImmediately: true,
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const { comissionRub } = calculationStore.values;
|
||||
return comissionRub;
|
||||
},
|
||||
effect: comissionRub => {
|
||||
if (comissionRub === undefined) {
|
||||
return;
|
||||
}
|
||||
const { supplierCurrency, leaseObjectPrice } = calculationStore.values;
|
||||
calculatePerc(calculationStore)(
|
||||
supplierCurrency,
|
||||
leaseObjectPrice,
|
||||
comissionRub,
|
||||
'comissionPerc',
|
||||
);
|
||||
if (leaseObjectPrice) {
|
||||
const perc = calculatePerc(calculationStore)(
|
||||
supplierCurrency,
|
||||
leaseObjectPrice,
|
||||
comissionRub,
|
||||
);
|
||||
calculationStore.setValue('comissionPerc', perc);
|
||||
} else {
|
||||
calculationStore.setValue('comissionPerc', 0);
|
||||
}
|
||||
},
|
||||
options: {
|
||||
fireImmediately: true,
|
||||
@ -1333,18 +1330,19 @@ const reactionEffects: IReactionEffect[] = [
|
||||
effect: ([
|
||||
supplierCurrencyId,
|
||||
leaseObjectPrice,
|
||||
lastPaymentPerc,
|
||||
lastPaymentPerc = 0,
|
||||
lastPaymentRule,
|
||||
]) => {
|
||||
if (lastPaymentPerc === undefined || lastPaymentRule !== 100000001) {
|
||||
if (lastPaymentRule !== 100000001) {
|
||||
return;
|
||||
}
|
||||
calculateRub(calculationStore)(
|
||||
|
||||
const rub = calculateRub(calculationStore)(
|
||||
supplierCurrencyId,
|
||||
leaseObjectPrice,
|
||||
lastPaymentPerc,
|
||||
'lastPaymentRub',
|
||||
);
|
||||
calculationStore.setValue('lastPaymentRub', rub);
|
||||
},
|
||||
options: {
|
||||
fireImmediately: true,
|
||||
@ -1368,24 +1366,78 @@ const reactionEffects: IReactionEffect[] = [
|
||||
effect: ([
|
||||
supplierCurrencyId,
|
||||
leaseObjectPrice,
|
||||
lastPaymentRub,
|
||||
lastPaymentRub = 0,
|
||||
lastPaymentRule,
|
||||
]) => {
|
||||
if (lastPaymentRub === undefined || lastPaymentRule !== 100000000) {
|
||||
if (lastPaymentRule !== 100000000) {
|
||||
return;
|
||||
}
|
||||
calculatePerc(calculationStore)(
|
||||
supplierCurrencyId,
|
||||
leaseObjectPrice,
|
||||
lastPaymentRub,
|
||||
'lastPaymentPerc',
|
||||
);
|
||||
if (leaseObjectPrice) {
|
||||
const perc = calculatePerc(calculationStore)(
|
||||
supplierCurrencyId,
|
||||
leaseObjectPrice,
|
||||
lastPaymentRub,
|
||||
);
|
||||
calculationStore.setValue('lastPaymentPerc', perc);
|
||||
} else {
|
||||
calculationStore.setValue('lastPaymentPerc', 0);
|
||||
}
|
||||
},
|
||||
options: {
|
||||
fireImmediately: true,
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const { supplierDiscountRub } = calculationStore.values;
|
||||
return supplierDiscountRub;
|
||||
},
|
||||
effect: supplierDiscountRub => {
|
||||
const { leaseObjectPrice } = calculationStore.values;
|
||||
if (
|
||||
leaseObjectPrice &&
|
||||
leaseObjectPrice > 0 &&
|
||||
supplierDiscountRub >= leaseObjectPrice
|
||||
) {
|
||||
calculationStore.setValidation('tbxSupplierDiscountRub', false);
|
||||
openNotification({
|
||||
type: 'error',
|
||||
title: 'Ошибка',
|
||||
description:
|
||||
'Скидка от поставщика не может быть больше или равна стоимости ПЛ.',
|
||||
})();
|
||||
} else {
|
||||
calculationStore.setValidation('tbxSupplierDiscountRub', undefined);
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const { firstPaymentRub } = calculationStore.values;
|
||||
return firstPaymentRub;
|
||||
},
|
||||
effect: firstPaymentRub => {
|
||||
const { leaseObjectPrice } = calculationStore.values;
|
||||
if (
|
||||
leaseObjectPrice &&
|
||||
leaseObjectPrice > 0 &&
|
||||
firstPaymentRub >= leaseObjectPrice
|
||||
) {
|
||||
calculationStore.setValidation('tbxFirstPaymentRub', false);
|
||||
openNotification({
|
||||
type: 'error',
|
||||
title: 'Ошибка',
|
||||
description:
|
||||
'Первый платеж не может быть больше или равен стоимости ПЛ.',
|
||||
})();
|
||||
} else {
|
||||
calculationStore.setValidation('tbxFirstPaymentRub', undefined);
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const {
|
||||
|
||||
Reference in New Issue
Block a user