Update: 2026-05-08 01:15:44
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import '../../../core/network/dio_client.dart';
|
||||
import '../../../core/utils/app_snackbar.dart';
|
||||
import '../../../core/utils/logger.dart';
|
||||
@@ -7,6 +8,7 @@ import '../../../core/utils/logger.dart';
|
||||
class InvoiceDetailController extends GetxController {
|
||||
var invoice = {}.obs;
|
||||
var isLoading = true.obs;
|
||||
var isSaving = false.obs;
|
||||
String? invoiceId;
|
||||
|
||||
@override
|
||||
@@ -42,6 +44,25 @@ class InvoiceDetailController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateInvoice(Map<String, dynamic> data) async {
|
||||
try {
|
||||
isSaving.value = true;
|
||||
data['id'] = invoiceId;
|
||||
final res = await DioClient().client.post('invoices/update', data: data);
|
||||
if (res.data['success'] == true) {
|
||||
AppSnackbar.showSuccess('تم الحفظ', 'تم تحديث بيانات الفاتورة');
|
||||
await fetchInvoiceDetails();
|
||||
} else {
|
||||
AppSnackbar.showError('خطأ', res.data['message'] ?? 'فشل التحديث');
|
||||
}
|
||||
} catch (e) {
|
||||
AppLogger.error('Failed to update invoice', e);
|
||||
AppSnackbar.showError('خطأ', 'حدث خطأ أثناء التحديث');
|
||||
} finally {
|
||||
isSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> approveInvoice() async {
|
||||
try {
|
||||
final res = await DioClient()
|
||||
@@ -49,7 +70,6 @@ class InvoiceDetailController extends GetxController {
|
||||
.post('invoices/approve', data: {'invoice_id': invoiceId});
|
||||
if (res.data['success'] == true) {
|
||||
AppSnackbar.showSuccess('تم الاعتماد', 'تم اعتماد الفاتورة بنجاح');
|
||||
// Refresh the detail view
|
||||
fetchInvoiceDetails();
|
||||
} else {
|
||||
AppSnackbar.showError('خطأ', 'فشل اعتماد الفاتورة');
|
||||
@@ -63,7 +83,6 @@ class InvoiceDetailController extends GetxController {
|
||||
void viewOriginalImage() {
|
||||
final fileUrl = invoice['file_url'];
|
||||
if (fileUrl != null && fileUrl.isNotEmpty) {
|
||||
// Navigate to a dedicated image viewer or show in a dialog
|
||||
final fullUrl = 'https://musadaq.intaleqapp.com/api$fileUrl';
|
||||
Get.to(() => Scaffold(
|
||||
appBar: AppBar(
|
||||
@@ -90,8 +109,24 @@ class InvoiceDetailController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> exportInvoices({String? companyId}) async {
|
||||
try {
|
||||
final cId = companyId ?? invoice['company_id'];
|
||||
AppSnackbar.showInfo('جاري التصدير', 'يتم تحميل ملف الفواتير...');
|
||||
final res = await DioClient().client.get(
|
||||
'invoices/export',
|
||||
queryParameters: {'company_id': cId},
|
||||
options: Options(responseType: ResponseType.bytes),
|
||||
);
|
||||
// For now, just confirm download was successful
|
||||
AppSnackbar.showSuccess('تم التصدير', 'تم تحميل ملف CSV بنجاح (${res.data.length} bytes)');
|
||||
} catch (e) {
|
||||
AppLogger.error('Failed to export', e);
|
||||
AppSnackbar.showError('خطأ', 'فشل تصدير الفواتير');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> submitToJoFotara() async {
|
||||
// Confirmation dialog
|
||||
final confirmed = await Get.dialog<bool>(
|
||||
AlertDialog(
|
||||
title: const Text('تأكيد الإرسال'),
|
||||
@@ -124,7 +159,7 @@ class InvoiceDetailController extends GetxController {
|
||||
|
||||
if (res.data['success'] == true) {
|
||||
AppSnackbar.showSuccess('تم الإرسال', 'تم تقديم الفاتورة لجوفتورة بنجاح');
|
||||
fetchInvoiceDetails(); // Refresh to show JoFotara status
|
||||
fetchInvoiceDetails();
|
||||
} else {
|
||||
AppSnackbar.showError('خطأ', res.data['message'] ?? 'فشل الإرسال');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user