You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

201 lines
4.7 KiB

// Models/client.dart
class Client {
final int? id;
final String nom;
final String prenom;
final String email;
final String telephone;
final String? adresse;
final DateTime dateCreation;
final bool actif;
Client({
this.id,
required this.nom,
required this.prenom,
required this.email,
required this.telephone,
this.adresse,
required this.dateCreation,
this.actif = true,
});
Map<String, dynamic> toMap() {
return {
'id': id,
'nom': nom,
'prenom': prenom,
'email': email,
'telephone': telephone,
'adresse': adresse,
'dateCreation': dateCreation.toIso8601String(),
'actif': actif ? 1 : 0,
};
}
factory Client.fromMap(Map<String, dynamic> map) {
return Client(
id: map['id'],
nom: map['nom'],
prenom: map['prenom'],
email: map['email'],
telephone: map['telephone'],
adresse: map['adresse'],
dateCreation: DateTime.parse(map['dateCreation']),
actif: map['actif'] == 1,
);
}
String get nomComplet => '$prenom $nom';
}
enum StatutCommande {
enAttente,
confirmee,
enPreparation,
expediee,
livree,
annulee
}
class Commande {
final int? id;
final int clientId;
final DateTime dateCommande;
final StatutCommande statut;
final double montantTotal;
final String? notes;
final DateTime? dateLivraison;
final int? commandeurId;
final int? validateurId;
// Données du client (pour les jointures)
final String? clientNom;
final String? clientPrenom;
final String? clientEmail;
Commande({
this.id,
required this.clientId,
required this.dateCommande,
this.statut = StatutCommande.enAttente,
required this.montantTotal,
this.notes,
this.dateLivraison,
this.commandeurId,
this.validateurId,
this.clientNom,
this.clientPrenom,
this.clientEmail,
});
Map<String, dynamic> toMap() {
return {
'id': id,
'clientId': clientId,
'dateCommande': dateCommande.toIso8601String(),
'statut': statut.index,
'montantTotal': montantTotal,
'notes': notes,
'dateLivraison': dateLivraison?.toIso8601String(),
'commandeurId': commandeurId,
'validateurId': validateurId,
};
}
factory Commande.fromMap(Map<String, dynamic> map) {
return Commande(
id: map['id'],
clientId: map['clientId'],
dateCommande: DateTime.parse(map['dateCommande']),
statut: StatutCommande.values[map['statut']],
montantTotal: map['montantTotal'].toDouble(),
notes: map['notes'],
dateLivraison: map['dateLivraison'] != null
? DateTime.parse(map['dateLivraison'])
: null,
commandeurId: map['commandeurId'],
validateurId: map['validateurId'],
clientNom: map['clientNom'],
clientPrenom: map['clientPrenom'],
clientEmail: map['clientEmail'],
);
}
String get statutLibelle {
switch (statut) {
case StatutCommande.enAttente:
return 'En attente';
case StatutCommande.confirmee:
return 'Confirmée';
case StatutCommande.enPreparation:
return 'En préparation';
case StatutCommande.expediee:
return 'Expédiée';
case StatutCommande.livree:
return 'Livrée';
case StatutCommande.annulee:
return 'Annulée';
default:
return 'Inconnu';
}
}
String get clientNomComplet =>
clientPrenom != null && clientNom != null
? '$clientPrenom $clientNom'
: 'Client inconnu';
}
// Models/detail_commande.dart
class DetailCommande {
final int? id;
final int commandeId;
final int produitId;
final int quantite;
final double prixUnitaire;
final double sousTotal;
// Données du produit (pour les jointures)
final String? produitNom;
final String? produitImage;
final String? produitReference;
DetailCommande({
this.id,
required this.commandeId,
required this.produitId,
required this.quantite,
required this.prixUnitaire,
required this.sousTotal,
this.produitNom,
this.produitImage,
this.produitReference,
});
Map<String, dynamic> toMap() {
return {
'id': id,
'commandeId': commandeId,
'produitId': produitId,
'quantite': quantite,
'prixUnitaire': prixUnitaire,
'sousTotal': sousTotal,
};
}
factory DetailCommande.fromMap(Map<String, dynamic> map) {
return DetailCommande(
id: map['id'],
commandeId: map['commandeId'],
produitId: map['produitId'],
quantite: map['quantite'],
prixUnitaire: map['prixUnitaire'].toDouble(),
sousTotal: map['sousTotal'].toDouble(),
produitNom: map['produitNom'],
produitImage: map['produitImage'],
produitReference: map['produitReference'],
);
}
}