tbxFirstPaymentRub, tbxFirstPaymentPerc

This commit is contained in:
vchikalkin 2023-02-09 14:49:39 +03:00
parent b61bca1947
commit 13fc2b4c78
2 changed files with 33 additions and 3 deletions

View File

@ -40,7 +40,7 @@ const defaultValues: CalculationValues = {
engineVolume: 0,
finDepartmentRewardCondtion: null,
finDepartmentRewardSumm: 0,
firstPaymentPerc: 25,
firstPaymentPerc: 0,
firstPaymentRub: 0,
fuelCard: null,
fullPriceWithDiscount: false,
@ -113,7 +113,7 @@ const defaultValues: CalculationValues = {
quoteUrl: null,
rate: null,
recalcWithRevision: false,
redemptionPaymentSum: 1_000,
redemptionPaymentSum: 1000,
regionRegistration: null,
registration: null,
registrationDescription: '-',

View File

@ -3,9 +3,11 @@ import { VAT } from '@/constants/values';
import * as CRMTypes from '@/graphql/crm.types';
import type { ReactionsContext } from '@/process/types';
import { autorun, reaction } from 'mobx';
import { pick } from 'radash';
import { makeDisposable } from 'tools';
export default function commonReactions({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
const { $calculation, $process } = store;
reaction(
() => $calculation.element('radioLastPaymentRule').getValue(),
@ -88,4 +90,32 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
$calculation.element('tbxVATInLeaseObjectPrice').setValue(priceVAT);
}
});
reaction(
() =>
pick($calculation.$values.values, [
'firstPaymentPerc',
'addEquipmentPrice',
'importProgramSum',
'plPriceRub',
]),
({ firstPaymentPerc, addEquipmentPrice, importProgramSum, plPriceRub }) => {
const rub = (firstPaymentPerc * (plPriceRub + addEquipmentPrice - importProgramSum)) / 100;
$calculation.element('tbxFirstPaymentRub').setValue(rub);
}
);
makeDisposable(
() =>
reaction(
() => pick($calculation.$values.values, ['firstPaymentRub']),
({ firstPaymentRub }) => {
const { plPriceRub, addEquipmentPrice, importProgramSum } = $calculation.$values.values;
const perc =
(firstPaymentRub / (plPriceRub + addEquipmentPrice - importProgramSum)) * 100;
$calculation.element('tbxFirstPaymentPerc').setValue(perc);
}
),
() => $process.has('LoadKP')
);
}