コード例 #1
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;
  }
コード例 #2
0
ファイル: MOrderLine.java プロジェクト: metasfresh/metasfresh
 /**
  * ************************************************************************ Default Constructor
  *
  * @param ctx context
  * @param C_OrderLine_ID order line to load
  * @param trxName trx name
  */
 public MOrderLine(Properties ctx, int C_OrderLine_ID, String trxName) {
   super(ctx, C_OrderLine_ID, trxName);
   if (C_OrderLine_ID == 0) {
     // setC_Order_ID (0);
     // setLine (0);
     // setM_Warehouse_ID (0); // @M_Warehouse_ID@
     // setC_BPartner_ID(0);
     // setC_BPartner_Location_ID (0); // @C_BPartner_Location_ID@
     // setC_Currency_ID (0); // @C_Currency_ID@
     // setDateOrdered (new Timestamp(System.currentTimeMillis())); // @DateOrdered@
     //
     // setC_Tax_ID (0);
     // setC_UOM_ID (0);
     //
     setFreightAmt(Env.ZERO);
     setLineNetAmt(Env.ZERO);
     //
     setPriceEntered(Env.ZERO);
     setPriceActual(Env.ZERO);
     setPriceLimit(Env.ZERO);
     setPriceList(Env.ZERO);
     //
     setM_AttributeSetInstance_ID(0);
     //
     setQtyEntered(Env.ZERO);
     setQtyOrdered(Env.ZERO); // 1
     setQtyDelivered(Env.ZERO);
     setQtyInvoiced(Env.ZERO);
     // task 09358: get rid of this; instead, update qtyReserved at one central place
     // setQtyReserved(Env.ZERO);
     //
     setIsDescription(false); // N
     setProcessed(false);
     setLine(0);
   }
 } // MOrderLine
コード例 #3
0
ファイル: MOrderLine.java プロジェクト: metasfresh/metasfresh
 /**
  * Set Price Entered/Actual. Use this Method if the Line UOM is the Product UOM
  *
  * @param PriceActual price
  */
 public void setPrice(BigDecimal PriceActual) {
   setPriceEntered(PriceActual);
   setPriceActual(PriceActual);
 } // setPrice