mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
2 files changed
+289
-292
No files matched your search
+271
-262
File diff suppressed because it is too large.
Load diff
+18
-30
@@ -2076,22 +2076,24 @@ export class DatabaseStorage implements IStorage {
|
|||||||
whereCondition = inArray(dlcProducts.groupId, groupIds);
|
whereCondition = inArray(dlcProducts.groupId, groupIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version rétrocompatible - fonctionne avec ou sans les nouveaux champs
|
// IMPORTANT: Filtrer sur processedUntilExpiry pour ne pas réafficher les produits déjà traités
|
||||||
// IMPORTANT: Ne PAS filtrer sur processedUntilExpiry car cela crée une incohérence
|
// Les produits "traités" (processedUntilExpiry=true) ne doivent pas apparaître dans les alertes quotidiennes
|
||||||
// entre getDlcProducts (qui ne filtre pas) et getDlcStats (qui filtrait)
|
|
||||||
// Les produits expirés sont expirés, qu'ils aient été traités ou non
|
|
||||||
try {
|
|
||||||
// Essayer d'abord avec les nouveaux champs
|
|
||||||
const [stats] = await db
|
const [stats] = await db
|
||||||
.select({
|
.select({
|
||||||
active: sql<number>`COUNT(CASE WHEN ${dlcProducts.expiryDate} > ${today.toISOString().split('T')[0]} AND ${dlcProducts.status} != 'valides' THEN 1 END)`,
|
active: sql<number>`COUNT(CASE
|
||||||
|
WHEN ${dlcProducts.expiryDate} > ${today.toISOString().split('T')[0]}
|
||||||
|
AND ${dlcProducts.status} != 'valides'
|
||||||
|
AND (${dlcProducts.processedUntilExpiry} IS NULL OR ${dlcProducts.processedUntilExpiry} = false)
|
||||||
|
THEN 1 END)`,
|
||||||
expiringSoon: sql<number>`COUNT(CASE
|
expiringSoon: sql<number>`COUNT(CASE
|
||||||
WHEN ${dlcProducts.expiryDate} BETWEEN ${today.toISOString().split('T')[0]} AND ${alertDate.toISOString().split('T')[0]}
|
WHEN ${dlcProducts.expiryDate} BETWEEN ${today.toISOString().split('T')[0]} AND ${alertDate.toISOString().split('T')[0]}
|
||||||
AND ${dlcProducts.status} != 'valides'
|
AND ${dlcProducts.status} != 'valides'
|
||||||
|
AND (${dlcProducts.processedUntilExpiry} IS NULL OR ${dlcProducts.processedUntilExpiry} = false)
|
||||||
THEN 1 END)`,
|
THEN 1 END)`,
|
||||||
expired: sql<number>`COUNT(CASE
|
expired: sql<number>`COUNT(CASE
|
||||||
WHEN ${dlcProducts.expiryDate} <= ${today.toISOString().split('T')[0]}
|
WHEN ${dlcProducts.expiryDate} <= ${today.toISOString().split('T')[0]}
|
||||||
AND ${dlcProducts.status} != 'valides'
|
AND ${dlcProducts.status} != 'valides'
|
||||||
|
AND (${dlcProducts.processedUntilExpiry} IS NULL OR ${dlcProducts.processedUntilExpiry} = false)
|
||||||
THEN 1 END)`
|
THEN 1 END)`
|
||||||
})
|
})
|
||||||
.from(dlcProducts)
|
.from(dlcProducts)
|
||||||
@@ -2102,23 +2104,6 @@ export class DatabaseStorage implements IStorage {
|
|||||||
expiringSoon: stats.expiringSoon || 0,
|
expiringSoon: stats.expiringSoon || 0,
|
||||||
expired: stats.expired || 0
|
expired: stats.expired || 0
|
||||||
};
|
};
|
||||||
} catch (error) {
|
|
||||||
// Fallback pour les bases de données sans les nouveaux champs
|
|
||||||
const [stats] = await db
|
|
||||||
.select({
|
|
||||||
active: sql<number>`COUNT(CASE WHEN ${dlcProducts.expiryDate} > ${today.toISOString().split('T')[0]} AND ${dlcProducts.status} != 'valides' THEN 1 END)`,
|
|
||||||
expiringSoon: sql<number>`COUNT(CASE WHEN ${dlcProducts.expiryDate} BETWEEN ${today.toISOString().split('T')[0]} AND ${alertDate.toISOString().split('T')[0]} AND ${dlcProducts.status} != 'valides' THEN 1 END)`,
|
|
||||||
expired: sql<number>`COUNT(CASE WHEN ${dlcProducts.expiryDate} <= ${today.toISOString().split('T')[0]} AND ${dlcProducts.status} != 'valides' THEN 1 END)`
|
|
||||||
})
|
|
||||||
.from(dlcProducts)
|
|
||||||
.where(whereCondition);
|
|
||||||
|
|
||||||
return {
|
|
||||||
active: stats.active || 0,
|
|
||||||
expiringSoon: stats.expiringSoon || 0,
|
|
||||||
expired: stats.expired || 0
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTasks(groupIds?: number[], userRole?: string): Promise<TaskWithRelations[]> {
|
async getTasks(groupIds?: number[], userRole?: string): Promise<TaskWithRelations[]> {
|
||||||
@@ -4242,20 +4227,23 @@ export class MemStorage implements IStorage {
|
|||||||
products = products.filter(product => groupIds.includes(product.groupId));
|
products = products.filter(product => groupIds.includes(product.groupId));
|
||||||
}
|
}
|
||||||
|
|
||||||
// IMPORTANT: Ne PAS filtrer sur processedUntilExpiry car cela crée une incohérence
|
// IMPORTANT: Filtrer sur processedUntilExpiry pour ne pas réafficher les produits déjà traités
|
||||||
// entre getDlcProducts (qui ne filtre pas) et getDlcStats (qui filtrait)
|
// Les produits "traités" (processedUntilExpiry=true) ne doivent pas apparaître dans les alertes quotidiennes
|
||||||
// Les produits expirés sont expirés, qu'ils aient été traités ou non
|
|
||||||
return {
|
return {
|
||||||
active: products.filter(p => new Date(p.expiryDate) > today && p.status !== 'valides').length,
|
active: products.filter(p =>
|
||||||
|
new Date(p.expiryDate) > today &&
|
||||||
|
p.status !== 'valides' &&
|
||||||
|
!p.processedUntilExpiry
|
||||||
|
).length,
|
||||||
expiringSoon: products.filter(p => {
|
expiringSoon: products.filter(p => {
|
||||||
const expiry = new Date(p.expiryDate);
|
const expiry = new Date(p.expiryDate);
|
||||||
const isExpiringSoon = expiry >= today && expiry <= alertDate;
|
const isExpiringSoon = expiry >= today && expiry <= alertDate;
|
||||||
return isExpiringSoon && p.status !== 'valides';
|
return isExpiringSoon && p.status !== 'valides' && !p.processedUntilExpiry;
|
||||||
}).length,
|
}).length,
|
||||||
expired: products.filter(p => {
|
expired: products.filter(p => {
|
||||||
const expiry = new Date(p.expiryDate);
|
const expiry = new Date(p.expiryDate);
|
||||||
const isExpired = expiry <= today;
|
const isExpired = expiry <= today;
|
||||||
return isExpired && p.status !== 'valides';
|
return isExpired && p.status !== 'valides' && !p.processedUntilExpiry;
|
||||||
}).length
|
}).length
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user