91 lines
3.0 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import ValuesSchema from '@/config/schema/values';
import { VAT } from '@/constants/values';
import { round } from 'tools';
import { z } from 'zod';
export function createValidationSchema() {
return ValuesSchema.pick({
VATInLeaseObjectPrice: true,
balanceHolder: true,
firstPaymentRub: true,
lastPaymentPerc: true,
leaseObjectPriceWthtVAT: true,
partialVAT: true,
plPriceRub: true,
product: true,
subsidySum: true,
supplierDiscountRub: true,
}).superRefine(
async (
{
VATInLeaseObjectPrice,
leaseObjectPriceWthtVAT,
product: productId,
supplierDiscountRub,
plPriceRub,
firstPaymentRub,
subsidySum,
balanceHolder,
lastPaymentPerc,
partialVAT,
},
ctx
) => {
if (
productId &&
partialVAT &&
round(VATInLeaseObjectPrice / leaseObjectPriceWthtVAT, 2) >= VAT
) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message:
'При продаже ПЛ после ФЛ размер НДС в стоимости ПЛ не может составлять 20% и более от стоимости с НДС. Проверьте корректность НДС, либо измените Продукт',
path: ['tbxVATInLeaseObjectPrice'],
});
}
if (supplierDiscountRub >= plPriceRub) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Скидка не может быть больше или равна стоимости ПЛ',
path: ['tbxSupplierDiscountRub'],
});
}
if (firstPaymentRub >= plPriceRub) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Первый платеж не может быть больше или равен стоимости ПЛ',
path: ['tbxFirstPaymentRub'],
});
}
if (firstPaymentRub - subsidySum < 0) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message:
'Первый платеж с учетом субсидии получается отрицательный, увеличьте первый платеж',
path: ['tbxFirstPaymentRub'],
});
}
if (balanceHolder === 100_000_001) {
if (lastPaymentPerc < 1) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message:
'При балансе лизингодатель последний платеж не может быть меньше 1%! Увеличьте значение.',
path: ['tbxLastPaymentPerc'],
});
}
} else if (lastPaymentPerc === 0) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Последний платеж не может быть равен 0. Увеличьте значение',
path: ['tbxLastPaymentPerc'],
});
}
}
);
}