Compare commits
3 Commits
3e6a81c2c3
...
5ad019d35e
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ad019d35e | |||
| a52749c415 | |||
| ab398bddc6 |
@ -8,7 +8,8 @@ plugins {
|
||||
android {
|
||||
namespace = "com.example.my_app"
|
||||
compileSdk = flutter.compileSdkVersion
|
||||
ndkVersion = flutter.ndkVersion
|
||||
ndkVersion = "26.3.11579264"
|
||||
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
|
||||
@ -1447,58 +1447,61 @@ class AppDatabase {
|
||||
// --- TRANSACTIONS COMPLEXES ---
|
||||
|
||||
// Méthode pour créer une commande complète avec remises
|
||||
Future<int> createCommandeComplete(
|
||||
Client client, Commande commande, List<DetailCommande> details) async {
|
||||
final db = await database;
|
||||
Future<int> createCommandeComplete(
|
||||
Client client, Commande commande, List<DetailCommande> details) async {
|
||||
final db = await database;
|
||||
|
||||
try {
|
||||
await db.query('START TRANSACTION');
|
||||
try {
|
||||
await db.query('START TRANSACTION');
|
||||
|
||||
// 1. Créer ou récupérer le client
|
||||
final existingOrNewClient = await createOrGetClient(client);
|
||||
final clientId = existingOrNewClient.id!;
|
||||
// 1. Créer ou récupérer le client
|
||||
final existingOrNewClient = await createOrGetClient(client);
|
||||
final clientId = existingOrNewClient.id!;
|
||||
|
||||
// 2. Créer la commande
|
||||
final commandeMap = commande.toMap();
|
||||
commandeMap.remove('id');
|
||||
commandeMap['clientId'] = clientId;
|
||||
// 2. Créer la commande
|
||||
final commandeMap = commande.toMap();
|
||||
commandeMap.remove('id');
|
||||
commandeMap['clientId'] = clientId;
|
||||
|
||||
final commandeFields = commandeMap.keys.join(', ');
|
||||
final commandePlaceholders =
|
||||
List.filled(commandeMap.length, '?').join(', ');
|
||||
final commandeFields = commandeMap.keys.join(', ');
|
||||
final commandePlaceholders = List.filled(commandeMap.length, '?').join(', ');
|
||||
|
||||
final commandeResult = await db.query(
|
||||
'INSERT INTO commandes ($commandeFields) VALUES ($commandePlaceholders)',
|
||||
commandeMap.values.toList());
|
||||
final commandeId = commandeResult.insertId!;
|
||||
final commandeResult = await db.query(
|
||||
'INSERT INTO commandes ($commandeFields) VALUES ($commandePlaceholders)',
|
||||
commandeMap.values.toList(),
|
||||
);
|
||||
final commandeId = commandeResult.insertId!;
|
||||
|
||||
// 3. Créer les détails de commande avec remises
|
||||
for (final detail in details) {
|
||||
final detailMap = detail.toMap();
|
||||
detailMap.remove('id');
|
||||
detailMap['commandeId'] = commandeId;
|
||||
// 3. Créer les détails de commande avec remises
|
||||
for (final detail in details) {
|
||||
final detailMap = detail.toMap();
|
||||
detailMap.remove('id');
|
||||
detailMap['commandeId'] = commandeId;
|
||||
|
||||
final detailFields = detailMap.keys.join(', ');
|
||||
final detailPlaceholders =
|
||||
List.filled(detailMap.length, '?').join(', ');
|
||||
final detailFields = detailMap.keys.join(', ');
|
||||
final detailPlaceholders = List.filled(detailMap.length, '?').join(', ');
|
||||
|
||||
await db.query(
|
||||
'INSERT INTO details_commandes ($detailFields) VALUES ($detailPlaceholders)',
|
||||
detailMap.values.toList());
|
||||
await db.query(
|
||||
'INSERT INTO details_commandes ($detailFields) VALUES ($detailPlaceholders)',
|
||||
detailMap.values.toList(),
|
||||
);
|
||||
|
||||
// 4. Mettre à jour le stock
|
||||
await db.query('UPDATE products SET stock = stock - ? WHERE id = ?',
|
||||
[detail.quantite, detail.produitId]);
|
||||
}
|
||||
|
||||
await db.query('COMMIT');
|
||||
return commandeId;
|
||||
} catch (e) {
|
||||
await db.query('ROLLBACK');
|
||||
print("Erreur lors de la création de la commande complète: $e");
|
||||
rethrow;
|
||||
// 4. Mettre à jour le stock
|
||||
await db.query(
|
||||
'UPDATE products SET stock = stock - ? WHERE id = ?',
|
||||
[detail.quantite, detail.produitId],
|
||||
);
|
||||
}
|
||||
|
||||
await db.query('COMMIT');
|
||||
return commandeId;
|
||||
} catch (e) {
|
||||
await db.query('ROLLBACK');
|
||||
print("Erreur lors de la création de la commande complète: $e");
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Méthode pour mettre à jour un détail de commande (utile pour modifier les remises)
|
||||
Future<int> updateDetailCommande(DetailCommande detail) async {
|
||||
|
||||
@ -52,6 +52,7 @@ class _ApprobationSortiesPageState extends State<ApprobationSortiesPage> {
|
||||
Text('Quantité: ${sortie['quantite']}'),
|
||||
Text('Demandeur: ${sortie['admin_nom']}'),
|
||||
Text('Motif: ${sortie['motif']}'),
|
||||
Text('Note: ${sortie['notes']}'),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'Confirmer l\'approbation de cette demande de sortie personnelle ?',
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -177,7 +177,7 @@ void _login() async {
|
||||
|
||||
// 6. Navigation immédiate
|
||||
if (mounted) {
|
||||
if (userCredentials['role'] == 'commercial') {
|
||||
if (userCredentials['role'] == 'commercial' || userCredentials['role'] == 'caisse') {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const MainLayout()),
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
16
pubspec.lock
16
pubspec.lock
@ -37,10 +37,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: async
|
||||
sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb"
|
||||
sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.13.0"
|
||||
version: "2.12.0"
|
||||
barcode:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -181,10 +181,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: fake_async
|
||||
sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44"
|
||||
sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.3"
|
||||
version: "1.3.2"
|
||||
ffi:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -516,10 +516,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker
|
||||
sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"
|
||||
sha256: c35baad643ba394b40aac41080300150a4f08fd0fd6a10378f8f7c6bc161acec
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "10.0.9"
|
||||
version: "10.0.8"
|
||||
leak_tracker_flutter_testing:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -1193,10 +1193,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vm_service
|
||||
sha256: ddfa8d30d89985b96407efce8acbdd124701f96741f2d981ca860662f1c0dc02
|
||||
sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "15.0.0"
|
||||
version: "14.3.1"
|
||||
web:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user