source: trunk/grails-app/controllers/ReportController.groovy @ 967

Revision 743, 11.7 KB checked in by gav, 8 years ago (diff)

Add mandatoryRequirements report.

Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2import org.codehaus.groovy.grails.commons.ConfigurationHolder
3import org.springframework.web.servlet.support.RequestContextUtils as RCU
4
5class ReportController extends BaseController {
6
7    def authService
8    def dateUtilService
9    def taskReportService
10    def assetReportService
11    def inventoryReportService
12
13    def index = { redirect(action:templatePortrait,params:params) }
14
15    // the delete, save and update actions only accept POST requests
16    //static allowedMethods = [list:'POST']
17
18    def templatePortrait = {
19
20        params.startDate = new Date()
21        params.endDate = new Date()
22
23        params.reportTitle = "Template Report (Portrait)"
24        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
25        params.currentUser = authService.currentUser
26        params.startDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.startDate)
27        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
28
29        def dataModel = createTemplateData()
30
31        // Jasper plugin controller expects data to be a Collection.
32        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
33
34    } // templatePortrait
35
36    def templateLandscape = {
37
38        params.startDate = new Date()
39        params.endDate = new Date()
40
41        params.reportTitle = "Template Report (Landscape)"
42        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
43        params.currentUser = authService.currentUser
44        params.startDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.startDate)
45        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
46
47        def dataModel = createTemplateData()
48
49        // Jasper plugin controller expects data to be a Collection.
50        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
51
52    } // templateLandscape
53
54    private createTemplateData() {
55
56        def result = [:]
57        result.summaryOfCalculationMethod = "Summary string of the calculations performed."
58        result.dataList = []
59        for(i in 1..5) {
60            def dataDetails = [:]
61            dataDetails.description = "Data description " + i.toString()
62            result.dataList << dataDetails
63        }
64
65        // Success.
66        return result
67
68    } // createTemplateData
69
70    def downloadTemplate = {
71
72        // params.fileName is not used directly to negate any security issues..
73        def fileName = (params.fileName == 'templateLandscape.jrxml') ? 'templateLandscape.jrxml' : 'templatePortrait.jrxml'
74        def f = grailsApplication.mainContext.getResource("reports/${fileName}").getFile()
75        if(f.isFile()) {
76            response.contentType = ConfigurationHolder.config.grails.mime.types["text"]
77            response.setHeader("Content-disposition", "attachment; filename=${fileName}")
78            render f.text
79        }
80        else
81            render(status:404, text: "File Not Found: ${f}")
82
83    } // downLoadTemplate
84
85    def reactiveRatio = {
86
87        def result = taskReportService.getReactiveRatio(params, RCU.getLocale(request))
88
89        params.reportTitle = "Reactive Ratio Report"
90        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
91        params.currentUser = authService.currentUser
92        params.startDateString = result.startDateString
93        params.endDateString = result.endDateString
94
95        if(!result.error) {
96            // Jasper plugin controller expects data to be a Collection.
97            chain(controller:'jasper', action:'index', model:[data: [result]], params:params)
98            return
99        }
100
101        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
102        redirect(controller: 'appCore', action: 'start', params: [showTab:'showReportsTab'])
103
104    } // reactiveRatio
105
106    def immediateCallouts = {
107
108        def result = taskReportService.getImmediateCallouts(params, RCU.getLocale(request))
109
110        params.reportTitle = "Immediate Callouts"
111        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
112        params.currentUser = authService.currentUser
113        params.startDateString = result.startDateString
114        params.endDateString = result.endDateString
115
116        if(!result.error) {
117            // Jasper plugin controller expects data to be a Collection.
118            chain(controller:'jasper', action:'index', model:[data: [result]], params:params)
119            return
120        }
121
122        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
123        redirect(controller: 'appCore', action: 'start', params: [showTab:'showReportsTab'])
124
125    } // immediateCallouts
126
127    def stockTakeOverview = {
128
129        params.reportTitle = "Stock Take Overview"
130        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
131        params.currentUser = authService.currentUser
132
133        def dataModel = inventoryReportService.getStockTakeOverview(params, RCU.getLocale(request))
134
135        // Jasper plugin controller expects data to be a Collection.
136        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
137
138    } // stockTakeOverview
139
140    def stockTakeByLocation = {
141
142        params.reportTitle = "Stock Take By Location"
143        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
144        params.currentUser = authService.currentUser
145
146        def dataModel = inventoryReportService.getStockTakeByLocation(params, RCU.getLocale(request))
147
148        // Jasper plugin controller expects data to be a Collection.
149        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
150
151    } // stockTakeByLocation
152
153    def assetDetail = {
154
155        params.reportTitle = "Asset Detail"
156        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
157        params.currentUser = authService.currentUser
158        if(params.section.id == 'all') {
159            params.section = "All"
160            params.site = "All"
161        }
162        else {
163            params.section = Section.get(params.section.id.toLong())
164            params.site = params.section.site
165        }
166
167        def dataModel = assetReportService.getAssetDetail(params, RCU.getLocale(request))
168
169        // Jasper plugin controller expects data to be a Collection.
170        chain(controller:'jasper', action:'index', model:[data: dataModel], params:params)
171
172    } // assetDetail
173
174    def assetRegister = {
175
176        params.reportTitle = "Asset Register"
177        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
178        params.currentUser = authService.currentUser
179
180        def dataModel = assetReportService.getAssetRegister(params, RCU.getLocale(request))
181
182        // Jasper plugin controller expects data to be a Collection.
183        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
184
185    } // assetRegister
186
187    def equipmentRegisterOhsGsp = {
188        render(view: 'equipmentRegisterOhs')
189    }
190
191    def equipmentRegisterOhs = {
192
193        params.calculateRegulatoryTaskCompletion = true
194        def result = assetReportService.getEquipmentRegister(params, RCU.getLocale(request))
195
196        params.reportTitle = "Equipment Register OH&S"
197        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
198        params.currentUser = authService.currentUser
199        params.startDateString = result.startDateString
200        params.endDateString = result.endDateString
201
202        if(!result.error) {
203            // Jasper plugin controller expects data to be a Collection.
204            chain(controller:'jasper', action:'index', model:[data: [result]], params:params)
205            return
206        }
207
208        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
209        redirect(action: 'equipmentRegisterOhsGsp')
210
211//         render {
212//             dataModel.dataList.each {
213//                 p("$it")
214//             }
215//         }
216
217    } // equipmentRegisterOhs
218
219    def equipmentRegisterFinancial = {
220
221        params.reportTitle = "Equipment Register Financial"
222        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
223        params.currentUser = authService.currentUser
224
225        def dataModel = assetReportService.getEquipmentRegister(params, RCU.getLocale(request))
226
227        // Jasper plugin controller expects data to be a Collection.
228        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
229
230    } // equipmentRegisterFinancial
231
232    def inventoryValueDetailedGsp = {
233        render(view: 'inventoryValueDetailed')
234    }
235
236    def inventoryValueDetailed = {
237
238        params.reportTitle = "Inventory Value Detailed"
239        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
240        params.currentUser = authService.currentUser
241
242        def dataModel = inventoryReportService.getInventoryValueDetailed(params, RCU.getLocale(request))
243
244        // Jasper plugin controller expects data to be a Collection.
245        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
246
247    }
248
249    def inventoryValueOverviewGsp = {
250        render(view: 'inventoryValueOverview')
251    }
252
253    def inventoryValueOverview = {
254
255        params.reportTitle = "Inventory Value Overview"
256        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
257        params.currentUser = authService.currentUser
258
259        def dataModel = inventoryReportService.getInventoryValueOverview(params, RCU.getLocale(request))
260
261        // Jasper plugin controller expects data to be a Collection.
262        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
263
264    }
265
266    def regulatoryRequirementsGsp = {
267        render(view: 'regulatoryRequirements')
268    }
269
270    def regulatoryRequirements = {
271
272        def result = assetReportService.getRegulatoryRequirements(params, RCU.getLocale(request))
273
274        params.reportTitle = "Asset Regulatory Requirements"
275        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
276        params.currentUser = authService.currentUser
277        params.startDateString = result.startDateString
278        params.endDateString = result.endDateString
279
280        if(!result.error) {
281            // Jasper plugin controller expects data to be a Collection.
282            chain(controller:'jasper', action:'index', model:[data: [result]], params:params)
283            return
284        }
285
286        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
287        redirect(action: 'regulatoryRequirementsGsp')
288
289    } // regulatoryRequirements
290
291    def mandatoryRequirementsGsp = {
292        render(view: 'mandatoryRequirements')
293    }
294
295    def mandatoryRequirements = {
296
297        def result = assetReportService.getMandatoryRequirements(params, RCU.getLocale(request))
298
299        params.reportTitle = "Asset Mandatory Requirements"
300        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
301        params.currentUser = authService.currentUser
302        params.startDateString = result.startDateString
303        params.endDateString = result.endDateString
304
305        if(!result.error) {
306            // Jasper plugin controller expects data to be a Collection.
307            chain(controller:'jasper', action:'index', model:[data: [result]], params:params)
308            return
309        }
310
311        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
312        redirect(action: 'mandatoryRequirementsGsp')
313
314    } // mandatoryRequirements
315
316} // end of class.
Note: See TracBrowser for help on using the repository browser.