2026-03-10-1

This commit is contained in:
Hamza-Ayed
2026-03-10 00:02:17 +03:00
parent c000d22ca3
commit cdda136006
28 changed files with 9912 additions and 3592 deletions

View File

@@ -4,10 +4,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import 'package:image_picker/image_picker.dart';
import 'package:sefer_admin1/constant/colors.dart';
import 'package:sefer_admin1/constant/links.dart';
import 'package:sefer_admin1/views/widgets/my_scafold.dart';
import 'package:sefer_admin1/views/widgets/my_textField.dart';
import '../../constant/box_name.dart';
import '../../constant/info.dart';
@@ -28,6 +25,11 @@ class _AddInvoicePageState extends State<AddInvoicePage> {
File? _imageFile;
bool _isLoading = false;
// الألوان المستخدمة في الثيم
final Color primaryColor = const Color(0xFF4F46E5); // Indigo
final Color secondaryColor = const Color(0xFF818CF8); // Lighter Indigo
final Color bgColor = const Color(0xFFF3F4F6); // Light Gray Background
String generateInvoiceNumber() {
final now = DateTime.now();
return "INV-${now.year}${now.month.toString().padLeft(2, '0')}${now.day.toString().padLeft(2, '0')}-${now.microsecond}";
@@ -36,7 +38,7 @@ class _AddInvoicePageState extends State<AddInvoicePage> {
Future<void> uploadInvoice() async {
if (!_formKey.currentState!.validate()) return;
final driverID = '123'; // ← عدّله حسب نظامك
final driverID = '123'; // قيمة افتراضية أو يمكن جلبها من الكونترولر
final invoiceNumber = generateInvoiceNumber();
final amount = _amountController.text.trim();
final itemName = _itemNameController.text.trim();
@@ -45,11 +47,13 @@ class _AddInvoicePageState extends State<AddInvoicePage> {
setState(() => _isLoading = true);
try {
// إعداد الترويسة (Headers)
final headers = {
'Authorization':
'Bearer ${r(box.read(BoxName.jwt)).split(AppInformation.addd)[0]}',
'X-HMAC-Auth': '${box.read(BoxName.hmac)}',
};
final uri = Uri.parse(AppLink.addInvoice);
final request = http.MultipartRequest('POST', uri)
..fields['driverID'] = driverID
@@ -59,41 +63,62 @@ class _AddInvoicePageState extends State<AddInvoicePage> {
..fields['date'] = date
..headers.addAll(headers);
// إضافة الصورة إذا وجدت
if (_imageFile != null) {
final imageName = _imageFile!.path.split('/').last;
final imageStream = http.ByteStream(_imageFile!.openRead());
final imageLength = await _imageFile!.length();
request.files.add(http.MultipartFile(
final multipartFile = await http.MultipartFile.fromPath(
'image',
imageStream,
imageLength,
filename: imageName,
));
} else {}
_imageFile!.path,
);
request.files.add(multipartFile);
}
final response = await request.send();
final respStr = await response.stream.bytesToString();
final data = jsonDecode(respStr);
// محاولة تحليل الاستجابة
Map<String, dynamic> data;
try {
data = jsonDecode(respStr);
} catch (e) {
data = {'status': 'error', 'message': 'Invalid server response'};
}
if (data['status'] == 'success') {
Get.snackbar('تم الحفظ', 'تم حفظ الفاتورة بنجاح',
backgroundColor: Colors.green.shade100);
Get.snackbar(
'نجاح',
'تم حفظ الفاتورة بنجاح',
backgroundColor: Colors.green.withOpacity(0.1),
colorText: Colors.green[800],
snackPosition: SnackPosition.TOP,
margin: const EdgeInsets.all(10),
borderRadius: 20,
);
_itemNameController.clear();
_amountController.clear();
setState(() => _imageFile = null);
Get.back(); // العودة للصفحة السابقة
// تأخير بسيط قبل العودة لتحديث الصفحة السابقة
Future.delayed(const Duration(seconds: 1), () {
Get.back(result: true);
});
} else {
Get.snackbar('خطأ', data['message'],
backgroundColor: Colors.red.shade100);
Get.snackbar(
'تنبيه',
data['message'] ?? 'حدث خطأ غير معروف',
backgroundColor: Colors.red.withOpacity(0.1),
colorText: Colors.red[800],
);
}
} catch (e, stacktrace) {
Get.snackbar('فشل الإرسال', e.toString(),
backgroundColor: Colors.red.shade100);
} catch (e) {
Get.snackbar(
'خطأ في الاتصال',
e.toString(),
backgroundColor: Colors.red.withOpacity(0.1),
colorText: Colors.red[800],
);
} finally {
setState(() => _isLoading = false);
if (mounted) setState(() => _isLoading = false);
}
}
@@ -114,76 +139,263 @@ class _AddInvoicePageState extends State<AddInvoicePage> {
@override
Widget build(BuildContext context) {
return MyScafolld(
title: 'إضافة فاتورة جديدة',
body: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _formKey,
child: ListView(
children: [
MyTextForm(
controller: _itemNameController,
label: 'اسم البضاعة',
hint: 'مثال: قطع غيار',
type: TextInputType.text,
// validator: (val) =>
// val!.isEmpty ? 'الرجاء إدخال اسم البضاعة' : null,
),
const SizedBox(height: 16),
MyTextForm(
controller: _amountController,
label: 'قيمة الفاتورة',
hint: 'مثال: 150.75',
type: TextInputType.numberWithOptions(decimal: true),
// validator: (val) =>
// val!.isEmpty ? 'الرجاء إدخال المبلغ' : null,
),
const SizedBox(height: 20),
Text('صورة الفاتورة (اختياري)',
style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: 10),
Container(
height: 180,
decoration: BoxDecoration(
color: Colors.grey.shade200,
border: Border.all(color: Colors.grey.shade400),
borderRadius: BorderRadius.circular(10),
),
child: _imageFile != null
? ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image.file(_imageFile!, fit: BoxFit.cover),
)
: const Center(child: Text('لم يتم اختيار صورة')),
),
const SizedBox(height: 12),
ElevatedButton.icon(
onPressed: pickInvoiceImage,
icon: const Icon(Icons.image),
label: const Text('اختيار صورة'),
),
const SizedBox(height: 30),
ElevatedButton(
onPressed: _isLoading ? null : uploadInvoice,
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 16),
backgroundColor: AppColor.primaryColor,
),
child: _isLoading
? const CircularProgressIndicator(color: Colors.white)
: const Text(
'حفظ الفاتورة',
style: TextStyle(color: Colors.white),
),
),
],
return Scaffold(
backgroundColor: bgColor,
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
centerTitle: true,
title: const Text(
'إضافة فاتورة جديدة',
style:
TextStyle(color: Color(0xFF1F2937), fontWeight: FontWeight.bold),
),
leading: IconButton(
icon: const Icon(Icons.arrow_back_ios_new, color: Color(0xFF1F2937)),
onPressed: () => Get.back(),
),
flexibleSpace: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.white, bgColor],
),
),
),
],
isleading: true,
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(20.0),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// قسم البيانات الأساسية
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 15,
offset: const Offset(0, 5),
),
],
),
child: Column(
children: [
_buildModernTextField(
controller: _itemNameController,
label: 'اسم البضاعة / الخدمة',
icon: Icons.inventory_2_outlined,
hint: 'مثال: صيانة سيارة',
),
const SizedBox(height: 20),
_buildModernTextField(
controller: _amountController,
label: 'قيمة الفاتورة (د.أ)',
icon: Icons.attach_money,
hint: '0.00',
isNumber: true,
),
],
),
),
const SizedBox(height: 25),
// قسم الصورة
Text(
'صورة الفاتورة',
style: TextStyle(
color: Colors.grey[700],
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
const SizedBox(height: 10),
InkWell(
onTap: pickInvoiceImage,
borderRadius: BorderRadius.circular(20),
child: Container(
height: 200,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: _imageFile != null
? primaryColor
: Colors.grey.shade300,
width: 2,
style: _imageFile != null
? BorderStyle.solid
: BorderStyle.solid,
),
image: _imageFile != null
? DecorationImage(
image: FileImage(_imageFile!),
fit: BoxFit.cover,
)
: null,
),
child: _imageFile == null
? Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: const EdgeInsets.all(15),
decoration: BoxDecoration(
color: primaryColor.withOpacity(0.05),
shape: BoxShape.circle,
),
child: Icon(Icons.add_a_photo_rounded,
size: 40, color: primaryColor),
),
const SizedBox(height: 10),
Text(
'اضغط لرفع صورة الفاتورة',
style: TextStyle(
color: Colors.grey[500],
fontWeight: FontWeight.w500,
),
),
],
)
: Stack(
children: [
Positioned(
top: 10,
right: 10,
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.9),
shape: BoxShape.circle,
),
child: Icon(Icons.edit,
color: primaryColor, size: 20),
),
),
],
),
),
),
const SizedBox(height: 40),
// زر الحفظ
SizedBox(
height: 55,
child: ElevatedButton(
onPressed: _isLoading ? null : uploadInvoice,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
padding: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
),
child: Ink(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: _isLoading
? [Colors.grey, Colors.grey]
: [primaryColor, secondaryColor],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
borderRadius: BorderRadius.circular(15),
boxShadow: [
if (!_isLoading)
BoxShadow(
color: primaryColor.withOpacity(0.4),
blurRadius: 10,
offset: const Offset(0, 4),
),
],
),
child: Container(
alignment: Alignment.center,
child: _isLoading
? const SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(
color: Colors.white,
strokeWidth: 2,
),
)
: const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.save_rounded, color: Colors.white),
SizedBox(width: 10),
Text(
'حفظ الفاتورة',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
),
),
],
),
),
),
);
}
Widget _buildModernTextField({
required TextEditingController controller,
required String label,
required IconData icon,
required String hint,
bool isNumber = false,
}) {
return TextFormField(
controller: controller,
keyboardType: isNumber
? const TextInputType.numberWithOptions(decimal: true)
: TextInputType.text,
validator: (val) {
if (val == null || val.isEmpty) {
return 'هذا الحقل مطلوب';
}
return null;
},
decoration: InputDecoration(
labelText: label,
hintText: hint,
prefixIcon: Icon(icon, color: primaryColor.withOpacity(0.7)),
filled: true,
fillColor: Colors.grey[50],
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none,
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: Colors.grey.shade200),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: primaryColor, width: 1.5),
),
contentPadding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
),
);
}
}

