added paymentadjustment head crud operation
This commit is contained in:
parent
51cca64dd5
commit
aa947b791b
@ -34,6 +34,8 @@ const Header = () => {
|
||||
const isDashboardPath =
|
||||
/^\/dashboard$/.test(location.pathname) || /^\/$/.test(location.pathname);
|
||||
const isProjectPath = /^\/projects$/.test(location.pathname);
|
||||
const isCollectionPath =
|
||||
/^\/collection$/.test(location.pathname) || /^\/$/.test(location.pathname);
|
||||
|
||||
const showProjectDropdown = (pathname) => {
|
||||
const isDirectoryPath = /^\/directory$/.test(pathname);
|
||||
@ -216,7 +218,7 @@ const Header = () => {
|
||||
className="dropdown-menu"
|
||||
style={{ overflow: "auto", maxHeight: "300px" }}
|
||||
>
|
||||
{isDashboardPath && (
|
||||
{(isDashboardPath|| isCollectionPath) &&(
|
||||
<li>
|
||||
<button
|
||||
className="dropdown-item"
|
||||
|
@ -11,7 +11,7 @@ import { formatFigure, localToUtc } from "../../utils/appUtils";
|
||||
import { formatUTCToLocalTime } from "../../utils/dateUtils";
|
||||
import Avatar from "../common/Avatar";
|
||||
import { PaymentHistorySkeleton } from "./CollectionSkeleton";
|
||||
import { usePaymentType } from "../../hooks/masterHook/useMaster";
|
||||
import { usePaymentAjustmentHead } from "../../hooks/masterHook/useMaster";
|
||||
|
||||
const AddPayment = ({ onClose }) => {
|
||||
const { addPayment } = useCollectionContext();
|
||||
@ -23,7 +23,7 @@ const AddPayment = ({ onClose }) => {
|
||||
isLoading: isPaymentTypeLoading,
|
||||
isError: isPaymentTypeError,
|
||||
error: paymentError,
|
||||
} = usePaymentType(true);
|
||||
} = usePaymentAjustmentHead(true);
|
||||
const methods = useForm({
|
||||
resolver: zodResolver(paymentSchema),
|
||||
defaultValues: defaultPayment,
|
||||
|
@ -6,9 +6,11 @@ import { formatUTCToLocalTime } from "../../utils/dateUtils";
|
||||
import Pagination from "../common/Pagination";
|
||||
import { useCollectionContext } from "../../pages/collections/CollectionPage";
|
||||
import { CollectionTableSkeleton } from "./CollectionSkeleton";
|
||||
import { useSelectedProject } from "../../slices/apiDataManager";
|
||||
|
||||
const CollectionList = ({ fromDate, toDate, isPending, searchString }) => {
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const selectedProject = useSelectedProject()
|
||||
const searchDebounce = useDebounce(searchString, 500);
|
||||
|
||||
const { data, isLoading, isError, error } = useCollections(
|
||||
@ -18,6 +20,7 @@ const CollectionList = ({ fromDate, toDate, isPending, searchString }) => {
|
||||
localToUtc(toDate),
|
||||
isPending,
|
||||
true,
|
||||
selectedProject,
|
||||
searchDebounce
|
||||
);
|
||||
const { setProcessedPayment, setAddPayment, setViewCollection } =
|
||||
|
@ -76,7 +76,7 @@ const Comment = ({ invoice }) => {
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
<p className="text-muted">No comments yet.</p>
|
||||
<div className="text-center py-2"> <p className="text-muted">No comments yet.</p></div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
@ -7,7 +7,7 @@ const PaymentHistoryTable = ({data}) => {
|
||||
return (
|
||||
<div>
|
||||
|
||||
{data?.receivedInvoicePayments?.length > 0 && (
|
||||
{data?.receivedInvoicePayments?.length > 0 ? (
|
||||
<div className="pt-1 data-tabe table-responsive">
|
||||
<table className="table table-bordered table-responsive mt-2">
|
||||
<thead className="table-light">
|
||||
@ -45,7 +45,7 @@ const PaymentHistoryTable = ({data}) => {
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
):(<div className='text-center py-2'><p>No History</p></div>)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
@ -16,10 +16,10 @@ import ManageDocumentCategory from "./ManageDocumentCategory";
|
||||
import ManageDocumentType from "./ManageDocumentType";
|
||||
import ManageServices from "./Services/ManageServices";
|
||||
import ServiceGroups from "./Services/ServicesGroups";
|
||||
import ManagePaymentHead from "./paymentAdjustmentHead/ManagePaymentHead";
|
||||
|
||||
const MasterModal = ({ modaldata, closeModal }) => {
|
||||
if (!modaldata?.modalType || modaldata.modalType === "delete") {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -58,21 +58,17 @@ const MasterModal = ({ modaldata, closeModal }) => {
|
||||
"Edit-Document Type": (
|
||||
<ManageDocumentType data={item} onClose={closeModal} />
|
||||
),
|
||||
"Services": (
|
||||
<ManageServices onClose={closeModal} />
|
||||
),
|
||||
"Edit-Services": (
|
||||
<ManageServices data={item} onClose={closeModal} />
|
||||
),
|
||||
"Manage-Services": (
|
||||
<ServiceGroups service={item} onClose={closeModal}/>
|
||||
),
|
||||
Services: <ManageServices onClose={closeModal} />,
|
||||
"Edit-Services": <ManageServices data={item} onClose={closeModal} />,
|
||||
"Manage-Services": <ServiceGroups service={item} onClose={closeModal} />,
|
||||
"Payment Adjustment Head": <ManagePaymentHead onClose={closeModal} />,
|
||||
"Edit-Payment Adjustment Head": <ManagePaymentHead data={item} onClose={closeModal} />
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="p-2 p-md-1">
|
||||
<div className="text-center">
|
||||
<p className="fs-5 fw-semibold" >{`${masterType, " ", modalType}`}</p>
|
||||
<p className="fs-5 fw-semibold">{`${(masterType, " ", modalType)}`}</p>
|
||||
</div>
|
||||
{modalComponents[modalType] || null}
|
||||
</div>
|
||||
|
@ -0,0 +1,107 @@
|
||||
import React, { useEffect } from "react";
|
||||
import { z } from "zod";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import Label from "../../common/Label";
|
||||
import { useCreatePaymentAjustmentHead, useUpdatePaymentAjustmentHead } from "../../../hooks/masterHook/useMaster";
|
||||
|
||||
export const simpleFormSchema = z.object({
|
||||
name: z.string().min(1, "Name is required"),
|
||||
description: z.string().min(1, "Description is required"),
|
||||
});
|
||||
|
||||
const ManagePaymentHead = ({ data, onClose }) => {
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
reset,
|
||||
formState: { errors },
|
||||
} = useForm({
|
||||
resolver: zodResolver(simpleFormSchema),
|
||||
defaultValues: {
|
||||
name: "",
|
||||
description: "",
|
||||
},
|
||||
});
|
||||
|
||||
const {mutate:CreateAjustmentHead,isPending} = useCreatePaymentAjustmentHead(()=>{
|
||||
handleClose?.()
|
||||
});
|
||||
const {mutate:UpdateAjustmentHead,isPending:isUpdating} = useUpdatePaymentAjustmentHead(()=>{
|
||||
handleClose?.()
|
||||
})
|
||||
const onSubmit = (formData) => {
|
||||
if(data){
|
||||
let id = data?.id;
|
||||
const payload = {
|
||||
...formData,
|
||||
id:id,
|
||||
}
|
||||
UpdateAjustmentHead({id:id,payload:payload})
|
||||
}else{
|
||||
let payload={
|
||||
...formData
|
||||
}
|
||||
CreateAjustmentHead(payload)
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
reset({
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
});
|
||||
}
|
||||
}, [data]);
|
||||
const handleClose = () => {
|
||||
reset();
|
||||
onClose();
|
||||
};
|
||||
return (
|
||||
<div className="row text-start">
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="p-4">
|
||||
<div className="mb-3">
|
||||
<Label htmlFor="name" required>
|
||||
Name
|
||||
</Label>
|
||||
<input
|
||||
type="text"
|
||||
{...register("name")}
|
||||
className={`form-control ${errors.name ? "is-invalid" : ""}`}
|
||||
/>
|
||||
{errors.name && (
|
||||
<div className="invalid-feedback">{errors.name.message}</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="mb-3">
|
||||
<Label htmlFor="description" required>
|
||||
Description
|
||||
</Label>
|
||||
<textarea
|
||||
{...register("description")}
|
||||
className={`form-control ${errors.description ? "is-invalid" : ""}`}
|
||||
/>
|
||||
{errors.description && (
|
||||
<div className="invalid-feedback">{errors.description.message}</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="d-flex flex-row justify-content-end gap-2">
|
||||
<button
|
||||
className="btn btn-sm btn-label-secondary"
|
||||
onClick={handleClose} disabled={isUpdating || isPending}
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button type="submit" className="btn btn-sm btn-primary" disabled={isUpdating || isPending}>
|
||||
{isPending || isUpdating ? "Please Wait" :data ? "Update":"Submit"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ManagePaymentHead;
|
@ -10,10 +10,10 @@ import {
|
||||
} from "@tanstack/react-query";
|
||||
import showToast from "../../services/toastService";
|
||||
|
||||
export const usePaymentType = (isActive) => {
|
||||
export const usePaymentAjustmentHead = (isActive) => {
|
||||
return useQuery({
|
||||
queryKey: ["paymentType",isActive],
|
||||
queryFn: async () => await MasterRespository.getPaymentType(isActive),
|
||||
queryFn: async () => await MasterRespository.getPaymentAdjustmentHead(isActive),
|
||||
|
||||
});
|
||||
};
|
||||
@ -303,6 +303,8 @@ const fetchMasterData = async (masterType) => {
|
||||
return (await MasterRespository.getDocumentTypes()).data;
|
||||
case "Document Category":
|
||||
return (await MasterRespository.getDocumentCategories()).data;
|
||||
case "Payment Adjustment Head":
|
||||
return (await MasterRespository.getPaymentAdjustmentHead(true)).data;
|
||||
case "Status":
|
||||
return [
|
||||
{
|
||||
@ -998,7 +1000,52 @@ export const useUpdateDocumentType = (onSuccessCallback) => {
|
||||
},
|
||||
});
|
||||
};
|
||||
// -Delete Master --------
|
||||
// ------------------------------x-x--------x-x------------------------------------
|
||||
|
||||
// ==============================Payment Adjustment Head =============================
|
||||
export const useCreatePaymentAjustmentHead = (onSuccessCallback) => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (payload) => {
|
||||
const resp = await MasterRespository.createPaymentAjustmentHead(payload);
|
||||
return resp.data;
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["masterData", "Payment Adjustment Head"],
|
||||
});
|
||||
showToast("Payment Ajustment Head successfully", "success");
|
||||
if (onSuccessCallback) onSuccessCallback(data);
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast(error.message || "Something went wrong", "error");
|
||||
},
|
||||
});
|
||||
};
|
||||
export const useUpdatePaymentAjustmentHead = (onSuccessCallback) => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ id, payload }) => {
|
||||
const resp = await MasterRespository.updatePaymentAjustmentHead(id, payload);
|
||||
return resp.data;
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["masterData", "Payment Adjustment Head"],
|
||||
});
|
||||
showToast("Payment Ajustment Head Updated successfully", "success");
|
||||
if (onSuccessCallback) onSuccessCallback(data);
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast(error.message || "Something went wrong", "error");
|
||||
},
|
||||
});
|
||||
};
|
||||
// ====================x=x====================x=x==================================
|
||||
|
||||
// --------Delete Master --------
|
||||
export const useDeleteMasterItem = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
|
@ -9,6 +9,7 @@ export const useCollections = (
|
||||
toDate,
|
||||
isPending,
|
||||
isActive,
|
||||
projectId,
|
||||
searchString
|
||||
) => {
|
||||
return useQuery({
|
||||
@ -20,6 +21,7 @@ export const useCollections = (
|
||||
toDate,
|
||||
isPending,
|
||||
isActive,
|
||||
projectId,
|
||||
searchString,
|
||||
],
|
||||
|
||||
@ -31,6 +33,7 @@ export const useCollections = (
|
||||
toDate,
|
||||
isPending,
|
||||
isActive,
|
||||
projectId,
|
||||
searchString
|
||||
);
|
||||
return response.data;
|
||||
|
@ -67,6 +67,7 @@ const CollectionPage = () => {
|
||||
const handleMarkedPayment = (payload) => {
|
||||
MarkedReceived(payload);
|
||||
};
|
||||
console.log(fromDate,toDate)
|
||||
return (
|
||||
<CollectionContext.Provider value={contextMassager}>
|
||||
<div className="container-fluid">
|
||||
|
@ -7,12 +7,13 @@ export const CollectionRepository = {
|
||||
updateCollection:(id,data)=>{
|
||||
api.put(`/api/Collection/invoice/edit/${id}`,data)
|
||||
},
|
||||
getCollections: (pageSize, pageNumber,fromDate,toDate, isPending,isActive, searchString) => {
|
||||
getCollections: (pageSize, pageNumber,fromDate,toDate, isPending,isActive,projectId, searchString) => {
|
||||
let url = `/api/Collection/invoice/list?pageSize=${pageSize}&pageNumber=${pageNumber}&isPending=${isPending}&isActive=${isActive}&searchString=${searchString}`;
|
||||
|
||||
const params = [];
|
||||
if (fromDate) params.push(`fromDate=${fromDate}`);
|
||||
if (toDate) params.push(`toDate=${toDate}`);
|
||||
if(projectId) params.push(`projectId=${projectId}`)
|
||||
|
||||
if (params.length > 0) {
|
||||
url += `&${params.join("&")}`;
|
||||
|
@ -58,6 +58,7 @@ export const MasterRespository = {
|
||||
"Document Type": (id) => api.delete(`/api/Master/document-type/delete/${id}`),
|
||||
"Document Category": (id) =>
|
||||
api.delete(`/api/Master/document-category/delete/${id}`),
|
||||
"Payment Adjustment Head":(id,isActive)=>api.delete(`/api/Master/payment-adjustment-head/delete/${id}`,(isActive=false)),
|
||||
|
||||
getWorkCategory: () => api.get(`/api/master/work-categories`),
|
||||
createWorkCategory: (data) => api.post(`/api/master/work-category`, data),
|
||||
@ -131,6 +132,8 @@ export const MasterRespository = {
|
||||
|
||||
getOrganizationType: () => api.get("/api/Master/organization-type/list"),
|
||||
|
||||
getPaymentType: (isActive) =>
|
||||
getPaymentAdjustmentHead: (isActive) =>
|
||||
api.get(`/api/Master/payment-adjustment-head/list?isActive=${isActive}`),
|
||||
createPaymentAjustmentHead:(data)=>api.post(`/api/Master/payment-adjustment-head`, data),
|
||||
updatePaymentAjustmentHead:(id,data)=>api.put(`/api/Master/payment-adjustment-head/edit/${id}`, data)
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user