calculate: pass payment sums to preparedPayments

This commit is contained in:
vchikalkin 2023-04-20 14:13:16 +03:00
parent b38f25a039
commit 8e2e9167fc
7 changed files with 13 additions and 9 deletions

View File

@ -1,6 +1,7 @@
import { z } from 'zod';
const PaymentsSchema = z.object({
sums: z.number().optional().array(),
values: z.number().array(),
});

View File

@ -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) => {

View File

@ -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) => {

View File

@ -79,6 +79,7 @@ export async function getKPData({
return {
payments: {
sums: [],
values: [
quote?.evo_first_payment_perc ?? 0,
...paymentsValues,

View File

@ -19,7 +19,7 @@ export function createValidationSchema() {
seasonType: true,
})
.extend({
payments: PaymentsSchema,
payments: PaymentsSchema.omit({ sums: true }),
})
.superRefine(
async (

View File

@ -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,
})),

View File

@ -46,7 +46,7 @@ const defaultInsurance = {
};
const defaultFingap = { keys: [] };
const defaultPayments = { values: [] };
const defaultPayments = { values: [], sums: [] };
const { URL_CRM_DOWNLOADKP_BASE } = getUrls();