| 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 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 dataModel = taskReportService.getReactiveRatio(params, RCU.getLocale(request)) |
|---|
| 94 | |
|---|
| 95 | // Jasper plugin controller expects data to be a Collection. |
|---|
| 96 | chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params) |
|---|
| 97 | |
|---|
| 98 | } // reactiveRatio |
|---|
| 99 | |
|---|
| 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 | |
|---|
| 108 | def dataModel = taskReportService.getImmediateCallouts(params, RCU.getLocale(request)) |
|---|
| 109 | |
|---|
| 110 | // Jasper plugin controller expects data to be a Collection. |
|---|
| 111 | chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params) |
|---|
| 112 | |
|---|
| 113 | } // immediateCallouts |
|---|
| 114 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 164 | def dataModel = assetReportService.getAssetRegister(params, RCU.getLocale(request)) |
|---|
| 165 | |
|---|
| 166 | // Jasper plugin controller expects data to be a Collection. |
|---|
| 167 | chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params) |
|---|
| 168 | |
|---|
| 169 | } // assetRegister |
|---|
| 170 | |
|---|
| 171 | def equipmentRegister = { |
|---|
| 172 | |
|---|
| 173 | params.reportTitle = "Equipment Register" |
|---|
| 174 | params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL() |
|---|
| 175 | params.currentUser = authService.currentUser |
|---|
| 176 | |
|---|
| 177 | def dataModel = assetReportService.getEquipmentRegister(params, RCU.getLocale(request)) |
|---|
| 178 | |
|---|
| 179 | // Jasper plugin controller expects data to be a Collection. |
|---|
| 180 | chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params) |
|---|
| 181 | |
|---|
| 182 | // render { |
|---|
| 183 | // dataModel.dataList.each { |
|---|
| 184 | // p("$it") |
|---|
| 185 | // } |
|---|
| 186 | // } |
|---|
| 187 | |
|---|
| 188 | } // equipmentRegister |
|---|
| 189 | |
|---|
| 190 | def inventoryValueDetailedGsp = { |
|---|
| 191 | render(view: 'inventoryValueDetailed') |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | def inventoryValueDetailed = { |
|---|
| 195 | |
|---|
| 196 | params.reportTitle = "Inventory Value Detailed" |
|---|
| 197 | params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL() |
|---|
| 198 | params.currentUser = authService.currentUser |
|---|
| 199 | |
|---|
| 200 | def dataModel = inventoryReportService.getInventoryValueDetailed(params, RCU.getLocale(request)) |
|---|
| 201 | |
|---|
| 202 | // Jasper plugin controller expects data to be a Collection. |
|---|
| 203 | chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params) |
|---|
| 204 | |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | def inventoryValueOverviewGsp = { |
|---|
| 208 | render(view: 'inventoryValueOverview') |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | def inventoryValueOverview = { |
|---|
| 212 | |
|---|
| 213 | params.reportTitle = "Inventory Value Overview" |
|---|
| 214 | params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL() |
|---|
| 215 | params.currentUser = authService.currentUser |
|---|
| 216 | |
|---|
| 217 | def dataModel = inventoryReportService.getInventoryValueOverview(params, RCU.getLocale(request)) |
|---|
| 218 | |
|---|
| 219 | // Jasper plugin controller expects data to be a Collection. |
|---|
| 220 | chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params) |
|---|
| 221 | |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | } // end of class. |
|---|