Ejemplo n.º 1
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());
  }