added payee default

This commit is contained in:
pramod.mahajan 2025-11-05 18:10:24 +05:30
parent ec2a1706fc
commit 9b091840d6
5 changed files with 75 additions and 41 deletions

View File

@ -114,7 +114,7 @@ export const ExpenseActionScheam = (
reimburseTransactionId: z.string().nullable().optional(), reimburseTransactionId: z.string().nullable().optional(),
reimburseDate: z.string().nullable().optional(), reimburseDate: z.string().nullable().optional(),
reimburseById: z.string().nullable().optional(), reimburseById: z.string().nullable().optional(),
tdsPercentage: z.number().optional(), tdsPercentage: z.number().nullable().optional(),
baseAmount: z.string().nullable().optional(), baseAmount: z.string().nullable().optional(),
taxAmount: z.string().nullable().optional(), taxAmount: z.string().nullable().optional(),
}) })
@ -166,10 +166,10 @@ export const defaultActionValues = {
reimburseTransactionId: null, reimburseTransactionId: null,
reimburseDate: null, reimburseDate: null,
reimburseById: "", reimburseById: null,
tdsPercentage: 0, tdsPercentage: null,
baseAmount: "", baseAmount:null,
taxAmount: "", taxAmount: null,
}; };
export const SearchSchema = z.object({ export const SearchSchema = z.object({

View File

@ -393,7 +393,7 @@ const ViewExpense = ({ ExpenseId }) => {
{IsPaymentProcess && nextStatusWithPermission?.length > 0 && ( {IsPaymentProcess && nextStatusWithPermission?.length > 0 && (
<div className="row "> <div className="row ">
<div className="col-12 col-md-6 text-start"> <div className="col-12 col-md-6 text-start">
<label className="form-label">Transaction Id </label> <Label className="form-label" required>Transaction Id </Label>
<input <input
type="text" type="text"
className="form-control form-control-sm" className="form-control form-control-sm"
@ -405,8 +405,8 @@ const ViewExpense = ({ ExpenseId }) => {
</small> </small>
)} )}
</div> </div>
<div className="col-12 col-md-6 text-start mb-2"> <div className="col-12 col-md-6 text-start mb-1">
<label className="form-label">Transaction Date </label> <Label className="form-label" required>Transaction Date </Label>
<DatePicker <DatePicker
name="reimburseDate" name="reimburseDate"
control={control} control={control}
@ -419,7 +419,7 @@ const ViewExpense = ({ ExpenseId }) => {
</small> </small>
)} )}
</div> </div>
<div className="col-12 col-md-6 text-start mb-2"> <div className="col-12 col-md-6 text-start mb-1">
<Label className="form-label" required> <Label className="form-label" required>
Reimburse By{" "} Reimburse By{" "}
</Label> </Label>
@ -476,7 +476,7 @@ const ViewExpense = ({ ExpenseId }) => {
</div> </div>
</div> </div>
)} )}
<div className="col-12 mb-3 text-start mt-2"> <div className="col-12 mb-3 text-start mt-1">
{((nextStatusWithPermission.length > 0 && {((nextStatusWithPermission.length > 0 &&
!IsRejectedExpense) || !IsRejectedExpense) ||
(IsRejectedExpense && isCreatedBy)) && ( (IsRejectedExpense && isCreatedBy)) && (

View File

@ -1,7 +1,7 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { useCurrencies, useProjectName } from "../../hooks/useProjects"; import { useCurrencies, useProjectName } from "../../hooks/useProjects";
import Label from "../common/Label"; import Label from "../common/Label";
import { useForm } from "react-hook-form"; import { Controller, useForm } from "react-hook-form";
import { useExpenseCategory } from "../../hooks/masterHook/useMaster"; import { useExpenseCategory } from "../../hooks/masterHook/useMaster";
import DatePicker from "../common/DatePicker"; import DatePicker from "../common/DatePicker";
import { import {
@ -50,7 +50,12 @@ function ManagePaymentRequest({ closeModal, requestToEdit = null }) {
} = useExpenseCategory(); } = useExpenseCategory();
const { profile } = useProfile(); const { profile } = useProfile();
const {data:Payees,isLoading:isPayeeLoaing,isError:isPayeeError,error:payeeError} = usePayee() const {
data: Payees,
isLoading: isPayeeLoaing,
isError: isPayeeError,
error: payeeError,
} = usePayee();
const schema = PaymentRequestSchema(ExpenseCategories); const schema = PaymentRequestSchema(ExpenseCategories);
const { const {
register, register,
@ -113,7 +118,6 @@ function ManagePaymentRequest({ closeModal, requestToEdit = null }) {
reader.onerror = (error) => reject(error); reader.onerror = (error) => reject(error);
}); });
const removeFile = (index) => { const removeFile = (index) => {
debugger
if (requestToEdit) { if (requestToEdit) {
const newFiles = files.map((file, i) => { const newFiles = files.map((file, i) => {
if (file.documentId !== index) return file; if (file.documentId !== index) return file;
@ -183,7 +187,7 @@ function ManagePaymentRequest({ closeModal, requestToEdit = null }) {
let payload = { let payload = {
...fromdata, ...fromdata,
dueDate: localToUtc(fromdata.dueDate), dueDate: localToUtc(fromdata.dueDate),
payee: isItself ? profile?.employeeInfo?.id : fromdata.payee, payee: isItself ? `${profile?.employeeInfo?.firstName} ${profile?.employeeInfo?.lastName}` : fromdata.payee,
}; };
if (requestToEdit) { if (requestToEdit) {
const editPayload = { const editPayload = {
@ -198,7 +202,12 @@ function ManagePaymentRequest({ closeModal, requestToEdit = null }) {
}; };
const handleSetItSelf = (e) => { const handleSetItSelf = (e) => {
setisItself(e.target.value); setisItself(e.target.value);
setValue("payee", `${profile?.employeeInfo.firstName} ${profile?.employeeInfo.lastName}`); let name = `${profile?.employeeInfo.firstName} ${profile?.employeeInfo.lastName}`
setValue(
"payee",
name
);
}; };
return ( return (
@ -280,26 +289,53 @@ function ManagePaymentRequest({ closeModal, requestToEdit = null }) {
)} )}
</div> </div>
<div className="col-md-6"> <div className="col-md-6 ">
<Label htmlFor="isAdvancePayment" className="form-label" required> <Label htmlFor="isAdvance" className="form-label">
Advance Payment Is Advance Payment
</Label> </Label>
<select
<Controller
name="isAdvancePayment"
control={control}
defaultValue={defaultPaymentRequest.isAdvancePayment ?? false}
render={({ field }) => (
<div className="d-flex align-items-center gap-3">
<div className="form-check d-flex flex-row m-0 gap-2">
<input
type="radio"
id="isAdvancePayment" id="isAdvancePayment"
className="form-select form-select-sm" className="form-check-input m-0"
{...register("isAdvancePayment", { // mark checked when the controlled value is true
setValueAs: (v) => checked={field.value === true}
v === "true" ? true : v === "false" ? false : undefined, onChange={() => field.onChange(true)} // send boolean true
})} />
<Label
className="form-check-label"
> >
<option value="">Select Option</option> Yes
<option value="true">True</option> </Label>
<option value="false">False</option> </div>
</select>
{errors.isAdvancePayment && ( <div className="form-check d-flex flex-row m-0 gap-2">
<small className="danger-text"> <input
{errors.isAdvancePayment.message} type="radio"
</small> id="isVariableFalse"
className="form-check-input m-0"
checked={field.value === false}
onChange={() => field.onChange(false)} // send boolean false
/>
<Label
className="form-check-label"
>
No
</Label>
</div>
</div>
)}
/>
{errors.isVariable && (
<small className="danger-text">{errors.isVariable.message}</small>
)} )}
</div> </div>
</div> </div>
@ -425,9 +461,7 @@ function ManagePaymentRequest({ closeModal, requestToEdit = null }) {
{/* Upload Document */} {/* Upload Document */}
<div className="row my-2 text-start"> <div className="row my-2 text-start">
<div className="col-md-12"> <div className="col-md-12">
<Label className="form-label"> <Label className="form-label">Upload Bill </Label>
Upload Bill{" "}
</Label>
<div <div
className="border border-secondary border-dashed rounded p-4 text-center bg-textMuted position-relative" className="border border-secondary border-dashed rounded p-4 text-center bg-textMuted position-relative"

View File

@ -18,7 +18,7 @@ export const PaymentRequestSchema = (expenseTypes, isItself) => {
dueDate: z.string().min(1, { message: "Date is required" }), dueDate: z.string().min(1, { message: "Date is required" }),
description: z.string().min(1, { message: "Description is required" }), description: z.string().min(1, { message: "Description is required" }),
payee: z.string().min(1, { message: "Supplier name is required" }), payee: z.string().min(1, { message: "Supplier name is required" }),
isAdvancePayment: z.boolean().optional(), isAdvancePayment: z.boolean().optional().default(false),
amount: z.coerce amount: z.coerce
.number({ .number({
invalid_type_error: "Amount is required and must be a number", invalid_type_error: "Amount is required and must be a number",
@ -56,7 +56,7 @@ export const defaultPaymentRequest = {
dueDate: "", dueDate: "",
projectId: "", projectId: "",
expenseCategoryId: "", expenseCategoryId: "",
isAdvancePayment: boolean, isAdvancePayment: false,
billAttachments: [], billAttachments: [],
}; };

View File

@ -52,7 +52,7 @@ const Avatar = ({ firstName, lastName, size = "sm", classAvatar }) => {
return ( return (
<div className="avatar-wrapper p-1"> <div className="avatar-wrapper p-1">
<div className={`avatar avatar-${size} me-2 ${classAvatar}`}> <div className={`avatar avatar-${size} me-2 ${classAvatar}`}>
<span className={`avatar-initial rounded-circle ${bgClass}`}> <span className={`avatar-initial rounded-circle text-white ${bgClass}`}>
{generateAvatarText(firstName, lastName)} {generateAvatarText(firstName, lastName)}
</span> </span>
</div> </div>