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

Last change on this file since 708 was 708, checked in by gav, 13 years ago

Fix small bug in reactive ratio report, where BigDecimal? not returned and therefore setScale() not available.
Also return error message for endDate < startDate.

File size: 9.6 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
87        params.reportTitle = "Reactive Ratio Report"
[538]88        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
[533]89        params.currentUser = authService.currentUser
[535]90        params.startDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.startDate)
91        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
92
[708]93        def result = taskReportService.getReactiveRatio(params, RCU.getLocale(request))
[533]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
108        params.reportTitle = "Immediate Callouts"
109        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
110        params.currentUser = authService.currentUser
111        params.startDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.startDate)
112        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
113
[545]114        def dataModel = taskReportService.getImmediateCallouts(params, RCU.getLocale(request))
[542]115
[545]116        // Jasper plugin controller expects data to be a Collection.
117        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
[542]118
[545]119    } // immediateCallouts
[533]120
[546]121    def stockTakeOverview = {
122
123        params.reportTitle = "Stock Take Overview"
124        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
125        params.currentUser = authService.currentUser
126
127        def dataModel = inventoryReportService.getStockTakeOverview(params, RCU.getLocale(request))
128
129        // Jasper plugin controller expects data to be a Collection.
130        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
131
132    } // stockTakeOverview
133
134    def stockTakeByLocation = {
135
136        params.reportTitle = "Stock Take By Location"
137        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
138        params.currentUser = authService.currentUser
139
140        def dataModel = inventoryReportService.getStockTakeByLocation(params, RCU.getLocale(request))
141
142        // Jasper plugin controller expects data to be a Collection.
143        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
144
145    } // stockTakeByLocation
146
[652]147    def assetDetail = {
148
149        params.reportTitle = "Asset Detail"
150        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
151        params.currentUser = authService.currentUser
[687]152        if(params.section.id == 'all') {
153            params.section = "All"
154            params.site = "All"
155        }
156        else {
157            params.section = Section.get(params.section.id.toLong())
158            params.site = params.section.site
159        }
[652]160
161        def dataModel = assetReportService.getAssetDetail(params, RCU.getLocale(request))
162
163        // Jasper plugin controller expects data to be a Collection.
164        chain(controller:'jasper', action:'index', model:[data: dataModel], params:params)
165
166    } // assetDetail
167
168    def assetRegister = {
169
170        params.reportTitle = "Asset Register"
171        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
172        params.currentUser = authService.currentUser
173
174        def dataModel = assetReportService.getAssetRegister(params, RCU.getLocale(request))
175
176        // Jasper plugin controller expects data to be a Collection.
177        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
178
179    } // assetRegister
180
[706]181    def equipmentRegisterOhsGsp = {
182        render(view: 'equipmentRegisterOhs')
183    }
184
[695]185    def equipmentRegisterOhs = {
[654]186
[695]187        params.reportTitle = "Equipment Register OH&S"
[654]188        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
189        params.currentUser = authService.currentUser
190
[706]191        params.calculateRegulatoryTaskCompletion = true
192        params.startDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.startDate)
193        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
194
[654]195        def dataModel = assetReportService.getEquipmentRegister(params, RCU.getLocale(request))
196
197        // Jasper plugin controller expects data to be a Collection.
198        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
199
200//         render {
201//             dataModel.dataList.each {
202//                 p("$it")
203//             }
204//         }
205
[695]206    } // equipmentRegisterOhs
[654]207
[696]208    def equipmentRegisterFinancial = {
209
210        params.reportTitle = "Equipment Register Financial"
211        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
212        params.currentUser = authService.currentUser
213
214        def dataModel = assetReportService.getEquipmentRegister(params, RCU.getLocale(request))
215
216        // Jasper plugin controller expects data to be a Collection.
217        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
218
219    } // equipmentRegisterFinancial
220
[671]221    def inventoryValueDetailedGsp = {
222        render(view: 'inventoryValueDetailed')
[668]223    }
224
[671]225    def inventoryValueDetailed = {
[668]226
[671]227        params.reportTitle = "Inventory Value Detailed"
[668]228        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
229        params.currentUser = authService.currentUser
230
[671]231        def dataModel = inventoryReportService.getInventoryValueDetailed(params, RCU.getLocale(request))
[668]232
233        // Jasper plugin controller expects data to be a Collection.
234        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
235
236    }
237
[676]238    def inventoryValueOverviewGsp = {
239        render(view: 'inventoryValueOverview')
240    }
241
242    def inventoryValueOverview = {
243
244        params.reportTitle = "Inventory Value Overview"
245        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
246        params.currentUser = authService.currentUser
247
248        def dataModel = inventoryReportService.getInventoryValueOverview(params, RCU.getLocale(request))
249
250        // Jasper plugin controller expects data to be a Collection.
251        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
252
253    }
254
[533]255} // end of class.
Note: See TracBrowser for help on using the repository browser.