//
// Retrieve data used to calculate the pro-rata work split
//
Date assignmentStart = assignment.getStart();
Date assignmentFinish = assignment.getFinish();
Duration calendarWork = calendar.getWork(assignmentStart, assignmentFinish, TimeUnit.MINUTES);
Duration assignmentWork = assignment.getTotalAmount();
if (calendarWork.getDuration() != 0)
{
//
// Split the first day
//
Date splitFinish;
double splitMinutes;
if (calendar.isWorkingDate(assignmentStart))
{
Date splitStart = assignmentStart;
Date splitFinishTime = calendar.getFinishTime(splitStart);
splitFinish = DateUtility.setTime(splitStart, splitFinishTime);
Duration calendarSplitWork = calendar.getWork(splitStart, splitFinish, TimeUnit.MINUTES);
Duration calendarWorkPerDay = calendar.getWork(splitStart, TimeUnit.MINUTES);
Duration assignmentWorkPerDay = assignment.getAmountPerDay();
Duration splitWork;
if (calendarSplitWork.getDuration() == calendarWorkPerDay.getDuration())
{
{
if (calendarSplitWork.getDuration() == assignmentWorkPerDay.getDuration())
{
splitWork = assignmentWorkPerDay;
splitMinutes = splitWork.getDuration();
}
else
{
splitMinutes = assignmentWorkPerDay.getDuration();
splitMinutes *= calendarSplitWork.getDuration();
splitMinutes /= (8 * 60); // this appears to be a fixed value
splitWork = Duration.getInstance(splitMinutes, TimeUnit.MINUTES);
}
}
}
else
{
splitMinutes = assignmentWorkPerDay.getDuration();
splitMinutes *= calendarSplitWork.getDuration();
splitMinutes /= (8 * 60); // this appears to be a fixed value
splitWork = Duration.getInstance(splitMinutes, TimeUnit.MINUTES);
}
TimephasedWork split = new TimephasedWork();
split.setStart(splitStart);
split.setFinish(splitFinish);
split.setTotalAmount(splitWork);
result[0] = split;
}
else
{
splitFinish = assignmentStart;
splitMinutes = 0;
}
//
// Split the remainder
//
Date splitStart = calendar.getNextWorkStart(splitFinish);
splitFinish = assignmentFinish;
TimephasedWork split;
if (splitStart.getTime() > splitFinish.getTime())
{
split = null;
}
else
{
splitMinutes = assignmentWork.getDuration() - splitMinutes;
Duration splitWork = Duration.getInstance(splitMinutes, TimeUnit.MINUTES);
split = new TimephasedWork();
split.setStart(splitStart);
split.setFinish(splitFinish);
split.setTotalAmount(splitWork);