|
|
|
@ -1,5 +1,9 @@ |
|
|
|
import 'dart:io'; |
|
|
|
import 'dart:typed_data'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'package:image_picker/image_picker.dart'; |
|
|
|
import 'package:path_provider/path_provider.dart'; |
|
|
|
import 'package:youmazgestion/Components/app_bar.dart'; |
|
|
|
import 'package:youmazgestion/Components/appDrawer.dart'; |
|
|
|
import 'package:youmazgestion/Services/stock_managementDatabase.dart'; |
|
|
|
@ -22,8 +26,10 @@ class _AjoutPointDeVentePageState extends State<AjoutPointDeVentePage> { |
|
|
|
|
|
|
|
// Liste des points de vente |
|
|
|
List<Map<String, dynamic>> _pointsDeVente = []; |
|
|
|
List<Map<String, dynamic>> _filteredPointsDeVente = []; |
|
|
|
final TextEditingController _searchController = TextEditingController(); |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
void initState() { |
|
|
|
super.initState(); |
|
|
|
@ -31,10 +37,12 @@ class _AjoutPointDeVentePageState extends State<AjoutPointDeVentePage> { |
|
|
|
_searchController.addListener(_filterPointsDeVente); |
|
|
|
} |
|
|
|
|
|
|
|
Future<void> _loadPointsDeVente() async { |
|
|
|
Future<void> _loadPointsDeVente() async { |
|
|
|
if (mounted) { |
|
|
|
setState(() { |
|
|
|
_isLoading = true; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
final points = await _appDatabase.getPointsDeVente(); |
|
|
|
@ -46,11 +54,15 @@ Future<void> _loadPointsDeVente() async { |
|
|
|
point['constraintCount'] = (verification['reasons'] as List).length; |
|
|
|
} |
|
|
|
|
|
|
|
if (mounted) { |
|
|
|
setState(() { |
|
|
|
_pointsDeVente = points; |
|
|
|
_filteredPointsDeVente = List.from(points); |
|
|
|
_isLoading = false; |
|
|
|
}); |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
if (mounted) { |
|
|
|
setState(() { |
|
|
|
_isLoading = false; |
|
|
|
}); |
|
|
|
@ -62,22 +74,25 @@ Future<void> _loadPointsDeVente() async { |
|
|
|
colorText: Colors.white, |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void _filterPointsDeVente() { |
|
|
|
final query = _searchController.text.toLowerCase(); |
|
|
|
if (query.isEmpty) { |
|
|
|
_loadPointsDeVente(); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void _filterPointsDeVente() { |
|
|
|
final query = _searchController.text.toLowerCase().trim(); |
|
|
|
if (mounted) { |
|
|
|
setState(() { |
|
|
|
_pointsDeVente = _pointsDeVente.where((point) { |
|
|
|
if (query.isEmpty) { |
|
|
|
_filteredPointsDeVente = List.from(_pointsDeVente); |
|
|
|
} else { |
|
|
|
_filteredPointsDeVente = _pointsDeVente.where((point) { |
|
|
|
final nom = point['nom']?.toString().toLowerCase() ?? ''; |
|
|
|
return nom.contains(query); |
|
|
|
final code = point['code']?.toString().toLowerCase() ?? ''; |
|
|
|
return nom.contains(query) || code.contains(query); |
|
|
|
}).toList(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Future<void> _submitForm() async { |
|
|
|
if (_formKey.currentState!.validate()) { |
|
|
|
@ -114,26 +129,261 @@ Future<void> _loadPointsDeVente() async { |
|
|
|
colorText: Colors.white, |
|
|
|
); |
|
|
|
} finally { |
|
|
|
if (mounted) { |
|
|
|
setState(() { |
|
|
|
_isLoading = false; |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Future<void> _showConstraintDialog(int id, Map<String, dynamic> verificationResult) async { |
|
|
|
} |
|
|
|
Future<void> editPointDeVente(BuildContext context, Map<String, dynamic> pointDeVente) async { |
|
|
|
print('=== DIAGNOSTIC DES DONNÉES ==='); |
|
|
|
print('ID: ${pointDeVente['id']}'); |
|
|
|
print('Nom: ${pointDeVente['nom']}'); |
|
|
|
print('Code: ${pointDeVente['code']}'); |
|
|
|
print('Content (ticket): "${pointDeVente['content']}" (Type: ${pointDeVente['content'].runtimeType})'); |
|
|
|
print('Livraison: "${pointDeVente['livraison']}" (Type: ${pointDeVente['livraison'].runtimeType})'); |
|
|
|
print('Facture: "${pointDeVente['facture']}" (Type: ${pointDeVente['facture'].runtimeType})'); |
|
|
|
print('Logo: ${pointDeVente['logo']?.runtimeType}'); |
|
|
|
print('Toutes les clés: ${pointDeVente.keys.toList()}'); |
|
|
|
print('==============================='); |
|
|
|
final _editFormKey = GlobalKey<FormState>(); |
|
|
|
final ImagePicker _picker = ImagePicker(); |
|
|
|
|
|
|
|
// Fonction helper pour convertir les valeurs en String de manière sûre |
|
|
|
String safeStringConversion(dynamic value) { |
|
|
|
if (value == null) return ''; |
|
|
|
if (value is String) return value; |
|
|
|
// Vérifier si c'est un type binaire (Uint8List, List<int>, etc.) |
|
|
|
if (value is Uint8List || value is List<int> || value is List) { |
|
|
|
// Si c'est des données binaires, on retourne une chaîne vide |
|
|
|
// car on ne peut pas les convertir en texte lisible |
|
|
|
return ''; |
|
|
|
} |
|
|
|
// Pour tous les autres types, essayer la conversion toString() |
|
|
|
try { |
|
|
|
return value.toString(); |
|
|
|
} catch (e) { |
|
|
|
print('Erreur conversion vers String: $e, type: ${value.runtimeType}'); |
|
|
|
return ''; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Initialisation dynamique des contrôleurs avec conversion sécurisée |
|
|
|
final _editNomController = TextEditingController( |
|
|
|
text: safeStringConversion(pointDeVente['nom']) |
|
|
|
); |
|
|
|
final _editCodeController = TextEditingController( |
|
|
|
text: safeStringConversion(pointDeVente['code']) |
|
|
|
); |
|
|
|
final _editTicketController = TextEditingController( |
|
|
|
text: safeStringConversion(pointDeVente['content']) |
|
|
|
); |
|
|
|
final _editLivraisonController = TextEditingController( |
|
|
|
text: safeStringConversion(pointDeVente['livraison']) |
|
|
|
); |
|
|
|
final _editFactureController = TextEditingController( |
|
|
|
text: safeStringConversion(pointDeVente['facture']) |
|
|
|
); |
|
|
|
|
|
|
|
File? _selectedImage; |
|
|
|
Uint8List? _currentImageBlob; |
|
|
|
|
|
|
|
// Gérer la conversion du logo de manière sécurisée |
|
|
|
final logoData = pointDeVente['logo']; |
|
|
|
if (logoData != null) { |
|
|
|
try { |
|
|
|
if (logoData is Uint8List) { |
|
|
|
_currentImageBlob = logoData; |
|
|
|
} else if (logoData is List<int>) { |
|
|
|
_currentImageBlob = Uint8List.fromList(logoData); |
|
|
|
} else if (logoData is List) { |
|
|
|
// Cas où c'est une List<dynamic> contenant des int |
|
|
|
_currentImageBlob = Uint8List.fromList(logoData.cast<int>()); |
|
|
|
} else { |
|
|
|
// Type non supporté (comme Blob), laisser null et logger |
|
|
|
print('Type de logo non supporté: ${logoData.runtimeType}'); |
|
|
|
_currentImageBlob = null; |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
print('Erreur lors de la conversion du logo: $e'); |
|
|
|
_currentImageBlob = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
bool _isEditLoading = false; |
|
|
|
|
|
|
|
Future<void> pickImage(ImageSource source) async { |
|
|
|
try { |
|
|
|
final XFile? image = await _picker.pickImage(source: source); |
|
|
|
if (image != null) { |
|
|
|
_selectedImage = File(image.path); |
|
|
|
_currentImageBlob = await _selectedImage!.readAsBytes(); |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
print('Erreur lors de la sélection de l\'image : $e'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Future<void> saveChanges() async { |
|
|
|
if (_editFormKey.currentState?.validate() ?? false) { |
|
|
|
_isEditLoading = true; |
|
|
|
|
|
|
|
try { |
|
|
|
await _appDatabase.updatePointDeVentes( |
|
|
|
pointDeVente['id'], |
|
|
|
_editNomController.text.trim(), |
|
|
|
_editCodeController.text.trim(), |
|
|
|
content: _editTicketController.text.trim(), |
|
|
|
livraison: _editLivraisonController.text.trim(), |
|
|
|
facture: _editFactureController.text.trim(), |
|
|
|
imagePath: _currentImageBlob, |
|
|
|
); |
|
|
|
|
|
|
|
Get.back(); // Fermer le dialog |
|
|
|
ScaffoldMessenger.of(context).showSnackBar( |
|
|
|
const SnackBar(content: Text('Modification enregistrée avec succès')), |
|
|
|
); |
|
|
|
|
|
|
|
await _loadPointsDeVente(); // Rafraîchir la liste |
|
|
|
} catch (e) { |
|
|
|
print('Erreur lors de la sauvegarde : $e'); |
|
|
|
ScaffoldMessenger.of(context).showSnackBar( |
|
|
|
const SnackBar(content: Text('Erreur lors de la modification')), |
|
|
|
); |
|
|
|
} finally { |
|
|
|
_isEditLoading = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Affichage de la boîte de dialogue |
|
|
|
await Get.dialog( |
|
|
|
Dialog( |
|
|
|
child: ConstrainedBox( |
|
|
|
constraints: const BoxConstraints(maxWidth: 500, maxHeight: 700), |
|
|
|
child: Padding( |
|
|
|
padding: const EdgeInsets.all(16.0), |
|
|
|
child: Form( |
|
|
|
key: _editFormKey, |
|
|
|
child: SingleChildScrollView( |
|
|
|
child: Column( |
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
children: [ |
|
|
|
const Text('Modifier le point de vente', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), |
|
|
|
const SizedBox(height: 16), |
|
|
|
TextFormField( |
|
|
|
controller: _editNomController, |
|
|
|
decoration: const InputDecoration(labelText: 'Nom du point de vente'), |
|
|
|
validator: (value) => value == null || value.isEmpty ? 'Le nom est requis' : null, |
|
|
|
), |
|
|
|
const SizedBox(height: 8), |
|
|
|
TextFormField( |
|
|
|
controller: _editCodeController, |
|
|
|
decoration: const InputDecoration(labelText: 'Code du point de vente'), |
|
|
|
), |
|
|
|
const SizedBox(height: 8), |
|
|
|
TextFormField( |
|
|
|
controller: _editTicketController, |
|
|
|
decoration: const InputDecoration(labelText: 'Info ticket'), |
|
|
|
maxLines: 3, |
|
|
|
), |
|
|
|
const SizedBox(height: 8), |
|
|
|
TextFormField( |
|
|
|
controller: _editLivraisonController, |
|
|
|
decoration: const InputDecoration(labelText: 'Info bon de livraison'), |
|
|
|
maxLines: 3, |
|
|
|
), |
|
|
|
const SizedBox(height: 8), |
|
|
|
TextFormField( |
|
|
|
controller: _editFactureController, |
|
|
|
decoration: const InputDecoration(labelText: 'Info facture'), |
|
|
|
maxLines: 3, |
|
|
|
), |
|
|
|
const SizedBox(height: 16), |
|
|
|
Row( |
|
|
|
children: [ |
|
|
|
Expanded( |
|
|
|
child: ElevatedButton.icon( |
|
|
|
onPressed: () => pickImage(ImageSource.gallery), |
|
|
|
icon: const Icon(Icons.image), |
|
|
|
label: const Text('Galerie'), |
|
|
|
), |
|
|
|
), |
|
|
|
const SizedBox(width: 10), |
|
|
|
Expanded( |
|
|
|
child: ElevatedButton.icon( |
|
|
|
onPressed: () => pickImage(ImageSource.camera), |
|
|
|
icon: const Icon(Icons.camera_alt), |
|
|
|
label: const Text('Caméra'), |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
const SizedBox(height: 10), |
|
|
|
if (_currentImageBlob != null) |
|
|
|
Container( |
|
|
|
height: 100, |
|
|
|
width: double.infinity, |
|
|
|
decoration: BoxDecoration( |
|
|
|
borderRadius: BorderRadius.circular(8), |
|
|
|
border: Border.all(color: Colors.grey.shade300), |
|
|
|
), |
|
|
|
child: ClipRRect( |
|
|
|
borderRadius: BorderRadius.circular(8), |
|
|
|
child: Image.memory( |
|
|
|
_currentImageBlob!, |
|
|
|
fit: BoxFit.cover, |
|
|
|
errorBuilder: (context, error, stackTrace) => |
|
|
|
const Center(child: Text('Erreur image')), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
const SizedBox(height: 16), |
|
|
|
SizedBox( |
|
|
|
width: double.infinity, |
|
|
|
child: ElevatedButton.icon( |
|
|
|
onPressed: _isEditLoading ? null : saveChanges, |
|
|
|
icon: const Icon(Icons.save), |
|
|
|
label: Text(_isEditLoading ? 'Sauvegarde...' : 'Enregistrer'), |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
|
|
|
|
// Nettoyage |
|
|
|
await Future.delayed(const Duration(milliseconds: 200)); |
|
|
|
_editNomController.dispose(); |
|
|
|
_editCodeController.dispose(); |
|
|
|
_editTicketController.dispose(); |
|
|
|
_editLivraisonController.dispose(); |
|
|
|
_editFactureController.dispose(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Future<void> _showConstraintDialog(int id, Map<String, dynamic> verificationResult) async { |
|
|
|
final reasons = verificationResult['reasons'] as List<String>; |
|
|
|
final suggestions = verificationResult['suggestions'] as List<String>; |
|
|
|
|
|
|
|
await Get.dialog( |
|
|
|
AlertDialog( |
|
|
|
title: Row( |
|
|
|
children: const [ |
|
|
|
title: const Row( |
|
|
|
children: [ |
|
|
|
Icon(Icons.warning, color: Colors.orange), |
|
|
|
SizedBox(width: 8), |
|
|
|
Text('Suppression impossible'), |
|
|
|
Expanded(child: Text('Suppression impossible')), |
|
|
|
], |
|
|
|
), |
|
|
|
content: SingleChildScrollView( |
|
|
|
content: ConstrainedBox( |
|
|
|
constraints: const BoxConstraints(maxHeight: 400), |
|
|
|
child: SingleChildScrollView( |
|
|
|
child: Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
@ -174,6 +424,7 @@ Future<void> _showConstraintDialog(int id, Map<String, dynamic> verificationResu |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
actions: [ |
|
|
|
TextButton( |
|
|
|
onPressed: () => Get.back(), |
|
|
|
@ -189,13 +440,14 @@ Future<void> _showConstraintDialog(int id, Map<String, dynamic> verificationResu |
|
|
|
backgroundColor: Colors.blue, |
|
|
|
foregroundColor: Colors.white, |
|
|
|
), |
|
|
|
child: const Text('Transférer les produits'), |
|
|
|
child: const Text('Transférer'), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
); |
|
|
|
} |
|
|
|
Future<void> _showTransferDialog(int sourcePointDeVenteId) async { |
|
|
|
} |
|
|
|
|
|
|
|
Future<void> _showTransferDialog(int sourcePointDeVenteId) async { |
|
|
|
final pointsDeVente = await _appDatabase.getPointsDeVenteForTransfer(sourcePointDeVenteId); |
|
|
|
|
|
|
|
if (pointsDeVente.isEmpty) { |
|
|
|
@ -214,31 +466,35 @@ Future<void> _showTransferDialog(int sourcePointDeVenteId) async { |
|
|
|
await Get.dialog( |
|
|
|
AlertDialog( |
|
|
|
title: const Text('Transférer les produits'), |
|
|
|
content: Column( |
|
|
|
content: ConstrainedBox( |
|
|
|
constraints: const BoxConstraints(minWidth: 300), |
|
|
|
child: Column( |
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
children: [ |
|
|
|
const Text('Sélectionnez le point de vente de destination pour les produits :'), |
|
|
|
const SizedBox(height: 16), |
|
|
|
SizedBox( |
|
|
|
width: double.maxFinite, |
|
|
|
child: DropdownButtonFormField<int>( |
|
|
|
DropdownButtonFormField<int>( |
|
|
|
value: selectedPointDeVenteId, |
|
|
|
isExpanded: true, |
|
|
|
decoration: const InputDecoration( |
|
|
|
labelText: 'Point de vente de destination', |
|
|
|
border: OutlineInputBorder(), |
|
|
|
), |
|
|
|
items: pointsDeVente.map((pv) => DropdownMenuItem<int>( |
|
|
|
value: pv['id'] as int, |
|
|
|
child: Text(pv['nom'] as String), |
|
|
|
child: Text( |
|
|
|
pv['nom'] as String, |
|
|
|
overflow: TextOverflow.ellipsis, |
|
|
|
), |
|
|
|
)).toList(), |
|
|
|
onChanged: (value) { |
|
|
|
selectedPointDeVenteId = value; |
|
|
|
}, |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
actions: [ |
|
|
|
TextButton( |
|
|
|
onPressed: () => Get.back(), |
|
|
|
@ -263,20 +519,21 @@ Future<void> _showTransferDialog(int sourcePointDeVenteId) async { |
|
|
|
backgroundColor: Colors.green, |
|
|
|
foregroundColor: Colors.white, |
|
|
|
), |
|
|
|
child: const Text('Transférer et supprimer'), |
|
|
|
child: const Text('Transférer'), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
); |
|
|
|
} |
|
|
|
// Nouvelle méthode pour effectuer le transfert et la suppression |
|
|
|
Future<void> _performTransferAndDelete(int sourceId, int targetId) async { |
|
|
|
} |
|
|
|
|
|
|
|
Future<void> _performTransferAndDelete(int sourceId, int targetId) async { |
|
|
|
if (mounted) { |
|
|
|
setState(() { |
|
|
|
_isLoading = true; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
// Afficher un dialog de confirmation final |
|
|
|
final confirmed = await Get.dialog<bool>( |
|
|
|
AlertDialog( |
|
|
|
title: const Text('Confirmation finale'), |
|
|
|
@ -324,38 +581,97 @@ Future<void> _performTransferAndDelete(int sourceId, int targetId) async { |
|
|
|
colorText: Colors.white, |
|
|
|
); |
|
|
|
} finally { |
|
|
|
if (mounted) { |
|
|
|
setState(() { |
|
|
|
_isLoading = false; |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
// Vous pouvez aussi ajouter une méthode pour voir les détails d'un point de vente |
|
|
|
Future<void> _showPointDeVenteDetails(Map<String, dynamic> pointDeVente) async { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Future<void> _showPointDeVenteDetails(Map<String, dynamic> pointDeVente) async { |
|
|
|
final id = pointDeVente['id'] as int; |
|
|
|
|
|
|
|
try { |
|
|
|
// Récupérer les statistiques |
|
|
|
final stats = await _getPointDeVenteStats(id); |
|
|
|
|
|
|
|
await Get.dialog( |
|
|
|
AlertDialog( |
|
|
|
title: Text('Détails: ${pointDeVente['nom']}'), |
|
|
|
content: SingleChildScrollView( |
|
|
|
title: Text( |
|
|
|
'Détails: ${pointDeVente['nom']}', |
|
|
|
style: const TextStyle(fontSize: 16), |
|
|
|
), |
|
|
|
content: ConstrainedBox( |
|
|
|
constraints: const BoxConstraints( |
|
|
|
maxWidth: 400, |
|
|
|
maxHeight: 500, |
|
|
|
), |
|
|
|
child: SingleChildScrollView( |
|
|
|
child: Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
children: [ |
|
|
|
if (pointDeVente['logo'] != null) |
|
|
|
Container( |
|
|
|
height: 150, |
|
|
|
width: double.infinity, |
|
|
|
margin: const EdgeInsets.only(bottom: 16), |
|
|
|
decoration: BoxDecoration( |
|
|
|
borderRadius: BorderRadius.circular(8), |
|
|
|
border: Border.all(color: Colors.grey.shade300), |
|
|
|
), |
|
|
|
child: ClipRRect( |
|
|
|
borderRadius: BorderRadius.circular(8), |
|
|
|
child: Image.memory( |
|
|
|
pointDeVente['logo'] as Uint8List, |
|
|
|
fit: BoxFit.cover, |
|
|
|
errorBuilder: (context, error, stackTrace) { |
|
|
|
return Container( |
|
|
|
color: Colors.grey.shade200, |
|
|
|
child: const Center( |
|
|
|
child: Text('Image non disponible'), |
|
|
|
), |
|
|
|
); |
|
|
|
}, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
|
|
|
|
_buildStatRow('Produits associés', '${stats['produits']}'), |
|
|
|
_buildStatRow('Utilisateurs associés', '${stats['utilisateurs']}'), |
|
|
|
_buildStatRow('Demandes de transfert', '${stats['transferts']}'), |
|
|
|
const SizedBox(height: 8), |
|
|
|
Text( |
|
|
|
'Code: ${pointDeVente['code'] ?? 'N/A'}', |
|
|
|
if (pointDeVente['content'] != null && |
|
|
|
pointDeVente['content'].toString().isNotEmpty) |
|
|
|
Padding( |
|
|
|
padding: const EdgeInsets.only(top: 4), |
|
|
|
child: Text( |
|
|
|
'Ticket: ${pointDeVente['content']}', |
|
|
|
style: const TextStyle(fontSize: 12, color: Colors.grey), |
|
|
|
), |
|
|
|
), |
|
|
|
if (pointDeVente['livraison'] != null && |
|
|
|
pointDeVente['livraison'].toString().isNotEmpty) |
|
|
|
Padding( |
|
|
|
padding: const EdgeInsets.only(top: 4), |
|
|
|
child: Text( |
|
|
|
'Bon de livraison: ${pointDeVente['livraison']}', |
|
|
|
style: const TextStyle(fontSize: 12, color: Colors.grey), |
|
|
|
), |
|
|
|
), |
|
|
|
if (pointDeVente['facture'] != null && |
|
|
|
pointDeVente['facture'].toString().isNotEmpty) |
|
|
|
Padding( |
|
|
|
padding: const EdgeInsets.only(top: 4), |
|
|
|
child: Text( |
|
|
|
'Facture: ${pointDeVente['facture']}', |
|
|
|
style: const TextStyle(fontSize: 12, color: Colors.grey), |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
actions: [ |
|
|
|
TextButton( |
|
|
|
onPressed: () => Get.back(), |
|
|
|
@ -373,23 +689,30 @@ Future<void> _showPointDeVenteDetails(Map<String, dynamic> pointDeVente) async { |
|
|
|
colorText: Colors.white, |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Widget _buildStatRow(String label, String value) { |
|
|
|
Widget _buildStatRow(String label, String value) { |
|
|
|
return Padding( |
|
|
|
padding: const EdgeInsets.symmetric(vertical: 2), |
|
|
|
child: Row( |
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
children: [ |
|
|
|
Text(label), |
|
|
|
Text(value, style: const TextStyle(fontWeight: FontWeight.bold)), |
|
|
|
Expanded( |
|
|
|
child: Text( |
|
|
|
label, |
|
|
|
style: const TextStyle(fontSize: 13), |
|
|
|
), |
|
|
|
), |
|
|
|
Text( |
|
|
|
value, |
|
|
|
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 13), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Méthode helper pour récupérer les stats |
|
|
|
Future<Map<String, int>> _getPointDeVenteStats(int id) async { |
|
|
|
Future<Map<String, int>> _getPointDeVenteStats(int id) async { |
|
|
|
final verification = await _appDatabase.checkCanDeletePointDeVente(id); |
|
|
|
|
|
|
|
// Parser les raisons pour extraire les nombres |
|
|
|
@ -410,19 +733,16 @@ Future<Map<String, int>> _getPointDeVenteStats(int id) async { |
|
|
|
'utilisateurs': utilisateurs, |
|
|
|
'transferts': transferts, |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Future<void> _deletePointDeVente(int id) async { |
|
|
|
// 1. D'abord vérifier si la suppression est possible |
|
|
|
final verificationResult = await _appDatabase.checkCanDeletePointDeVente(id); |
|
|
|
|
|
|
|
if (!verificationResult['canDelete']) { |
|
|
|
// Afficher un dialog avec les détails des contraintes |
|
|
|
await _showConstraintDialog(id, verificationResult); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 2. Si pas de contraintes, procéder normalement |
|
|
|
final confirmed = await Get.dialog<bool>( |
|
|
|
AlertDialog( |
|
|
|
title: const Text('Confirmer la suppression'), |
|
|
|
@ -441,9 +761,11 @@ Future<Map<String, int>> _getPointDeVenteStats(int id) async { |
|
|
|
); |
|
|
|
|
|
|
|
if (confirmed == true) { |
|
|
|
if (mounted) { |
|
|
|
setState(() { |
|
|
|
_isLoading = true; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
await _appDatabase.deletePointDeVente(id); |
|
|
|
@ -465,12 +787,14 @@ Future<Map<String, int>> _getPointDeVenteStats(int id) async { |
|
|
|
colorText: Colors.white, |
|
|
|
); |
|
|
|
} finally { |
|
|
|
if (mounted) { |
|
|
|
setState(() { |
|
|
|
_isLoading = false; |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
@ -503,7 +827,6 @@ Future<Map<String, int>> _getPointDeVenteStats(int id) async { |
|
|
|
), |
|
|
|
const SizedBox(height: 16), |
|
|
|
|
|
|
|
// Champ Nom |
|
|
|
TextFormField( |
|
|
|
controller: _nomController, |
|
|
|
decoration: InputDecoration( |
|
|
|
@ -524,7 +847,6 @@ Future<Map<String, int>> _getPointDeVenteStats(int id) async { |
|
|
|
), |
|
|
|
const SizedBox(height: 12), |
|
|
|
|
|
|
|
// Champ Code |
|
|
|
TextFormField( |
|
|
|
controller: _codeController, |
|
|
|
decoration: InputDecoration( |
|
|
|
@ -539,10 +861,8 @@ Future<Map<String, int>> _getPointDeVenteStats(int id) async { |
|
|
|
), |
|
|
|
const SizedBox(height: 16), |
|
|
|
|
|
|
|
// Bouton de soumission |
|
|
|
ElevatedButton( |
|
|
|
onPressed: _isLoading ? null : _submitForm, |
|
|
|
|
|
|
|
style: ElevatedButton.styleFrom( |
|
|
|
padding: const EdgeInsets.symmetric(vertical: 16), |
|
|
|
backgroundColor: Colors.blue.shade800, |
|
|
|
@ -579,7 +899,7 @@ Future<Map<String, int>> _getPointDeVenteStats(int id) async { |
|
|
|
children: [ |
|
|
|
// Barre de recherche |
|
|
|
Padding( |
|
|
|
padding: const EdgeInsets.only(bottom: 8), |
|
|
|
padding: const EdgeInsets.only(bottom: 16), |
|
|
|
child: TextField( |
|
|
|
controller: _searchController, |
|
|
|
decoration: InputDecoration( |
|
|
|
@ -595,7 +915,7 @@ Future<Map<String, int>> _getPointDeVenteStats(int id) async { |
|
|
|
icon: const Icon(Icons.clear), |
|
|
|
onPressed: () { |
|
|
|
_searchController.clear(); |
|
|
|
_loadPointsDeVente(); |
|
|
|
_filterPointsDeVente(); |
|
|
|
}, |
|
|
|
) |
|
|
|
: null, |
|
|
|
@ -603,49 +923,11 @@ Future<Map<String, int>> _getPointDeVenteStats(int id) async { |
|
|
|
), |
|
|
|
), |
|
|
|
|
|
|
|
// En-tête de liste |
|
|
|
Padding( |
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8), |
|
|
|
child: Row( |
|
|
|
children: [ |
|
|
|
const Expanded( |
|
|
|
flex: 2, |
|
|
|
child: Text( |
|
|
|
'Nom', |
|
|
|
style: TextStyle( |
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
color: Color.fromARGB(255, 9, 56, 95), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
const Expanded( |
|
|
|
child: Text( |
|
|
|
'Code', |
|
|
|
style: TextStyle( |
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
color: Color.fromARGB(255, 9, 56, 95), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
SizedBox( |
|
|
|
width: 40, |
|
|
|
child: Text( |
|
|
|
'Actions', |
|
|
|
style: TextStyle( |
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
color: Color.fromARGB(255, 9, 56, 95), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
|
|
|
|
// Liste |
|
|
|
Expanded( |
|
|
|
child: _isLoading && _pointsDeVente.isEmpty |
|
|
|
child: _isLoading && _filteredPointsDeVente.isEmpty |
|
|
|
? const Center(child: CircularProgressIndicator()) |
|
|
|
: _pointsDeVente.isEmpty |
|
|
|
: _filteredPointsDeVente.isEmpty |
|
|
|
? const Center( |
|
|
|
child: Column( |
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
@ -663,12 +945,11 @@ Future<Map<String, int>> _getPointDeVenteStats(int id) async { |
|
|
|
), |
|
|
|
) |
|
|
|
: ListView.builder( |
|
|
|
itemCount: _pointsDeVente.length, |
|
|
|
itemCount: _filteredPointsDeVente.length, |
|
|
|
itemBuilder: (context, index) { |
|
|
|
final point = _pointsDeVente[index]; |
|
|
|
final point = _filteredPointsDeVente[index]; |
|
|
|
final canDelete = point['canDelete'] ?? true; |
|
|
|
final constraintCount = point['constraintCount'] ?? 0; |
|
|
|
|
|
|
|
return Card( |
|
|
|
margin: const EdgeInsets.only(bottom: 8), |
|
|
|
elevation: 2, |
|
|
|
@ -791,7 +1072,16 @@ Future<Map<String, int>> _getPointDeVenteStats(int id) async { |
|
|
|
onPressed: () => _showPointDeVenteDetails(point), |
|
|
|
tooltip: 'Voir les détails', |
|
|
|
), |
|
|
|
|
|
|
|
// Bouton modifier |
|
|
|
IconButton( |
|
|
|
icon: Icon( |
|
|
|
Icons.edit, |
|
|
|
size: 20, |
|
|
|
color: Colors.blue.shade600, |
|
|
|
), |
|
|
|
onPressed: () => editPointDeVente(context, point), |
|
|
|
tooltip: 'Modifier point de vente', |
|
|
|
), |
|
|
|
// Bouton suppression avec indication visuelle |
|
|
|
IconButton( |
|
|
|
icon: Icon( |
|
|
|
@ -810,7 +1100,7 @@ Future<Map<String, int>> _getPointDeVenteStats(int id) async { |
|
|
|
), |
|
|
|
); |
|
|
|
}, |
|
|
|
) |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
|