Version initiale de Gestion Prix
App Flutter de gestion de stock/prix pour tablette Android (100% local) : scan code-barres (OpenFoodFacts), prix au kilo/litre, packs, inventaire, prix d'achat + marge, filtres de tri, étiquettes PDF, design noir & blanc. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
final NumberFormat _euro = NumberFormat.currency(locale: 'fr_FR', symbol: '€');
|
||||
|
||||
String euro(double v) => _euro.format(v);
|
||||
@@ -0,0 +1,41 @@
|
||||
import '../models/produit.dart';
|
||||
|
||||
/// Critères de tri partagés (page Produits et page Étiquettes).
|
||||
enum Tri {
|
||||
recent('Récents'),
|
||||
alpha('A → Z'),
|
||||
prixAsc('Prix ↑'),
|
||||
prixDesc('Prix ↓'),
|
||||
margeDesc('Marge ↓'),
|
||||
margeAsc('Marge ↑');
|
||||
|
||||
const Tri(this.libelle);
|
||||
final String libelle;
|
||||
}
|
||||
|
||||
/// Retourne une copie triée de [source] selon [tri].
|
||||
List<Produit> trierProduits(List<Produit> source, Tri tri) {
|
||||
final list = List<Produit>.of(source);
|
||||
switch (tri) {
|
||||
case Tri.recent:
|
||||
// Plus récemment ajouté en premier (date d'ajout, puis id).
|
||||
list.sort((a, b) {
|
||||
final c = b.creeLe.compareTo(a.creeLe);
|
||||
if (c != 0) return c;
|
||||
return (int.tryParse(b.id) ?? 0).compareTo(int.tryParse(a.id) ?? 0);
|
||||
});
|
||||
case Tri.alpha:
|
||||
list.sort((a, b) => a.nom.toLowerCase().compareTo(b.nom.toLowerCase()));
|
||||
case Tri.prixAsc:
|
||||
list.sort((a, b) => a.prix.compareTo(b.prix));
|
||||
case Tri.prixDesc:
|
||||
list.sort((a, b) => b.prix.compareTo(a.prix));
|
||||
case Tri.margeDesc:
|
||||
list.sort(
|
||||
(a, b) => (b.coefficient ?? -1e18).compareTo(a.coefficient ?? -1e18));
|
||||
case Tri.margeAsc:
|
||||
list.sort(
|
||||
(a, b) => (a.coefficient ?? 1e18).compareTo(b.coefficient ?? 1e18));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
Reference in New Issue
Block a user