Hello Support,
I’m trying to generate from scratch complete fixed duration task with 4 different resources - one resource is cost resource and rest of them are work resources with different calendars. This is how it looks like files.zip (128.4 KB) I have problems with setting resources calendar (each resource in mpp file has Standard calendar - however Im changing it). Another thing is that duration is wrong, it should have 57.6h totally - as in expected output mpp file.
Code which Im using to generate output file:
Project project = new Project("test.mpt");
project.set(Prj.START_DATE, toDate(LocalDateTime.of(2019, 1, 1, 0, 0)));
Calendar standard = project.getCalendars().add("Standard");
Calendar.makeStandardCalendar(standard);
Calendar hour24 = project.getCalendars().add("24H");
Calendar.make24HourCalendar(hour24);
Calendar nighShift = project.getCalendars().add("Night_shift");
Calendar.makeNightShiftCalendar(nighShift);
project.set(Prj.CALENDAR, hour24);
Task task1 = project.getRootTask().getChildren().add("test task");
task1.set(Tsk.IS_MANUAL, NullableBool.to_NullableBool(false));
task1.set(Tsk.TYPE, TaskType.FixedDuration);
task1.set(Tsk.DURATION, task1.getParentProject().getDuration(2, 4));
task1.set(Tsk.WORK, task1.getParentProject().getDuration(57.6, 2));
Resource cost = project.getResources().add("Fixed cost");
cost.set(Rsc.COST_PER_USE, new BigDecimal(500));
cost.set(Rsc.TYPE, ResourceType.Cost);
Resource et = project.getResources().add("ET");
et.set(Rsc.TYPE, ResourceType.Work);
et.set(Rsc.STANDARD_RATE, toBigDecimal(125d));
et.set(Rsc.OVERTIME_RATE, toBigDecimal(1d));
Calendar cal1 = project.getCalendars().add(et.get(Rsc.NAME));
cal1.setBaseCalendar(nighShift);
cal1.setBaselineCalendar(true);
et.set(Rsc.CALENDAR, cal1);
Resource projEng = project.getResources().add("Project Engineer");
projEng.set(Rsc.TYPE, ResourceType.Work);
projEng.set(Rsc.STANDARD_RATE, toBigDecimal(150d));
projEng.set(Rsc.OVERTIME_RATE, toBigDecimal(1d));
Calendar cal2 = project.getCalendars().add(projEng.get(Rsc.NAME));
cal2.setBaseCalendar(hour24);
cal2.setBaselineCalendar(true);
projEng.set(Rsc.CALENDAR, cal2);
Resource projMan = project.getResources().add("Project Manager");
projMan.set(Rsc.TYPE, ResourceType.Work);
projMan.set(Rsc.STANDARD_RATE, toBigDecimal(200d));
projMan.set(Rsc.OVERTIME_RATE, toBigDecimal(1d));
Calendar cal3 = project.getCalendars().add(projMan.get(Rsc.NAME));
cal3.setBaseCalendar(hour24);
cal3.setBaselineCalendar(true);
projMan.set(Rsc.CALENDAR, cal3);
ResourceAssignment etAssn = project.getResourceAssignments().add(task1, et);
etAssn.set(Asn.UNITS, 2d);
ResourceAssignment projManAssn = project.getResourceAssignments().add(task1, projMan);
projManAssn.set(Asn.UNITS, 0.2d);
ResourceAssignment projEngAssn = project.getResourceAssignments().add(task1, projEng);
projEngAssn.set(Asn.UNITS, 0.2d);
ResourceAssignment assn = project.getResourceAssignments().add(task1, cost);
assn.set(Asn.UNITS, 1d);
project.save("output.mpp", SaveFileFormat.MPP);
Could you please help me with achieve the same result as shown in expected ouput mpp file programatically?
@dusinski,
I have worked with sample code shared by you. The code snippet you have shared includes some undeclared variables so would you please share SSCCE complete working sample code so that we may try to further investigate to help you out.
Im very sorry, I forgot to remove utils form code, this is code:
Project project = new Project("test.mpt");
project.set(Prj.START_DATE, Date.from(LocalDateTime.of(2019, 1, 1, 0, 0).atZone(ZoneId.systemDefault()).toInstant()));
Calendar standard = project.getCalendars().add("Standard");
Calendar.makeStandardCalendar(standard);
Calendar hour24 = project.getCalendars().add("24H");
Calendar.make24HourCalendar(hour24);
Calendar nighShift = project.getCalendars().add("Night_shift");
Calendar.makeNightShiftCalendar(nighShift);
project.set(Prj.CALENDAR, hour24);
Task task1 = project.getRootTask().getChildren().add("test task");
task1.set(Tsk.IS_MANUAL, NullableBool.to_NullableBool(false));
task1.set(Tsk.TYPE, TaskType.FixedDuration);
task1.set(Tsk.DURATION, task1.getParentProject().getDuration(2, 4));
task1.set(Tsk.WORK, task1.getParentProject().getDuration(57.6, 2));
Resource cost = project.getResources().add("Fixed cost");
cost.set(Rsc.COST_PER_USE, new BigDecimal(500));
cost.set(Rsc.TYPE, ResourceType.Cost);
Resource et = project.getResources().add("ET");
et.set(Rsc.TYPE, ResourceType.Work);
et.set(Rsc.STANDARD_RATE, new BigDecimal("125"));
et.set(Rsc.OVERTIME_RATE, new BigDecimal("1"));
Calendar cal1 = project.getCalendars().add(et.get(Rsc.NAME));
cal1.setBaseCalendar(nighShift);
cal1.setBaselineCalendar(true);
et.set(Rsc.CALENDAR, cal1);
Resource projEng = project.getResources().add("Project Engineer");
projEng.set(Rsc.TYPE, ResourceType.Work);
projEng.set(Rsc.STANDARD_RATE, new BigDecimal("150"));
projEng.set(Rsc.OVERTIME_RATE, new BigDecimal("1"));
Calendar cal2 = project.getCalendars().add(projEng.get(Rsc.NAME));
cal2.setBaseCalendar(hour24);
cal2.setBaselineCalendar(true);
projEng.set(Rsc.CALENDAR, cal2);
Resource projMan = project.getResources().add("Project Manager");
projMan.set(Rsc.TYPE, ResourceType.Work);
projMan.set(Rsc.STANDARD_RATE, new BigDecimal("200"));
projMan.set(Rsc.OVERTIME_RATE, new BigDecimal("1"));
Calendar cal3 = project.getCalendars().add(projMan.get(Rsc.NAME));
cal3.setBaseCalendar(hour24);
cal3.setBaselineCalendar(true);
projMan.set(Rsc.CALENDAR, cal3);
ResourceAssignment etAssn = project.getResourceAssignments().add(task1, et);
etAssn.set(Asn.UNITS, 2d);
ResourceAssignment projManAssn = project.getResourceAssignments().add(task1, projMan);
projManAssn.set(Asn.UNITS, 0.2d);
ResourceAssignment projEngAssn = project.getResourceAssignments().add(task1, projEng);
projEngAssn.set(Asn.UNITS, 0.2d);
ResourceAssignment assn = project.getResourceAssignments().add(task1, cost);
assn.set(Asn.UNITS, 1d);
project.save("output.mpp", SaveFileFormat.MPP);
I also notice that fixed cost is not shown properly when Im setting project calendar, there must be something wrong in my logic.
@dusinski,
I have worked with source file and sample code shared by you and have been able to observe issue. An issue with ID TASKSJAVA-894 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.
1 Like
Hello @Adnan.Ahmad,
Could you please provide me url to issue TASKSJAVA-894. I would like to find out what is current status of this issue. Thank you.
@dusinski,
Unfortunately, we can only provide the issue ID and you can check the status from bottom of this page where issue is linked with this thread. The issue tracking system is internal and is only for Aspose staff.
1 Like
Is there any update on this issue? I found out that when you save file as xml format and then import xml in microsoft project resource calendard will be set properly. So there must be for sure bug with saving file with mpp extension.
@dusinski,
I regret to share that at present the issue is still unresolved. We request for your patience till the time the issue gets resolved.