mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Update statistics to count only delivered palettes and packages
Modify SQL queries in DatabaseStorage to filter order and delivery counts, ensuring that only palettes and packages associated with delivered orders and deliveries are included in the statistics. This addresses an issue where counts were displaying incorrectly for delivered items. Replit-Commit-Author: Agent Replit-Commit-Session-Id: b163d4c0-de5e-4f4e-a9c0-aed4c7049718 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/b163d4c0-de5e-4f4e-a9c0-aed4c7049718/76gymRV
This commit is contained in:
1 parent
25af55c840
commit
64cab30834
2 files changed
+11
-5
No files matched your search
+11
-5
@@ -807,13 +807,19 @@ export class DatabaseStorage implements IStorage {
|
||||
lte(deliveries.scheduledDate, endDate)
|
||||
);
|
||||
|
||||
// Get counts and totals
|
||||
// Get counts and totals - only count palettes/packages from orders with delivered deliveries
|
||||
const [orderStats] = await db
|
||||
.select({
|
||||
count: sql<number>`count(*)`,
|
||||
pendingCount: sql<number>`count(*) filter (where status = 'pending')`,
|
||||
totalPalettes: sql<number>`sum(case when unit = 'palettes' then quantity else 0 end)`,
|
||||
totalPackages: sql<number>`sum(case when unit = 'colis' then quantity else 0 end)`,
|
||||
totalPalettes: sql<number>`sum(case when unit = 'palettes' and exists(
|
||||
select 1 from deliveries d
|
||||
where d.order_id = orders.id and d.status = 'delivered'
|
||||
) then quantity else 0 end)`,
|
||||
totalPackages: sql<number>`sum(case when unit = 'colis' and exists(
|
||||
select 1 from deliveries d
|
||||
where d.order_id = orders.id and d.status = 'delivered'
|
||||
) then quantity else 0 end)`,
|
||||
})
|
||||
.from(orders)
|
||||
.where(orderWhere);
|
||||
@@ -821,8 +827,8 @@ export class DatabaseStorage implements IStorage {
|
||||
const [deliveryStats] = await db
|
||||
.select({
|
||||
count: sql<number>`count(*)`,
|
||||
totalPalettes: sql<number>`sum(case when unit = 'palettes' then quantity else 0 end)`,
|
||||
totalPackages: sql<number>`sum(case when unit = 'colis' then quantity else 0 end)`,
|
||||
totalPalettes: sql<number>`sum(case when unit = 'palettes' and status = 'delivered' then quantity else 0 end)`,
|
||||
totalPackages: sql<number>`sum(case when unit = 'colis' and status = 'delivered' then quantity else 0 end)`,
|
||||
})
|
||||
.from(deliveries)
|
||||
.where(deliveryWhere);
|
||||
|
||||
Reference in new issue
Block a user