Update: 2026-05-15 04:35:25
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import '../../../core/services/upload_progress_service.dart';
|
||||
import '../../../core/utils/logger.dart';
|
||||
import '../../../core/utils/app_snackbar.dart';
|
||||
@@ -123,11 +124,92 @@ class ScannerController extends GetxController {
|
||||
addImage(file.path!);
|
||||
}
|
||||
}
|
||||
AppSnackbar.showSuccess('تمت الإضافة', 'تم استيراد ملفات الفواتير بنجاح');
|
||||
AppSnackbar.showSuccess('تمت الإضافة', 'تم استيراد ملفات PDF بنجاح');
|
||||
}
|
||||
} catch (e) {
|
||||
AppLogger.error('Failed to pick PDF', e);
|
||||
AppSnackbar.showError('خطأ', 'تعذر استيراد الملفات');
|
||||
AppSnackbar.showError('خطأ', 'تعذر استيراد ملفات PDF');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> pickFromGallery() async {
|
||||
try {
|
||||
final ImagePicker picker = ImagePicker();
|
||||
final List<XFile> images = await picker.pickMultiImage();
|
||||
|
||||
if (images.isNotEmpty) {
|
||||
for (var image in images) {
|
||||
addImage(image.path);
|
||||
}
|
||||
AppSnackbar.showSuccess('تمت الإضافة', 'تم استيراد الصور من المعرض بنجاح');
|
||||
}
|
||||
} catch (e) {
|
||||
AppLogger.error('Failed to pick from gallery', e);
|
||||
AppSnackbar.showError('خطأ', 'تعذر استيراد الصور من المعرض');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> pickExcelFile() async {
|
||||
if (selectedCompanyId.isEmpty) {
|
||||
AppSnackbar.showWarning('تنبيه', 'الرجاء اختيار الشركة أولاً');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
||||
type: FileType.custom,
|
||||
allowedExtensions: ['xlsx', 'xls', 'csv'],
|
||||
allowMultiple: false,
|
||||
);
|
||||
|
||||
if (result != null && result.files.single.path != null) {
|
||||
final filePath = result.files.single.path!;
|
||||
await uploadExcel(filePath);
|
||||
}
|
||||
} catch (e) {
|
||||
AppLogger.error('Failed to pick Excel', e);
|
||||
AppSnackbar.showError('خطأ', 'تعذر استيراد ملف الإكسل');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> uploadExcel(String filePath) async {
|
||||
try {
|
||||
isProcessing.value = true;
|
||||
uploadProgress.value = 0.0;
|
||||
|
||||
_progressService.startUpload(selectedCompanyName.value, 1);
|
||||
|
||||
final file = File(filePath);
|
||||
final fileName = file.path.split('/').last;
|
||||
|
||||
FormData formData = FormData.fromMap({
|
||||
'company_id': selectedCompanyId.value,
|
||||
'file': await MultipartFile.fromFile(file.path, filename: fileName),
|
||||
});
|
||||
|
||||
final response = await DioClient().client.post(
|
||||
'excel/import',
|
||||
data: formData,
|
||||
onSendProgress: (sent, total) {
|
||||
uploadProgress.value = sent / total;
|
||||
_progressService.updateProgress(uploadProgress.value, 1);
|
||||
},
|
||||
);
|
||||
|
||||
if (response.data['success'] == true) {
|
||||
_progressService.complete();
|
||||
AppSnackbar.showSuccess('تم بنجاح', response.data['message'] ?? 'تم استيراد البيانات بنجاح');
|
||||
Get.back();
|
||||
} else {
|
||||
_progressService.fail();
|
||||
AppSnackbar.showError('خطأ', response.data['message'] ?? 'فشل استيراد ملف الإكسل');
|
||||
}
|
||||
} catch (e) {
|
||||
_progressService.fail();
|
||||
AppLogger.error('Excel upload failed', e);
|
||||
AppSnackbar.showError('خطأ', 'حدث خطأ أثناء رفع ملف الإكسل');
|
||||
} finally {
|
||||
isProcessing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user