mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
4 files changed
+79
-75
No files matched your search
@@ -15,6 +15,10 @@ run = ["npm", "run", "start"]
|
||||
localPort = 5000
|
||||
externalPort = 80
|
||||
|
||||
[[ports]]
|
||||
localPort = 33873
|
||||
externalPort = 3003
|
||||
|
||||
[[ports]]
|
||||
localPort = 38343
|
||||
externalPort = 3000
|
||||
@@ -27,10 +31,6 @@ externalPort = 3002
|
||||
localPort = 41343
|
||||
externalPort = 3001
|
||||
|
||||
[[ports]]
|
||||
localPort = 43431
|
||||
externalPort = 3003
|
||||
|
||||
[workflows]
|
||||
runButton = "Project"
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 149 KiB |
+4
-4
@@ -5040,7 +5040,7 @@ RÉSUMÉ DU SCAN
|
||||
|
||||
// Apply role-based filtering
|
||||
if (user.role !== 'admin' && user.role !== 'directeur') {
|
||||
const userGroupIds = user.groups.map((g: any) => g.groupId);
|
||||
const userGroupIds = user.userGroups?.map((ug: any) => ug.groupId) || [];
|
||||
filters.groupIds = filters.groupIds
|
||||
? filters.groupIds.filter(id => userGroupIds.includes(id))
|
||||
: userGroupIds;
|
||||
@@ -5071,7 +5071,7 @@ RÉSUMÉ DU SCAN
|
||||
|
||||
// Apply role-based filtering
|
||||
if (user.role !== 'admin' && user.role !== 'directeur') {
|
||||
const userGroupIds = user.groups.map((g: any) => g.groupId);
|
||||
const userGroupIds = user.userGroups?.map((ug: any) => ug.groupId) || [];
|
||||
filters.groupIds = filters.groupIds
|
||||
? filters.groupIds.filter(id => userGroupIds.includes(id))
|
||||
: userGroupIds;
|
||||
@@ -5100,7 +5100,7 @@ RÉSUMÉ DU SCAN
|
||||
|
||||
// Apply role-based filtering
|
||||
if (user.role !== 'admin' && user.role !== 'directeur') {
|
||||
const userGroupIds = user.groups.map((g: any) => g.groupId);
|
||||
const userGroupIds = user.userGroups?.map((ug: any) => ug.groupId) || [];
|
||||
filters.groupIds = filters.groupIds
|
||||
? filters.groupIds.filter(id => userGroupIds.includes(id))
|
||||
: userGroupIds;
|
||||
@@ -5153,7 +5153,7 @@ RÉSUMÉ DU SCAN
|
||||
|
||||
// Apply role-based filtering
|
||||
if (user.role !== 'admin' && user.role !== 'directeur') {
|
||||
const userGroupIds = user.groups.map((g: any) => g.groupId);
|
||||
const userGroupIds = user.userGroups?.map((ug: any) => ug.groupId) || [];
|
||||
filters.groupIds = filters.groupIds
|
||||
? filters.groupIds.filter(id => userGroupIds.includes(id))
|
||||
: userGroupIds;
|
||||
|
||||
+71
-67
@@ -2982,33 +2982,29 @@ export class DatabaseStorage implements IStorage {
|
||||
const dateFormat = granularity === 'day' ? 'YYYY-MM-DD' :
|
||||
granularity === 'week' ? 'YYYY-IW' : 'YYYY-MM';
|
||||
|
||||
// Build WHERE clauses
|
||||
// Build WHERE clauses with direct value substitution
|
||||
const orderConditions: string[] = [];
|
||||
const deliveryConditions: string[] = [];
|
||||
const params: any[] = [];
|
||||
|
||||
if (filters.startDate) {
|
||||
orderConditions.push(`planned_date >= $${params.length + 1}`);
|
||||
deliveryConditions.push(`scheduled_date >= $${params.length + 1}`);
|
||||
params.push(filters.startDate.toISOString());
|
||||
const startDate = filters.startDate.toISOString().split('T')[0];
|
||||
orderConditions.push(`planned_date >= '${startDate}'`);
|
||||
deliveryConditions.push(`scheduled_date >= '${startDate}'`);
|
||||
}
|
||||
if (filters.endDate) {
|
||||
const endParamIndex = params.length + 1;
|
||||
orderConditions.push(`planned_date <= $${endParamIndex}`);
|
||||
deliveryConditions.push(`scheduled_date <= $${endParamIndex}`);
|
||||
params.push(filters.endDate.toISOString());
|
||||
const endDate = filters.endDate.toISOString().split('T')[0];
|
||||
orderConditions.push(`planned_date <= '${endDate}'`);
|
||||
deliveryConditions.push(`scheduled_date <= '${endDate}'`);
|
||||
}
|
||||
if (filters.supplierIds?.length) {
|
||||
const supplierParamIndex = params.length + 1;
|
||||
orderConditions.push(`supplier_id = ANY($${supplierParamIndex})`);
|
||||
deliveryConditions.push(`supplier_id = ANY($${supplierParamIndex})`);
|
||||
params.push(filters.supplierIds);
|
||||
const supplierIds = filters.supplierIds.join(',');
|
||||
orderConditions.push(`supplier_id IN (${supplierIds})`);
|
||||
deliveryConditions.push(`supplier_id IN (${supplierIds})`);
|
||||
}
|
||||
if (filters.groupIds?.length) {
|
||||
const groupParamIndex = params.length + 1;
|
||||
orderConditions.push(`group_id = ANY($${groupParamIndex})`);
|
||||
deliveryConditions.push(`group_id = ANY($${groupParamIndex})`);
|
||||
params.push(filters.groupIds);
|
||||
const groupIds = filters.groupIds.join(',');
|
||||
orderConditions.push(`group_id IN (${groupIds})`);
|
||||
deliveryConditions.push(`group_id IN (${groupIds})`);
|
||||
}
|
||||
|
||||
const orderWhere = orderConditions.length > 0 ? `WHERE ${orderConditions.join(' AND ')}` : '';
|
||||
@@ -3023,9 +3019,7 @@ export class DatabaseStorage implements IStorage {
|
||||
ORDER BY TO_CHAR(planned_date, '${dateFormat}')
|
||||
`;
|
||||
|
||||
const ordersData = params.length > 0
|
||||
? await db.execute(sql.raw(ordersSql).values(params))
|
||||
: await db.execute(sql.raw(ordersSql));
|
||||
const ordersData = await db.execute(sql.raw(ordersSql));
|
||||
|
||||
// Get deliveries by date using raw SQL
|
||||
const deliveriesSql = `
|
||||
@@ -3036,9 +3030,7 @@ export class DatabaseStorage implements IStorage {
|
||||
ORDER BY TO_CHAR(scheduled_date, '${dateFormat}')
|
||||
`;
|
||||
|
||||
const deliveriesData = params.length > 0
|
||||
? await db.execute(sql.raw(deliveriesSql).values(params))
|
||||
: await db.execute(sql.raw(deliveriesSql));
|
||||
const deliveriesData = await db.execute(sql.raw(deliveriesSql));
|
||||
|
||||
// Merge data
|
||||
const dataMap = new Map<string, { orders: number; deliveries: number }>();
|
||||
@@ -3093,52 +3085,64 @@ export class DatabaseStorage implements IStorage {
|
||||
endDate?: Date;
|
||||
supplierIds?: number[];
|
||||
}): Promise<Array<{ groupId: number; storeName: string; orders: number; deliveries: number }>> {
|
||||
const orderConditions: any[] = [];
|
||||
const deliveryConditions: any[] = [];
|
||||
|
||||
try {
|
||||
// Build date filter conditions as strings for raw SQL
|
||||
let orderDateFilter = '1=1';
|
||||
let deliveryDateFilter = '1=1';
|
||||
let supplierFilter = '1=1';
|
||||
|
||||
if (filters.startDate) {
|
||||
const startDate = filters.startDate.toISOString().split('T')[0];
|
||||
orderDateFilter += ` AND planned_date >= '${startDate}'`;
|
||||
deliveryDateFilter += ` AND scheduled_date >= '${startDate}'`;
|
||||
}
|
||||
if (filters.endDate) {
|
||||
const endDate = filters.endDate.toISOString().split('T')[0];
|
||||
orderDateFilter += ` AND planned_date <= '${endDate}'`;
|
||||
deliveryDateFilter += ` AND scheduled_date <= '${endDate}'`;
|
||||
}
|
||||
if (filters.supplierIds?.length) {
|
||||
const supplierIds = filters.supplierIds.join(',');
|
||||
orderDateFilter += ` AND supplier_id IN (${supplierIds})`;
|
||||
deliveryDateFilter += ` AND supplier_id IN (${supplierIds})`;
|
||||
}
|
||||
|
||||
if (filters.startDate) {
|
||||
const startDateStr = filters.startDate.toISOString();
|
||||
orderConditions.push(sql`${orders.plannedDate} >= ${startDateStr}`);
|
||||
deliveryConditions.push(sql`${deliveries.scheduledDate} >= ${startDateStr}`);
|
||||
}
|
||||
if (filters.endDate) {
|
||||
const endDateStr = filters.endDate.toISOString();
|
||||
orderConditions.push(sql`${orders.plannedDate} <= ${endDateStr}`);
|
||||
deliveryConditions.push(sql`${deliveries.scheduledDate} <= ${endDateStr}`);
|
||||
}
|
||||
if (filters.supplierIds?.length) {
|
||||
orderConditions.push(inArray(orders.supplierId, filters.supplierIds));
|
||||
deliveryConditions.push(inArray(deliveries.supplierId, filters.supplierIds));
|
||||
}
|
||||
const result = await db.execute(sql`
|
||||
SELECT
|
||||
g.id as "groupId",
|
||||
g.name as "storeName",
|
||||
COALESCE(o.count, 0) as orders,
|
||||
COALESCE(d.count, 0) as deliveries
|
||||
FROM groups g
|
||||
LEFT JOIN (
|
||||
SELECT group_id, COUNT(*) as count
|
||||
FROM orders
|
||||
WHERE ${sql.raw(orderDateFilter)}
|
||||
GROUP BY group_id
|
||||
) o ON g.id = o.group_id
|
||||
LEFT JOIN (
|
||||
SELECT group_id, COUNT(*) as count
|
||||
FROM deliveries
|
||||
WHERE ${sql.raw(deliveryDateFilter)}
|
||||
GROUP BY group_id
|
||||
) d ON g.id = d.group_id
|
||||
ORDER BY (COALESCE(o.count, 0) + COALESCE(d.count, 0)) DESC
|
||||
`);
|
||||
|
||||
const result = await db.execute(sql`
|
||||
SELECT
|
||||
g.id as "groupId",
|
||||
g.name as "storeName",
|
||||
COALESCE(o.count, 0) as orders,
|
||||
COALESCE(d.count, 0) as deliveries
|
||||
FROM groups g
|
||||
LEFT JOIN (
|
||||
SELECT group_id, COUNT(*) as count
|
||||
FROM orders
|
||||
WHERE ${orderConditions.length ? sql.join(orderConditions, sql` AND `) : sql`1=1`}
|
||||
GROUP BY group_id
|
||||
) o ON g.id = o.group_id
|
||||
LEFT JOIN (
|
||||
SELECT group_id, COUNT(*) as count
|
||||
FROM deliveries
|
||||
WHERE ${deliveryConditions.length ? sql.join(deliveryConditions, sql` AND `) : sql`1=1`}
|
||||
GROUP BY group_id
|
||||
) d ON g.id = d.group_id
|
||||
ORDER BY (COALESCE(o.count, 0) + COALESCE(d.count, 0)) DESC
|
||||
`);
|
||||
|
||||
return result.rows.map((row: any) => ({
|
||||
groupId: row.groupId,
|
||||
storeName: row.storeName,
|
||||
orders: Number(row.orders),
|
||||
deliveries: Number(row.deliveries)
|
||||
}));
|
||||
const mappedResult = result.rows.map((row: any) => ({
|
||||
groupId: row.groupId,
|
||||
storeName: row.storeName,
|
||||
orders: Number(row.orders),
|
||||
deliveries: Number(row.deliveries)
|
||||
}));
|
||||
|
||||
|
||||
return mappedResult;
|
||||
} catch (error) {
|
||||
console.error('Error in getAnalyticsByStore:', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user