Example #1
0
 public void createUsageVariances(MPPCostCollector ccuv) {
   // Apply only for material Usage Variance
   if (!ccuv.isCostCollectorType(X_PP_Cost_Collector.COSTCOLLECTORTYPE_UsegeVariance)) {
     throw new IllegalArgumentException("Cost Collector is not Material Usage Variance");
   }
   //
   final I_M_Product product;
   final BigDecimal qty;
   if (ccuv.getPP_Order_BOMLine_ID() > 0) {
     product = MProduct.get(ccuv.getCtx(), ccuv.getM_Product_ID());
     qty = ccuv.getMovementQty();
   } else {
     product = MProduct.forS_Resource_ID(ccuv.getCtx(), ccuv.getS_Resource_ID(), null);
     final RoutingService routingService =
         RoutingServiceFactory.get().getRoutingService(ccuv.getAD_Client_ID());
     qty = routingService.getResourceBaseValue(ccuv.getS_Resource_ID(), ccuv);
   }
   //
   for (I_C_AcctSchema as : getAcctSchema(ccuv)) {
     for (I_M_CostElement element : getCostElements(ccuv.getCtx())) {
       final BigDecimal price =
           getProductActualCostPrice(ccuv, product, as, element, ccuv.get_TrxName());
       final BigDecimal amt = roundCost(price.multiply(qty), as.getC_AcctSchema_ID());
       //
       // Create / Update Cost Detail
       createVarianceCostDetail(
           ccuv, amt, qty, null, // no original cost detail
           product, as, element);
     } // for ELements
   } // Account Schema
 }
Example #2
0
 public void createMethodVariances(MPPCostCollector cc) {
   if (!cc.isCostCollectorType(X_PP_Cost_Collector.COSTCOLLECTORTYPE_ActivityControl)) return;
   //
   final int std_resource_id = cc.getPP_Order_Node().getAD_WF_Node().getS_Resource_ID();
   final int actual_resource_id = cc.getS_Resource_ID();
   if (std_resource_id == actual_resource_id) {
     return;
   }
   //
   I_PP_Cost_Collector ccmv = null; // Cost Collector - Method Change Variance
   final RoutingService routingService =
       RoutingServiceFactory.get().getRoutingService(cc.getAD_Client_ID());
   for (I_C_AcctSchema as : getAcctSchema(cc)) {
     for (I_M_CostElement element : getCostElements(cc.getCtx())) {
       final I_M_Product resourcePStd =
           MProduct.forS_Resource_ID(cc.getCtx(), std_resource_id, null);
       final I_M_Product resourcePActual =
           MProduct.forS_Resource_ID(cc.getCtx(), actual_resource_id, null);
       final BigDecimal priceStd =
           getProductActualCostPrice(cc, resourcePStd, as, element, cc.get_TrxName());
       final BigDecimal priceActual =
           getProductActualCostPrice(cc, resourcePActual, as, element, cc.get_TrxName());
       if (priceStd.compareTo(priceActual) == 0) {
         continue;
       }
       //
       if (ccmv == null) {
         ccmv =
             createVarianceCostCollector(
                 cc, X_PP_Cost_Collector.COSTCOLLECTORTYPE_MethodChangeVariance);
       }
       //
       final BigDecimal qty = routingService.getResourceBaseValue(cc.getS_Resource_ID(), cc);
       final BigDecimal amtStd = priceStd.multiply(qty);
       final BigDecimal amtActual = priceActual.multiply(qty);
       //
       createVarianceCostDetail(ccmv, amtActual, qty, null, resourcePActual, as, element);
       createVarianceCostDetail(
           ccmv, amtStd.negate(), qty.negate(), null, resourcePStd, as, element);
     }
   }
   //
   if (ccmv != null) {
     Services.get(IDocActionBL.class)
         .processEx(ccmv, DocAction.ACTION_Complete, DocAction.STATUS_Completed);
   }
 }
Example #3
0
 public BigDecimal getResourceStandardCostRate(
     I_PP_Cost_Collector cc, int S_Resource_ID, CostDimension d, String trxName) {
   final Properties ctx = InterfaceWrapperHelper.getCtx(cc);
   final I_M_Product resourceProduct =
       MProduct.forS_Resource_ID(ctx, S_Resource_ID, ITrx.TRXNAME_None);
   return getProductStandardCostPrice(
       cc,
       resourceProduct,
       MAcctSchema.get(ctx, d.getC_AcctSchema_ID()),
       MCostElement.get(ctx, d.getM_CostElement_ID()));
 }
Example #4
0
 public BigDecimal getResourceActualCostRate(
     I_PP_Cost_Collector cc, int S_Resource_ID, CostDimension d, String trxName) {
   if (S_Resource_ID <= 0) return Env.ZERO;
   final MProduct resourceProduct = MProduct.forS_Resource_ID(Env.getCtx(), S_Resource_ID, null);
   return getProductActualCostPrice(
       cc,
       resourceProduct,
       MAcctSchema.get(Env.getCtx(), d.getC_AcctSchema_ID()),
       MCostElement.get(Env.getCtx(), d.getM_CostElement_ID()),
       trxName);
 }
Example #5
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);
    }
  }
Example #6
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);
     }
   }
 }