68 lines
2.2 KiB
Dart
68 lines
2.2 KiB
Dart
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('عذراً', 'لا توجد صورة مرتبطة بهذه الفاتورة');
|
|
}
|
|
}
|
|
}
|