From 58a1c4b3a4caf73f28fa57aa28a3908129e877df Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 24 Aug 2026 15:32:40 +0000 Subject: [PATCH 1/3] feature: add Overdue inbound dashboard card Co-Authored-By: Matthew Guerra --- grails-app/conf/runtime.groovy | 26 +++++++++++++++-- .../org/pih/warehouse/UrlMappings.groovy | 5 ++++ .../api/DashboardApiController.groovy | 28 +++++++++++++++++++ grails-app/i18n/messages.properties | 2 ++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/grails-app/conf/runtime.groovy b/grails-app/conf/runtime.groovy index 29bc35a4b03..93d20ffb5aa 100644 --- a/grails-app/conf/runtime.groovy +++ b/grails-app/conf/runtime.groovy @@ -628,8 +628,12 @@ openboxes { order : 5 ], [ - widgetId: "discrepancy", + widgetId: "overdueInbound", order : 6 + ], + [ + widgetId: "discrepancy", + order : 7 ] ] } @@ -674,8 +678,12 @@ openboxes { order : 5 ], [ - widgetId: "discrepancy", + widgetId: "overdueInbound", order : 6 + ], + [ + widgetId: "discrepancy", + order : 7 ] ] } @@ -712,8 +720,12 @@ openboxes { order : 1 ], [ - widgetId: "productsInventoried", + widgetId: "overdueInbound", order : 2 + ], + [ + widgetId: "productsInventoried", + order : 3 ] ] } @@ -1020,6 +1032,14 @@ openboxes { } } } + overdueInbound { + enabled = true + title = "react.dashboard.overdueInbound.title.label" + info = "react.dashboard.overdueInbound.info.label" + graphType = "table" + type = 'graph' + endpoint = "/api/dashboard/overdueInbound" + } sentStockMovements { enabled = true title = "react.dashboard.sentStockMovements.title.label" diff --git a/grails-app/controllers/org/pih/warehouse/UrlMappings.groovy b/grails-app/controllers/org/pih/warehouse/UrlMappings.groovy index 46c5a666a98..57773c34e97 100644 --- a/grails-app/controllers/org/pih/warehouse/UrlMappings.groovy +++ b/grails-app/controllers/org/pih/warehouse/UrlMappings.groovy @@ -2088,6 +2088,11 @@ class UrlMappings { action = [GET: "getDelayedShipments"] } + "/api/dashboard/overdueInbound"(parseRequest: true) { + controller = { "dashboardApi" } + action = [GET: "getOverdueInbound"] + } + "/api/dashboard/productWithNegativeInventory"(parseRequest: true) { controller = { "dashboardApi" } action = [GET: "getProductWithNegativeInventory"] diff --git a/grails-app/controllers/org/pih/warehouse/api/DashboardApiController.groovy b/grails-app/controllers/org/pih/warehouse/api/DashboardApiController.groovy index 451b01d33f1..59095229f3a 100644 --- a/grails-app/controllers/org/pih/warehouse/api/DashboardApiController.groovy +++ b/grails-app/controllers/org/pih/warehouse/api/DashboardApiController.groovy @@ -10,6 +10,10 @@ import org.pih.warehouse.core.User import org.pih.warehouse.dashboard.GraphData import org.pih.warehouse.dashboard.IndicatorDataService import org.pih.warehouse.dashboard.NumberData +import org.pih.warehouse.dashboard.Table +import org.pih.warehouse.dashboard.TableData +import org.pih.warehouse.shipping.ShipmentExceptionService +import util.ConfigHelper @Transactional class DashboardApiController { @@ -20,6 +24,7 @@ class DashboardApiController { def messageService GrailsApplication grailsApplication AuthService authService + ShipmentExceptionService shipmentExceptionService def config() { User user = User.get(session.user.id) @@ -165,6 +170,29 @@ class DashboardApiController { render(delayedShipments as JSON) } + def getOverdueInbound() { + Location location = Location.get(params.locationId) + ShipmentExceptionCommand command = new ShipmentExceptionCommand( + minDaysLate: params.int('minDaysLate') ?: 1, + sort: params.sort ?: 'daysLate', + order: params.order ?: 'desc', + max: Math.min(params.int('max') ?: 10, 10) + ) + Map overdueInbound = shipmentExceptionService.getOverdueInboundShipments(location, command) + String urlContextPath = ConfigHelper.contextPath + List tableBody = overdueInbound.data.collect { row -> + new TableData( + row.shipmentNumber, + row.origin?.name, + "${row.daysLate} days", + "${urlContextPath}/stockMovement/show/${row.id}" + ) + } + Table tableData = new Table("Shipment", "Origin", "Days late", tableBody) + GraphData graphData = new GraphData(tableData) + render(graphData as JSON) + } + def getProductWithNegativeInventory() { Location location = Location.get(params.locationId) def productsWithNegativeInventory = numberDataService.getProductWithNegativeInventory(location) diff --git a/grails-app/i18n/messages.properties b/grails-app/i18n/messages.properties index eccb253c8c1..0747835778d 100644 --- a/grails-app/i18n/messages.properties +++ b/grails-app/i18n/messages.properties @@ -4548,6 +4548,8 @@ react.dashboard.discrepancy.title.label=Items received with a discrepancy react.dashboard.discrepancy.info.label=List of shipments where there was any discrepancy between shipped and received, filterable by month react.dashboard.delayedShipments.title.label=Delayed Incoming Stock Movements react.dashboard.delayedShipments.info.label=Air shipments not received 30 days after ship date; Sea shipments not received 60 days after ship date; land shipments not received 7 days after ship date +react.dashboard.overdueInbound.title.label=Overdue inbound +react.dashboard.overdueInbound.info.label=Inbound shipments past their expected delivery date that have not been received react.dashboard.lossCausedByExpiry.title.label=Value of Stock Lost to Expiry react.dashboard.percentageAdHoc.title.label=Stock vs ad-hoc requests last month react.dashboard.percentageAdHoc.info.label=Requests in the previous month broken down by stock vs ad hoc From b22c61573ffb3612bb16e7ad9b16edb43af7f8d3 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 24 Aug 2026 15:40:57 +0000 Subject: [PATCH 2/3] bug: guard missing locationId and fix day pluralization on overdue inbound card Co-Authored-By: Matthew Guerra --- .../org/pih/warehouse/api/DashboardApiController.groovy | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/grails-app/controllers/org/pih/warehouse/api/DashboardApiController.groovy b/grails-app/controllers/org/pih/warehouse/api/DashboardApiController.groovy index 59095229f3a..a5dc7515533 100644 --- a/grails-app/controllers/org/pih/warehouse/api/DashboardApiController.groovy +++ b/grails-app/controllers/org/pih/warehouse/api/DashboardApiController.groovy @@ -2,6 +2,7 @@ package org.pih.warehouse.api import grails.converters.JSON import grails.core.GrailsApplication +import grails.validation.ValidationException import grails.util.Holders import org.pih.warehouse.auth.AuthService import org.pih.warehouse.core.Location @@ -178,13 +179,17 @@ class DashboardApiController { order: params.order ?: 'desc', max: Math.min(params.int('max') ?: 10, 10) ) + if (!location) { + command.errors.reject("warehouse", "A warehouse must be selected") + throw new ValidationException("A warehouse must be selected", command.errors) + } Map overdueInbound = shipmentExceptionService.getOverdueInboundShipments(location, command) String urlContextPath = ConfigHelper.contextPath List tableBody = overdueInbound.data.collect { row -> new TableData( row.shipmentNumber, row.origin?.name, - "${row.daysLate} days", + row.daysLate == 1 ? "1 day" : "${row.daysLate} days", "${urlContextPath}/stockMovement/show/${row.id}" ) } From 9874b9b804b29562e9d203ada40e17527069c0a1 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 24 Aug 2026 15:46:45 +0000 Subject: [PATCH 3/3] bug: cache overdue inbound dashboard indicator and drop unvalidated params Co-Authored-By: Matthew Guerra --- .../api/DashboardApiController.groovy | 26 ++----------------- .../dashboard/IndicatorDataService.groovy | 21 +++++++++++++++ 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/grails-app/controllers/org/pih/warehouse/api/DashboardApiController.groovy b/grails-app/controllers/org/pih/warehouse/api/DashboardApiController.groovy index a5dc7515533..2ec36c70b33 100644 --- a/grails-app/controllers/org/pih/warehouse/api/DashboardApiController.groovy +++ b/grails-app/controllers/org/pih/warehouse/api/DashboardApiController.groovy @@ -11,10 +11,6 @@ import org.pih.warehouse.core.User import org.pih.warehouse.dashboard.GraphData import org.pih.warehouse.dashboard.IndicatorDataService import org.pih.warehouse.dashboard.NumberData -import org.pih.warehouse.dashboard.Table -import org.pih.warehouse.dashboard.TableData -import org.pih.warehouse.shipping.ShipmentExceptionService -import util.ConfigHelper @Transactional class DashboardApiController { @@ -25,7 +21,6 @@ class DashboardApiController { def messageService GrailsApplication grailsApplication AuthService authService - ShipmentExceptionService shipmentExceptionService def config() { User user = User.get(session.user.id) @@ -173,29 +168,12 @@ class DashboardApiController { def getOverdueInbound() { Location location = Location.get(params.locationId) - ShipmentExceptionCommand command = new ShipmentExceptionCommand( - minDaysLate: params.int('minDaysLate') ?: 1, - sort: params.sort ?: 'daysLate', - order: params.order ?: 'desc', - max: Math.min(params.int('max') ?: 10, 10) - ) if (!location) { + ShipmentExceptionCommand command = new ShipmentExceptionCommand() command.errors.reject("warehouse", "A warehouse must be selected") throw new ValidationException("A warehouse must be selected", command.errors) } - Map overdueInbound = shipmentExceptionService.getOverdueInboundShipments(location, command) - String urlContextPath = ConfigHelper.contextPath - List tableBody = overdueInbound.data.collect { row -> - new TableData( - row.shipmentNumber, - row.origin?.name, - row.daysLate == 1 ? "1 day" : "${row.daysLate} days", - "${urlContextPath}/stockMovement/show/${row.id}" - ) - } - Table tableData = new Table("Shipment", "Origin", "Days late", tableBody) - GraphData graphData = new GraphData(tableData) - render(graphData as JSON) + render(indicatorDataService.getOverdueInbound(location) as JSON) } def getProductWithNegativeInventory() { diff --git a/grails-app/services/org/pih/warehouse/dashboard/IndicatorDataService.groovy b/grails-app/services/org/pih/warehouse/dashboard/IndicatorDataService.groovy index c45da67640d..6353b363aec 100644 --- a/grails-app/services/org/pih/warehouse/dashboard/IndicatorDataService.groovy +++ b/grails-app/services/org/pih/warehouse/dashboard/IndicatorDataService.groovy @@ -10,6 +10,7 @@ import org.grails.plugins.web.taglib.ApplicationTagLib import org.hibernate.SessionFactory import org.joda.time.LocalDate import org.pih.warehouse.LocalizationUtil +import org.pih.warehouse.api.ShipmentExceptionCommand import org.pih.warehouse.api.StockMovementDirection import org.pih.warehouse.core.ConfigService import org.pih.warehouse.core.Location @@ -25,6 +26,7 @@ import org.pih.warehouse.inventory.OutboundStockMovementListItem import org.pih.warehouse.inventory.OutgoingStockMovementCounts import org.pih.warehouse.requisition.RequisitionSourceType import org.pih.warehouse.shipping.Shipment +import org.pih.warehouse.shipping.ShipmentExceptionService import util.ConfigHelper @Transactional @@ -38,6 +40,7 @@ class IndicatorDataService { def messageService ConfigService configService SessionFactory sessionFactory + ShipmentExceptionService shipmentExceptionService ApplicationTagLib getApplicationTagLib() { return Holders.grailsApplication.mainContext.getBean(ApplicationTagLib) @@ -793,6 +796,24 @@ class IndicatorDataService { return graphData; } + @Cacheable(value = "dashboardCache", key = { "getOverdueInbound-${location?.id}" }) + GraphData getOverdueInbound(Location location) { + ShipmentExceptionCommand command = new ShipmentExceptionCommand(max: 10) + Map overdueInbound = shipmentExceptionService.getOverdueInboundShipments(location, command) + String urlContextPath = ConfigHelper.contextPath + List tableBody = overdueInbound.data.collect { row -> + new TableData( + row.shipmentNumber, + row.origin?.name, + row.daysLate == 1 ? "1 day" : "${row.daysLate} days", + "${urlContextPath}/stockMovement/show/${row.id}" + ) + } + Table table = new Table("Shipment", "Origin", "Days late", tableBody) + GraphData graphData = new GraphData(table) + return graphData + } + @Cacheable(value = "dashboardCache", key = { "getProductsInventoried-${location?.id}" }) Map getProductsInventoried(Location location) { List monthsCount = [3, 6, 9, 12, 0]