feat: ultimate warehouse management features (blind count, offline sync, shelf locking, discrepancy dashboard)
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
'use client';
|
||||
import { useState, useEffect } from 'react';
|
||||
import Header from '@/components/Header';
|
||||
import { AlertTriangle, CheckCircle, PackageSearch, RefreshCw, Send, ListTree, ArrowDownRight, ArrowUpRight } from 'lucide-react';
|
||||
|
||||
export default function DiscrepancyDashboard() {
|
||||
const [warehouse, setWarehouse] = useState('11');
|
||||
const [data, setData] = useState({ discrepancies: [], accurate: [] });
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
}, [warehouse]);
|
||||
|
||||
const fetchData = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await fetch(`/api/reports/discrepancies?warehouse=${warehouse}`);
|
||||
if (res.ok) {
|
||||
const result = await res.json();
|
||||
setData(result);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleRecount = async (productId, productName) => {
|
||||
// In a full system, this would call /api/tasks to assign a recount task
|
||||
alert(`تسک بازشماری برای کالا "${productName}" (کد: ${productId}) صادر شد.`);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-full min-h-screen bg-gray-50 flex flex-col pb-24">
|
||||
<Header title="داشبورد مغایرتگیری" showBack={true} />
|
||||
|
||||
<div className="flex-1 px-4 md:px-8 pt-6 max-w-5xl mx-auto w-full flex flex-col gap-6">
|
||||
|
||||
{/* Controls */}
|
||||
<div className="bg-white rounded-[24px] p-4 flex flex-col sm:flex-row items-center justify-between gap-4 shadow-sm border border-gray-100">
|
||||
<div className="flex items-center gap-3 w-full sm:w-auto">
|
||||
<div className="w-10 h-10 bg-indigo-50 text-indigo-600 rounded-xl flex items-center justify-center">
|
||||
<ListTree size={20} />
|
||||
</div>
|
||||
<div>
|
||||
<h2 className="text-sm font-bold text-gray-800">انتخاب انبار</h2>
|
||||
<p className="text-xs text-gray-400">انبار مورد نظر برای بررسی مغایرت</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-3 w-full sm:w-auto">
|
||||
<select
|
||||
value={warehouse}
|
||||
onChange={(e) => setWarehouse(e.target.value)}
|
||||
className="bg-gray-50 border border-gray-200 rounded-xl px-4 py-2.5 text-sm font-bold focus:outline-none focus:border-indigo-500 flex-1 sm:w-48"
|
||||
>
|
||||
<option value="11">انبار مرکزی (11)</option>
|
||||
<option value="13">انبار فروشگاه (13)</option>
|
||||
<option value="14">انبار کارگاه شارژ (14)</option>
|
||||
<option value="15">انبار کارگاه تعمیرات (15)</option>
|
||||
</select>
|
||||
<button onClick={fetchData} className="bg-gray-900 text-white p-3 rounded-xl hover:bg-gray-800 transition-colors">
|
||||
<RefreshCw size={18} className={loading ? 'animate-spin' : ''} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Stats */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="bg-white border border-red-100 rounded-[24px] p-5 shadow-sm flex flex-col gap-2 relative overflow-hidden">
|
||||
<div className="absolute top-0 right-0 w-16 h-16 bg-red-50 rounded-bl-[40px] flex items-center justify-center -mr-2 -mt-2">
|
||||
<AlertTriangle className="text-red-500" size={20} />
|
||||
</div>
|
||||
<p className="text-xs font-bold text-gray-500">کالاهای دارای مغایرت</p>
|
||||
<p className="text-3xl font-black text-red-600">{loading ? '-' : data.discrepancies.length}</p>
|
||||
</div>
|
||||
|
||||
<div className="bg-white border border-green-100 rounded-[24px] p-5 shadow-sm flex flex-col gap-2 relative overflow-hidden">
|
||||
<div className="absolute top-0 right-0 w-16 h-16 bg-green-50 rounded-bl-[40px] flex items-center justify-center -mr-2 -mt-2">
|
||||
<CheckCircle className="text-green-500" size={20} />
|
||||
</div>
|
||||
<p className="text-xs font-bold text-gray-500">کالاهای بدون مغایرت</p>
|
||||
<p className="text-3xl font-black text-green-600">{loading ? '-' : data.accurate.length}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Discrepancies List */}
|
||||
<div className="bg-white rounded-[24px] shadow-sm border border-gray-100 overflow-hidden flex flex-col">
|
||||
<div className="p-5 border-b border-gray-100 flex items-center gap-2">
|
||||
<PackageSearch className="text-red-500" size={20} />
|
||||
<h3 className="font-bold text-gray-800">لیست کالاهای مغایرتدار</h3>
|
||||
</div>
|
||||
|
||||
<div className="p-0 overflow-x-auto">
|
||||
<table className="w-full text-right text-sm">
|
||||
<thead className="bg-gray-50 text-gray-500 text-xs font-bold">
|
||||
<tr>
|
||||
<th className="px-6 py-4">کالا</th>
|
||||
<th className="px-6 py-4">موجودی سیستم</th>
|
||||
<th className="px-6 py-4">شمارش شده</th>
|
||||
<th className="px-6 py-4">مغایرت</th>
|
||||
<th className="px-6 py-4">قفسهها</th>
|
||||
<th className="px-6 py-4 text-left">عملیات</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-100">
|
||||
{data.discrepancies.map((item, idx) => (
|
||||
<tr key={idx} className="hover:bg-red-50/50 transition-colors">
|
||||
<td className="px-6 py-4">
|
||||
<p className="font-bold text-gray-800">{item.product_name}</p>
|
||||
<p className="text-[10px] text-gray-400">کد: {item.product_id}</p>
|
||||
</td>
|
||||
<td className="px-6 py-4 font-bold text-gray-600">{item.system_expected}</td>
|
||||
<td className="px-6 py-4 font-bold text-gray-900">{item.total_counted}</td>
|
||||
<td className="px-6 py-4">
|
||||
<div className={`inline-flex items-center gap-1 px-2.5 py-1 rounded-lg text-xs font-black ${item.difference > 0 ? 'bg-blue-100 text-blue-700' : 'bg-red-100 text-red-700'}`}>
|
||||
{item.difference > 0 ? <ArrowUpRight size={14} /> : <ArrowDownRight size={14} />}
|
||||
{Math.abs(item.difference)}
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-6 py-4 text-xs font-medium text-gray-500">
|
||||
{item.locations.length > 0 ? item.locations.join('، ') : 'پیدا نشد'}
|
||||
</td>
|
||||
<td className="px-6 py-4 text-left">
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<button
|
||||
onClick={() => handleRecount(item.product_id, item.product_name)}
|
||||
className="bg-orange-50 text-orange-600 hover:bg-orange-100 px-3 py-1.5 rounded-lg text-xs font-bold transition-colors"
|
||||
>
|
||||
درخواست بازشماری
|
||||
</button>
|
||||
<button className="bg-gray-900 text-white hover:bg-gray-800 px-3 py-1.5 rounded-lg text-xs font-bold transition-colors flex items-center gap-1">
|
||||
<Send size={12} />
|
||||
ارسال تعدیل
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{data.discrepancies.length === 0 && !loading && (
|
||||
<tr>
|
||||
<td colSpan="6" className="px-6 py-12 text-center text-gray-400 font-bold">
|
||||
هیچ مغایرتی یافت نشد. همه چیز مرتب است! 🎉
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
{loading && (
|
||||
<tr>
|
||||
<td colSpan="6" className="px-6 py-12 text-center text-indigo-500 font-bold animate-pulse">
|
||||
در حال پردازش و مقایسه اطلاعات...
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
'use client';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Save, EyeOff, ShieldCheck, Check } from 'lucide-react';
|
||||
import { motion } from 'framer-motion';
|
||||
|
||||
export default function SettingsPage() {
|
||||
const [settings, setSettings] = useState({
|
||||
blind_counting: false,
|
||||
correction_roles: ['ADMIN', 'SUPERVISOR']
|
||||
});
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [saved, setSaved] = useState(false);
|
||||
|
||||
const availableRoles = [
|
||||
{ id: 'ADMIN', label: 'مدیر کل' },
|
||||
{ id: 'SUPERVISOR', label: 'سرپرست انبار' },
|
||||
{ id: 'ACCOUNTANT', label: 'حسابدار' },
|
||||
{ id: 'COUNTER', label: 'انبارگردان' }
|
||||
];
|
||||
|
||||
useEffect(() => {
|
||||
fetchSettings();
|
||||
}, []);
|
||||
|
||||
const fetchSettings = async () => {
|
||||
try {
|
||||
const res = await fetch('/api/settings');
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
setSettings(prev => ({ ...prev, ...data }));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
setSaving(true);
|
||||
setSaved(false);
|
||||
try {
|
||||
const res = await fetch('/api/settings', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(settings)
|
||||
});
|
||||
if (res.ok) {
|
||||
setSaved(true);
|
||||
setTimeout(() => setSaved(false), 3000);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const toggleRole = (roleId) => {
|
||||
setSettings(prev => {
|
||||
const roles = prev.correction_roles || [];
|
||||
if (roles.includes(roleId)) {
|
||||
return { ...prev, correction_roles: roles.filter(r => r !== roleId) };
|
||||
} else {
|
||||
return { ...prev, correction_roles: [...roles, roleId] };
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (loading) return <div className="p-8 flex justify-center"><div className="w-8 h-8 border-2 border-indigo-500 border-t-transparent rounded-full animate-spin"></div></div>;
|
||||
|
||||
return (
|
||||
<div className="max-w-3xl mx-auto p-4 md:p-8 space-y-8">
|
||||
<div>
|
||||
<h1 className="text-2xl font-black text-gray-800 tracking-tight">تنظیمات سیستم</h1>
|
||||
<p className="text-sm text-gray-500 font-medium mt-1">مدیریت قوانین انبارگردانی و دسترسیها</p>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-[24px] p-6 shadow-sm border border-gray-100 space-y-8">
|
||||
|
||||
{/* Blind Counting Setting */}
|
||||
<div className="flex items-start justify-between gap-4 border-b border-gray-50 pb-8">
|
||||
<div>
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<div className="w-8 h-8 rounded-xl bg-purple-50 text-purple-600 flex items-center justify-center">
|
||||
<EyeOff size={18} />
|
||||
</div>
|
||||
<h2 className="text-base font-bold text-gray-800">شمارش کور (Blind Counting)</h2>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500 leading-relaxed max-w-lg">
|
||||
در صورت فعال بودن، انبارگردانها موجودی فعلی سیستم را نمیبینند و مجبورند به جای تایید کورکورانه، کالاها را به صورت واقعی بشمارند.
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setSettings(s => ({ ...s, blind_counting: !s.blind_counting }))}
|
||||
className={`relative inline-flex h-7 w-14 items-center rounded-full transition-colors ${settings.blind_counting ? 'bg-indigo-600' : 'bg-gray-200'}`}
|
||||
>
|
||||
<span className={`inline-block h-5 w-5 transform rounded-full bg-white transition-transform shadow-sm ${settings.blind_counting ? '-translate-x-1.5' : '-translate-x-8'}`} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Correction Roles Setting */}
|
||||
<div>
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<div className="w-8 h-8 rounded-xl bg-blue-50 text-blue-600 flex items-center justify-center">
|
||||
<ShieldCheck size={18} />
|
||||
</div>
|
||||
<h2 className="text-base font-bold text-gray-800">دسترسی ثبت اصلاحیه</h2>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500 leading-relaxed mb-4">
|
||||
وقتی انبارگردانی یک قفسه بسته میشود، چه نقشهایی اجازه دارند درخواست اصلاحیه ثبت کنند؟ (حالت چندانتخابی)
|
||||
</p>
|
||||
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-3">
|
||||
{availableRoles.map(role => {
|
||||
const isSelected = settings.correction_roles?.includes(role.id);
|
||||
return (
|
||||
<button
|
||||
key={role.id}
|
||||
onClick={() => toggleRole(role.id)}
|
||||
className={`flex items-center justify-between p-4 rounded-[16px] border text-xs font-bold transition-all ${
|
||||
isSelected
|
||||
? 'border-blue-500 bg-blue-50 text-blue-700'
|
||||
: 'border-gray-200 bg-white text-gray-600 hover:border-gray-300'
|
||||
}`}
|
||||
>
|
||||
{role.label}
|
||||
{isSelected && <Check size={14} />}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end">
|
||||
<motion.button
|
||||
whileTap={{ scale: 0.97 }}
|
||||
onClick={handleSave}
|
||||
disabled={saving}
|
||||
className="flex items-center gap-2 bg-gray-900 text-white px-8 py-4 rounded-[20px] text-sm font-bold shadow-md hover:bg-gray-800 transition-colors disabled:opacity-70"
|
||||
>
|
||||
{saving ? (
|
||||
<div className="w-5 h-5 border-2 border-white/30 border-t-white rounded-full animate-spin"></div>
|
||||
) : saved ? (
|
||||
<>
|
||||
<Check size={18} />
|
||||
ذخیره شد
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Save size={18} />
|
||||
ذخیره تغییرات
|
||||
</>
|
||||
)}
|
||||
</motion.button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user