View File

@@ -1,24 +1,32 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import '../../constant/links.dart';
import '../../controller/admin/get_all_invoice_controller.dart';
import '../../controller/functions/crud.dart';
import '../../print.dart';
import 'add_invoice_page.dart';
// نفترض أن هذا الموديل موجود في مشروعك، إذا لم يكن موجوداً يرجى إضافته أو تعديل الاستيراد
// import '../../model/invoice_model.dart';
class InvoiceListPage extends StatefulWidget {
const InvoiceListPage({super.key});
@override
_InvoiceListPageState createState() => _InvoiceListPageState();
}
class _InvoiceListPageState extends State<InvoiceListPage> {
List<InvoiceModel> invoices = [];
List<dynamic> invoices = []; // استخدام dynamic لتجنب مشاكل الموديل إذا اختلف
int totalCount = 0;
double totalAmount = 0.0;
bool isLoading = true;
// الألوان "الإيجابية" للتصميم الجديد
final Color primaryColor = const Color(0xFF4F46E5); // Indigo
final Color secondaryColor = const Color(0xFF818CF8); // Lighter Indigo
final Color moneyColor = const Color(0xFF059669); // Emerald Green
final Color bgColor = const Color(0xFFF3F4F6); // Light Gray Background
@override
void initState() {
super.initState();
@@ -26,255 +34,423 @@ class _InvoiceListPageState extends State<InvoiceListPage> {
}
Future<void> fetchInvoices() async {
// لإظهار مؤشر التحديث بشكل جيد
if (!isLoading) {
setState(() {});
}
if (!mounted) return;
setState(() => isLoading = true);
final response = await CRUD().post(link: AppLink.getInvoices, payload: {});
final data = (response);
Log.print('data: $data');
try {
final response =
await CRUD().post(link: AppLink.getInvoices, payload: {});
if (mounted) {
if (data != 'failure' && data['status'] == 'success') {
setState(() {
invoices = List.from(data['data'])
.map((item) => InvoiceModel.fromJson(item))
.toList();
totalCount = data['summary']['count'];
totalAmount =
double.tryParse(data['summary']['total'].toString()) ?? 0.0;
isLoading = false;
});
if (response != 'failure' && response['status'] == 'success') {
final data = response;
if (mounted) {
setState(() {
invoices = data['data']; // استخدام البيانات مباشرة
totalCount = int.tryParse(data['summary']['count'].toString()) ?? 0;
totalAmount =
double.tryParse(data['summary']['total'].toString()) ?? 0.0;
isLoading = false;
});
}
} else {
setState(() {
isLoading = false;
});
Get.snackbar("خطأ", "فشل في تحميل الفواتير. حاول التحديث مرة أخرى.",
backgroundColor: Colors.red.withOpacity(0.8),
colorText: Colors.white);
if (mounted) {
setState(() => isLoading = false);
Get.snackbar("تنبيه", "لا توجد فواتير لعرضها أو حدث خطأ",
backgroundColor: Colors.orange.withOpacity(0.2),
colorText: Colors.orange[900]);
}
}
} catch (e) {
Log.print('Error fetching invoices: $e');
if (mounted) setState(() => isLoading = false);
}
}
// --- دالة لعرض الصورة في نافذة منبثقة ---
void _showImageDialog(BuildContext context, String imageUrl) {
showDialog(
context: context,
builder: (BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
child: GestureDetector(
// لإغلاق الصورة عند الضغط عليها
onTap: () => Navigator.of(context).pop(),
child: Container(
padding: EdgeInsets.all(12),
child: InteractiveViewer(
// لإتاحة التكبير والتصغير
panEnabled: true,
minScale: 0.5,
maxScale: 4,
child: Image.network(
imageUrl,
fit: BoxFit.contain,
// إظهار مؤشر تحميل أثناء جلب الصورة
loadingBuilder: (BuildContext context, Widget child,
ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) return child;
return Center(
child: CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes!
: null,
),
);
},
// إظهار أيقونة خطأ في حال فشل تحميل الصورة
errorBuilder: (context, error, stackTrace) {
return Icon(Icons.broken_image,
size: 100, color: Colors.red);
},
),
),
),
),
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("قائمة الفواتير"),
centerTitle: true,
elevation: 2,
actions: [
IconButton(
icon: Icon(Icons.add_a_photo),
onPressed: () {
// يمكنك إضافة إجراء الطباعة هنا
Get.to(() => AddInvoicePage());
},
),
],
),
body: isLoading
? Center(child: CircularProgressIndicator())
: RefreshIndicator(
onRefresh: fetchInvoices, // خاصية السحب للتحديث
child: Column(
children: [
Expanded(
child: ListView.builder(
padding:
EdgeInsets.symmetric(vertical: 8.0, horizontal: 12.0),
itemCount: invoices.length,
itemBuilder: (context, index) {
final invoice = invoices[index];
return Card(
elevation: 4,
margin: EdgeInsets.symmetric(vertical: 8.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: InkWell(
borderRadius: BorderRadius.circular(15.0),
onTap: () {
// التحقق من وجود رابط للصورة قبل محاولة عرضه
if (invoice.imageLink != null &&
invoice.imageLink!.isNotEmpty) {
_showImageDialog(context, invoice.imageLink!);
} else {
Get.snackbar("لا توجد صورة",
"هذه الفاتورة لا تحتوي على صورة مرفقة.");
}
},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
// أيقونة الفاتورة الرئيسية
Icon(Icons.receipt_long,
color: Theme.of(context).primaryColor,
size: 40),
SizedBox(width: 16),
// تفاصيل الفاتورة
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
"فاتورة رقم: ${invoice.invoiceNumber}",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
SizedBox(height: 8),
Text(
"الاسم: ${invoice.name}",
style: TextStyle(
color: Colors.green.shade700,
fontWeight: FontWeight.w500,
),
),
SizedBox(height: 8),
Text(
"المبلغ: ${invoice.amount} د.أ",
style: TextStyle(
color: Colors.green.shade700,
fontWeight: FontWeight.w500,
),
),
SizedBox(height: 4),
Text(
"التاريخ: ${invoice.date}",
style: TextStyle(
color: Colors.grey.shade600,
fontSize: 12,
),
),
],
),
),
// أيقونة توضح وجود صورة
if (invoice.imageLink != null &&
invoice.imageLink!.isNotEmpty)
Icon(Icons.image_outlined,
color: Colors.blueAccent, size: 30),
],
),
),
),
);
},
),
),
_buildSummaryCard(), // بطاقة الملخص السفلية
],
),
),
);
}
Widget _buildSummaryCard() {
return Card(
margin: EdgeInsets.all(0),
elevation: 8,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
),
child: Container(
padding: EdgeInsets.symmetric(vertical: 20, horizontal: 25),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
builder: (_) => Dialog(
backgroundColor: Colors.transparent,
child: Stack(
alignment: Alignment.center,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"إجمالي الفواتير",
style: TextStyle(color: Colors.grey.shade600, fontSize: 14),
),
Text(
"$totalCount",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
),
padding: const EdgeInsets.all(5),
child: ClipRRect(
borderRadius: BorderRadius.circular(15),
child: InteractiveViewer(
panEnabled: true,
minScale: 0.5,
maxScale: 4,
child: Image.network(
imageUrl,
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) return child;
return SizedBox(
height: 200,
width: 200,
child: Center(
child: CircularProgressIndicator(color: primaryColor),
),
);
},
errorBuilder: (context, error, stackTrace) {
return const SizedBox(
height: 150,
width: 150,
child: Icon(Icons.broken_image,
size: 60, color: Colors.grey),
);
},
),
),
],
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
"المبلغ الإجمالي",
style: TextStyle(color: Colors.grey.shade600, fontSize: 14),
Positioned(
top: 0,
right: 0,
child: CircleAvatar(
backgroundColor: Colors.white,
child: IconButton(
icon: const Icon(Icons.close, color: Colors.black),
onPressed: () => Navigator.pop(context),
),
Text(
"${totalAmount.toStringAsFixed(2)} د.أ",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: Colors.green.shade800,
),
),
],
),
),
],
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: bgColor,
// زر عائم بتصميم متدرج
floatingActionButton: Container(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [primaryColor, secondaryColor]),
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(
color: primaryColor.withOpacity(0.4),
blurRadius: 10,
offset: const Offset(0, 4))
],
),
child: FloatingActionButton.extended(
onPressed: () => Get.to(() => AddInvoicePage()),
label: const Text('إضافة فاتورة',
style: TextStyle(fontWeight: FontWeight.bold)),
icon: const Icon(Icons.add),
backgroundColor: Colors.transparent,
elevation: 0,
),
),
body: Column(
children: [
// 1. رأس الصفحة (Header & Summary)
_buildHeader(),
// 2. قائمة الفواتير
Expanded(
child: isLoading
? Center(child: CircularProgressIndicator(color: primaryColor))
: invoices.isEmpty
? _buildEmptyState()
: RefreshIndicator(
onRefresh: fetchInvoices,
color: primaryColor,
child: ListView.builder(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 80),
itemCount: invoices.length,
physics: const BouncingScrollPhysics(),
itemBuilder: (context, index) {
final invoice = invoices[index];
return _buildInvoiceCard(invoice);
},
),
),
),
],
),
);
}
// === تصميم الهيدر (رأس الصفحة) ===
Widget _buildHeader() {
return Container(
width: double.infinity,
padding: EdgeInsets.only(
top: MediaQuery.of(context).padding.top + 20,
bottom: 30,
left: 20,
right: 20,
),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [primaryColor, const Color(0xFF6366F1)],
),
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30),
),
boxShadow: [
BoxShadow(
color: primaryColor.withOpacity(0.3),
blurRadius: 20,
offset: const Offset(0, 10),
),
],
),
child: Column(
children: [
// العنوان وزر الرجوع
Row(
children: [
IconButton(
icon: const Icon(Icons.arrow_back_ios,
color: Colors.white, size: 20),
onPressed: () => Get.back(),
),
const Expanded(
child: Text(
"سجل الفواتير",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(width: 40), // للمحاذاة
],
),
const SizedBox(height: 25),
// بطاقات الملخص
Row(
children: [
Expanded(
child: _buildSummaryItem(
title: "الإجمالي",
value: "${totalAmount.toStringAsFixed(1)} د.أ",
icon: Icons.attach_money,
isMoney: true,
),
),
Container(width: 1, height: 40, color: Colors.white24),
Expanded(
child: _buildSummaryItem(
title: "عدد الفواتير",
value: "$totalCount",
icon: Icons.receipt_long,
isMoney: false,
),
),
],
),
],
),
);
}
Widget _buildSummaryItem(
{required String title,
required String value,
required IconData icon,
required bool isMoney}) {
return Column(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
shape: BoxShape.circle,
),
child: Icon(icon, color: Colors.white, size: 20),
),
const SizedBox(height: 8),
Text(
value,
style: TextStyle(
color: isMoney ? const Color(0xFFD1FAE5) : Colors.white,
fontSize: 22,
fontWeight: FontWeight.bold,
),
),
Text(
title,
style: TextStyle(color: Colors.white.withOpacity(0.8), fontSize: 12),
),
],
);
}
// === تصميم بطاقة الفاتورة ===
Widget _buildInvoiceCard(dynamic invoice) {
// استخراج البيانات بأمان
String name = invoice['name'] ?? 'بدون اسم';
String amount = invoice['amount']?.toString() ?? '0';
String date = invoice['date'] ?? '';
String invNumber = invoice['invoiceNumber']?.toString() ?? '#';
String? imageUrl = invoice['imageLink'];
return Container(
margin: const EdgeInsets.only(bottom: 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.03),
blurRadius: 15,
offset: const Offset(0, 5),
),
],
),
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius: BorderRadius.circular(20),
onTap: () {
if (imageUrl != null && imageUrl.isNotEmpty) {
_showImageDialog(context, imageUrl);
} else {
Get.snackbar("تنبيه", "لا توجد صورة مرفقة",
backgroundColor: Colors.grey[200], colorText: Colors.black);
}
},
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
// 1. أيقونة أو صورة مصغرة
Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: primaryColor.withOpacity(0.08),
borderRadius: BorderRadius.circular(15),
),
child: imageUrl != null && imageUrl.isNotEmpty
? ClipRRect(
borderRadius: BorderRadius.circular(15),
child: Image.network(
imageUrl,
fit: BoxFit.cover,
errorBuilder: (_, __, ___) =>
Icon(Icons.receipt, color: primaryColor),
),
)
: Icon(Icons.receipt_outlined, color: primaryColor),
),
const SizedBox(width: 16),
// 2. التفاصيل
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
name,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
color: Color(0xFF1F2937),
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.circular(8),
),
child: Text(
"#$invNumber",
style: TextStyle(
fontSize: 10,
color: Colors.grey[600],
fontWeight: FontWeight.bold),
),
),
],
),
const SizedBox(height: 6),
Text(
date,
style: TextStyle(color: Colors.grey[500], fontSize: 12),
),
],
),
),
const SizedBox(width: 12),
// 3. المبلغ
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
"$amount",
style: TextStyle(
color: moneyColor,
fontWeight: FontWeight.w900,
fontSize: 18,
),
),
Text(
"د.أ",
style: TextStyle(
color: moneyColor.withOpacity(0.7),
fontWeight: FontWeight.w500,
fontSize: 12,
),
),
],
),
],
),
),
),
),
);
}
Widget _buildEmptyState() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.receipt_long_rounded, size: 80, color: Colors.grey[300]),
const SizedBox(height: 16),
Text(
"لا توجد فواتير حالياً",
style: TextStyle(color: Colors.grey[500], fontSize: 16),
),
const SizedBox(height: 8),
TextButton.icon(
onPressed: fetchInvoices,
icon: const Icon(Icons.refresh),
label: const Text("تحديث"),
),
],
),
);
}
}