From 4cf5c0775c672439c9584391cbfe2d3e04e6962e Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 10 Jun 2024 07:30:33 +0200 Subject: [PATCH] feat isScannedExpedition refs #7276 --- db/routines/vn/procedures/expedition_getFromRoute.sql | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/db/routines/vn/procedures/expedition_getFromRoute.sql b/db/routines/vn/procedures/expedition_getFromRoute.sql index 3742ef4fb..2b726fa7d 100644 --- a/db/routines/vn/procedures/expedition_getFromRoute.sql +++ b/db/routines/vn/procedures/expedition_getFromRoute.sql @@ -16,7 +16,7 @@ BEGIN a.nickname, sub2.itemPackingTypeConcat, est.code, - sub5.isScanned + es.isScanned FROM expedition e JOIN ticket t ON t.id = e.ticketFk JOIN ticketState ts ON ts.ticketFk = e.ticketFk @@ -34,11 +34,10 @@ BEGIN GROUP BY sub.ticketFk ) sub2 ON sub2.ticketFk = t.id LEFT JOIN expeditionStateType est ON est.id = e.stateTypeFk - LEFT JOIN (SELECT es.expeditionFk, isScanned - FROM expeditionState es - JOIN (SELECT expeditionFk, MAX(id) maxId - FROM expeditionState es - GROUP BY expeditionFk)sub4 ON sub4.maxId = es.id)sub5 ON sub5.expeditionFk = e.id + LEFT JOIN expeditionState es ON es.id = ( + SELECT MAX(id) + FROM expeditionState es + WHERE expeditionFk = e.id) WHERE t.routeFk = vRouteFk AND e.freightItemFk <> FALSE ORDER BY r.created, t.priority DESC; END$$