示例#1
0
 /**
  * Get Base value for Cost Distribution
  *
  * @param CostDistribution cost Distribution
  * @return base number
  */
 public BigDecimal getBase(String CostDistribution) {
   if (MLandedCost.LANDEDCOSTDISTRIBUTION_Costs.equals(CostDistribution)) {
     MInvoiceLine m_il = MInvoiceLine.getOfInOutLine(this);
     if (m_il == null) {
       log.severe("No Invoice Line for: " + this.toString());
       return Env.ZERO;
     }
     return this.getMovementQty().multiply(m_il.getPriceActual()); // Actual delivery
   } else if (MLandedCost.LANDEDCOSTDISTRIBUTION_Line.equals(CostDistribution)) return Env.ONE;
   else if (MLandedCost.LANDEDCOSTDISTRIBUTION_Quantity.equals(CostDistribution))
     return getMovementQty();
   else if (MLandedCost.LANDEDCOSTDISTRIBUTION_Volume.equals(CostDistribution)) {
     MProduct product = getProduct();
     if (product == null) {
       log.severe("No Product");
       return Env.ZERO;
     }
     return getMovementQty().multiply(product.getVolume());
   } else if (MLandedCost.LANDEDCOSTDISTRIBUTION_Weight.equals(CostDistribution)) {
     MProduct product = getProduct();
     if (product == null) {
       log.severe("No Product");
       return Env.ZERO;
     }
     return getMovementQty().multiply(product.getWeight());
   }
   //
   log.severe("Invalid Criteria: " + CostDistribution);
   return Env.ZERO;
 } //	getBase
  @Override
  protected String validateAction() {

    String validate = null;

    DefaultMutableTreeNode node =
        (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
    BOMLineWrapper line = null;
    if (!(node.getUserObject() instanceof BOMLineWrapper)) {

      validate =
          "'"
              + node.getUserObject().getClass().getName()
              + "' isn't a type of 'BOMLineWrapper'(ClassCastException)";
    } else {

      line = (BOMLineWrapper) node.getUserObject();
      MProduct p = new MProduct(Env.getCtx(), line.getM_Product_ID(), null);

      if (p.getM_AttributeSet_ID() == 0) {

        validate = Services.get(IMsgBL.class).getMsg(Env.getCtx(), "PAttributeNoAttributeSet");
      }
    }

    return validate;
  }
  /**
   * Import record using X_I_ProductPlanning table
   *
   * @param ipp X_I_ProductPlanning
   */
  private void importPurchaseProductPlanning(X_I_ProductPlanning ipp) {
    MProduct product = MProduct.get(getCtx(), ipp.getM_Product_ID());
    if (product.isPurchased()) {
      final StringBuffer whereClause = new StringBuffer();
      whereClause.append(MProductPO.COLUMNNAME_M_Product_ID).append("=? AND ");
      whereClause.append(MProductPO.COLUMNNAME_C_BPartner_ID).append("=?");
      MProductPO productPO =
          new Query(getCtx(), MProductPO.Table_Name, whereClause.toString(), get_TrxName())
              .setClient_ID()
              .setParameters(new Object[] {ipp.getM_Product_ID(), ipp.getC_BPartner_ID()})
              .first();

      if (productPO == null) {
        productPO = new MProductPO(getCtx(), 0, get_TrxName());
      }

      productPO.setAD_Org_ID(ipp.getAD_Org_ID());
      productPO.setM_Product_ID(ipp.getM_Product_ID());
      productPO.setC_BPartner_ID(ipp.getC_BPartner_ID());
      productPO.setOrder_Min(ipp.getOrder_Min());
      productPO.setOrder_Pack(ipp.getOrder_Pack());
      productPO.setDeliveryTime_Promised(ipp.getDeliveryTime_Promised().intValue());
      productPO.setVendorProductNo(ipp.getVendorProductNo());
      productPO.saveEx();
    }
  }
示例#4
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
 }
