Update: 2026-05-08 00:26:39

This commit is contained in:
Hamza-Ayed
2026-05-08 00:26:40 +03:00
parent 51d1d42f75
commit 08e2a87c10
24 changed files with 1743 additions and 210 deletions

View File

@@ -18,6 +18,7 @@ import '../../features/onboarding/views/onboarding_view.dart';
import '../../features/onboarding/controllers/onboarding_controller.dart';
import '../../core/storage/secure_storage.dart';
import '../../features/companies/views/companies_management_view.dart';
import '../../features/companies/views/company_stats_view.dart';
import '../../features/users/views/users_management_view.dart';
import '../../features/tenants/views/tenants_management_view.dart';
@@ -138,6 +139,10 @@ class AppPages {
name: AppRoutes.COMPANIES_MANAGEMENT,
page: () => const CompaniesManagementView(),
),
GetPage(
name: AppRoutes.COMPANY_STATS,
page: () => const CompanyStatsView(),
),
GetPage(
name: AppRoutes.TENANTS_MANAGEMENT,
page: () => const TenantsManagementView(),

View File

@@ -18,6 +18,7 @@ abstract class AppRoutes {
static const INVOICE_DETAIL = '/invoice-detail';
static const ONBOARDING = '/onboarding';
static const COMPANIES_MANAGEMENT = '/companies-management';
static const COMPANY_STATS = '/company-stats';
static const TENANTS_MANAGEMENT = '/tenants-management';
static const USERS_MANAGEMENT = '/users-management';
}

View File

@@ -0,0 +1,43 @@
import 'package:get/get.dart';
import 'package:dio/dio.dart';
import '../../../core/network/dio_client.dart';
import '../../../core/utils/logger.dart';
import '../../../core/utils/app_snackbar.dart';
class CompanyStatsController extends GetxController {
final Dio _dio = DioClient().client;
var isLoading = false.obs;
var company = <String, dynamic>{}.obs;
var totals = <String, dynamic>{}.obs;
var monthly = <Map<String, dynamic>>[].obs;
final String companyId;
final String companyName;
CompanyStatsController({required this.companyId, required this.companyName});
@override
void onInit() {
super.onInit();
fetchStats();
}
Future<void> fetchStats() async {
try {
isLoading.value = true;
final response = await _dio.get('companies/stats?company_id=$companyId');
if (response.data['success'] == true) {
final data = response.data['data'];
company.value = Map<String, dynamic>.from(data['company'] ?? {});
totals.value = Map<String, dynamic>.from(data['totals'] ?? {});
monthly.value = List<Map<String, dynamic>>.from(data['monthly'] ?? []);
}
} catch (e) {
AppLogger.error('Company stats error', e);
AppSnackbar.showError('خطأ', 'فشل تحميل الإحصائيات');
} finally {
isLoading.value = false;
}
}
}

View File

@@ -0,0 +1,394 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controllers/company_stats_controller.dart';
class CompanyStatsView extends StatelessWidget {
const CompanyStatsView({super.key});
@override
Widget build(BuildContext context) {
final args = Get.arguments as Map<String, dynamic>;
final controller = Get.put(
CompanyStatsController(
companyId: args['company_id'],
companyName: args['company_name'],
),
tag: args['company_id'],
);
final isDark = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
appBar: AppBar(
title: Text(
'إحصائيات ${args['company_name']}',
style: const TextStyle(fontFamily: 'El Messiri', fontSize: 16),
overflow: TextOverflow.ellipsis,
),
centerTitle: true,
backgroundColor: const Color(0xFF0F4C81),
foregroundColor: Colors.white,
elevation: 0,
actions: [
Obx(() => controller.isLoading.value
? const Padding(
padding: EdgeInsets.all(14),
child: SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
color: Colors.white, strokeWidth: 2),
),
)
: IconButton(
icon: const Icon(Icons.refresh),
onPressed: controller.fetchStats,
)),
],
),
body: Obx(() {
if (controller.isLoading.value && controller.totals.isEmpty) {
return const Center(child: CircularProgressIndicator());
}
if (controller.totals.isEmpty) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.bar_chart_outlined,
size: 80, color: Colors.grey.shade400),
const SizedBox(height: 16),
const Text('لا توجد بيانات بعد',
style: TextStyle(fontSize: 18, color: Colors.grey)),
],
),
);
}
final totals = controller.totals;
final monthly = controller.monthly;
return RefreshIndicator(
onRefresh: controller.fetchStats,
child: ListView(
padding: const EdgeInsets.all(16),
children: [
// ── Lifetime Totals ──────────────────────────────
_sectionTitle('الإحصائيات الإجمالية', isDark),
const SizedBox(height: 12),
GridView.count(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
crossAxisCount: 2,
mainAxisSpacing: 12,
crossAxisSpacing: 12,
childAspectRatio: 1.6,
children: [
_statCard(
icon: Icons.receipt_long_rounded,
label: 'إجمالي الفواتير',
value: _fmt(totals['total_invoices']),
color: const Color(0xFF0F4C81),
isDark: isDark,
),
_statCard(
icon: Icons.check_circle_rounded,
label: 'فواتير معتمدة',
value: _fmt(totals['approved_count']),
color: const Color(0xFF10B981),
isDark: isDark,
),
_statCard(
icon: Icons.attach_money_rounded,
label: 'إجمالي المبيعات',
value: '${_fmtAmount(totals['total_amount'])} د.أ',
color: const Color(0xFFD4AF37),
isDark: isDark,
),
_statCard(
icon: Icons.percent_rounded,
label: 'إجمالي الضريبة',
value: '${_fmtAmount(totals['total_tax'])} د.أ',
color: const Color(0xFF8B5CF6),
isDark: isDark,
),
],
),
// Approval Rate
const SizedBox(height: 20),
_buildApprovalRateCard(totals, isDark),
// ── Monthly Breakdown ────────────────────────────
if (monthly.isNotEmpty) ...[
const SizedBox(height: 24),
_sectionTitle('التفاصيل الشهرية (آخر 12 شهر)', isDark),
const SizedBox(height: 12),
...monthly.map((m) => _buildMonthRow(m, isDark)),
],
],
),
);
}),
);
}
Widget _sectionTitle(String title, bool isDark) {
return Row(
children: [
Container(
width: 4,
height: 20,
decoration: BoxDecoration(
color: const Color(0xFF0F4C81),
borderRadius: BorderRadius.circular(2),
),
),
const SizedBox(width: 10),
Text(
title,
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
],
);
}
Widget _statCard({
required IconData icon,
required String label,
required String value,
required Color color,
required bool isDark,
}) {
return Container(
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF1E1E2E) : Colors.white,
borderRadius: BorderRadius.circular(14),
border:
Border.all(color: isDark ? Colors.white10 : Colors.grey.shade200),
boxShadow: isDark
? []
: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.04),
blurRadius: 8,
offset: const Offset(0, 2))
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: [
Container(
padding: const EdgeInsets.all(6),
decoration: BoxDecoration(
color: color.withValues(alpha: 0.1),
shape: BoxShape.circle,
),
child: Icon(icon, color: color, size: 18),
),
const SizedBox(width: 8),
Expanded(
child: Text(label,
style: TextStyle(
fontSize: 11,
color: isDark ? Colors.white54 : Colors.grey.shade600),
overflow: TextOverflow.ellipsis),
),
],
),
const SizedBox(height: 8),
Text(
value,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: color,
),
),
],
),
);
}
Widget _buildApprovalRateCard(Map<String, dynamic> totals, bool isDark) {
final total =
int.tryParse(totals['total_invoices']?.toString() ?? '0') ?? 0;
final approved =
int.tryParse(totals['approved_count']?.toString() ?? '0') ?? 0;
final rate = total > 0 ? (approved / total) : 0.0;
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF1E1E2E) : Colors.white,
borderRadius: BorderRadius.circular(14),
border:
Border.all(color: isDark ? Colors.white10 : Colors.grey.shade200),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('نسبة القبول',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14)),
Text(
'${(rate * 100).toStringAsFixed(1)}%',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
color: rate > 0.8
? const Color(0xFF10B981)
: rate > 0.5
? const Color(0xFFD4AF37)
: const Color(0xFFDC2626),
),
),
],
),
const SizedBox(height: 10),
ClipRRect(
borderRadius: BorderRadius.circular(4),
child: LinearProgressIndicator(
value: rate,
minHeight: 8,
color: rate > 0.8
? const Color(0xFF10B981)
: rate > 0.5
? const Color(0xFFD4AF37)
: const Color(0xFFDC2626),
backgroundColor:
isDark ? Colors.white10 : const Color(0xFFE2E8F0),
),
),
const SizedBox(height: 8),
Text(
'$approved معتمدة من أصل $total فاتورة',
style: TextStyle(
fontSize: 12,
color: isDark ? Colors.white54 : Colors.grey.shade600),
),
],
),
);
}
Widget _buildMonthRow(Map<String, dynamic> m, bool isDark) {
return Container(
margin: const EdgeInsets.only(bottom: 10),
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF1E1E2E) : Colors.white,
borderRadius: BorderRadius.circular(12),
border:
Border.all(color: isDark ? Colors.white10 : Colors.grey.shade200),
),
child: Row(
children: [
// Month label
Container(
width: 56,
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 4),
decoration: BoxDecoration(
color: const Color(0xFF0F4C81).withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
),
child: Text(
_formatMonth(m['month']?.toString() ?? ''),
style: const TextStyle(
fontSize: 11,
fontWeight: FontWeight.bold,
color: Color(0xFF0F4C81),
),
textAlign: TextAlign.center,
),
),
const SizedBox(width: 12),
// Stats
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Icon(Icons.receipt_long_rounded,
size: 14, color: Colors.grey),
const SizedBox(width: 4),
Text('${_fmt(m['total_invoices'])} فاتورة',
style: const TextStyle(
fontSize: 12, fontWeight: FontWeight.w600)),
const SizedBox(width: 12),
const Icon(Icons.check_circle_outline,
size: 14, color: Color(0xFF10B981)),
const SizedBox(width: 4),
Text('${_fmt(m['approved_count'])} معتمدة',
style: const TextStyle(
fontSize: 12, color: Color(0xFF10B981))),
],
),
const SizedBox(height: 4),
Row(
children: [
Text(
'${_fmtAmount(m['total_amount'])} د.أ مبيعات',
style: TextStyle(
fontSize: 12,
color: isDark ? Colors.white70 : Colors.black87),
),
const SizedBox(width: 12),
Text(
'${_fmtAmount(m['total_tax'])} د.أ ضريبة',
style: const TextStyle(
fontSize: 12, color: Color(0xFF8B5CF6)),
),
],
),
],
),
),
],
),
);
}
String _fmt(dynamic v) {
if (v == null) return '0';
return int.tryParse(v.toString())?.toString() ?? v.toString();
}
String _fmtAmount(dynamic v) {
if (v == null) return '0.000';
final d = double.tryParse(v.toString()) ?? 0;
return d.toStringAsFixed(3);
}
String _formatMonth(String m) {
if (m.isEmpty) return m;
final parts = m.split('-');
if (parts.length < 2) return m;
final months = [
'',
'يناير',
'فبراير',
'مارس',
'أبريل',
'مايو',
'يونيو',
'يوليو',
'أغسطس',
'سبتمبر',
'أكتوبر',
'نوفمبر',
'ديسمبر'
];
final monthIndex = int.tryParse(parts[1]) ?? 0;
final monthName = monthIndex > 0 && monthIndex < months.length
? months[monthIndex]
: parts[1];
return '$monthName\n${parts[0]}';
}
}

