Changeset 706 for trunk/grails-app/services
- Timestamp:
- Nov 10, 2010, 5:30:28 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/AssetReportService.groovy
r687 r706 137 137 result.site = result.section.site 138 138 139 // Start date. 140 if(params.startDate) 141 params.startDate = dateUtilService.makeDate(params.startDate_year, params.startDate_month, params.startDate_day) 142 else 143 params.startDate = dateUtilService.oneWeekAgo 144 145 // End date. 146 if(params.endDate) 147 params.endDate = dateUtilService.makeDate(params.endDate_year, params.endDate_month, params.endDate_day) 148 else 149 params.endDate = dateUtilService.today 150 151 // Normalise date range. 152 if(params.endDate < params.startDate) 153 params.endDate = params.startDate 154 139 155 // Inner join used to return only attribTypes that are used by AssetSubItemExtendedAttributes. 140 156 // So the result is only assetSubItem extendedAttributeTypes. … … 166 182 result.assetsWithoutEquipment = AssetSubItem.executeQuery(assetsWithoutEquipmentQ.query, assetsWithoutEquipmentQ.namedParams) 167 183 184 // Subquery to count regulatory tasks. 185 def regulatoryTaskCountQ = new HqlBuilder().query { 186 187 select 'count (distinct task)' 188 from 'Task as task', 189 'left join task.associatedAssets as associatedAsset' 190 where 'task.mandatoryRegulatory = true' 191 and 'task.targetStartDate < :endDate' 192 and 'task.targetCompletionDate >= :startDate' 193 and '(task.primaryAsset.id = asset.id or associatedAsset.id = asset.id)' 194 and 'task.trash = false' 195 } 196 197 def totalRegulatoryTaskCountQ = regulatoryTaskCountQ.query 198 199 regulatoryTaskCountQ.and 'task.taskStatus.id = 3' 200 def completedRegulatoryTaskCountQ = regulatoryTaskCountQ.query 201 168 202 // A result is returned for every level 1 assetSubItem and for any extended attributes. 169 203 def q = new HqlBuilder().query { 204 170 205 select 'new map(asset.name as assetName', 171 206 'assetSubItem.name as name', 172 207 'assetSubItem.description as description', 173 208 'assetSubItem.comment as comment', 209 "0 as totalRegulatoryTaskCount", 210 "0 as completedRegulatoryTaskCount", 174 211 'attribT.name as attribType', 175 212 'attrib.value as attribValue)' … … 187 224 // A result is returned for every asset and for any extended attributes. 188 225 def assetResultsQ = new HqlBuilder().query { 226 227 // Subquery namedParams. 228 namedParams.startDate = params.startDate 229 namedParams.endDate = params.endDate+1 230 189 231 select 'new map(asset.name as assetName', 190 232 "' Asset Details' as name", // Place holder 'equipment' name, 3 leading spaces for sorting. 191 233 'asset.description as description', 192 234 'asset.comment as comment', 235 "($totalRegulatoryTaskCountQ) as totalRegulatoryTaskCount", 236 "($completedRegulatoryTaskCountQ) as completedRegulatoryTaskCount", 193 237 'attribT.name as attribType', 194 238 'attrib.value as attribValue)' … … 211 255 def rows = [:] 212 256 equipmentResults.each { equipmentResult -> 213 // Create row if it does not exist yet. 257 214 258 def rowKey = equipmentResult.assetName+equipmentResult.name 259 260 // Create new row if it does not exist yet. 215 261 if(!rows.containsKey(rowKey)) { 216 262 rows[rowKey] = ['assetName': equipmentResult.assetName, 217 'name':equipmentResult.name, 218 'description':equipmentResult.description, 219 'comment':equipmentResult.comment] 263 'name':equipmentResult.name, 264 'description':equipmentResult.description, 265 'comment':equipmentResult.comment, 266 'Regulatory Task Completion': ' '] 220 267 221 268 // Add all attribType columns. … … 223 270 rows[rowKey][column] = ' ' 224 271 } 225 } 272 273 // Caluculate and assign RegulatoryTaskCompletion, only for Assets. 274 if(params.calculateRegulatoryTaskCompletion) { 275 276 if(equipmentResult.totalRegulatoryTaskCount) { 277 def percentComplete = (equipmentResult.completedRegulatoryTaskCount / equipmentResult.totalRegulatoryTaskCount)*100 278 rows[rowKey]['Regulatory Task Completion'] = "${percentComplete.toInteger()}% (${equipmentResult.completedRegulatoryTaskCount}/${equipmentResult.totalRegulatoryTaskCount})" 279 } 280 else if(equipmentResult.name == ' Asset Details') 281 rows[rowKey]['Regulatory Task Completion'] = 'N/A' 282 } 283 284 } // Create new row. 226 285 227 286 // Assign value to column. 228 287 rows[rowKey][equipmentResult.attribType] = equipmentResult.attribValue 229 } 288 } // each. 230 289 231 290 // The value of each row is the dataList used by the report table.
Note: See TracChangeset
for help on using the changeset viewer.