if (task != null && resource != null)
{
Duration work = task.getWork();
int percentComplete = NumberUtility.getInt(task.getPercentageComplete());
ResourceAssignment assignment = task.addResourceAssignment(resource);
assignment.setUnits(units);
assignment.setWork(work);
if (percentComplete != 0)
{
Duration actualWork = Duration.getInstance((work.getDuration() * percentComplete) / 100, work.getUnits());
assignment.setActualWork(actualWork);
assignment.setRemainingWork(Duration.getInstance(work.getDuration() - actualWork.getDuration(), work.getUnits()));
}
else
{
assignment.setRemainingWork(work);
}
assignment.setStart(task.getStart());
assignment.setFinish(task.getFinish());
tasksWithAssignments.add(task);
m_projectFile.fireAssignmentReadEvent(assignment);
}
}
//
// Adjust work per assignment for tasks with multiple assignments
//
for (Task task : tasksWithAssignments)
{
List<ResourceAssignment> assignments = task.getResourceAssignments();
if (assignments.size() > 1)
{
double maxUnits = 0;
for (ResourceAssignment assignment : assignments)
{
maxUnits += assignment.getUnits().doubleValue();
}
for (ResourceAssignment assignment : assignments)
{
Duration work = assignment.getWork();
double factor = assignment.getUnits().doubleValue() / maxUnits;
work = Duration.getInstance(work.getDuration() * factor, work.getUnits());
assignment.setWork(work);
Duration actualWork = assignment.getActualWork();
if (actualWork != null)
{
actualWork = Duration.getInstance(actualWork.getDuration() * factor, actualWork.getUnits());
assignment.setActualWork(actualWork);
}
Duration remainingWork = assignment.getRemainingWork();
if (remainingWork != null)
{
remainingWork = Duration.getInstance(remainingWork.getDuration() * factor, remainingWork.getUnits());
assignment.setRemainingWork(remainingWork);
}
}
}
}
}