changed employee api for manage expense
This commit is contained in:
parent
68bd0d6bb5
commit
96e4760345
@ -33,7 +33,7 @@ const ExpenseStatusLogs = ({ data }) => {
|
||||
<small className="text-secondary text-tiny ms-2">
|
||||
<em>{log.action}</em>
|
||||
</small>
|
||||
<span className="text-tiny text-secondary d-block small">{log?.updateAt ?? "14-Aug-2025"}</span>
|
||||
<span className="text-tiny text-secondary d-block small">{log?.updateAt}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="d-flex align-items-center text-muted small mt-1">
|
||||
|
||||
@ -14,6 +14,8 @@ import useMaster, {
|
||||
import {
|
||||
useEmployeesAllOrByProjectId,
|
||||
useEmployeesByProject,
|
||||
useEmployeesName,
|
||||
useEmployeesNameByProject,
|
||||
} from "../../hooks/useEmployees";
|
||||
import Avatar from "../common/Avatar";
|
||||
import {
|
||||
@ -24,6 +26,7 @@ import {
|
||||
import ExpenseSkeleton from "./ExpenseSkeleton";
|
||||
import moment from "moment";
|
||||
import DatePicker from "../common/DatePicker";
|
||||
import ErrorPage from "../../pages/ErrorPage";
|
||||
|
||||
const ManageExpense = ({ closeModal, expenseToEdit = null }) => {
|
||||
const {
|
||||
@ -31,6 +34,7 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => {
|
||||
isLoading,
|
||||
error: ExpenseErrorLoad,
|
||||
} = useExpense(expenseToEdit);
|
||||
console.log(data)
|
||||
const [ExpenseType, setExpenseType] = useState();
|
||||
const dispatch = useDispatch();
|
||||
const {
|
||||
@ -53,11 +57,14 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => {
|
||||
});
|
||||
|
||||
const selectedproject = watch("projectId");
|
||||
const selectedProject = useSelector(
|
||||
(store) => store.localVariables.projectId
|
||||
);
|
||||
const { projectNames, loading: projectLoading, error } = useProjectName();
|
||||
debugger
|
||||
|
||||
const {
|
||||
projectNames,
|
||||
loading: projectLoading,
|
||||
error,
|
||||
isError: isProjectError,
|
||||
} = useProjectName();
|
||||
|
||||
const {
|
||||
PaymentModes,
|
||||
loading: PaymentModeLoading,
|
||||
@ -69,11 +76,10 @@ debugger
|
||||
error: stausError,
|
||||
} = useExpenseStatus();
|
||||
const {
|
||||
employees,
|
||||
loading: EmpLoading,
|
||||
error: EmpError,
|
||||
} = useEmployeesByProject(selectedproject);
|
||||
|
||||
data: employees,
|
||||
isLoading: EmpLoading,
|
||||
isError: isEmployeeError,
|
||||
} = useEmployeesNameByProject(selectedproject);
|
||||
const files = watch("billAttachments");
|
||||
const onFileChange = async (e) => {
|
||||
const newFiles = Array.from(e.target.files);
|
||||
@ -90,7 +96,7 @@ debugger
|
||||
contentType: file.type,
|
||||
fileSize: file.size,
|
||||
description: "",
|
||||
isActive:true
|
||||
isActive: true,
|
||||
};
|
||||
})
|
||||
);
|
||||
@ -136,7 +142,8 @@ debugger
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (expenseToEdit && data && employees) {
|
||||
if (expenseToEdit && data ) {
|
||||
|
||||
reset({
|
||||
projectId: data.project.id || "",
|
||||
expensesTypeId: data.expensesType.id || "",
|
||||
@ -173,7 +180,12 @@ debugger
|
||||
}
|
||||
);
|
||||
const onSubmit = (fromdata) => {
|
||||
let payload = {...fromdata,transactionDate: moment.utc(fromdata.transactionDate, 'DD-MM-YYYY').toISOString()}
|
||||
let payload = {
|
||||
...fromdata,
|
||||
transactionDate: moment
|
||||
.utc(fromdata.transactionDate, "DD-MM-YYYY")
|
||||
.toISOString(),
|
||||
};
|
||||
if (expenseToEdit) {
|
||||
const editPayload = { ...payload, id: data.id };
|
||||
ExpenseUpdate({ id: data.id, payload: editPayload });
|
||||
@ -191,13 +203,10 @@ debugger
|
||||
reset();
|
||||
closeModal();
|
||||
};
|
||||
if (
|
||||
StatusLoadding ||
|
||||
projectLoading ||
|
||||
ExpenseLoading ||
|
||||
isLoading
|
||||
)
|
||||
if (StatusLoadding || projectLoading || ExpenseLoading || isLoading)
|
||||
return <ExpenseSkeleton />;
|
||||
|
||||
|
||||
return (
|
||||
<div className="container p-3">
|
||||
<h5 className="m-0">
|
||||
@ -206,9 +215,7 @@ debugger
|
||||
<form id="expenseForm" onSubmit={handleSubmit(onSubmit)}>
|
||||
<div className="row my-2">
|
||||
<div className="col-md-6">
|
||||
<label className="form-label">
|
||||
Select Project
|
||||
</label>
|
||||
<label className="form-label">Select Project</label>
|
||||
<select
|
||||
className="form-select form-select-sm"
|
||||
{...register("projectId")}
|
||||
@ -323,17 +330,7 @@ debugger
|
||||
<label htmlFor="transactionDate" className="form-label ">
|
||||
Transaction Date
|
||||
</label>
|
||||
{/* <input
|
||||
type="date"
|
||||
className="form-control form-control-sm"
|
||||
placeholder="YYYY-MM-DD"
|
||||
id="flatpickr-date"
|
||||
{...register("transactionDate")}
|
||||
/> */}
|
||||
<DatePicker
|
||||
name="transactionDate"
|
||||
control={control}
|
||||
/>
|
||||
<DatePicker name="transactionDate" control={control} />
|
||||
|
||||
{errors.transactionDate && (
|
||||
<small className="danger-text">
|
||||
@ -415,9 +412,7 @@ debugger
|
||||
|
||||
{ExpenseType?.noOfPersonsRequired && (
|
||||
<div className="col-md-6">
|
||||
<label >
|
||||
No. of Persons
|
||||
</label>
|
||||
<label>No. of Persons</label>
|
||||
<input
|
||||
type="number"
|
||||
id="noOfPersons"
|
||||
@ -435,7 +430,7 @@ debugger
|
||||
</div>
|
||||
|
||||
<div className="row my-2">
|
||||
<div className="col-md-12" >
|
||||
<div className="col-md-12">
|
||||
<label htmlFor="description">Description</label>
|
||||
<textarea
|
||||
id="description"
|
||||
@ -542,7 +537,11 @@ debugger
|
||||
className="btn btn-primary btn-sm mt-3"
|
||||
disabled={isPending || createPending}
|
||||
>
|
||||
{isPending || createPending ? "Please Wait..." : expenseToEdit ? "Update" : "Submit"}
|
||||
{isPending || createPending
|
||||
? "Please Wait..."
|
||||
: expenseToEdit
|
||||
? "Update"
|
||||
: "Submit"}
|
||||
</button>
|
||||
<button
|
||||
type="reset"
|
||||
|
||||
@ -251,7 +251,7 @@ const ViewExpense = ({ ExpenseId }) => {
|
||||
|
||||
{/* Row 6 */}
|
||||
{data.createdBy && (
|
||||
<div className="col-md-6 mb-3 text-start">
|
||||
<div className="col-md-6 text-start">
|
||||
<div className="d-flex align-items-center">
|
||||
<label
|
||||
className="form-label me-2 mb-0 fw-semibold"
|
||||
@ -353,41 +353,7 @@ const ViewExpense = ({ ExpenseId }) => {
|
||||
</div>
|
||||
)} */}
|
||||
</div>
|
||||
{data.expensesReimburse && (
|
||||
<div className="row text-start">
|
||||
<div className="col-md-6 ">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">
|
||||
Transaction ID :
|
||||
</label>
|
||||
{data.expensesReimburse.reimburseTransactionId || "N/A"}
|
||||
</div>
|
||||
<div className="col-md-6 ">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">
|
||||
Reimburse Date :
|
||||
</label>
|
||||
{formatUTCToLocalTime(data.expensesReimburse.reimburseDate)}
|
||||
</div>
|
||||
|
||||
{data.expensesReimburse && (
|
||||
<>
|
||||
<div className="col-md-6 d-flex align-items-center">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">
|
||||
Reimburse By :
|
||||
</label>
|
||||
<Avatar
|
||||
size="xs"
|
||||
classAvatar="m-0 me-1"
|
||||
firstName={data?.expensesReimburse?.reimburseBy?.firstName}
|
||||
lastName={data?.expensesReimburse?.reimburseBy?.lastName}
|
||||
/>
|
||||
<span className="text-muted">
|
||||
{`${data?.expensesReimburse?.reimburseBy?.firstName} ${data?.expensesReimburse?.reimburseBy?.lastName}`.trim()}
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* <div className="text-start">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">
|
||||
@ -395,7 +361,7 @@ const ViewExpense = ({ ExpenseId }) => {
|
||||
</label>
|
||||
<div className="text-muted">{data?.description}</div>
|
||||
</div> */}
|
||||
<div className="col-12 my-2 text-start">
|
||||
<div className="col-12 text-start">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">Attachment :</label>
|
||||
|
||||
{data?.documents?.map((doc) => {
|
||||
@ -456,6 +422,42 @@ const ViewExpense = ({ ExpenseId }) => {
|
||||
})}
|
||||
</div>
|
||||
|
||||
|
||||
{data.expensesReimburse && (
|
||||
<div className="row text-start">
|
||||
<div className="col-md-6 mb-sm-0 mb-2">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">
|
||||
Transaction ID :
|
||||
</label>
|
||||
{data.expensesReimburse.reimburseTransactionId || "N/A"}
|
||||
</div>
|
||||
<div className="col-md-6 ">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">
|
||||
Reimburse Date :
|
||||
</label>
|
||||
{formatUTCToLocalTime(data.expensesReimburse.reimburseDate)}
|
||||
</div>
|
||||
|
||||
{data.expensesReimburse && (
|
||||
<>
|
||||
<div className="col-md-6 d-flex align-items-center">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">
|
||||
Reimburse By :
|
||||
</label>
|
||||
<Avatar
|
||||
size="xs"
|
||||
classAvatar="m-0 me-1"
|
||||
firstName={data?.expensesReimburse?.reimburseBy?.firstName}
|
||||
lastName={data?.expensesReimburse?.reimburseBy?.lastName}
|
||||
/>
|
||||
<span className="text-muted">
|
||||
{`${data?.expensesReimburse?.reimburseBy?.firstName} ${data?.expensesReimburse?.reimburseBy?.lastName}`.trim()}
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<hr className="divider my-1" />
|
||||
|
||||
{Array.isArray(data?.nextStatus) && data.nextStatus.length > 0 && (
|
||||
|
||||
@ -174,6 +174,7 @@ export const useEmployeeProfile = (employeeId) => {
|
||||
};
|
||||
|
||||
export const useEmployeesName = (projectId, search) => {
|
||||
debugger
|
||||
return useQuery({
|
||||
queryKey: ["employees", projectId, search],
|
||||
queryFn: async() => await EmployeeRepository.getEmployeeName(projectId, search),
|
||||
@ -182,6 +183,19 @@ export const useEmployeesName = (projectId, search) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useEmployeesNameByProject = (projectId) => {
|
||||
return useQuery({
|
||||
queryKey: ["Projectemployees", projectId],
|
||||
queryFn: async () => {
|
||||
const response = await EmployeeRepository.getEmployeeName(projectId);
|
||||
return response?.data || []; // handle undefined/null response
|
||||
},
|
||||
enabled: !!projectId, // only fetch if projectId is truthy
|
||||
staleTime: 5 * 60 * 1000, // cache for 5 minutes
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// Mutation------------------------------------------------------------------
|
||||
|
||||
export const useUpdateEmployee = () => {
|
||||
|
||||
@ -313,6 +313,7 @@ export const useProjectName = () => {
|
||||
isLoading,
|
||||
error,
|
||||
refetch,
|
||||
isError
|
||||
} = useQuery({
|
||||
queryKey: ["basicProjectNameList"],
|
||||
queryFn: async () => {
|
||||
@ -323,7 +324,7 @@ export const useProjectName = () => {
|
||||
showToast(error.message || "Error while Fetching project Name", "error");
|
||||
},
|
||||
});
|
||||
return { projectNames: data, loading: isLoading, Error: error, refetch };
|
||||
return { projectNames: data, loading: isLoading, Error: error, refetch,isError };
|
||||
};
|
||||
|
||||
export const useProjectInfra = (projectId) => {
|
||||
|
||||
@ -11,12 +11,16 @@ const EmployeeRepository = {
|
||||
// deleteEmployee: ( id ) => api.delete( `/users/${ id }` ),
|
||||
getEmployeeProfile: (id) => api.get(`/api/employee/profile/get/${id}`),
|
||||
deleteEmployee: (id) => api.delete(`/api/employee/${id}`),
|
||||
getEmployeeName: (projectId, search) =>
|
||||
api.get(
|
||||
`/api/Employee/basic${projectId ? `?projectId=${projectId}` : ""}${
|
||||
search ? `${projectId ? "&" : "?"}searchString=${search}` : ""
|
||||
}`
|
||||
),
|
||||
getEmployeeName: (projectId, search) => {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (projectId) params.append("projectId", projectId);
|
||||
if (search) params.append("searchString", search);
|
||||
|
||||
const query = params.toString();
|
||||
return api.get(`/api/Employee/basic${query ? `?${query}` : ""}`);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export default EmployeeRepository;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user