diff --git a/apps/web/process/price/reactions/common.ts b/apps/web/process/price/reactions/common.ts index 1683a1f..771dc21 100644 --- a/apps/web/process/price/reactions/common.ts +++ b/apps/web/process/price/reactions/common.ts @@ -169,28 +169,40 @@ export default function reactions({ store, apolloClient }: ProcessContext) { 'lastPaymentPerc', 'addEquipmentPrice', 'importProgramSum', + 'lastPaymentRule', ]), - ({ addEquipmentPrice, lastPaymentPerc, plPriceRub, importProgramSum }) => { + ({ addEquipmentPrice, lastPaymentPerc, plPriceRub, importProgramSum, lastPaymentRule }) => { + if (lastPaymentRule === 100_000_000) { + return; + } + const rub = (lastPaymentPerc * (plPriceRub + addEquipmentPrice - importProgramSum)) / 100; $calculation.element('tbxLastPaymentRub').setValue(rub); } ), - () => $calculation.element('radioLastPaymentRule').getValue() === 100_000_000 + () => $process.has('LoadKP') ); makeDisposable( () => reaction( - () => $calculation.element('tbxLastPaymentRub').getValue(), - (lastPaymentRub) => { - const { plPriceRub, addEquipmentPrice, importProgramSum } = - $calculation.$values.getValues(); + () => + $calculation.$values.getValues([ + 'plPriceRub', + 'lastPaymentRub', + 'addEquipmentPrice', + 'importProgramSum', + 'lastPaymentRule', + ]), + ({ lastPaymentRub, plPriceRub, addEquipmentPrice, importProgramSum, lastPaymentRule }) => { + if (lastPaymentRule === 100_000_001) { + return; + } + const perc = (lastPaymentRub / (plPriceRub + addEquipmentPrice - importProgramSum)) * 100; $calculation.element('tbxLastPaymentPerc').setValue(perc); } ), - () => - $process.has('LoadKP') || - $calculation.element('radioLastPaymentRule').getValue() === 100_000_001 + () => $process.has('LoadKP') ); }