示例#5
0
 /**
  * Set Order Line. Does not set Quantity!
  *
  * @param oLine order line
  * @param M_Locator_ID locator
  * @param Qty used only to find suitable locator
  */
 public void setOrderLine(MOrderLine oLine, int M_Locator_ID, BigDecimal Qty) {
   setC_OrderLine_ID(oLine.getC_OrderLine_ID());
   setLine(oLine.getLine());
   setC_UOM_ID(oLine.getC_UOM_ID());
   MProduct product = oLine.getProduct();
   if (product == null) {
     set_ValueNoCheck("M_Product_ID", null);
     set_ValueNoCheck("M_AttributeSetInstance_ID", null);
     set_ValueNoCheck("M_Locator_ID", null);
   } else {
     setM_Product_ID(oLine.getM_Product_ID());
     setM_AttributeSetInstance_ID(oLine.getM_AttributeSetInstance_ID());
     //
     if (product.isItem()) {
       if (M_Locator_ID == 0) setM_Locator_ID(Qty); // 	requires warehouse, product, asi
       else setM_Locator_ID(M_Locator_ID);
     } else set_ValueNoCheck("M_Locator_ID", null);
   }
   setC_Charge_ID(oLine.getC_Charge_ID());
   setDescription(oLine.getDescription());
   setIsDescription(oLine.isDescription());
   //
   setC_Project_ID(oLine.getC_Project_ID());
   setC_ProjectPhase_ID(oLine.getC_ProjectPhase_ID());
   setC_ProjectTask_ID(oLine.getC_ProjectTask_ID());
   setC_Activity_ID(oLine.getC_Activity_ID());
   setC_Campaign_ID(oLine.getC_Campaign_ID());
   setAD_OrgTrx_ID(oLine.getAD_OrgTrx_ID());
   setUser1_ID(oLine.getUser1_ID());
   setUser2_ID(oLine.getUser2_ID());
 } //	setOrderLine
示例#6
0
 /**
  * Set Movement Qty - enforce Product UOM
  *
  * @param MovementQty
  */
 public void setMovementQty(BigDecimal MovementQty) {
   MProduct product = getProduct();
   if (MovementQty != null && product != null) {
     int precision = product.getUOMPrecision();
     MovementQty = MovementQty.setScale(precision, BigDecimal.ROUND_HALF_UP);
   }
   super.setMovementQty(MovementQty);
 } //	setMovementQty
示例#7
0
 /**
  * Set Qty Ordered - enforce Product UOM
  *
  * @param QtyOrdered
  */
 @Override
 public void setQtyOrdered(BigDecimal QtyOrdered) {
   MProduct product = getProduct();
   if (QtyOrdered != null && product != null) {
     int precision = product.getUOMPrecision();
     QtyOrdered = QtyOrdered.setScale(precision, BigDecimal.ROUND_HALF_UP);
   }
   super.setQtyOrdered(QtyOrdered);
 } // setQtyOrdered
示例#8
0
  /**
   * Is this an Item Product (vs. not a Service, a charge)
   *
   * @return true if product
   */
  public boolean isItem() {
    if (m_isItem != null) return m_isItem.booleanValue();

    m_isItem = Boolean.FALSE;
    if (getM_Product_ID() != 0) {
      MProduct product = MProduct.get(Env.getCtx(), getM_Product_ID());
      if (product.get_ID() == getM_Product_ID() && product.isItem()) m_isItem = Boolean.TRUE;
    }
    return m_isItem.booleanValue();
  } //	isItem
  /**
   * Create Facts (the accounting logic) for PJI
   *
   * <pre>
   *  Issue
   *      ProjectWIP      DR
   *      Inventory               CR
   *  </pre>
   *
   * Project Account is either Asset or WIP depending on Project Type
   *
   * @param as accounting schema
   * @return Fact
   */
  public ArrayList<Fact> createFacts(MAcctSchema as) {
    //  create Fact Header
    Fact fact = new Fact(this, as, Fact.POST_Actual);
    setC_Currency_ID(as.getC_Currency_ID());

    MProject project = new MProject(getCtx(), m_issue.getC_Project_ID(), getTrxName());
    String ProjectCategory = project.getProjectCategory();
    MProduct product = MProduct.get(getCtx(), m_issue.getM_Product_ID());

    //  Line pointers
    FactLine dr = null;
    FactLine cr = null;

    //  Issue Cost
    BigDecimal costs = null;
    BigDecimal total = Env.ZERO;
    if (m_issue.getM_InOutLine_ID() != 0) costs = getPOCost(as);
    else if (m_issue.getS_TimeExpenseLine_ID() != 0) costs = getLaborCost(as);
    if (costs == null) // 	standard Product Costs
    {
      for (MCostDetail cost : m_line.getCostDetail(as)) {
        if (!MCostDetail.existsCost(cost)) continue;

        costs = MCostDetail.getTotalCost(cost, as);
        total = total.add(costs);
      }
    }

    if (total == null || total.signum() == 0) {
      p_Error = "Resubmit - No Costs for " + product.getName();
      log.log(Level.WARNING, p_Error);
      return null;
    }

    //  Project         DR
    int acctType = ACCTTYPE_ProjectWIP;
    if (MProject.PROJECTCATEGORY_AssetProject.equals(ProjectCategory))
      acctType = ACCTTYPE_ProjectAsset;
    dr = fact.createLine(m_line, getAccount(acctType, as), as.getC_Currency_ID(), costs, null);
    dr.setQty(m_line.getQty().negate());

    //  Inventory               CR
    acctType = ProductCost.ACCTTYPE_P_Asset;
    if (product.isService()) acctType = ProductCost.ACCTTYPE_P_Expense;
    cr =
        fact.createLine(
            m_line, m_line.getAccount(acctType, as), as.getC_Currency_ID(), null, costs);
    cr.setM_Locator_ID(m_line.getM_Locator_ID());
    cr.setLocationFromLocator(m_line.getM_Locator_ID(), true); // from Loc
    //
    ArrayList<Fact> facts = new ArrayList<Fact>();
    facts.add(fact);
    return facts;
  } //  createFact
