Example #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;
 }
Example #2
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
  }