Update: 2026-05-07 03:06:15
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import 'package:get/get.dart';
|
||||
import '../../../core/network/dio_client.dart';
|
||||
import '../../../core/utils/app_snackbar.dart';
|
||||
import '../../../core/utils/logger.dart';
|
||||
|
||||
class InvoiceDetailController extends GetxController {
|
||||
var invoice = {}.obs;
|
||||
var isLoading = true.obs;
|
||||
String? invoiceId;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
if (Get.arguments != null) {
|
||||
invoiceId = Get.arguments['id'];
|
||||
if (invoiceId != null) {
|
||||
fetchInvoiceDetails();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchInvoiceDetails() async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
final res = await DioClient().client.get('invoices/view', queryParameters: {'id': invoiceId});
|
||||
|
||||
if (res.data['success'] == true && res.data['data'] != null) {
|
||||
invoice.value = res.data['data'];
|
||||
} else {
|
||||
AppSnackbar.showError('خطأ', 'لم يتم العثور على الفاتورة');
|
||||
Get.back();
|
||||
}
|
||||
} catch (e) {
|
||||
AppLogger.error('Failed to fetch invoice details', e);
|
||||
AppSnackbar.showError('خطأ', 'فشل تحميل بيانات الفاتورة');
|
||||
Get.back();
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> approveInvoice() async {
|
||||
try {
|
||||
final res = await DioClient().client.post('invoices/approve', data: {'invoice_id': invoiceId});
|
||||
if (res.data['success'] == true) {
|
||||
AppSnackbar.showSuccess('تم الاعتماد', 'تم اعتماد الفاتورة بنجاح');
|
||||
// Refresh the detail view
|
||||
fetchInvoiceDetails();
|
||||
} else {
|
||||
AppSnackbar.showError('خطأ', 'فشل اعتماد الفاتورة');
|
||||
}
|
||||
} catch (e) {
|
||||
AppLogger.error('Failed to approve invoice', e);
|
||||
AppSnackbar.showError('خطأ', 'حدث خطأ غير متوقع');
|
||||
}
|
||||
}
|
||||
|
||||
void viewOriginalImage() {
|
||||
final imagePath = invoice['file_path'];
|
||||
if (imagePath != null && imagePath.isNotEmpty) {
|
||||
// In a real app, you would download/show the image. For now, just a snackbar or open URL.
|
||||
AppSnackbar.showInfo('قريباً', 'سيتم عرض الصورة قريباً');
|
||||
} else {
|
||||
AppSnackbar.showWarning('عذراً', 'لا توجد صورة مرتبطة بهذه الفاتورة');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import 'package:get/get.dart';
|
||||
import '../../../core/network/dio_client.dart';
|
||||
import '../../../core/utils/logger.dart';
|
||||
|
||||
class InvoicesController extends GetxController {
|
||||
var invoices = <Map<String, dynamic>>[].obs;
|
||||
var isLoading = true.obs;
|
||||
var filterStatus = 'all'.obs;
|
||||
var searchQuery = ''.obs;
|
||||
var isSearching = false.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
loadInvoices();
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>> get filteredInvoices {
|
||||
var list = invoices.toList();
|
||||
|
||||
if (filterStatus.value != 'all') {
|
||||
list = list.where((inv) => inv['status'] == filterStatus.value).toList();
|
||||
}
|
||||
|
||||
if (searchQuery.value.isNotEmpty) {
|
||||
final q = searchQuery.value.toLowerCase();
|
||||
list = list.where((inv) {
|
||||
final name = (inv['supplier_name'] ?? '').toString().toLowerCase();
|
||||
final num = (inv['invoice_number'] ?? '').toString().toLowerCase();
|
||||
return name.contains(q) || num.contains(q);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void toggleSearch() {
|
||||
isSearching.value = !isSearching.value;
|
||||
if (!isSearching.value) searchQuery.value = '';
|
||||
}
|
||||
|
||||
Future<void> loadInvoices() async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
final res = await DioClient().client.get('invoices');
|
||||
if (res.data['success'] == true && res.data['data'] != null) {
|
||||
invoices.value = List<Map<String, dynamic>>.from(res.data['data']);
|
||||
}
|
||||
} catch (e) {
|
||||
AppLogger.error('Failed to load invoices', e);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user