|
|
@ -806,12 +806,24 @@ class AppDatabase { |
|
|
|
|
|
|
|
|
Future<List<Commande>> getCommandes() async { |
|
|
Future<List<Commande>> getCommandes() async { |
|
|
final db = await database; |
|
|
final db = await database; |
|
|
|
|
|
|
|
|
final result = await db.query(''' |
|
|
final result = await db.query(''' |
|
|
SELECT c.*, cl.nom as clientNom, cl.prenom as clientPrenom, cl.email as clientEmail |
|
|
SELECT |
|
|
|
|
|
c.*, |
|
|
|
|
|
cl.nom as clientNom, |
|
|
|
|
|
cl.prenom as clientPrenom, |
|
|
|
|
|
cl.email as clientEmail, |
|
|
|
|
|
u.nom as commandeurNom, |
|
|
|
|
|
u.prenom as commandeurPrenom, |
|
|
|
|
|
pdv.nom as pointDeVenteNom, |
|
|
|
|
|
pdv.id as pointDeVenteId |
|
|
FROM commandes c |
|
|
FROM commandes c |
|
|
LEFT JOIN clients cl ON c.clientId = cl.id |
|
|
LEFT JOIN clients cl ON c.clientId = cl.id |
|
|
|
|
|
LEFT JOIN users u ON c.commandeurId = u.id |
|
|
|
|
|
LEFT JOIN points_de_vente pdv ON u.point_de_vente_id = pdv.id |
|
|
ORDER BY c.dateCommande DESC |
|
|
ORDER BY c.dateCommande DESC |
|
|
'''); |
|
|
'''); |
|
|
|
|
|
|
|
|
return result.map((row) => Commande.fromMap(row.fields)).toList(); |
|
|
return result.map((row) => Commande.fromMap(row.fields)).toList(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -1464,7 +1476,8 @@ class AppDatabase { |
|
|
commandeMap['clientId'] = clientId; |
|
|
commandeMap['clientId'] = clientId; |
|
|
|
|
|
|
|
|
final commandeFields = commandeMap.keys.join(', '); |
|
|
final commandeFields = commandeMap.keys.join(', '); |
|
|
final commandePlaceholders = List.filled(commandeMap.length, '?').join(', '); |
|
|
final commandePlaceholders = |
|
|
|
|
|
List.filled(commandeMap.length, '?').join(', '); |
|
|
|
|
|
|
|
|
final commandeResult = await db.query( |
|
|
final commandeResult = await db.query( |
|
|
'INSERT INTO commandes ($commandeFields) VALUES ($commandePlaceholders)', |
|
|
'INSERT INTO commandes ($commandeFields) VALUES ($commandePlaceholders)', |
|
|
@ -1479,7 +1492,8 @@ class AppDatabase { |
|
|
detailMap['commandeId'] = commandeId; |
|
|
detailMap['commandeId'] = commandeId; |
|
|
|
|
|
|
|
|
final detailFields = detailMap.keys.join(', '); |
|
|
final detailFields = detailMap.keys.join(', '); |
|
|
final detailPlaceholders = List.filled(detailMap.length, '?').join(', '); |
|
|
final detailPlaceholders = |
|
|
|
|
|
List.filled(detailMap.length, '?').join(', '); |
|
|
|
|
|
|
|
|
await db.query( |
|
|
await db.query( |
|
|
'INSERT INTO details_commandes ($detailFields) VALUES ($detailPlaceholders)', |
|
|
'INSERT INTO details_commandes ($detailFields) VALUES ($detailPlaceholders)', |
|
|
@ -1502,7 +1516,6 @@ class AppDatabase { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Méthode pour mettre à jour un détail de commande (utile pour modifier les remises) |
|
|
// Méthode pour mettre à jour un détail de commande (utile pour modifier les remises) |
|
|
Future<int> updateDetailCommande(DetailCommande detail) async { |
|
|
Future<int> updateDetailCommande(DetailCommande detail) async { |
|
|
final db = await database; |
|
|
final db = await database; |
|
|
|