feat(mobile): upload pièce justificative LCB-FT (T020 - Spec 001)
Implémentation upload documents pour transactions épargne ≥ seuil LCB-FT : Backend : - DocumentUploadService (@lazySingleton) : upload JPG/PNG/PDF max 5MB - Dio provider dans register_module.dart (timeouts 15s) Mobile : - 3 dialogs épargne modifiés (dépôt, retrait, transfert) - FilePicker + upload + validation seuil - UI états (idle, loading, success) - Validation : pièce requise si montant ≥ seuil Corrections : - AppLogger.error() : signature correcte (error: param nommé) - Assets : création répertoires mobile_money/ et virement/ Spec 001 : 27/27 tâches (100%) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
|
||||
import '../../../../core/constants/lcb_ft_constants.dart';
|
||||
import '../../../../core/data/repositories/parametres_lcb_ft_repository.dart';
|
||||
@@ -7,6 +9,7 @@ import '../../../../core/utils/error_formatter.dart';
|
||||
import '../../data/models/compte_epargne_model.dart';
|
||||
import '../../data/models/transaction_epargne_request.dart';
|
||||
import '../../data/repositories/transaction_epargne_repository.dart';
|
||||
import '../../data/services/document_upload_service.dart';
|
||||
import '../../../../shared/design_system/unionflow_design_system.dart';
|
||||
|
||||
/// Dialogue de transfert entre deux comptes épargne du membre.
|
||||
@@ -32,14 +35,20 @@ class _TransfertEpargneDialogState extends State<TransfertEpargneDialog> {
|
||||
final _motifController = TextEditingController();
|
||||
final _origineFondsController = TextEditingController();
|
||||
bool _loading = false;
|
||||
bool _uploadingDocument = false;
|
||||
String? _compteDestinationId;
|
||||
late TransactionEpargneRepository _repository;
|
||||
late ParametresLcbFtRepository _parametresRepository;
|
||||
late DocumentUploadService _uploadService;
|
||||
|
||||
/// Seuil LCB-FT récupéré depuis l'API (fallback à 500k XOF).
|
||||
double _seuilLcbFt = kSeuilOrigineFondsObligatoireXOF;
|
||||
bool _seuilLoaded = false;
|
||||
|
||||
/// Pièce justificative pour opérations au-dessus du seuil
|
||||
File? _pieceJustificative;
|
||||
String? _pieceJustificativeId;
|
||||
|
||||
List<CompteEpargneModel> get _comptesDestination {
|
||||
if (widget.compteSource.id == null) return [];
|
||||
return widget.tousLesComptes
|
||||
@@ -57,6 +66,7 @@ class _TransfertEpargneDialogState extends State<TransfertEpargneDialog> {
|
||||
super.initState();
|
||||
_repository = GetIt.I<TransactionEpargneRepository>();
|
||||
_parametresRepository = GetIt.I<ParametresLcbFtRepository>();
|
||||
_uploadService = GetIt.I<DocumentUploadService>();
|
||||
if (_comptesDestination.isNotEmpty) _compteDestinationId = _comptesDestination.first.id;
|
||||
_chargerSeuil();
|
||||
}
|
||||
@@ -80,6 +90,57 @@ class _TransfertEpargneDialogState extends State<TransfertEpargneDialog> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// Choisir et uploader une pièce justificative (photo ou PDF)
|
||||
Future<void> _choisirPieceJustificative() async {
|
||||
try {
|
||||
final result = await FilePicker.platform.pickFiles(
|
||||
type: FileType.custom,
|
||||
allowedExtensions: ['jpg', 'jpeg', 'png', 'pdf'],
|
||||
allowMultiple: false,
|
||||
);
|
||||
|
||||
if (result == null || result.files.isEmpty) return;
|
||||
|
||||
final file = File(result.files.single.path!);
|
||||
setState(() {
|
||||
_uploadingDocument = true;
|
||||
_pieceJustificative = file;
|
||||
});
|
||||
|
||||
// Upload du fichier
|
||||
final documentId = await _uploadService.uploadDocument(
|
||||
file: file,
|
||||
description: 'Pièce justificative - Transfert épargne',
|
||||
typeDocument: 'PIECE_JUSTIFICATIVE',
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_pieceJustificativeId = documentId;
|
||||
_uploadingDocument = false;
|
||||
});
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('✓ Pièce justificative uploadée avec succès'),
|
||||
backgroundColor: ColorTokens.success,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_uploadingDocument = false;
|
||||
_pieceJustificative = null;
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Erreur upload : ${e.toString()}'),
|
||||
backgroundColor: ColorTokens.error,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _submit() async {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
if (_compteDestinationId == null || _compteDestinationId!.isEmpty) {
|
||||
@@ -110,6 +171,17 @@ class _TransfertEpargneDialogState extends State<TransfertEpargneDialog> {
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (_origineFondsRequis && _pieceJustificativeId == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'Une pièce justificative est requise pour les opérations ≥ ${_seuilLcbFt.toStringAsFixed(0)} XOF (LCB-FT).',
|
||||
),
|
||||
duration: const Duration(seconds: 4),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
setState(() => _loading = true);
|
||||
try {
|
||||
final request = TransactionEpargneRequest(
|
||||
@@ -119,6 +191,7 @@ class _TransfertEpargneDialogState extends State<TransfertEpargneDialog> {
|
||||
compteDestinationId: _compteDestinationId,
|
||||
motif: _motifController.text.trim().isEmpty ? null : _motifController.text.trim(),
|
||||
origineFonds: _origineFondsController.text.trim().isEmpty ? null : _origineFondsController.text.trim(),
|
||||
pieceJustificativeId: _pieceJustificativeId,
|
||||
);
|
||||
await _repository.transferer(request);
|
||||
if (!mounted) return;
|
||||
@@ -240,6 +313,51 @@ class _TransfertEpargneDialogState extends State<TransfertEpargneDialog> {
|
||||
style: TypographyTokens.bodySmall?.copyWith(color: ColorTokens.primary),
|
||||
),
|
||||
),
|
||||
if (_origineFondsRequis) ...[
|
||||
const SizedBox(height: 16),
|
||||
OutlinedButton.icon(
|
||||
onPressed: _uploadingDocument ? null : _choisirPieceJustificative,
|
||||
icon: _uploadingDocument
|
||||
? const SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: Icon(
|
||||
_pieceJustificativeId != null ? Icons.check_circle : Icons.attach_file,
|
||||
color: _pieceJustificativeId != null ? Colors.green : null,
|
||||
),
|
||||
label: Text(
|
||||
_pieceJustificativeId != null
|
||||
? 'Pièce justificative uploadée'
|
||||
: 'Joindre une pièce justificative *',
|
||||
),
|
||||
style: OutlinedButton.styleFrom(
|
||||
minimumSize: const Size(double.infinity, 48),
|
||||
side: _pieceJustificativeId != null
|
||||
? const BorderSide(color: Colors.green)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
if (_pieceJustificative != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4.0),
|
||||
child: Text(
|
||||
_pieceJustificative!.path.split('/').last,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4.0),
|
||||
child: Text(
|
||||
'Photo ou PDF (max 5 MB)',
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user