loadKP: return correct plPriceRub, discountRub
This commit is contained in:
parent
2d658208f6
commit
5c72c272b8
@ -2,8 +2,10 @@ import type { GetQuoteInputData, GetQuoteProcessData } from '../load-kp/types';
|
||||
import initializeApollo from '@/apollo/client';
|
||||
import defaultValues from '@/config/default-values';
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
import { createCurrencyUtility } from '@/utils/currency';
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const QUERY_GET_QUOTE_PRICE_DATA = gql`
|
||||
query GetQuotePriceData($quoteId: Uuid!) {
|
||||
quote(quoteId: $quoteId) {
|
||||
@ -38,22 +40,45 @@ export async function getKPData({
|
||||
},
|
||||
});
|
||||
|
||||
const { RUB } = createCurrencyUtility({ apolloClient });
|
||||
|
||||
const supplierCurrency = quote?.evo_transactioncurrencyid;
|
||||
|
||||
const leaseObjectPrice = quote?.evo_supplier_currency_price ?? defaultValues.leaseObjectPrice;
|
||||
const plPriceRub = supplierCurrency
|
||||
? await RUB({
|
||||
currencyid: supplierCurrency,
|
||||
value: leaseObjectPrice,
|
||||
})
|
||||
: defaultValues.plPriceRub;
|
||||
|
||||
const supplierDiscountRub =
|
||||
quote?.evo_discount_supplier_currency ?? defaultValues.supplierDiscountRub;
|
||||
const discountRub = supplierCurrency
|
||||
? await RUB({
|
||||
currencyid: supplierCurrency,
|
||||
value: supplierDiscountRub,
|
||||
})
|
||||
: defaultValues.discountRub;
|
||||
|
||||
return {
|
||||
values: {
|
||||
VATInLeaseObjectPrice:
|
||||
quote?.evo_nds_in_price_supplier_currency ?? defaultValues.VATInLeaseObjectPrice,
|
||||
addEquipmentPrice: quote?.evo_equip_price ?? defaultValues.addEquipmentPrice,
|
||||
comissionPerc: quote?.evo_comission_perc ?? defaultValues.comissionPerc,
|
||||
// supplierDiscountRub,
|
||||
discountRub,
|
||||
// comissionRub: quote?.evo_comission_rub ,
|
||||
firstPaymentPerc: quote?.evo_first_payment_perc ?? defaultValues.firstPaymentPerc,
|
||||
// lastPaymentRub: quote?.evo_last_payment_rub ,
|
||||
lastPaymentPerc: quote?.evo_last_payment_perc ?? defaultValues.lastPaymentPerc,
|
||||
lastPaymentRule: quote?.evo_last_payment_calc,
|
||||
leaseObjectPrice: quote?.evo_supplier_currency_price ?? defaultValues.leaseObjectPrice,
|
||||
leaseObjectPrice,
|
||||
plPriceRub,
|
||||
// leaseObjectPriceWthtVAT: quote?.evo_price_without_nds_supplier_currency ,
|
||||
supplierCurrency: quote?.evo_transactioncurrencyid,
|
||||
supplierDiscountPerc: quote?.evo_discount_perc ?? defaultValues.supplierDiscountPerc,
|
||||
// supplierDiscountRub: quote?.evo_discount_supplier_currency ,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,55 +1,64 @@
|
||||
import type { ProcessContext } from '@/process/types';
|
||||
import { createCurrencyUtility } from '@/utils/currency';
|
||||
import { reaction } from 'mobx';
|
||||
import { makeDisposable } from 'tools';
|
||||
|
||||
export default function reactions({ store, apolloClient }: ProcessContext) {
|
||||
const { $calculation } = store;
|
||||
const { $calculation, $process } = store;
|
||||
|
||||
const { RUB } = createCurrencyUtility({ apolloClient });
|
||||
|
||||
reaction(
|
||||
() => $calculation.$values.getValues(['supplierCurrency', 'leaseObjectPrice']),
|
||||
async ({ supplierCurrency: supplierCurrencyId, leaseObjectPrice }) => {
|
||||
if (!supplierCurrencyId) {
|
||||
$calculation.$values.resetValue('plPriceRub');
|
||||
makeDisposable(
|
||||
() =>
|
||||
reaction(
|
||||
() => $calculation.$values.getValues(['supplierCurrency', 'leaseObjectPrice']),
|
||||
async ({ supplierCurrency: supplierCurrencyId, leaseObjectPrice }) => {
|
||||
if (!supplierCurrencyId) {
|
||||
$calculation.$values.resetValue('plPriceRub');
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$calculation.$values.setValue(
|
||||
'plPriceRub',
|
||||
await RUB({
|
||||
currencyid: supplierCurrencyId,
|
||||
value: leaseObjectPrice,
|
||||
})
|
||||
);
|
||||
},
|
||||
{
|
||||
delay: 100,
|
||||
fireImmediately: true,
|
||||
}
|
||||
$calculation.$values.setValue(
|
||||
'plPriceRub',
|
||||
await RUB({
|
||||
currencyid: supplierCurrencyId,
|
||||
value: leaseObjectPrice,
|
||||
})
|
||||
);
|
||||
},
|
||||
{
|
||||
delay: 100,
|
||||
fireImmediately: true,
|
||||
}
|
||||
),
|
||||
() => $process.has('LoadKP')
|
||||
);
|
||||
|
||||
reaction(
|
||||
() => $calculation.$values.getValues(['supplierCurrency', 'supplierDiscountRub']),
|
||||
async ({ supplierCurrency: supplierCurrencyId, supplierDiscountRub }) => {
|
||||
if (!supplierCurrencyId) {
|
||||
$calculation.$values.resetValue('discountRub');
|
||||
makeDisposable(
|
||||
() =>
|
||||
reaction(
|
||||
() => $calculation.$values.getValues(['supplierCurrency', 'supplierDiscountRub']),
|
||||
async ({ supplierCurrency: supplierCurrencyId, supplierDiscountRub }) => {
|
||||
if (!supplierCurrencyId) {
|
||||
$calculation.$values.resetValue('discountRub');
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$calculation.$values.setValue(
|
||||
'discountRub',
|
||||
await RUB({
|
||||
currencyid: supplierCurrencyId,
|
||||
value: supplierDiscountRub,
|
||||
})
|
||||
);
|
||||
},
|
||||
{
|
||||
delay: 100,
|
||||
fireImmediately: true,
|
||||
}
|
||||
$calculation.$values.setValue(
|
||||
'discountRub',
|
||||
await RUB({
|
||||
currencyid: supplierCurrencyId,
|
||||
value: supplierDiscountRub,
|
||||
})
|
||||
);
|
||||
},
|
||||
{
|
||||
delay: 100,
|
||||
fireImmediately: true,
|
||||
}
|
||||
),
|
||||
() => $process.has('LoadKP')
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user