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

Last change on this file since 613 was 546, checked in by gav, 14 years ago

Add new Inventory Stock Take reports.

File size: 5.5 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
[546]10    def inventoryReportService
[533]11
12    def index = { redirect(action:templatePortrait,params:params) }
13
14    // the delete, save and update actions only accept POST requests
15    //static allowedMethods = [list:'POST']
16
17    def templatePortrait = {
18
[545]19        params.startDate = new Date()
20        params.endDate = new Date()
21
[533]22        params.reportTitle = "Template Report (Portrait)"
[545]23        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
[533]24        params.currentUser = authService.currentUser
[545]25        params.startDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.startDate)
26        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
27
[533]28        def dataModel = createTemplateData()
29
[545]30        // Jasper plugin controller expects data to be a Collection.
31        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
[533]32
[545]33    } // templatePortrait
34
[533]35    def templateLandscape = {
36
[545]37        params.startDate = new Date()
38        params.endDate = new Date()
39
[533]40        params.reportTitle = "Template Report (Landscape)"
[545]41        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
[533]42        params.currentUser = authService.currentUser
[545]43        params.startDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.startDate)
44        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
45
[533]46        def dataModel = createTemplateData()
47
[545]48        // Jasper plugin controller expects data to be a Collection.
49        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
[533]50
[545]51    } // templateLandscape
52
[533]53    private createTemplateData() {
[545]54
55        def result = [:]
56        result.summaryOfCalculationMethod = "Summary string of the calculations performed."
57        result.dataList = []
[533]58        for(i in 1..5) {
[545]59            def dataDetails = [:]
60            dataDetails.description = "Data description " + i.toString()
61            result.dataList << dataDetails
[533]62        }
63
[545]64        // Success.
65        return result
66
67    } // createTemplateData
68
69    def downloadTemplate = {
70
71        // params.fileName is not used directly to negate any security issues..
72        def fileName = (params.fileName == 'templateLandscape.jrxml') ? 'templateLandscape.jrxml' : 'templatePortrait.jrxml'
73        def f = grailsApplication.mainContext.getResource("reports/${fileName}").getFile()
74        if(f.isFile()) {
75            response.contentType = ConfigurationHolder.config.grails.mime.types["text"]
76            response.setHeader("Content-disposition", "attachment; filename=${fileName}")
77            render f.text
78        }
79        else
80            render(status:404, text: "File Not Found: ${f}")
81
82    } // downLoadTemplate
83
[533]84    def reactiveRatio = {
85
86        params.reportTitle = "Reactive Ratio Report"
[538]87        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
[533]88        params.currentUser = authService.currentUser
[535]89        params.startDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.startDate)
90        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
91
[545]92        def dataModel = taskReportService.getReactiveRatio(params, RCU.getLocale(request))
[533]93
[545]94        // Jasper plugin controller expects data to be a Collection.
95        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
[533]96
[545]97    } // reactiveRatio
98
[542]99    def immediateCallouts = {
100
101        params.reportTitle = "Immediate Callouts"
102        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
103        params.currentUser = authService.currentUser
104        params.startDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.startDate)
105        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
106
[545]107        def dataModel = taskReportService.getImmediateCallouts(params, RCU.getLocale(request))
[542]108
[545]109        // Jasper plugin controller expects data to be a Collection.
110        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
[542]111
[545]112    } // immediateCallouts
[533]113
[546]114    def stockTakeOverview = {
115
116        params.reportTitle = "Stock Take Overview"
117        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
118        params.currentUser = authService.currentUser
119
120        def dataModel = inventoryReportService.getStockTakeOverview(params, RCU.getLocale(request))
121
122        // Jasper plugin controller expects data to be a Collection.
123        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
124
125    } // stockTakeOverview
126
127    def stockTakeByLocation = {
128
129        params.reportTitle = "Stock Take By Location"
130        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
131        params.currentUser = authService.currentUser
132
133        def dataModel = inventoryReportService.getStockTakeByLocation(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    } // stockTakeByLocation
139
[533]140} // end of class.
Note: See TracBrowser for help on using the repository browser.