Skip to content

Commit

Permalink
Merge pull request #186 from chrisala/master
Browse files Browse the repository at this point in the history
Green army report and data import updates
  • Loading branch information
chrisala committed Mar 25, 2015
2 parents 20b0d11 + c4719f1 commit c39d1be
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 41 deletions.
2 changes: 1 addition & 1 deletion grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ grails.project.dependency.resolution = {
build ":release:3.0.1"

if (Environment.current != Environment.DEVELOPMENT) {
compile ":fieldcapture-plugin:1.0.1-SNAPSHOT"
compile ":fieldcapture-plugin:1.0.2-SNAPSHOT"
}

}
Expand Down
111 changes: 77 additions & 34 deletions grails-app/controllers/au/org/ala/merit/OrganisationController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class OrganisationController extends au.org.ala.fieldcapture.OrganisationControl

response.setContentType('text/plain')

def sheets = ['Jul14', 'Aug14', 'Sep14', 'Oct14', 'Nov14', 'Dec14', 'Jan15']
def sheets = ['Jul14', 'Aug14', 'Sep14', 'Oct14', 'Nov14', 'Dec14', 'Jan15', 'Feb15']
if (request.respondsTo('getFile')) {
def file = request.getFile('gaData')
if (file) {
Expand Down Expand Up @@ -279,6 +279,46 @@ class OrganisationController extends au.org.ala.fieldcapture.OrganisationControl
}
}

def commencementDate = getCellValue(row, 7)
def actualCommencementDate = getCellValue(row, 9)
if ((commencementDate && (commencementDate instanceof Number) || (actualCommencementDate && actualCommencementDate instanceof Number))) {
def commencementDateString = ''
if (commencementDate && (commencementDate instanceof Number)) {
commencementDateString = excelDateToISODateString(commencementDate)
}

def actualCommencementDateString = ''
if (actualCommencementDate && (actualCommencementDate instanceof Number)) {
actualCommencementDateString = excelDateToISODateString(actualCommencementDate)
}

def startDateString = actualCommencementDateString ?: commencementDateString

if (startDateString != project.plannedStartDate) {
println "Project ${projectId} actual commencement date ${startDateString} plannedStartDate ${project.plannedStartDate}\n"

println "****************************Updating project dates and activities!!! ${project.grantId} ${project.projectId}**********************************"


def originalStartDate = DateUtils.parse(project.plannedStartDate)
def originalEndDate = DateUtils.parse(project.plannedEndDate)

def originalDuration = new Interval(originalStartDate, originalEndDate).toDuration()

def startDate = DateUtils.parse(startDateString)

def endDate = startDate.plus(originalDuration)

def endDateString = DateUtils.format(endDate.toDateTimeISO())

projectService.update(project.projectId, [plannedStartDate: startDateString, plannedEndDate: endDateString])

updateActivities(project, [], startDateString, endDateString)

// Reload the updated project
project = projectService.get(project.projectId, 'all')
}
}

def continuingProject = getCellValue(row, 11)
def completed = getCellValue(row, 13)
Expand Down Expand Up @@ -454,56 +494,59 @@ class OrganisationController extends au.org.ala.fieldcapture.OrganisationControl
results << "Project ${project.grantId} actual commencement date ${plannedStartDate} plannedStartDate ${project.plannedStartDate}\n"
}

def newDetails= [plannedStartDate: plannedStartDate, plannedEndDate: plannedEndDate, workOrderId: workOrderId, timeline:null]
def newDetails= [plannedStartDate: plannedStartDate, workOrderStartDate: plannedStartDate, plannedEndDate: plannedEndDate, workOrderEndDate: plannedEndDate, workOrderId: workOrderId, timeline:null]
resp = projectService.update(project.projectId, newDetails)
if (!resp || resp.error) {
errors << "Unable to update project ${project.grantId} : ${resp?.error}"
}
else {
updateActivities(project, errors, plannedStartDate, plannedEndDate)
}
return [error:errors, results:results]

def activitiesWithDefaultDates = project.activities.findAll {
}

