diff --git a/apps/web/config/default-values.ts b/apps/web/config/default-values.ts index d29e818..e457cd3 100644 --- a/apps/web/config/default-values.ts +++ b/apps/web/config/default-values.ts @@ -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: '-', diff --git a/apps/web/process/price/reactions/common.ts b/apps/web/process/price/reactions/common.ts index 03f5f21..4a25ed7 100644 --- a/apps/web/process/price/reactions/common.ts +++ b/apps/web/process/price/reactions/common.ts @@ -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') + ); }