예제 #1
0
 /**
  * Create & Proce Cost Detail for Variances
  *
  * @param ccv
  * @param amt
  * @param qty
  * @param cd (optional)
  * @param product
  * @param as
  * @param element
  * @return
  */
 private MCostDetail createVarianceCostDetail(
     I_PP_Cost_Collector ccv,
     BigDecimal amt,
     BigDecimal qty,
     MCostDetail cd,
     I_M_Product product,
     I_C_AcctSchema as,
     I_M_CostElement element) {
   final Properties ctx = InterfaceWrapperHelper.getCtx(ccv);
   final String trxName = InterfaceWrapperHelper.getTrxName(ccv);
   final MCostDetail cdv = new MCostDetail(ctx, 0, trxName);
   if (cd != null) {
     MCostDetail.copyValues(cd, cdv);
     cdv.setProcessed(false);
   }
   if (product != null) {
     cdv.setM_Product_ID(product.getM_Product_ID());
     cdv.setM_AttributeSetInstance_ID(0);
   }
   if (as != null) {
     cdv.setC_AcctSchema_ID(as.getC_AcctSchema_ID());
   }
   if (element != null) {
     cdv.setM_CostElement_ID(element.getM_CostElement_ID());
   }
   //
   cdv.setPP_Cost_Collector_ID(ccv.getPP_Cost_Collector_ID());
   cdv.setAmt(amt);
   cdv.setQty(qty);
   cdv.saveEx();
   processCostDetail(cdv);
   return cdv;
 }
예제 #2
0
  public BigDecimal getProductStandardCostPrice(
      I_PP_Cost_Collector cc, I_M_Product product, I_C_AcctSchema as, I_M_CostElement element) {
    final String trxName = InterfaceWrapperHelper.getTrxName(cc);

    final CostDimension d =
        new CostDimension(
            product,
            as,
            as.getM_CostType_ID(),
            0, // AD_Org_ID,
            0, // M_ASI_ID,
            element.getM_CostElement_ID());

    final I_PP_Order_Cost oc =
        d.toQueryBuilder(I_PP_Order_Cost.class, trxName)
            .addEqualsFilter(I_PP_Order_Cost.COLUMNNAME_PP_Order_ID, cc.getPP_Order_ID())
            .create()
            .firstOnly(I_PP_Order_Cost.class);
    if (oc == null) {
      return BigDecimal.ZERO;
    }

    final BigDecimal costs = oc.getCurrentCostPrice().add(oc.getCurrentCostPriceLL());
    return roundCost(costs, as.getC_AcctSchema_ID());
  }
예제 #3
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);
    }
  }
예제 #4
0
 public void createActivityControl(MPPCostCollector cc) {
   if (!cc.isCostCollectorType(X_PP_Cost_Collector.COSTCOLLECTORTYPE_ActivityControl)) return;
   //
   final I_M_Product product = MProduct.forS_Resource_ID(cc.getCtx(), cc.getS_Resource_ID(), null);
   final RoutingService routingService =
       RoutingServiceFactory.get().getRoutingService(cc.getAD_Client_ID());
   final BigDecimal qty = routingService.getResourceBaseValue(cc.getS_Resource_ID(), cc);
   for (MAcctSchema as : getAcctSchema(cc)) {
     for (I_M_CostElement element : getCostElements(cc.getCtx())) {
       if (!isActivityControlElement(element)) {
         continue;
       }
       final CostDimension d =
           new CostDimension(
               product,
               as,
               as.getM_CostType_ID(),
               0, // AD_Org_ID,
               0, // M_ASI_ID
               element.getM_CostElement_ID());
       final BigDecimal price =
           getResourceActualCostRate(cc, cc.getS_Resource_ID(), d, cc.get_TrxName());
       BigDecimal costs = price.multiply(qty);
       if (costs.scale() > as.getCostingPrecision())
         costs = costs.setScale(as.getCostingPrecision(), RoundingMode.HALF_UP);
       //
       MCostDetail cd =
           new MCostDetail(
               as,
               0, // AD_Org_ID,
               d.getM_Product_ID(),
               0, // M_AttributeSetInstance_ID,
               element.getM_CostElement_ID(),
               costs.negate(),
               qty.negate(),
               "", // Description,
               cc.get_TrxName());
       cd.setPP_Cost_Collector_ID(cc.getPP_Cost_Collector_ID());
       cd.saveEx();
       processCostDetail(cd);
     }
   }
 }
