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

Last change on this file since 787 was 743, checked in by gav, 14 years ago

Add mandatoryRequirements report.

File size: 11.7 KB
RevLine 
[533]1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
[545]2import org.codehaus.groovy.grails.commons.ConfigurationHolder
[533]3import org.springframework.web.servlet.support.RequestContextUtils as RCU
4
5class ReportController extends BaseController {
6
7    def authService
8    def dateUtilService
9    def taskReportService
[652]10    def assetReportService
[546]11    def inventoryReportService
[533]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
[545]20        params.startDate = new Date()
21        params.endDate = new Date()
22
[533]23        params.reportTitle = "Template Report (Portrait)"
[545]24        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
[533]25        params.currentUser = authService.currentUser
[545]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
[533]29        def dataModel = createTemplateData()
30
[545]31        // Jasper plugin controller expects data to be a Collection.
32        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
[533]33
[545]34    } // templatePortrait
35
[533]36    def templateLandscape = {
37
[545]38        params.startDate = new Date()
39        params.endDate = new Date()
40
[533]41        params.reportTitle = "Template Report (Landscape)"
[545]42        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
[533]43        params.currentUser = authService.currentUser
[545]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
[533]47        def dataModel = createTemplateData()
48
[545]49        // Jasper plugin controller expects data to be a Collection.
50        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
[533]51
[545]52    } // templateLandscape
53
[533]54    private createTemplateData() {
[545]55
56        def result = [:]
57        result.summaryOfCalculationMethod = "Summary string of the calculations performed."
58        result.dataList = []
[533]59        for(i in 1..5) {
[545]60            def dataDetails = [:]
61            dataDetails.description = "Data description " + i.toString()
62            result.dataList << dataDetails
[533]63        }
64
[545]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
[533]85    def reactiveRatio = {
86
[732]87        def result = taskReportService.getReactiveRatio(params, RCU.getLocale(request))
88
[533]89        params.reportTitle = "Reactive Ratio Report"
[538]90        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
[533]91        params.currentUser = authService.currentUser
[732]92        params.startDateString = result.startDateString
93        params.endDateString = result.endDateString
[535]94
[708]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        }
[533]100
[708]101        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
102        redirect(controller: 'appCore', action: 'start', params: [showTab:'showReportsTab'])
103
[545]104    } // reactiveRatio
105
[542]106    def immediateCallouts = {
107
[732]108        def result = taskReportService.getImmediateCallouts(params, RCU.getLocale(request))
109
[542]110        params.reportTitle = "Immediate Callouts"
111        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
112        params.currentUser = authService.currentUser
[732]113        params.startDateString = result.startDateString
114        params.endDateString = result.endDateString
[542]115
[709]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        }
[542]121
[709]122        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
123        redirect(controller: 'appCore', action: 'start', params: [showTab:'showReportsTab'])
124
[545]125    } // immediateCallouts
[533]126
[546]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
[652]153    def assetDetail = {
154
155        params.reportTitle = "Asset Detail"
156        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
157        params.currentUser = authService.currentUser
[687]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        }
[652]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
[706]187    def equipmentRegisterOhsGsp = {
188        render(view: 'equipmentRegisterOhs')
189    }
190
[695]191    def equipmentRegisterOhs = {
[654]192
[733]193        params.calculateRegulatoryTaskCompletion = true
194        def result = assetReportService.getEquipmentRegister(params, RCU.getLocale(request))
195
[695]196        params.reportTitle = "Equipment Register OH&S"
[654]197        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
198        params.currentUser = authService.currentUser
[733]199        params.startDateString = result.startDateString
200        params.endDateString = result.endDateString
[654]201
[710]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        }
[654]207
[710]208        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
209        redirect(action: 'equipmentRegisterOhsGsp')
210
[654]211//         render {
212//             dataModel.dataList.each {
213//                 p("$it")
214//             }
215//         }
216
[695]217    } // equipmentRegisterOhs
[654]218
[696]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
[671]232    def inventoryValueDetailedGsp = {
233        render(view: 'inventoryValueDetailed')
[668]234    }
235
[671]236    def inventoryValueDetailed = {
[668]237
[671]238        params.reportTitle = "Inventory Value Detailed"
[668]239        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
240        params.currentUser = authService.currentUser
241
[671]242        def dataModel = inventoryReportService.getInventoryValueDetailed(params, RCU.getLocale(request))
[668]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
[676]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
[740]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)
[743]287        redirect(action: 'regulatoryRequirementsGsp')
[740]288
289    } // regulatoryRequirements
290
[743]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
[533]316} // end of class.
Note: See TracBrowser for help on using the repository browser.