示例#10
0
 /**
  * Set Product
  *
  * @param product product
  */
 public void setProduct(MProduct product) {
   m_product = product;
   if (m_product != null) {
     setM_Product_ID(m_product.getM_Product_ID());
     setC_UOM_ID(m_product.getC_UOM_ID());
   } else {
     setM_Product_ID(0);
     setC_UOM_ID(0);
   }
   setM_AttributeSetInstance_ID(0);
 } //	setProduct
示例#11
0
 /**
  * Perform process.
  *
  * @return Message (text with variables)
  * @throws Exception if not successful
  */
 protected String doIt() throws Exception {
   if (log.isLoggable(Level.INFO)) log.info("M_Product_ID=" + p_M_Product_ID);
   if (p_M_Product_ID == 0)
     throw new AdempiereUserError("@NotFound@: @M_Product_ID@ = " + p_M_Product_ID);
   MProduct product = MProduct.get(getCtx(), p_M_Product_ID);
   if (product.get_ID() != p_M_Product_ID)
     throw new AdempiereUserError("@NotFound@: @M_Product_ID@ = " + p_M_Product_ID);
   //
   if (MCostDetail.processProduct(product, get_TrxName())) return "@OK@";
   return "@Error@";
 } //	doIt
示例#12
0
  /**
   * ************************************************************************ Invoice Line -
   * Product. - reset C_Charge_ID / M_AttributeSetInstance_ID - PriceList, PriceStd, PriceLimit,
   * C_Currency_ID, EnforcePriceLimit - UOM Calls Tax
   *
   * @param ctx context
   * @param WindowNo window no
   * @param mTab tab
   * @param mField field
   * @param value value
   * @return null or error message
   */
  public String product(
      Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) {
    Integer M_Product_ID = (Integer) value;
    Integer M_AttributeSetInstance_ID = 0;

    if (M_Product_ID == null || M_Product_ID.intValue() == 0) return "";
    mTab.setValue("C_Charge_ID", null);

    //	Get Model and check the Attribute Set Instance from the context
    MProduct m_product = MProduct.get(Env.getCtx(), M_Product_ID);
    mTab.setValue("M_AttributeSetInstance_ID", m_product.getEnvAttributeSetInstance(ctx, WindowNo));

    /** *** Price Calculation see also qty *** */
    boolean IsSOTrx = Env.getContext(ctx, WindowNo, "IsSOTrx").equals("Y");
    int C_BPartner_ID = Env.getContextAsInt(ctx, WindowNo, WindowNo, "C_BPartner_ID");
    BigDecimal Qty = (BigDecimal) mTab.getValue("QtyInvoiced");
    MProductPricing pp = new MProductPricing(M_Product_ID.intValue(), C_BPartner_ID, Qty, IsSOTrx);
    //
    int M_PriceList_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_ID");
    pp.setM_PriceList_ID(M_PriceList_ID);

    Timestamp invoiceDate = Env.getContextAsDate(ctx, WindowNo, "DateInvoiced");
    /** PLV is only accurate if PL selected in header */
    int M_PriceList_Version_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_Version_ID");
    if (M_PriceList_Version_ID == 0 && M_PriceList_ID > 0) {
      String sql =
          "SELECT plv.M_PriceList_Version_ID "
              + "FROM M_PriceList_Version plv "
              + "WHERE plv.M_PriceList_ID=? " //	1
              + " AND plv.ValidFrom <= ? "
              + "ORDER BY plv.ValidFrom DESC";
      //	Use newest price list - may not be future

      M_PriceList_Version_ID = DB.getSQLValueEx(null, sql, M_PriceList_ID, invoiceDate);
      if (M_PriceList_Version_ID > 0)
        Env.setContext(ctx, WindowNo, "M_PriceList_Version_ID", M_PriceList_Version_ID);
    }

    pp.setM_PriceList_Version_ID(M_PriceList_Version_ID);
    Timestamp date = Env.getContextAsDate(ctx, WindowNo, "DateInvoiced");
    pp.setPriceDate(date);
    //
    mTab.setValue("PriceList", pp.getPriceList());
    mTab.setValue("PriceLimit", pp.getPriceLimit());
    mTab.setValue("PriceActual", pp.getPriceStd());
    mTab.setValue("PriceEntered", pp.getPriceStd());
    mTab.setValue("C_Currency_ID", new Integer(pp.getC_Currency_ID()));
    //	mTab.setValue("Discount", pp.getDiscount());
    mTab.setValue("C_UOM_ID", new Integer(pp.getC_UOM_ID()));
    Env.setContext(ctx, WindowNo, "EnforcePriceLimit", pp.isEnforcePriceLimit() ? "Y" : "N");
    Env.setContext(ctx, WindowNo, "DiscountSchema", pp.isDiscountSchema() ? "Y" : "N");
    //
    return tax(ctx, WindowNo, mTab, mField, value);
  } //	product
