From 8e2e9167fc3eb58302f7e58f7d576b94d8365fc1 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Thu, 20 Apr 2023 14:13:16 +0300 Subject: [PATCH] calculate: pass payment sums to preparedPayments --- apps/web/config/schema/payments.ts | 1 + apps/web/process/calculate/action.ts | 5 +++-- apps/web/process/create-kp/action.ts | 5 +++-- apps/web/process/payments/get-kp-data.ts | 1 + apps/web/process/payments/validation.ts | 2 +- apps/web/server/routers/calculate/lib/request.ts | 6 +++--- apps/web/server/routers/quote/index.ts | 2 +- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/web/config/schema/payments.ts b/apps/web/config/schema/payments.ts index 9ef49b5..13d1194 100644 --- a/apps/web/config/schema/payments.ts +++ b/apps/web/config/schema/payments.ts @@ -1,6 +1,7 @@ import { z } from 'zod'; const PaymentsSchema = z.object({ + sums: z.number().optional().array(), values: z.number().array(), }); diff --git a/apps/web/process/calculate/action.ts b/apps/web/process/calculate/action.ts index cb198b3..0cbb5a0 100644 --- a/apps/web/process/calculate/action.ts +++ b/apps/web/process/calculate/action.ts @@ -22,12 +22,13 @@ export async function action({ store, trpcClient }: ProcessContext) { osago: toJS($tables.insurance.row('osago').getValues()), }; - const payments = toJS($tables.payments.values); + const paymentRelations = toJS($tables.payments.values); + const paymentSums = toJS($tables.payments.sums); trpcClient.calculate .mutate({ insurance: { values: insurance }, - payments: { values: payments }, + payments: { sums: paymentSums, values: paymentRelations }, values, }) .then((res) => { diff --git a/apps/web/process/create-kp/action.ts b/apps/web/process/create-kp/action.ts index 47f0ce1..d4a40f6 100644 --- a/apps/web/process/create-kp/action.ts +++ b/apps/web/process/create-kp/action.ts @@ -25,13 +25,14 @@ export function action({ store, trpcClient, apolloClient }: ProcessContext) { const fingap = $tables.fingap.getSelectedRisks(); - const payments = toJS($tables.payments.values); + const paymentRelations = toJS($tables.payments.values); + const paymentSums = toJS($tables.payments.sums); trpcClient.createQuote .mutate({ fingap, insurance: { values: insurance }, - payments: { values: payments }, + payments: { sums: paymentSums, values: paymentRelations }, values, }) .then(async (res) => { diff --git a/apps/web/process/payments/get-kp-data.ts b/apps/web/process/payments/get-kp-data.ts index 69823ef..fb69233 100644 --- a/apps/web/process/payments/get-kp-data.ts +++ b/apps/web/process/payments/get-kp-data.ts @@ -79,6 +79,7 @@ export async function getKPData({ return { payments: { + sums: [], values: [ quote?.evo_first_payment_perc ?? 0, ...paymentsValues, diff --git a/apps/web/process/payments/validation.ts b/apps/web/process/payments/validation.ts index 5a5fc1f..c89aae6 100644 --- a/apps/web/process/payments/validation.ts +++ b/apps/web/process/payments/validation.ts @@ -19,7 +19,7 @@ export function createValidationSchema() { seasonType: true, }) .extend({ - payments: PaymentsSchema, + payments: PaymentsSchema.omit({ sums: true }), }) .superRefine( async ( diff --git a/apps/web/server/routers/calculate/lib/request.ts b/apps/web/server/routers/calculate/lib/request.ts index 15c7afb..23a080e 100644 --- a/apps/web/server/routers/calculate/lib/request.ts +++ b/apps/web/server/routers/calculate/lib/request.ts @@ -34,12 +34,12 @@ export async function createRequestData({ const { RUB } = createCurrencyUtility({ apolloClient }); const preparedPayments: CoreTypes.PreparedPayments = { - rows: payments.values.map((payment, index) => ({ + rows: payments.values.map((value, index) => ({ gpsBasePayment: 0, gpsCostPayment: 0, numberPayment: index + 1, - percentPayment: index === 0 ? 0 : payment, - sumPayment: 0, + percentPayment: index === 0 ? 0 : value, + sumPayment: (payments.sums[index] ?? 0) / (1 + VAT), tlmBasePayment: 0, tlmCostPayment: 0, })), diff --git a/apps/web/server/routers/quote/index.ts b/apps/web/server/routers/quote/index.ts index a6a6946..fae060b 100644 --- a/apps/web/server/routers/quote/index.ts +++ b/apps/web/server/routers/quote/index.ts @@ -46,7 +46,7 @@ const defaultInsurance = { }; const defaultFingap = { keys: [] }; -const defaultPayments = { values: [] }; +const defaultPayments = { values: [], sums: [] }; const { URL_CRM_DOWNLOADKP_BASE } = getUrls();