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

Last change on this file since 673 was 671, checked in by gav, 14 years ago

Rename Inventory Value report to Inventory Detailed Value.

File size: 8.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
[545]93        def dataModel = taskReportService.getReactiveRatio(params, RCU.getLocale(request))
[533]94
[545]95        // Jasper plugin controller expects data to be a Collection.
96        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
[533]97
[545]98    } // reactiveRatio
99
[542]100    def immediateCallouts = {
101
102        params.reportTitle = "Immediate Callouts"
103        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
104        params.currentUser = authService.currentUser
105        params.startDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.startDate)
106        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
107
[545]108        def dataModel = taskReportService.getImmediateCallouts(params, RCU.getLocale(request))
[542]109
[545]110        // Jasper plugin controller expects data to be a Collection.
111        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
[542]112
[545]113    } // immediateCallouts
[533]114
[546]115    def stockTakeOverview = {
116
117        params.reportTitle = "Stock Take Overview"
118        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
119        params.currentUser = authService.currentUser
120
121        def dataModel = inventoryReportService.getStockTakeOverview(params, RCU.getLocale(request))
122
123        // Jasper plugin controller expects data to be a Collection.
124        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
125
126    } // stockTakeOverview
127
128    def stockTakeByLocation = {
129
130        params.reportTitle = "Stock Take By Location"
131        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
132        params.currentUser = authService.currentUser
133
134        def dataModel = inventoryReportService.getStockTakeByLocation(params, RCU.getLocale(request))
135
136        // Jasper plugin controller expects data to be a Collection.
137        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
138
139    } // stockTakeByLocation
140
[652]141    def assetDetail = {
142
143        params.reportTitle = "Asset Detail"
144        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
145        params.currentUser = authService.currentUser
146        if(params.asset.id == 'all')
147            params.asset = "All"
148        else
149            params.asset = Asset.get(params.asset.id.toLong())
150
151        def dataModel = assetReportService.getAssetDetail(params, RCU.getLocale(request))
152
153        // Jasper plugin controller expects data to be a Collection.
154        chain(controller:'jasper', action:'index', model:[data: dataModel], params:params)
155
156    } // assetDetail
157
158    def assetRegister = {
159
160        params.reportTitle = "Asset Register"
161        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
162        params.currentUser = authService.currentUser
163        if(params.section.id == 'all')
164            params.section = "All"
165        else
166            params.section = Section.get(params.section.id.toLong())
167
168        def dataModel = assetReportService.getAssetRegister(params, RCU.getLocale(request))
169
170        // Jasper plugin controller expects data to be a Collection.
171        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
172
173    } // assetRegister
174
[654]175    def equipmentRegister = {
176
177        params.reportTitle = "Equipment Register"
178        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
179        params.currentUser = authService.currentUser
180        if(params.section.id == 'all')
181            params.section = "All"
182        else
183            params.section = Section.get(params.section.id.toLong())
184
185        def dataModel = assetReportService.getEquipmentRegister(params, RCU.getLocale(request))
186
187        // Jasper plugin controller expects data to be a Collection.
188        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
189
190//         render {
191//             dataModel.dataList.each {
192//                 p("$it")
193//             }
194//         }
195
196    } // equipmentRegister
197
[671]198    def inventoryValueDetailedGsp = {
199        render(view: 'inventoryValueDetailed')
[668]200    }
201
[671]202    def inventoryValueDetailed = {
[668]203
[671]204        params.reportTitle = "Inventory Value Detailed"
[668]205        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
206        params.currentUser = authService.currentUser
207
[671]208        def dataModel = inventoryReportService.getInventoryValueDetailed(params, RCU.getLocale(request))
[668]209
210        // Jasper plugin controller expects data to be a Collection.
211        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
212
213    }
214
[533]215} // end of class.
Note: See TracBrowser for help on using the repository browser.