示例#13
0
  public static MOrderLine createOrderLine(
      Properties ctx,
      MOrder order,
      int productId,
      BigDecimal qty,
      BigDecimal discount,
      BigDecimal lineNet)
      throws OperationException {
    if (qty == null) {
      qty = Env.ONE;
    }

    MOrderLine orderLine = new MOrderLine(order);

    MProduct product = new MProduct(ctx, productId, order.get_TrxName());
    MTax tax =
        TaxManager.getTaxFromCategory(ctx, product.getC_TaxCategory_ID(), order.get_TrxName());
    orderLine.setC_Tax_ID(tax.get_ID());
    orderLine.setC_UOM_ID(product.getC_UOM_ID());
    orderLine.setC_BPartner_ID(order.getC_BPartner_ID());
    // Must set Product Id before quantity Ordered.
    orderLine.setM_Product_ID(productId);
    orderLine.setQty(qty);
    orderLine.setPrice();

    // Bug fix, set price to 2dp
    MPriceList orderPriceList = MPriceList.get(ctx, order.getM_PriceList_ID(), order.get_TrxName());

    if (!orderPriceList.isTaxIncluded()) {
      BigDecimal taxAmt = tax.calculateTax(lineNet, true, 12);
      BigDecimal lineNetWithoutTax = lineNet.subtract(taxAmt);
      orderLine.setLineNetAmt(lineNetWithoutTax);

      BigDecimal unitPriceWithoutTax =
          lineNetWithoutTax.divide(qty, 12, BigDecimal.ROUND_HALF_DOWN);

      orderLine.setPriceEntered(unitPriceWithoutTax.setScale(2, BigDecimal.ROUND_HALF_UP));
      orderLine.setPriceActual(unitPriceWithoutTax.setScale(2, BigDecimal.ROUND_HALF_UP));
    } else {
      BigDecimal unitPrice = lineNet.divide(qty, 12, BigDecimal.ROUND_HALF_DOWN);
      orderLine.setLineNetAmt(lineNet.setScale(2, BigDecimal.ROUND_HALF_UP));
      orderLine.setPriceEntered(unitPrice.setScale(2, BigDecimal.ROUND_HALF_UP));
      orderLine.setPriceActual(unitPrice.setScale(2, BigDecimal.ROUND_HALF_UP));
    }

    if (discount.doubleValue() != 0.0) {
      orderLine.setDiscount();
    }

    PoManager.save(orderLine);

    return orderLine;
  }