예제 #5
0
  /**
   * @param cc
   * @param product
   * @param as
   * @param element
   * @param failIfNoCostFound
   * @param trxName
   * @return cost price or null if no cost was found and <code>failIfNoCostFound</code> is <code>
   *     true</code>.
   */
  public BigDecimal getProductActualCostPrice(
      final I_PP_Cost_Collector cc,
      final I_M_Product product,
      final I_C_AcctSchema as,
      final I_M_CostElement element,
      final boolean failIfNoCostFound,
      final String trxName) {
    final CostDimension d =
        new CostDimension(
            product,
            as,
            as.getM_CostType_ID(),
            cc.getAD_Org_ID(), // AD_Org_ID,
            cc.getM_AttributeSetInstance_ID(), // M_ASI_ID,
            element.getM_CostElement_ID());

    final I_M_Cost cost = d.toQuery(I_M_Cost.class, trxName).firstOnly(I_M_Cost.class);
    if (cost == null) {
      if (!failIfNoCostFound) {
        return null;
      }

      throw new LiberoException(
          "@NotFound@ @M_Cost@ - "
              + "@M_AcctSchema_ID@="
              + as
              + ", @M_CostElement_ID@="
              + element
              + ", @M_Product_ID@="
              + product
              + ", Dimension="
              + d);
    }

    final BigDecimal price = cost.getCurrentCostPrice().add(cost.getCurrentCostPriceLL());
    return roundCost(price, as.getC_AcctSchema_ID());
  }
예제 #6
0
 public static boolean isActivityControlElement(I_M_CostElement element) {
   String costElementType = element.getCostElementType();
   return MCostElement.COSTELEMENTTYPE_Resource.equals(costElementType)
       || MCostElement.COSTELEMENTTYPE_Overhead.equals(costElementType)
       || MCostElement.COSTELEMENTTYPE_BurdenMOverhead.equals(costElementType);
 }
예제 #7
0
  /**
   * Create Cost Detail (Material Issue, Material Receipt)
   *
   * @param model
   * @param mtrx Material Transaction
   */
  public void createCostDetail(IDocumentLine model, MTransaction mtrx) {
    final I_PP_Cost_Collector cc =
        (model instanceof MPPCostCollector ? (MPPCostCollector) model : null);

    final Properties ctx = mtrx.getCtx();

    for (I_C_AcctSchema as : getAcctSchema(mtrx)) {
      // Cost Detail
      final I_M_Product product = MProduct.get(ctx, mtrx.getM_Product_ID());
      final String costingMethod = Services.get(IProductBL.class).getCostingMethod(product, as);
      // Check costing method
      if (!getCostingMethod().equals(costingMethod)) {
        throw new LiberoException("Costing method not supported - " + costingMethod);
      }
      //
      for (I_M_CostElement element : getCostElements(ctx)) {
        //
        // Delete Unprocessed zero Differences
        deleteCostDetail(
            model, as, element.getM_CostElement_ID(), mtrx.getM_AttributeSetInstance_ID());
        //
        // Get Costs
        final BigDecimal qty = mtrx.getMovementQty();
        final BigDecimal price =
            getProductActualCostPriceOrZero(cc, product, as, element, mtrx.get_TrxName());
        final BigDecimal amt = roundCost(price.multiply(qty), as.getC_AcctSchema_ID());
        //
        // Create / Update Cost Detail
        MCostDetail cd = getCostDetail(model, mtrx, as, element.getM_CostElement_ID());
        if (cd == null) // createNew
        {
          cd =
              new MCostDetail(
                  as,
                  mtrx.getAD_Org_ID(),
                  mtrx.getM_Product_ID(),
                  mtrx.getM_AttributeSetInstance_ID(),
                  element.getM_CostElement_ID(),
                  amt,
                  qty,
                  model.getDescription(),
                  mtrx.get_TrxName());
          // cd.setMovementDate(mtrx.getMovementDate());
          // if (cost != null)
          // {
          // cd.setCurrentCostPrice(cost.getCurrentCostPrice());
          // cd.setCurrentCostPriceLL(cost.getCurrentCostPriceLL());
          // }
          // else
          // {
          // cd.setCurrentCostPrice(Env.ZERO);
          // cd.setCurrentCostPriceLL(Env.ZERO);
          // }
          // cd.setM_CostType_ID(as.getM_CostType_ID());
          // //cd.setCostingMethod(element.getCostingMethod());
          // cd.setM_Transaction_ID(mtrx.get_ID());
          if (cc != null) {
            cd.setPP_Cost_Collector_ID(cc.getPP_Cost_Collector_ID());
          }
        } else {
          cd.setDeltaAmt(amt.subtract(cd.getAmt()));
          cd.setDeltaQty(mtrx.getMovementQty().subtract(cd.getQty()));
          if (cd.isDelta()) {
            cd.setProcessed(false);
            cd.setAmt(amt);
            cd.setQty(mtrx.getMovementQty());
          }
        }
        cd.saveEx();
        processCostDetail(cd);
        log.info("" + cd);
      } // for ELements
    } // Account Schema
  }