Files
musadaq-saas/musadaq-app/lib/features/invoices/views/invoice_detail_view.dart
2026-05-07 03:06:15 +03:00

206 lines
8.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controllers/invoice_detail_controller.dart';
class InvoiceDetailView extends StatelessWidget {
const InvoiceDetailView({super.key});
@override
Widget build(BuildContext context) {
final controller = Get.put(InvoiceDetailController());
final isDark = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
backgroundColor: isDark ? const Color(0xFF121212) : const Color(0xFFF5F7FA),
appBar: AppBar(
title: const Text('تفاصيل الفاتورة', style: TextStyle(fontWeight: FontWeight.bold)),
backgroundColor: isDark ? const Color(0xFF1E1E2E) : const Color(0xFF0F4C81),
foregroundColor: Colors.white,
elevation: 0,
),
body: Obx(() {
if (controller.isLoading.value) {
return const Center(child: CircularProgressIndicator(color: Color(0xFF0F4C81)));
}
if (controller.invoice.isEmpty) {
return const Center(child: Text('لم يتم العثور على الفاتورة'));
}
final inv = controller.invoice;
final status = inv['status'] ?? 'pending';
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),
],
),
),
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),
],
),
),
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),
],
),
),
const SizedBox(height: 32),
// Action Buttons
if (status == 'extracted') ...[
SizedBox(
height: 52,
child: ElevatedButton.icon(
onPressed: () => controller.approveInvoice(),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF10B981),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
icon: const Icon(Icons.check_circle_outline),
label: const Text('اعتماد الفاتورة نهائياً', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
),
),
const SizedBox(height: 12),
],
SizedBox(
height: 52,
child: OutlinedButton.icon(
onPressed: () => controller.viewOriginalImage(),
style: OutlinedButton.styleFrom(
foregroundColor: const Color(0xFF0F4C81),
side: const BorderSide(color: Color(0xFF0F4C81)),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
icon: const Icon(Icons.image_outlined),
label: const Text('عرض صورة الفاتورة الأصلية', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
),
),
const SizedBox(height: 40),
],
),
);
}),
);
}
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 = 'قيد المعالجة';
}
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration(
color: color.withOpacity(0.1),
borderRadius: BorderRadius.circular(20),
border: Border.all(color: color.withOpacity(0.2)),
),
child: Text(text, style: TextStyle(color: color, fontWeight: FontWeight.bold, fontSize: 13)),
);
}
Widget _buildInfoRow(String label, String value, bool isDark, {bool isBold = false}) {
return Row(
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,
),
),
],
);
}
}