示例#14
0
 /**
  * Quantity UOM
  *
  * @return Transaction or Storage M_UOM_ID
  */
 public int getC_UOM_ID() {
   //	Trx UOM
   int index = p_po.get_ColumnIndex("C_UOM_ID");
   if (index != -1) {
     Integer ii = (Integer) p_po.get_Value(index);
     if (ii != null) return ii.intValue();
   }
   //  Storage UOM
   MProduct product = getProduct();
   if (product != null) return product.getC_UOM_ID();
   //
   return 0;
 } //  getC_UOM
示例#15
0
 /**
  * Get MProduct from Cache
  *
  * @param ctx context
  * @param M_Product_ID id
  * @return MProduct or null
  */
 public static MProduct get(Properties ctx, int M_Product_ID) {
   if (M_Product_ID <= 0) {
     return null;
   }
   Integer key = new Integer(M_Product_ID);
   MProduct retValue = (MProduct) s_cache.get(key);
   if (retValue != null) {
     return retValue;
   }
   retValue = new MProduct(ctx, M_Product_ID, null);
   if (retValue.get_ID() != 0) {
     s_cache.put(key, retValue);
   }
   return retValue;
 } //	get
  private int selectASIID(BOMLineWrapper line) {

    if (line.getM_Product_ID() <= 0) return -1;

    MProduct p = new MProduct(Env.getCtx(), line.getM_Product_ID(), null);
    PAttributeInstance pai =
        new PAttributeInstance(
            (JFrame) null,
            p.getName(),
            getParameterValueAsInt("M_Warehouse_ID"),
            0,
            line.getM_Product_ID(),
            0);

    return pai.getM_AttributeSetInstance_ID();
  }
示例#17
0
  private BigDecimal getAmount(MTimeExpenseLine schedule, String mode) {
    BigDecimal amount = Env.ZERO;

    if (!(schedule.get_ValueAsBoolean("IsPaid"))) {
      MProduct concept = (MProduct) schedule.getM_Product();
      MExpenseType conceptType = (MExpenseType) concept.getS_ExpenseType();
      String type = concept.get_ValueAsString(MInvoiceSchedule.COLUMNNAME_InvoiceFrequency);
      if (mode.equals(type)) {
        amount = amount.add(schedule.getApprovalAmt());
        schedule.set_ValueOfColumn("IsPaid", true);
        schedule.saveEx();
      }
    }

    return amount;
  }
示例#18
0
 /**
  * Set Product
  *
  * @param product product
  */
 public void setProduct(MProduct product) {
   Services.get(IOrderLineBL.class)
       .setM_Product_ID(
           InterfaceWrapperHelper.create(this, de.metas.interfaces.I_C_OrderLine.class),
           product.getM_Product_ID(),
           true);
 } // setProduct
示例#19
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);
   }
 }
示例#20
0
  /**
   * Generate an Explosion for this BOM
   *
   * @param PP_Product_BOMLine_ID ID BOM Line
   */
  public void parentExplotion(int PP_Product_BOM_ID, BigDecimal qtyRequiered) throws Exception {
    ArrayList<Object> parameters = new ArrayList<Object>();
    parameters.add(PP_Product_BOM_ID);

    final StringBuilder whereClause =
        new StringBuilder(MPPProductBOMLine.COLUMNNAME_PP_Product_BOM_ID).append("=?");

    if (p_BackflushGroup != null) {
      whereClause
          .append(" AND ")
          .append(MPPProductBOMLine.COLUMNNAME_BackflushGroup)
          .append("LIKE ?");
      parameters.add(p_BackflushGroup);
    }

    List<MPPProductBOMLine> bomLines =
        new Query(getCtx(), MPPProductBOMLine.Table_Name, whereClause.toString(), get_TrxName())
            .setClient_ID()
            .setOnlyActiveRecords(true)
            .setParameters(parameters)
            .setOrderBy(MPPProductBOMLine.COLUMNNAME_Line)
            .list();

    for (MPPProductBOMLine line : bomLines) {
      if (line.isValidFromTo(p_DateTrx)) {
        SeqNo += 1;
        MProduct product = new MProduct(getCtx(), line.getM_Product_ID(), get_TrxName());
        X_T_BOMLine tboml = new X_T_BOMLine(ctx, 0, null);
        tboml.setAD_Org_ID(product.getAD_Org_ID());
        tboml.setPP_Product_BOM_ID(PP_Product_BOM_ID);
        tboml.setPP_Product_BOMLine_ID(line.get_ID());
        tboml.setM_Product_ID(line.getM_Product_ID());
        tboml.setLevelNo(LevelNo);
        tboml.setDateTrx(p_DateTrx);
        tboml.setLevels(levels.substring(0, LevelNo) + LevelNo);
        tboml.setSeqNo(SeqNo);
        tboml.setAD_PInstance_ID(AD_PInstance_ID);
        tboml.setSel_Product_ID(p_M_Product_ID);
        tboml.setQtyBOM(line.getQty(true));
        tboml.setQtyRequired(qtyRequiered.multiply(line.getQty(true)));
        tboml.setM_Warehouse_ID(p_M_Warehouse_ID);
        tboml.setImplosion(false);
        tboml.saveEx();
        component(line.getM_Product_ID(), tboml.getQtyBOM());
      }
    }
  }
