Adding Purchase Order and Requisition Status in Masters.
This commit is contained in:
parent
a2f105dd41
commit
20b8d9ae01
@ -0,0 +1,97 @@
|
|||||||
|
import React, { useEffect } from "react";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import Label from "../../common/Label";
|
||||||
|
import { useCreatePurhaseOrderStatus, useUpdatePurchaseOrderStatus } from "../../../hooks/masterHook/useMaster";
|
||||||
|
|
||||||
|
const PurchaseOrderStatusSchema = z.object({
|
||||||
|
name: z.string().min(1, { message: "Name is required" }),
|
||||||
|
description: z.string().min(1, { message: "Description is required" }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const PurchaseOrderStatus = ({ data = null, onClose }) => {
|
||||||
|
const {
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
reset,
|
||||||
|
formState: { errors },
|
||||||
|
} = useForm({
|
||||||
|
resolver: zodResolver(PurchaseOrderStatusSchema),
|
||||||
|
defaultValues: { name: "", description: "" },
|
||||||
|
});
|
||||||
|
|
||||||
|
const { mutate: CreatePurchaseOrderStatus, isPending } = useCreatePurhaseOrderStatus(() =>
|
||||||
|
onClose?.()
|
||||||
|
);
|
||||||
|
const { mutate: UpdatePurchaseOrderStatus, isPending: Updating } = useUpdatePurchaseOrderStatus(() => onClose?.())
|
||||||
|
|
||||||
|
const onSubmit = (payload) => {
|
||||||
|
if (data) {
|
||||||
|
UpdatePurchaseOrderStatus({ id: data.id, payload: { ...payload, id: data.id } })
|
||||||
|
} else (
|
||||||
|
CreatePurchaseOrderStatus(payload)
|
||||||
|
)
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data) {
|
||||||
|
reset({
|
||||||
|
name: data.name ?? "",
|
||||||
|
description: data.description ?? ""
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [data])
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form className="row g-2" onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
<div className="col-12 col-md-12 text-start">
|
||||||
|
<Label className="form-label" required>Name</Label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
{...register("name")}
|
||||||
|
className={`form-control ${errors.name ? "is-invalids" : ""}`}
|
||||||
|
/>
|
||||||
|
{errors.name && <p className="danger-text">{errors.name.message}</p>}
|
||||||
|
</div>
|
||||||
|
<div className="col-12 col-md-12 text-start">
|
||||||
|
<Label className="form-label" htmlFor="description" required>
|
||||||
|
Description
|
||||||
|
</Label>
|
||||||
|
<textarea
|
||||||
|
rows="3"
|
||||||
|
{...register("description")}
|
||||||
|
className={`form-control ${errors.description ? "is-invalids" : ""}`}
|
||||||
|
></textarea>
|
||||||
|
|
||||||
|
{errors.description && (
|
||||||
|
<p className="danger-text">{errors.description.message}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="col-12 text-end">
|
||||||
|
<button
|
||||||
|
type="reset"
|
||||||
|
className="btn btn-sm btn-label-secondary me-3"
|
||||||
|
data-bs-dismiss="modal"
|
||||||
|
aria-label="Close"
|
||||||
|
disabled={isPending || Updating}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="btn btn-sm btn-primary"
|
||||||
|
disabled={isPending || Updating}
|
||||||
|
>
|
||||||
|
{isPending || Updating ? "Please Wait..." : Updating ? "Update" : "Submit"}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PurchaseOrderStatus;
|
||||||
@ -0,0 +1,99 @@
|
|||||||
|
import React, { useEffect } from "react";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
// import { useCreatePaymentMode, useUpdatePaymentMode } from "../../hooks/masterHook/useMaster";
|
||||||
|
// import Label from "../common/Label";
|
||||||
|
import Label from "../../common/Label";
|
||||||
|
import { useCreateRequisitionStatus, useUpdateRequisitionStatus } from "../../../hooks/masterHook/useMaster";
|
||||||
|
|
||||||
|
const RequisitionStatusSchema = z.object({
|
||||||
|
name: z.string().min(1, { message: "Name is required" }),
|
||||||
|
description: z.string().min(1, { message: "Description is required" }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const RequisitionStatus = ({ data = null, onClose }) => {
|
||||||
|
const {
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
reset,
|
||||||
|
formState: { errors },
|
||||||
|
} = useForm({
|
||||||
|
resolver: zodResolver(RequisitionStatusSchema),
|
||||||
|
defaultValues: { name: "", description: "" },
|
||||||
|
});
|
||||||
|
|
||||||
|
const { mutate: CreateRequisitionStatus, isPending } = useCreateRequisitionStatus(() =>
|
||||||
|
onClose?.()
|
||||||
|
);
|
||||||
|
const { mutate: UpdateRequisitionStatus, isPending: Updating } = useUpdateRequisitionStatus(() => onClose?.())
|
||||||
|
|
||||||
|
const onSubmit = (payload) => {
|
||||||
|
if (data) {
|
||||||
|
UpdateRequisitionStatus({ id: data.id, payload: { ...payload, id: data.id } })
|
||||||
|
} else (
|
||||||
|
CreateRequisitionStatus(payload)
|
||||||
|
)
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data) {
|
||||||
|
reset({
|
||||||
|
name: data.name ?? "",
|
||||||
|
description: data.description ?? ""
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [data])
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form className="row g-2" onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
<div className="col-12 col-md-12 text-start">
|
||||||
|
<Label className="form-label" required>Name</Label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
{...register("name")}
|
||||||
|
className={`form-control ${errors.name ? "is-invalids" : ""}`}
|
||||||
|
/>
|
||||||
|
{errors.name && <p className="danger-text">{errors.name.message}</p>}
|
||||||
|
</div>
|
||||||
|
<div className="col-12 col-md-12 text-start">
|
||||||
|
<Label className="form-label" htmlFor="description" required>
|
||||||
|
Description
|
||||||
|
</Label>
|
||||||
|
<textarea
|
||||||
|
rows="3"
|
||||||
|
{...register("description")}
|
||||||
|
className={`form-control ${errors.description ? "is-invalids" : ""}`}
|
||||||
|
></textarea>
|
||||||
|
|
||||||
|
{errors.description && (
|
||||||
|
<p className="danger-text">{errors.description.message}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="col-12 text-end">
|
||||||
|
<button
|
||||||
|
type="reset"
|
||||||
|
className="btn btn-sm btn-label-secondary me-3"
|
||||||
|
data-bs-dismiss="modal"
|
||||||
|
aria-label="Close"
|
||||||
|
disabled={isPending || Updating}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="btn btn-sm btn-primary"
|
||||||
|
disabled={isPending || Updating}
|
||||||
|
>
|
||||||
|
{isPending || Updating ? "Please Wait..." : Updating ? "Update" : "Submit"}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RequisitionStatus;
|
||||||
@ -17,6 +17,8 @@ import ManageDocumentType from "./ManageDocumentType";
|
|||||||
import ManageServices from "./Services/ManageServices";
|
import ManageServices from "./Services/ManageServices";
|
||||||
import ServiceGroups from "./Services/ServicesGroups";
|
import ServiceGroups from "./Services/ServicesGroups";
|
||||||
import ManagePaymentHead from "./paymentAdjustmentHead/ManagePaymentHead";
|
import ManagePaymentHead from "./paymentAdjustmentHead/ManagePaymentHead";
|
||||||
|
import RequisitionStatus from "./InventoryManagement/RequisitionStatus";
|
||||||
|
import PurchaseOrderStatus from "./InventoryManagement/PurchaseOrderStatus";
|
||||||
|
|
||||||
const MasterModal = ({ modaldata, closeModal }) => {
|
const MasterModal = ({ modaldata, closeModal }) => {
|
||||||
if (!modaldata?.modalType || modaldata.modalType === "delete") {
|
if (!modaldata?.modalType || modaldata.modalType === "delete") {
|
||||||
@ -62,7 +64,16 @@ const MasterModal = ({ modaldata, closeModal }) => {
|
|||||||
"Edit-Services": <ManageServices data={item} onClose={closeModal} />,
|
"Edit-Services": <ManageServices data={item} onClose={closeModal} />,
|
||||||
"Manage-Services": <ServiceGroups service={item} onClose={closeModal} />,
|
"Manage-Services": <ServiceGroups service={item} onClose={closeModal} />,
|
||||||
"Payment Adjustment Head": <ManagePaymentHead onClose={closeModal} />,
|
"Payment Adjustment Head": <ManagePaymentHead onClose={closeModal} />,
|
||||||
"Edit-Payment Adjustment Head": <ManagePaymentHead data={item} onClose={closeModal} />
|
"Edit-Payment Adjustment Head": <ManagePaymentHead data={item} onClose={closeModal} />,
|
||||||
|
|
||||||
|
"Requisition Status": <RequisitionStatus onClose={closeModal} />,
|
||||||
|
"Edit-Requisition Status": (
|
||||||
|
<RequisitionStatus data={item} onClose={closeModal} />
|
||||||
|
),
|
||||||
|
"Purchase Order Status": <PurchaseOrderStatus onClose={closeModal} />,
|
||||||
|
"Edit-Purchase Order Status": (
|
||||||
|
<PurchaseOrderStatus data={item} onClose={closeModal} />
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -25,6 +25,20 @@ export const useServices = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const useRequisitionStatus = (isActive) => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["requisitionStatus",isActive],
|
||||||
|
queryFn: async () => await MasterRespository.getRequisitionStatus(isActive),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
export const usePurchaseOrderStatus = (isActive) => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["purchaseOrderStatus",isActive],
|
||||||
|
queryFn: async () => await MasterRespository.getPurchaseOrderStatus(isActive),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const useGroups = (serviceId) => {
|
export const useGroups = (serviceId) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["groups", serviceId],
|
queryKey: ["groups", serviceId],
|
||||||
@ -305,6 +319,10 @@ const fetchMasterData = async (masterType) => {
|
|||||||
return (await MasterRespository.getDocumentCategories()).data;
|
return (await MasterRespository.getDocumentCategories()).data;
|
||||||
case "Payment Adjustment Head":
|
case "Payment Adjustment Head":
|
||||||
return (await MasterRespository.getPaymentAdjustmentHead(true)).data;
|
return (await MasterRespository.getPaymentAdjustmentHead(true)).data;
|
||||||
|
case "Requisition Status":
|
||||||
|
return (await MasterRespository.getRequisitionStatus()).data;
|
||||||
|
case "Purchase Order Status":
|
||||||
|
return (await MasterRespository.getPurchaseOrderStatus()).data;
|
||||||
case "Status":
|
case "Status":
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@ -1043,6 +1061,93 @@ export const useUpdatePaymentAjustmentHead = (onSuccessCallback) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ============================== Requisition-Status =============================
|
||||||
|
|
||||||
|
export const useCreateRequisitionStatus = (onSuccessCallback) => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: async (payload) => {
|
||||||
|
const resp = await MasterRespository.createRequisitionStatus(payload);
|
||||||
|
return resp.data;
|
||||||
|
},
|
||||||
|
onSuccess: (data) => {
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ["masterData", "Requisition Status"],
|
||||||
|
});
|
||||||
|
showToast("Requisition Status successfully", "success");
|
||||||
|
if (onSuccessCallback) onSuccessCallback(data);
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast(error.message || "Something went wrong", "error");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
export const useUpdateRequisitionStatus = (onSuccessCallback) => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: async ({ id, payload }) => {
|
||||||
|
const resp = await MasterRespository.updateRequisitionStatus(id, payload);
|
||||||
|
return resp.data;
|
||||||
|
},
|
||||||
|
onSuccess: (data) => {
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ["masterData", "Requisition Status"],
|
||||||
|
});
|
||||||
|
showToast("Requisition Status Updated successfully", "success");
|
||||||
|
if (onSuccessCallback) onSuccessCallback(data);
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast(error.message || "Something went wrong", "error");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// ============================== Purchase Order Status =============================
|
||||||
|
|
||||||
|
export const useCreatePurhaseOrderStatus = (onSuccessCallback) => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: async (payload) => {
|
||||||
|
const resp = await MasterRespository.createPurchaseOrderStatus(payload);
|
||||||
|
return resp.data;
|
||||||
|
},
|
||||||
|
onSuccess: (data) => {
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ["masterData", "Purchase Order Status"],
|
||||||
|
});
|
||||||
|
showToast("Purchase Order Status successfully", "success");
|
||||||
|
if (onSuccessCallback) onSuccessCallback(data);
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast(error.message || "Something went wrong", "error");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
export const useUpdatePurchaseOrderStatus = (onSuccessCallback) => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: async ({ id, payload }) => {
|
||||||
|
const resp = await MasterRespository.updatePurchaseOrderStatus(id, payload);
|
||||||
|
return resp.data;
|
||||||
|
},
|
||||||
|
onSuccess: (data) => {
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ["masterData", "Purchase Order Status"],
|
||||||
|
});
|
||||||
|
showToast("Purchase Order Status Updated successfully", "success");
|
||||||
|
if (onSuccessCallback) onSuccessCallback(data);
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast(error.message || "Something went wrong", "error");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// ====================x=x====================x=x==================================
|
// ====================x=x====================x=x==================================
|
||||||
|
|
||||||
// --------Delete Master --------
|
// --------Delete Master --------
|
||||||
|
|||||||
@ -60,6 +60,12 @@ export const MasterRespository = {
|
|||||||
api.delete(`/api/Master/document-category/delete/${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)),
|
"Payment Adjustment Head": (id, isActive) => api.delete(`/api/Master/payment-adjustment-head/delete/${id}`, (isActive = false)),
|
||||||
|
|
||||||
|
"Requisition Status": (id, isActive = false) =>
|
||||||
|
api.delete(`/api/master/requisition-status/delete/${id}?isActive=${isActive}`),
|
||||||
|
"Purchase Order Status": (id, isActive = false) =>
|
||||||
|
api.delete(`/api/master/purchase-order-status/delete/${id}?isActive=${isActive}`),
|
||||||
|
|
||||||
|
|
||||||
getWorkCategory: () => api.get(`/api/master/work-categories`),
|
getWorkCategory: () => api.get(`/api/master/work-categories`),
|
||||||
createWorkCategory: (data) => api.post(`/api/master/work-category`, data),
|
createWorkCategory: (data) => api.post(`/api/master/work-category`, data),
|
||||||
updateWorkCategory: (id, data) =>
|
updateWorkCategory: (id, data) =>
|
||||||
@ -95,8 +101,7 @@ export const MasterRespository = {
|
|||||||
|
|
||||||
getDocumentCategories: (entityType) =>
|
getDocumentCategories: (entityType) =>
|
||||||
api.get(
|
api.get(
|
||||||
`/api/Master/document-category/list${
|
`/api/Master/document-category/list${entityType ? `?entityTypeId=${entityType}` : ""
|
||||||
entityType ? `?entityTypeId=${entityType}` : ""
|
|
||||||
}`
|
}`
|
||||||
),
|
),
|
||||||
createDocumenyCategory: (data) =>
|
createDocumenyCategory: (data) =>
|
||||||
@ -106,8 +111,7 @@ export const MasterRespository = {
|
|||||||
|
|
||||||
getDocumentTypes: (category) =>
|
getDocumentTypes: (category) =>
|
||||||
api.get(
|
api.get(
|
||||||
`/api/Master/document-type/list${
|
`/api/Master/document-type/list${category ? `?documentCategoryId=${category}` : ""
|
||||||
category ? `?documentCategoryId=${category}` : ""
|
|
||||||
}`
|
}`
|
||||||
),
|
),
|
||||||
|
|
||||||
@ -135,5 +139,20 @@ export const MasterRespository = {
|
|||||||
getPaymentAdjustmentHead: (isActive) =>
|
getPaymentAdjustmentHead: (isActive) =>
|
||||||
api.get(`/api/Master/payment-adjustment-head/list?isActive=${isActive}`),
|
api.get(`/api/Master/payment-adjustment-head/list?isActive=${isActive}`),
|
||||||
createPaymentAjustmentHead: (data) => api.post(`/api/Master/payment-adjustment-head`, data),
|
createPaymentAjustmentHead: (data) => api.post(`/api/Master/payment-adjustment-head`, data),
|
||||||
updatePaymentAjustmentHead:(id,data)=>api.put(`/api/Master/payment-adjustment-head/edit/${id}`, data)
|
updatePaymentAjustmentHead: (id, data) => api.put(`/api/Master/payment-adjustment-head/edit/${id}`, data),
|
||||||
|
|
||||||
|
getRequisitionStatus: (isActive = true) =>
|
||||||
|
api.get(`/api/master/requisition-status/list?isActive=${isActive}`),
|
||||||
|
createRequisitionStatus: (data) => api.post(`/api/master/requisition-status/create`, data),
|
||||||
|
updateRequisitionStatus: (id, data) => api.put(`/api/master/requisition-status/edit/${id}`, data),
|
||||||
|
|
||||||
|
|
||||||
|
getPurchaseOrderStatus: (isActive = true) =>
|
||||||
|
api.get(`/api/master/purchase-order-status/list?isActive=${isActive}`),
|
||||||
|
createPurchaseOrderStatus: (data) => api.post(`/api/master/purchase-order-status/create`, data),
|
||||||
|
updatePurchaseOrderStatus: (id, data) => api.put(`/api/master/purchase-order-status/edit/${id}`, data),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user