💎 Complete luxury overhaul: Invoices, Companies, Staff, Settings redesigned & renamed Sidebar
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* ════════════════════════════════════════════════════════════
|
||||
* مُصادَق (Musadaq) — Invoices Management Page
|
||||
* مُصادَق (Musadaq) — Invoices Management Page (Premium Dark)
|
||||
* ════════════════════════════════════════════════════════════
|
||||
*/
|
||||
|
||||
@@ -21,7 +21,9 @@ import {
|
||||
FileText,
|
||||
Send,
|
||||
Download,
|
||||
Trash2
|
||||
Trash2,
|
||||
Loader2,
|
||||
X
|
||||
} from 'lucide-react';
|
||||
import apiClient from '../../api/client';
|
||||
|
||||
@@ -46,23 +48,12 @@ export const InvoicesPage = () => {
|
||||
const fetchData = async () => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
// Fetch companies first so the dropdown always works
|
||||
try {
|
||||
const compRes = await apiClient.get('/companies');
|
||||
console.log('Fetched Companies:', compRes.data);
|
||||
setCompanies(compRes.data);
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch companies', err);
|
||||
}
|
||||
|
||||
// Fetch invoices separately
|
||||
try {
|
||||
const invRes = await apiClient.get('/invoices');
|
||||
console.log('Fetched Invoices:', invRes.data);
|
||||
setInvoices(invRes.data);
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch invoices', err);
|
||||
}
|
||||
const [compRes, invRes] = await Promise.all([
|
||||
apiClient.get('/companies').catch(() => ({ data: [] })),
|
||||
apiClient.get('/invoices').catch(() => ({ data: [] }))
|
||||
]);
|
||||
setCompanies(compRes.data);
|
||||
setInvoices(invRes.data);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
@@ -110,10 +101,6 @@ export const InvoicesPage = () => {
|
||||
};
|
||||
|
||||
const handleSubmitToJoFotara = async (inv: any) => {
|
||||
if (inv.status !== 'validated' && inv.status !== 'extracted') {
|
||||
alert('يجب أن تكون الفاتورة مدققة أو مستخرجة أولاً');
|
||||
return;
|
||||
}
|
||||
setSubmitLoading(inv.id);
|
||||
try {
|
||||
await apiClient.post(`/invoices/${inv.id}/submit`);
|
||||
@@ -134,30 +121,23 @@ export const InvoicesPage = () => {
|
||||
|
||||
const filteredInvoices = invoices.filter(inv =>
|
||||
inv.invoice_number?.includes(searchTerm) ||
|
||||
inv.company?.name?.includes(searchTerm)
|
||||
inv.company?.name?.toLowerCase().includes(searchTerm.toLowerCase())
|
||||
);
|
||||
|
||||
const StatusBadge = ({ invoice }: { invoice: any }) => {
|
||||
const status = invoice.status;
|
||||
const config: any = {
|
||||
approved: { color: 'text-emerald-700 bg-emerald-50 border-emerald-100', icon: CheckCircle2, label: 'تم التصديق' },
|
||||
validated: { color: 'text-blue-700 bg-blue-50 border-blue-100', icon: CheckCircle2, label: 'جاهز للإرسال' },
|
||||
extracted: { color: 'text-indigo-700 bg-indigo-50 border-indigo-100', icon: CheckCircle2, label: 'تم الاستخراج' },
|
||||
uploaded: { color: 'text-amber-700 bg-amber-50 border-amber-100', icon: Clock, label: 'قيد المعالجة AI' },
|
||||
extracting: { color: 'text-amber-700 bg-amber-50 border-amber-100', icon: Clock, label: 'قيد الاستخراج' },
|
||||
validation_failed: { color: 'text-red-700 bg-red-50 border-red-100', icon: AlertCircle, label: 'خطأ في التحقق' },
|
||||
approved: { color: 'text-emerald-400 bg-emerald-500/10 border-emerald-500/20', icon: CheckCircle2, label: 'تم التصديق' },
|
||||
validated: { color: 'text-blue-400 bg-blue-500/10 border-blue-500/20', icon: CheckCircle2, label: 'جاهز للإرسال' },
|
||||
extracted: { color: 'text-indigo-400 bg-indigo-500/10 border-indigo-500/20', icon: CheckCircle2, label: 'تم الاستخراج' },
|
||||
uploaded: { color: 'text-amber-400 bg-amber-500/10 border-amber-500/20', icon: Clock, label: 'قيد المعالجة AI' },
|
||||
extracting: { color: 'text-amber-400 bg-amber-500/10 border-amber-500/20', icon: Clock, label: 'قيد الاستخراج' },
|
||||
validation_failed: { color: 'text-red-400 bg-red-500/10 border-red-500/20', icon: AlertCircle, label: 'خطأ في التحقق' },
|
||||
};
|
||||
const { color, icon: Icon, label } = config[status] || { color: 'text-slate-500 bg-slate-50', icon: Clock, label: status };
|
||||
const { color, icon: Icon, label } = config[status] || { color: 'text-slate-400 bg-slate-800', icon: Clock, label: status };
|
||||
|
||||
const errorTitle = status === 'validation_failed' && invoice.validation_errors
|
||||
? invoice.validation_errors.join('\n')
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<span
|
||||
title={errorTitle}
|
||||
className={`inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-[10px] font-bold border ${color} uppercase tracking-tight cursor-help`}
|
||||
>
|
||||
<span className={`inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-[10px] font-bold border ${color} uppercase tracking-tight`}>
|
||||
<Icon className="w-3 h-3" />
|
||||
{label}
|
||||
</span>
|
||||
@@ -165,15 +145,15 @@ export const InvoicesPage = () => {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-8 h-full flex flex-col animate-in fade-in slide-in-from-bottom-4 duration-700">
|
||||
<div className="space-y-8 animate-in fade-in duration-700">
|
||||
<header className="flex items-center justify-between">
|
||||
<div>
|
||||
<h2 className="text-3xl font-bold text-slate-900">إدارة الفواتير</h2>
|
||||
<p className="text-slate-500 mt-1">عرض، معالجة، وإرسال الفواتير الضريبية لبوابة الضريبة.</p>
|
||||
<h2 className="text-3xl font-black text-white">إدارة الفواتير</h2>
|
||||
<p className="text-slate-400 mt-1">عرض، معالجة، وإرسال الفواتير الضريبية لبوابة الضريبة.</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setIsUploadModalOpen(true)}
|
||||
className="btn-primary py-3 px-8 rounded-2xl flex items-center gap-2 shadow-xl shadow-primary-500/25 active:scale-95 transition-all"
|
||||
className="bg-emerald-500 hover:bg-emerald-600 text-slate-950 font-bold py-3 px-8 rounded-xl flex items-center gap-2 shadow-lg shadow-emerald-500/20 transition-all active:scale-95"
|
||||
>
|
||||
<Upload className="w-5 h-5" />
|
||||
رفع فاتورة جديدة
|
||||
@@ -182,138 +162,94 @@ export const InvoicesPage = () => {
|
||||
|
||||
{/* ── Filter & Search Bar ──────────────────────────────── */}
|
||||
<div className="flex gap-4">
|
||||
<div className="flex-1 glass border-slate-200 rounded-2xl px-4 py-3 flex items-center gap-3">
|
||||
<Search className="w-5 h-5 text-slate-400" />
|
||||
<div className="flex-1 bg-slate-900/50 backdrop-blur-xl border border-slate-800/60 rounded-xl px-4 py-3 flex items-center gap-3">
|
||||
<Search className="w-5 h-5 text-slate-500" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="ابحث برقم الفاتورة، اسم الشركة، أو التاريخ..."
|
||||
className="bg-transparent border-none outline-none flex-1 text-slate-800 text-sm"
|
||||
className="bg-transparent border-none outline-none flex-1 text-slate-200 text-sm placeholder-slate-500"
|
||||
value={searchTerm}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<button className="glass border-slate-200 px-6 rounded-2xl flex items-center gap-2 text-slate-600 hover:bg-slate-50 transition-all font-semibold">
|
||||
<button className="bg-slate-800/60 border border-slate-700/50 px-6 rounded-xl flex items-center gap-2 text-slate-300 hover:bg-slate-800 transition-all font-bold text-sm">
|
||||
<Filter className="w-4 h-4" />
|
||||
فلترة
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* ── Invoices Table ───────────────────────────────────── */}
|
||||
<div className="flex-1 card-premium overflow-hidden flex flex-col bg-white border border-slate-100">
|
||||
<div className="bg-slate-900/50 backdrop-blur-xl border border-slate-800/60 rounded-2xl overflow-hidden min-h-[400px] flex flex-col">
|
||||
{isLoading ? (
|
||||
<div className="flex-1 flex justify-center items-center">
|
||||
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary-600"></div>
|
||||
<div className="flex-1 flex flex-col justify-center items-center">
|
||||
<Loader2 className="w-8 h-8 text-emerald-500 animate-spin mb-4" />
|
||||
<p className="text-slate-500 text-sm">جاري جلب الفواتير...</p>
|
||||
</div>
|
||||
) : filteredInvoices.length === 0 ? (
|
||||
<div className="flex-1 flex flex-col items-center justify-center p-20 text-center">
|
||||
<div className="w-24 h-24 bg-slate-50 rounded-full flex items-center justify-center mb-6 border border-slate-100">
|
||||
<FileText className="w-10 h-10 text-slate-300" />
|
||||
<div className="w-20 h-20 bg-slate-800 rounded-2xl flex items-center justify-center mb-6 border border-slate-700">
|
||||
<FileText className="w-10 h-10 text-slate-600" />
|
||||
</div>
|
||||
<h3 className="text-xl font-bold text-slate-900 mb-2">لا توجد فواتير بعد</h3>
|
||||
<h3 className="text-xl font-bold text-white mb-2">لا توجد فواتير بعد</h3>
|
||||
<p className="text-slate-500 max-w-sm mb-8">ابدأ برفع أول فاتورة ليقوم محرك الذكاء الاصطناعي باستخراج بياناتها ومصادقتها ضريبياً.</p>
|
||||
<button onClick={() => setIsUploadModalOpen(true)} className="btn-primary py-3 px-8 rounded-2xl flex items-center gap-2">
|
||||
<button onClick={() => setIsUploadModalOpen(true)} className="bg-emerald-500 hover:bg-emerald-600 text-slate-950 font-bold py-3 px-8 rounded-xl transition-all">
|
||||
ارفع فاتورتك الأولى
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-right border-collapse">
|
||||
<thead className="bg-slate-50/80 border-b border-slate-100">
|
||||
<table className="w-full text-right">
|
||||
<thead className="bg-slate-800/50 border-b border-slate-800/60">
|
||||
<tr>
|
||||
<th className="px-6 py-4 text-sm font-bold text-slate-500">رقم الفاتورة</th>
|
||||
<th className="px-6 py-4 text-sm font-bold text-slate-500">الشركة</th>
|
||||
<th className="px-6 py-4 text-sm font-bold text-slate-500">التاريخ</th>
|
||||
<th className="px-6 py-4 text-sm font-bold text-slate-500 text-left">المجموع (JOD)</th>
|
||||
<th className="px-6 py-4 text-sm font-bold text-slate-500">الحالة</th>
|
||||
<th className="px-6 py-4 text-sm font-bold text-slate-500 w-20 text-center">إجراءات</th>
|
||||
<th className="px-6 py-4 text-xs font-bold text-slate-400">رقم الفاتورة</th>
|
||||
<th className="px-6 py-4 text-xs font-bold text-slate-400">الشركة</th>
|
||||
<th className="px-6 py-4 text-xs font-bold text-slate-400">التاريخ</th>
|
||||
<th className="px-6 py-4 text-xs font-bold text-slate-400 text-left">المجموع (JOD)</th>
|
||||
<th className="px-6 py-4 text-xs font-bold text-slate-400">الحالة</th>
|
||||
<th className="px-6 py-4 text-xs font-bold text-slate-400 text-center">إجراءات</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-slate-100">
|
||||
<tbody className="divide-y divide-slate-800/50">
|
||||
{filteredInvoices.map((inv, idx) => (
|
||||
<motion.tr
|
||||
key={inv.id}
|
||||
initial={{ opacity: 0, x: 20 }}
|
||||
animate={{ opacity: 1, x: 0 }}
|
||||
transition={{ delay: idx * 0.05 }}
|
||||
className="hover:bg-slate-50/50 transition-colors group cursor-pointer"
|
||||
className="hover:bg-slate-800/30 transition-colors group cursor-pointer"
|
||||
onClick={() => {
|
||||
setViewingInvoice(inv);
|
||||
setIsViewModalOpen(true);
|
||||
}}
|
||||
>
|
||||
<td className="px-6 py-4 font-bold text-slate-900">{inv.invoice_number || '---'}</td>
|
||||
<td className="px-6 py-4 text-slate-600 font-medium">
|
||||
<td className="px-6 py-4 font-bold text-white">{inv.invoice_number || '---'}</td>
|
||||
<td className="px-6 py-4 text-slate-400">
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-7 h-7 bg-slate-100 rounded-md flex items-center justify-center">
|
||||
<Building2 className="w-4 h-4 text-slate-400" />
|
||||
</div>
|
||||
{inv.company?.name || 'شركة غير معروفة'}
|
||||
<Building2 className="w-4 h-4 text-slate-600" />
|
||||
{inv.company?.name || '---'}
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-6 py-4 text-slate-500 text-sm">
|
||||
{inv.invoice_date ? new Date(inv.invoice_date).toLocaleDateString('ar-JO') : '---'}
|
||||
</td>
|
||||
<td className="px-6 py-4 font-mono font-bold text-slate-800 text-left">
|
||||
<td className="px-6 py-4 font-mono font-bold text-emerald-400 text-left">
|
||||
{Number(inv.grand_total).toLocaleString('en-US', { minimumFractionDigits: 3 })}
|
||||
</td>
|
||||
<td className="px-6 py-4"><StatusBadge invoice={inv} /></td>
|
||||
<td className="px-6 py-4 text-center relative">
|
||||
<div className="flex items-center justify-center gap-2">
|
||||
<td className="px-6 py-4 text-center">
|
||||
<div className="flex items-center justify-center gap-2" onClick={e => e.stopPropagation()}>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setViewingInvoice(inv);
|
||||
setIsViewModalOpen(true);
|
||||
}}
|
||||
className="p-2 text-slate-400 hover:text-primary-600 hover:bg-primary-50 rounded-lg transition-all"
|
||||
title="عرض الفاتورة"
|
||||
onClick={() => { setViewingInvoice(inv); setIsViewModalOpen(true); }}
|
||||
className="p-2 text-slate-500 hover:text-emerald-400 hover:bg-emerald-500/10 rounded-lg transition-all"
|
||||
>
|
||||
<Eye className="w-4 h-4" />
|
||||
</button>
|
||||
|
||||
<div className="relative group/menu">
|
||||
<button
|
||||
className="p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-100 rounded-lg transition-all"
|
||||
>
|
||||
<MoreVertical className="w-4 h-4" />
|
||||
</button>
|
||||
|
||||
{/* Dropdown Menu */}
|
||||
<div className="absolute left-0 mt-2 w-48 bg-white border border-slate-100 rounded-2xl shadow-xl shadow-slate-200/50 opacity-0 invisible group-hover/menu:opacity-100 group-hover/menu:visible transition-all z-10 py-2">
|
||||
<button
|
||||
disabled={submitLoading === inv.id}
|
||||
onClick={(e) => { e.stopPropagation(); handleSubmitToJoFotara(inv); }}
|
||||
className="w-full text-right px-4 py-2 text-sm text-slate-700 hover:bg-slate-50 flex items-center gap-2 disabled:opacity-50"
|
||||
>
|
||||
{submitLoading === inv.id ? (
|
||||
<div className="w-4 h-4 border-2 border-primary-600/30 border-t-primary-600 rounded-full animate-spin" />
|
||||
) : (
|
||||
<Send className="w-4 h-4 text-emerald-500" />
|
||||
)}
|
||||
إرسال لـ جو فوترة
|
||||
</button>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
const token = localStorage.getItem('access_token');
|
||||
window.open(`${apiClient.defaults.baseURL}/invoices/${inv.id}/file?token=${token}`, '_blank');
|
||||
}}
|
||||
className="w-full text-right px-4 py-2 text-sm text-slate-700 hover:bg-slate-50 flex items-center gap-2"
|
||||
>
|
||||
<Download className="w-4 h-4 text-slate-400" />
|
||||
تحميل الملف الأصلي
|
||||
</button>
|
||||
<div className="h-px bg-slate-100 my-1 mx-2" />
|
||||
<button
|
||||
disabled={deleteLoading === inv.id}
|
||||
onClick={(e) => { e.stopPropagation(); handleDelete(inv.id); }}
|
||||
className="w-full text-right px-4 py-2 text-sm text-red-600 hover:bg-red-50 flex items-center gap-2 disabled:opacity-50"
|
||||
>
|
||||
{deleteLoading === inv.id ? (
|
||||
<div className="w-4 h-4 border-2 border-red-600/30 border-t-red-600 rounded-full animate-spin" />
|
||||
) : (
|
||||
<Trash2 className="w-4 h-4" />
|
||||
)}
|
||||
حذف الفاتورة
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => handleDelete(inv.id)}
|
||||
className="p-2 text-slate-500 hover:text-red-400 hover:bg-red-500/10 rounded-lg transition-all"
|
||||
>
|
||||
{deleteLoading === inv.id ? <Loader2 className="w-4 h-4 animate-spin" /> : <Trash2 className="w-4 h-4" />}
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</motion.tr>
|
||||
@@ -325,13 +261,13 @@ export const InvoicesPage = () => {
|
||||
|
||||
{/* ── Pagination ───────────────────────────────────────── */}
|
||||
{!isLoading && filteredInvoices.length > 0 && (
|
||||
<footer className="px-6 py-4 bg-slate-50/50 border-t border-slate-100 flex items-center justify-between">
|
||||
<footer className="px-6 py-4 bg-slate-800/30 border-t border-slate-800/60 flex items-center justify-between mt-auto">
|
||||
<p className="text-sm text-slate-500">عرض {filteredInvoices.length} فواتير</p>
|
||||
<div className="flex gap-2">
|
||||
<button className="p-2 text-slate-400 hover:text-slate-600 disabled:opacity-30 border border-slate-200 rounded-xl bg-white shadow-sm">
|
||||
<button className="p-2 text-slate-500 hover:text-white border border-slate-700 rounded-xl bg-slate-800 transition-all">
|
||||
<ChevronRight className="w-5 h-5" />
|
||||
</button>
|
||||
<button className="p-2 text-slate-400 hover:text-slate-600 disabled:opacity-30 border border-slate-200 rounded-xl bg-white shadow-sm">
|
||||
<button className="p-2 text-slate-500 hover:text-white border border-slate-700 rounded-xl bg-slate-800 transition-all">
|
||||
<ChevronLeft className="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
@@ -342,26 +278,28 @@ export const InvoicesPage = () => {
|
||||
{/* ── Upload Modal ─────────────────────────────────────── */}
|
||||
<AnimatePresence>
|
||||
{isUploadModalOpen && (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-slate-900/60 backdrop-blur-sm">
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-slate-950/80 backdrop-blur-md">
|
||||
<motion.div
|
||||
initial={{ scale: 0.9, opacity: 0 }}
|
||||
animate={{ scale: 1, opacity: 1 }}
|
||||
exit={{ scale: 0.9, opacity: 0 }}
|
||||
className="bg-white rounded-[32px] p-8 w-full max-w-xl shadow-2xl overflow-hidden relative"
|
||||
className="bg-slate-900 border border-slate-800 p-8 w-full max-w-xl rounded-3xl shadow-2xl relative"
|
||||
>
|
||||
<div className="absolute top-0 right-0 w-32 h-32 bg-primary-50 rounded-full -mr-16 -mt-16 opacity-50" />
|
||||
<button onClick={() => setIsUploadModalOpen(false)} className="absolute top-6 left-6 text-slate-500 hover:text-white transition-colors">
|
||||
<X className="w-6 h-6" />
|
||||
</button>
|
||||
|
||||
<h3 className="text-2xl font-bold text-slate-900 mb-2 relative">رفع فاتورة جديدة</h3>
|
||||
<p className="text-slate-500 mb-8 relative">اختر الشركة وملف الفاتورة (PDF أو صورة) وسيقوم الذكاء الاصطناعي بالباقي.</p>
|
||||
<h3 className="text-2xl font-bold text-white mb-2">رفع فاتورة جديدة</h3>
|
||||
<p className="text-slate-400 mb-8 text-sm">اختر الشركة وملف الفاتورة (PDF أو صورة) وسيقوم الذكاء الاصطناعي بالباقي.</p>
|
||||
|
||||
<form onSubmit={handleUpload} className="space-y-6 relative">
|
||||
<form onSubmit={handleUpload} className="space-y-6">
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-slate-700 mb-2">اختر الشركة</label>
|
||||
<label className="block text-sm font-bold text-slate-300 mb-2">اختر الشركة</label>
|
||||
<select
|
||||
required
|
||||
value={selectedCompanyId}
|
||||
onChange={e => setSelectedCompanyId(e.target.value)}
|
||||
className="w-full bg-slate-50 border border-slate-200 rounded-2xl px-5 py-4 outline-none focus:border-primary-500 focus:ring-4 focus:ring-primary-500/10 transition-all appearance-none cursor-pointer"
|
||||
className="w-full bg-slate-800 border border-slate-700 rounded-xl px-5 py-4 outline-none focus:border-emerald-500/50 transition-all text-white appearance-none cursor-pointer"
|
||||
>
|
||||
<option value="">-- اختر شركة --</option>
|
||||
{companies.map(c => (
|
||||
@@ -371,7 +309,7 @@ export const InvoicesPage = () => {
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-slate-700 mb-2">ملف الفاتورة</label>
|
||||
<label className="block text-sm font-bold text-slate-300 mb-2">ملف الفاتورة</label>
|
||||
<div className="relative group">
|
||||
<input
|
||||
type="file"
|
||||
@@ -380,14 +318,12 @@ export const InvoicesPage = () => {
|
||||
accept=".pdf,image/*"
|
||||
className="absolute inset-0 w-full h-full opacity-0 cursor-pointer z-10"
|
||||
/>
|
||||
<div className="border-2 border-dashed border-slate-200 rounded-2xl p-10 flex flex-col items-center group-hover:border-primary-400 group-hover:bg-primary-50/30 transition-all bg-slate-50/50">
|
||||
<div className="w-14 h-14 bg-white rounded-2xl shadow-sm flex items-center justify-center mb-4 group-hover:scale-110 transition-transform">
|
||||
<Upload className="w-7 h-7 text-primary-600" />
|
||||
</div>
|
||||
<p className="font-bold text-slate-800">
|
||||
<div className="border-2 border-dashed border-slate-700 rounded-xl p-10 flex flex-col items-center group-hover:border-emerald-500/50 group-hover:bg-emerald-500/5 transition-all bg-slate-800/50">
|
||||
<Upload className="w-10 h-10 text-slate-600 mb-4 transition-colors group-hover:text-emerald-500" />
|
||||
<p className="font-bold text-slate-300 text-center">
|
||||
{selectedFile ? selectedFile.name : 'اسحب الملف هنا أو انقر للاختيار'}
|
||||
</p>
|
||||
<p className="text-sm text-slate-400 mt-1">PDF, JPG, PNG (حد أقصى 10MB)</p>
|
||||
<p className="text-xs text-slate-500 mt-2">PDF, JPG, PNG (حد أقصى 10MB)</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -396,26 +332,17 @@ export const InvoicesPage = () => {
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setIsUploadModalOpen(false)}
|
||||
className="flex-1 bg-slate-100 text-slate-700 font-bold py-4 rounded-2xl hover:bg-slate-200 transition-all"
|
||||
className="flex-1 bg-slate-800 text-slate-300 font-bold py-4 rounded-xl hover:bg-slate-700 transition-all"
|
||||
>
|
||||
إلغاء
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isUploading || !selectedCompanyId || !selectedFile}
|
||||
className="flex-[2] btn-primary py-4 rounded-2xl shadow-lg shadow-primary-500/30 disabled:opacity-50 flex items-center justify-center gap-3"
|
||||
className="flex-[2] bg-emerald-500 text-slate-950 font-bold py-4 rounded-xl shadow-lg shadow-emerald-500/20 disabled:opacity-50 flex items-center justify-center gap-3 transition-all"
|
||||
>
|
||||
{isUploading ? (
|
||||
<>
|
||||
<div className="w-5 h-5 border-2 border-white/30 border-t-white rounded-full animate-spin" />
|
||||
جاري الرفع والمعالجة...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Upload className="w-5 h-5" />
|
||||
ابدأ المعالجة الآن
|
||||
</>
|
||||
)}
|
||||
{isUploading ? <Loader2 className="w-5 h-5 animate-spin" /> : <Upload className="w-5 h-5" />}
|
||||
{isUploading ? 'جاري المعالجة...' : 'ابدأ المعالجة الآن'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -423,61 +350,45 @@ export const InvoicesPage = () => {
|
||||
</div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
|
||||
{/* ── View Invoice Modal ─────────────────────────────────── */}
|
||||
<AnimatePresence>
|
||||
{isViewModalOpen && viewingInvoice && (
|
||||
<div className="fixed inset-0 z-[60] flex items-center justify-center p-4 bg-slate-900/80 backdrop-blur-md">
|
||||
<div className="fixed inset-0 z-[60] flex items-center justify-center p-4 bg-slate-950/90 backdrop-blur-md">
|
||||
<motion.div
|
||||
initial={{ scale: 0.9, opacity: 0 }}
|
||||
initial={{ scale: 0.95, opacity: 0 }}
|
||||
animate={{ scale: 1, opacity: 1 }}
|
||||
exit={{ scale: 0.9, opacity: 0 }}
|
||||
className="bg-white rounded-[40px] w-full max-w-5xl h-[90vh] shadow-2xl flex flex-col overflow-hidden"
|
||||
exit={{ scale: 0.95, opacity: 0 }}
|
||||
className="bg-slate-900 border border-slate-800 w-full max-w-5xl h-[90vh] rounded-[32px] shadow-2xl flex flex-col overflow-hidden"
|
||||
>
|
||||
<header className="px-8 py-6 border-b border-slate-100 flex items-center justify-between bg-white">
|
||||
<header className="px-8 py-6 border-b border-slate-800 flex items-center justify-between">
|
||||
<div>
|
||||
<h3 className="text-2xl font-bold text-slate-900">معاينة الفاتورة</h3>
|
||||
<p className="text-slate-500 font-medium">رقم: {viewingInvoice.invoice_number || '---'} • {viewingInvoice.company?.name}</p>
|
||||
<h3 className="text-2xl font-bold text-white">معاينة الفاتورة</h3>
|
||||
<p className="text-slate-500 text-sm">رقم: {viewingInvoice.invoice_number || '---'} • {viewingInvoice.company?.name}</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setIsViewModalOpen(false)}
|
||||
className="w-12 h-12 flex items-center justify-center rounded-2xl bg-slate-50 text-slate-400 hover:bg-slate-100 hover:text-slate-600 transition-all"
|
||||
className="w-10 h-10 flex items-center justify-center rounded-xl bg-slate-800 text-slate-500 hover:text-white transition-all"
|
||||
>
|
||||
<ChevronLeft className="w-6 h-6 rotate-180" />
|
||||
<X className="w-6 h-6" />
|
||||
</button>
|
||||
</header>
|
||||
|
||||
{viewingInvoice.validation_errors && viewingInvoice.validation_errors.length > 0 && (
|
||||
<div className="px-8 py-4 bg-red-50 border-b border-red-100 flex items-start gap-3">
|
||||
<AlertCircle className="w-5 h-5 text-red-600 mt-0.5 shrink-0" />
|
||||
<div>
|
||||
<h4 className="text-sm font-bold text-red-900 mb-1">فشل التحقق الضريبي:</h4>
|
||||
<ul className="text-xs text-red-700 space-y-1 list-disc list-inside">
|
||||
{viewingInvoice.validation_errors.map((err: string, i: number) => (
|
||||
<li key={i}>{err}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex-1 overflow-auto bg-slate-100 p-8 flex justify-center items-start">
|
||||
<div className="bg-white shadow-2xl rounded-sm overflow-hidden max-w-full">
|
||||
<div className="flex-1 overflow-auto bg-slate-950 p-8 flex justify-center items-start">
|
||||
<div className="bg-white rounded-lg overflow-hidden shadow-2xl">
|
||||
<img
|
||||
src={`${apiClient.defaults.baseURL}/invoices/${viewingInvoice.id}/file?token=${localStorage.getItem('access_token')}`}
|
||||
alt="Invoice"
|
||||
className="max-w-full h-auto"
|
||||
onError={(e) => {
|
||||
// Fallback for PDF or Error
|
||||
e.currentTarget.style.display = 'none';
|
||||
const token = localStorage.getItem('access_token');
|
||||
e.currentTarget.parentElement!.innerHTML = `
|
||||
<div class="p-20 text-center">
|
||||
<div class="w-20 h-20 bg-slate-50 rounded-full flex items-center justify-center mx-auto mb-4 border border-slate-200">
|
||||
<svg class="w-10 h-10 text-slate-300" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"/><polyline points="14 2 14 8 20 8"/></svg>
|
||||
</div>
|
||||
<h4 class="text-xl font-bold text-slate-900 mb-2">تعذر عرض الصورة مباشرة</h4>
|
||||
<p class="text-slate-500 mb-6">قد يكون الملف بتنسيق PDF أو حدث خطأ أثناء التحميل.</p>
|
||||
<a href="${apiClient.defaults.baseURL}/invoices/${viewingInvoice.id}/file?token=${token}" target="_blank" class="btn-primary px-8 py-3 rounded-xl inline-block">فتح الملف في نافذة جديدة</a>
|
||||
<div class="p-20 text-center bg-slate-900 text-slate-300 w-[600px]">
|
||||
<FileText class="w-16 h-16 text-slate-700 mx-auto mb-4" />
|
||||
<h4 class="text-xl font-bold text-white mb-2">تعذر عرض الملف</h4>
|
||||
<p class="text-slate-500 mb-8">قد يكون الملف PDF أو حدث خطأ في التحميل.</p>
|
||||
<a href="${apiClient.defaults.baseURL}/invoices/${viewingInvoice.id}/file?token=${token}" target="_blank" class="px-8 py-3 bg-emerald-500 text-slate-950 font-bold rounded-xl inline-block">تحميل الملف لفتحه</a>
|
||||
</div>
|
||||
`;
|
||||
}}
|
||||
@@ -485,15 +396,15 @@ export const InvoicesPage = () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer className="px-8 py-6 border-t border-slate-100 flex items-center justify-between bg-slate-50/50">
|
||||
<div className="flex items-center gap-6">
|
||||
<footer className="px-8 py-6 border-t border-slate-800 bg-slate-900/50 flex items-center justify-between">
|
||||
<div className="flex items-center gap-8">
|
||||
<div>
|
||||
<p className="text-[10px] uppercase tracking-widest text-slate-400 font-bold mb-1">المجموع الكلي</p>
|
||||
<p className="text-xl font-black text-primary-700">{Number(viewingInvoice.grand_total).toLocaleString('en-US', { minimumFractionDigits: 3 })} JOD</p>
|
||||
<p className="text-[10px] uppercase tracking-widest text-slate-500 font-bold mb-1">المجموع الكلي</p>
|
||||
<p className="text-xl font-black text-emerald-400">{Number(viewingInvoice.grand_total).toLocaleString('en-US', { minimumFractionDigits: 3 })} JOD</p>
|
||||
</div>
|
||||
<div className="w-px h-10 bg-slate-200" />
|
||||
<div className="w-px h-10 bg-slate-800" />
|
||||
<div>
|
||||
<p className="text-[10px] uppercase tracking-widest text-slate-400 font-bold mb-1">الحالة</p>
|
||||
<p className="text-[10px] uppercase tracking-widest text-slate-500 font-bold mb-1">الحالة</p>
|
||||
<StatusBadge invoice={viewingInvoice} />
|
||||
</div>
|
||||
</div>
|
||||
@@ -503,19 +414,16 @@ export const InvoicesPage = () => {
|
||||
const token = localStorage.getItem('access_token');
|
||||
window.open(`${apiClient.defaults.baseURL}/invoices/${viewingInvoice.id}/file?token=${token}`, '_blank');
|
||||
}}
|
||||
className="px-6 py-3 rounded-xl bg-white border border-slate-200 text-slate-700 font-bold flex items-center gap-2 hover:bg-slate-50 transition-all shadow-sm"
|
||||
className="px-6 py-3 rounded-xl bg-slate-800 border border-slate-700 text-slate-300 font-bold flex items-center gap-2 hover:bg-slate-700 transition-all"
|
||||
>
|
||||
<Download className="w-4 h-4" />
|
||||
تحميل الأصلي
|
||||
تحميل
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
setIsViewModalOpen(false);
|
||||
handleSubmitToJoFotara(viewingInvoice);
|
||||
}}
|
||||
className="btn-primary px-8 py-3 rounded-xl flex items-center gap-2 shadow-lg shadow-primary-500/20"
|
||||
onClick={() => handleSubmitToJoFotara(viewingInvoice)}
|
||||
className="bg-emerald-500 hover:bg-emerald-600 text-slate-950 font-bold px-8 py-3 rounded-xl flex items-center gap-2 shadow-lg shadow-emerald-500/20 transition-all"
|
||||
>
|
||||
<Send className="w-4 h-4" />
|
||||
{submitLoading === viewingInvoice.id ? <Loader2 className="w-5 h-5 animate-spin" /> : <Send className="w-4 h-4" />}
|
||||
إرسال لجو فوترة
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user