114 lines
3.2 KiB
JavaScript
114 lines
3.2 KiB
JavaScript
import { boolean, z } from "zod";
|
|
import { INR_CURRENCY_CODE } from "../../utils/constants";
|
|
|
|
export const PaymentRecurringExpense = () => {
|
|
return z.object({
|
|
title: z.string().min(1, { message: "Title is required" }).transform((val) => val.trim()),
|
|
description: z.string().min(1, { message: "Description is required" }).transform((val) => val.trim()),
|
|
payee: z.string().min(1, { message: "Payee name is required" }).transform((val) => val.trim()),
|
|
notifyTo: z.array(z.string()).min(1,"Please select at lest one user"),
|
|
currencyId: z
|
|
.string()
|
|
.min(1, { message: "Currency is required" })
|
|
.transform((val) => val.trim()),
|
|
|
|
amount: z
|
|
.number({
|
|
required_error: "Amount is required",
|
|
invalid_type_error: "Amount must be a number",
|
|
})
|
|
.min(1, { message: "Amount must be greater than 0" })
|
|
.refine((val) => /^\d+(\.\d{1,2})?$/.test(val.toString()), {
|
|
message: "Amount must have at most 2 decimal places",
|
|
}),
|
|
|
|
strikeDate: z
|
|
.string()
|
|
.min(1, { message: "Strike Date is required" })
|
|
.refine((val) => !isNaN(Date.parse(val)), {
|
|
message: "Invalid date format",
|
|
})
|
|
.transform((val) => val.trim()),
|
|
|
|
projectId: z
|
|
.string()
|
|
.min(1, { message: "Project is required" })
|
|
.transform((val) => val.trim()),
|
|
|
|
paymentBufferDays: z
|
|
.number({
|
|
required_error: "Buffer days is required",
|
|
invalid_type_error: "Buffer days must be a number",
|
|
})
|
|
.min(0, { message: "Buffer days cannot be negative" }),
|
|
|
|
endDate: z
|
|
.string()
|
|
.min(1, { message: "End Date is required" })
|
|
.refine((val) => !isNaN(Date.parse(val)), {
|
|
message: "Invalid date format",
|
|
})
|
|
.transform((val) => val.trim()),
|
|
|
|
expenseCategoryId: z
|
|
.string()
|
|
.min(1, { message: "Expense Category is required" })
|
|
.transform((val) => val.trim()),
|
|
|
|
statusId: z
|
|
.string()
|
|
.min(1, { message: "Please select a status" })
|
|
.transform((val) => val.trim()),
|
|
|
|
frequency: z
|
|
.number({
|
|
required_error: "Frequency is required",
|
|
invalid_type_error: "Frequency must be a number",
|
|
})
|
|
.refine((val) => [0, 1, 2, 3, 4, 5].includes(val), {
|
|
message: "Invalid frequency selected",
|
|
}),
|
|
|
|
isVariable: z.boolean().optional(),
|
|
});
|
|
};
|
|
|
|
|
|
export const defaultRecurringExpense = {
|
|
title: "",
|
|
description: "",
|
|
payee: "",
|
|
notifyTo: [],
|
|
currencyId: "",
|
|
amount: 0,
|
|
strikeDate: "",
|
|
projectId: "",
|
|
paymentBufferDays: 0,
|
|
endDate: "",
|
|
expenseCategoryId: "",
|
|
statusId: "",
|
|
frequency: 1,
|
|
isVariable: true,
|
|
};
|
|
|
|
|
|
export const SearchRecurringExpenseSchema = z.object({
|
|
title: z.array(z.string()).optional(),
|
|
description: z.array(z.string()).optional(),
|
|
payee: z.array(z.string()).optional(),
|
|
notifyTo: z.array(z.string()).optional(),
|
|
currencyId: z.array(z.string()).optional(),
|
|
amount: z.array(z.string()).optional(),
|
|
strikeDate: z.string().optional(),
|
|
projectId: z.string().optional(),
|
|
paymentBufferDays: z.string().optional(),
|
|
numberOfIteration: z.string().optional(),
|
|
expenseCategoryId: z.string().optional(),
|
|
statusId: z.string().optional(),
|
|
frequency: z.string().optional(),
|
|
isVariable: z.string().optional(),
|
|
});
|
|
|
|
|
|
|