public class LineItem extends java.lang.Object implements Taxable
Order. Central objects that holds all line items related data
required for amount calculation. A LineItem is Taxable which means getTotal(Order) is used
for tax calculation. This line item holds the basePrice and the numberOfUnits. Additionally the giveAwayCount can be
set (10 items are bought, 5 of them are free) and this line item holds a ordered List of
LineItemDiscounts and LineItemCharges. The line item must use the same Currency as the linked
Order or a CurrenciesAreNotEqualException is thrown.| Constructor and Description |
|---|
LineItem(Money basePrice)
Creates a new line item with the given base price and one unit.
|
LineItem(Money basePrice,
int numberOfUnits)
Creates a new line item with the given base price and number of units.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addCharge(int index,
LineItemCharge lineItemCharge)
Adds a single charge to this line item at a specific position.
|
void |
addCharge(LineItemCharge lineItemCharge)
Adds a single charge to this line item.
|
void |
addCharges(LineItemCharge... lineItemCharges)
Adds multiple charges to this line item.
|
void |
addCharges(java.util.List<LineItemCharge> lineItemCharges)
Adds multiple charges to this line item.
|
void |
addDiscount(int index,
LineItemDiscount discount)
Adds a single discount to this line item at a specific position.
|
void |
addDiscount(LineItemDiscount discount)
Adds a single discount to this line item.
|
void |
addDiscounts(LineItemDiscount... discounts)
Adds multiple discounts to this line item.
|
void |
addDiscounts(java.util.List<LineItemDiscount> discounts)
Adds multiple discounts to this line item.
|
protected void |
assertCurrency(AbstractAmount amount) |
protected Money |
calculateCharge(Money currentValue,
LineItemCharge charge) |
protected Money |
calculateDiscount(Money currentValue,
LineItemDiscount discount) |
void |
clearCharges()
Removes all attached charges of the current line item.
|
void |
clearDiscounts()
Removes all attached discounts of the current line item.
|
Money |
getBasePrice()
Returns the base price of this line item.
|
java.util.List<LineItemCharge> |
getCharges()
Returns all charges assigned to this line item.
|
java.util.List<LineItemDiscount> |
getDiscounts()
Returns all discounts assigned to this line item.
|
int |
getGiveAwayUnits()
Tells the number of units to be 'for free' meaning that they're excluded from calculation completely.
|
int |
getNumberOfUnits()
Returns the regular number of units within that line item.
|
int |
getNumberOfUnitsForCalculation()
Returns the number of units that are applicable for calculation.
|
Order |
getOrder() |
Money |
getSubTotal()
Calculates the line item sub total.
|
java.util.Collection<Tax> |
getTaxes()
Returns all taxes which are targeting this line item.
|
Money |
getTotal(Order context)
Calculates to line item total.
|
Money |
getTotalCharge()
Calculates the total of all line item charges.
|
java.util.Map<LineItemCharge,Money> |
getTotalCharges()
Calculates totals of all line item charges separately.
|
Money |
getTotalDiscount()
Calculates the total of all line item discounts.
|
java.util.Map<LineItemDiscount,Money> |
getTotalDiscounts()
Calculates the totals of all line item discounts separately.
|
void |
removeCharge(LineItemCharge charge)
Removes a charge from this line item.
|
void |
removeDiscount(LineItemDiscount discount)
Removes a single discount from this line item.
|
void |
setGiveAwayUnits(int giveAwayCount)
Changes the number of units to be 'for free' meaning that they're excluded from calculation completely.
|
void |
setNumberOfUnits(int numberOfUnits)
Changes the number of regular units within that line item.
|
void |
setOrder(Order order)
Sets the
Order to for this line item belongs to. |
java.lang.String |
toString()
{numberOfUnits}x {basePrice} {currency}(free:{giveAwayCount}) discounts:[...] charges:[...] |
public LineItem(Money basePrice)
public LineItem(Money basePrice, int numberOfUnits)
public Money getTotal(Order context)
getTotal in interface Taxablecontext - the order within the tax is being calculatedgetSubTotal(),
getTotalDiscount(),
getTotalCharge()public Money getSubTotal()
setGiveAwayUnits(int) for how some units may be excluded).getTotal(Order)public Money getTotalDiscount()
getTotalDiscounts()public Money getTotalCharge()
getTotalCharges()public java.util.Map<LineItemDiscount,Money> getTotalDiscounts()
LineItemDiscount -> Money )getTotalDiscount()public java.util.Map<LineItemCharge,Money> getTotalCharges()
LineItemCharge -> Money )getTotalCharge()protected Money calculateDiscount(Money currentValue, LineItemDiscount discount)
protected Money calculateCharge(Money currentValue, LineItemCharge charge)
public int getNumberOfUnits()
setGiveAwayUnits(int).public final void setNumberOfUnits(int numberOfUnits)
setGiveAwayUnits(int).public void setOrder(Order order)
Order to for this line item belongs to. Is needed for the calculation because all line item must
have the same currency (Order.getCurrency() is used to check it).public Order getOrder()
MissingCalculationDataException - if order is null and this method or any calculation method (getTotal...) is called.public Money getBasePrice()
public java.lang.String toString()
{numberOfUnits}x {basePrice} {currency}(free:{giveAwayCount}) discounts:[...] charges:[...]toString in class java.lang.Objectpublic java.util.List<LineItemDiscount> getDiscounts()
public void addDiscounts(LineItemDiscount... discounts)
CurrenciesAreNotEqualException - in case at least one discount is absolute and uses a different currency than the enclosing orderpublic void addDiscounts(java.util.List<LineItemDiscount> discounts)
CurrenciesAreNotEqualException - in case at least one discount is absolute and uses a different currency than the enclosing orderpublic void addDiscount(int index,
LineItemDiscount discount)
index - the position to add the discount atCurrenciesAreNotEqualException - in case at it's a absolute discount and uses a different currency than the enclosing orderprotected void assertCurrency(AbstractAmount amount)
public void addDiscount(LineItemDiscount discount)
CurrenciesAreNotEqualException - in case at it's a absolute discount and uses a different currency than the enclosing orderpublic void clearDiscounts()
public void removeDiscount(LineItemDiscount discount)
public java.util.List<LineItemCharge> getCharges()
public void addCharges(LineItemCharge... lineItemCharges)
CurrenciesAreNotEqualException - in case there is at least one absolute charge which uses a different currency than the enclosing orderpublic void addCharges(java.util.List<LineItemCharge> lineItemCharges)
CurrenciesAreNotEqualException - in case there is at least one absolute charge which uses a different currency than the enclosing orderpublic void addCharge(LineItemCharge lineItemCharge)
CurrenciesAreNotEqualException - in case at it's a absolute charge and uses a different currency than the enclosing orderpublic void addCharge(int index,
LineItemCharge lineItemCharge)
index - the position to add the charge atCurrenciesAreNotEqualException - in case at it's a absolute charge and uses a different currency than the enclosing orderpublic void clearCharges()
public void removeCharge(LineItemCharge charge)
public int getNumberOfUnitsForCalculation()
getNumberOfUnits() - getGiveAwayUnits().public int getGiveAwayUnits()
public final void setGiveAwayUnits(int giveAwayCount)
public java.util.Collection<Tax> getTaxes()
Order.getTaxesFor(Taxable)Copyright © 2018 SAP SE. All Rights Reserved.