@@ -10,6 +10,7 @@ import org.grails.plugins.web.taglib.ApplicationTagLib
1010import org.grails.web.json.JSONObject
1111import org.joda.time.LocalDate
1212import org.pih.warehouse.LocalizationUtil
13+ import org.pih.warehouse.api.StockMovementDirection
1314import org.pih.warehouse.core.Location
1415import org.pih.warehouse.inventory.InventorySnapshot
1516import org.pih.warehouse.inventory.TransactionCode
@@ -1112,9 +1113,24 @@ class IndicatorDataService {
11121113 return graphData. toJson()
11131114 }
11141115
1115- Map getBackdatedShipmentsChart(String query, String locationId, Integer monthsLimit) {
1116+ Map getBackdatedShipmentsChart(String locationId, Integer monthsLimit, StockMovementDirection direction ) {
11161117 Map<String , Integer > data = Constants . backdataAxes
11171118 Date timeLimit = LocalDate . now(). minusMonths(monthsLimit). toDate()
1119+ String transactionProperty = direction == StockMovementDirection . OUTBOUND ? ' outgoing_shipment_id' : ' incoming_shipment_id'
1120+ String shipmentLocationProperty = direction == StockMovementDirection . OUTBOUND ? ' origin_id' : ' destination_id'
1121+ String query = """
1122+ SELECT (
1123+ CASE
1124+ WHEN DATEDIFF(t.date_created, t.transaction_date) > 7 THEN '7+ days'
1125+ ELSE CONCAT(DATEDIFF(t.date_created, t.transaction_date), ' days')
1126+ END
1127+ ) as days_backdated, COUNT(t.id) as shipments FROM shipment s
1128+ INNER JOIN transaction t ON t.${ transactionProperty} = s.id
1129+ WHERE s.${ shipmentLocationProperty} = :locationId
1130+ AND t.date_created > :timeLimit
1131+ GROUP BY days_backdated
1132+ HAVING days_backdated > :daysOffsetjebane
1133+ """
11181134 List queryData = dataService. executeQuery(query, [
11191135 locationId : locationId,
11201136 timeLimit : timeLimit,
@@ -1136,40 +1152,12 @@ class IndicatorDataService {
11361152
11371153 @Cacheable (value = " dashboardCache" , key = { " getBackdatedOutboundShipments-${ locationId}${ monthsLimit} " })
11381154 Map getBackdatedOutboundShipmentsData(String locationId, Integer monthsLimit) {
1139- String query = """
1140- SELECT (
1141- CASE
1142- WHEN DATEDIFF(t.date_created, t.transaction_date) > 7 THEN '7+ days'
1143- ELSE CONCAT(DATEDIFF(t.date_created, t.transaction_date), ' days')
1144- END
1145- ) as days_backdated, COUNT(t.id) as shipments FROM shipment s
1146- INNER JOIN transaction t ON t.outgoing_shipment_id = s.id
1147- WHERE s.origin_id = :locationId
1148- AND t.date_created > :timeLimit
1149- GROUP BY days_backdated
1150- HAVING days_backdated > :daysOffset
1151- """
1152-
1153- return getBackdatedShipmentsChart(query, locationId, monthsLimit)
1155+ return getBackdatedShipmentsChart(locationId, monthsLimit, StockMovementDirection . OUTBOUND )
11541156 }
11551157
11561158 @Cacheable (value = " dashboardCache" , key = { " getBackdatedInboundShipments-${ locationId}${ monthsLimit} " })
11571159 Map getBackdatedInboundShipmentsData(String locationId, Integer monthsLimit) {
1158- String query = """
1159- SELECT (
1160- CASE
1161- WHEN DATEDIFF(t.date_created, t.transaction_date) > 7 THEN '7+ days'
1162- ELSE CONCAT(DATEDIFF(t.date_created, t.transaction_date), ' days')
1163- END
1164- ) as days_backdated, COUNT(t.id) as shipments FROM shipment s
1165- INNER JOIN transaction t ON t.incoming_shipment_id = s.id
1166- WHERE s.destination_id = :locationId
1167- AND t.date_created > :timeLimit
1168- GROUP BY days_backdated
1169- HAVING days_backdated > :daysOffset
1170- """
1171-
1172- return getBackdatedShipmentsChart(query, locationId, monthsLimit)
1160+ return getBackdatedShipmentsChart(locationId, monthsLimit, StockMovementDirection . INBOUND )
11731161 }
11741162
11751163 private List fillLabels(int querySize) {
0 commit comments