diff --git a/src/Router/all_routes.jsx b/src/Router/all_routes.jsx index 6657f59..37bb440 100644 --- a/src/Router/all_routes.jsx +++ b/src/Router/all_routes.jsx @@ -155,6 +155,7 @@ export const all_routes = { taxreport: "/tax-report", profitloss: "/profit-loss-report", notes: "/notes", + outletlist: "/outlet-list", filemanager: "/file-manager", profile: "/profile", signin: "/signin", diff --git a/src/Router/router.link.jsx b/src/Router/router.link.jsx index bd08b5e..32e3d31 100644 --- a/src/Router/router.link.jsx +++ b/src/Router/router.link.jsx @@ -206,6 +206,7 @@ import ProductList3 from "../feature-module/inventory/productlist3"; import { all_routes } from "./all_routes"; import PaymentMethodList from "../feature-module/FinanceAccounts/paymentmethodlist"; import CompanyList from "../feature-module/superadmin/companylist"; +import OutletList from "../feature-module/inventory/outletlist"; export const publicRoutes = [ { @@ -1499,13 +1500,20 @@ export const publicRoutes = [ route: Route, }, { - id: 1, + id: 121, path: routes.companylist, name: "companies", element: , route: Route, role: 'superadmin' - } + }, + { + id: 122, + path: routes.outletlist, + name: "outlets", + element: , + route: Route + }, ]; export const posRoutes = [ diff --git a/src/components/CustomPagination.jsx b/src/components/CustomPagination.jsx index 48a5ad2..ef92f1c 100644 --- a/src/components/CustomPagination.jsx +++ b/src/components/CustomPagination.jsx @@ -10,7 +10,6 @@ import { useSelector } from "react-redux"; const CustomPagination = ({ currentPage = 1, pageSize = 10, - totalCount = 0, totalPages = 1, loading = false, onPageChange, @@ -70,8 +69,6 @@ const CustomPagination = ({ }; }, []); - console.log(totalCount); - // Handle page change const handlePageClick = (page) => { if (!loading && page !== currentPage && onPageChange) { diff --git a/src/core/json/siderbar_data.jsx b/src/core/json/siderbar_data.jsx index 945305e..5271045 100644 --- a/src/core/json/siderbar_data.jsx +++ b/src/core/json/siderbar_data.jsx @@ -145,6 +145,13 @@ export const SidebarData = [ showSubRoute: false, submenu: false, }, + { + label: "Outlets", + link: "/outlet-list", + icon: , + showSubRoute: false, + submenu: false, + }, { label: "Warranty", link: "/warranty", diff --git a/src/core/modals/financeaccount/addpaymentmethod.jsx b/src/core/modals/financeaccount/addpaymentmethod.jsx new file mode 100644 index 0000000..8c83558 --- /dev/null +++ b/src/core/modals/financeaccount/addpaymentmethod.jsx @@ -0,0 +1,211 @@ +import { useState } from "react"; +import { useDispatch, useSelector } from "react-redux"; +import Swal from "sweetalert2"; +import { + createPaymentMethod, + fetchPaymentMethods, +} from "../../redux/actions/paymentMethodActions"; +import Select from "react-select"; + +const AddPaymentMethod = () => { + const dispatch = useDispatch(); + const { creating } = useSelector((state) => state.paymentMethods); + + const [formData, setFormData] = useState({ + name: "", + is_active: false, + requires_receipt: false, + type: "", + }); + + const handleInputChange = (e) => { + setFormData({ + ...formData, + [e.target.name]: e.target.value, + }); + }; + + const handleCheckboxChange = (e) => { + setFormData((prevData) => ({ + ...prevData, + [e.target.name]: e.target.checked, + })); + }; + + const handleSelectChange = (field, selectedOption) => { + setFormData((prevData) => ({ + ...prevData, + [field]: selectedOption.value, + })); + }; + + const handleSubmit = async (e) => { + e.preventDefault(); + + try { + await dispatch(createPaymentMethod(formData)); + + await dispatch(fetchPaymentMethods()); + + Swal.fire({ + title: "Success!", + text: "Payment Method created successfully!", + icon: "success", + showConfirmButton: false, + timer: 1500, + }).then(() => { + const closeButton = document.querySelector( + "#add-payment-method .btn-close" + ); + closeButton.click(); + }); + } catch (error) { + console.error("Error creating Payment Method:", error); + + // Show error message + Swal.fire({ + icon: "error", + title: "Error!", + text: + error?.response?.data?.errors[0]?.cause || + "Failed to create Payment Method. Please try again.", + }); + } + }; + + const typeOptions = [ + { + label: "Card", + value: "card", + }, + { + label: "Cash", + value: "cash", + }, + { + label: "Digital Wallet", + value: "digital_wallet", + }, + ]; + + return ( +
+ {/* Add Payment Method */} +
+
+
+
+
+
+
+

Create Payment Method

+
+ +
+
+
+
+ + +
+
+ + + +
+
+
+
+ Require Receipt + +
+
+
+ + +
+ +
+
+
+
+
+
+ {/* /Add Category */} + + ); +}; + +export default AddPaymentMethod; diff --git a/src/core/modals/financeaccount/editpaymentmethod.jsx b/src/core/modals/financeaccount/editpaymentmethod.jsx new file mode 100644 index 0000000..2ceee43 --- /dev/null +++ b/src/core/modals/financeaccount/editpaymentmethod.jsx @@ -0,0 +1,222 @@ +import { useEffect, useState } from "react"; +import { useDispatch, useSelector } from "react-redux"; +import Select from "react-select"; +import Swal from "sweetalert2"; +import { + fetchPaymentMethods, + updatePaymentMethod, +} from "../../redux/actions/paymentMethodActions"; + +const EditPaymentMethod = () => { + const dispatch = useDispatch(); + const { updating, currentPaymentMethod, currentPage, pageSize } = useSelector( + (state) => state.paymentMethods + ); + + const [formData, setFormData] = useState({ + name: "", + is_active: false, + requires_receipt: false, + type: "", + }); + + useEffect(() => { + if (currentPaymentMethod) { + setFormData(currentPaymentMethod); + } + }, [currentPaymentMethod]); + + const handleInputChange = (e) => { + setFormData({ + ...formData, + [e.target.name]: e.target.value, + }); + }; + + const handleCheckboxChange = (e) => { + setFormData((prevData) => ({ + ...prevData, + [e.target.name]: e.target.checked, + })); + }; + + const handleSelectChange = (field, selectedOption) => { + setFormData((prevData) => ({ + ...prevData, + [field]: selectedOption.value, + })); + }; + + const handleSubmit = async (e) => { + e.preventDefault(); + + try { + await dispatch(updatePaymentMethod(currentPaymentMethod?.id, formData)); + + await dispatch( + fetchPaymentMethods({ page: currentPage, limit: pageSize }) + ); + + Swal.fire({ + title: "Success!", + text: "Payment Method Updated successfully!", + icon: "success", + showConfirmButton: false, + timer: 1500, + }).then(() => { + const closeButton = document.querySelector( + "#edit-payment-method .btn-close" + ); + closeButton.click(); + }); + } catch (error) { + console.error("Error updating Payment Method:", error); + + // Show error message + Swal.fire({ + icon: "error", + title: "Error!", + text: + error?.response?.data?.errors[0]?.cause || + "Failed to Update Payment Method. Please try again.", + }); + } + }; + + const typeOptions = [ + { + label: "Card", + value: "card", + }, + { + label: "Cash", + value: "cash", + }, + { + label: "Digital Wallet", + value: "digital_wallet", + }, + ]; + + return ( +
+ {/* Edit Payment Method */} +
+
+
+
+
+
+
+

Edit Payment Method

+
+ +
+
+
+
+ + +
+
+ + + +
+
+
+
+ Require Receipt + +
+
+
+ + +
+ +
+
+
+
+
+
+ {/* /Add Category */} + + ); +}; + +export default EditPaymentMethod; diff --git a/src/core/modals/inventory/editoutletlist.jsx b/src/core/modals/inventory/editoutletlist.jsx new file mode 100644 index 0000000..28c2b2d --- /dev/null +++ b/src/core/modals/inventory/editoutletlist.jsx @@ -0,0 +1,186 @@ +import { useEffect, useState } from "react"; +import { useDispatch, useSelector } from "react-redux"; +import Swal from "sweetalert2"; +import { fetchOutlets, updateOutlet } from "../../redux/actions/outletActions"; + +const EditOutletList = () => { + const dispatch = useDispatch(); + + const { currentOutlet, updating, currentPage, pageSize } = useSelector( + (state) => state.outlets + ); + + const [formData, setFormData] = useState({ + name: "", + address: "", + phone_number: "", + email: "", + is_active: "", + }); + + useEffect(() => { + if (currentOutlet) { + setFormData(currentOutlet); + } + }, [currentOutlet]); + + const handleInputChange = (e) => { + setFormData({ + ...formData, + [e.target.name]: e.target.value, + }); + }; + + const handleCheckboxChange = (e) => { + setFormData((prevData) => ({ + ...prevData, + [e.target.name]: e.target.checked, + })); + }; + + const handleSubmit = async (e) => { + e.preventDefault(); + + try { + await dispatch(updateOutlet(currentOutlet?.id, formData)); + + await dispatch(fetchOutlets({ page: currentPage, limit: pageSize })); + + Swal.fire({ + title: "Success!", + text: "Outlet updated successfully!", + icon: "success", + showConfirmButton: false, + timer: 1500, + }).then(() => { + const closeButton = document.querySelector("#edit-outlet .btn-close"); + closeButton.click(); + }); + } catch (error) { + console.error("Error updating outlet:", error); + + // Show error message + Swal.fire({ + icon: "error", + title: "Error!", + text: error?.response?.data?.errors[0]?.cause || "Failed to update outlet. Please try again.", + }); + } + }; + + return ( +
+ {/* Edit Outlet */} +
+
+
+
+
+
+
+

Edit Outlet

+
+ +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ Status + +
+
+
+ + +
+
+
+
+
+
+
+
+ {/* /Edit Outlet */} +
+ ); +}; + +export default EditOutletList; diff --git a/src/core/modals/stocks/managestockModal.jsx b/src/core/modals/stocks/managestockModal.jsx index 367ce7c..1d1018a 100644 --- a/src/core/modals/stocks/managestockModal.jsx +++ b/src/core/modals/stocks/managestockModal.jsx @@ -5,9 +5,9 @@ import Swal from "sweetalert2"; import outletsApi from "../../../services/outletsApi"; import productsApi from "../../../services/productsApi"; import { + adjustInventory, createInventory, fetchInventories, - updateInventory, } from "../../redux/actions/inventoryActions"; const ManageStockModal = () => { @@ -21,8 +21,10 @@ const ManageStockModal = () => { outlet_id: "", product_id: "", quantity: "", + delta: "", min_stock_level: "", max_stock_level: "", + reason: "", }; }; @@ -85,7 +87,7 @@ const ManageStockModal = () => { e.preventDefault(); try { - await dispatch(updateInventory(currentInventory?.id, formData)); + await dispatch(adjustInventory(formData)); await dispatch(fetchInventories()); @@ -107,7 +109,9 @@ const ManageStockModal = () => { Swal.fire({ icon: "error", title: "Error!", - text: error.message || "Failed to update stock. Please try again.", + text: + error?.response?.data?.errors[0]?.cause || + "Failed to update stock. Please try again.", }); } }; @@ -273,7 +277,7 @@ const ManageStockModal = () => {
-

Edit Stock

+

Adjust Stock