示例#21
0
  public void createRateVariances(MPPCostCollector cc) {
    final I_M_Product product;
    if (cc.isCostCollectorType(X_PP_Cost_Collector.COSTCOLLECTORTYPE_ActivityControl)) {
      final I_AD_WF_Node node = cc.getPP_Order_Node().getAD_WF_Node();
      product = MProduct.forS_Resource_ID(cc.getCtx(), node.getS_Resource_ID(), null);
    } else if (cc.isCostCollectorType(X_PP_Cost_Collector.COSTCOLLECTORTYPE_ComponentIssue)) {
      final I_PP_Order_BOMLine bomLine = cc.getPP_Order_BOMLine();
      product = MProduct.get(cc.getCtx(), bomLine.getM_Product_ID());
    } else {
      return;
    }

    I_PP_Cost_Collector ccrv = null; // Cost Collector - Rate Variance
    for (MAcctSchema as : getAcctSchema(cc)) {
      for (I_M_CostElement element : getCostElements(cc.getCtx())) {
        final MCostDetail cd = getCostDetail(cc, element.getM_CostElement_ID());
        if (cd == null) {
          continue;
        }

        //
        final BigDecimal qty = cd.getQty();
        final BigDecimal priceStd = getProductStandardCostPrice(cc, product, as, element);
        final BigDecimal priceActual =
            getProductActualCostPriceOrZero(cc, product, as, element, cc.get_TrxName());
        final BigDecimal amtStd = roundCost(priceStd.multiply(qty), as.getC_AcctSchema_ID());
        final BigDecimal amtActual = roundCost(priceActual.multiply(qty), as.getC_AcctSchema_ID());
        if (amtStd.compareTo(amtActual) == 0) {
          continue;
        }

        //
        if (ccrv == null) {
          ccrv =
              createVarianceCostCollector(cc, X_PP_Cost_Collector.COSTCOLLECTORTYPE_RateVariance);
        }
        //
        createVarianceCostDetail(ccrv, amtActual.negate(), qty.negate(), cd, null, as, element);
        createVarianceCostDetail(ccrv, amtStd, qty, cd, null, as, element);
      }
    }
    //
    if (ccrv != null) {
      Services.get(IDocActionBL.class)
          .processEx(ccrv, DocAction.ACTION_Complete, DocAction.STATUS_Completed);
    }
  }
示例#22
0
 /**
  * Get Name
  *
  * @return get the name of the line (from Product)
  */
 public String getName() {
   getProduct();
   if (m_product != null) return m_product.getName();
   if (getC_Charge_ID() != 0) {
     MCharge charge = MCharge.get(getCtx(), getC_Charge_ID());
     return charge.getName();
   }
   return "";
 } // getName
