From b568188a3e2a2912889b3a4dd90bb797e0885a37 Mon Sep 17 00:00:00 2001 From: Kartik Sharma Date: Mon, 17 Nov 2025 10:31:41 +0530 Subject: [PATCH] Adding TDS Calculation in ViewExpense. --- src/components/Expenses/ViewExpense.jsx | 157 ++++++++++-------- .../PaymentRequest/ActionPaymentRequest.jsx | 14 +- src/utils/appUtils.js | 18 ++ 3 files changed, 112 insertions(+), 77 deletions(-) diff --git a/src/components/Expenses/ViewExpense.jsx b/src/components/Expenses/ViewExpense.jsx index a4b1089b..8c032fc0 100644 --- a/src/components/Expenses/ViewExpense.jsx +++ b/src/components/Expenses/ViewExpense.jsx @@ -10,6 +10,7 @@ import { zodResolver } from "@hookform/resolvers/zod"; import { defaultActionValues, ExpenseActionScheam } from "./ExpenseSchema"; import { useExpenseContext } from "../../pages/Expense/ExpensePage"; import { + calculateTDSPercentage, formatCurrency, formatFigure, getColorNameFromHex, @@ -54,12 +55,22 @@ const ViewExpense = ({ ExpenseId }) => { setValue, reset, control, + watch, formState: { errors }, } = useForm({ resolver: zodResolver(ActionSchema), defaultValues: defaultActionValues, }); +const baseAmount = Number(watch("baseAmount")) || 0; +const taxAmount = Number(watch("taxAmount")) || 0; +const tdsPercentage = Number(watch("tdsPercentage")) || 0; + + + const { grossAmount, tdsAmount, netPayable } = useMemo(() => { + return calculateTDSPercentage(baseAmount, taxAmount, tdsPercentage); + }, [baseAmount, taxAmount, tdsPercentage]); + const userPermissions = useSelector( (state) => state?.globalVariables?.loginUser?.featurePermissions || [] ); @@ -132,9 +143,8 @@ const ViewExpense = ({ ExpenseId }) => { {data?.expenseUId} {" "} {data?.status?.name} @@ -142,7 +152,7 @@ const ViewExpense = ({ ExpenseId }) => { {/* Row 1 */} -
+
*/} {/* Row 5 */} - -
+ +
- + - - -
-
- + + +
+
+ {formatUTCToLocalTime(data?.createdAt, true)} - + +
-
{/* Created & Paid By */} {data.createdBy && ( @@ -307,9 +317,8 @@ const ViewExpense = ({ ExpenseId }) => { lastName={data.createdBy?.lastName} /> - {`${data.createdBy?.firstName ?? ""} ${ - data.createdBy?.lastName ?? "" - }`.trim() || "N/A"} + {`${data.createdBy?.firstName ?? ""} ${data.createdBy?.lastName ?? "" + }`.trim() || "N/A"}
@@ -337,31 +346,30 @@ const ViewExpense = ({ ExpenseId }) => {
*/} -
-
- -
-
-
- - - {`${data.paidBy?.firstName ?? ""} ${ - data.paidBy?.lastName ?? "" +
+
+ +
+
+
+ + + {`${data.paidBy?.firstName ?? ""} ${data.paidBy?.lastName ?? "" }`.trim() || "N/A"} - -
+
+
{/* Description */}
@@ -493,19 +501,7 @@ const ViewExpense = ({ ExpenseId }) => { projectId={null} />
-
- - - {errors.tdsPercentage && ( - - {errors.tdsPercentage.message} - - )} -
+
+
+ + + {errors.tdsPercentage && ( + + {errors.tdsPercentage.message} + + )} +
+
+
+ TDS Amount: + {tdsAmount.toFixed(2)} +
+ +
+ Net Payable: + {netPayable.toFixed(2)} +
+
+ )}
{((nextStatusWithPermission.length > 0 && !IsRejectedExpense) || (IsRejectedExpense && isCreatedBy)) && ( - <> - -