use of org.compiere.model.MResource in project adempiere by adempiere.
the class DefaultRoutingServiceImpl method convertDurationToResourceUOM.
protected BigDecimal convertDurationToResourceUOM(BigDecimal duration, int S_Resource_ID, I_AD_WF_Node node) {
MResource resource = MResource.get(Env.getCtx(), S_Resource_ID);
I_AD_Workflow wf = MWorkflow.get(Env.getCtx(), node.getAD_Workflow_ID());
I_C_UOM resourceUOM = MUOM.get(Env.getCtx(), resource.getC_UOM_ID());
return convertDuration(duration, wf.getDurationUnit(), resourceUOM);
}
use of org.compiere.model.MResource in project adempiere by adempiere.
the class DefaultRoutingServiceImpl method getResourceBaseValue.
protected BigDecimal getResourceBaseValue(int S_Resource_ID, I_AD_WF_Node node, I_PP_Cost_Collector cc) {
if (node == null)
node = cc.getPP_Order_Node().getAD_WF_Node();
final Properties ctx = (node instanceof PO ? ((PO) node).getCtx() : Env.getCtx());
final MResource resource = MResource.get(ctx, S_Resource_ID);
final MUOM resourceUOM = MUOM.get(ctx, resource.getC_UOM_ID());
//
if (isTime(resourceUOM)) {
BigDecimal duration = calculateDuration(node, cc);
I_AD_Workflow wf = MWorkflow.get(ctx, node.getAD_Workflow_ID());
BigDecimal convertedDuration = convertDuration(duration, wf.getDurationUnit(), resourceUOM);
return convertedDuration;
} else {
throw new AdempiereException("@NotSupported@ @C_UOM_ID@ - " + resourceUOM);
}
}
use of org.compiere.model.MResource in project adempiere by adempiere.
the class CRP method runCRP.
public void runCRP(MPPOrder order) {
log.info("PP_Order DocumentNo:" + order.getDocumentNo());
MPPOrderWorkflow owf = order.getMPPOrderWorkflow();
if (owf == null) {
// TODO: generate notice
addLog("WARNING: No workflow found - " + order);
return;
}
log.info("PP_Order Workflow:" + owf.getName());
final ArrayList<Integer> visitedNodes = new ArrayList<Integer>();
// Schedule Fordward
if (p_ScheduleType.equals(FORWARD_SCHEDULING)) {
Timestamp date = order.getDateStartSchedule();
int nodeId = owf.getPP_Order_Node_ID();
MPPOrderNode node = null;
while (nodeId != 0) {
node = owf.getNode(nodeId);
if (visitedNodes.contains(nodeId)) {
throw new CRPException("Cyclic transition found").setPP_Order_Node(node);
}
visitedNodes.add(nodeId);
log.info("PP_Order Node:" + node.getName() != null ? node.getName() : "" + " Description:" + node.getDescription() != null ? node.getDescription() : "");
//
MResource resource = MResource.get(getCtx(), node.getS_Resource_ID());
// Skip this node if there is no resource
if (resource == null) {
nodeId = owf.getNext(nodeId, getAD_Client_ID());
continue;
}
if (!reasoner.isAvailable(resource)) {
throw new CRPException("@ResourceNotInSlotDay@").setS_Resource(resource);
}
long nodeMillis = calculateMillisFor(node, owf.getDurationBaseSec());
Timestamp dateFinish = scheduleForward(date, nodeMillis, resource);
node.setDateStartSchedule(date);
node.setDateFinishSchedule(dateFinish);
node.saveEx();
date = node.getDateFinishSchedule();
nodeId = owf.getNext(nodeId, getAD_Client_ID());
}
// Update order finish date
if (node != null && node.getDateFinishSchedule() != null) {
order.setDateFinishSchedule(node.getDateFinishSchedule());
}
} else // Schedule backward
if (p_ScheduleType.equals(BACKWARD_SCHEDULING)) {
Timestamp date = order.getDateFinishSchedule();
int nodeId = owf.getNodeLastID(getAD_Client_ID());
MPPOrderNode node = null;
while (nodeId != 0) {
node = owf.getNode(nodeId);
if (visitedNodes.contains(nodeId)) {
throw new CRPException("Cyclic transition found - ").setPP_Order_Node(node);
}
visitedNodes.add(nodeId);
log.info("PP_Order Node:" + node.getName() != null ? node.getName() : "" + " Description:" + node.getDescription() != null ? node.getDescription() : "");
//
MResource resource = MResource.get(getCtx(), node.getS_Resource_ID());
// Skip this node if there is no resource
if (resource == null) {
nodeId = owf.getPrevious(nodeId, getAD_Client_ID());
continue;
}
if (!reasoner.isAvailable(resource)) {
throw new CRPException("@ResourceNotInSlotDay@").setS_Resource(resource);
}
long nodeMillis = calculateMillisFor(node, owf.getDurationBaseSec());
Timestamp dateStart = scheduleBackward(date, nodeMillis, resource);
node.setDateStartSchedule(dateStart);
node.setDateFinishSchedule(date);
node.saveEx();
date = node.getDateStartSchedule();
nodeId = owf.getPrevious(nodeId, getAD_Client_ID());
}
// Update order start date
if (node != null && node.getDateStartSchedule() != null) {
order.setDateStartSchedule(node.getDateStartSchedule());
}
} else {
throw new CRPException("Unknown scheduling method - " + p_ScheduleType);
}
order.saveEx(get_TrxName());
}
Aggregations