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

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

Return error message on equipment register (OH&S) report submit when endDate < startDate.

File size: 10.1 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
[709]114        def result = taskReportService.getImmediateCallouts(params, RCU.getLocale(request))
[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
[695]193        params.reportTitle = "Equipment Register OH&S"
[654]194        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
195        params.currentUser = authService.currentUser
196
[706]197        params.calculateRegulatoryTaskCompletion = true
198        params.startDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.startDate)
199        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
200
[710]201        def result = assetReportService.getEquipmentRegister(params, RCU.getLocale(request))
[654]202
[710]203        if(!result.error) {
204            // Jasper plugin controller expects data to be a Collection.
205            chain(controller:'jasper', action:'index', model:[data: [result]], params:params)
206            return
207        }
[654]208
[710]209        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
210        redirect(action: 'equipmentRegisterOhsGsp')
211
[654]212//         render {
213//             dataModel.dataList.each {
214//                 p("$it")
215//             }
216//         }
217
[695]218    } // equipmentRegisterOhs
[654]219
[696]220    def equipmentRegisterFinancial = {
221
222        params.reportTitle = "Equipment Register Financial"
223        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
224        params.currentUser = authService.currentUser
225
226        def dataModel = assetReportService.getEquipmentRegister(params, RCU.getLocale(request))
227
228        // Jasper plugin controller expects data to be a Collection.
229        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
230
231    } // equipmentRegisterFinancial
232
[671]233    def inventoryValueDetailedGsp = {
234        render(view: 'inventoryValueDetailed')
[668]235    }
236
[671]237    def inventoryValueDetailed = {
[668]238
[671]239        params.reportTitle = "Inventory Value Detailed"
[668]240        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
241        params.currentUser = authService.currentUser
242
[671]243        def dataModel = inventoryReportService.getInventoryValueDetailed(params, RCU.getLocale(request))
[668]244
245        // Jasper plugin controller expects data to be a Collection.
246        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
247
248    }
249
[676]250    def inventoryValueOverviewGsp = {
251        render(view: 'inventoryValueOverview')
252    }
253
254    def inventoryValueOverview = {
255
256        params.reportTitle = "Inventory Value Overview"
257        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
258        params.currentUser = authService.currentUser
259
260        def dataModel = inventoryReportService.getInventoryValueOverview(params, RCU.getLocale(request))
261
262        // Jasper plugin controller expects data to be a Collection.
263        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
264
265    }
266
[533]267} // end of class.
Note: See TracBrowser for help on using the repository browser.