示例#23
0
  /**
   * Add Product
   *
   * @param element panel
   * @param product product
   */
  private void addProduct(CPanel element, MProduct product) {
    Insets ii = new Insets(2, 4, 2, 4);
    int M_Product_ID = product.getM_Product_ID();
    CPanel pe = new CPanel();
    pe.setBorder(BorderFactory.createLineBorder(Color.BLUE, 1));
    pe.setLayout(new GridBagLayout());

    //	Product Value - Price
    pe.add(
        new JLabel(product.getValue()),
        new GridBagConstraints(
            0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, ii, 0, 0));
    String formatted = "";
    if (m_M_PriceList_Version_ID != 0) {
      MProductPrice pp =
          MProductPrice.get(Env.getCtx(), m_M_PriceList_Version_ID, M_Product_ID, null);
      if (pp != null) {
        BigDecimal price = pp.getPriceStd();
        formatted = m_price.format(price);
      } else formatted = "-";
    }
    pe.add(
        new JLabel(formatted, JLabel.RIGHT),
        new GridBagConstraints(
            1, 0, 1, 1, .5, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, ii, 0, 0));

    //	Product Name - Qty
    pe.add(
        new JLabel(product.getName()),
        new GridBagConstraints(
            0, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, ii, 0, 0));
    formatted = "";
    if (m_M_Warehouse_ID != 0) {
      BigDecimal qty = MStorage.getQtyAvailable(m_M_Warehouse_ID, M_Product_ID, 0, null);
      if (qty == null) formatted = "-";
      else formatted = m_qty.format(qty);
    }
    pe.add(
        new JLabel(formatted, JLabel.RIGHT),
        new GridBagConstraints(
            1, 1, 1, 1, .5, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, ii, 0, 0));
    //
    element.add(pe);
  } //	addProduct
示例#24
0
  public void calculateItems(String childValue) {
    singleMonth = Env.ZERO;
    ;
    singleYear = Env.ZERO;
    ;
    singleTotal = Env.ZERO;

    consolidatedMonth = Env.ZERO;
    consolidatedYear = Env.ZERO;
    consolidatedTotal = Env.ZERO;
    paymentValue = Env.ZERO;

    I_C_BPartner student = studentList.get(childValue);

    for (MTimeExpenseLine paymentSchedule : paymentSchedules) {
      if (paymentSchedule.getC_BPartner_ID() == student.getC_BPartner_ID()) {
        if (!(paymentSchedule.get_ValueAsBoolean("IsPaid"))) {
          I_M_Product concept = paymentSchedule.getM_Product();
          MExpenseType conceptType = (MExpenseType) concept.getS_ExpenseType();

          String type = conceptType.get_ValueAsString(MInvoiceSchedule.COLUMNNAME_InvoiceFrequency);
          if (MInvoiceSchedule.INVOICEFREQUENCY_Monthly.equals(type))
            singleMonth = singleMonth.add(paymentSchedule.getApprovalAmt());
          else if ("Y".equals(type)) singleYear = singleYear.add(paymentSchedule.getApprovalAmt());

          singleTotal = singleTotal.add(paymentSchedule.getApprovalAmt());
        }
      }

      if (!(paymentSchedule.get_ValueAsBoolean("IsPaid"))) {
        MProduct concept = (MProduct) paymentSchedule.getM_Product();
        MExpenseType conceptType = (MExpenseType) concept.getS_ExpenseType();
        String type = conceptType.get_ValueAsString(MInvoiceSchedule.COLUMNNAME_InvoiceFrequency);
        if (MInvoiceSchedule.INVOICEFREQUENCY_Monthly.equals(type))
          consolidatedMonth = consolidatedMonth.add(paymentSchedule.getApprovalAmt());
        else if ("Y".equals(type))
          consolidatedYear = consolidatedYear.add(paymentSchedule.getApprovalAmt());

        consolidatedTotal = consolidatedTotal.add(paymentSchedule.getApprovalAmt());
      }
    }
  }
示例#25
0
 public BigDecimal getResourceStandardCostRate(
     I_PP_Cost_Collector cc, int S_Resource_ID, CostDimension d, String trxName) {
   final Properties ctx = InterfaceWrapperHelper.getCtx(cc);
   final I_M_Product resourceProduct =
       MProduct.forS_Resource_ID(ctx, S_Resource_ID, ITrx.TRXNAME_None);
   return getProductStandardCostPrice(
       cc,
       resourceProduct,
       MAcctSchema.get(ctx, d.getC_AcctSchema_ID()),
       MCostElement.get(ctx, d.getM_CostElement_ID()));
 }
示例#26
0
 public BigDecimal getResourceActualCostRate(
     I_PP_Cost_Collector cc, int S_Resource_ID, CostDimension d, String trxName) {
   if (S_Resource_ID <= 0) return Env.ZERO;
   final MProduct resourceProduct = MProduct.forS_Resource_ID(Env.getCtx(), S_Resource_ID, null);
   return getProductActualCostPrice(
       cc,
       resourceProduct,
       MAcctSchema.get(Env.getCtx(), d.getC_AcctSchema_ID()),
       MCostElement.get(Env.getCtx(), d.getM_CostElement_ID()),
       trxName);
 }
