This repository has been archived on 2025-05-09. You can view files and clone it, but cannot push or open issues or pull requests.

98 lines
2.8 KiB
TypeScript

import { pipe } from 'core/tools/func';
import { ICalculationStore } from 'core/types/Calculation/Store';
import { Process } from 'core/types/Calculation/Store/process';
import { reaction } from 'mobx';
export default function ($calculation: ICalculationStore) {
reaction(
() => {
return {
product: $calculation.getOption('selectProduct'),
...$calculation.getValues([
'leasingPeriod',
'deliveryTime',
'firstPaymentPerc',
'lastPaymentPerc',
'leaseObjectUsed',
'leaseObjectType',
]),
};
},
({
product,
leasingPeriod,
deliveryTime,
firstPaymentPerc,
lastPaymentPerc,
leaseObjectUsed,
leaseObjectType,
}) => {
if (product && leasingPeriod && deliveryTime) {
const target_tarif = $calculation.options.selectTarif?.find(
pipe(
tarif =>
tarif.evo_baseproductid === product.evo_baseproductid &&
tarif.evo_min_period <= leasingPeriod &&
tarif.evo_max_period >= leasingPeriod &&
tarif.evo_delivery_time?.includes(deliveryTime) &&
tarif.evo_min_first_payment <= firstPaymentPerc &&
tarif.evo_max_first_payment >= firstPaymentPerc &&
tarif.evo_min_last_payment <= lastPaymentPerc &&
tarif.evo_max_last_payment >= lastPaymentPerc &&
tarif,
tarif => {
if (
!tarif?.evo_leasingobject_types?.length ||
(leaseObjectType &&
tarif.evo_leasingobject_types
.map(x => x.evo_leasingobject_typeid)
.includes(leaseObjectType))
) {
return tarif;
}
},
tarif => {
if (leaseObjectUsed === true) {
if (
!tarif?.evo_pl_use_type?.length ||
tarif.evo_pl_use_type.includes(100_000_001)
) {
return tarif;
}
} else {
if (
!tarif?.evo_pl_use_type?.length ||
tarif.evo_pl_use_type.includes(100_000_000)
) {
return tarif;
}
}
},
),
);
$calculation.setValue('tarif', target_tarif?.evo_tarifid);
} else {
$calculation.setValue('tarif', null);
}
},
);
reaction(
() => $calculation.values.tarif,
tarifid => {
const { calculationProcess } = $calculation.stores;
if (calculationProcess.hasProcess(Process.LoadKp)) {
return;
}
const tarif = $calculation.getOption('selectTarif', {
evo_tarifid: tarifid,
});
$calculation.setValue('IRR_Perc', tarif?.evo_irr);
},
);
}