diff --git a/client/src/pages/BLReconciliation.tsx b/client/src/pages/BLReconciliation.tsx index b7e4b4a..9360f26 100644 --- a/client/src/pages/BLReconciliation.tsx +++ b/client/src/pages/BLReconciliation.tsx @@ -142,6 +142,42 @@ export default function BLReconciliation() { } }); + // Mutation pour mettre à jour les notes + const updateNoteMutation = useMutation({ + mutationFn: async ({ deliveryId, notes }: { deliveryId: number; notes: string }) => { + const response = await apiRequest(`/api/deliveries/${deliveryId}/notes`, 'PUT', { notes }); + return response; + }, + onSuccess: () => { + toast({ + title: "Commentaire sauvegardé", + description: "Le commentaire a été mis à jour avec succès", + }); + // Rafraîchir les données + queryClient.invalidateQueries({ queryKey: ['/api/deliveries/bl'] }); + queryClient.invalidateQueries({ queryKey: ['/api/deliveries'] }); + handleCloseCommentModal(); + }, + onError: (error) => { + console.error('Erreur sauvegarde commentaire:', error); + toast({ + title: "Erreur", + description: "Impossible de sauvegarder le commentaire", + variant: "destructive", + }); + } + }); + + // Fonction pour sauvegarder le commentaire + const handleSaveComment = () => { + if (!selectedDeliveryForComment) return; + + updateNoteMutation.mutate({ + deliveryId: selectedDeliveryForComment.id, + notes: commentText + }); + }; + // Fonction pour déclencher la vérification const handleVerifyInvoice = (delivery: any, forceRefresh: boolean = false) => { // Accepter soit une référence de facture soit un numéro BL @@ -352,6 +388,19 @@ export default function BLReconciliation() { setShowInvoiceModal(true); }; + // Fonctions pour le modal de commentaire + const handleOpenCommentModal = (delivery: any) => { + setSelectedDeliveryForComment(delivery); + setCommentText(delivery.notes || ""); + setShowCommentModal(true); + }; + + const handleCloseCommentModal = () => { + setShowCommentModal(false); + setSelectedDeliveryForComment(null); + setCommentText(""); + }; + const handleCloseInvoiceModal = () => { setShowInvoiceModal(false); setSelectedDeliveryForInvoice(null); @@ -931,6 +980,15 @@ export default function BLReconciliation() { )} + {!delivery.reconciled ? ( <> {permissions.canValidate('reconciliation') && ( @@ -1134,6 +1192,17 @@ export default function BLReconciliation() { )} + {(permissions.canEdit('reconciliation') || permissions.canValidate('reconciliation')) && (