if (it.plannedStartDate == project.plannedStartDate && it.plannedEndDate == project.plannedEndDate) {
return true
}
def actStart = DateUtils.parse(it.plannedStartDate)
def actEnd = DateUtils.parse(it.plannedEndDate)
private void updateActivities(project, errors, plannedStartDate, plannedEndDate) {
def activitiesWithDefaultDates = project.activities.findAll {

return new Duration(actStart, actEnd).isLongerThan(Weeks.weeks(19).toStandardDuration())
if (it.plannedStartDate == project.plannedStartDate && it.plannedEndDate == project.plannedEndDate) {
return true
}
def actStart = DateUtils.parse(it.plannedStartDate)
def actEnd = DateUtils.parse(it.plannedEndDate)

def modifiedActivities = project.activities.findAll {
!(it.activityId in activitiesWithDefaultDates.collect{a -> a.activityId})
}
return new Duration(actStart, actEnd).isLongerThan(Weeks.weeks(19).toStandardDuration())
}

if (modifiedActivities) {
errors << "${project.grantId}: Number of activities with non-default dates: ${modifiedActivities.size()}"
}
def modifiedActivities = project.activities.findAll {
!(it.activityId in activitiesWithDefaultDates.collect { a -> a.activityId })
}

if (modifiedActivities) {
errors << "${project.grantId}: Number of activities with non-default dates: ${modifiedActivities.size()}"
}

if (modifiedActivities) {
modifiedActivities.each {
if (it.plannedStartDate < plannedStartDate) {
errors << "${project.grantId}: Activity ${it.description} starts before contract date: ${it.plannedStartDate}, ${plannedStartDate}"
}
if (it.plannedEndDate > plannedEndDate) {
errors << "${project.grantId}: Activity ${it.description} ends after contract end date: ${it.plannedEndDate}, ${plannedEndDate}"
}
if (it.plannedEndDate < plannedStartDate) {
errors << "${project.grantId}: Activity ${it.description} ends before contract start date: ${it.plannedEndDate}, ${plannedStartDate}"
}
}

if (modifiedActivities) {
modifiedActivities.each {
if (it.plannedStartDate < plannedStartDate) {
errors << "${project.grantId}: Activity ${it.description} starts before contract date: ${it.plannedStartDate}, ${plannedStartDate}"
}
if (it.plannedEndDate > plannedEndDate) {
errors << "${project.grantId}: Activity ${it.description} ends after contract end date: ${it.plannedEndDate}, ${plannedEndDate}"
}
if (it.plannedEndDate < plannedStartDate) {
errors << "${project.grantId}: Activity ${it.description} ends before contract start date: ${it.plannedEndDate}, ${plannedStartDate}"
}
}

if (activitiesWithDefaultDates) {
// Update the dates of the works activities that haven't been modified from the original defaults.
def activityIds = activitiesWithDefaultDates.collect { it.activityId }
activityService.bulkUpdateActivities(activityIds, [plannedStartDate: plannedStartDate, plannedEndDate: plannedEndDate])
}
projectService.createReportingActivitiesForProject(project.projectId, [[period: Period.months(1), type: 'Green Army - Monthly project status report']])
}
return [error:errors, results:results]

if (activitiesWithDefaultDates) {
// Update the dates of the works activities that haven't been modified from the original defaults.
def activityIds = activitiesWithDefaultDates.collect { it.activityId }
activityService.bulkUpdateActivities(activityIds, [plannedStartDate: plannedStartDate, plannedEndDate: plannedEndDate])
}
projectService.createReportingActivitiesForProject(project.projectId, [[period: Period.months(1), type: 'Green Army - Monthly project status report']])
}
}
14 changes: 13 additions & 1 deletion grails-app/services/au/org/ala/merit/ProjectService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@ class ProjectService extends au.org.ala.fieldcapture.ProjectService {
def update(id, body) {
TimeZone.setDefault(TimeZone.getTimeZone('UTC'))
body?.custom?.details?.lastUpdated = new Date().format("yyyy-MM-dd'T'HH:mm:ss'Z'")
webService.doPost(grailsApplication.config.ecodata.baseUrl + 'project/' + id, body)

def datesChanged = false
if (body['plannedStartDate'] || body['plannedEndDate']) {
body.timeline = null // Force a reset of the project timeline.
datesChanged = true
}

def resp = super.update(id, body)
// if (datesChanged && resp && !resp.error) {
// createReportingActivitiesForProject(id)
// }

return resp
}

/**
Expand Down
10 changes: 5 additions & 5 deletions grails-app/views/report/_announcements.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
var events = <fc:modelAsJavascript model="${events}"></fc:modelAsJavascript>;
var columns = [
{title:'Grant ID', width:'10%', render:projectUrlRenderer, data:'grantId'},
{title:'Name', width:'25%', data:'name'},
{title:'Proposed Date of event/announcement (if known)', data:'eventDate', render:dateRenderer},
{title:'State/Territory', width:'10%', data:'state'},
{title:'Electorate(s) of the Project', width:'10%', data:'electorate'},
{title:'Name of Organisation/Proponent', width:'10%', data:'organisationName'},
{title:'What programme does the announcement relate to?', width:'13%', data:'associatedProgram'},
{title:'Name', width:'25%', data:'name'},
{title:'Proposed event/annoucement', data:'eventName'},
{title:'Proposed Date of event/announcement (if known)', data:'eventDate', render:dateRenderer},
{title:'Description of the event', data:'eventDescription'},
{title:'Will there be, or do you intend there to be, media involvement in this event?', data:'media'},
{title:'MERI plan approval status', data:'planStatus'}];
{title:'MERI plan approval status', data:'planStatus'},
{title:'What programme does the announcement relate to?', width:'13%', data:'associatedProgram'},
{title:'Grant ID', width:'10%', render:projectUrlRenderer, data:'grantId'}];
$('#announcementsTable').dataTable({
Expand Down

0 comments on commit c39d1be

Please sign in to comment.