process/payments: add get-kp-data
This commit is contained in:
parent
b0e7624cd9
commit
878ec1d62a
@ -25,7 +25,14 @@ export const columns: ColumnsType<Payment> = [
|
|||||||
render: (_value, payment) => {
|
render: (_value, payment) => {
|
||||||
const Component = buildValueComponent(payment.num, InputNumber);
|
const Component = buildValueComponent(payment.num, InputNumber);
|
||||||
|
|
||||||
return <Component min={0.01} max={100} step={1} precision={2} />;
|
return (
|
||||||
|
<Component
|
||||||
|
min={payment.num === 0 ? 0 : 0.01}
|
||||||
|
max={100}
|
||||||
|
step={1}
|
||||||
|
precision={payment.num === 0 ? 4 : 2}
|
||||||
|
/>
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
7
config/schema/payments.ts
Normal file
7
config/schema/payments.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
const PaymentsSchema = z.object({
|
||||||
|
values: z.number().array(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default PaymentsSchema;
|
||||||
@ -599,7 +599,7 @@ type evo_baseproduct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type evo_graph {
|
type evo_graph {
|
||||||
createdon: DateTime
|
createdon: DateTime!
|
||||||
evo_addcontractid: Uuid
|
evo_addcontractid: Uuid
|
||||||
evo_contractid: Uuid
|
evo_contractid: Uuid
|
||||||
evo_cost_equipment_sum: Decimal
|
evo_cost_equipment_sum: Decimal
|
||||||
@ -611,7 +611,7 @@ type evo_graph {
|
|||||||
evo_graphid: Uuid
|
evo_graphid: Uuid
|
||||||
evo_name: String
|
evo_name: String
|
||||||
evo_nds: Decimal
|
evo_nds: Decimal
|
||||||
evo_planpayments: [evo_planpayment]
|
evo_planpayments: [evo_planpayment!]
|
||||||
evo_quoteid: Uuid
|
evo_quoteid: Uuid
|
||||||
evo_sumpay_withnds: Decimal
|
evo_sumpay_withnds: Decimal
|
||||||
evo_sumpay_withoutnds: Decimal
|
evo_sumpay_withoutnds: Decimal
|
||||||
@ -1123,7 +1123,7 @@ type quote {
|
|||||||
evo_gender: Int
|
evo_gender: Int
|
||||||
evo_gps_brandid: Uuid
|
evo_gps_brandid: Uuid
|
||||||
evo_gps_modelid: Uuid
|
evo_gps_modelid: Uuid
|
||||||
evo_graphs: [evo_graph]
|
evo_graphs: [evo_graph!]
|
||||||
evo_graph_irr: Decimal
|
evo_graph_irr: Decimal
|
||||||
evo_graph_type: Int
|
evo_graph_type: Int
|
||||||
evo_guarantor1_another_peyments: Decimal
|
evo_guarantor1_another_peyments: Decimal
|
||||||
|
|||||||
@ -129,21 +129,6 @@ export type GetFinGapAddProductTypesQueryVariables = Exact<{
|
|||||||
|
|
||||||
export type GetFinGapAddProductTypesQuery = { __typename?: 'Query', evo_addproduct_types: Array<{ __typename?: 'evo_addproduct_type', evo_addproduct_typeid: string | null, evo_name: string | null, evo_type_calc_cerebellum: number | null, evo_cost_service_provider_withoutnds: number | null, evo_addproduct_types: Array<{ __typename?: 'evo_addproduct_type', evo_addproduct_typeid: string | null } | null> | null } | null> | null };
|
export type GetFinGapAddProductTypesQuery = { __typename?: 'Query', evo_addproduct_types: Array<{ __typename?: 'evo_addproduct_type', evo_addproduct_typeid: string | null, evo_name: string | null, evo_type_calc_cerebellum: number | null, evo_cost_service_provider_withoutnds: number | null, evo_addproduct_types: Array<{ __typename?: 'evo_addproduct_type', evo_addproduct_typeid: string | null } | null> | null } | null> | null };
|
||||||
|
|
||||||
export type GetAddproductTypesQueryVariables = Exact<{ [key: string]: never; }>;
|
|
||||||
|
|
||||||
|
|
||||||
export type GetAddproductTypesQuery = { __typename?: 'Query', evo_addproduct_types: Array<{ __typename?: 'evo_addproduct_type', evo_graph_price: number | null, evo_product_type: number | null, label: string | null, value: string | null } | null> | null };
|
|
||||||
|
|
||||||
export type GetBrandsQueryVariables = Exact<{ [key: string]: never; }>;
|
|
||||||
|
|
||||||
|
|
||||||
export type GetBrandsQuery = { __typename?: 'Query', selectBrand: Array<{ __typename?: 'evo_brand', label: string | null, value: string | null } | null> | null };
|
|
||||||
|
|
||||||
export type GetDealersQueryVariables = Exact<{ [key: string]: never; }>;
|
|
||||||
|
|
||||||
|
|
||||||
export type GetDealersQuery = { __typename?: 'Query', selectDealer: Array<{ __typename?: 'account', label: string | null, value: string | null } | null> | null };
|
|
||||||
|
|
||||||
export type GetInsuranceDataQueryVariables = Exact<{
|
export type GetInsuranceDataQueryVariables = Exact<{
|
||||||
evo_account_type: InputMaybe<Array<Scalars['Int']> | Scalars['Int']>;
|
evo_account_type: InputMaybe<Array<Scalars['Int']> | Scalars['Int']>;
|
||||||
}>;
|
}>;
|
||||||
@ -170,6 +155,21 @@ export type GetRegionsQueryVariables = Exact<{ [key: string]: never; }>;
|
|||||||
|
|
||||||
export type GetRegionsQuery = { __typename?: 'Query', evo_regions: Array<{ __typename?: 'evo_region', label: string | null, value: string | null } | null> | null };
|
export type GetRegionsQuery = { __typename?: 'Query', evo_regions: Array<{ __typename?: 'evo_region', label: string | null, value: string | null } | null> | null };
|
||||||
|
|
||||||
|
export type GetBrandsQueryVariables = Exact<{ [key: string]: never; }>;
|
||||||
|
|
||||||
|
|
||||||
|
export type GetBrandsQuery = { __typename?: 'Query', selectBrand: Array<{ __typename?: 'evo_brand', label: string | null, value: string | null } | null> | null };
|
||||||
|
|
||||||
|
export type GetDealersQueryVariables = Exact<{ [key: string]: never; }>;
|
||||||
|
|
||||||
|
|
||||||
|
export type GetDealersQuery = { __typename?: 'Query', selectDealer: Array<{ __typename?: 'account', label: string | null, value: string | null } | null> | null };
|
||||||
|
|
||||||
|
export type GetAddproductTypesQueryVariables = Exact<{ [key: string]: never; }>;
|
||||||
|
|
||||||
|
|
||||||
|
export type GetAddproductTypesQuery = { __typename?: 'Query', evo_addproduct_types: Array<{ __typename?: 'evo_addproduct_type', evo_graph_price: number | null, evo_product_type: number | null, label: string | null, value: string | null } | null> | null };
|
||||||
|
|
||||||
export type GetOwnerDataQueryVariables = Exact<{
|
export type GetOwnerDataQueryVariables = Exact<{
|
||||||
domainname: InputMaybe<Scalars['String']>;
|
domainname: InputMaybe<Scalars['String']>;
|
||||||
}>;
|
}>;
|
||||||
@ -224,6 +224,13 @@ export type GetQuoteUrlQueryVariables = Exact<{
|
|||||||
|
|
||||||
export type GetQuoteUrlQuery = { __typename?: 'Query', entity: { __typename?: 'quote', link: string | null } | null };
|
export type GetQuoteUrlQuery = { __typename?: 'Query', entity: { __typename?: 'quote', link: string | null } | null };
|
||||||
|
|
||||||
|
export type GetPaymentsDataFromQuoteQueryVariables = Exact<{
|
||||||
|
quoteId: Scalars['Uuid'];
|
||||||
|
}>;
|
||||||
|
|
||||||
|
|
||||||
|
export type GetPaymentsDataFromQuoteQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_period: number | null, evo_accept_period: number | null, evo_first_payment_perc: number | null, evo_last_payment_perc: number | null, evo_graph_type: number | null, evo_payments_decrease_perc: number | null, evo_seasons_type: number | null, evo_high_season: number | null, evo_graphs: Array<{ __typename?: 'evo_graph', createdon: string, evo_sumpay_withnds: number | null, evo_planpayments: Array<{ __typename?: 'evo_planpayment', evo_payment_ratio: number | null }> | null }> | null } | null };
|
||||||
|
|
||||||
export type GetCurrencyChangesQueryVariables = Exact<{
|
export type GetCurrencyChangesQueryVariables = Exact<{
|
||||||
currentDate: InputMaybe<Scalars['DateTime']>;
|
currentDate: InputMaybe<Scalars['DateTime']>;
|
||||||
}>;
|
}>;
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import { pick } from 'radash';
|
|||||||
const key = 'KP_LOADING_INFO';
|
const key = 'KP_LOADING_INFO';
|
||||||
|
|
||||||
export default function loadKpReactions({ store, trpcClient }: ReactionsContext) {
|
export default function loadKpReactions({ store, trpcClient }: ReactionsContext) {
|
||||||
const { $calculation, $process } = store;
|
const { $calculation, $process, $tables } = store;
|
||||||
|
|
||||||
reaction(
|
reaction(
|
||||||
() => $calculation.element('selectQuote').getValue(),
|
() => $calculation.element('selectQuote').getValue(),
|
||||||
@ -29,13 +29,16 @@ export default function loadKpReactions({ store, trpcClient }: ReactionsContext)
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
trpcClient.quote.getValues
|
trpcClient.quote.getData
|
||||||
.query(payload)
|
.query(payload)
|
||||||
.then(({ values }) => {
|
.then(({ values, payments }) => {
|
||||||
$calculation.$values.setValues({
|
$calculation.$values.setValues({
|
||||||
values,
|
values,
|
||||||
exclude: ['lead', 'opportunity', 'quote', 'leadUrl', 'opportunityUrl', 'quoteUrl'],
|
exclude: ['lead', 'opportunity', 'quote', 'leadUrl', 'opportunityUrl', 'quoteUrl'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$tables.payments.setValues(payments.values);
|
||||||
|
|
||||||
message.success({
|
message.success({
|
||||||
key,
|
key,
|
||||||
content: `КП ${quoteName} загружено`,
|
content: `КП ${quoteName} загружено`,
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import PaymentsSchema from 'config/schema/payments';
|
||||||
import ValuesSchema from 'config/schema/values';
|
import ValuesSchema from 'config/schema/values';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
@ -12,10 +13,12 @@ export type GetQuoteDataInput = z.infer<typeof GetQuoteDataInputSchema>;
|
|||||||
|
|
||||||
export const GetQuoteDataOutputSchema = z.object({
|
export const GetQuoteDataOutputSchema = z.object({
|
||||||
values: ValuesSchema,
|
values: ValuesSchema,
|
||||||
|
payments: PaymentsSchema,
|
||||||
});
|
});
|
||||||
export type GetQuoteDataOutput = z.infer<typeof GetQuoteDataOutputSchema>;
|
export type GetQuoteDataOutput = z.infer<typeof GetQuoteDataOutputSchema>;
|
||||||
|
|
||||||
export const GetQuoteDataPartOutputSchema = z.object({
|
export const QuoteProcessDataSchema = z.object({
|
||||||
values: ValuesSchema.partial(),
|
values: ValuesSchema.partial(),
|
||||||
|
payments: PaymentsSchema.optional(),
|
||||||
});
|
});
|
||||||
export type GetQuoteDataPartOutput = z.infer<typeof GetQuoteDataPartOutputSchema>;
|
export type QuoteProcessData = z.infer<typeof QuoteProcessDataSchema>;
|
||||||
|
|||||||
75
process/payments/get-kp-data.ts
Normal file
75
process/payments/get-kp-data.ts
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
|
import { gql } from '@apollo/client';
|
||||||
|
import initializeApollo from 'apollo/client';
|
||||||
|
import type * as CRMTypes from 'graphql/crm.types';
|
||||||
|
import { sort } from 'radash';
|
||||||
|
import type { GetQuoteDataInput, QuoteProcessData } from '../load-kp/types';
|
||||||
|
|
||||||
|
const QUERY_GET_PAYMENTS_DATA_FROM_QUOTE = gql`
|
||||||
|
query GetPaymentsDataFromQuote($quoteId: Uuid!) {
|
||||||
|
quote(quoteId: $quoteId) {
|
||||||
|
evo_period
|
||||||
|
evo_accept_period
|
||||||
|
evo_first_payment_perc
|
||||||
|
evo_last_payment_perc
|
||||||
|
evo_graph_type
|
||||||
|
evo_payments_decrease_perc
|
||||||
|
evo_seasons_type
|
||||||
|
evo_high_season
|
||||||
|
evo_graphs {
|
||||||
|
createdon
|
||||||
|
evo_sumpay_withnds
|
||||||
|
evo_planpayments {
|
||||||
|
evo_payment_ratio
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default async function getPaymentsDataFromKP({
|
||||||
|
values: { quote: quoteId, recalcWithRevision },
|
||||||
|
}: GetQuoteDataInput): Promise<QuoteProcessData> {
|
||||||
|
const apolloClient = initializeApollo();
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: { quote },
|
||||||
|
} = await apolloClient.query<
|
||||||
|
CRMTypes.GetPaymentsDataFromQuoteQuery,
|
||||||
|
CRMTypes.GetPaymentsDataFromQuoteQueryVariables
|
||||||
|
>({
|
||||||
|
query: QUERY_GET_PAYMENTS_DATA_FROM_QUOTE,
|
||||||
|
variables: {
|
||||||
|
quoteId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const leasingPeriod = recalcWithRevision
|
||||||
|
? Math.min(quote?.evo_period ?? 0, quote?.evo_accept_period ?? 0)
|
||||||
|
: quote?.evo_period ?? 0;
|
||||||
|
|
||||||
|
let payments: Array<number> = [];
|
||||||
|
if (quote?.evo_graphs) {
|
||||||
|
payments =
|
||||||
|
sort(quote?.evo_graphs, (evo_graph) => Date.parse(evo_graph?.createdon))
|
||||||
|
.at(0)
|
||||||
|
?.evo_planpayments?.slice(1, -1)
|
||||||
|
.slice(0, leasingPeriod - 2)
|
||||||
|
.map((payment) => payment?.evo_payment_ratio || 0) || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
values: {
|
||||||
|
leasingPeriod,
|
||||||
|
graphType: quote?.evo_graph_type ?? undefined,
|
||||||
|
parmentsDecreasePercent: quote?.evo_payments_decrease_perc || 0,
|
||||||
|
highSeasonStart: quote?.evo_high_season,
|
||||||
|
seasonType: quote?.evo_seasons_type,
|
||||||
|
firstPaymentPerc: quote?.evo_first_payment_perc || 0,
|
||||||
|
lastPaymentPerc: quote?.evo_last_payment_perc || 0,
|
||||||
|
},
|
||||||
|
payments: {
|
||||||
|
values: [quote?.evo_first_payment_perc || 0, ...payments, quote?.evo_last_payment_perc || 0],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -34,169 +34,175 @@ export default function paymentsReactions({ store }: ReactionsContext) {
|
|||||||
/**
|
/**
|
||||||
* Аннуитет
|
* Аннуитет
|
||||||
*/
|
*/
|
||||||
makeDisposable(
|
reaction(
|
||||||
() =>
|
() => {
|
||||||
reaction(
|
const graphType = $calculation.element('radioGraphType').getValue();
|
||||||
() => {
|
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
|
||||||
const graphType = $calculation.element('radioGraphType').getValue();
|
|
||||||
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
graphType,
|
graphType,
|
||||||
leasingPeriod,
|
leasingPeriod,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
({ graphType, leasingPeriod }) => {
|
({ graphType, leasingPeriod }) => {
|
||||||
if (graphType === 100_000_000) {
|
if (graphType === 100_000_000) {
|
||||||
const middlePayments: Row[] = Array.from(
|
const middlePayments: Row[] = Array.from(
|
||||||
{
|
{
|
||||||
length: leasingPeriod - 2,
|
length: leasingPeriod - 2,
|
||||||
},
|
},
|
||||||
() => ({
|
() => ({
|
||||||
value: 100,
|
value: 100,
|
||||||
status: 'Disabled',
|
status: 'Disabled',
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue();
|
const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue();
|
||||||
const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue();
|
const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue();
|
||||||
|
|
||||||
$tables.payments.setRows([
|
const rows: Row[] = [
|
||||||
{
|
{
|
||||||
value: firstPaymentPerc,
|
value: firstPaymentPerc,
|
||||||
status: 'Disabled',
|
status: 'Disabled',
|
||||||
},
|
},
|
||||||
...middlePayments,
|
...middlePayments,
|
||||||
{
|
{
|
||||||
value: lastPaymentPerc,
|
value: lastPaymentPerc,
|
||||||
status: 'Disabled',
|
status: 'Disabled',
|
||||||
},
|
},
|
||||||
]);
|
];
|
||||||
}
|
|
||||||
},
|
if (!$process.has('LoadKP')) {
|
||||||
{
|
$tables.payments.setValues(rows.map((row) => row.value));
|
||||||
fireImmediately: true,
|
|
||||||
}
|
}
|
||||||
),
|
|
||||||
() => $process.has('LoadKP')
|
$tables.payments.setStatuses(rows.map((row) => row.status));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fireImmediately: true,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Равноубывающий
|
* Равноубывающий
|
||||||
*/
|
*/
|
||||||
makeDisposable(
|
|
||||||
() =>
|
|
||||||
reaction(
|
|
||||||
() => {
|
|
||||||
const graphType = $calculation.element('radioGraphType').getValue();
|
|
||||||
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
|
|
||||||
const parmentsDecreasePercent = $calculation
|
|
||||||
.element('tbxParmentsDecreasePercent')
|
|
||||||
.getValue();
|
|
||||||
|
|
||||||
return {
|
reaction(
|
||||||
graphType,
|
() => {
|
||||||
leasingPeriod,
|
const graphType = $calculation.element('radioGraphType').getValue();
|
||||||
parmentsDecreasePercent,
|
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
|
||||||
};
|
const parmentsDecreasePercent = $calculation.element('tbxParmentsDecreasePercent').getValue();
|
||||||
},
|
|
||||||
({ graphType, leasingPeriod, parmentsDecreasePercent }) => {
|
|
||||||
if (graphType === 100_000_002) {
|
|
||||||
const middlePayments: Row[] = Array.from(
|
|
||||||
{
|
|
||||||
length: leasingPeriod - 2,
|
|
||||||
},
|
|
||||||
(_, k) => {
|
|
||||||
const payment = 100 * (parmentsDecreasePercent / 100) ** k;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
value: Number(payment.toFixed(2)),
|
graphType,
|
||||||
status: 'Disabled',
|
leasingPeriod,
|
||||||
};
|
parmentsDecreasePercent,
|
||||||
}
|
};
|
||||||
);
|
},
|
||||||
|
({ graphType, leasingPeriod, parmentsDecreasePercent }) => {
|
||||||
|
if (graphType === 100_000_002) {
|
||||||
|
const middlePayments: Row[] = Array.from(
|
||||||
|
{
|
||||||
|
length: leasingPeriod - 2,
|
||||||
|
},
|
||||||
|
(_, k) => {
|
||||||
|
const payment = 100 * (parmentsDecreasePercent / 100) ** k;
|
||||||
|
|
||||||
const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue();
|
return {
|
||||||
const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue();
|
value: Number(payment.toFixed(2)),
|
||||||
|
status: 'Disabled',
|
||||||
$tables.payments.setRows([
|
};
|
||||||
{
|
|
||||||
value: firstPaymentPerc,
|
|
||||||
status: 'Disabled',
|
|
||||||
},
|
|
||||||
...middlePayments,
|
|
||||||
{
|
|
||||||
value: lastPaymentPerc,
|
|
||||||
status: 'Disabled',
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue();
|
||||||
|
const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue();
|
||||||
|
|
||||||
|
const rows: Row[] = [
|
||||||
|
{
|
||||||
|
value: firstPaymentPerc,
|
||||||
|
status: 'Disabled',
|
||||||
|
},
|
||||||
|
...middlePayments,
|
||||||
|
{
|
||||||
|
value: lastPaymentPerc,
|
||||||
|
status: 'Disabled',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$process.has('LoadKP')) {
|
||||||
|
$tables.payments.setValues(rows.map((row) => row.value));
|
||||||
}
|
}
|
||||||
),
|
|
||||||
() => $process.has('LoadKP')
|
$tables.payments.setStatuses(rows.map((row) => row.status));
|
||||||
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Легкий старт
|
* Легкий старт
|
||||||
*/
|
*/
|
||||||
makeDisposable(
|
|
||||||
() =>
|
|
||||||
reaction(
|
|
||||||
() => {
|
|
||||||
const graphType = $calculation.element('radioGraphType').getValue();
|
|
||||||
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
|
|
||||||
|
|
||||||
return {
|
reaction(
|
||||||
graphType,
|
() => {
|
||||||
leasingPeriod,
|
const graphType = $calculation.element('radioGraphType').getValue();
|
||||||
};
|
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
|
||||||
},
|
|
||||||
({ graphType, leasingPeriod }) => {
|
|
||||||
if (graphType === 100_000_004) {
|
|
||||||
const editablePayments: Row[] = [
|
|
||||||
{
|
|
||||||
value: 25,
|
|
||||||
status: 'Default',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 50,
|
|
||||||
status: 'Default',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 75,
|
|
||||||
status: 'Default',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const payments: Row[] = Array.from(
|
return {
|
||||||
{
|
graphType,
|
||||||
length: leasingPeriod - 5,
|
leasingPeriod,
|
||||||
},
|
};
|
||||||
() => ({
|
},
|
||||||
value: 100,
|
({ graphType, leasingPeriod }) => {
|
||||||
status: 'Disabled',
|
if (graphType === 100_000_004) {
|
||||||
})
|
const editablePayments: Row[] = [
|
||||||
);
|
{
|
||||||
|
value: 25,
|
||||||
|
status: 'Default',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 50,
|
||||||
|
status: 'Default',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 75,
|
||||||
|
status: 'Default',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue();
|
const payments: Row[] = Array.from(
|
||||||
const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue();
|
{
|
||||||
|
length: leasingPeriod - 5,
|
||||||
|
},
|
||||||
|
() => ({
|
||||||
|
value: 100,
|
||||||
|
status: 'Disabled',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
$tables.payments.setRows([
|
const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue();
|
||||||
{
|
const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue();
|
||||||
value: firstPaymentPerc,
|
|
||||||
status: 'Disabled',
|
const rows: Row[] = [
|
||||||
},
|
{
|
||||||
...editablePayments,
|
value: firstPaymentPerc,
|
||||||
...payments,
|
status: 'Disabled',
|
||||||
{
|
},
|
||||||
value: lastPaymentPerc,
|
...editablePayments,
|
||||||
status: 'Disabled',
|
...payments,
|
||||||
},
|
{
|
||||||
]);
|
value: lastPaymentPerc,
|
||||||
}
|
status: 'Disabled',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$process.has('LoadKP')) {
|
||||||
|
$tables.payments.setValues(rows.map((row) => row.value));
|
||||||
}
|
}
|
||||||
),
|
|
||||||
() => $process.has('LoadKP')
|
$tables.payments.setStatuses(rows.map((row) => row.status));
|
||||||
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -237,99 +243,101 @@ export default function paymentsReactions({ store }: ReactionsContext) {
|
|||||||
100_000_006: [100, 7, 3],
|
100_000_006: [100, 7, 3],
|
||||||
};
|
};
|
||||||
|
|
||||||
makeDisposable(
|
reaction(
|
||||||
() =>
|
() => {
|
||||||
reaction(
|
const degressionType = $calculation.element('selectSeasonType').getValue();
|
||||||
() => {
|
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
|
||||||
const degressionType = $calculation.element('selectSeasonType').getValue();
|
const graphType = $calculation.element('radioGraphType').getValue();
|
||||||
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
|
|
||||||
const graphType = $calculation.element('radioGraphType').getValue();
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
degressionType,
|
degressionType,
|
||||||
leasingPeriod,
|
leasingPeriod,
|
||||||
graphType,
|
graphType,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
({ degressionType, leasingPeriod, graphType }) => {
|
({ degressionType, leasingPeriod, graphType }) => {
|
||||||
if (graphType === 100_000_001) {
|
if (graphType === 100_000_001) {
|
||||||
let payments: Row[] = [];
|
let middlePayments: Row[] = [];
|
||||||
|
|
||||||
switch (degressionType) {
|
switch (degressionType) {
|
||||||
case 100_000_007: {
|
case 100_000_007: {
|
||||||
const editablePayments: Row[] = Array.from(
|
const editablePayments: Row[] = Array.from(
|
||||||
{
|
|
||||||
length: leasingPeriod - 3,
|
|
||||||
},
|
|
||||||
() => ({
|
|
||||||
value: 100,
|
|
||||||
status: 'Default',
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
payments = [
|
|
||||||
{
|
|
||||||
value: 100,
|
|
||||||
status: 'Disabled',
|
|
||||||
},
|
|
||||||
...editablePayments,
|
|
||||||
];
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 100_000_003:
|
|
||||||
case 100_000_004:
|
|
||||||
case 100_000_005:
|
|
||||||
case 100_000_006: {
|
|
||||||
const [step1, step2, step3] = degressionSteps[degressionType];
|
|
||||||
const paymentsInStep = Math.ceil((leasingPeriod - 2) / 3);
|
|
||||||
|
|
||||||
payments = Array.from(
|
|
||||||
{
|
|
||||||
length: leasingPeriod - 2,
|
|
||||||
},
|
|
||||||
(_v, i) => {
|
|
||||||
let value = step3;
|
|
||||||
|
|
||||||
if (i <= paymentsInStep * 2 - 1) {
|
|
||||||
value = step2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i <= paymentsInStep - 1) {
|
|
||||||
value = step1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
value,
|
|
||||||
status: 'Disabled',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue();
|
|
||||||
const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue();
|
|
||||||
|
|
||||||
$tables.payments.setRows([
|
|
||||||
{
|
{
|
||||||
value: firstPaymentPerc,
|
length: leasingPeriod - 3,
|
||||||
|
},
|
||||||
|
() => ({
|
||||||
|
value: 100,
|
||||||
|
status: 'Default',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
middlePayments = [
|
||||||
|
{
|
||||||
|
value: 100,
|
||||||
status: 'Disabled',
|
status: 'Disabled',
|
||||||
},
|
},
|
||||||
...payments,
|
...editablePayments,
|
||||||
|
];
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 100_000_003:
|
||||||
|
case 100_000_004:
|
||||||
|
case 100_000_005:
|
||||||
|
case 100_000_006: {
|
||||||
|
const [step1, step2, step3] = degressionSteps[degressionType];
|
||||||
|
const paymentsInStep = Math.ceil((leasingPeriod - 2) / 3);
|
||||||
|
|
||||||
|
middlePayments = Array.from(
|
||||||
{
|
{
|
||||||
value: lastPaymentPerc,
|
length: leasingPeriod - 2,
|
||||||
status: 'Disabled',
|
|
||||||
},
|
},
|
||||||
]);
|
(_v, i) => {
|
||||||
|
let value = step3;
|
||||||
|
|
||||||
|
if (i <= paymentsInStep * 2 - 1) {
|
||||||
|
value = step2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i <= paymentsInStep - 1) {
|
||||||
|
value = step1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
value,
|
||||||
|
status: 'Disabled',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
),
|
|
||||||
() => $process.has('LoadKP')
|
const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue();
|
||||||
|
const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue();
|
||||||
|
|
||||||
|
const rows: Row[] = [
|
||||||
|
{
|
||||||
|
value: firstPaymentPerc,
|
||||||
|
status: 'Disabled',
|
||||||
|
},
|
||||||
|
...middlePayments,
|
||||||
|
{
|
||||||
|
value: lastPaymentPerc,
|
||||||
|
status: 'Disabled',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$process.has('LoadKP')) {
|
||||||
|
$tables.payments.setValues(rows.map((row) => row.value));
|
||||||
|
}
|
||||||
|
|
||||||
|
$tables.payments.setStatuses(rows.map((row) => row.status));
|
||||||
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
makeDisposable(
|
makeDisposable(
|
||||||
@ -436,57 +444,59 @@ export default function paymentsReactions({ store }: ReactionsContext) {
|
|||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
makeDisposable(
|
reaction(
|
||||||
() =>
|
() => {
|
||||||
reaction(
|
const seasonType = $calculation.element('selectSeasonType').getValue();
|
||||||
() => {
|
const highSeasonStartOption = $calculation.element('selectHighSeasonStart').getOption();
|
||||||
const seasonType = $calculation.element('selectSeasonType').getValue();
|
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
|
||||||
const highSeasonStartOption = $calculation.element('selectHighSeasonStart').getOption();
|
|
||||||
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
seasonType,
|
seasonType,
|
||||||
highSeasonStartOption,
|
highSeasonStartOption,
|
||||||
leasingPeriod,
|
leasingPeriod,
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
({ seasonType, highSeasonStartOption, leasingPeriod }) => {
|
||||||
|
const graphType = $calculation.element('radioGraphType').getValue();
|
||||||
|
if (graphType !== 100_000_003) return;
|
||||||
|
|
||||||
|
if (!seasonType || !highSeasonStartOption) {
|
||||||
|
$tables.payments.setValues([]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const seasons = seasonsTools.generateSeasons(
|
||||||
|
seasonType,
|
||||||
|
seasonsConstants.DEFAULT_SEASONS_VALUES
|
||||||
|
);
|
||||||
|
const shiftNumber = Number.parseInt(highSeasonStartOption.label, 10) - 2;
|
||||||
|
const payments = seasonsTools.generateSeasonsPayments(
|
||||||
|
leasingPeriod,
|
||||||
|
shift(seasons, shiftNumber)
|
||||||
|
);
|
||||||
|
const middlePayments: Row[] = generateSeasonPaymentsRows(seasonType, shiftNumber, payments);
|
||||||
|
const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue();
|
||||||
|
const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue();
|
||||||
|
|
||||||
|
const rows: Row[] = [
|
||||||
|
{
|
||||||
|
value: firstPaymentPerc,
|
||||||
|
status: 'Disabled',
|
||||||
},
|
},
|
||||||
({ seasonType, highSeasonStartOption, leasingPeriod }) => {
|
...middlePayments,
|
||||||
const graphType = $calculation.element('radioGraphType').getValue();
|
{
|
||||||
if (graphType !== 100_000_003) return;
|
value: lastPaymentPerc,
|
||||||
|
status: 'Disabled',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
if (!seasonType || !highSeasonStartOption) {
|
if (!$process.has('LoadKP')) {
|
||||||
$tables.payments.setValues([]);
|
$tables.payments.setValues(rows.map((row) => row.value));
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
$tables.payments.setStatuses(rows.map((row) => row.status));
|
||||||
}
|
}
|
||||||
|
|
||||||
const seasons = seasonsTools.generateSeasons(
|
|
||||||
seasonType,
|
|
||||||
seasonsConstants.DEFAULT_SEASONS_VALUES
|
|
||||||
);
|
|
||||||
const shiftNumber = Number.parseInt(highSeasonStartOption.label, 10) - 2;
|
|
||||||
const payments = seasonsTools.generateSeasonsPayments(
|
|
||||||
leasingPeriod,
|
|
||||||
shift(seasons, shiftNumber)
|
|
||||||
);
|
|
||||||
const rows: Row[] = generateSeasonPaymentsRows(seasonType, shiftNumber, payments);
|
|
||||||
const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue();
|
|
||||||
const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue();
|
|
||||||
|
|
||||||
$tables.payments.setRows([
|
|
||||||
{
|
|
||||||
value: firstPaymentPerc,
|
|
||||||
status: 'Disabled',
|
|
||||||
},
|
|
||||||
...rows,
|
|
||||||
{
|
|
||||||
value: lastPaymentPerc,
|
|
||||||
status: 'Disabled',
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
() => $process.has('LoadKP')
|
|
||||||
);
|
);
|
||||||
|
|
||||||
makeDisposable(
|
makeDisposable(
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { gql } from '@apollo/client';
|
import { gql } from '@apollo/client';
|
||||||
import initializeApollo from 'apollo/client';
|
import initializeApollo from 'apollo/client';
|
||||||
import type * as CRMTypes from 'graphql/crm.types';
|
import type * as CRMTypes from 'graphql/crm.types';
|
||||||
import type { GetQuoteDataInput, GetQuoteDataPartOutput } from '../../load-kp/types';
|
import type { GetQuoteDataInput, QuoteProcessData } from '../../load-kp/types';
|
||||||
import getSums from './get-sums';
|
import getSums from './get-sums';
|
||||||
|
|
||||||
const QUERY_GET_AGENTS_DATA_FROM_QUOTE = gql`
|
const QUERY_GET_AGENTS_DATA_FROM_QUOTE = gql`
|
||||||
@ -40,7 +40,7 @@ export type Quote = NonNullable<CRMTypes.GetAgentsDataFromQuoteQuery['quote']>;
|
|||||||
|
|
||||||
export default async function getSupplierAgentsDataFromKP({
|
export default async function getSupplierAgentsDataFromKP({
|
||||||
values: { quote: quoteId },
|
values: { quote: quoteId },
|
||||||
}: GetQuoteDataInput): Promise<GetQuoteDataPartOutput> {
|
}: GetQuoteDataInput): Promise<QuoteProcessData> {
|
||||||
const apolloClient = initializeApollo();
|
const apolloClient = initializeApollo();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
|||||||
@ -1,20 +1,29 @@
|
|||||||
import defaultValues from 'config/default-values';
|
import defaultValues from 'config/default-values';
|
||||||
import { GetQuoteDataInputSchema, GetQuoteDataOutputSchema } from 'process/load-kp/types';
|
import { GetQuoteDataInputSchema, GetQuoteDataOutputSchema } from 'process/load-kp/types';
|
||||||
|
import getPaymentsDataFromKP from 'process/payments/get-kp-data';
|
||||||
import getSupplierAgentsDataFromKP from 'process/supplier-agent/get-kp-values';
|
import getSupplierAgentsDataFromKP from 'process/supplier-agent/get-kp-values';
|
||||||
import { t } from '../server';
|
import { t } from '../server';
|
||||||
|
|
||||||
const quoteRouter = t.router({
|
const quoteRouter = t.router({
|
||||||
getValues: t.procedure
|
getData: t.procedure
|
||||||
.input(GetQuoteDataInputSchema)
|
.input(GetQuoteDataInputSchema)
|
||||||
.output(GetQuoteDataOutputSchema)
|
.output(GetQuoteDataOutputSchema)
|
||||||
.query(async ({ input }) => {
|
.query(async ({ input }) => {
|
||||||
const { values: supplierAgentsValues } = await getSupplierAgentsDataFromKP(input);
|
const { values: supplierAgentsValues } = await getSupplierAgentsDataFromKP(input);
|
||||||
|
const {
|
||||||
|
values: paymentsValues,
|
||||||
|
payments = {
|
||||||
|
values: [],
|
||||||
|
},
|
||||||
|
} = await getPaymentsDataFromKP(input);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
values: {
|
values: {
|
||||||
...defaultValues,
|
...defaultValues,
|
||||||
...supplierAgentsValues,
|
...supplierAgentsValues,
|
||||||
|
...paymentsValues,
|
||||||
},
|
},
|
||||||
|
payments,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user