Update: 2026-05-07 03:06:15

This commit is contained in:
Hamza-Ayed
2026-05-07 03:06:15 +03:00
parent 272971fc5b
commit bfb6368ec8
28 changed files with 3292 additions and 188 deletions

View File

@@ -8,90 +8,92 @@ class DashboardView extends GetView<DashboardController> {
@override
Widget build(BuildContext context) {
// We instantiate the controller here if not bound, though we should use binding in routes.
// For safety, let's put it here or rely on the router binding.
Get.put(DashboardController());
final isDark = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
backgroundColor: const Color(0xFFF5F7FA),
appBar: AppBar(
title: const Text('لوحة التحكم - مُصادَق', style: TextStyle(fontWeight: FontWeight.bold)),
backgroundColor: const Color(0xFF0F4C81),
foregroundColor: Colors.white,
elevation: 0,
actions: [
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () => controller.refreshData(),
return Column(
children: [
// Custom Top Bar
Container(
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top, left: 8, right: 8, bottom: 12),
color: isDark ? const Color(0xFF1E1E2E) : const Color(0xFF0F4C81),
child: Row(
children: [
const SizedBox(width: 48),
Expanded(
child: Center(
child: Text(
'مُصادَق',
style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold),
),
),
),
IconButton(
icon: const Icon(Icons.notifications_outlined, color: Colors.white),
onPressed: () => Get.snackbar('قريباً', 'الإشعارات ستتوفر قريباً'),
),
IconButton(
icon: const Icon(Icons.refresh, color: Colors.white),
onPressed: () => controller.refreshData(),
),
],
),
IconButton(
icon: const Icon(Icons.logout),
onPressed: () => controller.logout(),
)
],
),
body: Obx(() {
if (controller.isLoading.value) {
return const Center(child: CircularProgressIndicator(color: Color(0xFF0F4C81)));
}
),
Expanded(
child: Obx(() {
if (controller.isLoading.value) {
return const Center(child: CircularProgressIndicator(color: Color(0xFF0F4C81)));
}
final stats = controller.stats;
final role = controller.userRole.value;
final stats = controller.stats;
final role = controller.userRole.value;
return RefreshIndicator(
onRefresh: () async => controller.refreshData(),
child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildWelcomeHeader(role),
const SizedBox(height: 24),
// Action Buttons
_buildQuickActions(),
const SizedBox(height: 32),
// Invoice Stats
const Text('إحصائيات الفواتير', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(height: 12),
_buildInvoiceStats(stats),
// Role Specific Stats (Companies, Users, Tenants)
if (role == 'admin' || role == 'super_admin') ...[
const SizedBox(height: 24),
const Text('نظرة عامة', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(height: 12),
_buildRoleSpecificStats(stats, role),
],
// Quota
if (role == 'admin' && stats['subscription'] != null) ...[
const SizedBox(height: 24),
_buildQuotaMeter(stats['subscription']),
],
const SizedBox(height: 32),
const Text('أحدث النشاطات', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(height: 12),
_buildRecentActivity(),
const SizedBox(height: 40),
],
),
),
);
}),
return RefreshIndicator(
onRefresh: () async => controller.refreshData(),
child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildWelcomeHeader(role, isDark),
const SizedBox(height: 24),
_buildQuickActions(isDark),
const SizedBox(height: 32),
const Text('إحصائيات الفواتير', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(height: 12),
_buildInvoiceStats(stats, isDark),
if (role == 'admin' || role == 'super_admin') ...[
const SizedBox(height: 24),
const Text('نظرة عامة', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(height: 12),
_buildRoleSpecificStats(stats, role, isDark),
],
if (role == 'admin' && stats['subscription'] != null) ...[
const SizedBox(height: 24),
_buildQuotaMeter(stats['subscription'], isDark),
],
const SizedBox(height: 32),
const Text('أحدث النشاطات', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(height: 12),
_buildRecentActivity(isDark),
const SizedBox(height: 40),
],
),
),
);
}),
),
],
);
}
Widget _buildWelcomeHeader(String role) {
Widget _buildWelcomeHeader(String role, bool isDark) {
String roleName = 'مستخدم';
switch (role) {
case 'super_admin': roleName = 'مدير النظام'; break;
case 'admin': roleName = 'مدير المكتب'; break;
case 'accountant': roleName = 'محاسب'; break;
case 'viewer': roleName = 'مشاهد'; break;
}
return Row(
@@ -106,20 +108,20 @@ class DashboardView extends GetView<DashboardController> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('مرحباً بك في مُصادَق 👋', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
Text('صلاحيات: $roleName', style: const TextStyle(color: Colors.grey, fontSize: 14)),
Text('صلاحيات: $roleName', style: TextStyle(color: isDark ? Colors.white38 : Colors.grey, fontSize: 14)),
],
),
],
);
}
Widget _buildQuickActions() {
Widget _buildQuickActions(bool isDark) {
return Row(
children: [
Expanded(
child: ElevatedButton.icon(
icon: const Icon(Icons.document_scanner),
label: const Text('المسح الضوئي', style: TextStyle(fontWeight: FontWeight.bold)),
label: const Text('المسح الضوئي', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 13)),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF0F4C81),
foregroundColor: Colors.white,
@@ -130,69 +132,66 @@ class DashboardView extends GetView<DashboardController> {
),
),
const SizedBox(width: 12),
if (controller.userRole.value == 'admin')
Expanded(
child: OutlinedButton.icon(
icon: const Icon(Icons.business),
label: const Text('إدارة الشركات', style: TextStyle(fontWeight: FontWeight.bold)),
style: OutlinedButton.styleFrom(
foregroundColor: const Color(0xFF0F4C81),
side: const BorderSide(color: Color(0xFF0F4C81)),
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
onPressed: () {
Get.snackbar('قريباً', 'سيتم إطلاق هذه الميزة قريباً');
},
Expanded(
child: OutlinedButton.icon(
icon: const Icon(Icons.mic_rounded),
label: const Text('المساعد الصوتي', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 13)),
style: OutlinedButton.styleFrom(
foregroundColor: isDark ? const Color(0xFF5EEAD4) : const Color(0xFF0F4C81),
side: BorderSide(color: isDark ? const Color(0xFF5EEAD4) : const Color(0xFF0F4C81)),
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
onPressed: () {
Get.snackbar('المساعد الصوتي', 'يتم تجهيز خوادم AI (Grok & Gemini) للاستماع لأوامرك...');
},
),
),
],
);
}
Widget _buildInvoiceStats(Map stats) {
Widget _buildInvoiceStats(Map stats, bool isDark) {
final inv = stats['invoices'] ?? {'total': 0, 'pending': 0, 'approved': 0};
return Row(
children: [
_buildStatCard('الكل', inv['total'].toString(), Icons.receipt_long, Colors.blue),
_buildStatCard('الكل', inv['total'].toString(), Icons.receipt_long, Colors.blue, isDark),
const SizedBox(width: 12),
_buildStatCard('قيد المعالجة', inv['pending'].toString(), Icons.hourglass_empty, Colors.orange),
_buildStatCard('قيد المعالجة', inv['pending'].toString(), Icons.hourglass_empty, Colors.orange, isDark),
const SizedBox(width: 12),
_buildStatCard('معتمدة', inv['approved'].toString(), Icons.check_circle, Colors.green),
_buildStatCard('معتمدة', inv['approved'].toString(), Icons.check_circle, Colors.green, isDark),
],
);
}
Widget _buildRoleSpecificStats(Map stats, String role) {
Widget _buildRoleSpecificStats(Map stats, String role, bool isDark) {
if (role == 'super_admin') {
return Row(
children: [
_buildStatCard('المستأجرين', (stats['tenants'] ?? 0).toString(), Icons.business_center, Colors.indigo),
_buildStatCard('المستأجرين', (stats['tenants'] ?? 0).toString(), Icons.business_center, Colors.indigo, isDark),
const SizedBox(width: 12),
_buildStatCard('المستخدمين', (stats['total_users'] ?? 0).toString(), Icons.people, Colors.purple),
_buildStatCard('المستخدمين', (stats['total_users'] ?? 0).toString(), Icons.people, Colors.purple, isDark),
],
);
} else {
return Row(
children: [
_buildStatCard('الشركات', (stats['companies'] ?? 0).toString(), Icons.business, Colors.indigo),
_buildStatCard('الشركات', (stats['companies'] ?? 0).toString(), Icons.business, Colors.indigo, isDark),
const SizedBox(width: 12),
_buildStatCard('المستخدمين', (stats['users'] ?? 0).toString(), Icons.people, Colors.purple),
_buildStatCard('المستخدمين', (stats['users'] ?? 0).toString(), Icons.people, Colors.purple, isDark),
],
);
}
}
Widget _buildStatCard(String title, String count, IconData icon, Color color) {
Widget _buildStatCard(String title, String count, IconData icon, Color color, bool isDark) {
return Expanded(
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
color: isDark ? const Color(0xFF1E1E2E) : Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10, offset: const Offset(0, 4)),
],
border: Border.all(color: isDark ? Colors.white10 : Colors.grey.shade200),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -200,14 +199,14 @@ class DashboardView extends GetView<DashboardController> {
Icon(icon, color: color, size: 28),
const SizedBox(height: 12),
Text(count, style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
Text(title, style: const TextStyle(color: Colors.grey, fontSize: 12)),
Text(title, style: TextStyle(color: isDark ? Colors.white38 : Colors.grey, fontSize: 12)),
],
),
),
);
}
Widget _buildQuotaMeter(Map subscription) {
Widget _buildQuotaMeter(Map subscription, bool isDark) {
int limit = subscription['limit'] ?? 100;
int used = subscription['used'] ?? 0;
double progress = limit > 0 ? (used / limit) : 0;
@@ -215,9 +214,9 @@ class DashboardView extends GetView<DashboardController> {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
color: isDark ? const Color(0xFF1E1E2E) : Colors.white,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: const Color(0xFFE2E8F0)),
border: Border.all(color: isDark ? Colors.white10 : Colors.grey.shade200),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -226,7 +225,7 @@ class DashboardView extends GetView<DashboardController> {
const SizedBox(height: 12),
LinearProgressIndicator(
value: progress,
backgroundColor: Colors.grey.shade200,
backgroundColor: isDark ? Colors.white10 : Colors.grey.shade200,
color: progress > 0.9 ? Colors.red : const Color(0xFF0F4C81),
minHeight: 8,
borderRadius: BorderRadius.circular(4),
@@ -236,7 +235,7 @@ class DashboardView extends GetView<DashboardController> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('$used فاتورة', style: const TextStyle(fontWeight: FontWeight.bold, color: Color(0xFF0F4C81))),
Text('من $limit', style: const TextStyle(color: Colors.grey)),
Text('من $limit', style: TextStyle(color: isDark ? Colors.white38 : Colors.grey)),
],
)
],
@@ -244,9 +243,9 @@ class DashboardView extends GetView<DashboardController> {
);
}
Widget _buildRecentActivity() {
Widget _buildRecentActivity(bool isDark) {
if (controller.recentActivities.isEmpty) {
return const Center(child: Text('لا توجد نشاطات حديثة', style: TextStyle(color: Colors.grey)));
return Center(child: Text('لا توجد نشاطات حديثة', style: TextStyle(color: isDark ? Colors.white38 : Colors.grey)));
}
return ListView.builder(
@@ -258,14 +257,14 @@ class DashboardView extends GetView<DashboardController> {
return Card(
margin: const EdgeInsets.only(bottom: 8),
elevation: 0,
color: Colors.white,
color: isDark ? const Color(0xFF1E1E2E) : Colors.white,
shape: RoundedRectangleBorder(
side: const BorderSide(color: Color(0xFFE2E8F0)),
side: BorderSide(color: isDark ? Colors.white10 : Colors.grey.shade200),
borderRadius: BorderRadius.circular(12),
),
child: ListTile(
leading: CircleAvatar(
backgroundColor: const Color(0xFFF1F5F9),
backgroundColor: isDark ? Colors.white10 : const Color(0xFFF1F5F9),
child: Icon(_getActivityIcon(act['action']), color: const Color(0xFF64748B), size: 18),
),
title: Text(_formatAction(act['action'])),
@@ -282,6 +281,7 @@ class DashboardView extends GetView<DashboardController> {
IconData _getActivityIcon(String action) {
if (action.contains('approved')) return Icons.check_circle;
if (action.contains('extracted')) return Icons.auto_awesome;
if (action.contains('created')) return Icons.add_circle;
if (action.contains('deleted')) return Icons.delete;
if (action.contains('login')) return Icons.login;
@@ -302,7 +302,6 @@ class DashboardView extends GetView<DashboardController> {
}
String _timeAgo(String datetime) {
// A simple timeAgo formatter for demo purposes
try {
final dt = DateTime.parse(datetime);
final diff = DateTime.now().difference(dt);