Пример #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
 }
Пример #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);
   }
 }
Пример #3
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);
     }
   }
 }