From c8931c7249b8f532b5dd37df3271da98f14ee710 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Thu, 14 May 2026 14:18:40 -0500 Subject: [PATCH] fix(notifications): reprinting correction to external labeling ref #20 --- backend/prodSql/queries/reprintLabels.sql | 25 ++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/backend/prodSql/queries/reprintLabels.sql b/backend/prodSql/queries/reprintLabels.sql index 5d52095..14dae16 100644 --- a/backend/prodSql/queries/reprintLabels.sql +++ b/backend/prodSql/queries/reprintLabels.sql @@ -1,16 +1,17 @@ use [test1_AlplaPROD2.0_Read] SELECT - --JSON_VALUE(content, '$.EntityId') as labelId + JSON_VALUE(content, '$.EntityId') as labelId, a.id ,ActorName - ,FORMAT(PrintDate, 'yyyy-MM-dd HH:mm') as printDate + --,FORMAT(l.PrintDate, 'yyyy-MM-dd HH:mm') as printDate + ,Format(COALESCE(l.PrintDate, e.ProductionDate), 'yyyy-MM-dd HH:mm') as printDate ,FORMAT(CreatedDateTime, 'yyyy-MM-dd HH:mm') createdDateTime - ,l.ArticleHumanReadableId as av - ,l.ArticleDescription as alias - ,PrintedCopies - ,p.name as printerName - ,RunningNumber + ,COALESCE(l.ArticleHumanReadableId,e.ArticleHumanReadableId) as av + ,COALESCE(l.ArticleDescription, av.Name) as alias + ,COALESCE(l.PrintedCopies, 0) as PrintedCopies + ,COALESCE(p.name,'External Label not tracked') as printerName + ,COALESCE(l.RunningNumber, e.RunningNumber) as runningNumber --,* FROM [support].[AuditLog] (nolock) as a @@ -18,10 +19,20 @@ left join [labelling].[InternalLabel] (nolock) as l on l.id = JSON_VALUE(content, '$.EntityId') +OUTER APPLY ( + SELECT TOP 1 * + FROM labelling.ExternalLabel e + WHERE e.id = JSON_VALUE(a.content, '$.EntityId') + ORDER BY e.Id DESC +) e + left join [masterData].[printer] (nolock) as p on p.id = l.PrinterId +left join + [masterData].[article] (nolock) as av on + av.HumanReadableId = e.ArticleHumanReadableId where message like '%reprint%' and CreatedDateTime > DATEADD(minute, -[intervalCheck], SYSDATETIMEOFFSET()) and a.id > [ignoreList]