示例#27
0
 public Collection<MCost> getByElement(
     MProduct product,
     MAcctSchema as,
     int M_CostType_ID,
     int AD_Org_ID,
     int M_AttributeSetInstance_ID,
     int M_CostElement_ID) {
   CostDimension cd =
       new CostDimension(
           product, as, M_CostType_ID, AD_Org_ID, M_AttributeSetInstance_ID, M_CostElement_ID);
   return cd.toQuery(MCost.class, product.get_TrxName()).setOnlyActiveRecords(true).list();
 }
示例#28
0
  /**
   * Perform process.
   *
   * @return Message (clear text)
   * @throws Exception if not successful
   */
  protected String doIt() throws Exception {
    AD_PInstance_ID = getAD_PInstance_ID();
    final MProduct product = MProduct.get(getCtx(), p_M_Product_ID);
    if (!product.isVerified())
      throw new AdempiereException(
          "Product BOM Configuration not verified. Please verify the product first - "
              + product.getValue()); // TODO: translate

    try {
      loadBOM();
      print();
    } catch (Exception e) {
      log.log(Level.SEVERE, "PrintBOM", e.toString());
      throw new Exception(e.getLocalizedMessage());
    } finally {
      String sql = "DELETE FROM T_BomLine WHERE AD_PInstance_ID = " + AD_PInstance_ID;
      DB.executeUpdateEx(sql, get_TrxName());
    }

    return "@OK@";
  } // doIt
示例#29
0
  /** Action: Fill Tree with all nodes */
  private void loadBOM() throws Exception {
    int count = 0;
    if (p_M_Product_ID == 0) raiseError("Error: ", "Product ID not found");

    MProduct product = new MProduct(getCtx(), p_M_Product_ID, get_TrxName());
    X_T_BOMLine tboml = new X_T_BOMLine(ctx, 0, null);
    tboml.setAD_Org_ID(product.getAD_Org_ID());
    tboml.setPP_Product_BOM_ID(0);
    tboml.setPP_Product_BOMLine_ID(0);
    tboml.setSel_Product_ID(p_M_Product_ID);
    tboml.setM_Product_ID(p_M_Product_ID);
    tboml.setSel_Product_ID(p_M_Product_ID);
    tboml.setDateTrx(p_DateTrx);
    tboml.setImplosion(false);
    tboml.setLevelNo(0);
    tboml.setLevels("0");
    tboml.setQtyBOM(Env.ONE);
    tboml.setQtyRequired(p_QtyRequiered);
    tboml.setM_Warehouse_ID(p_M_Warehouse_ID);
    tboml.setSeqNo(0);
    tboml.setAD_PInstance_ID(AD_PInstance_ID);
    tboml.saveEx();

    final String whereClause = MPPProductBOM.COLUMNNAME_M_Product_ID + "=?";
    List<MPPProductBOM> boms =
        new Query(getCtx(), X_PP_Product_BOM.Table_Name, whereClause, get_TrxName())
            .setClient_ID()
            .setOnlyActiveRecords(true)
            .setParameters(p_M_Product_ID)
            .list();

    for (MPPProductBOM bom : boms) {
      if (bom.isValidFromTo(p_DateTrx)) {
        parentExplotion(bom.get_ID(), p_QtyRequiered);
        ++count;
      }
    }

    if (count == 0) raiseError("Error: ", "Product is not a BOM");
  }
示例#30
0
  /**
   * Get Product from Cache
   *
   * @param ctx context
   * @param S_Resource_ID resource ID
   * @param trxName
   * @return MProduct or null if not found
   */
  public static MProduct forS_Resource_ID(Properties ctx, int S_Resource_ID, String trxName) {
    if (S_Resource_ID <= 0) {
      return null;
    }

    // Try Cache
    if (trxName == null) {
      for (MProduct p : s_cache.values()) {
        if (p.getS_Resource_ID() == S_Resource_ID) {
          return p;
        }
      }
    }
    // Load from DB
    MProduct p =
        new Query(ctx, Table_Name, COLUMNNAME_S_Resource_ID + "=?", trxName)
            .setParameters(new Object[] {S_Resource_ID})
            .firstOnly();
    if (p != null && trxName == null) {
      s_cache.put(p.getM_Product_ID(), p);
    }
    return p;
  }