added merged payment and delete
This commit is contained in:
parent
76d99d6a14
commit
aa2e732ff4
102
src/components/purchase/PurchaseActions.jsx
Normal file
102
src/components/purchase/PurchaseActions.jsx
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
export const getPurchaseActions = ({
|
||||||
|
item,
|
||||||
|
isActive,
|
||||||
|
canDelete,
|
||||||
|
canAddChallan,
|
||||||
|
setViewPurchase,
|
||||||
|
setManagePurchase,
|
||||||
|
setDeletingId,
|
||||||
|
setIsDeleteModalOpen,
|
||||||
|
setChallan,
|
||||||
|
setAddPayment,
|
||||||
|
}) => {
|
||||||
|
const actions = [];
|
||||||
|
|
||||||
|
// VIEW
|
||||||
|
actions.push({
|
||||||
|
key: "view",
|
||||||
|
label: "View",
|
||||||
|
icon: "bx bx-show",
|
||||||
|
show: true,
|
||||||
|
onClick: () =>
|
||||||
|
setViewPurchase({
|
||||||
|
isOpen: true,
|
||||||
|
purchaseId: item.id,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!isActive) {
|
||||||
|
// EDIT
|
||||||
|
actions.push({
|
||||||
|
key: "edit",
|
||||||
|
label: "Edit",
|
||||||
|
icon: "bx bx-edit",
|
||||||
|
show: true,
|
||||||
|
onClick: () =>
|
||||||
|
setManagePurchase({
|
||||||
|
isOpen: true,
|
||||||
|
purchaseId: item.id,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
// DELETE
|
||||||
|
actions.push({
|
||||||
|
key: "delete",
|
||||||
|
label: "Delete",
|
||||||
|
icon: "bx bx-trash",
|
||||||
|
show: canDelete,
|
||||||
|
onClick: () => {
|
||||||
|
setDeletingId(item.id);
|
||||||
|
setIsDeleteModalOpen(true);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// ADD CHALLAN
|
||||||
|
actions.push({
|
||||||
|
key: "challan",
|
||||||
|
label: "Add Delivery Challan",
|
||||||
|
icon: "bx bx-file bx-plus",
|
||||||
|
show: canAddChallan,
|
||||||
|
onClick: () =>
|
||||||
|
setChallan({
|
||||||
|
isOpen: true,
|
||||||
|
purchaseId: item.id,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
// ADD PAYMENT
|
||||||
|
actions.push({
|
||||||
|
key: "payment",
|
||||||
|
label: "Add Payment",
|
||||||
|
icon: "bx bx-wallet",
|
||||||
|
show: true,
|
||||||
|
onClick: () =>
|
||||||
|
setAddPayment({
|
||||||
|
isOpen: true,
|
||||||
|
purchaseId: item.id,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// RESTORE
|
||||||
|
actions.push({
|
||||||
|
key: "restore",
|
||||||
|
label: "Restore",
|
||||||
|
icon: "bx bx-undo",
|
||||||
|
show: true,
|
||||||
|
onClick: () => {
|
||||||
|
setDeletingId(item.id);
|
||||||
|
setIsDeleteModalOpen(true);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return actions.filter((a) => a.show);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const DropdownItem = ({ icon, label, onClick }) => (
|
||||||
|
<li>
|
||||||
|
<a className="dropdown-item cursor-pointer" onClick={onClick}>
|
||||||
|
<i className={`${icon} me-2`}></i> {label}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
@ -1,21 +1,33 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { useDeletePurchaseInvoice, usePurchasesList } from "../../hooks/usePurchase";
|
import {
|
||||||
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
useDeletePurchaseInvoice,
|
||||||
|
usePurchasesList,
|
||||||
|
} from "../../hooks/usePurchase";
|
||||||
|
import {
|
||||||
|
ADD_DELIVERY_CHALLAN,
|
||||||
|
DELETEPURCHASE_INVOICE,
|
||||||
|
ITEMS_PER_PAGE,
|
||||||
|
} from "../../utils/constants";
|
||||||
import Pagination from "../common/Pagination";
|
import Pagination from "../common/Pagination";
|
||||||
import { PurchaseColumn } from "./Purchasetable";
|
import { PurchaseColumn } from "./Purchasetable";
|
||||||
import { SpinnerLoader } from "../common/Loader";
|
import { SpinnerLoader } from "../common/Loader";
|
||||||
import { useDebounce } from "../../utils/appUtils";
|
import { useDebounce } from "../../utils/appUtils";
|
||||||
import { usePurchaseContext } from "../../pages/purchase/PurchasePage";
|
import { usePurchaseContext } from "../../pages/purchase/PurchasePage";
|
||||||
import ConfirmModal from "../common/ConfirmModal";
|
import ConfirmModal from "../common/ConfirmModal";
|
||||||
|
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||||
|
import { DropdownItem, getPurchaseActions } from "./PurchaseActions";
|
||||||
|
|
||||||
const PurchaseList = ({ searchString, isActive }) => {
|
const PurchaseList = ({ searchString, isActive }) => {
|
||||||
const { setViewPurchase, setManagePurchase, setChallan } =
|
const { setViewPurchase, setManagePurchase, setChallan, setAddPayment } =
|
||||||
usePurchaseContext();
|
usePurchaseContext();
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const { mutate: DeletePurchaseInvoice, isPending } = useDeletePurchaseInvoice();
|
const { mutate: DeletePurchaseInvoice, isPending } =
|
||||||
|
useDeletePurchaseInvoice();
|
||||||
const [IsDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
const [IsDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
||||||
const [deletingId, setDeletingId] = useState(null);
|
const [deletingId, setDeletingId] = useState(null);
|
||||||
|
|
||||||
|
const canAddChallan = useHasUserPermission(ADD_DELIVERY_CHALLAN);
|
||||||
|
const canDelete = useHasUserPermission(DELETEPURCHASE_INVOICE);
|
||||||
|
|
||||||
const debounceSearch = useDebounce(searchString, 300);
|
const debounceSearch = useDebounce(searchString, 300);
|
||||||
const { data, isLoading } = usePurchasesList(
|
const { data, isLoading } = usePurchasesList(
|
||||||
@ -47,7 +59,6 @@ const PurchaseList = ({ searchString, isActive }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{IsDeleteModalOpen && (
|
{IsDeleteModalOpen && (
|
||||||
@ -55,7 +66,11 @@ const PurchaseList = ({ searchString, isActive }) => {
|
|||||||
isOpen={IsDeleteModalOpen}
|
isOpen={IsDeleteModalOpen}
|
||||||
type={!isActive ? "delete" : "undo"}
|
type={!isActive ? "delete" : "undo"}
|
||||||
header={!isActive ? "Delete Invoice" : "Restore Invoice"}
|
header={!isActive ? "Delete Invoice" : "Restore Invoice"}
|
||||||
message={!isActive ? "Are you sure you want to delete?" : "Are you sure you want to restore?"}
|
message={
|
||||||
|
!isActive
|
||||||
|
? "Are you sure you want to delete?"
|
||||||
|
: "Are you sure you want to restore?"
|
||||||
|
}
|
||||||
onSubmit={handleDeleteRestore}
|
onSubmit={handleDeleteRestore}
|
||||||
onClose={() => setIsDeleteModalOpen(false)}
|
onClose={() => setIsDeleteModalOpen(false)}
|
||||||
loading={isPending}
|
loading={isPending}
|
||||||
@ -104,7 +119,6 @@ const PurchaseList = ({ searchString, isActive }) => {
|
|||||||
</tr>
|
</tr>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
||||||
{!isLoading &&
|
{!isLoading &&
|
||||||
data?.data?.map((item, index) => (
|
data?.data?.map((item, index) => (
|
||||||
<tr key={item?.id || index}>
|
<tr key={item?.id || index}>
|
||||||
@ -131,58 +145,25 @@ const PurchaseList = ({ searchString, isActive }) => {
|
|||||||
></i>
|
></i>
|
||||||
</button>
|
</button>
|
||||||
<ul className="dropdown-menu dropdown-menu-end">
|
<ul className="dropdown-menu dropdown-menu-end">
|
||||||
<li>
|
{getPurchaseActions({
|
||||||
<a
|
item,
|
||||||
className="dropdown-item cursor-pointer"
|
isActive,
|
||||||
onClick={() => setViewPurchase({ isOpen: true, purchaseId: item.id })}
|
canDelete,
|
||||||
>
|
canAddChallan,
|
||||||
<i className="bx bx-show me-2"></i> View
|
setViewPurchase,
|
||||||
</a>
|
setManagePurchase,
|
||||||
</li>
|
setDeletingId,
|
||||||
{!isActive ? (
|
setIsDeleteModalOpen,
|
||||||
<>
|
setChallan,
|
||||||
<li>
|
setAddPayment,
|
||||||
<a
|
}).map((action) => (
|
||||||
className="dropdown-item cursor-pointer"
|
<DropdownItem
|
||||||
onClick={() => setManagePurchase({ isOpen: true, purchaseId: item.id })}
|
key={action.key}
|
||||||
>
|
icon={action.icon}
|
||||||
<i className="bx bx-edit me-2"></i> Edit
|
label={action.label}
|
||||||
</a>
|
onClick={action.onClick}
|
||||||
</li>
|
/>
|
||||||
<li>
|
))}
|
||||||
<a
|
|
||||||
className="dropdown-item cursor-pointer"
|
|
||||||
onClick={() => {
|
|
||||||
setDeletingId(item.id);
|
|
||||||
setIsDeleteModalOpen(true);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<i className="bx bx-trash me-2"></i> Delete
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a
|
|
||||||
className="dropdown-item cursor-pointer"
|
|
||||||
onClick={() => setChallan({ isOpen: true, purchaseId: item.id })}
|
|
||||||
>
|
|
||||||
<i className="bx bx-file bx-plus me-2"></i> Add Delivery Challan
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<li>
|
|
||||||
<a
|
|
||||||
className="dropdown-item cursor-pointer"
|
|
||||||
onClick={() => {
|
|
||||||
setDeletingId(item.id);
|
|
||||||
setIsDeleteModalOpen(true);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<i className="bx bx-undo me-2"></i> Restore
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
)}
|
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@ -20,7 +20,7 @@ import { SpinnerLoader } from "../common/Loader";
|
|||||||
import { formatUTCToLocalTime } from "../../utils/dateUtils";
|
import { formatUTCToLocalTime } from "../../utils/dateUtils";
|
||||||
import Avatar from "../common/Avatar";
|
import Avatar from "../common/Avatar";
|
||||||
|
|
||||||
const PurchasePayment = ({ purchaseId }) => {
|
const PurchasePayment = ({onClose, purchaseId }) => {
|
||||||
const {
|
const {
|
||||||
data: Purchase,
|
data: Purchase,
|
||||||
isLoading: isPurchaseLoading,
|
isLoading: isPurchaseLoading,
|
||||||
|
|||||||
@ -131,6 +131,27 @@ export const useAddDeliverChallan = (onSuccessCallback) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
export const useAddPurchasePayment =(onSuccessCallback)=>{
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: async (payload) =>
|
||||||
|
PurchaseRepository.AddPayment(payload),
|
||||||
|
onSuccess: (data, variables) => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["purchase_payment_history"] });
|
||||||
|
showToast("Payment added successfully", "success");
|
||||||
|
if (onSuccessCallback) onSuccessCallback();
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast(
|
||||||
|
error?.response?.data?.message ||
|
||||||
|
error.message ||
|
||||||
|
"Failed to Add payment",
|
||||||
|
"error"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export const useDeletePurchaseInvoice = () => {
|
export const useDeletePurchaseInvoice = () => {
|
||||||
|
|||||||
@ -89,7 +89,7 @@ const PurchasePage = () => {
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<di className="col-sm-6 text-end">
|
<div className="col-sm-6 text-end">
|
||||||
{canCreatePurchase && (
|
{canCreatePurchase && (
|
||||||
<button
|
<button
|
||||||
className="btn btn-sm btn-primary"
|
className="btn btn-sm btn-primary"
|
||||||
@ -103,7 +103,7 @@ const PurchasePage = () => {
|
|||||||
<i className="bx bx-plus-circle me-2"></i>Add
|
<i className="bx bx-plus-circle me-2"></i>Add
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</di>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -164,7 +164,10 @@ const PurchasePage = () => {
|
|||||||
setAddPayment({ isOpen: false, purchaseId: null })
|
setAddPayment({ isOpen: false, purchaseId: null })
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<PurchasePayment purchaseId={addPayment.purchaseId} />
|
<PurchasePayment
|
||||||
|
onClose={() => setAddPayment({ isOpen: false, purchaseId: null })}
|
||||||
|
purchaseId={addPayment.purchaseId}
|
||||||
|
/>
|
||||||
</GlobalModel>
|
</GlobalModel>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -15,6 +15,9 @@ export const PurchaseRepository = {
|
|||||||
addDelievryChallan: (data) =>
|
addDelievryChallan: (data) =>
|
||||||
api.post(`/api/PurchaseInvoice/delivery-challan/create`, data),
|
api.post(`/api/PurchaseInvoice/delivery-challan/create`, data),
|
||||||
|
|
||||||
|
AddPayment: (data) => api.post(`/api/PurchaseInvoice/add/payment`, data),
|
||||||
|
GetPaymentHistory: (purchaseInvoiceId) =>
|
||||||
|
api.get(`/api/PurchaseInvoice/payment-history/list/${purchaseInvoiceId}`),
|
||||||
deletePurchase: (id, isActive = false) =>
|
deletePurchase: (id, isActive = false) =>
|
||||||
api.delete(`/api/PurchaseInvoice/delete/${id}?isActive=${isActive}`),
|
api.delete(`/api/PurchaseInvoice/delete/${id}?isActive=${isActive}`),
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user