use of org.compiere.model.MResourceType in project adempiere by adempiere.
the class DefaultRoutingServiceImplTest method getCreatePlant.
private I_S_Resource getCreatePlant() {
final String plantValue = "JUnit_Plant_24x7";
MResource plant = new Query(getCtx(), MResource.Table_Name, "Value=?", null).setParameters(new Object[] { plantValue }).setClient_ID().firstOnly();
if (plant == null) {
plant = new MResource(getCtx(), 0, null);
plant.setValue(plantValue);
}
plant.setName(plantValue);
plant.setIsManufacturingResource(true);
plant.setManufacturingResourceType(MResource.MANUFACTURINGRESOURCETYPE_Plant);
plant.setPlanningHorizon(365);
plant.setM_Warehouse_ID(getM_Warehouse_ID());
//
MResourceType rt = null;
if (plant.getS_ResourceType_ID() <= 0) {
rt = new MResourceType(getCtx(), 0, null);
} else {
rt = new MResourceType(getCtx(), plant.getS_ResourceType_ID(), null);
}
rt.setValue(plantValue);
rt.setName(plantValue);
rt.setAllowUoMFractions(true);
rt.setC_TaxCategory_ID(getC_TaxCategory_ID());
rt.setM_Product_Category_ID(getM_Product_Category_ID());
// Hour
rt.setC_UOM_ID(getC_UOM_ID("HR"));
rt.setIsDateSlot(false);
rt.setIsTimeSlot(false);
rt.setIsSingleAssignment(false);
rt.saveEx();
plant.setS_ResourceType_ID(rt.getS_ResourceType_ID());
//
plant.saveEx();
return plant;
}
use of org.compiere.model.MResourceType in project adempiere by adempiere.
the class DefaultRoutingServiceImpl method calculateDuration.
public BigDecimal calculateDuration(I_AD_Workflow wf, I_S_Resource plant, BigDecimal qty) {
if (plant == null)
return Env.ZERO;
final Properties ctx = ((PO) wf).getCtx();
final MResourceType S_ResourceType = MResourceType.get(ctx, plant.getS_ResourceType_ID());
BigDecimal AvailableDayTime = new BigDecimal(S_ResourceType.getTimeSlotHours());
int AvailableDays = S_ResourceType.getAvailableDaysWeek();
double durationBaseSec = getDurationBaseSec(wf.getDurationUnit());
double durationTotal = 0.0;
MWFNode[] nodes = ((MWorkflow) wf).getNodes(false, Env.getAD_Client_ID(ctx));
for (I_AD_WF_Node node : nodes) {
// Qty independent times:
durationTotal += node.getQueuingTime();
durationTotal += node.getSetupTime();
durationTotal += node.getWaitingTime();
durationTotal += node.getMovingTime();
// Get OverlapUnits - number of units that must be completed before they are moved the next activity
double overlapUnits = qty.doubleValue();
if (node.getOverlapUnits() > 0 && node.getOverlapUnits() < overlapUnits) {
overlapUnits = node.getOverlapUnits();
}
double durationBeforeOverlap = node.getDuration() * overlapUnits;
durationTotal += durationBeforeOverlap;
}
BigDecimal requiredTime = BigDecimal.valueOf(durationTotal * durationBaseSec / 60 / 60);
// TODO: implement here, Victor's suggestion - https://sourceforge.net/forum/message.php?msg_id=5179460
// Weekly Factor
BigDecimal WeeklyFactor = new BigDecimal(7).divide(new BigDecimal(AvailableDays), 8, RoundingMode.UP);
return (requiredTime.multiply(WeeklyFactor)).divide(AvailableDayTime, 0, RoundingMode.UP);
}
Aggregations