import React, { useState } from 'react'; const InventoryManagement = () => { const [inventory, setInventory] = useState([ { id: 1, product: 'لپ‌تاپ ایسوس', code: 'LAP001', currentStock: 5, minStock: 2, maxStock: 20, unit: 'عدد', lastUpdate: '1403/01/15' }, { id: 2, product: 'موبایل سامسونگ', code: 'MOB002', currentStock: 12, minStock: 5, maxStock: 50, unit: 'عدد', lastUpdate: '1403/01/14' }, { id: 3, product: 'کتاب برنامه‌نویسی', code: 'BOK003', currentStock: 25, minStock: 10, maxStock: 100, unit: 'جلد', lastUpdate: '1403/01/13' } ]); const [showAdjustmentForm, setShowAdjustmentForm] = useState(false); const [selectedProduct, setSelectedProduct] = useState(null); const [adjustmentData, setAdjustmentData] = useState({ type: 'افزایش', quantity: '', reason: '' }); const handleAdjustmentChange = (e) => { const { name, value } = e.target; setAdjustmentData(prev => ({ ...prev, [name]: value })); }; const handleStockAdjustment = (e) => { e.preventDefault(); const adjustmentQuantity = parseInt(adjustmentData.quantity); const newStock = adjustmentData.type === 'افزایش' ? selectedProduct.currentStock + adjustmentQuantity : selectedProduct.currentStock - adjustmentQuantity; if (newStock < 0) { alert('موجودی نمی‌تواند منفی باشد!'); return; } setInventory(inventory.map(item => item.id === selectedProduct.id ? { ...item, currentStock: newStock, lastUpdate: new Date().toLocaleDateString('fa-IR') } : item )); setShowAdjustmentForm(false); setSelectedProduct(null); setAdjustmentData({ type: 'افزایش', quantity: '', reason: '' }); }; const handleCancelAdjustment = () => { setShowAdjustmentForm(false); setSelectedProduct(null); setAdjustmentData({ type: 'افزایش', quantity: '', reason: '' }); }; const getStockStatus = (current, min, max) => { if (current <= min) return { status: 'کم', color: 'bg-red-100 text-red-800' }; if (current >= max) return { status: 'زیاد', color: 'bg-yellow-100 text-yellow-800' }; return { status: 'مناسب', color: 'bg-green-100 text-green-800' }; }; const lowStockItems = inventory.filter(item => item.currentStock <= item.minStock); const totalValue = inventory.reduce((sum, item) => { // Assuming average price for calculation const avgPrice = item.product === 'لپ‌تاپ ایسوس' ? 15000000 : item.product === 'موبایل سامسونگ' ? 8000000 : 150000; return sum + (item.currentStock * avgPrice); }, 0); const formatPrice = (price) => { return new Intl.NumberFormat('fa-IR').format(price) + ' ریال'; }; return (

مدیریت انبار

{/* Inventory Summary */}
📦

کل کالاها

{inventory.length}

⚠️

کمبود موجودی

{lowStockItems.length}

💰

ارزش کل انبار

{formatPrice(totalValue)}

📊

کل موجودی

{inventory.reduce((sum, item) => sum + item.currentStock, 0)}

{/* Low Stock Alert */} {lowStockItems.length > 0 && (

هشدار کمبود موجودی

{lowStockItems.map(item => (
{item.product} - موجودی فعلی: {item.currentStock} {item.unit} (حداقل: {item.minStock})
))}
)} {/* Stock Adjustment Form Modal */} {showAdjustmentForm && (

تنظیم موجودی