Update: 2026-05-07 00:14:28
This commit is contained in:
@@ -4,14 +4,30 @@ import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import '../../../core/utils/logger.dart';
|
||||
import '../../../core/utils/app_snackbar.dart';
|
||||
import '../../../core/services/image_processing_service.dart';
|
||||
import '../../../core/services/invoice_upload_service.dart';
|
||||
|
||||
class ScannerController extends GetxController {
|
||||
var capturedImages = <File>[].obs;
|
||||
var isProcessing = false.obs;
|
||||
var uploadProgress = 0.0.obs;
|
||||
|
||||
void addImage(String imagePath) {
|
||||
capturedImages.add(File(imagePath));
|
||||
AppLogger.print('Added image to batch: $imagePath. Total: ${capturedImages.length}');
|
||||
final InvoiceUploadService _uploadService = InvoiceUploadService();
|
||||
|
||||
Future<void> addImage(String imagePath) async {
|
||||
isProcessing.value = true;
|
||||
try {
|
||||
File originalFile = File(imagePath);
|
||||
// Process image (compress, grayscale, contrast)
|
||||
File? processedFile = await ImageProcessingService.processInvoiceImage(originalFile);
|
||||
|
||||
if (processedFile != null) {
|
||||
capturedImages.add(processedFile);
|
||||
AppLogger.print('Added processed image to batch. Total: ${capturedImages.length}');
|
||||
}
|
||||
} finally {
|
||||
isProcessing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
void removeImage(int index) {
|
||||
@@ -20,7 +36,7 @@ class ScannerController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> uploadBatch() async {
|
||||
Future<void> uploadBatch(String companyId) async {
|
||||
if (capturedImages.isEmpty) {
|
||||
AppSnackbar.showWarning('تنبيه', 'الرجاء تصوير فاتورة واحدة على الأقل');
|
||||
return;
|
||||
@@ -28,17 +44,28 @@ class ScannerController extends GetxController {
|
||||
|
||||
try {
|
||||
isProcessing.value = true;
|
||||
uploadProgress.value = 0.0;
|
||||
AppLogger.print('Uploading batch of ${capturedImages.length} images...');
|
||||
|
||||
// TODO: Implement actual upload logic with Dio
|
||||
await Future.delayed(const Duration(seconds: 2)); // Simulate
|
||||
final batchId = await _uploadService.uploadBatch(
|
||||
companyId: companyId,
|
||||
images: capturedImages,
|
||||
onProgress: (current, total) {
|
||||
uploadProgress.value = current / total;
|
||||
},
|
||||
);
|
||||
|
||||
AppSnackbar.showSuccess('نجاح', 'تم رفع ${capturedImages.length} فواتير للمعالجة بنجاح');
|
||||
capturedImages.clear();
|
||||
Get.back(); // Go back to dashboard or previous screen
|
||||
if (batchId != null) {
|
||||
AppSnackbar.showSuccess('نجاح', 'تم رفع ${capturedImages.length} فواتير للمعالجة بنجاح');
|
||||
capturedImages.clear();
|
||||
uploadProgress.value = 0.0;
|
||||
Get.back(); // Go back to dashboard or previous screen
|
||||
} else {
|
||||
AppSnackbar.showError('خطأ', 'فشل رفع الفواتير، يرجى المحاولة لاحقاً');
|
||||
}
|
||||
} catch (e) {
|
||||
AppLogger.error('Failed to upload batch', e);
|
||||
AppSnackbar.showError('خطأ', 'فشل رفع الفواتير، يرجى المحاولة لاحقاً');
|
||||
AppSnackbar.showError('خطأ', 'حدث خطأ غير متوقع أثناء الرفع');
|
||||
} finally {
|
||||
isProcessing.value = false;
|
||||
}
|
||||
|
||||
@@ -138,7 +138,8 @@ class ScannerView extends GetView<ScannerController> {
|
||||
: ElevatedButton.icon(
|
||||
onPressed: controller.isProcessing.value
|
||||
? null
|
||||
: () => controller.uploadBatch(),
|
||||
// TODO: Get actual company_id from user selection
|
||||
: () => controller.uploadBatch('mock_company_id_123'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF0F4C81),
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
@@ -146,11 +147,15 @@ class ScannerView extends GetView<ScannerController> {
|
||||
borderRadius: BorderRadius.circular(30)),
|
||||
),
|
||||
icon: controller.isProcessing.value
|
||||
? const SizedBox(
|
||||
? SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white, strokeWidth: 2))
|
||||
value: controller.uploadProgress.value > 0
|
||||
? controller.uploadProgress.value
|
||||
: null,
|
||||
color: Colors.white,
|
||||
strokeWidth: 2))
|
||||
: const Icon(Icons.cloud_upload, color: Colors.white),
|
||||
label: Text(
|
||||
'رفع ${controller.capturedImages.length} فواتير',
|
||||
|
||||
Reference in New Issue
Block a user