Java Code Examples for net.sf.mpxj.Task#setRemainingCost()

The following examples show how to use net.sf.mpxj.Task#setRemainingCost() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrimaveraReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * See the notes above.
 *
 * @param parentTask parent task
 */
private void updateTaskCosts(Task parentTask)
{
   double baselineCost = 0;
   double actualCost = 0;
   double remainingCost = 0;
   double cost = 0;

   //process children first before adding their costs
   for (Task child : parentTask.getChildTasks())
   {
      updateTaskCosts(child);
      baselineCost += NumberHelper.getDouble(child.getBaselineCost());
      actualCost += NumberHelper.getDouble(child.getActualCost());
      remainingCost += NumberHelper.getDouble(child.getRemainingCost());
      cost += NumberHelper.getDouble(child.getCost());
   }

   List<ResourceAssignment> resourceAssignments = parentTask.getResourceAssignments();
   for (ResourceAssignment assignment : resourceAssignments)
   {
      baselineCost += NumberHelper.getDouble(assignment.getBaselineCost());
      actualCost += NumberHelper.getDouble(assignment.getActualCost());
      remainingCost += NumberHelper.getDouble(assignment.getRemainingCost());
      cost += NumberHelper.getDouble(assignment.getCost());
   }

   parentTask.setBaselineCost(NumberHelper.getDouble(baselineCost));
   parentTask.setActualCost(NumberHelper.getDouble(actualCost));
   parentTask.setRemainingCost(NumberHelper.getDouble(remainingCost));
   parentTask.setCost(NumberHelper.getDouble(cost));
}
 
Example 2
Source File: PrimaveraPMFileReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Process resource assignments.
 *
 * @param project xml container
 */
private void processAssignments(ProjectType project)
{
   List<ResourceAssignmentType> assignments = project.getResourceAssignment();
   for (ResourceAssignmentType row : assignments)
   {
      Task task = m_projectFile.getTaskByUniqueID(mapTaskID(row.getActivityObjectId()));
      Resource resource = m_projectFile.getResourceByUniqueID(row.getResourceObjectId());
      if (task != null && resource != null)
      {
         ResourceAssignment assignment = task.addResourceAssignment(resource);

         assignment.setUniqueID(row.getObjectId());
         assignment.setRemainingWork(getDuration(row.getRemainingUnits()));
         assignment.setBaselineWork(getDuration(row.getPlannedUnits()));
         assignment.setActualWork(getDuration(row.getActualUnits()));
         assignment.setRemainingCost(row.getRemainingCost());
         assignment.setBaselineCost(row.getPlannedCost());
         assignment.setActualCost(row.getActualCost());
         assignment.setActualStart(row.getActualStartDate());
         assignment.setActualFinish(row.getActualFinishDate());
         assignment.setBaselineStart(row.getPlannedStartDate());
         assignment.setBaselineFinish(row.getPlannedFinishDate());
         assignment.setGUID(DatatypeConverter.parseUUID(row.getGUID()));

         task.setActualCost(Double.valueOf(NumberHelper.getDouble(task.getActualCost()) + NumberHelper.getDouble(assignment.getActualCost())));
         task.setRemainingCost(Double.valueOf(NumberHelper.getDouble(task.getRemainingCost()) + NumberHelper.getDouble(assignment.getRemainingCost())));
         task.setBaselineCost(Double.valueOf(NumberHelper.getDouble(task.getBaselineCost()) + NumberHelper.getDouble(assignment.getBaselineCost())));

         populateField(assignment, AssignmentField.WORK, AssignmentField.ACTUAL_WORK, AssignmentField.BASELINE_WORK);
         populateField(assignment, AssignmentField.COST, AssignmentField.ACTUAL_COST, AssignmentField.BASELINE_COST);
         populateField(assignment, AssignmentField.START, AssignmentField.ACTUAL_START, AssignmentField.BASELINE_START);
         populateField(assignment, AssignmentField.FINISH, AssignmentField.ACTUAL_FINISH, AssignmentField.BASELINE_FINISH);

         readUDFTypes(assignment, row.getUDF());

         m_eventManager.fireAssignmentReadEvent(assignment);
      }
   }
}
 
Example 3
Source File: ProgressRecord.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override public void process(Context context)
{
   Double totalCost = getDouble(4);
   Double costToDate = getDouble(5);
   Double remainingCost = Double.valueOf(NumberHelper.getDouble(totalCost) - NumberHelper.getDouble(costToDate));
   Duration totalFloat = getDuration(12);
   if ("-".equals(getString(11)))
   {
      totalFloat = Duration.getInstance(-totalFloat.getDuration(), TimeUnit.DAYS);
   }

   Task task = context.getTask(getString(0));
   task.setActualStart(getDate(1));
   task.setActualFinish(getDate(2));
   task.setRemainingDuration(getDuration(3));
   task.setCost(getDouble(4));
   task.setRemainingCost(remainingCost);
   task.setCost(1, getDouble(6));
   task.setEarlyStart(getDate(7));
   task.setEarlyFinish(getDate(8));
   task.setLateStart(getDate(9));
   task.setLateFinish(getDate(10));
   task.setTotalSlack(totalFloat);

   Date start = task.getActualStart() == null ? task.getEarlyStart() : task.getActualStart();
   Date finish = task.getActualFinish() == null ? task.getEarlyFinish() : task.getActualFinish();
   double percentComplete = 0;

   if (task.getActualFinish() == null)
   {
      Duration duration = task.getDuration();
      Duration remainingDuration = task.getRemainingDuration();
      if (duration != null && remainingDuration != null)
      {
         double durationValue = duration.getDuration();
         double remainingDurationValue = remainingDuration.getDuration();
         if (durationValue != 0 && remainingDurationValue < durationValue)
         {
            percentComplete = ((durationValue - remainingDurationValue) * 100.0) / durationValue;
         }
      }
   }
   else
   {
      percentComplete = 100.0;
   }

   task.setStart(start);
   task.setFinish(finish);
   task.setPercentageComplete(Double.valueOf(percentComplete));
}