public CoProductReceiptHUProducer(final I_PP_Cost_Collector cc) {
    super(cc);

    Check.assumeNotNull(cc, "cc not null");
    _costCollector = cc;

    Check.assume(
        cc.getPP_Order_BOMLine_ID() > 0,
        "Order BOM Line shall be set to cost collector when receiving co/bu products: {}",
        cc);
    _ppOrderBOMLine =
        InterfaceWrapperHelper.create(cc.getPP_Order_BOMLine(), I_PP_Order_BOMLine.class);
    Check.assumeNotNull(_ppOrderBOMLine, "ppOrderBOMLine not null");
  }
Example #2
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 #3
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());
  }
Example #4
0
 private I_PP_Cost_Collector createVarianceCostCollector(
     I_PP_Cost_Collector cc, String CostCollectorType) {
   final I_PP_Cost_Collector ccv =
       InterfaceWrapperHelper.newInstance(I_PP_Cost_Collector.class, cc);
   InterfaceWrapperHelper.copyValues(cc, ccv);
   ccv.setProcessing(false);
   ccv.setProcessed(false);
   ccv.setDocStatus(X_PP_Cost_Collector.DOCSTATUS_Drafted);
   ccv.setDocAction(X_PP_Cost_Collector.DOCACTION_Complete);
   ccv.setCostCollectorType(CostCollectorType);
   ccv.setDocumentNo(null); // reset
   cc.setPP_Cost_Collector_Parent(cc); // link to parent
   InterfaceWrapperHelper.save(ccv);
   return ccv;
 }
Example #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());
  }
Example #6
0
  private final void createReversal(
      final I_M_CostDetail costDetail, final I_PP_Cost_Collector reversalCostCollector) {
    final I_M_CostDetail costDetailReversal =
        InterfaceWrapperHelper.newInstance(I_M_CostDetail.class, costDetail);
    InterfaceWrapperHelper.copyValues(
        costDetail, costDetailReversal, true); // honorIsCalculated=true
    costDetailReversal.setPP_Cost_Collector_ID(reversalCostCollector.getPP_Cost_Collector_ID());
    costDetailReversal.setQty(costDetail.getQty().negate());
    costDetailReversal.setAmt(costDetail.getAmt().negate());
    costDetailReversal.setDeltaQty(costDetail.getDeltaQty().negate());
    costDetailReversal.setDeltaAmt(costDetail.getDeltaAmt().negate());
    costDetailReversal.setProcessed(false);
    InterfaceWrapperHelper.save(costDetailReversal);

    processCostDetail(costDetailReversal);
  }
Example #7
0
  public void createReversals(final I_PP_Cost_Collector reversalCostCollector) {
    Check.assumeNotNull(reversalCostCollector, "reversalCostCollector not null");

    //
    // Get the original cost collector
    final I_PP_Cost_Collector costCollector = reversalCostCollector.getReversal();
    Check.assumeNotNull(costCollector, "costCollector not null");

    //
    // Get the original cost details
    final List<I_M_CostDetail> costDetails =
        Services.get(IPPCostCollectorDAO.class).retrieveCostDetails(costCollector);

    for (final I_M_CostDetail cd : costDetails) {
      createReversal(cd, reversalCostCollector);
    }
  }
Example #8
0
  private MCostDetail getCostDetail(I_PP_Cost_Collector cc, int M_CostElement_ID) {
    final String whereClause =
        MCostDetail.COLUMNNAME_PP_Cost_Collector_ID
            + "=?"
            + " AND "
            + MCostDetail.COLUMNNAME_M_CostElement_ID
            + "=?";

    final Properties ctx = InterfaceWrapperHelper.getCtx(cc);
    final String trxName = InterfaceWrapperHelper.getTrxName(cc);
    MCostDetail cd =
        new Query(ctx, MCostDetail.Table_Name, whereClause, trxName)
            .setParameters(new Object[] {cc.getPP_Cost_Collector_ID(), M_CostElement_ID})
            .setOrderBy(
                MCostDetail.COLUMNNAME_Qty
                    + " DESC") // TODO : fix this; we have 2 cost details; now we are taking the one
                               // with bigger qty; we must find a proper way
            .first();
    return cd;
  }
  @Override
  protected IAllocationRequest createAllocationRequest(final IHUContext huContext) {
    final I_PP_Cost_Collector cc = getPP_Cost_Collector();
    final I_C_UOM uom = cc.getC_UOM();

    final BigDecimal qtyReceived =
        Services.get(IPPOrderBOMBL.class).adjustCoProductQty(cc.getMovementQty());

    final Timestamp date = cc.getMovementDate();
    final I_M_Product product = cc.getM_Product();

    final IAllocationRequest allocationRequest =
        AllocationUtils.createQtyRequest(
            huContext,
            product, // product
            qtyReceived, // the quantity we received
            uom,
            date, // transaction date
            cc.getPP_Order() // referenced model
            );

    return allocationRequest;
  }
Example #10
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
  }