View File

@@ -89,4 +89,48 @@ class InvoiceDetailController extends GetxController {
AppSnackbar.showWarning('عذراً', 'لا توجد صورة مرتبطة بهذه الفاتورة');
}
}
Future<void> submitToJoFotara() async {
// Confirmation dialog
final confirmed = await Get.dialog<bool>(
AlertDialog(
title: const Text('تأكيد الإرسال'),
content: const Text(
'هل أنت متأكد من إرسال هذه الفاتورة لمنظومة جوفتورة؟\nلا يمكن التراجع عن هذا الإجراء.'),
actions: [
TextButton(
onPressed: () => Get.back(result: false),
child: const Text('إلغاء'),
),
ElevatedButton(
onPressed: () => Get.back(result: true),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF6366F1),
),
child: const Text('إرسال', style: TextStyle(color: Colors.white)),
),
],
),
);
if (confirmed != true) return;
try {
AppSnackbar.showInfo('جاري الإرسال', 'يتم إرسال الفاتورة لمنظومة جوفتورة...');
final res = await DioClient().client.post(
'invoices/submit-jofotara',
data: {'invoice_id': invoiceId},
);
if (res.data['success'] == true) {
AppSnackbar.showSuccess('تم الإرسال', 'تم تقديم الفاتورة لجوفتورة بنجاح');
fetchInvoiceDetails(); // Refresh to show JoFotara status
} else {
AppSnackbar.showError('خطأ', res.data['message'] ?? 'فشل الإرسال');
}
} catch (e) {
AppLogger.error('Failed to submit to JoFotara', e);
AppSnackbar.showError('خطأ', 'فشل إرسال الفاتورة لجوفتورة');
}
}
}

