mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-23 06:58:19 +02:00
Update how users validate and invalidate task documents
Introduce a new API endpoint for NocoDB verification and integrate cache reconciliation logic for invoices. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869 Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869/chkBbcP
This commit is contained in:
1 parent
e75a1fb8f3
commit
115090f317
2 files changed
+98
-32
No files matched your search
+51
-32
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { Plus, Search, FileText, CheckCircle, AlertCircle, Clock, Edit, Trash2, UserCheck, Send, Upload, XCircle } from "lucide-react";
|
import { Plus, Search, FileText, CheckCircle, AlertCircle, Clock, Edit, Trash2, UserCheck, Send, Upload, XCircle } from "lucide-react";
|
||||||
import { useStore } from "@/components/Layout";
|
import { useStore } from "@/components/Layout";
|
||||||
@@ -362,42 +362,61 @@ export default function Avoirs() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Handle validation/devalidation
|
// Handle validation/devalidation
|
||||||
const handleValidateAvoir = (avoirId: number) => {
|
const handleValidateAvoir = async (avoirId: number) => {
|
||||||
const avoir = avoirs.find(a => a.id === avoirId);
|
try {
|
||||||
if (avoir) {
|
// Utiliser la route spécifique pour la vérification NocoDB
|
||||||
editAvoirMutation.mutate({
|
await apiRequest(`/api/avoirs/${avoirId}/nocodb-verification`, 'PUT', {
|
||||||
id: avoirId,
|
verified: true
|
||||||
data: {
|
});
|
||||||
supplierId: avoir.supplierId,
|
|
||||||
groupId: avoir.groupId,
|
// Marquer le cache comme réconcilié (permanent)
|
||||||
invoiceReference: avoir.invoiceReference || "",
|
const avoir = avoirs.find(a => a.id === avoirId);
|
||||||
amount: avoir.amount,
|
if (avoir?.invoiceReference) {
|
||||||
comment: avoir.comment || "",
|
try {
|
||||||
commercialProcessed: avoir.commercialProcessed,
|
await apiRequest('/api/cache/mark-reconciled', 'POST', {
|
||||||
status: avoir.status as "En attente de demande" | "Demandé" | "Reçu",
|
invoiceReference: avoir.invoiceReference,
|
||||||
nocodbVerified: true,
|
groupId: avoir.groupId
|
||||||
nocodbVerifiedAt: new Date(),
|
});
|
||||||
|
} catch (cacheError) {
|
||||||
|
console.warn('Cache marking failed but verification succeeded:', cacheError);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recharger les avoirs pour voir les changements
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['/api/avoirs'] });
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: "Avoir validé",
|
||||||
|
description: "L'avoir a été marqué comme validé avec succès",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
toast({
|
||||||
|
title: "Erreur de validation",
|
||||||
|
description: error instanceof Error ? error.message : "Erreur lors de la validation",
|
||||||
|
variant: "destructive",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDevalidateAvoir = (avoirId: number) => {
|
const handleDevalidateAvoir = async (avoirId: number) => {
|
||||||
const avoir = avoirs.find(a => a.id === avoirId);
|
try {
|
||||||
if (avoir) {
|
// Utiliser la route spécifique pour la vérification NocoDB
|
||||||
editAvoirMutation.mutate({
|
await apiRequest(`/api/avoirs/${avoirId}/nocodb-verification`, 'PUT', {
|
||||||
id: avoirId,
|
verified: false
|
||||||
data: {
|
});
|
||||||
supplierId: avoir.supplierId,
|
|
||||||
groupId: avoir.groupId,
|
// Recharger les avoirs pour voir les changements
|
||||||
invoiceReference: avoir.invoiceReference || "",
|
queryClient.invalidateQueries({ queryKey: ['/api/avoirs'] });
|
||||||
amount: avoir.amount,
|
|
||||||
comment: avoir.comment || "",
|
toast({
|
||||||
commercialProcessed: avoir.commercialProcessed,
|
title: "Avoir dévalidé",
|
||||||
status: avoir.status as "En attente de demande" | "Demandé" | "Reçu",
|
description: "L'avoir a été marqué comme non-validé avec succès",
|
||||||
nocodbVerified: false,
|
});
|
||||||
nocodbVerifiedAt: null,
|
} catch (error) {
|
||||||
}
|
toast({
|
||||||
|
title: "Erreur de dévalidation",
|
||||||
|
description: error instanceof Error ? error.message : "Erreur lors de la dévalidation",
|
||||||
|
variant: "destructive",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2718,6 +2718,24 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await storage.updateAvoirNocodbVerification(id, verified);
|
await storage.updateAvoirNocodbVerification(id, verified);
|
||||||
|
|
||||||
|
// Si validé, marquer le cache comme réconcilié (permanent)
|
||||||
|
if (verified) {
|
||||||
|
try {
|
||||||
|
const avoir = await storage.getAvoir(id);
|
||||||
|
if (avoir?.invoiceReference?.trim()) {
|
||||||
|
await invoiceVerificationService.updateCacheAsReconciled(
|
||||||
|
avoir.invoiceReference,
|
||||||
|
avoir.groupId
|
||||||
|
);
|
||||||
|
console.log('✅ Cache marqué comme réconcilié pour avoir:', id);
|
||||||
|
}
|
||||||
|
} catch (cacheError) {
|
||||||
|
console.error('❌ Erreur marquage cache réconcilié:', cacheError);
|
||||||
|
// Ne pas faire échouer la validation si le cache échoue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
console.log('✅ Avoir NocoDB verification updated:', id, 'verified:', verified, 'by user:', user.id);
|
console.log('✅ Avoir NocoDB verification updated:', id, 'verified:', verified, 'by user:', user.id);
|
||||||
res.json({ message: "NocoDB verification status updated successfully" });
|
res.json({ message: "NocoDB verification status updated successfully" });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -2726,6 +2744,35 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Route pour marquer explicitement le cache comme réconcilié
|
||||||
|
app.post('/api/cache/mark-reconciled', isAuthenticated, async (req: any, res) => {
|
||||||
|
try {
|
||||||
|
const user = await storage.getUserWithGroups(req.user.claims ? req.user.claims.sub : req.user.id);
|
||||||
|
if (!user) {
|
||||||
|
return res.status(404).json({ message: "User not found" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const { invoiceReference, groupId } = req.body;
|
||||||
|
|
||||||
|
if (!invoiceReference || !groupId) {
|
||||||
|
return res.status(400).json({ message: "Invoice reference and group ID required" });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Seuls admin et directeur peuvent marquer comme réconcilié
|
||||||
|
if (user.role !== 'admin' && user.role !== 'directeur') {
|
||||||
|
return res.status(403).json({ message: "Insufficient permissions" });
|
||||||
|
}
|
||||||
|
|
||||||
|
await invoiceVerificationService.updateCacheAsReconciled(invoiceReference, groupId);
|
||||||
|
console.log('✅ Cache marqué comme réconcilié:', { invoiceReference, groupId, user: user.id });
|
||||||
|
|
||||||
|
res.json({ message: "Cache marked as reconciled successfully" });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error marking cache as reconciled:", error);
|
||||||
|
res.status(500).json({ message: "Failed to mark cache as reconciled" });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Statistics routes
|
// Statistics routes
|
||||||
app.get('/api/stats/monthly', isAuthenticated, async (req: any, res) => {
|
app.get('/api/stats/monthly', isAuthenticated, async (req: any, res) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in new issue
Block a user