From ec2a1706fca8afaf8ad650c5010b0e81e1e7b04d Mon Sep 17 00:00:00 2001 From: "pramod.mahajan" Date: Wed, 5 Nov 2025 17:04:04 +0530 Subject: [PATCH] added new fields inside Expense action - tds, baseAmount, taxAmount --- src/components/Expenses/ExpenseList.jsx | 13 +- src/components/Expenses/ExpenseSchema.js | 38 +- src/components/Expenses/ManageExpense.jsx | 58 +- src/components/Expenses/ViewExpense.jsx | 690 ++++++++++-------- .../PaymentRequest/ManagePaymentRequest.jsx | 4 +- .../PaymentRequest/ViewPaymentRequest.jsx | 4 +- src/components/common/EmployeeSearchInput.jsx | 2 +- src/utils/constants.jsx | 1 + 8 files changed, 488 insertions(+), 322 deletions(-) diff --git a/src/components/Expenses/ExpenseList.jsx b/src/components/Expenses/ExpenseList.jsx index 474fa374..fb82d067 100644 --- a/src/components/Expenses/ExpenseList.jsx +++ b/src/components/Expenses/ExpenseList.jsx @@ -124,9 +124,9 @@ const ExpenseList = ({ filters, groupBy = "transactionDate", searchText }) => { align: "text-start mx-2", }, { - key: "expensesType", + key: "expensesCategory", label: "Expense Category", - getValue: (e) => e.expensesType?.name || "N/A", + getValue: (e) => e.expenseCategory?.name || "N/A", align: "text-start", }, { @@ -254,7 +254,7 @@ const ExpenseList = ({ filters, groupBy = "transactionDate", searchText }) => { className={`sorting d-table-cell `} aria-sort="descending" > -
{col.label}
+
{col.label}
) )} @@ -289,9 +289,12 @@ const ExpenseList = ({ filters, groupBy = "transactionDate", searchText }) => { (col.isAlwaysVisible || groupBy !== col.key) && ( -
{col.customRender +
{col.customRender ? col.customRender(expense) : col.getValue(expense)}
diff --git a/src/components/Expenses/ExpenseSchema.js b/src/components/Expenses/ExpenseSchema.js index dd189d83..65c05133 100644 --- a/src/components/Expenses/ExpenseSchema.js +++ b/src/components/Expenses/ExpenseSchema.js @@ -1,5 +1,6 @@ import { z } from "zod"; import { localToUtc } from "../../utils/appUtils"; +import { DEFAULT_CURRENCY } from "../../utils/constants"; const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB const ALLOWED_TYPES = [ @@ -24,6 +25,10 @@ export const ExpenseSchema = (expenseTypes) => { location: z.string().min(1, { message: "Location is required" }), supplerName: z.string().min(1, { message: "Supplier name is required" }), gstNumber: z.string().optional(), + currencyId: z + .string() + .min(1, { message: "currency is required" }) + .default(DEFAULT_CURRENCY), amount: z.coerce .number({ invalid_type_error: "Amount is required and must be a number", @@ -94,6 +99,7 @@ export const defaultExpense = { amount: "", noOfPersons: "", gstNumber: "", + currencyId: DEFAULT_CURRENCY, billAttachments: [], }; @@ -108,6 +114,9 @@ export const ExpenseActionScheam = ( reimburseTransactionId: z.string().nullable().optional(), reimburseDate: z.string().nullable().optional(), reimburseById: z.string().nullable().optional(), + tdsPercentage: z.number().optional(), + baseAmount: z.string().nullable().optional(), + taxAmount: z.string().nullable().optional(), }) .superRefine((data, ctx) => { if (isReimbursement) { @@ -125,15 +134,7 @@ export const ExpenseActionScheam = ( message: "Reimburse Date is required", }); } - // let reimburse_Date = localToUtc(data.reimburseDate); - // if (transactionDate > reimburse_Date) { - // ctx.addIssue({ - // code: z.ZodIssueCode.custom, - // path: ["reimburseDate"], - // message: - // "Reimburse Date must be greater than or equal to Expense created Date", - // }); - // } + if (!data.reimburseById) { ctx.addIssue({ code: z.ZodIssueCode.custom, @@ -141,6 +142,20 @@ export const ExpenseActionScheam = ( message: "Reimburse By is required", }); } + if (!data.baseAmount) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + path: ["baseAmount"], + message: "Base Amount i required", + }); + } + if (!data.taxAmount) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + path: ["taxAmount"], + message: "Tax is required", + }); + } } }); }; @@ -151,7 +166,10 @@ export const defaultActionValues = { reimburseTransactionId: null, reimburseDate: null, - reimburseById: null, + reimburseById: "", + tdsPercentage: 0, + baseAmount: "", + taxAmount: "", }; export const SearchSchema = z.object({ diff --git a/src/components/Expenses/ManageExpense.jsx b/src/components/Expenses/ManageExpense.jsx index 539497ca..fd3fb4b3 100644 --- a/src/components/Expenses/ManageExpense.jsx +++ b/src/components/Expenses/ManageExpense.jsx @@ -3,7 +3,7 @@ import React, { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { defaultExpense, ExpenseSchema } from "./ExpenseSchema"; import { formatFileSize, localToUtc } from "../../utils/appUtils"; -import { useProjectName } from "../../hooks/useProjects"; +import { useCurrencies, useProjectName } from "../../hooks/useProjects"; import { useDispatch, useSelector } from "react-redux"; import { changeMaster } from "../../slices/localVariablesSlice"; import useMaster, { @@ -30,7 +30,7 @@ import ErrorPage from "../../pages/ErrorPage"; import Label from "../common/Label"; import EmployeeSearchInput from "../common/EmployeeSearchInput"; import Filelist from "./Filelist"; - +import { DEFAULT_CURRENCY } from "../../utils/constants"; const ManageExpense = ({ closeModal, expenseToEdit = null }) => { const { @@ -67,7 +67,11 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => { error, isError: isProjectError, } = useProjectName(); - + const { + data: currencies, + isLoading: currencyLoading, + error: currencyError, + } = useCurrencies(); const { PaymentModes, loading: PaymentModeLoading, @@ -83,7 +87,7 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => { isLoading: EmpLoading, isError: isEmployeeError, } = useEmployeesNameByProject(selectedproject); - + const files = watch("billAttachments"); const onFileChange = async (e) => { const newFiles = Array.from(e.target.files); @@ -129,7 +133,8 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => { reader.onload = () => resolve(reader.result.split(",")[1]); reader.onerror = (error) => reject(error); }); - const removeFile = (index) => {documentId + const removeFile = (index) => { + documentId; if (expenseToEdit) { const newFiles = files.map((file, i) => { if (file.documentId !== index) return file; @@ -160,6 +165,7 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => { amount: data.amount || "", noOfPersons: data.noOfPersons || "", gstNumber: data.gstNumber || "", + currencyId: data.currencyId || DEFAULT_CURRENCY, billAttachments: data.documents ? data.documents.map((doc) => ({ fileName: doc.fileName, @@ -198,7 +204,9 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => { const ExpenseTypeId = watch("expensesCategoryId"); useEffect(() => { - setExpenseType(ExpenseCategories?.find((type) => type.id === ExpenseTypeId)); + setExpenseType( + ExpenseCategories?.find((type) => type.id === ExpenseTypeId) + ); }, [ExpenseTypeId]); const handleClose = () => { @@ -299,7 +307,7 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => { )}
- + {
)} +
+ + + {errors.currencyId && ( + {errors.currencyId.message} + )} +
@@ -452,7 +486,7 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => {
-
+