diff --git a/apps/web/graphql/crm.types.ts b/apps/web/graphql/crm.types.ts index 4ea012a..fd58714 100644 --- a/apps/web/graphql/crm.types.ts +++ b/apps/web/graphql/crm.types.ts @@ -498,6 +498,13 @@ export type GetQuoteConfiguratorDataQueryVariables = Exact<{ export type GetQuoteConfiguratorDataQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_baseproductid: string | null, evo_client_typeid: string | null, evo_msfo_irr: number | null } | null }; +export type GetQuoteCreateKpDataQueryVariables = Exact<{ + quoteId: Scalars['Uuid']; +}>; + + +export type GetQuoteCreateKpDataQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_price_with_discount: boolean | null, evo_price_without_discount_quote: boolean | null, evo_cost_increace: boolean | null, evo_insurance: boolean | null, evo_registration_quote: boolean | null, evo_card_quote: boolean | null, evo_nsib_quote: boolean | null, evo_redemption_graph: boolean | null, evo_fingap_quote: boolean | null, evo_contact_name: string | null, evo_gender: number | null } | null }; + export type GetQuoteFingapDataQueryVariables = Exact<{ quoteId: Scalars['Uuid']; }>; @@ -653,6 +660,7 @@ export const GetRolesDocument = {"kind":"Document","definitions":[{"kind":"Opera export const GetQuoteAddProductDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteAddProductData"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_product_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_typeid"}}]}}]}}]}}]} as unknown as DocumentNode; export const GetQuoteBonusDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteBonusData"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_sale_bonus"}}]}}]}}]} as unknown as DocumentNode; export const GetQuoteConfiguratorDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteConfiguratorData"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_baseproductid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_client_typeid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_msfo_irr"}}]}}]}}]} as unknown as DocumentNode; +export const GetQuoteCreateKpDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteCreateKPData"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_price_with_discount"}},{"kind":"Field","name":{"kind":"Name","value":"evo_price_without_discount_quote"}},{"kind":"Field","name":{"kind":"Name","value":"evo_cost_increace"}},{"kind":"Field","name":{"kind":"Name","value":"evo_insurance"}},{"kind":"Field","name":{"kind":"Name","value":"evo_registration_quote"}},{"kind":"Field","name":{"kind":"Name","value":"evo_card_quote"}},{"kind":"Field","name":{"kind":"Name","value":"evo_nsib_quote"}},{"kind":"Field","name":{"kind":"Name","value":"evo_redemption_graph"}},{"kind":"Field","name":{"kind":"Name","value":"evo_fingap_quote"}},{"kind":"Field","name":{"kind":"Name","value":"evo_contact_name"}},{"kind":"Field","name":{"kind":"Name","value":"evo_gender"}}]}}]}}]} as unknown as DocumentNode; export const GetQuoteFingapDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteFingapData"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_product_risks"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_typeid"}}]}}]}}]}}]} as unknown as DocumentNode; export const GetFinGapAddProductTypesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetFinGAPAddProductTypes"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_datefrom_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_dateto_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_product_type"},"value":{"kind":"IntValue","value":"100000006"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_typeid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","name":{"kind":"Name","value":"evo_type_calc_cerebellum"}},{"kind":"Field","name":{"kind":"Name","value":"evo_cost_service_provider_withoutnds"}},{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_typeid"}}]}}]}}]}}]} as unknown as DocumentNode; export const GetQuoteGibddDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteGibddData"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_db_accept_registration"}},{"kind":"Field","name":{"kind":"Name","value":"evo_object_registration"}},{"kind":"Field","name":{"kind":"Name","value":"evo_pts_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_vehicle_tax_year"}},{"kind":"Field","name":{"kind":"Name","value":"evo_vehicle_tax_approved"}},{"kind":"Field","name":{"kind":"Name","value":"evo_category_tr"}},{"kind":"Field","name":{"kind":"Name","value":"evo_vehicle_type_tax"}},{"kind":"Field","name":{"kind":"Name","value":"evo_regionid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_townid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_legal_regionid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_legal_townid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_registration_regionid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_req_telematic"}},{"kind":"Field","name":{"kind":"Name","value":"evo_req_telematic_accept"}}]}}]}}]} as unknown as DocumentNode; diff --git a/apps/web/process/create-kp/get-kp-data.ts b/apps/web/process/create-kp/get-kp-data.ts new file mode 100644 index 0000000..cf34cf3 --- /dev/null +++ b/apps/web/process/create-kp/get-kp-data.ts @@ -0,0 +1,56 @@ +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 { gql } from '@apollo/client'; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const QUERY_GET_CREATEKP_DATA = gql` + query GetQuoteCreateKPData($quoteId: Uuid!) { + quote(quoteId: $quoteId) { + evo_price_with_discount + evo_price_without_discount_quote + evo_cost_increace + evo_insurance + evo_registration_quote + evo_card_quote + evo_nsib_quote + evo_redemption_graph + evo_fingap_quote + evo_contact_name + evo_gender + } + } +`; + +export async function getKPData({ + values: { quote: quoteId }, +}: GetQuoteInputData): Promise { + const apolloClient = initializeApollo(); + + const { + data: { quote }, + } = await apolloClient.query({ + query: CRMTypes.GetQuoteCreateKpDataDocument, + variables: { + quoteId, + }, + }); + + return { + values: { + NSIB: quote?.evo_nsib_quote ?? defaultValues.NSIB, + costIncrease: quote?.evo_cost_increace ?? defaultValues.costIncrease, + fullPriceWithDiscount: + quote?.evo_price_without_discount_quote ?? defaultValues.fullPriceWithDiscount, + insurance: quote?.evo_insurance ?? defaultValues.insurance, + priceWithDiscount: quote?.evo_price_with_discount ?? defaultValues.priceWithDiscount, + quoteContactGender: quote?.evo_gender ?? defaultValues.quoteContactGender, + quoteName: quote?.evo_contact_name ?? defaultValues.quoteName, + quoteRedemptionGraph: quote?.evo_redemption_graph ?? defaultValues.quoteRedemptionGraph, + registrationQuote: quote?.evo_registration_quote ?? defaultValues.registrationQuote, + showFinGAP: quote?.evo_fingap_quote ?? defaultValues.showFinGAP, + technicalCardQuote: quote?.evo_card_quote ?? defaultValues.technicalCardQuote, + }, + }; +} diff --git a/apps/web/process/create-kp/index.ts b/apps/web/process/create-kp/index.ts index facb8da..3299eac 100644 --- a/apps/web/process/create-kp/index.ts +++ b/apps/web/process/create-kp/index.ts @@ -1,2 +1,3 @@ export * from './action'; +export * from './get-kp-data'; export * as reactions from './reactions'; diff --git a/apps/web/process/leasing-object/reactions/common.ts b/apps/web/process/leasing-object/reactions/common.ts index c51518c..0cbce4e 100644 --- a/apps/web/process/leasing-object/reactions/common.ts +++ b/apps/web/process/leasing-object/reactions/common.ts @@ -332,6 +332,9 @@ export default function reactions({ store, apolloClient }: ProcessContext) { return; } + let evo_importer_reward_perc = 0; + let evo_importer_reward_rub = 0; + if (modelId) { const { data: { evo_model }, @@ -341,17 +344,15 @@ export default function reactions({ store, apolloClient }: ProcessContext) { }); if (evo_model?.evo_importer_reward_perc) { - tbxImporterRewardPerc.setValue(evo_model?.evo_importer_reward_perc); - } else { - tbxImporterRewardPerc.resetValue(); + evo_importer_reward_perc = evo_model?.evo_importer_reward_perc; } if (evo_model?.evo_importer_reward_rub) { - tbxImporterRewardRub.setValue(evo_model?.evo_importer_reward_rub); - } else { - tbxImporterRewardRub.resetValue(); + evo_importer_reward_rub = evo_model?.evo_importer_reward_rub; } - } else if (brandId) { + } + + if (brandId && evo_importer_reward_perc === 0 && evo_importer_reward_rub === 0) { const { data: { evo_brand }, } = await apolloClient.query({ @@ -360,20 +361,16 @@ export default function reactions({ store, apolloClient }: ProcessContext) { }); if (evo_brand?.evo_importer_reward_perc) { - tbxImporterRewardPerc.setValue(evo_brand?.evo_importer_reward_perc); - } else { - tbxImporterRewardPerc.resetValue(); + evo_importer_reward_perc = evo_brand?.evo_importer_reward_perc; } if (evo_brand?.evo_importer_reward_rub) { - tbxImporterRewardRub.setValue(evo_brand?.evo_importer_reward_rub); - } else { - tbxImporterRewardRub.resetValue(); + evo_importer_reward_rub = evo_brand?.evo_importer_reward_rub; } - } else { - tbxImporterRewardPerc.resetValue(); - tbxImporterRewardRub.resetValue(); } + + tbxImporterRewardPerc.setValue(evo_importer_reward_perc); + tbxImporterRewardRub.setValue(evo_importer_reward_rub); } ); diff --git a/apps/web/process/price/reactions/computed.ts b/apps/web/process/price/reactions/computed.ts index 1e0a476..199f479 100644 --- a/apps/web/process/price/reactions/computed.ts +++ b/apps/web/process/price/reactions/computed.ts @@ -57,6 +57,7 @@ export default function reactions({ store, apolloClient }: ProcessContext) { }, { delay: 100, + fireImmediately: true, } ); } diff --git a/apps/web/process/supplier-agent/validation.ts b/apps/web/process/supplier-agent/validation.ts index 63baed2..6a5c0b7 100644 --- a/apps/web/process/supplier-agent/validation.ts +++ b/apps/web/process/supplier-agent/validation.ts @@ -1,3 +1,4 @@ +/* eslint-disable sonarjs/cognitive-complexity */ /* eslint-disable complexity */ import type { ValidationContext } from '../types'; import type { Elements } from '@/Components/Calculation/config/map/values'; @@ -109,6 +110,36 @@ function helper({ apolloClient, ctx }: ValidationContext & { ctx: RefinementCtx } } }, + + async validateRewardWithoutOtherAgent({ + conditionId, + fieldName, + }: { + conditionId: string | null; + fieldName: string; + }) { + if (conditionId) { + const { + data: { evo_reward_condition }, + } = await apolloClient.query< + CRMTypes.GetRewardConditionQuery, + CRMTypes.GetRewardConditionQueryVariables + >({ + query: CRMTypes.GetRewardConditionDocument, + variables: { + conditionId, + }, + }); + + if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: 'Согласно условиям АД выплата допустима только этому агенту', + path: [fieldName], + }); + } + } + }, }; } @@ -152,13 +183,15 @@ export function createValidationSchema(context: ValidationContext) { .merge(SumsSchema) .superRefine(async (values, ctx) => { const { + calcBroker, calcBrokerRewardCondition, calcBrokerRewardSum, + calcDoubleAgent, calcDoubleAgentRewardCondition, calcDoubleAgentRewardSumm, + calcFinDepartment, dealer: dealerId, dealerBroker, - calcFinDepartment, dealerBrokerRewardCondition, dealerBrokerRewardSumm, dealerPerson, @@ -169,9 +202,8 @@ export function createValidationSchema(context: ValidationContext) { indAgent, indAgentRewardCondition, indAgentRewardSumm, - calcDoubleAgent, - calcBroker, } = values; + /** * Добавить валидацию на кнопку Рассчитать: * если tbxDealerRewardSumm > 0 и @@ -339,7 +371,7 @@ export function createValidationSchema(context: ValidationContext) { }); } - const { validateRewardSum } = helper({ ...context, ctx }); + const { validateRewardSum, validateRewardWithoutOtherAgent } = helper({ ...context, ctx }); await validateRewardSum({ agentid: dealerPerson, @@ -382,5 +414,54 @@ export function createValidationSchema(context: ValidationContext) { sum: finDepartmentRewardSumm, sumFieldName: 'tbxFinDepartmentRewardSumm', }); + + /** + * Если в 2х и более полях RewardSumm значения больше 0 И в полях RewardCondtion есть хотя бы одна запись, + * у которой evo_reward_condition.evo_agency_agreementid. Выплата без других агентов + * (evo_reward_without_other_agent) = True, + * то выводить ошибку "Согласно условиям АД выплата допустима только этому агенту" на то RewardCondtion, + * у которого evo_reward_condition.evo_agency_agreementid равно True + * иначе все ок + */ + if ( + [ + calcBrokerRewardSum, + calcDoubleAgentRewardSumm, + dealerBrokerRewardSumm, + dealerRewardSumm, + finDepartmentRewardSumm, + indAgentRewardSumm, + ].filter((x) => x > 0).length > 1 + ) { + await validateRewardWithoutOtherAgent({ + conditionId: calcBrokerRewardCondition, + fieldName: 'selectCalcBrokerRewardCondition', + }); + + await validateRewardWithoutOtherAgent({ + conditionId: calcDoubleAgentRewardCondition, + fieldName: 'selectCalcDoubleAgentRewardCondition', + }); + + await validateRewardWithoutOtherAgent({ + conditionId: dealerBrokerRewardCondition, + fieldName: 'selectDealerBrokerRewardCondition', + }); + + await validateRewardWithoutOtherAgent({ + conditionId: dealerRewardCondition, + fieldName: 'selectDealerRewardCondition', + }); + + await validateRewardWithoutOtherAgent({ + conditionId: finDepartmentRewardCondtion, + fieldName: 'selectFinDepartmentRewardCondtion', + }); + + await validateRewardWithoutOtherAgent({ + conditionId: indAgentRewardCondition, + fieldName: 'selectIndAgentRewardCondition', + }); + } }); } diff --git a/apps/web/server/routers/quote/index.ts b/apps/web/server/routers/quote/index.ts index 6bb82f4..4fa50d1 100644 --- a/apps/web/server/routers/quote/index.ts +++ b/apps/web/server/routers/quote/index.ts @@ -21,6 +21,7 @@ import * as CRMTypes from '@/graphql/crm.types'; import * as addProduct from '@/process/add-product'; import * as bonuses from '@/process/bonuses'; import * as configurator from '@/process/configurator'; +import * as createKpProcess from '@/process/create-kp'; import * as fingapProcess from '@/process/fingap'; import * as gibdd from '@/process/gibdd'; import * as insuranceProcess from '@/process/insurance'; @@ -63,6 +64,7 @@ export const quoteRouter = router({ subsidy, insuranceProcess, addProduct, + createKpProcess, ].map(({ getKPData }) => getKPData(input)) ); diff --git a/apps/web/stores/calculation/values/index.ts b/apps/web/stores/calculation/values/index.ts index 60ae3f1..15e738f 100644 --- a/apps/web/stores/calculation/values/index.ts +++ b/apps/web/stores/calculation/values/index.ts @@ -26,7 +26,9 @@ export default class ValuesStore { public setValues = (values: Partial) => { (Object.keys(values) as Array).forEach((valueName) => { const value = values[valueName]; - if (value) this.setValue(valueName, value); + if (value !== null && value !== undefined) { + this.setValue(valueName, value); + } }); };