feat(frontend): module Achats complet (commandes, réception, stock)
- Modèles Fournisseur, PurchaseOrder, PurchaseOrderLine - FournisseurService + PurchaseOrderService (create, receive) - AchatsProvider : chargement parallèle commandes + fournisseurs - AchatsScreen : liste avec badges statut colorés (violet) - PurchaseOrderFormScreen : lignes dynamiques, calcul HT/TVA/TTC - PurchaseOrderDetailScreen : détail + bouton Réceptionner - Réception → entrée stock automatique via backend Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../models/purchase_order.dart';
|
||||
import '../models/fournisseur.dart';
|
||||
import '../services/purchase_order_service.dart';
|
||||
import '../services/fournisseur_service.dart';
|
||||
|
||||
class AchatsProvider extends ChangeNotifier {
|
||||
List<PurchaseOrder> _orders = [];
|
||||
List<Fournisseur> _fournisseurs = [];
|
||||
bool _isLoading = false;
|
||||
String? _error;
|
||||
|
||||
List<PurchaseOrder> get orders => _orders;
|
||||
List<Fournisseur> get fournisseurs => _fournisseurs;
|
||||
bool get isLoading => _isLoading;
|
||||
String? get error => _error;
|
||||
|
||||
Future<void> load() async {
|
||||
_isLoading = true;
|
||||
_error = null;
|
||||
notifyListeners();
|
||||
try {
|
||||
final results = await Future.wait([
|
||||
PurchaseOrderService.fetchAll(),
|
||||
FournisseurService.fetchAll(),
|
||||
]);
|
||||
_orders = results[0] as List<PurchaseOrder>;
|
||||
_fournisseurs = results[1] as List<Fournisseur>;
|
||||
} catch (_) {
|
||||
_error = 'Impossible de charger les commandes achats.';
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> createOrder(PurchaseOrder order) async {
|
||||
try {
|
||||
final created = await PurchaseOrderService.create(order);
|
||||
_orders.insert(0, created);
|
||||
notifyListeners();
|
||||
return null;
|
||||
} catch (_) {
|
||||
return 'Erreur lors de la création de la commande';
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> receive(int orderId, List<PurchaseOrderLine> lignes) async {
|
||||
try {
|
||||
final payload = {
|
||||
'dateReception': DateTime.now().toIso8601String().substring(0, 10),
|
||||
'lignes': lignes.map((l) => {
|
||||
'purchaseOrderLine': {'id': l.id},
|
||||
'article': {'id': l.article!.id},
|
||||
'quantiteRecue': l.quantiteCommandee,
|
||||
}).toList(),
|
||||
};
|
||||
await PurchaseOrderService.receive(orderId, payload);
|
||||
await load();
|
||||
return null;
|
||||
} catch (_) {
|
||||
return 'Erreur lors de la réception';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user