- Timestamp:
- Sep 23, 2010, 5:01:46 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/ReportController.groovy
r652 r654 173 173 } // assetRegister 174 174 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 175 198 } // end of class. -
trunk/grails-app/services/AssetReportService.groovy
r652 r654 117 117 } // getAssetDetail 118 118 119 /** 120 * Selects and returns level 1 sub items (aka machines or equipment) and their details. 121 * @param params The request params, may contain params to specify the search. 122 * @param locale The locale to use when generating result.message. 123 */ 124 def getEquipmentRegister(params, locale) { 125 def result = [:] 126 127 // Inner join used to return only attribTypes that are used by AssetSubItemExtendedAttributes. 128 // So the result is only assetSubItem extendedAttributeTypes. 129 def attribTypesQ = new HqlBuilder().query { 130 select 'distinct attribT.name' 131 from 'AssetSubItemExtendedAttribute attrib', 132 'join attrib.extendedAttributeType as attribT' 133 order 'by attribT.name asc' 134 } 135 result.attribTypes = Asset.executeQuery(attribTypesQ.query, attribTypesQ.namedParams) 136 137 // Since there will be nothing to show in the report table for assets without level 1 assetSubItems, 138 // a list needs to be given to the user. 139 def assetsWithoutEquipmentQ = new HqlBuilder().query { 140 select 'distinct asset' 141 from 'Asset asset', 142 'left join asset.assetSubItems as assetSubItem' 143 where 'assetSubItem = null' 144 } 145 result.assetsWithoutEquipment = AssetSubItem.executeQuery(assetsWithoutEquipmentQ.query, assetsWithoutEquipmentQ.namedParams) 146 147 // A result is returned for every level 1 assetSubItem and for any extended attributes. 148 def q = new HqlBuilder().query { 149 select 'new map(asset.name as assetName', 150 'assetSubItem.name as name', 151 'assetSubItem.description as description', 152 'assetSubItem.comment as comment', 153 'attribT.name as attribType', 154 'attrib.value as attribValue)' 155 from 'AssetSubItem assetSubItem', 156 'inner join assetSubItem.assets as asset', 157 'left join assetSubItem.assetSubItemExtendedAttributes as attrib', 158 'left join attrib.extendedAttributeType as attribT' 159 where 'asset != null' // ensure that only level 1 assetSubItems are returned. 160 if(params.section instanceof Section) { 161 namedParams.section = params.section 162 and 'asset.section = :section' 163 } 164 order 'by asset.name asc, assetSubItem.name asc, attribT.name asc' 165 } 166 def equipmentResults = AssetSubItem.executeQuery(q.query, q.namedParams) 167 168 // Build the report table rows. 169 // Rows are keyed by equipmentResult.assetName+equipmentResult.name` while the value is a Map of the attributes. 170 // The report table then groups by assetName. 171 def rows = [:] 172 equipmentResults.each { equipmentResult -> 173 // Create row if it does not exist yet. 174 def rowKey = equipmentResult.assetName+equipmentResult.name 175 if(!rows.containsKey(rowKey)) { 176 rows[rowKey] = ['assetName': equipmentResult.assetName, 177 'name':equipmentResult.name, 178 'description':equipmentResult.description, 179 'comment':equipmentResult.comment] 180 181 // Add all attribType columns. 182 result.attribTypes.each { column -> 183 rows[rowKey][column] = null 184 } 185 } 186 187 // Assign value to column. 188 rows[rowKey][equipmentResult.attribType] = equipmentResult.attribValue 189 } 190 191 // The value of each row is the dataList used by the report table. 192 result.dataList = rows.collect {it.value} 193 // Print formatting, since we are done with these as objects. 194 result.attribTypes = result.attribTypes.join(', ') 195 result.assetsWithoutEquipment = result.assetsWithoutEquipment.collect {it.name}.join(', ') 196 197 // Success. 198 return result 199 200 } // getEquipmentRegister 201 119 202 } // end class -
trunk/grails-app/views/appCore/start.gsp
r652 r654 148 148 </g:select> 149 149 </g:jasperReport> 150 <br /> 150 151 <g:jasperReport controller="report" 151 152 action="assetRegister" … … 161 162 <br /> 162 163 <g:jasperReport controller="report" 164 action="equipmentRegister" 165 jasper="equipmentRegister" 166 name="Equipment Register" 167 format="PDF, XLS"> 168 <g:select optionKey="id" 169 from="${Section.findAllByIsActive(true).sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }}" 170 name="section.id" 171 noSelection="['all':/${g.message(code:'default.all.select.text')}/]"> 172 </g:select> 173 </g:jasperReport> 174 <br /> 175 <g:jasperReport controller="report" 163 176 action="templatePortrait" 164 177 jasper="templatePortrait" -
trunk/web-app/reports/equipmentRegister.jrxml
r653 r654 4 4 <property name="ireport.encoding" value="UTF-8"/> 5 5 <property name="ireport.zoom" value="1.5"/> 6 <property name="ireport.x" value=" 15"/>7 <property name="ireport.y" value=" 0"/>6 <property name="ireport.x" value="31"/> 7 <property name="ireport.y" value="672"/> 8 8 <import value="net.sf.jasperreports.engine.*"/> 9 9 <import value="java.util.*"/> … … 50 50 <field name="Registration Required" class="java.lang.String"/> 51 51 <field name="Registration Expiry Date" class="java.lang.String"/> 52 <field name="assetName" class="java.lang.String"/> 52 53 <group name="assetName"> 53 <groupExpression><![CDATA[$F{ name}]]></groupExpression>54 <groupExpression><![CDATA[$F{assetName}]]></groupExpression> 54 55 </group> 55 56 </subDataset> … … 65 66 </queryString> 66 67 <field name="dataList" class="java.util.List"/> 67 <field name="attribTypes" class="java.util.List"/> 68 <field name="attribTypes" class="java.lang.String"/> 69 <field name="assetsWithoutEquipment" class="java.lang.String"/> 68 70 <background> 69 71 <band splitType="Stretch"/> … … 103 105 </datasetRun> 104 106 <jr:column width="100"> 105 <jr:columnHeader style="table_CH" height="32" rowSpan="1"> 106 <staticText> 107 <reportElement stretchType="RelativeToTallestObject" x="2" y="0" width="96" height="32" isPrintWhenDetailOverflows="true"/> 108 <textElement textAlignment="Center" verticalAlignment="Middle"> 109 <font fontName="Serif" size="8"/> 107 <jr:groupHeader groupName="assetName"> 108 <jr:cell height="20" rowSpan="1"> 109 <textField isStretchWithOverflow="true"> 110 <reportElement stretchType="RelativeToTallestObject" x="2" y="2" width="96" height="16" isPrintWhenDetailOverflows="true"/> 111 <textElement verticalAlignment="Middle"> 112 <font fontName="Serif" size="10"/> 113 </textElement> 114 <textFieldExpression class="java.lang.String"><![CDATA[$F{assetName}]]></textFieldExpression> 115 </textField> 116 </jr:cell> 117 </jr:groupHeader> 118 <jr:columnHeader style="table_CH" height="32" rowSpan="1"> 119 <staticText> 120 <reportElement stretchType="RelativeToTallestObject" x="2" y="0" width="96" height="16" isPrintWhenDetailOverflows="true"/> 121 <textElement verticalAlignment="Middle"> 122 <font fontName="Serif"/> 110 123 </textElement> 111 124 <text><![CDATA[Asset]]></text> 125 </staticText> 126 <staticText> 127 <reportElement x="2" y="16" width="96" height="16"/> 128 <textElement textAlignment="Center"/> 129 <text><![CDATA[Equipment]]></text> 112 130 </staticText> 113 131 </jr:columnHeader> … … 457 475 <summary> 458 476 <band height="369"> 459 <textField >460 <reportElement x="0" y="30" width="824" height="91"/>477 <textField isStretchWithOverflow="true"> 478 <reportElement stretchType="RelativeToTallestObject" x="13" y="36" width="824" height="25" isPrintWhenDetailOverflows="true"/> 461 479 <textElement> 462 480 <font fontName="Serif"/> 463 481 </textElement> 464 <textFieldExpression class="java.lang.String"><![CDATA["Asset Extended Attributes: \n"+$F{attribTypes}]]></textFieldExpression> 482 <textFieldExpression class="java.lang.String"><![CDATA["AssetSubItem Extended Attributes: \n"+$F{attribTypes}]]></textFieldExpression> 483 </textField> 484 <textField> 485 <reportElement key="staticText-1" x="242" y="0" width="340" height="30"/> 486 <textElement textAlignment="Center" verticalAlignment="Top" markup="none"> 487 <font size="20"/> 488 </textElement> 489 <textFieldExpression class="java.lang.String"><![CDATA["Summary"]]></textFieldExpression> 490 </textField> 491 <textField isStretchWithOverflow="true"> 492 <reportElement stretchType="RelativeToTallestObject" x="13" y="85" width="824" height="26" isPrintWhenDetailOverflows="true"/> 493 <textElement> 494 <font fontName="Serif"/> 495 </textElement> 496 <textFieldExpression class="java.lang.String"><![CDATA[$F{assetsWithoutEquipment}]]></textFieldExpression> 497 </textField> 498 <textField> 499 <reportElement x="13" y="66" width="824" height="19" forecolor="#FF0033"> 500 <printWhenExpression><![CDATA[$F{assetsWithoutEquipment}]]></printWhenExpression> 501 </reportElement> 502 <textElement> 503 <font fontName="Serif"/> 504 </textElement> 505 <textFieldExpression class="java.lang.String"><![CDATA["The following assets have no sub items (equipment) and therefore are not listed in the equipment table: \n"+$F{assetsWithoutEquipment}]]></textFieldExpression> 465 506 </textField> 466 507 </band>
Note: See TracChangeset
for help on using the changeset viewer.