+
-
-
{
- if (e.target.checked) {
- const fractionalPart =
- total % 1;
- setOrderDiscount(
- fractionalPart?.toFixed(
- 2
- )
- );
- } else {
- setOrderDiscount(0);
- }
- }}
- />
+
+
+
+
+
+
+
+
+
+
+
setSearchQuery(e.target.value)}
+ placeholder="Scan Barcode or Search Product Name..."
+ value={searchQuery}
+ autoFocus
+ />
+
+
+ {
+ products.length > 0 && (
+
+
+ {products.map((product) => (
+
+ ))}
+
+
+ )
+ }
+
-
-
-
Total:
-
-
-
Paid:
-
-
{
- const value =
- e.target.value;
- if (
- parseFloat(value) < 0 ||
- parseFloat(value) >
- updateTotal
- ) {
- return;
- }
- setPaid(value);
- }}
- />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Sub Total
+
+ {currency} {Number(total).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
+
+
+
+
+ Surcharge Type
+
+
+ {
+ selectedMethod?.surcharge_type === 'percentage' ? (
+ {`${selectedMethod?.surcharge_value} %`}
+ ) : selectedMethod?.surcharge_type === 'fixed' ? (
+ Fixed
+ ) : (
+ None
+ )
+ }
+
+
+
+
+ Surcharge Value
+
+
+ {currency} {Number(surchargeAmount).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
+
+
+
+
+
+
+ Award Discount:
+
+
+
+
+ e.target.select()} // Select all text on click for faster typing
+ onChange={(e) => {
+ const value = e.target.value;
+ const numValue = parseFloat(value);
+
+ // Allow clearing the input (empty string) or valid numbers within range
+ if (value === "" || (numValue >= 0 && numValue <= total)) {
+ setOrderDiscount(value);
+ }
+ }}
+ />
+
+
+
+
+
+
+
+
+ Amount Paid:
+
+
+
+
+ {
+ const value =
+ e.target.value;
+ if (
+ parseFloat(value) < 0 ||
+ parseFloat(value) >
+ updateTotal
+ ) {
+ return;
+ }
+ setPaid(value);
+ }}
+ />
+
+
+
+
+ {/* Final Totals Section */}
+
+
+ Total Due
+
+ {Number(updateTotal).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
+
+
+
+ Balance
+ 0 ? 'text-danger' : 'text-success'}`}>
+ {Number(due).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
+
+
+
+
-
-
-
Due:
-
- {due}
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- setSearchBarcode(e.target.value)
- }
- />
+ >
+ ) : (
+ <>
+
+
+
-
-
- setSearchQuery(e.target.value)
- }
- />
-
-
-
- {products.length > 0 &&
- products.map((product, index) => (
-
- addProductToCart(product.id)
- }
- className="col-6 col-md-4 col-lg-3 mb-3"
- key={index}
- style={{ cursor: "pointer" }}
- >
-
-

{
- e.target.onerror = null;
- e.target.src = `${fullDomainWithPort}/assets/images/no-image.png`;
- }}
- width={120}
- height={100}
- />
-
-
- {product.name} (
- {product.quantity})
-
-
- Price:{" "}
- {
- product?.discounted_price
- }
-
-
-
-
- ))}
-
- {loading && (
-
- Loading more...
-
- )}
+
-
-
-
+ >
+ )
+ }
+
>
);
diff --git a/resources/js/components/Purchase/Purchase.jsx b/resources/js/components/Purchase/Purchase.jsx
old mode 100644
new mode 100755
index 24263d2..673b432
--- a/resources/js/components/Purchase/Purchase.jsx
+++ b/resources/js/components/Purchase/Purchase.jsx
@@ -21,6 +21,7 @@ export default function Purchase() {
const [shipping, setShipping] = useState(0);
const [products, setProducts] = useState([]);
const [searchResults, setSearchResults] = useState([]);
+
useEffect(() => {
const searchParams = new URLSearchParams(window.location.search);
const barcodeParam = searchParams.get("barcode");
@@ -79,7 +80,7 @@ export default function Purchase() {
}
// Optional: Uncomment if you want to show loading state
- // setLoading(true);
+ setLoading(true);
try {
const res = await axios.get("/admin/products", {
@@ -92,7 +93,7 @@ export default function Purchase() {
if (productsData?.data && productsData.data.length) {
productsData.data.forEach((product) => {
const existingProductIndex = products.findIndex(
- (p) => p.id === product.id
+ (p) => p.id === product.id,
);
if (existingProductIndex !== -1) {
// Product exists, increment qty
@@ -148,7 +149,7 @@ export default function Purchase() {
...product,
qty: newQty,
subTotal: parseFloat(
- (product.purchase_price * newQty).toFixed(2)
+ (product.purchase_price * newQty).toFixed(2),
),
};
}
@@ -181,9 +182,9 @@ export default function Purchase() {
const calculateTotals = () => {
const subTotal = products.reduce(
(sum, product) => sum + product.subTotal,
- 0
+ 0,
);
- const formattedSubTotal = parseFloat(subTotal.toFixed(2));
+ const formattedSubTotal = parseFloat(Number(subTotal).toFixed(2));
const formattedTax = parseFloat((tax || 0).toFixed(2));
const formattedDiscount = parseFloat((discount || 0).toFixed(2));
const formattedShipping = parseFloat((shipping || 0).toFixed(2));
@@ -193,7 +194,7 @@ export default function Purchase() {
formattedTax -
formattedDiscount +
formattedShipping
- ).toFixed(2)
+ ).toFixed(2),
);
return {
@@ -206,6 +207,7 @@ export default function Purchase() {
};
const totals = calculateTotals();
+
const handleSubmit = async () => {
if (totals.grandTotal <= 0) {
// toast.error("Total must be greater than zero.");
@@ -252,7 +254,7 @@ export default function Purchase() {
window.location.href = "/admin/purchase";
} catch (err) {
toast.error(
- err.response?.data?.message || "An error occurred"
+ err.response?.data?.message || "An error occurred",
);
}
}
@@ -282,25 +284,27 @@ export default function Purchase() {
// Call the async function inside useEffect
getProducts();
}, [searchTerm]);
+
// Handle adding selected product to the products list
// Handle adding selected product to the products list
const handleProductSelect = (product) => {
- const existingProductIndex = products.findIndex(
- (p) => p.id === product.id
- );
+ setProducts((prevProducts) => {
+ const existingProduct = prevProducts.find((p) => p.id === product.id);
- if (existingProductIndex !== -1) {
- // If product exists, increment quantity
- setProducts((prevProducts) => {
- const updatedProducts = [...prevProducts];
- updatedProducts[existingProductIndex].qty += 1;
- updatedProducts[existingProductIndex].subTotal =
- updatedProducts[existingProductIndex].purchase_price *
- updatedProducts[existingProductIndex].qty;
- return updatedProducts;
- });
- } else {
- // Add new product to the list
+ if (existingProduct) {
+ // Return a NEW array with a NEW object for the updated item
+ return prevProducts.map((p) =>
+ p.id === product.id
+ ? {
+ ...p,
+ qty: p.qty + 1,
+ subTotal: p.purchase_price * (p.qty + 1)
+ }
+ : p
+ );
+ }
+
+ // Add new product
const newProduct = {
id: product.id,
name: product.name,
@@ -310,307 +314,202 @@ export default function Purchase() {
qty: 1,
subTotal: product.purchase_price,
};
- setProducts((prevProducts) => [...prevProducts, newProduct]);
- }
- // Clear search term and results
+ return [...prevProducts, newProduct];
+ });
+
setSearchTerm("");
setSearchResults([]);
};
+
return (
- <>
-
-
-
-
-
-
-
-
{
- const formattedDate = date
- ? date
- .toISOString()
- .split("T")[0]
- : null;
- setDate(formattedDate);
- }}
- />
+
+
+
+
+ {/* Left Side: Product Selection & Table */}
+
+
+
+
+
+
+
+ setDate(d ? d.toISOString().split("T")[0] : null)}
+ placeholderText="Select Date"
+ />
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
- setSearchTerm(e.target.value)
- }
- placeholder="Enter product barcode/name"
+ onChange={(e) => setSearchTerm(e.target.value)}
+ placeholder="Scan barcode or type product name..."
+ autoFocus
/>
-
+
+ {
+ searchResults.length > 0 && (
+
+
+ {searchResults.map((product) => (
+
+ ))}
+
+
+ )
+ }
- {/* Display search results below the input */}
- {searchResults.length > 0 && (
-
-
-
- {searchResults.map((product) => (
- -
- handleProductSelect(product)
- }
- style={{ cursor: "pointer" }}
- >
- {product.name} - $
- {product.price}
-
- ))}
-
-
-
- )}
-
-
-
-
+
+
-
-
-
-
-
-
-
- | Subtotal: |
-
- {totals.subTotal.toFixed(2)}
- |
-
-
- | Tax: |
-
- {totals.tax.toFixed(2)}
- |
-
-
- | Discount: |
-
- {totals.discount.toFixed(2)}
- |
-
-
- | Shipping: |
-
- {totals.shipping.toFixed(2)}
- |
-
-
- | Grand Total: |
-
- {totals.grandTotal.toFixed(
- 2
- )}
- |
-
-
-
-
-
-
-
-
-
-
-
-
- setTax(parseFloat(e.target.value) || 0)
- }
- placeholder="Enter tax"
- name="tax"
- required
- />
-
-
-
-
- setDiscount(
- parseFloat(e.target.value) || 0
- )
- }
- placeholder="Enter discount"
- name="discount"
- required
- />
-
-
-
-
- setShipping(
- parseFloat(e.target.value) || 0
- )
- }
- placeholder="Enter shipping"
- name="shipping"
- required
- />
+
+ {/* Right Side: Calculation & Actions */}
+
+
+
+
Order Summary
+
+
+
+
+
+
+
Grand Total
+
+ KES {totals.grandTotal.toLocaleString(undefined, { minimumFractionDigits: 2 })}
+
+
+
+
+
Cancel
-
-
-
- >
+
);
}
diff --git a/resources/js/components/Purchase/Suppliers.jsx b/resources/js/components/Purchase/Suppliers.jsx
old mode 100644
new mode 100755
diff --git a/resources/js/sounds/beep-02.mp3 b/resources/js/sounds/beep-02.mp3
old mode 100644
new mode 100755
diff --git a/resources/js/sounds/beep-07a.mp3 b/resources/js/sounds/beep-07a.mp3
old mode 100644
new mode 100755
diff --git a/resources/js/utils/playSound.jsx b/resources/js/utils/playSound.jsx
old mode 100644
new mode 100755
diff --git a/resources/views/backend/brands/create.blade.php b/resources/views/backend/brands/create.blade.php
old mode 100644
new mode 100755
diff --git a/resources/views/backend/brands/edit.blade.php b/resources/views/backend/brands/edit.blade.php
old mode 100644
new mode 100755
diff --git a/resources/views/backend/brands/index.blade.php b/resources/views/backend/brands/index.blade.php
old mode 100644
new mode 100755
index 4bdcc7b..ff1960a
--- a/resources/views/backend/brands/index.blade.php
+++ b/resources/views/backend/brands/index.blade.php
@@ -21,7 +21,7 @@
| # |
- |
+
Name |
Status |
Action |
@@ -55,10 +55,10 @@
data: 'DT_RowIndex',
name: 'DT_RowIndex'
},
- {
- data: 'image',
- name: 'image'
- },
+ // {
+ // data: 'image',
+ // name: 'image'
+ // },
{
data: 'name',
name: 'name'
diff --git a/resources/views/backend/cart/index.blade.php b/resources/views/backend/cart/index.blade.php
old mode 100644
new mode 100755
index be31540..0ddde9d
--- a/resources/views/backend/cart/index.blade.php
+++ b/resources/views/backend/cart/index.blade.php
@@ -1,5 +1,5 @@
@extends('backend.master')
-@section('title', 'Pos')
+@section('title', 'New Order')
@section('content')
@push('style')
diff --git a/resources/views/backend/categories/create.blade.php b/resources/views/backend/categories/create.blade.php
old mode 100644
new mode 100755
diff --git a/resources/views/backend/categories/edit.blade.php b/resources/views/backend/categories/edit.blade.php
old mode 100644
new mode 100755
diff --git a/resources/views/backend/categories/index.blade.php b/resources/views/backend/categories/index.blade.php
old mode 100644
new mode 100755
diff --git a/resources/views/backend/customers/create.blade.php b/resources/views/backend/customers/create.blade.php
old mode 100644
new mode 100755
diff --git a/resources/views/backend/customers/edit.blade.php b/resources/views/backend/customers/edit.blade.php
old mode 100644
new mode 100755
diff --git a/resources/views/backend/customers/index.blade.php b/resources/views/backend/customers/index.blade.php
old mode 100644
new mode 100755
diff --git a/resources/views/backend/layouts/navbar.blade.php b/resources/views/backend/layouts/navbar.blade.php
index f249d0d..0d0e38a 100755
--- a/resources/views/backend/layouts/navbar.blade.php
+++ b/resources/views/backend/layouts/navbar.blade.php
@@ -1,73 +1,52 @@
-