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

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

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

File size: 10.1 KB
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        params.reportTitle = "Reactive Ratio Report"
88        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
89        params.currentUser = authService.currentUser
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
93        def result = taskReportService.getReactiveRatio(params, RCU.getLocale(request))
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        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
114        def result = taskReportService.getImmediateCallouts(params, RCU.getLocale(request))
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.reportTitle = "Equipment Register OH&S"
194        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
195        params.currentUser = authService.currentUser
196
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
201        def result = assetReportService.getEquipmentRegister(params, RCU.getLocale(request))
202
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        }
208
209        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
210        redirect(action: 'equipmentRegisterOhsGsp')
211
212//         render {
213//             dataModel.dataList.each {
214//                 p("$it")
215//             }
216//         }
217
218    } // equipmentRegisterOhs
219
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
233    def inventoryValueDetailedGsp = {
234        render(view: 'inventoryValueDetailed')
235    }
236
237    def inventoryValueDetailed = {
238
239        params.reportTitle = "Inventory Value Detailed"
240        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
241        params.currentUser = authService.currentUser
242
243        def dataModel = inventoryReportService.getInventoryValueDetailed(params, RCU.getLocale(request))
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
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
267} // end of class.
Note: See TracBrowser for help on using the repository browser.