Changeset 706


Ignore:
Timestamp:
Nov 10, 2010, 5:30:28 AM (13 years ago)
Author:
gav
Message:

Implement ticket #88 - "Implement Regulatory Task Completion on Equipmet Register Report OH&S"

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/ReportController.groovy

    r696 r706  
    173173    } // assetRegister
    174174
     175    def equipmentRegisterOhsGsp = {
     176        render(view: 'equipmentRegisterOhs')
     177    }
     178
    175179    def equipmentRegisterOhs = {
    176180
     
    178182        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
    179183        params.currentUser = authService.currentUser
     184
     185        params.calculateRegulatoryTaskCompletion = true
     186        params.startDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.startDate)
     187        params.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: params.endDate)
    180188
    181189        def dataModel = assetReportService.getEquipmentRegister(params, RCU.getLocale(request))
  • trunk/grails-app/services/AssetReportService.groovy

    r687 r706  
    137137        result.site = result.section.site
    138138
     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
    139155        // Inner join used to return only attribTypes that are used by AssetSubItemExtendedAttributes.
    140156        // So the result is only assetSubItem extendedAttributeTypes.
     
    166182        result.assetsWithoutEquipment = AssetSubItem.executeQuery(assetsWithoutEquipmentQ.query, assetsWithoutEquipmentQ.namedParams)
    167183
     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
    168202        // A result is returned for every level 1 assetSubItem and for any extended attributes.
    169203        def q = new HqlBuilder().query {
     204
    170205            select 'new map(asset.name as assetName',
    171206                        'assetSubItem.name as name',
    172207                        'assetSubItem.description as description',
    173208                        'assetSubItem.comment as comment',
     209                        "0 as totalRegulatoryTaskCount",
     210                        "0 as completedRegulatoryTaskCount",
    174211                        'attribT.name as attribType',
    175212                        'attrib.value as attribValue)'
     
    187224        // A result is returned for every asset and for any extended attributes.
    188225        def assetResultsQ = new HqlBuilder().query {
     226
     227            // Subquery namedParams.
     228            namedParams.startDate = params.startDate
     229            namedParams.endDate = params.endDate+1
     230
    189231            select 'new map(asset.name as assetName',
    190232                        "'   Asset Details' as name", // Place holder 'equipment' name, 3 leading spaces for sorting.
    191233                        'asset.description as description',
    192234                        'asset.comment as comment',
     235                        "($totalRegulatoryTaskCountQ) as totalRegulatoryTaskCount",
     236                        "($completedRegulatoryTaskCountQ) as completedRegulatoryTaskCount",
    193237                        'attribT.name as attribType',
    194238                        'attrib.value as attribValue)'
     
    211255        def rows = [:]
    212256        equipmentResults.each { equipmentResult ->
    213             // Create row if it does not exist yet.
     257
    214258            def rowKey = equipmentResult.assetName+equipmentResult.name
     259
     260            // Create new row if it does not exist yet.
    215261            if(!rows.containsKey(rowKey)) {
    216262                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': ' ']
    220267
    221268                // Add all attribType columns.
     
    223270                    rows[rowKey][column] = ' '
    224271                }
    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.
    226285
    227286            // Assign value to column.
    228287            rows[rowKey][equipmentResult.attribType] = equipmentResult.attribValue
    229         }
     288        } // each.
    230289
    231290        // The value of each row is the dataList used by the report table.
  • trunk/grails-app/views/appCore/start.gsp

    r696 r706  
    138138                                            <br />
    139139                                            <g:jasperReport controller="report"
     140                                                                            action="templatePortrait"
     141                                                                            jasper="templatePortrait"
     142                                                                            name="Template (Portrait)"
     143                                                                            format="PDF, XLS">
     144                                                <g:link controller="report" action="downloadTemplate" params="[fileName: 'templatePortrait.jrxml']">
     145                                                    Download
     146                                                </g:link>
     147                                            </g:jasperReport>
     148                                            <br />
     149                                            <g:jasperReport controller="report"
     150                                                                            action="templateLandscape"
     151                                                                            jasper="templateLandscape"
     152                                                                            name="Template (Landscape)"
     153                                                                            format="PDF, XLS">
     154                                                <g:link controller="report" action="downloadTemplate" params="[fileName: 'templateLandscape.jrxml']">
     155                                                    Download
     156                                                </g:link>
     157                                            </g:jasperReport>
     158                                            <br />
     159                                        </td>
     160                                    </tr>
     161
     162                                    <tr class="prop">
     163                                        <td valign="top" class="name">
     164                                            <label>Assets:</label>
     165                                        </td>
     166                                        <td valign="top" class="value">
     167                                            <g:link controller="report" action="equipmentRegisterOhsGsp">
     168                                                Equipment Register (OH&amp;S)
     169                                            </g:link>
     170                                            <br />
     171                                            <br />
     172                                            <g:jasperReport controller="report"
     173                                                                            action="equipmentRegisterFinancial"
     174                                                                            jasper="equipmentRegisterFinancial"
     175                                                                            name="Equipment Register (Financial)"
     176                                                                            format="PDF, XLS">
     177                                                <g:select optionKey="id"
     178                                                                    from="${sections}"
     179                                                                    name="section.id">
     180                                                </g:select>
     181                                            </g:jasperReport>
     182                                            <br />
     183                                            <g:jasperReport controller="report"
     184                                                                            action="assetRegister"
     185                                                                            jasper="assetRegister"
     186                                                                            name="Asset Register"
     187                                                                            format="PDF, XLS">
     188                                                <g:select optionKey="id"
     189                                                                    from="${sections}"
     190                                                                    name="section.id">
     191                                                </g:select>
     192                                            </g:jasperReport>
     193                                            <br />
     194                                            <g:jasperReport controller="report"
    140195                                                                            action="assetDetail"
    141196                                                                            jasper="assetDetail"
     
    149204                                            </g:jasperReport>
    150205                                            <br />
    151                                             <g:jasperReport controller="report"
    152                                                                             action="assetRegister"
    153                                                                             jasper="assetRegister"
    154                                                                             name="Asset Register"
    155                                                                             format="PDF, XLS">
    156                                                 <g:select optionKey="id"
    157                                                                     from="${sections}"
    158                                                                     name="section.id">
    159                                                 </g:select>
    160                                             </g:jasperReport>
    161                                             <br />
    162                                             <g:jasperReport controller="report"
    163                                                                             action="equipmentRegisterOhs"
    164                                                                             jasper="equipmentRegisterOhs"
    165                                                                             name="Equipment Register (OH&amp;S)"
    166                                                                             format="PDF, XLS">
    167                                                 <g:select optionKey="id"
    168                                                                     from="${sections}"
    169                                                                     name="section.id">
    170                                                 </g:select>
    171                                             </g:jasperReport>
    172                                             <br />
    173                                             <g:jasperReport controller="report"
    174                                                                             action="equipmentRegisterFinancial"
    175                                                                             jasper="equipmentRegisterFinancial"
    176                                                                             name="Equipment Register (Financial)"
    177                                                                             format="PDF, XLS">
    178                                                 <g:select optionKey="id"
    179                                                                     from="${sections}"
    180                                                                     name="section.id">
    181                                                 </g:select>
    182                                             </g:jasperReport>
    183                                             <br />
    184                                             <g:jasperReport controller="report"
    185                                                                             action="templatePortrait"
    186                                                                             jasper="templatePortrait"
    187                                                                             name="Template (Portrait)"
    188                                                                             format="PDF, XLS">
    189                                                 <g:link controller="report" action="downloadTemplate" params="[fileName: 'templatePortrait.jrxml']">
    190                                                     Download
    191                                                 </g:link>
    192                                             </g:jasperReport>
    193                                             <br />
    194                                             <g:jasperReport controller="report"
    195                                                                             action="templateLandscape"
    196                                                                             jasper="templateLandscape"
    197                                                                             name="Template (Landscape)"
    198                                                                             format="PDF, XLS">
    199                                                 <g:link controller="report" action="downloadTemplate" params="[fileName: 'templateLandscape.jrxml']">
    200                                                     Download
    201                                                 </g:link>
    202                                             </g:jasperReport>
    203                                             <br />
    204                                         </td>
    205206                                    </tr>
    206207
  • trunk/web-app/reports/equipmentRegisterOhs.jrxml

    r695 r706  
    44        <property name="ireport.encoding" value="UTF-8"/>
    55        <property name="ireport.zoom" value="1.5"/>
    6         <property name="ireport.x" value="0"/>
    7         <property name="ireport.y" value="624"/>
     6        <property name="ireport.x" value="337"/>
     7        <property name="ireport.y" value="0"/>
    88        <import value="net.sf.jasperreports.engine.*"/>
    99        <import value="java.util.*"/>
     
    4949                <field name="Safe Work Procedure" class="java.lang.String"/>
    5050                <field name="Regulatory Requirement" class="java.lang.String"/>
    51                 <field name="Maintenance % Completion" class="java.lang.String"/>
     51                <field name="Regulatory Task Completion" class="java.lang.String"/>
    5252                <field name="Registration Required" class="java.lang.String"/>
    5353                <field name="Registration Expiry Date" class="java.lang.String"/>
     
    6464                <defaultValueExpression><![CDATA["C:\\Documents and Settings\\kromhoutg\\My Documents\\reports\\"]]></defaultValueExpression>
    6565        </parameter>
     66        <parameter name="startDateString" class="java.lang.String"/>
     67        <parameter name="endDateString" class="java.lang.String"/>
    6668        <queryString language="SQL">
    6769                <![CDATA[]]>
     
    7880                <band height="57" splitType="Stretch">
    7981                        <textField>
    80                                 <reportElement key="staticText-1" x="398" y="14" width="340" height="20"/>
     82                                <reportElement key="staticText-1" x="398" y="5" width="340" height="20"/>
    8183                                <textElement textAlignment="Center" verticalAlignment="Top" markup="none">
    8284                                        <font fontName="Serif" size="14"/>
     
    8991                        </image>
    9092                        <textField>
    91                                 <reportElement x="398" y="34" width="340" height="15" isPrintWhenDetailOverflows="true"/>
     93                                <reportElement x="398" y="25" width="340" height="15" isPrintWhenDetailOverflows="true"/>
    9294                                <textElement textAlignment="Center">
    9395                                        <font fontName="Serif" size="10"/>
    9496                                </textElement>
    9597                                <textFieldExpression class="java.lang.String"><![CDATA["Site: "+$F{site}.name+", "+"Section: "+$F{section}.name]]></textFieldExpression>
     98                        </textField>
     99                        <textField pattern="dd-MMM-yyyy" isBlankWhenNull="true">
     100                                <reportElement x="398" y="40" width="340" height="12"/>
     101                                <textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
     102                                        <font fontName="Serif" size="8"/>
     103                                </textElement>
     104                                <textFieldExpression class="java.lang.String"><![CDATA[$P{startDateString}+" to "+$P{endDateString}]]></textFieldExpression>
    96105                        </textField>
    97106                </band>
     
    324333                                                                        <font fontName="Serif" size="8" isBold="false"/>
    325334                                                                </textElement>
    326                                                                 <text><![CDATA[Regulatory Requirement (Y/N)]]></text>
     335                                                                <text><![CDATA[Regulatory Requirement]]></text>
    327336                                                        </staticText>
    328337                                                </jr:columnHeader>
     
    344353                                                                        <font fontName="Serif" size="8" isBold="false"/>
    345354                                                                </textElement>
    346                                                                 <text><![CDATA[Maintenance % Completion]]></text>
     355                                                                <text><![CDATA[Regulatory Task Complete]]></text>
    347356                                                        </staticText>
    348357                                                </jr:columnHeader>
     
    353362                                                                        <font fontName="Serif" size="8"/>
    354363                                                                </textElement>
    355                                                                 <textFieldExpression class="java.lang.String"><![CDATA[$F{Maintenance % Completion}]]></textFieldExpression>
     364                                                                <textFieldExpression class="java.lang.String"><![CDATA[$F{Regulatory Task Completion}]]></textFieldExpression>
    356365                                                        </textField>
    357366                                                </jr:detailCell>
Note: See TracChangeset for help on using the changeset viewer.