View File

@@ -80,6 +80,7 @@ class InvoicesController extends GetxController {
'approved',
'extracted',
'uploaded',
'submitted',
'rejected',
};

View File

@@ -17,6 +17,12 @@ class InvoiceDetailView extends StatelessWidget {
backgroundColor: isDark ? const Color(0xFF1E1E2E) : const Color(0xFF0F4C81),
foregroundColor: Colors.white,
elevation: 0,
actions: [
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () => controller.fetchInvoiceDetails(),
),
],
),
body: Obx(() {
if (controller.isLoading.value) {
@@ -29,103 +35,49 @@ class InvoiceDetailView extends StatelessWidget {
final inv = controller.invoice;
final status = inv['status'] ?? 'pending';
final items = (inv['items'] as List?) ?? [];
final warnings = (inv['validation_warnings'] as List?) ?? [];
final jofotara = inv['jofotara'];
return SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Header Card
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF1E1E2E) : Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: isDark ? Colors.white10 : Colors.grey.shade200),
),
child: Column(
children: [
Text(
inv['supplier_name'] ?? inv['company_name'] ?? 'بدون اسم',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: isDark ? Colors.white : const Color(0xFF0F172A),
),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(
'فاتورة ضريبية',
style: TextStyle(color: isDark ? Colors.white70 : Colors.grey.shade600),
),
const SizedBox(height: 16),
Text(
'${double.tryParse(inv['grand_total']?.toString() ?? '0')?.toStringAsFixed(2) ?? '0.00'} JOD',
style: TextStyle(
fontSize: 32,
fontWeight: FontWeight.w900,
color: isDark ? const Color(0xFF5EEAD4) : const Color(0xFF0F4C81),
fontFamily: 'monospace',
),
),
const SizedBox(height: 16),
_buildStatusChip(status),
],
),
),
// ─── Header Card ───
_buildHeaderCard(inv, status, isDark),
const SizedBox(height: 16),
// Details Card
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF1E1E2E) : Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: isDark ? Colors.white10 : Colors.grey.shade200),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('المعلومات الأساسية', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
const SizedBox(height: 16),
_buildInfoRow('رقم الفاتورة', inv['invoice_number'] ?? '', isDark),
const Divider(height: 24),
_buildInfoRow('تاريخ الإصدار', inv['invoice_date'] ?? '', isDark),
const Divider(height: 24),
_buildInfoRow('الرقم الضريبي', inv['tax_number'] ?? '', isDark),
],
),
),
// ─── AI Warnings ───
if (warnings.isNotEmpty) ...[
_buildWarningsCard(warnings, isDark),
const SizedBox(height: 16),
],
// ─── JoFotara Status ───
if (jofotara != null) ...[
_buildJoFotaraCard(jofotara, isDark),
const SizedBox(height: 16),
],
// ─── Supplier & Buyer ───
_buildPartiesCard(inv, isDark),
const SizedBox(height: 16),
// Amounts Card
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF1E1E2E) : Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: isDark ? Colors.white10 : Colors.grey.shade200),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('تفاصيل المبلغ', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
const SizedBox(height: 16),
_buildInfoRow('المبلغ الخاضع للضريبة', '${inv['subtotal'] ?? '0.00'} JOD', isDark),
const Divider(height: 24),
_buildInfoRow('قيمة الضريبة', '${inv['tax_amount'] ?? '0.00'} JOD', isDark),
const Divider(height: 24),
_buildInfoRow('الإجمالي', '${inv['grand_total'] ?? '0.00'} JOD', isDark, isBold: true),
],
),
),
// ─── Invoice Lines ───
if (items.isNotEmpty) ...[
_buildLinesCard(items, isDark),
const SizedBox(height: 16),
],
// ─── Amounts Card ───
_buildAmountsCard(inv, isDark),
const SizedBox(height: 32),
// Action Buttons
// ─── Action Buttons ───
if (status == 'extracted') ...[
SizedBox(
height: 52,
@@ -156,6 +108,24 @@ class InvoiceDetailView extends StatelessWidget {
label: const Text('عرض صورة الفاتورة الأصلية', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
),
),
if (jofotara == null && status == 'approved') ...[
const SizedBox(height: 12),
SizedBox(
height: 52,
child: ElevatedButton.icon(
onPressed: () => controller.submitToJoFotara(),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF6366F1),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
icon: const Icon(Icons.send_rounded),
label: const Text('إرسال لجوفتورة', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
),
),
],
const SizedBox(height: 40),
],
),
@@ -164,24 +134,391 @@ class InvoiceDetailView extends StatelessWidget {
);
}
// ─────────────────────────────────────────────
// Header Card
// ─────────────────────────────────────────────
Widget _buildHeaderCard(Map inv, String status, bool isDark) {
return Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF1E1E2E) : Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: isDark ? Colors.white10 : Colors.grey.shade200),
),
child: Column(
children: [
Text(
inv['supplier_name'] ?? inv['company_name'] ?? 'بدون اسم',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: isDark ? Colors.white : const Color(0xFF0F172A),
),
textAlign: TextAlign.center,
),
const SizedBox(height: 4),
Text(
'فاتورة ضريبية ${inv['invoice_type'] == 'credit' ? '(آجل)' : '(نقدية)'}',
style: TextStyle(color: isDark ? Colors.white70 : Colors.grey.shade600, fontSize: 13),
),
const SizedBox(height: 16),
Text(
'${_formatAmount(inv['grand_total'])} JOD',
style: TextStyle(
fontSize: 32,
fontWeight: FontWeight.w900,
color: isDark ? const Color(0xFF5EEAD4) : const Color(0xFF0F4C81),
fontFamily: 'monospace',
),
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildStatusChip(status),
if (inv['ai_confidence'] != null) ...[
const SizedBox(width: 8),
_buildConfidenceChip(inv['ai_confidence'], isDark),
],
],
),
],
),
);
}
// ─────────────────────────────────────────────
// AI Validation Warnings
// ─────────────────────────────────────────────
Widget _buildWarningsCard(List warnings, bool isDark) {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF2D1F00) : const Color(0xFFFFF7ED),
borderRadius: BorderRadius.circular(16),
border: Border.all(color: const Color(0xFFF59E0B).withValues(alpha: 0.3)),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Icon(Icons.warning_amber_rounded, color: Color(0xFFF59E0B), size: 20),
const SizedBox(width: 8),
Text(
'تحذيرات التدقيق الآلي (${warnings.length})',
style: const TextStyle(fontWeight: FontWeight.bold, color: Color(0xFFF59E0B)),
),
],
),
const SizedBox(height: 12),
...warnings.map((w) => Padding(
padding: const EdgeInsets.only(bottom: 6),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('⚠️ ', style: TextStyle(fontSize: 12)),
Expanded(
child: Text(
w.toString(),
style: TextStyle(
fontSize: 13,
color: isDark ? Colors.white70 : Colors.black87,
),
),
),
],
),
)),
],
),
);
}
// ─────────────────────────────────────────────
// JoFotara Status Card
// ─────────────────────────────────────────────
Widget _buildJoFotaraCard(Map jofotara, bool isDark) {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF0A2010) : const Color(0xFFF0FDF4),
borderRadius: BorderRadius.circular(16),
border: Border.all(color: const Color(0xFF10B981).withValues(alpha: 0.3)),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Icon(Icons.verified, color: Color(0xFF10B981), size: 20),
const SizedBox(width: 8),
const Text(
'مُقدَّمة لجوفتورة ✓',
style: TextStyle(fontWeight: FontWeight.bold, color: Color(0xFF10B981)),
),
],
),
const SizedBox(height: 12),
_buildMiniRow('UUID', jofotara['uuid'] ?? '', isDark),
const SizedBox(height: 6),
_buildMiniRow('تاريخ التقديم', jofotara['submitted_at'] ?? '', isDark),
if (jofotara['qr_image_uri'] != null) ...[
const SizedBox(height: 12),
Center(
child: Image.network(
jofotara['qr_image_uri'],
width: 140,
height: 140,
errorBuilder: (_, __, ___) => const SizedBox(),
),
),
],
],
),
);
}
// ─────────────────────────────────────────────
// Supplier & Buyer Card
// ─────────────────────────────────────────────
Widget _buildPartiesCard(Map inv, bool isDark) {
return Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF1E1E2E) : Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: isDark ? Colors.white10 : Colors.grey.shade200),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('المعلومات الأساسية', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
const SizedBox(height: 16),
_buildInfoRow('رقم الفاتورة', inv['invoice_number'] ?? '', isDark),
const Divider(height: 24),
_buildInfoRow('تاريخ الإصدار', inv['invoice_date'] ?? '', isDark),
const Divider(height: 24),
_buildInfoRow('المورّد', inv['supplier_name'] ?? '', isDark),
const Divider(height: 24),
_buildInfoRow('ض.م. المورّد', inv['supplier_tin'] ?? '', isDark),
if ((inv['buyer_name'] ?? '').toString().isNotEmpty) ...[
const Divider(height: 24),
_buildInfoRow('العميل', inv['buyer_name'] ?? '', isDark),
],
if ((inv['buyer_tin'] ?? '').toString().isNotEmpty) ...[
const Divider(height: 24),
_buildInfoRow('ض.م. العميل', inv['buyer_tin'] ?? '', isDark),
],
],
),
);
}
// ─────────────────────────────────────────────
// Invoice Lines Card
// ─────────────────────────────────────────────
Widget _buildLinesCard(List items, bool isDark) {
return Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF1E1E2E) : Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: isDark ? Colors.white10 : Colors.grey.shade200),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('بنود الفاتورة', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
Text(
'${items.length} بنود',
style: TextStyle(color: isDark ? Colors.white38 : Colors.grey, fontSize: 13),
),
],
),
const SizedBox(height: 16),
// Table header
Container(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 12),
decoration: BoxDecoration(
color: isDark ? Colors.white.withValues(alpha: 0.05) : const Color(0xFFF1F5F9),
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
const SizedBox(width: 30, child: Text('#', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 12))),
const Expanded(child: Text('الوصف', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 12))),
const SizedBox(width: 40, child: Text('كمية', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 12), textAlign: TextAlign.center)),
const SizedBox(width: 60, child: Text('سعر', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 12), textAlign: TextAlign.center)),
const SizedBox(width: 35, child: Text('ض%', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 12), textAlign: TextAlign.center)),
const SizedBox(width: 65, child: Text('إجمالي', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 12), textAlign: TextAlign.end)),
],
),
),
const SizedBox(height: 4),
// Table rows
...items.asMap().entries.map((entry) {
final item = entry.value;
final isLast = entry.key == items.length - 1;
return Container(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 12),
decoration: BoxDecoration(
border: isLast ? null : Border(bottom: BorderSide(color: isDark ? Colors.white10 : Colors.grey.shade200)),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 30,
child: Text(
(item['line_number'] ?? entry.key + 1).toString(),
style: TextStyle(fontSize: 12, color: isDark ? Colors.white38 : Colors.grey),
),
),
Expanded(
child: Text(
item['description'] ?? '',
style: const TextStyle(fontSize: 13),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
SizedBox(
width: 40,
child: Text(
_fmtNum(item['quantity']),
style: const TextStyle(fontSize: 12, fontFamily: 'monospace'),
textAlign: TextAlign.center,
),
),
SizedBox(
width: 60,
child: Text(
_fmtNum(item['unit_price']),
style: const TextStyle(fontSize: 12, fontFamily: 'monospace'),
textAlign: TextAlign.center,
),
),
SizedBox(
width: 35,
child: Text(
'${((double.tryParse(item['tax_rate']?.toString() ?? '0') ?? 0) * 100).toStringAsFixed(0)}%',
style: TextStyle(fontSize: 11, color: isDark ? Colors.white54 : Colors.grey.shade600),
textAlign: TextAlign.center,
),
),
SizedBox(
width: 65,
child: Text(
_fmtNum(item['line_total']),
style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w600, fontFamily: 'monospace'),
textAlign: TextAlign.end,
),
),
],
),
);
}),
],
),
);
}
// ─────────────────────────────────────────────
// Amounts Card
// ─────────────────────────────────────────────
Widget _buildAmountsCard(Map inv, bool isDark) {
return Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF1E1E2E) : Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: isDark ? Colors.white10 : Colors.grey.shade200),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('تفاصيل المبلغ', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
const SizedBox(height: 16),
_buildInfoRow('المبلغ الخاضع', '${_formatAmount(inv['subtotal'])} JOD', isDark),
if ((double.tryParse(inv['discount_total']?.toString() ?? '0') ?? 0) > 0) ...[
const Divider(height: 24),
_buildInfoRow('الخصم', '${_formatAmount(inv['discount_total'])} JOD', isDark),
],
const Divider(height: 24),
_buildInfoRow('قيمة الضريبة', '${_formatAmount(inv['tax_amount'])} JOD', isDark),
const Divider(height: 24),
_buildInfoRow('الإجمالي النهائي', '${_formatAmount(inv['grand_total'])} JOD', isDark, isBold: true),
],
),
);
}
// ─────────────────────────────────────────────
// Helper Widgets
// ─────────────────────────────────────────────
Widget _buildStatusChip(String status) {
Color color;
String text;
switch (status) {
case 'approved': color = const Color(0xFF10B981); text = '✓ معتمدة'; break;
case 'extracted': color = const Color(0xFF3B82F6); text = 'جاهزة للتدقيق'; break;
default: color = const Color(0xFFF59E0B); text = 'قيد المعالجة';
case 'approved':
color = const Color(0xFF10B981);
text = '✓ معتمدة';
break;
case 'extracted':
color = const Color(0xFF3B82F6);
text = 'جاهزة للتدقيق';
break;
case 'submitted':
color = const Color(0xFF6366F1);
text = 'مُقدَّمة لجوفتورة';
break;
default:
color = const Color(0xFFF59E0B);
text = 'قيد المعالجة';
}
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 6),
decoration: BoxDecoration(
color: color.withOpacity(0.1),
color: color.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(20),
border: Border.all(color: color.withOpacity(0.2)),
border: Border.all(color: color.withValues(alpha: 0.2)),
),
child: Text(text, style: TextStyle(color: color, fontWeight: FontWeight.bold, fontSize: 12)),
);
}
Widget _buildConfidenceChip(dynamic confidence, bool isDark) {
final score = (double.tryParse(confidence.toString()) ?? 0) * 100;
final color = score >= 90
? const Color(0xFF10B981)
: score >= 70
? const Color(0xFFF59E0B)
: const Color(0xFFEF4444);
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: color.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(20),
border: Border.all(color: color.withValues(alpha: 0.2)),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.auto_awesome, size: 12, color: color),
const SizedBox(width: 4),
Text(
'AI ${score.toStringAsFixed(0)}%',
style: TextStyle(color: color, fontWeight: FontWeight.bold, fontSize: 11, fontFamily: 'monospace'),
),
],
),
child: Text(text, style: TextStyle(color: color, fontWeight: FontWeight.bold, fontSize: 13)),
);
}
@@ -190,16 +527,45 @@ class InvoiceDetailView extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(label, style: TextStyle(fontSize: 14, color: isDark ? Colors.white70 : Colors.grey.shade600)),
Text(
value,
style: TextStyle(
fontWeight: isBold ? FontWeight.w900 : FontWeight.w600,
fontSize: isBold ? 18 : 15,
color: isDark ? Colors.white : Colors.black87,
fontFamily: value.contains(RegExp(r'[0-9]')) ? 'monospace' : null,
Flexible(
child: Text(
value,
style: TextStyle(
fontWeight: isBold ? FontWeight.w900 : FontWeight.w600,
fontSize: isBold ? 18 : 15,
color: isDark ? Colors.white : Colors.black87,
fontFamily: value.contains(RegExp(r'[0-9]')) ? 'monospace' : null,
),
textAlign: TextAlign.end,
),
),
],
);
}
Widget _buildMiniRow(String label, String value, bool isDark) {
return Row(
children: [
Text('$label: ', style: TextStyle(fontSize: 12, color: isDark ? Colors.white54 : Colors.grey)),
Expanded(
child: Text(
value,
style: const TextStyle(fontSize: 12, fontFamily: 'monospace'),
overflow: TextOverflow.ellipsis,
),
),
],
);
}
String _formatAmount(dynamic value) {
final num = double.tryParse(value?.toString() ?? '0') ?? 0;
return num.toStringAsFixed(3);
}
String _fmtNum(dynamic value) {
final num = double.tryParse(value?.toString() ?? '0') ?? 0;
if (num == num.truncateToDouble()) return num.toStringAsFixed(0);
return num.toStringAsFixed(3);
}
}

