Ejemplo n.º 1
0
  public void createRateVariances(MPPCostCollector cc) {
    final I_M_Product product;
    if (cc.isCostCollectorType(X_PP_Cost_Collector.COSTCOLLECTORTYPE_ActivityControl)) {
      final I_AD_WF_Node node = cc.getPP_Order_Node().getAD_WF_Node();
      product = MProduct.forS_Resource_ID(cc.getCtx(), node.getS_Resource_ID(), null);
    } else if (cc.isCostCollectorType(X_PP_Cost_Collector.COSTCOLLECTORTYPE_ComponentIssue)) {
      final I_PP_Order_BOMLine bomLine = cc.getPP_Order_BOMLine();
      product = MProduct.get(cc.getCtx(), bomLine.getM_Product_ID());
    } else {
      return;
    }

    I_PP_Cost_Collector ccrv = null; // Cost Collector - Rate Variance
    for (MAcctSchema as : getAcctSchema(cc)) {
      for (I_M_CostElement element : getCostElements(cc.getCtx())) {
        final MCostDetail cd = getCostDetail(cc, element.getM_CostElement_ID());
        if (cd == null) {
          continue;
        }

        //
        final BigDecimal qty = cd.getQty();
        final BigDecimal priceStd = getProductStandardCostPrice(cc, product, as, element);
        final BigDecimal priceActual =
            getProductActualCostPriceOrZero(cc, product, as, element, cc.get_TrxName());
        final BigDecimal amtStd = roundCost(priceStd.multiply(qty), as.getC_AcctSchema_ID());
        final BigDecimal amtActual = roundCost(priceActual.multiply(qty), as.getC_AcctSchema_ID());
        if (amtStd.compareTo(amtActual) == 0) {
          continue;
        }

        //
        if (ccrv == null) {
          ccrv =
              createVarianceCostCollector(cc, X_PP_Cost_Collector.COSTCOLLECTORTYPE_RateVariance);
        }
        //
        createVarianceCostDetail(ccrv, amtActual.negate(), qty.negate(), cd, null, as, element);
        createVarianceCostDetail(ccrv, amtStd, qty, cd, null, as, element);
      }
    }
    //
    if (ccrv != null) {
      Services.get(IDocActionBL.class)
          .processEx(ccrv, DocAction.ACTION_Complete, DocAction.STATUS_Completed);
    }
  }
Ejemplo n.º 2
0
  public I_AD_WF_Node createWorkflowNode(
      final I_AD_Workflow wf, final String nodeName, final boolean startNode) {
    final I_AD_WF_Node node =
        InterfaceWrapperHelper.newInstance(I_AD_WF_Node.class, contextProvider);
    node.setAD_Workflow_ID(wf.getAD_Workflow_ID());
    node.setValue(nodeName);
    node.setName(nodeName);

    InterfaceWrapperHelper.save(node);

    if (startNode) {
      wf.setAD_WF_Node_ID(node.getAD_WF_Node_ID());
      InterfaceWrapperHelper.save(wf);
    }

    return node;
  }