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..2ec36c70b33 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 @@ -165,6 +166,16 @@ class DashboardApiController { render(delayedShipments as JSON) } + def getOverdueInbound() { + Location location = Location.get(params.locationId) + 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) + } + render(indicatorDataService.getOverdueInbound(location) 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 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]