commit 28072025_03
This commit is contained in:
parent
f41fc922a6
commit
c5ef3ca0cb
@ -596,32 +596,23 @@ class AppDatabase {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<double> getValeurTotaleStock() async {
|
Future<double> getValeurTotaleStock() async {
|
||||||
final db = await database;
|
final db = await database;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Récupérer tous les produits
|
final result = await db.query(
|
||||||
final List<Map<String, dynamic>> products = (await db.query('products')) as List<Map<String, dynamic>>;
|
'SELECT SUM(stock * price) AS total_stock_value FROM products',
|
||||||
|
);
|
||||||
|
|
||||||
double valeurTotale = 0.0;
|
final value = result.first['total_stock_value'];
|
||||||
for (final product in products) {
|
return (value != null) ? (value as num).toDouble() : 0.0;
|
||||||
final stock = (product['stock'] as num?)?.toDouble();
|
|
||||||
final price = (product['price'] as num?)?.toDouble();
|
|
||||||
|
|
||||||
// Vérifier que stock et price ne sont pas null
|
|
||||||
if (stock != null && price != null) {
|
|
||||||
valeurTotale += (stock * price);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return valeurTotale;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Erreur lors du calcul de la valeur totale du stock : $e');
|
print('Erreur lors du calcul de la valeur totale du stock : $e');
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --- STATISTIQUES ---
|
// --- STATISTIQUES ---
|
||||||
|
|
||||||
Future<Map<String, dynamic>> getStatistiques() async {
|
Future<Map<String, dynamic>> getStatistiques() async {
|
||||||
@ -636,11 +627,14 @@ Future<double> getValeurTotaleStock() async {
|
|||||||
final chiffreAffaires = await db.query(
|
final chiffreAffaires = await db.query(
|
||||||
'SELECT SUM(montantTotal) as total FROM commandes WHERE statut != 5');
|
'SELECT SUM(montantTotal) as total FROM commandes WHERE statut != 5');
|
||||||
|
|
||||||
|
final valeurTotaleStock = await getValeurTotaleStock();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'totalClients': totalClients.first['count'],
|
'totalClients': totalClients.first['count'],
|
||||||
'totalCommandes': totalCommandes.first['count'],
|
'totalCommandes': totalCommandes.first['count'],
|
||||||
'totalProduits': totalProduits.first['count'],
|
'totalProduits': totalProduits.first['count'],
|
||||||
'chiffreAffaires': chiffreAffaires.first['total'] ?? 0.0,
|
'chiffreAffaires': chiffreAffaires.first['total'] ?? 0.0,
|
||||||
|
'valeurTotaleStock': valeurTotaleStock,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user