Ignore:
Timestamp:
Oct 5, 2010, 12:50:57 AM (14 years ago)
Author:
gav
Message:

Improvements to equipementRegister report, adding asset detail and layout.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/AssetReportService.groovy

    r678 r679  
    125125        def result = [:]
    126126
     127        result.section = Section.get(params.section.id.toLong())
     128        result.site = result.section.site
     129
    127130        // Inner join used to return only attribTypes that are used by AssetSubItemExtendedAttributes.
    128131        // So the result is only assetSubItem extendedAttributeTypes.
     
    135138        result.attribTypes = Asset.executeQuery(attribTypesQ.query, attribTypesQ.namedParams)
    136139
    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.
     140        // A useful list of assets without subItems to be given to the user.
    139141        def assetsWithoutEquipmentQ = new HqlBuilder().query {
    140142            select 'distinct asset'
     
    142144                    'left join asset.assetSubItems as assetSubItem'
    143145            where 'assetSubItem = null'
     146                namedParams.section = result.section
     147                and 'asset.section = :section'
    144148        }
    145149        result.assetsWithoutEquipment = AssetSubItem.executeQuery(assetsWithoutEquipmentQ.query, assetsWithoutEquipmentQ.namedParams)
     
    158162                    'left join attrib.extendedAttributeType as attribT'
    159163            where 'asset != null' // ensure that only level 1 assetSubItems are returned.
    160             if(params.section instanceof Section) {
    161                 namedParams.section = params.section
     164                namedParams.section = result.section
    162165                and 'asset.section = :section'
    163             }
    164166            order 'by asset.name asc, assetSubItem.name asc, attribT.name asc'
    165167        }
    166168        def equipmentResults = AssetSubItem.executeQuery(q.query, q.namedParams)
     169
     170        // A result is returned for every asset and for any extended attributes.
     171        def assetResultsQ = new HqlBuilder().query {
     172            select 'new map(asset.name as assetName',
     173                        "'   Asset Details' as name", // Place holder 'equipment' name, 3 leading spaces for sorting.
     174                        'asset.description as description',
     175                        'asset.comment as comment',
     176                        'attribT.name as attribType',
     177                        'attrib.value as attribValue)'
     178            from 'Asset asset',
     179                    'left join asset.assetExtendedAttributes as attrib',
     180                    'left join attrib.extendedAttributeType as attribT'
     181            where 'asset.section = :section'
     182                    namedParams.section = result.section
     183            order 'by asset.name asc, attribT.name asc'
     184        }
     185        def assetResults = Asset.executeQuery(assetResultsQ.query, assetResultsQ.namedParams)
     186
     187        // Add asset details to equipmentResults.
     188        equipmentResults.addAll(assetResults)
     189        equipmentResults.sort { p1, p2 -> p1.assetName.compareToIgnoreCase(p2.assetName) ?: p1.name.compareToIgnoreCase(p2.name) }
    167190
    168191        // Build the report table rows.
Note: See TracChangeset for help on using the changeset viewer.