ASPOSE.Tasks Populating Day Cost

How do I set daily cost for the details associated to the Resource in the Task Usage view? See attached image for additional information.

Thanks.

Craig

Hi Craig,

Thank you for contacting Aspose Support team.

The cost value is calculated after you set the standard rate of a resource. Please try the following code sample at your end and let us know your feedback.

Sample Code:

Project project = new Project("New Project 2010.mpp");

project.Set(Prj.StartDate, new DateTime(2016, 4, 22, 8, 0, 0));

project.Set(Prj.NewTasksAreManual, false);

Task task = project.RootTask.Children.Add("Task");

Resource rsc = project.Resources.Add("Rsc");

rsc.Set(Rsc.StandardRate, 10);


// 6 days duration

task.Set(Tsk.Duration, project.GetDuration(6));

ResourceAssignment assn = project.ResourceAssignments.Add(task, rsc);

Console.WriteLine("Assignment cost = " + assn.Get(Asn.Cost));

project.Save( "Output.mpp", SaveFileFormat.MPP);

Let me provide some more detail. I have tasks and resources in the Project file. I am looping through the TimephasedData and obtaining daily cost from an external source for the Task Resources and associated units. I need to set that cost back to the resource for the day that it was costed so that the Detail View on the Task Usage Grid is populate with Units and Cost.

Hi Craig,

Cost cannot be assigned directly. You need to set the rate tables of each resource in order to set the daily cost of the resource. Following is a sample code which changes the rates on different days for a resource. When we open the task usage, we can see the new cost according to the rates set on specific dates. Please give it a try and share the feedback.

String path = url + “Tasks_715764\”;<o:p></o:p>
Project proj = new Project(path + "Project2.mpp");
Resource res1 = proj.Resources.GetByUid(1);

Rate rate1 = res1.Rates.Add(new DateTime(2016, 5, 2, 8, 0, 0));
rate1.RatesTo = new DateTime(2016, 5, 4, 8, 0, 0);
rate1.StandardRate = 6;
rate1.RateTable = RateType.A;

Rate rate2 = res1.Rates.Add(new DateTime(2016, 5, 4, 8, 0, 0));
rate2.RatesTo = new DateTime(2016, 5, 30, 8, 0, 0);
rate2.StandardRate = 4;
rate2.RateTable = RateType.A;

proj.Save(path + "Project2.mpp",SaveFileFormat.MPP);