diff --git a/src/pages/Products.jsx b/src/pages/Products.jsx index 9639679..5aad77c 100644 --- a/src/pages/Products.jsx +++ b/src/pages/Products.jsx @@ -16,6 +16,7 @@ import { HiOutlineSearch, HiOutlineCube, HiOutlineX, + HiOutlinePrinter, } from "react-icons/hi"; const CATEGORIES = [ @@ -184,6 +185,104 @@ export default function Products() { return matchesSearch && matchesCategory; }); + const handlePrintProducts = () => { + const printWindow = window.open("", "_blank"); + + if (!printWindow) { + toast.error("تعذر فتح نافذة الطباعة"); + return; + } + + const rows = filteredProducts + .map((product, index) => { + const category = getCategoryMeta(product.category); + const totalValue = + (Number(product.quantity) || 0) * (Number(product.purchasePrice) || 0); + + return ` + + ${index + 1} + ${product.name || "-"} + ${category.name} + ${product.quantity || 0} + ${Number(product.purchasePrice || 0).toFixed(2)} ر.س + ${totalValue.toFixed(2)} ر.س + ${ + (product.quantity || 0) <= (product.minStock || 5) + ? "منخفض" + : "متوفر" + } + + `; + }) + .join(""); + + printWindow.document.write(` + + + + طباعة المنتجات + + + +

قائمة المنتجات

+

عدد المنتجات المطبوعة: ${filteredProducts.length}

+ + + + + + + + + + + + + + ${rows} + +
#اسم المنتجالفئةالكميةسعر الشراءإجمالي القيمةالحالة
+ + + + `); + + printWindow.document.close(); + }; + if (loading) { return (
@@ -200,18 +299,30 @@ export default function Products() {

إدارة المنتجات

{products.length} منتج في المخزون

- + +
+ + + +