Пример #1
0
 /**
  * Get Cost Detail
  *
  * @param model Model Inventory Line
  * @param as Account Schema
  * @param M_CostElement_ID Cost Element
  * @param M_AttributeSetInstance_ID
  * @return MCostDetail
  */
 private MCostDetail getCostDetail(
     IDocumentLine model, MTransaction mtrx, I_C_AcctSchema as, int M_CostElement_ID) {
   final String whereClause =
       "AD_Client_ID=? AND AD_Org_ID=?"
           + " AND "
           + model.get_TableName()
           + "_ID=?"
           + " AND "
           + MCostDetail.COLUMNNAME_M_Product_ID
           + "=?"
           + " AND "
           + MCostDetail.COLUMNNAME_M_AttributeSetInstance_ID
           + "=?"
           + " AND "
           + MCostDetail.COLUMNNAME_C_AcctSchema_ID
           + "=?"
           // +" AND "+MCostDetail.COLUMNNAME_M_CostType_ID+"=?"
           + " AND "
           + MCostDetail.COLUMNNAME_M_CostElement_ID
           + "=?";
   final Object[] params =
       new Object[] {
         mtrx.getAD_Client_ID(),
         mtrx.getAD_Org_ID(),
         model.get_ID(),
         mtrx.getM_Product_ID(),
         mtrx.getM_AttributeSetInstance_ID(),
         as.getC_AcctSchema_ID(),
         // as.getM_CostType_ID(),
         M_CostElement_ID,
       };
   return new Query(mtrx.getCtx(), MCostDetail.Table_Name, whereClause, mtrx.get_TrxName())
       .setParameters(params)
       .firstOnly();
 }
Пример #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
  }