calculate: pass payment sums to preparedPayments
This commit is contained in:
parent
b38f25a039
commit
8e2e9167fc
@ -1,6 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const PaymentsSchema = z.object({
|
||||
sums: z.number().optional().array(),
|
||||
values: z.number().array(),
|
||||
});
|
||||
|
||||
|
||||
@ -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) => {
|
||||
|
||||
@ -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) => {
|
||||
|
||||
@ -79,6 +79,7 @@ export async function getKPData({
|
||||
|
||||
return {
|
||||
payments: {
|
||||
sums: [],
|
||||
values: [
|
||||
quote?.evo_first_payment_perc ?? 0,
|
||||
...paymentsValues,
|
||||
|
||||
@ -19,7 +19,7 @@ export function createValidationSchema() {
|
||||
seasonType: true,
|
||||
})
|
||||
.extend({
|
||||
payments: PaymentsSchema,
|
||||
payments: PaymentsSchema.omit({ sums: true }),
|
||||
})
|
||||
.superRefine(
|
||||
async (
|
||||
|
||||
@ -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,
|
||||
})),
|
||||
|
||||
@ -46,7 +46,7 @@ const defaultInsurance = {
|
||||
};
|
||||
|
||||
const defaultFingap = { keys: [] };
|
||||
const defaultPayments = { values: [] };
|
||||
const defaultPayments = { values: [], sums: [] };
|
||||
|
||||
const { URL_CRM_DOWNLOADKP_BASE } = getUrls();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user