process/fingap: load data from kp
This commit is contained in:
parent
878ec1d62a
commit
102d3446e6
@ -1,10 +1,4 @@
|
||||
export type Risk = {
|
||||
key: string;
|
||||
riskId: string;
|
||||
riskName: string;
|
||||
calcType: number;
|
||||
premiumPerc: number;
|
||||
sum: number;
|
||||
premium: number;
|
||||
keys?: string[];
|
||||
};
|
||||
import type { RiskSchema } from 'config/schema/fingap';
|
||||
import type { z } from 'zod';
|
||||
|
||||
export type Risk = z.infer<typeof RiskSchema>;
|
||||
|
||||
@ -1,15 +1,10 @@
|
||||
import type { KeysSchema, RowSchema } from 'config/schema/insurance';
|
||||
import type { BaseOption, Status } from 'Elements/types';
|
||||
import type { z } from 'zod';
|
||||
|
||||
export type Keys = 'osago' | 'kasko' | 'fingap';
|
||||
export type Keys = z.infer<typeof KeysSchema>;
|
||||
|
||||
export type RowValues = {
|
||||
key: Keys;
|
||||
policyType: string;
|
||||
insuranceCompany: string | null;
|
||||
insured: 100_000_000 | 100_000_001 | null;
|
||||
insCost: number;
|
||||
insTerm: 100_000_000 | 100_000_001 | null;
|
||||
};
|
||||
export type RowValues = z.infer<typeof RowSchema>;
|
||||
|
||||
export type Values = Exclude<keyof RowValues, 'key'>;
|
||||
|
||||
|
||||
13
config/schema/fingap.ts
Normal file
13
config/schema/fingap.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import { z } from 'zod';
|
||||
|
||||
export const RiskSchema = z.object({
|
||||
key: z.string(),
|
||||
riskId: z.string(),
|
||||
riskName: z.string(),
|
||||
calcType: z.number(),
|
||||
premiumPerc: z.number(),
|
||||
sum: z.number(),
|
||||
premium: z.number(),
|
||||
keys: z.array(z.string()).optional(),
|
||||
});
|
||||
12
config/schema/insurance.ts
Normal file
12
config/schema/insurance.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const KeysSchema = z.union([z.literal('osago'), z.literal('kasko'), z.literal('fingap')]);
|
||||
|
||||
export const RowSchema = z.object({
|
||||
key: KeysSchema,
|
||||
policyType: z.string(),
|
||||
insuranceCompany: z.string().nullable(),
|
||||
insured: z.number().nullable(),
|
||||
insCost: z.number(),
|
||||
insTerm: z.number().nullable(),
|
||||
});
|
||||
@ -1222,7 +1222,7 @@ type quote {
|
||||
evo_price_without_nds_supplier_currency: Decimal
|
||||
evo_price_with_discount: Boolean
|
||||
evo_price_wthout_discount_nds_sup_currency: Decimal
|
||||
evo_product_risks: [evo_product_risk]
|
||||
evo_product_risks: [evo_product_risk!]
|
||||
evo_programsolution: Int
|
||||
evo_program_import_subsidyid: Uuid
|
||||
evo_program_import_subsidy_sum: Decimal
|
||||
|
||||
@ -122,6 +122,13 @@ export type GetCurrencySymbolQueryVariables = Exact<{
|
||||
|
||||
export type GetCurrencySymbolQuery = { __typename?: 'Query', transactioncurrency: { __typename?: 'transactioncurrency', currencysymbol: string | null } | null };
|
||||
|
||||
export type GetRisksDataFromQuoteQueryVariables = Exact<{
|
||||
quoteId: Scalars['Uuid'];
|
||||
}>;
|
||||
|
||||
|
||||
export type GetRisksDataFromQuoteQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_fingap_accountid: string | null, evo_fingap_payer: number | null, evo_fingap_period: number | null, evo_product_risks: Array<{ __typename?: 'evo_product_risk', evo_addproduct_typeid: string | null }> | null } | null };
|
||||
|
||||
export type GetFinGapAddProductTypesQueryVariables = Exact<{
|
||||
currentDate: InputMaybe<Scalars['DateTime']>;
|
||||
}>;
|
||||
|
||||
77
process/fingap/get-kp-data.ts
Normal file
77
process/fingap/get-kp-data.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import { gql } from '@apollo/client';
|
||||
import initializeApollo from 'apollo/client';
|
||||
import { RowSchema } from 'config/schema/insurance';
|
||||
import { defaultValues } from 'config/tables/insurance-table';
|
||||
import type * as CRMTypes from 'graphql/crm.types';
|
||||
import { z } from 'zod';
|
||||
import type { GetQuoteDataInput } from '../load-kp/types';
|
||||
import { GetQuoteDataOutputSchema } from '../load-kp/types';
|
||||
|
||||
const DEFAULT_FINGAP_ROW = defaultValues.find((x) => x.key === 'fingap')!;
|
||||
|
||||
const QUERY_GET_RISKS = gql`
|
||||
query GetRisksDataFromQuote($quoteId: Uuid!) {
|
||||
quote(quoteId: $quoteId) {
|
||||
evo_fingap_accountid
|
||||
evo_fingap_payer
|
||||
evo_fingap_period
|
||||
evo_product_risks {
|
||||
evo_addproduct_typeid
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const QuoteFingapProcessDataSchema = z.object({
|
||||
insurance: z.object({
|
||||
values: z.object({
|
||||
fingap: RowSchema,
|
||||
}),
|
||||
}),
|
||||
fingap: GetQuoteDataOutputSchema.shape.fingap,
|
||||
});
|
||||
|
||||
type QuoteFingapProcessData = z.infer<typeof QuoteFingapProcessDataSchema>;
|
||||
|
||||
export default async function getFingapDataFromKP({
|
||||
values: { quote: quoteId },
|
||||
}: GetQuoteDataInput): Promise<QuoteFingapProcessData> {
|
||||
const apolloClient = initializeApollo();
|
||||
|
||||
const {
|
||||
data: { quote },
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetRisksDataFromQuoteQuery,
|
||||
CRMTypes.GetRisksDataFromQuoteQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_RISKS,
|
||||
variables: {
|
||||
quoteId,
|
||||
},
|
||||
});
|
||||
|
||||
const values: Array<{ key: string }> = [];
|
||||
quote?.evo_product_risks?.forEach((x) => {
|
||||
if (x.evo_addproduct_typeid) {
|
||||
values.push({
|
||||
key: x.evo_addproduct_typeid,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
fingap: {
|
||||
values,
|
||||
},
|
||||
insurance: {
|
||||
values: {
|
||||
fingap: {
|
||||
...DEFAULT_FINGAP_ROW,
|
||||
insuranceCompany: quote?.evo_fingap_accountid || null,
|
||||
insured: quote?.evo_fingap_payer || null,
|
||||
insTerm: quote?.evo_fingap_period || null,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -2,6 +2,7 @@ import message from 'Elements/message';
|
||||
import { reaction } from 'mobx';
|
||||
import type { ReactionsContext } from 'process/types';
|
||||
import { pick } from 'radash';
|
||||
import extend from 'stores/tables/insurance/tools';
|
||||
|
||||
const key = 'KP_LOADING_INFO';
|
||||
|
||||
@ -31,7 +32,7 @@ export default function loadKpReactions({ store, trpcClient }: ReactionsContext)
|
||||
|
||||
trpcClient.quote.getData
|
||||
.query(payload)
|
||||
.then(({ values, payments }) => {
|
||||
.then(({ values, payments, insurance, fingap }) => {
|
||||
$calculation.$values.setValues({
|
||||
values,
|
||||
exclude: ['lead', 'opportunity', 'quote', 'leadUrl', 'opportunityUrl', 'quoteUrl'],
|
||||
@ -39,6 +40,18 @@ export default function loadKpReactions({ store, trpcClient }: ReactionsContext)
|
||||
|
||||
$tables.payments.setValues(payments.values);
|
||||
|
||||
if (insurance.values.osago) {
|
||||
extend($tables.insurance).setRowValues(insurance.values.osago);
|
||||
}
|
||||
if (insurance.values.kasko) {
|
||||
extend($tables.insurance).setRowValues(insurance.values.kasko);
|
||||
}
|
||||
if (insurance.values.fingap) {
|
||||
extend($tables.insurance).setRowValues(insurance.values.fingap);
|
||||
}
|
||||
|
||||
if (fingap) $tables.fingap.setSelectedKeys(fingap.values?.map((x) => x.key));
|
||||
|
||||
message.success({
|
||||
key,
|
||||
content: `КП ${quoteName} загружено`,
|
||||
|
||||
@ -1,24 +1,36 @@
|
||||
import { RiskSchema } from 'config/schema/fingap';
|
||||
import { KeysSchema, RowSchema } from 'config/schema/insurance';
|
||||
import PaymentsSchema from 'config/schema/payments';
|
||||
import ValuesSchema from 'config/schema/values';
|
||||
import { z } from 'zod';
|
||||
|
||||
const { quote, recalcWithRevision } = ValuesSchema.shape;
|
||||
export const GetQuoteDataInputSchema = z.object({
|
||||
values: ValuesSchema.pick({
|
||||
recalcWithRevision: true,
|
||||
}).extend({
|
||||
quote: ValuesSchema.shape.quote.unwrap(),
|
||||
}),
|
||||
values: z
|
||||
.object({
|
||||
quote: quote.unwrap(),
|
||||
recalcWithRevision,
|
||||
})
|
||||
.required(),
|
||||
});
|
||||
export type GetQuoteDataInput = z.infer<typeof GetQuoteDataInputSchema>;
|
||||
|
||||
export const GetQuoteDataOutputSchema = z.object({
|
||||
values: ValuesSchema,
|
||||
payments: PaymentsSchema,
|
||||
insurance: z
|
||||
.object({
|
||||
values: z.record(KeysSchema, RowSchema),
|
||||
})
|
||||
.required(),
|
||||
fingap: z
|
||||
.object({
|
||||
values: z.array(
|
||||
RiskSchema.pick({
|
||||
key: true,
|
||||
})
|
||||
),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
export type GetQuoteDataOutput = z.infer<typeof GetQuoteDataOutputSchema>;
|
||||
|
||||
export const QuoteProcessDataSchema = z.object({
|
||||
values: ValuesSchema.partial(),
|
||||
payments: PaymentsSchema.optional(),
|
||||
});
|
||||
export type QuoteProcessData = z.infer<typeof QuoteProcessDataSchema>;
|
||||
|
||||
@ -3,7 +3,9 @@ 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';
|
||||
import { z } from 'zod';
|
||||
import type { GetQuoteDataInput } from '../load-kp/types';
|
||||
import { GetQuoteDataOutputSchema } from '../load-kp/types';
|
||||
|
||||
const QUERY_GET_PAYMENTS_DATA_FROM_QUOTE = gql`
|
||||
query GetPaymentsDataFromQuote($quoteId: Uuid!) {
|
||||
@ -27,9 +29,16 @@ const QUERY_GET_PAYMENTS_DATA_FROM_QUOTE = gql`
|
||||
}
|
||||
`;
|
||||
|
||||
const { values, payments } = GetQuoteDataOutputSchema.shape;
|
||||
const QuotePaymentsProcessDataSchema = z.object({
|
||||
values: values.partial(),
|
||||
payments,
|
||||
});
|
||||
type QuotePaymentsProcessData = z.infer<typeof QuotePaymentsProcessDataSchema>;
|
||||
|
||||
export default async function getPaymentsDataFromKP({
|
||||
values: { quote: quoteId, recalcWithRevision },
|
||||
}: GetQuoteDataInput): Promise<QuoteProcessData> {
|
||||
}: GetQuoteDataInput): Promise<QuotePaymentsProcessData> {
|
||||
const apolloClient = initializeApollo();
|
||||
|
||||
const {
|
||||
@ -48,9 +57,9 @@ export default async function getPaymentsDataFromKP({
|
||||
? Math.min(quote?.evo_period ?? 0, quote?.evo_accept_period ?? 0)
|
||||
: quote?.evo_period ?? 0;
|
||||
|
||||
let payments: Array<number> = [];
|
||||
let paymentsValues: Array<number> = [];
|
||||
if (quote?.evo_graphs) {
|
||||
payments =
|
||||
paymentsValues =
|
||||
sort(quote?.evo_graphs, (evo_graph) => Date.parse(evo_graph?.createdon))
|
||||
.at(0)
|
||||
?.evo_planpayments?.slice(1, -1)
|
||||
@ -69,7 +78,11 @@ export default async function getPaymentsDataFromKP({
|
||||
lastPaymentPerc: quote?.evo_last_payment_perc || 0,
|
||||
},
|
||||
payments: {
|
||||
values: [quote?.evo_first_payment_perc || 0, ...payments, quote?.evo_last_payment_perc || 0],
|
||||
values: [
|
||||
quote?.evo_first_payment_perc || 0,
|
||||
...paymentsValues,
|
||||
quote?.evo_last_payment_perc || 0,
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
import { gql } from '@apollo/client';
|
||||
import initializeApollo from 'apollo/client';
|
||||
import type * as CRMTypes from 'graphql/crm.types';
|
||||
import type { GetQuoteDataInput, QuoteProcessData } from '../../load-kp/types';
|
||||
import { z } from 'zod';
|
||||
import type { GetQuoteDataInput } from '../../load-kp/types';
|
||||
import { GetQuoteDataOutputSchema } from '../../load-kp/types';
|
||||
import getSums from './get-sums';
|
||||
|
||||
const QUERY_GET_AGENTS_DATA_FROM_QUOTE = gql`
|
||||
@ -37,10 +39,14 @@ const QUERY_GET_AGENTS_DATA_FROM_QUOTE = gql`
|
||||
`;
|
||||
|
||||
export type Quote = NonNullable<CRMTypes.GetAgentsDataFromQuoteQuery['quote']>;
|
||||
const QuoteSupplierAgentProcessDataSchema = z.object({
|
||||
values: GetQuoteDataOutputSchema.shape.values.partial(),
|
||||
});
|
||||
type QuoteSupplierAgentProcessData = z.infer<typeof QuoteSupplierAgentProcessDataSchema>;
|
||||
|
||||
export default async function getSupplierAgentsDataFromKP({
|
||||
values: { quote: quoteId },
|
||||
}: GetQuoteDataInput): Promise<QuoteProcessData> {
|
||||
}: GetQuoteDataInput): Promise<QuoteSupplierAgentProcessData> {
|
||||
const apolloClient = initializeApollo();
|
||||
|
||||
const {
|
||||
|
||||
12
stores/tables/insurance/tools.ts
Normal file
12
stores/tables/insurance/tools.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import type * as Insurance from 'Components/Calculation/Form/Insurance/InsuranceTable/types';
|
||||
import type InsuranceTable from '.';
|
||||
|
||||
export default function extend(insuranceTable: InsuranceTable) {
|
||||
return {
|
||||
setRowValues(row: Insurance.RowValues) {
|
||||
(Object.keys(row) as Insurance.Values[]).forEach((valueName) => {
|
||||
insuranceTable.row(row.key).setValue(valueName, row[valueName]);
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -1,21 +1,22 @@
|
||||
import defaultValues from 'config/default-values';
|
||||
import { defaultValues as defaultInsuranceValues } from 'config/tables/insurance-table';
|
||||
import getFingapDataFromKP from 'process/fingap/get-kp-data';
|
||||
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 { t } from '../server';
|
||||
|
||||
const DEFAULT_OSAGO_ROW = defaultInsuranceValues.find((x) => x.key === 'osago');
|
||||
const DEFAULT_KASKO_ROW = defaultInsuranceValues.find((x) => x.key === 'kasko');
|
||||
|
||||
const quoteRouter = t.router({
|
||||
getData: t.procedure
|
||||
.input(GetQuoteDataInputSchema)
|
||||
.output(GetQuoteDataOutputSchema)
|
||||
.query(async ({ input }) => {
|
||||
const { values: supplierAgentsValues } = await getSupplierAgentsDataFromKP(input);
|
||||
const {
|
||||
values: paymentsValues,
|
||||
payments = {
|
||||
values: [],
|
||||
},
|
||||
} = await getPaymentsDataFromKP(input);
|
||||
const { values: paymentsValues, payments } = await getPaymentsDataFromKP(input);
|
||||
const { fingap, insurance: fingapInsurance } = await getFingapDataFromKP(input);
|
||||
|
||||
return {
|
||||
values: {
|
||||
@ -24,6 +25,14 @@ const quoteRouter = t.router({
|
||||
...paymentsValues,
|
||||
},
|
||||
payments,
|
||||
insurance: {
|
||||
values: {
|
||||
osago: DEFAULT_OSAGO_ROW,
|
||||
kasko: DEFAULT_KASKO_ROW,
|
||||
fingap: fingapInsurance.values.fingap,
|
||||
},
|
||||
},
|
||||
fingap,
|
||||
};
|
||||
}),
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user