fixed missing fieldd noOfEmployee inside employee

This commit is contained in:
pramod.mahajan 2025-11-06 18:08:19 +05:30
parent 72e5cf0bbe
commit 161f14d247
2 changed files with 55 additions and 51 deletions

View File

@ -10,7 +10,7 @@ const ALLOWED_TYPES = [
"image/jpeg", "image/jpeg",
]; ];
export const ExpenseSchema = (expenseTypes) => { export const ExpenseSchema = (ExpenseCategories) => {
return z return z
.object({ .object({
projectId: z.string().min(1, { message: "Project is required" }), projectId: z.string().min(1, { message: "Project is required" }),
@ -70,11 +70,11 @@ export const ExpenseSchema = (expenseTypes) => {
} }
) )
.superRefine((data, ctx) => { .superRefine((data, ctx) => {
const expenseType = expenseTypes.find( const ExpenseCategory = ExpenseCategories.find(
(et) => et.id === data.expensesCategoryId (et) => et.id === data.expenseCategoryId
); );
if ( if (
expenseType?.noOfPersonsRequired && ExpenseCategory?.noOfPersonsRequired &&
(!data.noOfPersons || data.noOfPersons < 1) (!data.noOfPersons || data.noOfPersons < 1)
) { ) {
ctx.addIssue({ ctx.addIssue({
@ -177,7 +177,7 @@ export const SearchSchema = z.object({
statusIds: z.array(z.string()).optional(), statusIds: z.array(z.string()).optional(),
createdByIds: z.array(z.string()).optional(), createdByIds: z.array(z.string()).optional(),
paidById: z.array(z.string()).optional(), paidById: z.array(z.string()).optional(),
ExpenseTypeIds: z.array(z.string()).optional(), ExpenseCategoryIds: z.array(z.string()).optional(),
startDate: z.string().optional(), startDate: z.string().optional(),
endDate: z.string().optional(), endDate: z.string().optional(),
isTransactionDate: z.boolean().default(true), isTransactionDate: z.boolean().default(true),
@ -188,7 +188,7 @@ export const defaultFilter = {
statusIds: [], statusIds: [],
createdByIds: [], createdByIds: [],
paidById: [], paidById: [],
ExpenseTypeIds: [], ExpenseCategoryIds: [],
isTransactionDate: true, isTransactionDate: true,
startDate: null, startDate: null,
endDate: null, endDate: null,

View File

@ -153,7 +153,7 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => {
if (expenseToEdit && data) { if (expenseToEdit && data) {
reset({ reset({
projectId: data.project.id || "", projectId: data.project.id || "",
expenseCategoryId: data.expenseType.id || "", expenseCategoryId: data?.expenseCategory?.id || "",
paymentModeId: data.paymentMode.id || "", paymentModeId: data.paymentMode.id || "",
paidById: data.paidBy.id || "", paidById: data.paidBy.id || "",
transactionDate: data.transactionDate?.slice(0, 10) || "", transactionDate: data.transactionDate?.slice(0, 10) || "",
@ -200,7 +200,7 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => {
CreateExpense(payload); CreateExpense(payload);
} }
}; };
const ExpenseTypeId = watch("expensesCategoryId"); const ExpenseTypeId = watch("expenseCategoryId");
useEffect(() => { useEffect(() => {
setExpenseType( setExpenseType(
@ -306,7 +306,9 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => {
)} )}
</div> </div>
<div className="col-12 col-md-6 text-start"> <div className="col-12 col-md-6 text-start">
<Label className="form-label" required>Paid By </Label> <Label className="form-label" required>
Paid By{" "}
</Label>
<EmployeeSearchInput <EmployeeSearchInput
control={control} control={control}
name="paidById" name="paidById"
@ -421,50 +423,52 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => {
)} )}
</div> </div>
{ExpenseType?.noOfPersonsRequired && (
<div className="col-md-6 mt-2 text-start">
<label className="form-label ">No. of Persons</label>
<input
type="number"
id="noOfPersons"
className="form-control form-control-sm"
{...register("noOfPersons")}
inputMode="numeric"
/>
{errors.noOfPersons && (
<small className="danger-text">
{errors.noOfPersons.message}
</small>
)}
</div>
)}
</div> </div>
<div className="col-md-6 text-start"> <div className="row">
<Label htmlFor="currencyId" className="form-label" required> <div className="col-md-6 text-start ">
Select Currency <Label htmlFor="currencyId" className="form-label" required>
</Label>
<select
className="form-select form-select-sm"
id="currencyId"
{...register("currencyId")}
>
<option value="" disabled>
Select Currency Select Currency
</option> </Label>
{currencyLoading ? ( <select
<option disabled>Loading...</option> className="form-select form-select-sm"
) : ( id="currencyId"
currencies?.map((currency) => ( {...register("currencyId")}
<option key={currency.id} value={currency.id}> >
{`${currency.currencyName} (${currency.symbol}) `} <option value="" disabled>
</option> Select Currency
)) </option>
{currencyLoading ? (
<option disabled>Loading...</option>
) : (
currencies?.map((currency) => (
<option key={currency.id} value={currency.id}>
{`${currency.currencyName} (${currency.symbol}) `}
</option>
))
)}
</select>
{errors.currencyId && (
<small className="danger-text">{errors.currencyId.message}</small>
)} )}
</select> </div>
{errors.currencyId && ( {ExpenseType?.noOfPersonsRequired && (
<small className="danger-text">{errors.currencyId.message}</small> <div className="col-md-6 text-start">
)} <Label className="form-label" required>No. of Persons</Label>
</div> <input
type="number"
id="noOfPersons"
className="form-control form-control-sm"
{...register("noOfPersons")}
inputMode="numeric"
/>
{errors.noOfPersons && (
<small className="danger-text">
{errors.noOfPersons.message}
</small>
)}
</div>
)}
</div>
<div className="row my-2 text-start"> <div className="row my-2 text-start">
<div className="col-md-12"> <div className="col-md-12">