View File

@@ -76,6 +76,7 @@ class InvoicesListView extends GetView<InvoicesController> {
_buildFilterChip('قيد المعالجة', 'uploaded', controller, isDark),
_buildFilterChip('جاهزة', 'extracted', controller, isDark),
_buildFilterChip('معتمدة', 'approved', controller, isDark),
_buildFilterChip('مُقدَّمة', 'submitted', controller, isDark),
],
),
),
@@ -147,6 +148,11 @@ class InvoicesListView extends GetView<InvoicesController> {
statusText = 'جاهزة للتدقيق';
statusIcon = Icons.pending_actions;
break;
case 'submitted':
statusColor = const Color(0xFF6366F1);
statusText = 'مُقدَّمة لجوفتورة';
statusIcon = Icons.verified;
break;
default:
statusColor = const Color(0xFFF59E0B);
statusText = 'قيد المعالجة';
@@ -174,7 +180,7 @@ class InvoicesListView extends GetView<InvoicesController> {
width: 48,
height: 48,
decoration: BoxDecoration(
color: statusColor.withOpacity(0.1),
color: statusColor.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(12),
),
child: Icon(statusIcon, color: statusColor, size: 24),
@@ -222,7 +228,7 @@ class InvoicesListView extends GetView<InvoicesController> {
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
decoration: BoxDecoration(
color: statusColor.withOpacity(0.1),
color: statusColor.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
),
child: Text(
@@ -272,7 +278,7 @@ class InvoicesListView extends GetView<InvoicesController> {
height: 80,
margin: const EdgeInsets.only(bottom: 12),
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.1),
color: Colors.grey.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(14),
),
),

View File

@@ -4,6 +4,7 @@ import 'package:get/get.dart';
import 'package:firebase_core/firebase_core.dart';
import 'app/routes/app_pages.dart';
import 'core/services/push_notification_service.dart';
import 'core/services/upload_progress_service.dart';
import 'app/theme/app_theme.dart';
@pragma('vm:entry-point')
@@ -22,6 +23,9 @@ void main() async {
// 2. Register background handler
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
// 3. Register global services
Get.put(UploadProgressService(), permanent: true);
runApp(const MusadaqApp());
}