stores/values: add getValues method
This commit is contained in:
parent
c035abb955
commit
cb42779c46
@ -6,7 +6,6 @@ import * as CRMTypes from '@/graphql/crm.types';
|
||||
import dayjs from 'dayjs';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
import { reaction } from 'mobx';
|
||||
import { pick } from 'radash';
|
||||
|
||||
dayjs.extend(utc);
|
||||
|
||||
@ -67,7 +66,7 @@ export default function commonReactions(context: ReactionsContext) {
|
||||
* данная запись должна быть связана с Продуктом product из поля Продукт selectProduct
|
||||
*/
|
||||
reaction(
|
||||
() => pick($calculation.$values.values, ['product', 'saleBonus']),
|
||||
() => $calculation.$values.getValues(['product', 'saleBonus']),
|
||||
async ({ product: productId, saleBonus }) => {
|
||||
if (!productId) {
|
||||
$calculation.element('tbxBonusCoefficient').resetValue();
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import helper from './lib/helper';
|
||||
import type { ReactionsContext } from '@/process/types';
|
||||
import { reaction } from 'mobx';
|
||||
import { pick } from 'radash';
|
||||
import { round } from 'tools';
|
||||
|
||||
export default function reactions(context: ReactionsContext) {
|
||||
@ -10,7 +9,7 @@ export default function reactions(context: ReactionsContext) {
|
||||
const { getCoefficient } = helper(context);
|
||||
|
||||
reaction(
|
||||
() => pick($calculation.$values.values, ['product', 'saleBonus']),
|
||||
() => $calculation.$values.getValues(['product', 'saleBonus']),
|
||||
async ({ product: productId, saleBonus }) => {
|
||||
const coefficient = await getCoefficient(productId);
|
||||
const maxBonus = (coefficient?.evo_sot_coefficient || 0) * 100;
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
import type { ReactionsContext } from '@/process/types';
|
||||
import { reaction } from 'mobx';
|
||||
import { pick } from 'radash';
|
||||
import { formatter } from 'tools';
|
||||
|
||||
export default function commonReactions({ store, apolloClient }: ReactionsContext) {
|
||||
@ -31,7 +30,7 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
|
||||
);
|
||||
|
||||
reaction(
|
||||
() => pick($calculation.$values.values, ['product', 'tarif', 'bonusCoefficient']),
|
||||
() => $calculation.$values.getValues(['product', 'tarif', 'bonusCoefficient']),
|
||||
async ({ product: productId, tarif: tarifId, bonusCoefficient }) => {
|
||||
let max = 0;
|
||||
let min = 0;
|
||||
|
||||
@ -15,18 +15,14 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
|
||||
const { $calculation } = store;
|
||||
|
||||
reaction(
|
||||
() => {
|
||||
const { product, subsidy, importProgram, dealer } = $calculation.$values.values;
|
||||
|
||||
return {
|
||||
dealerId: dealer,
|
||||
importProgramId: importProgram,
|
||||
productId: product,
|
||||
subsidyId: subsidy,
|
||||
};
|
||||
},
|
||||
// eslint-disable-next-line sonarjs/cognitive-complexity
|
||||
async ({ productId, subsidyId, importProgramId, dealerId }) => {
|
||||
() => $calculation.$values.getValues(['dealer', 'importProgram', 'product', 'subsidy']),
|
||||
async ({
|
||||
product: productId,
|
||||
subsidy: subsidyId,
|
||||
importProgram: importProgramId,
|
||||
dealer: dealerId,
|
||||
// eslint-disable-next-line sonarjs/cognitive-complexity
|
||||
}) => {
|
||||
/**
|
||||
* #1
|
||||
* DYN-190 При выборе значения в поле selectSubsidy необходимо добавить
|
||||
|
||||
@ -3,7 +3,7 @@ import * as CRMTypes from '@/graphql/crm.types';
|
||||
import type { ReactionsContext } from '@/process/types';
|
||||
import dayjs from 'dayjs';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
import { autorun, reaction } from 'mobx';
|
||||
import { reaction } from 'mobx';
|
||||
import { makeDisposable, normalizeOptions } from 'tools';
|
||||
|
||||
dayjs.extend(utc);
|
||||
@ -11,17 +11,24 @@ dayjs.extend(utc);
|
||||
export default function valuesReactions({ store, apolloClient }: ReactionsContext) {
|
||||
const { $calculation, $process } = store;
|
||||
|
||||
autorun(
|
||||
async () => {
|
||||
const {
|
||||
product,
|
||||
leasingPeriod,
|
||||
leaseObjectUsed,
|
||||
deliveryTime,
|
||||
firstPaymentPerc,
|
||||
lastPaymentPerc,
|
||||
} = $calculation.$values.values;
|
||||
|
||||
reaction(
|
||||
() =>
|
||||
$calculation.$values.getValues([
|
||||
'product',
|
||||
'leasingPeriod',
|
||||
'leaseObjectUsed',
|
||||
'deliveryTime',
|
||||
'firstPaymentPerc',
|
||||
'lastPaymentPerc',
|
||||
]),
|
||||
async ({
|
||||
product,
|
||||
leasingPeriod,
|
||||
leaseObjectUsed,
|
||||
deliveryTime,
|
||||
firstPaymentPerc,
|
||||
lastPaymentPerc,
|
||||
}) => {
|
||||
const currentDate = dayjs().utc(false).toISOString();
|
||||
|
||||
let {
|
||||
@ -74,6 +81,7 @@ export default function valuesReactions({ store, apolloClient }: ReactionsContex
|
||||
},
|
||||
{
|
||||
delay: 10,
|
||||
fireImmediately: true,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@ -9,18 +9,14 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
|
||||
const { $calculation } = store;
|
||||
|
||||
reaction(
|
||||
() => {
|
||||
const { brand, subsidy, importProgram, leaseObjectType } = $calculation.$values.values;
|
||||
|
||||
return {
|
||||
brandId: brand,
|
||||
importProgramId: importProgram,
|
||||
leaseObjectTypeId: leaseObjectType,
|
||||
subsidyId: subsidy,
|
||||
};
|
||||
},
|
||||
// eslint-disable-next-line sonarjs/cognitive-complexity
|
||||
async ({ brandId, subsidyId, importProgramId, leaseObjectTypeId }) => {
|
||||
() => $calculation.$values.getValues(['brand', 'importProgram', 'leaseObjectType', 'subsidy']),
|
||||
async ({
|
||||
brand: brandId,
|
||||
importProgram: importProgramId,
|
||||
leaseObjectType: leaseObjectTypeId,
|
||||
subsidy: subsidyId,
|
||||
// eslint-disable-next-line sonarjs/cognitive-complexity
|
||||
}) => {
|
||||
if (!brandId) {
|
||||
$calculation.element('selectModel').reset();
|
||||
|
||||
@ -122,18 +118,14 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
|
||||
);
|
||||
|
||||
reaction(
|
||||
() => {
|
||||
const { product, subsidy, importProgram, leaseObjectType } = $calculation.$values.values;
|
||||
|
||||
return {
|
||||
importProgramId: importProgram,
|
||||
leaseObjectTypeId: leaseObjectType,
|
||||
productId: product,
|
||||
subsidyId: subsidy,
|
||||
};
|
||||
},
|
||||
// eslint-disable-next-line sonarjs/cognitive-complexity
|
||||
async ({ productId, subsidyId, importProgramId, leaseObjectTypeId }) => {
|
||||
() =>
|
||||
$calculation.$values.getValues(['importProgram', 'leaseObjectType', 'product', 'subsidy']),
|
||||
async ({
|
||||
importProgram: importProgramId,
|
||||
leaseObjectType: leaseObjectTypeId,
|
||||
product: productId,
|
||||
subsidy: subsidyId,
|
||||
}) => {
|
||||
const {
|
||||
data: { evo_brands },
|
||||
} = await apolloClient.query({
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
import type { ReactionsContext } from '@/process/types';
|
||||
import { autorun, reaction } from 'mobx';
|
||||
import { pick } from 'radash';
|
||||
|
||||
export default function validationReactions({ store, apolloClient }: ReactionsContext) {
|
||||
const { $calculation } = store;
|
||||
@ -26,7 +25,7 @@ export default function validationReactions({ store, apolloClient }: ReactionsCo
|
||||
|
||||
reaction(
|
||||
() =>
|
||||
pick($calculation.$values.values, [
|
||||
$calculation.$values.getValues([
|
||||
'leaseObjectType',
|
||||
'engineVolume',
|
||||
'engineType',
|
||||
|
||||
@ -6,7 +6,7 @@ import { gql } from '@apollo/client';
|
||||
import dayjs from 'dayjs';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
import { reaction } from 'mobx';
|
||||
import { pick, uid } from 'radash';
|
||||
import { uid } from 'radash';
|
||||
import { normalizeOptions } from 'tools';
|
||||
import notification from 'ui/elements/notification';
|
||||
|
||||
@ -74,10 +74,8 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
|
||||
);
|
||||
|
||||
reaction(
|
||||
() => {
|
||||
const { values } = $calculation.$values;
|
||||
|
||||
return pick(values, [
|
||||
() =>
|
||||
$calculation.$values.getValues([
|
||||
'plPriceRub',
|
||||
'discountRub',
|
||||
'importProgramSum',
|
||||
@ -86,8 +84,7 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
|
||||
'leaseObjectType',
|
||||
'firstPaymentPerc',
|
||||
'model',
|
||||
]);
|
||||
},
|
||||
]),
|
||||
async ({
|
||||
plPriceRub,
|
||||
discountRub,
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import type { ReactionsContext } from '@/process/types';
|
||||
import extend from '@/stores/tables/insurance/tools';
|
||||
import { reaction } from 'mobx';
|
||||
import { pick } from 'radash';
|
||||
import message from 'ui/elements/message';
|
||||
|
||||
const key = 'KP_LOADING_INFO';
|
||||
@ -23,7 +22,7 @@ export default function loadKpReactions({ store, trpcClient }: ReactionsContext)
|
||||
key,
|
||||
});
|
||||
|
||||
const { recalcWithRevision } = $calculation.$values.values;
|
||||
const recalcWithRevision = $calculation.element('cbxRecalcWithRevision').getValue();
|
||||
|
||||
trpcClient.quote.getData
|
||||
.query({
|
||||
@ -33,7 +32,7 @@ export default function loadKpReactions({ store, trpcClient }: ReactionsContext)
|
||||
},
|
||||
})
|
||||
.then(({ values, payments, insurance, fingap }) => {
|
||||
const savedValues = pick($calculation.$values.values, [
|
||||
const savedValues = $calculation.$values.getValues([
|
||||
'lead',
|
||||
'opportunity',
|
||||
'quote',
|
||||
|
||||
@ -2,8 +2,7 @@
|
||||
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 { reaction } from 'mobx';
|
||||
import { makeDisposable } from 'tools';
|
||||
|
||||
export default function commonReactions({ store, apolloClient }: ReactionsContext) {
|
||||
@ -39,30 +38,37 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
|
||||
*/
|
||||
makeDisposable(
|
||||
() =>
|
||||
autorun(() => {
|
||||
const { leaseObjectPrice, supplierDiscountRub } = $calculation.$values.values;
|
||||
|
||||
$calculation
|
||||
.element('tbxSupplierDiscountPerc')
|
||||
.setValue((supplierDiscountRub / leaseObjectPrice) * 100);
|
||||
}),
|
||||
reaction(
|
||||
() => $calculation.$values.getValues(['leaseObjectPrice', 'supplierDiscountRub']),
|
||||
({ leaseObjectPrice, supplierDiscountRub }) => {
|
||||
$calculation
|
||||
.element('tbxSupplierDiscountPerc')
|
||||
.setValue((supplierDiscountRub / leaseObjectPrice) * 100);
|
||||
},
|
||||
{
|
||||
fireImmediately: true,
|
||||
}
|
||||
),
|
||||
() => $process.has('LoadKP')
|
||||
);
|
||||
|
||||
/**
|
||||
* Расчет суммы скидки поставщика в валюте
|
||||
*/
|
||||
autorun(() => {
|
||||
const { leaseObjectPrice, supplierDiscountPerc } = $calculation.$values.values;
|
||||
|
||||
$calculation
|
||||
.element('tbxSupplierDiscountRub')
|
||||
.setValue((supplierDiscountPerc * leaseObjectPrice) / 100);
|
||||
});
|
||||
reaction(
|
||||
() => $calculation.$values.getValues(['leaseObjectPrice', 'supplierDiscountPerc']),
|
||||
({ leaseObjectPrice, supplierDiscountPerc }) => {
|
||||
$calculation
|
||||
.element('tbxSupplierDiscountRub')
|
||||
.setValue((supplierDiscountPerc * leaseObjectPrice) / 100);
|
||||
},
|
||||
{
|
||||
fireImmediately: true,
|
||||
}
|
||||
);
|
||||
|
||||
reaction(
|
||||
() =>
|
||||
pick($calculation.$values.values, ['product', 'leaseObjectPrice', 'VATInLeaseObjectPrice']),
|
||||
() => $calculation.$values.getValues(['product', 'leaseObjectPrice', 'VATInLeaseObjectPrice']),
|
||||
async ({ product: productId, leaseObjectPrice, VATInLeaseObjectPrice }) => {
|
||||
let evo_sale_without_nds = false;
|
||||
|
||||
@ -95,7 +101,7 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
|
||||
|
||||
reaction(
|
||||
() =>
|
||||
pick($calculation.$values.values, [
|
||||
$calculation.$values.getValues([
|
||||
'firstPaymentPerc',
|
||||
'addEquipmentPrice',
|
||||
'importProgramSum',
|
||||
@ -122,7 +128,7 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
|
||||
);
|
||||
|
||||
reaction(
|
||||
() => pick($calculation.$values.values, ['comissionPerc', 'plPriceRub']),
|
||||
() => $calculation.$values.getValues(['comissionPerc', 'plPriceRub']),
|
||||
({ plPriceRub, comissionPerc }) => {
|
||||
const rub = (comissionPerc * plPriceRub) / 100;
|
||||
$calculation.element('tbxComissionRub').setValue(rub);
|
||||
@ -146,7 +152,7 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
|
||||
() =>
|
||||
reaction(
|
||||
() =>
|
||||
pick($calculation.$values.values, [
|
||||
$calculation.$values.getValues([
|
||||
'plPriceRub',
|
||||
'lastPaymentPerc',
|
||||
'addEquipmentPrice',
|
||||
|
||||
@ -3,7 +3,6 @@ import { VAT } from '@/constants/values';
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
import type { ReactionsContext } from '@/process/types';
|
||||
import { reaction } from 'mobx';
|
||||
import { pick } from 'radash';
|
||||
import { round } from 'tools';
|
||||
|
||||
export default function validationReactions({ store, apolloClient }: ReactionsContext) {
|
||||
@ -11,7 +10,7 @@ export default function validationReactions({ store, apolloClient }: ReactionsCo
|
||||
|
||||
reaction(
|
||||
() =>
|
||||
pick($calculation.$values.values, [
|
||||
$calculation.$values.getValues([
|
||||
'VATInLeaseObjectPrice',
|
||||
'leaseObjectPriceWthtVAT',
|
||||
'product',
|
||||
@ -43,7 +42,7 @@ export default function validationReactions({ store, apolloClient }: ReactionsCo
|
||||
);
|
||||
|
||||
reaction(
|
||||
() => pick($calculation.$values.values, ['supplierDiscountRub', 'plPriceRub']),
|
||||
() => $calculation.$values.getValues(['supplierDiscountRub', 'plPriceRub']),
|
||||
({ supplierDiscountRub, plPriceRub }) => {
|
||||
$calculation.element('tbxSupplierDiscountRub').validate({
|
||||
invalid: supplierDiscountRub >= plPriceRub,
|
||||
@ -53,7 +52,7 @@ export default function validationReactions({ store, apolloClient }: ReactionsCo
|
||||
);
|
||||
|
||||
reaction(
|
||||
() => pick($calculation.$values.values, ['firstPaymentRub', 'plPriceRub']),
|
||||
() => $calculation.$values.getValues(['firstPaymentRub', 'plPriceRub']),
|
||||
({ firstPaymentRub, plPriceRub }) => {
|
||||
$calculation.element('tbxFirstPaymentRub').validate({
|
||||
invalid: firstPaymentRub >= plPriceRub,
|
||||
@ -63,7 +62,7 @@ export default function validationReactions({ store, apolloClient }: ReactionsCo
|
||||
);
|
||||
|
||||
reaction(
|
||||
() => pick($calculation.$values.values, ['firstPaymentRub', 'subsidySum']),
|
||||
() => $calculation.$values.getValues(['firstPaymentRub', 'subsidySum']),
|
||||
({ firstPaymentRub, subsidySum }) => {
|
||||
$calculation.element('tbxFirstPaymentRub').validate({
|
||||
invalid: firstPaymentRub - subsidySum < 0,
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
import type { ReactionsContext } from '@/process/types';
|
||||
import { autorun, reaction } from 'mobx';
|
||||
import { pick } from 'radash';
|
||||
import { reaction } from 'mobx';
|
||||
|
||||
/**
|
||||
* При изменении "Программа от производителя" selectImportProgram , Стоимости ПЛ tbxLeaseObjectPrice, Валюты selectSupplierCurrency, Скидка от поставщика, в валюте поставщика (tbxSupplierDiscountRub)
|
||||
@ -24,7 +23,7 @@ export function computedReactions({ store, apolloClient }: ReactionsContext) {
|
||||
const { $calculation } = store;
|
||||
|
||||
reaction(
|
||||
() => pick($calculation.$values.values, ['importProgram', 'plPriceRub', 'supplierDiscountRub']),
|
||||
() => $calculation.$values.getValues(['importProgram', 'plPriceRub', 'supplierDiscountRub']),
|
||||
async ({ importProgram: importProgramId, plPriceRub, supplierDiscountRub }) => {
|
||||
if (importProgramId) {
|
||||
const {
|
||||
@ -52,44 +51,52 @@ export function computedReactions({ store, apolloClient }: ReactionsContext) {
|
||||
}
|
||||
);
|
||||
|
||||
autorun(async () => {
|
||||
const {
|
||||
reaction(
|
||||
() =>
|
||||
$calculation.$values.getValues([
|
||||
'subsidy',
|
||||
'plPriceRub',
|
||||
'discountRub',
|
||||
'addEquipmentPrice',
|
||||
'importProgramSum',
|
||||
]),
|
||||
async ({
|
||||
subsidy: subsidyId,
|
||||
plPriceRub,
|
||||
discountRub,
|
||||
addEquipmentPrice,
|
||||
importProgramSum,
|
||||
} = $calculation.$values.values;
|
||||
}) => {
|
||||
if (!subsidyId) {
|
||||
$calculation.element('tbxSubsidySum').resetValue();
|
||||
|
||||
if (!subsidyId) {
|
||||
$calculation.element('tbxSubsidySum').resetValue();
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
const {
|
||||
data: { evo_subsidy: subsidy },
|
||||
} = await apolloClient.query({
|
||||
query: CRMTypes.GetSubsidyDocument,
|
||||
variables: {
|
||||
subsidyId,
|
||||
},
|
||||
});
|
||||
|
||||
if (subsidy?.evo_subsidy_summ) {
|
||||
$calculation.element('tbxSubsidySum').setValue(subsidy?.evo_subsidy_summ);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const price = plPriceRub - discountRub - importProgramSum + addEquipmentPrice;
|
||||
|
||||
let sum = (price * (subsidy?.evo_percent_subsidy ?? 0)) / 100;
|
||||
const maxSum = subsidy?.evo_max_subsidy_summ ?? 0;
|
||||
if (sum > maxSum) sum = maxSum;
|
||||
|
||||
$calculation.element('tbxSubsidySum').setValue(sum);
|
||||
}
|
||||
|
||||
const {
|
||||
data: { evo_subsidy: subsidy },
|
||||
} = await apolloClient.query({
|
||||
query: CRMTypes.GetSubsidyDocument,
|
||||
variables: {
|
||||
subsidyId,
|
||||
},
|
||||
});
|
||||
|
||||
if (subsidy?.evo_subsidy_summ) {
|
||||
$calculation.element('tbxSubsidySum').setValue(subsidy?.evo_subsidy_summ);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const price = plPriceRub - discountRub - importProgramSum + addEquipmentPrice;
|
||||
|
||||
let sum = (price * (subsidy?.evo_percent_subsidy ?? 0)) / 100;
|
||||
const maxSum = subsidy?.evo_max_subsidy_summ ?? 0;
|
||||
if (sum > maxSum) sum = maxSum;
|
||||
|
||||
$calculation.element('tbxSubsidySum').setValue(sum);
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
|
||||
@ -2,6 +2,7 @@ import type RootStore from '../../root';
|
||||
import type { CalculationValues, Values } from './types';
|
||||
import defaultValues from '@/config/default-values';
|
||||
import { makeAutoObservable } from 'mobx';
|
||||
import { pick } from 'radash';
|
||||
|
||||
export default class ValuesStore {
|
||||
private root: RootStore;
|
||||
@ -16,6 +17,8 @@ export default class ValuesStore {
|
||||
this.values = initialValues;
|
||||
};
|
||||
|
||||
public getValues = <K extends keyof CalculationValues>(keys: K[]) => pick(this.values, keys);
|
||||
|
||||
public setValues = (params: { values: CalculationValues }) => {
|
||||
const { values } = params;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user