Update: 2026-05-07 22:19:17
This commit is contained in:
@@ -21,6 +21,8 @@ class ScannerController extends GetxController {
|
||||
var processedImagesCount = 0.obs;
|
||||
var totalImagesCount = 0.obs;
|
||||
var isBatchDone = false.obs;
|
||||
var selectedCompanyId = ''.obs;
|
||||
var selectedCompanyName = ''.obs;
|
||||
|
||||
final InvoiceUploadService _uploadService = InvoiceUploadService();
|
||||
final UploadProgressService _progressService =
|
||||
@@ -90,49 +92,28 @@ class ScannerController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> uploadBatch(String fallbackCompanyId) async {
|
||||
Future<void> uploadBatch() async {
|
||||
if (capturedImages.isEmpty) {
|
||||
AppSnackbar.showWarning('تنبيه', 'الرجاء تصوير فاتورة واحدة على الأقل');
|
||||
return;
|
||||
}
|
||||
if (selectedCompanyId.isEmpty) {
|
||||
AppSnackbar.showWarning('تنبيه', 'الرجاء اختيار الشركة أولاً');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
isProcessing.value = true;
|
||||
uploadProgress.value = 0.0;
|
||||
|
||||
String companyId = fallbackCompanyId;
|
||||
String companyName = 'شركة غير محددة';
|
||||
|
||||
if (companyId == 'mock_company_id_123' || companyId.isEmpty) {
|
||||
if (companies.isNotEmpty) {
|
||||
companyId = companies[0]['id'];
|
||||
companyName = companies[0]['name'] ?? 'شركتي';
|
||||
} else {
|
||||
final res = await DioClient().client.get('companies');
|
||||
if (res.data['success'] == true &&
|
||||
res.data['data'] != null &&
|
||||
res.data['data'].isNotEmpty) {
|
||||
companyId = res.data['data'][0]['id'];
|
||||
companyName = res.data['data'][0]['name'] ?? 'شركتي';
|
||||
} else {
|
||||
AppSnackbar.showError('خطأ', 'لا توجد شركات مسجلة في حسابك');
|
||||
isProcessing.value = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final comp = companies.firstWhereOrNull((c) => c['id'] == companyId);
|
||||
if (comp != null) companyName = comp['name'] ?? 'شركتي';
|
||||
}
|
||||
|
||||
AppLogger.print(
|
||||
'Uploading batch of ${capturedImages.length} images to company $companyId...');
|
||||
'Uploading batch of ${capturedImages.length} images to company ${selectedCompanyId.value}...');
|
||||
|
||||
// Start global progress
|
||||
_progressService.startUpload(companyName, capturedImages.length);
|
||||
_progressService.startUpload(selectedCompanyName.value, capturedImages.length);
|
||||
|
||||
final batchId = await _uploadService.uploadBatch(
|
||||
companyId: companyId,
|
||||
companyId: selectedCompanyId.value,
|
||||
images: capturedImages,
|
||||
onProgress: (current, total) {
|
||||
uploadProgress.value = current / total;
|
||||
@@ -149,6 +130,8 @@ class ScannerController extends GetxController {
|
||||
capturedImages.clear();
|
||||
uploadProgress.value = 0.0;
|
||||
isProcessing.value = false;
|
||||
selectedCompanyId.value = '';
|
||||
selectedCompanyName.value = '';
|
||||
|
||||
_progressService.startProcessing();
|
||||
Get.back(); // Go back to dashboard, progress will show in overlay
|
||||
@@ -167,6 +150,11 @@ class ScannerController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
void selectCompany(String id, String name) {
|
||||
selectedCompanyId.value = id;
|
||||
selectedCompanyName.value = name;
|
||||
}
|
||||
|
||||
Future<String> getSavePath() async {
|
||||
final directory = await getTemporaryDirectory();
|
||||
final fileName = 'invoice_${DateTime.now().millisecondsSinceEpoch}.jpg';
|
||||
|
||||
Reference in New Issue
Block a user