1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
2 | import org.codehaus.groovy.grails.commons.ConfigurationHolder |
---|
3 | import org.springframework.web.servlet.support.RequestContextUtils as RCU |
---|
4 | |
---|
5 | class ReportController extends BaseController { |
---|
6 | |
---|
7 | def authService |
---|
8 | def dateUtilService |
---|
9 | def taskReportService |
---|
10 | def inventoryReportService |
---|
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 | |
---|
19 | params.startDate = new Date() |
---|
20 | params.endDate = new Date() |
---|
21 | |
---|
22 | params.reportTitle = "Template Report (Portrait)" |
---|
23 | params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL() |
---|
24 | params.currentUser = authService.currentUser |
---|
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 | |
---|
28 | def dataModel = createTemplateData() |
---|
29 | |
---|
30 | // Jasper plugin controller expects data to be a Collection. |
---|
31 | chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params) |
---|
32 | |
---|
33 | } // templatePortrait |
---|
34 | |
---|
35 | def templateLandscape = { |
---|
36 | |
---|
37 | params.startDate = new Date() |
---|
38 | params.endDate = new Date() |
---|
39 | |
---|
40 | params.reportTitle = "Template Report (Landscape)" |
---|
41 | params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL() |
---|
42 | params.currentUser = authService.currentUser |
---|
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 | |
---|
46 | def dataModel = createTemplateData() |
---|
47 | |
---|
48 | // Jasper plugin controller expects data to be a Collection. |
---|
49 | chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params) |
---|
50 | |
---|
51 | } // templateLandscape |
---|
52 | |
---|
53 | private createTemplateData() { |
---|
54 | |
---|
55 | def result = [:] |
---|
56 | result.summaryOfCalculationMethod = "Summary string of the calculations performed." |
---|
57 | result.dataList = [] |
---|
58 | for(i in 1..5) { |
---|
59 | def dataDetails = [:] |
---|
60 | dataDetails.description = "Data description " + i.toString() |
---|
61 | result.dataList << dataDetails |
---|
62 | } |
---|
63 | |
---|
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 | |
---|
84 | def reactiveRatio = { |
---|
85 | |
---|
86 | params.reportTitle = "Reactive Ratio Report" |
---|
87 | params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL() |
---|
88 | params.currentUser = authService.currentUser |
---|
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 | |
---|
92 | def dataModel = taskReportService.getReactiveRatio(params, RCU.getLocale(request)) |
---|
93 | |
---|
94 | // Jasper plugin controller expects data to be a Collection. |
---|
95 | chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params) |
---|
96 | |
---|
97 | } // reactiveRatio |
---|
98 | |
---|
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 | |
---|
107 | def dataModel = taskReportService.getImmediateCallouts(params, RCU.getLocale(request)) |
---|
108 | |
---|
109 | // Jasper plugin controller expects data to be a Collection. |
---|
110 | chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params) |
---|
111 | |
---|
112 | } // immediateCallouts |
---|
113 | |
---|
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 | |
---|
140 | } // end of class. |
---|