Changeset 740 for trunk/grails-app


Ignore:
Timestamp:
Dec 13, 2010, 4:46:31 AM (14 years ago)
Author:
gav
Message:

Add regulatoryRequirements report.

Location:
trunk/grails-app
Files:
1 added
3 edited

Legend:

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

    r733 r740  
    264264    }
    265265
     266    def regulatoryRequirementsGsp = {
     267        render(view: 'regulatoryRequirements')
     268    }
     269
     270    def regulatoryRequirements = {
     271
     272        def result = assetReportService.getRegulatoryRequirements(params, RCU.getLocale(request))
     273
     274        params.reportTitle = "Asset Regulatory Requirements"
     275        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
     276        params.currentUser = authService.currentUser
     277        params.startDateString = result.startDateString
     278        params.endDateString = result.endDateString
     279
     280        if(!result.error) {
     281            // Jasper plugin controller expects data to be a Collection.
     282            chain(controller:'jasper', action:'index', model:[data: [result]], params:params)
     283            return
     284        }
     285
     286        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
     287        redirect(action: 'equipmentRegisterOhsGsp')
     288
     289//         render {
     290//             p("DataList:")
     291//             result.dataList?.each {
     292//                 p("$it")
     293//             }
     294//         }
     295
     296    } // regulatoryRequirements
     297
    266298} // end of class.
  • trunk/grails-app/services/AssetReportService.groovy

    r735 r740  
    300300    } // getEquipmentRegister
    301301
     302
     303    /**
     304    * Selects and returns assets regulatory requirements as specified in recurring regulatory tasks.
     305    * @param params The request params, may contain params to specify the search.
     306    * @param locale The locale to use when generating result.message.
     307    */
     308    def getRegulatoryRequirements(params, locale) {
     309        def result = [:]
     310
     311        def fail = { Map m ->
     312            result.error = [ code: m.code, args: [] ]
     313            return result
     314        }
     315
     316        result.section = Section.get(params.section.id.toLong())
     317        result.site = result.section.site
     318
     319        result.startDate = params.startDate ?: dateUtilService.oneWeekAgo
     320        result.endDate = params.endDate ?: dateUtilService.today
     321        // Auto swap date range.
     322        if(result.startDate > result.endDate) {
     323            def tempStartDate = result.startDate
     324            result.startDate = result.endDate
     325            result.endDate = tempStartDate
     326        }
     327
     328        result.startDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: result.startDate)
     329        result.endDateString = g.formatDate(format: "EEE, dd-MMM-yyyy", date: result.endDate)
     330
     331        result.summary = "This report only selects primary assets and not associated assets. \n"
     332        result.summary += "Tasks must have a recurrence enabled and regulatory requirement set."
     333
     334        // Subquery to count subTasks..
     335        def subTaskQ = new HqlBuilder().query {
     336            select 'count(subTask)'
     337            from 'task.subTasks as subTask'
     338            where 'subTask.trash = false'
     339                and 'subTask.targetStartDate < :endDate'
     340                and 'subTask.targetCompletionDate >= :startDate'
     341        }
     342        def subTaskTotalQ = subTaskQ.query
     343
     344        subTaskQ.and 'subTask.taskStatus.id = 3' // Complete.
     345        def subTaskCompletedQ = subTaskQ.query
     346
     347        def regulatoryTaskQ = new HqlBuilder().query {
     348            select 'new map(primaryAsset.name as assetName',
     349                        'primaryAsset.description as assetDescription',
     350                        'primaryAsset.isActive as assetIsActive',
     351                        'task.id as taskId',
     352                        'task.description as taskDescription',
     353                        "($subTaskTotalQ) as subTaskTotalCount",
     354                        "($subTaskCompletedQ) as subTaskCompletedCount)"
     355                        namedParams.startDate = result.startDate
     356                        namedParams.endDate = result.endDate
     357            from 'Task task',
     358                    'left join task.primaryAsset as primaryAsset',
     359                    'left join task.taskRecurringSchedule as taskRecurringSchedule'
     360            where 'task.regulatoryRequirement = true'
     361                and 'taskRecurringSchedule.enabled = true'
     362                and 'task.trash = false'
     363                        namedParams.sectionId = result.section.id
     364                and 'primaryAsset.section.id = :sectionId'
     365        }
     366        result.tasks = Task.executeQuery(regulatoryTaskQ.query, regulatoryTaskQ.namedParams)
     367
     368        // Build the report table row for each task.
     369        result.tasks.each { task ->
     370
     371            // Caluculate percentages and build description.
     372            def percentComplete
     373            def completionFigures
     374            if(task.subTaskTotalCount) {
     375                percentComplete = (task.subTaskCompletedCount / task.subTaskTotalCount) * 100
     376                task.completionFigures = "$percentComplete% ($task.subTaskCompletedCount/$task.subTaskTotalCount)"
     377            }
     378            else
     379                task.completionFigures = '0 sub tasks in date range'
     380        } // tasks.each
     381
     382        result.dataList = result.tasks
     383        result.dataList.sort { p1, p2 -> p1.assetName.compareToIgnoreCase(p2.assetName) }
     384
     385        // Success.
     386        return result
     387
     388    } // getRegulatoryRequirements
     389
    302390} // end class
  • trunk/grails-app/views/appCore/start.gsp

    r707 r740  
    170170                                            <br />
    171171                                            <br />
     172                                            <g:link controller="report" action="regulatoryRequirementsGsp">
     173                                                Regulatory Requirements
     174                                            </g:link>
     175                                            <br />
     176                                            <br />
    172177                                            <g:jasperReport controller="report"
    173178                                                                            action="equipmentRegisterFinancial"
Note: See TracChangeset for help on using the changeset viewer.