use of org.compiere.wf.MWFNode in project adempiere by adempiere.
the class WFPanel method start.
// actionPerformed
/**************************************************************************
* Start Node
* @param node node
*/
public void start(WFNode node) {
log.fine("Node=" + node);
MWFNode model = node.getModel();
// Info Text
StringBuffer msg = new StringBuffer("<HTML>");
msg.append("<H2>").append(model.getName(true)).append("</H2>");
String s = model.getDescription(true);
if (s != null && s.length() > 0)
msg.append("<B>").append(s).append("</B>");
s = model.getHelp(true);
if (s != null && s.length() > 0)
msg.append("<BR>").append(s);
msg.append("</HTML>");
infoTextPane.setText(msg.toString());
infoTextPane.setCaretPosition(0);
// Load Window
if (m_menu != null)
// async load
(new AMenuStartItem(model.getAD_WF_Node_ID(), false, model.getName(true), m_menu)).start();
//
m_activeNode = node;
//
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
boolean first = m_wf.isFirst(m_activeNode.getAD_WF_Node_ID(), AD_Client_ID);
boolean last = m_wf.isLast(m_activeNode.getAD_WF_Node_ID(), AD_Client_ID);
wfStart.setEnabled(!first);
wfBack.setEnabled(!first);
wfNext.setEnabled(!last);
wfEnd.setEnabled(!last);
}
use of org.compiere.wf.MWFNode in project adempiere by adempiere.
the class WFPanel method load.
// load
/**
* Load Workflow & Nodes
* @param AD_Workflow_ID ID
* @param readWrite if true nodes can be moved
*/
public void load(int AD_Workflow_ID, boolean readWrite) {
log.fine("RW=" + readWrite + " - AD_Workflow_ID=" + AD_Workflow_ID);
if (AD_Workflow_ID == 0)
return;
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
// Get Workflow
m_wf = new MWorkflow(Env.getCtx(), AD_Workflow_ID, null);
centerPanel.removeAll();
centerPanel.setReadWrite(readWrite);
if (readWrite)
centerPanel.setWorkflow(m_wf);
// Add Nodes for Paint
MWFNode[] nodes = m_wf.getNodes(true, AD_Client_ID);
for (int i = 0; i < nodes.length; i++) {
WFNode wfn = new WFNode(nodes[i]);
wfn.addPropertyChangeListener(WFNode.PROPERTY_SELECTED, this);
boolean rw = // in editor mode & owned
readWrite && (AD_Client_ID == nodes[i].getAD_Client_ID());
centerPanel.add(wfn, rw);
// Add Lines
MWFNodeNext[] nexts = nodes[i].getTransitions(AD_Client_ID);
for (int j = 0; j < nexts.length; j++) centerPanel.add(new WFLine(nexts[j]), false);
}
// Info Text
StringBuffer msg = new StringBuffer("<HTML>");
msg.append("<H2>").append(m_wf.getName(true)).append("</H2>");
String s = m_wf.getDescription(true);
if (s != null && s.length() > 0)
msg.append("<B>").append(s).append("</B>");
s = m_wf.getHelp(true);
if (s != null && s.length() > 0)
msg.append("<BR>").append(s);
msg.append("</HTML>");
infoTextPane.setText(msg.toString());
infoTextPane.setCaretPosition(0);
// Layout
centerPanel.validate();
centerPanel.repaint();
validate();
}
use of org.compiere.wf.MWFNode in project adempiere by adempiere.
the class RollupWorkflow method rollup.
/**
* Execute rollup process
* @param accountSchema
* @param costType
* @param costElement
* @param product
* @param workflow
* @param trxName
*/
protected void rollup(MAcctSchema accountSchema, MCostType costType, MCostElement costElement, MProduct product, MWorkflow workflow, String trxName) {
log.info("Workflow: " + workflow);
workflow.setCost(Env.ZERO);
double yield = 1;
int queuingTime = 0;
int setupTime = 0;
int duration = 0;
int waitingTime = 0;
int movingTime = 0;
int workingTime = 0;
MWFNode[] nodes = workflow.getNodes(false, getAD_Client_ID());
for (MWFNode node : nodes) {
node.setCost(Env.ZERO);
if (node.getYield() != 0) {
yield = yield * ((double) node.getYield() / 100);
}
// We use node.getDuration() instead of m_routingService.estimateWorkingTime(node) because
// this will be the minimum duration of this node. So even if the node have defined units/cycle
// we consider entire duration of the node.
long nodeDuration = node.getDuration();
queuingTime += node.getQueuingTime();
setupTime += node.getSetupTime();
duration += nodeDuration;
waitingTime += node.getWaitingTime();
movingTime += node.getMovingTime();
workingTime += node.getWorkingTime();
}
workflow.setCost(Env.ZERO);
workflow.setYield((int) (yield * 100));
workflow.setQueuingTime(queuingTime);
workflow.setSetupTime(setupTime);
workflow.setDuration(duration);
workflow.setWaitingTime(waitingTime);
workflow.setMovingTime(movingTime);
workflow.setWorkingTime(workingTime);
final CostDimension costDimension = new CostDimension(product, accountSchema, costType.getM_CostType_ID(), getOrganizationId(), getWarehouseId(), 0, costElement.get_ID());
MCost cost = MCost.getOrCreate(product, 0, accountSchema, getOrganizationId(), getWarehouseId(), costType.getM_CostType_ID(), costElement.getM_CostElement_ID());
cost.setFutureCostPrice(BigDecimal.ZERO);
if (!cost.isCostFrozen())
cost.setCurrentCostPrice(BigDecimal.ZERO);
AtomicReference<BigDecimal> segmentCost = new AtomicReference<>(Env.ZERO);
Arrays.stream(nodes).filter(node -> node != null).forEach(node -> {
final CostEngine costEngine = CostEngineFactory.getCostEngine(node.getAD_Client_ID());
final BigDecimal rate = StandardCostingMethod.getResourceActualCostRate(node.getS_Resource_ID(), costDimension, trxName);
final BigDecimal baseValue = routingService.getResourceBaseValue(node.getS_Resource_ID(), node);
BigDecimal nodeCostPrecision = baseValue.multiply(rate);
BigDecimal nodeCost;
if (nodeCostPrecision.scale() > accountSchema.getCostingPrecision())
nodeCost = nodeCostPrecision.setScale(accountSchema.getCostingPrecision(), RoundingMode.HALF_UP);
else
nodeCost = nodeCostPrecision;
segmentCost.updateAndGet(costAmt -> costAmt.add(nodeCost));
log.info(Msg.parseTranslation(getCtx(), " @M_CostElement_ID@ : ") + costElement.getName() + ", Node=" + node + ", BaseValue=" + baseValue + ", rate=" + rate + ", nodeCost=" + nodeCost + " => Cost=" + segmentCost);
node.setCost(node.getCost().add(nodeCost));
});
cost.setFutureCostPrice(segmentCost.get());
if (!cost.isCostFrozen())
cost.setCurrentCostPrice(segmentCost.get());
cost.saveEx();
// Update Workflow cost
workflow.setCost(workflow.getCost().add(segmentCost.get()));
// Save Workflow & Nodes
Arrays.stream(nodes).filter(node -> node != null).forEach(node -> node.saveEx());
workflow.saveEx();
log.info("Product: " + product.getName() + " WFCost: " + workflow.getCost());
}
use of org.compiere.wf.MWFNode in project adempiere by adempiere.
the class DefaultRoutingServiceImplTest method createNode.
private MWFNode createNode(MWorkflow wf, String value, int setupTime, int duration, int unitsCycles, int overlapUnits) {
if (value == null) {
value = "" + System.currentTimeMillis();
}
MWFNode node = new MWFNode(wf, value, value);
node.setSetupTime(setupTime);
node.setDuration(duration);
node.setUnitsCycles(BigDecimal.valueOf(unitsCycles));
node.setOverlapUnits(overlapUnits);
//
node.saveEx();
return node;
}
use of org.compiere.wf.MWFNode in project adempiere by adempiere.
the class MPPOrder method explotion.
/**
* Create PP_Order_BOM from PP_Product_BOM.
* Create PP_Order_Workflow from AD_Workflow.
*/
private void explotion() {
// Create BOM Head
final MPPProductBOM PP_Product_BOM = MPPProductBOM.get(getCtx(), getPP_Product_BOM_ID());
// Product from Order should be same as product from BOM - teo_sarca [ 2817870 ]
if (getM_Product_ID() != PP_Product_BOM.getM_Product_ID()) {
throw new AdempiereException("@NotMatch@ @PP_Product_BOM_ID@ , @M_Product_ID@");
}
// Product BOM Configuration should be verified - teo_sarca [ 2817870 ]
final MProduct product = MProduct.get(getCtx(), PP_Product_BOM.getM_Product_ID());
if (!product.isVerified()) {
// TODO: translate
throw new AdempiereException("Product BOM Configuration not verified. Please verify the product first - " + product.getValue());
}
if (PP_Product_BOM.isValidFromTo(getDateStartSchedule())) {
MPPOrderBOM PP_Order_BOM = new MPPOrderBOM(PP_Product_BOM, getPP_Order_ID(), get_TrxName());
PP_Order_BOM.setAD_Org_ID(getAD_Org_ID());
PP_Order_BOM.saveEx();
for (MPPProductBOMLine PP_Product_BOMline : PP_Product_BOM.getLines(true)) {
if (PP_Product_BOMline.isValidFromTo(getDateStartSchedule())) {
MPPOrderBOMLine PP_Order_BOMLine = new MPPOrderBOMLine(PP_Product_BOMline, getPP_Order_ID(), PP_Order_BOM.get_ID(), getM_Warehouse_ID(), get_TrxName());
PP_Order_BOMLine.setAD_Org_ID(getAD_Org_ID());
PP_Order_BOMLine.setM_Warehouse_ID(getM_Warehouse_ID());
PP_Order_BOMLine.setM_Locator_ID(getM_Locator_ID());
PP_Order_BOMLine.setQtyOrdered(getQtyOrdered());
PP_Order_BOMLine.saveEx();
} else // end if valid From / To
{
log.fine("BOM Line skiped - " + PP_Product_BOMline);
}
}
// end Create Order BOM
} else // end if From / To parent
{
throw new BOMExpiredException(PP_Product_BOM, getDateStartSchedule());
}
// Create Workflow (Routing & Process)
final MWorkflow AD_Workflow = MWorkflow.get(getCtx(), getAD_Workflow_ID());
// Workflow should be validated first - teo_sarca [ 2817870 ]
if (!AD_Workflow.isValid()) {
// TODO: translate
throw new AdempiereException("Routing is not valid. Please validate it first - " + AD_Workflow.getValue());
}
if (AD_Workflow.isValidFromTo(getDateStartSchedule())) {
MPPOrderWorkflow PP_Order_Workflow = new MPPOrderWorkflow(AD_Workflow, get_ID(), get_TrxName());
PP_Order_Workflow.setAD_Org_ID(getAD_Org_ID());
PP_Order_Workflow.saveEx();
for (MWFNode AD_WF_Node : AD_Workflow.getNodes(false, getAD_Client_ID())) {
if (AD_WF_Node.isValidFromTo(getDateStartSchedule())) {
MPPOrderNode PP_Order_Node = new MPPOrderNode(AD_WF_Node, PP_Order_Workflow, getQtyOrdered(), get_TrxName());
PP_Order_Node.setAD_Org_ID(getAD_Org_ID());
PP_Order_Node.saveEx();
for (MWFNodeNext AD_WF_NodeNext : AD_WF_Node.getTransitions(getAD_Client_ID())) {
MPPOrderNodeNext nodenext = new MPPOrderNodeNext(AD_WF_NodeNext, PP_Order_Node);
nodenext.setAD_Org_ID(getAD_Org_ID());
nodenext.saveEx();
}
for (MPPWFNodeProduct wfnp : MPPWFNodeProduct.forAD_WF_Node_ID(getCtx(), AD_WF_Node.get_ID())) {
MPPOrderNodeProduct nodeOrderProduct = new MPPOrderNodeProduct(wfnp, PP_Order_Node);
nodeOrderProduct.setAD_Org_ID(getAD_Org_ID());
nodeOrderProduct.saveEx();
}
for (MPPWFNodeAsset wfna : MPPWFNodeAsset.forAD_WF_Node_ID(getCtx(), AD_WF_Node.get_ID())) {
MPPOrderNodeAsset nodeorderasset = new MPPOrderNodeAsset(wfna, PP_Order_Node);
nodeorderasset.setAD_Org_ID(getAD_Org_ID());
nodeorderasset.saveEx();
}
}
// for node
}
// Update transitions nexts and set first node
// requery
PP_Order_Workflow.getNodes(true);
for (MPPOrderNode orderNode : PP_Order_Workflow.getNodes(false, getAD_Client_ID())) {
// set workflow start node
if (PP_Order_Workflow.getAD_WF_Node_ID() == orderNode.getAD_WF_Node_ID()) {
PP_Order_Workflow.setPP_Order_Node_ID(orderNode.getPP_Order_Node_ID());
}
// set node next
for (MPPOrderNodeNext next : orderNode.getTransitions(getAD_Client_ID())) {
next.setPP_Order_Next_ID();
next.saveEx();
}
}
PP_Order_Workflow.saveEx();
} else // workflow valid from/to
{
throw new RoutingExpiredException(AD_Workflow, getDateStartSchedule());
}
}
Aggregations