Update: 2026-05-08 02:11:29
This commit is contained in:
@@ -67,6 +67,79 @@ class InvoiceDetailController extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> approveInvoice() async {
|
||||
// First check for duplicates
|
||||
try {
|
||||
final dupRes = await DioClient().client.post('invoices/check-duplicate', data: {
|
||||
'invoice_number': invoice['invoice_number'],
|
||||
'supplier_tin': invoice['supplier_tin'],
|
||||
'grand_total': invoice['grand_total'],
|
||||
'invoice_date': invoice['invoice_date'],
|
||||
'exclude_id': invoiceId,
|
||||
});
|
||||
|
||||
if (dupRes.data['success'] == true) {
|
||||
final matches = dupRes.data['data']?['matches'] as List? ?? [];
|
||||
if (matches.isNotEmpty) {
|
||||
// Show duplicate warning
|
||||
final proceed = await Get.dialog<bool>(
|
||||
AlertDialog(
|
||||
title: const Row(
|
||||
children: [
|
||||
Icon(Icons.warning_amber, color: Colors.orange, size: 28),
|
||||
SizedBox(width: 8),
|
||||
Text('تحذير — فاتورة مكررة!', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
||||
],
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('تم العثور على ${matches.length} فاتورة مشابهة:', style: const TextStyle(fontWeight: FontWeight.w600)),
|
||||
const SizedBox(height: 12),
|
||||
...matches.take(3).map((m) => Container(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orange.withValues(alpha: 0.08),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: Colors.orange.withValues(alpha: 0.3)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('رقم: ${m['invoice_number'] ?? '—'}', style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w600)),
|
||||
Text('المورد: ${m['supplier_name'] ?? '—'}', style: const TextStyle(fontSize: 12)),
|
||||
Text('المبلغ: ${m['grand_total'] ?? '—'} | نوع التطابق: ${m['match_type'] ?? '—'}', style: const TextStyle(fontSize: 12, color: Colors.grey)),
|
||||
],
|
||||
),
|
||||
)),
|
||||
const SizedBox(height: 8),
|
||||
const Text('هل تريد الاستمرار بالاعتماد؟', style: TextStyle(fontWeight: FontWeight.w600)),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Get.back(result: false),
|
||||
child: const Text('إلغاء'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () => Get.back(result: true),
|
||||
style: ElevatedButton.styleFrom(backgroundColor: Colors.orange),
|
||||
child: const Text('اعتماد رغم التكرار', style: TextStyle(color: Colors.white)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (proceed != true) return;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// If duplicate check fails, proceed with approval anyway
|
||||
AppLogger.error('Duplicate check failed (proceeding)', e);
|
||||
}
|
||||
|
||||
// Proceed with approval
|
||||
try {
|
||||
final res = await DioClient()
|
||||
.client
|
||||
@@ -130,13 +203,16 @@ class InvoiceDetailController extends GetxController {
|
||||
final bytes = List<int>.from(res.data);
|
||||
await file.writeAsBytes(bytes);
|
||||
|
||||
// Try share, fallback to success message
|
||||
// Share via native sheet (share_plus v12 API)
|
||||
try {
|
||||
await Share.shareXFiles(
|
||||
[XFile(file.path, mimeType: 'text/csv', name: fileName)],
|
||||
subject: 'تصدير فواتير مُصادَق',
|
||||
await SharePlus.instance.share(
|
||||
ShareParams(
|
||||
files: [XFile(file.path, mimeType: 'text/csv', name: fileName)],
|
||||
title: 'تصدير فواتير مُصادَق',
|
||||
),
|
||||
);
|
||||
} catch (_) {
|
||||
} catch (shareErr) {
|
||||
AppLogger.error('Share fallback', shareErr);
|
||||
AppSnackbar.showSuccess('تم الحفظ', 'تم حفظ الملف: ${file.path}');
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -19,7 +19,11 @@ class InvoicesListView extends GetView<InvoicesController> {
|
||||
children: [
|
||||
// App Bar replacement
|
||||
Container(
|
||||
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top, left: 8, right: 8, bottom: 12),
|
||||
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: [
|
||||
@@ -28,7 +32,10 @@ class InvoicesListView extends GetView<InvoicesController> {
|
||||
child: Center(
|
||||
child: Text(
|
||||
'الفواتير',
|
||||
style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -52,13 +59,50 @@ class InvoicesListView extends GetView<InvoicesController> {
|
||||
}
|
||||
},
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(value: 'select', child: Row(children: [Icon(controller.isSelecting.value ? Icons.close : Icons.checklist, size: 18), const SizedBox(width: 8), Text(controller.isSelecting.value ? 'إلغاء التحديد' : 'تحديد متعدد')])),
|
||||
PopupMenuItem(
|
||||
value: 'select',
|
||||
child: Row(children: [
|
||||
Icon(
|
||||
controller.isSelecting.value
|
||||
? Icons.close
|
||||
: Icons.checklist,
|
||||
size: 18),
|
||||
const SizedBox(width: 8),
|
||||
Text(controller.isSelecting.value
|
||||
? 'إلغاء التحديد'
|
||||
: 'تحديد متعدد')
|
||||
])),
|
||||
if (controller.isSelecting.value) ...[
|
||||
const PopupMenuItem(value: 'select_all', child: Row(children: [Icon(Icons.select_all, size: 18), SizedBox(width: 8), Text('تحديد الكل (المستخرجة)')])),
|
||||
const PopupMenuItem(value: 'bulk_approve', child: Row(children: [Icon(Icons.check_circle, size: 18, color: Color(0xFF10B981)), SizedBox(width: 8), Text('اعتماد المحدد')])),
|
||||
const PopupMenuItem(
|
||||
value: 'select_all',
|
||||
child: Row(children: [
|
||||
Icon(Icons.select_all, size: 18),
|
||||
SizedBox(width: 8),
|
||||
Text('تحديد الكل (المستخرجة)')
|
||||
])),
|
||||
const PopupMenuItem(
|
||||
value: 'bulk_approve',
|
||||
child: Row(children: [
|
||||
Icon(Icons.check_circle,
|
||||
size: 18, color: Color(0xFF10B981)),
|
||||
SizedBox(width: 8),
|
||||
Text('اعتماد المحدد')
|
||||
])),
|
||||
],
|
||||
const PopupMenuItem(value: 'report', child: Row(children: [Icon(Icons.bar_chart, size: 18), SizedBox(width: 8), Text('التقرير الضريبي')])),
|
||||
const PopupMenuItem(value: 'export', child: Row(children: [Icon(Icons.file_download, size: 18), SizedBox(width: 8), Text('تصدير Excel')])),
|
||||
const PopupMenuItem(
|
||||
value: 'report',
|
||||
child: Row(children: [
|
||||
Icon(Icons.bar_chart, size: 18),
|
||||
SizedBox(width: 8),
|
||||
Text('التقرير الضريبي')
|
||||
])),
|
||||
const PopupMenuItem(
|
||||
value: 'export',
|
||||
child: Row(children: [
|
||||
Icon(Icons.file_download, size: 18),
|
||||
SizedBox(width: 8),
|
||||
Text('تصدير Excel')
|
||||
])),
|
||||
],
|
||||
),
|
||||
IconButton(
|
||||
@@ -71,29 +115,31 @@ class InvoicesListView extends GetView<InvoicesController> {
|
||||
|
||||
// Search Bar
|
||||
Obx(() => AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
height: controller.isSearching.value ? 64 : 0,
|
||||
child: controller.isSearching.value
|
||||
? Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: TextField(
|
||||
onChanged: (v) => controller.searchQuery.value = v,
|
||||
textDirection: TextDirection.rtl,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'بحث بالرقم أو اسم المورد...',
|
||||
prefixIcon: const Icon(Icons.search, size: 20),
|
||||
filled: true,
|
||||
fillColor: isDark ? Colors.white10 : Colors.white,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide.none,
|
||||
duration: const Duration(milliseconds: 300),
|
||||
height: controller.isSearching.value ? 64 : 0,
|
||||
child: controller.isSearching.value
|
||||
? Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16, vertical: 8),
|
||||
child: TextField(
|
||||
onChanged: (v) => controller.searchQuery.value = v,
|
||||
textDirection: TextDirection.rtl,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'بحث بالرقم أو اسم المورد...',
|
||||
prefixIcon: const Icon(Icons.search, size: 20),
|
||||
filled: true,
|
||||
fillColor: isDark ? Colors.white10 : Colors.white,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 16),
|
||||
),
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
),
|
||||
),
|
||||
)
|
||||
: const SizedBox(),
|
||||
)),
|
||||
)
|
||||
: const SizedBox(),
|
||||
)),
|
||||
|
||||
// Filter Tabs
|
||||
Container(
|
||||
@@ -128,9 +174,11 @@ class InvoicesListView extends GetView<InvoicesController> {
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async => controller.loadInvoices(),
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
itemCount: invoices.length,
|
||||
itemBuilder: (context, index) => _buildInvoiceCard(invoices[index], isDark),
|
||||
itemBuilder: (context, index) =>
|
||||
_buildInvoiceCard(invoices[index], isDark),
|
||||
),
|
||||
);
|
||||
}),
|
||||
@@ -148,23 +196,30 @@ class InvoicesListView extends GetView<InvoicesController> {
|
||||
children: [
|
||||
Text(
|
||||
'${controller.selectedIds.length} محدد',
|
||||
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 15),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 15),
|
||||
),
|
||||
const Spacer(),
|
||||
TextButton.icon(
|
||||
onPressed: () => controller.selectAllExtracted(),
|
||||
icon: const Icon(Icons.select_all, color: Colors.white, size: 18),
|
||||
label: const Text('الكل', style: TextStyle(color: Colors.white)),
|
||||
icon: const Icon(Icons.select_all,
|
||||
color: Colors.white, size: 18),
|
||||
label:
|
||||
const Text('الكل', style: TextStyle(color: Colors.white)),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () => controller.bulkApprove(),
|
||||
icon: const Icon(Icons.check_circle, size: 18),
|
||||
label: const Text('اعتماد', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
label: const Text('اعتماد',
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.white,
|
||||
foregroundColor: const Color(0xFF10B981),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10)),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -175,7 +230,8 @@ class InvoicesListView extends GetView<InvoicesController> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFilterChip(String label, String value, InvoicesController ctrl, bool isDark) {
|
||||
Widget _buildFilterChip(
|
||||
String label, String value, InvoicesController ctrl, bool isDark) {
|
||||
return Obx(() {
|
||||
final isSelected = ctrl.filterStatus.value == value;
|
||||
return Padding(
|
||||
@@ -187,12 +243,16 @@ class InvoicesListView extends GetView<InvoicesController> {
|
||||
selectedColor: const Color(0xFF0F4C81),
|
||||
backgroundColor: isDark ? Colors.white10 : Colors.white,
|
||||
labelStyle: TextStyle(
|
||||
color: isSelected ? Colors.white : (isDark ? Colors.white70 : Colors.black87),
|
||||
color: isSelected
|
||||
? Colors.white
|
||||
: (isDark ? Colors.white70 : Colors.black87),
|
||||
fontWeight: isSelected ? FontWeight.w700 : FontWeight.w400,
|
||||
fontSize: 13,
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
side: BorderSide(color: isSelected ? Colors.transparent : Colors.grey.shade300),
|
||||
shape:
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
side: BorderSide(
|
||||
color: isSelected ? Colors.transparent : Colors.grey.shade300),
|
||||
),
|
||||
);
|
||||
});
|
||||
@@ -229,108 +289,126 @@ class InvoicesListView extends GetView<InvoicesController> {
|
||||
return Obx(() {
|
||||
final isSelected = controller.selectedIds.contains(inv['id']);
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
elevation: 0,
|
||||
color: isSelected ? statusColor.withValues(alpha: 0.05) : (isDark ? const Color(0xFF1E1E2E) : Colors.white),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
side: BorderSide(color: isSelected ? statusColor : (isDark ? Colors.white10 : Colors.grey.shade200), width: isSelected ? 2 : 1),
|
||||
),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
onTap: () {
|
||||
if (controller.isSelecting.value) {
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
elevation: 0,
|
||||
color: isSelected
|
||||
? statusColor.withValues(alpha: 0.05)
|
||||
: (isDark ? const Color(0xFF1E1E2E) : Colors.white),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
side: BorderSide(
|
||||
color: isSelected
|
||||
? statusColor
|
||||
: (isDark ? Colors.white10 : Colors.grey.shade200),
|
||||
width: isSelected ? 2 : 1),
|
||||
),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
onTap: () {
|
||||
if (controller.isSelecting.value) {
|
||||
controller.toggleSelection(inv['id']);
|
||||
} else {
|
||||
Get.toNamed('/invoice-detail',
|
||||
arguments: {'id': inv['id'].toString()});
|
||||
}
|
||||
},
|
||||
onLongPress: () {
|
||||
if (!controller.isSelecting.value) {
|
||||
controller.isSelecting.value = true;
|
||||
}
|
||||
controller.toggleSelection(inv['id']);
|
||||
} else {
|
||||
Get.toNamed('/invoice-detail', arguments: {'id': inv['id'].toString()});
|
||||
}
|
||||
},
|
||||
onLongPress: () {
|
||||
if (!controller.isSelecting.value) {
|
||||
controller.isSelecting.value = true;
|
||||
}
|
||||
controller.toggleSelection(inv['id']);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
if (controller.isSelecting.value) ...[
|
||||
Checkbox(
|
||||
value: isSelected,
|
||||
onChanged: (_) => controller.toggleSelection(inv['id']),
|
||||
activeColor: statusColor,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
if (controller.isSelecting.value) ...[
|
||||
Checkbox(
|
||||
value: isSelected,
|
||||
onChanged: (_) => controller.toggleSelection(inv['id']),
|
||||
activeColor: statusColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(4)),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: statusColor.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Icon(statusIcon, color: statusColor, size: 24),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: statusColor.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
inv['supplier_name'] ??
|
||||
inv['company_name'] ??
|
||||
'بدون اسم',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 15,
|
||||
color:
|
||||
isDark ? Colors.white : const Color(0xFF0F172A),
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'# ${inv['invoice_number'] ?? '—'} • ${inv['invoice_date'] ?? '—'}',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color:
|
||||
isDark ? Colors.white38 : const Color(0xFF94A3B8),
|
||||
fontFamily: 'monospace',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Icon(statusIcon, color: statusColor, size: 24),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
inv['supplier_name'] ?? inv['company_name'] ?? 'بدون اسم',
|
||||
'${double.tryParse(inv['grand_total']?.toString() ?? '0')?.toStringAsFixed(2) ?? '0.00'} JOD',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 15,
|
||||
color: isDark ? Colors.white : const Color(0xFF0F172A),
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'# ${inv['invoice_number'] ?? '—'} • ${inv['invoice_date'] ?? '—'}',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isDark ? Colors.white38 : const Color(0xFF94A3B8),
|
||||
fontWeight: FontWeight.w800,
|
||||
fontSize: 14,
|
||||
color: isDark
|
||||
? const Color(0xFF5EEAD4)
|
||||
: const Color(0xFF008080),
|
||||
fontFamily: 'monospace',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: statusColor.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
statusText,
|
||||
style: TextStyle(
|
||||
color: statusColor,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
'${double.tryParse(inv['grand_total']?.toString() ?? '0')?.toStringAsFixed(2) ?? '0.00'} JOD',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w800,
|
||||
fontSize: 14,
|
||||
color: isDark ? const Color(0xFF5EEAD4) : const Color(0xFF008080),
|
||||
fontFamily: 'monospace',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: statusColor.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
statusText,
|
||||
style: TextStyle(color: statusColor, fontSize: 11, fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -339,7 +417,8 @@ class InvoicesListView extends GetView<InvoicesController> {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.receipt_long_rounded, size: 80, color: isDark ? Colors.white12 : Colors.grey.shade300),
|
||||
Icon(Icons.receipt_long_rounded,
|
||||
size: 80, color: isDark ? Colors.white12 : Colors.grey.shade300),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'لا توجد فواتير بعد',
|
||||
@@ -352,7 +431,9 @@ class InvoicesListView extends GetView<InvoicesController> {
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'ابدأ بتصوير فواتيرك من زر الماسح الضوئي',
|
||||
style: TextStyle(fontSize: 13, color: isDark ? Colors.white24 : Colors.grey.shade400),
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: isDark ? Colors.white24 : Colors.grey.shade400),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -378,24 +459,28 @@ class InvoicesListView extends GetView<InvoicesController> {
|
||||
try {
|
||||
AppSnackbar.showInfo('جاري التصدير', 'يتم تحميل ملف الفواتير...');
|
||||
final res = await DioClient().client.get(
|
||||
'invoices/export',
|
||||
options: Options(responseType: ResponseType.bytes),
|
||||
);
|
||||
'invoices/export',
|
||||
options: Options(responseType: ResponseType.bytes),
|
||||
);
|
||||
|
||||
// Save to temp file
|
||||
final dir = await getTemporaryDirectory();
|
||||
final fileName = 'musadaq_invoices_${DateTime.now().millisecondsSinceEpoch}.csv';
|
||||
final fileName =
|
||||
'musadaq_invoices_${DateTime.now().millisecondsSinceEpoch}.csv';
|
||||
final file = File('${dir.path}/$fileName');
|
||||
final bytes = List<int>.from(res.data);
|
||||
await file.writeAsBytes(bytes);
|
||||
|
||||
// Try share, fallback to success message
|
||||
// Share via native sheet (share_plus v12 API)
|
||||
try {
|
||||
await Share.shareXFiles(
|
||||
[XFile(file.path, mimeType: 'text/csv', name: fileName)],
|
||||
subject: 'تصدير فواتير مُصادَق',
|
||||
await SharePlus.instance.share(
|
||||
ShareParams(
|
||||
files: [XFile(file.path, mimeType: 'text/csv', name: fileName)],
|
||||
title: 'تصدير فواتير مُصادَق',
|
||||
),
|
||||
);
|
||||
} catch (_) {
|
||||
} catch (shareErr) {
|
||||
debugPrint('Share error (fallback to save): $shareErr');
|
||||
AppSnackbar.showSuccess('تم الحفظ', 'تم حفظ الملف: ${file.path}');
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user