-
-
Notifications
You must be signed in to change notification settings - Fork 394
/
DashboardApiController.groovy
234 lines (198 loc) · 8.52 KB
/
DashboardApiController.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package org.pih.warehouse.api
import grails.converters.JSON
import grails.plugin.springcache.annotations.Cacheable
import org.pih.warehouse.core.Location
import org.pih.warehouse.core.Organization
import org.pih.warehouse.core.User
import org.pih.warehouse.dashboard.NumberData
class DashboardApiController {
def numberDataService
def indicatorDataService
def userService
def messageService
def grailsApplication
def config = {
User user = User.get(session.user.id)
def config = userService.getDashboardConfig(user, params.id)
render(config as JSON)
}
def getSubdashboardKeys = {
def mainDashboardId = grailsApplication.config.openboxes.dashboardConfig.mainDashboardId
def config = grailsApplication.config.openboxes.dashboardConfig.dashboards[params.id ?: mainDashboardId]
render(config.keySet() as JSON)
}
def updateConfig = {
User user = User.get(session.user.id)
def config = userService.updateDashboardConfig(user, request.JSON)
render(config as JSON)
}
@Cacheable("dashboardCache")
def breadcrumbsConfig = {
render(grailsApplication.config.breadcrumbsConfig as JSON)
}
@Cacheable("dashboardCache")
def getInventoryByLotAndBin = {
Location location = Location.get(params.locationId)
NumberData numberData = numberDataService.getInventoryByLotAndBin(location)
render(numberData as JSON)
}
@Cacheable("dashboardCache")
def getInProgressShipments = {
Location location = Location.get(params.locationId)
User user = params.userId ? User.get(params.userId) : null
NumberData numberData = numberDataService.getInProgressShipments(user ?: session.user, location)
render(numberData as JSON)
}
@Cacheable("dashboardCache")
def getInProgressPutaways = {
Location location = Location.get(params.locationId)
User user = params.userId ? User.get(params.userId) : null
NumberData numberData = numberDataService.getInProgressPutaways(user ?: session.user, location)
render(numberData as JSON)
}
@Cacheable("dashboardCache")
def getReceivingBin = {
Location location = Location.get(params.locationId)
NumberData numberData = numberDataService.getReceivingBin(location)
render(numberData as JSON)
}
@Cacheable("dashboardCache")
def getItemsInventoried = {
Location location = Location.get(params.locationId)
NumberData numberData = numberDataService.getItemsInventoried(location)
render(numberData as JSON)
}
@Cacheable("dashboardCache")
def getDefaultBin = {
Location location = Location.get(params.locationId)
NumberData numberData = numberDataService.getDefaultBin(location)
render(numberData as JSON)
}
@Cacheable("dashboardCache")
def getExpiredProductsInStock = {
Location location = Location.get(params.locationId)
NumberData numberData = numberDataService.getExpiredProductsInStock(location)
render (numberData as JSON)
}
@Cacheable("dashboardCache")
def getExpirationSummary = {
Location location = Location.get(params.locationId)
def expirationSummary = indicatorDataService.getExpirationSummaryData(location, params)
render(expirationSummary.toJson() as JSON)
}
@Cacheable("dashboardCache")
def getFillRate = {
Location location = Location.get(params.locationId)
Location destination = Location.get(params.destinationLocation)
def fillRate = indicatorDataService.getFillRate(location, destination, params)
render(fillRate.toJson() as JSON)
}
@Cacheable("dashboardCache")
def getFillRateSnapshot = {
Location location = Location.get(params.locationId)
def fillRateSnapshot = indicatorDataService.getFillRateSnapshot(location, params)
render(fillRateSnapshot.toJson() as JSON)
}
def getFillRateDestinations = {
Location location = Location.get(params.locationId?:session.warehouse.id)
def destinations = []
def defaultDestination = [code : "react.dashboard.locationFilter.all.label", message : messageService.getMessage("react.dashboard.locationFilter.all")]
destinations << [id: "", name: defaultDestination]
destinations.addAll(indicatorDataService.getFillRateDestinations(location))
render([data: destinations] as JSON)
}
@Cacheable("dashboardCache")
def getInventorySummary = {
Location location = Location.get(params.locationId)
def inventorySummary = indicatorDataService.getInventorySummaryData(location)
render(inventorySummary.toJson() as JSON)
}
@Cacheable("dashboardCache")
def getSentStockMovements = {
Location location = Location.get(params.locationId)
def sentStockMovements = indicatorDataService.getSentStockMovements(location, params)
render(sentStockMovements.toJson() as JSON)
}
@Cacheable("dashboardCache")
def getRequisitionsByYear = {
Location location = Location.get(params.locationId)
def requisitionsByYear = indicatorDataService.getRequisitionsByYear(location, params)
render(requisitionsByYear.toJson() as JSON)
}
@Cacheable("dashboardCache")
def getReceivedStockMovements = {
Location location = Location.get(params.locationId)
def receivedStockMovements = indicatorDataService.getReceivedStockData(location, params)
render(receivedStockMovements.toJson() as JSON)
}
@Cacheable("dashboardCache")
def getOutgoingStock = {
Location location = Location.get(params.locationId)
def outgoingStock = indicatorDataService.getOutgoingStock(location)
render(outgoingStock.toJson() as JSON)
}
@Cacheable("dashboardCache")
def getIncomingStock = {
Location location = Location.get(params.locationId)
def incomingStock = indicatorDataService.getIncomingStock(location)
render(incomingStock.toJson() as JSON)
}
@Cacheable("dashboardCache")
def getDiscrepancy = {
Location location = Location.get(params.locationId)
def discrepancy = indicatorDataService.getDiscrepancy(location, params)
render(discrepancy as JSON)
}
@Cacheable("dashboardCache")
def getDelayedShipments = {
Location location = Location.get(params.locationId)
def delayedShipments = indicatorDataService.getDelayedShipments(location, request.contextPath)
render(delayedShipments as JSON)
}
@Cacheable("dashboardCache")
def getProductWithNegativeInventory = {
Location location = Location.get(params.locationId)
def productsWithNegativeInventory = numberDataService.getProductWithNegativeInventory(location)
render(productsWithNegativeInventory as JSON)
}
@Cacheable("dashboardCache")
def getLossCausedByExpiry = {
Location location = Location.get(params.locationId)
def lossCausedByExpiry = indicatorDataService.getLossCausedByExpiry(location, params)
render (lossCausedByExpiry.toJson() as JSON)
}
@Cacheable("dashboardCache")
def getProductsInventoried = {
Location location = Location.get(params.locationId)
def productsInventoried = indicatorDataService.getProductsInventoried(location)
render (productsInventoried.toJson() as JSON)
}
@Cacheable("dashboardCache")
def getPercentageAdHoc = {
Location location = Location.get(session?.warehouse?.id)
def percentageAdHoc = indicatorDataService.getPercentageAdHoc(location)
render (percentageAdHoc.toJson() as JSON)
}
@Cacheable("dashboardCache")
def getStockOutLastMonth = {
Location location = Location.get(session?.warehouse?.id)
def stockOutLastMonth = indicatorDataService.getStockOutLastMonth(location)
render (stockOutLastMonth.toJson() as JSON)
}
@Cacheable("dashboardCache")
def getOpenStockRequests = {
Location location = Location.get(params.locationId)
NumberData numberData = numberDataService.getOpenStockRequests(location)
render (numberData as JSON)
}
@Cacheable("dashboardCache")
def getInventoryValue = {
Location location = Location.get(params.locationId)
NumberData numberData = numberDataService.getInventoryValue(location)
render (numberData as JSON)
}
def getOpenPurchaseOrdersCount = {
NumberData numberData = numberDataService.getOpenPurchaseOrdersCount(params)
render (numberData as JSON)
}
}