Class Order


  • public class Order
    extends java.lang.Object
    Central Object that holds all calculation related data and strategies required for calculating the order/cart. The net/gross mode (see isNet()) and the current currency (getCurrency()) has to be provided during creation. After this point LineItem or other objects can be created with a different Currency but when adding it tho the current Order a CurrenciesAreNotEqualException is thrown.

    The getTotal...() methods returns the overall calculated Money for the different line item posts or taxes. With get...Values() a map is returned which shows the concrete single amount for each charge/discount/tax.

    • Constructor Detail

      • Order

        public Order​(Currency currency,
                     CalculationStrategies calculationStrategies)
        Creates a new gross order calculation object based on a specific currency.
        Parameters:
        currency - the currency the whole calculation will be in
        calculationStrategies - some strategies
      • Order

        public Order​(Currency currency,
                     boolean isNet,
                     CalculationStrategies calculationStrategies)
        Creates a new order calculation object based on a specific currency and bet/gross mode.
        Parameters:
        currency - the currency the whole calculation will be in
        isNet - true for net, false for gross mode
        calculationStrategies - some strategies
    • Method Detail

      • getTotalTaxFor

        public Money getTotalTaxFor​(Tax tax)
        Calculates the total tax for a specific Tax object.
      • getTotalTaxes

        public java.util.Map<Tax,​Money> getTotalTaxes()
        Calculates total taxes for all assigned Tax object.
        Returns:
        a map ( Tax -> Money )
      • getAutomaticTaxCorrectionFactor

        protected double getAutomaticTaxCorrectionFactor()
      • getFixedTaxedAdditionalCharges

        protected Money getFixedTaxedAdditionalCharges​(java.util.Map<OrderCharge,​Money> aocValues)
      • getTaxesFor

        public java.util.Collection<Tax> getTaxesFor​(Taxable object)
        Looks up potentially assigned Tax object for a given Taxable object.
        Returns:
        the assigned taxes or an empty collection
      • hasAssignedTaxes

        public boolean hasAssignedTaxes​(Taxable object)
        Returns:
        true if there is at least one Tax objects targeting the specified Taxable object
      • getTotalTax

        public Money getTotalTax()
        Returns the overall sum of taxes within this order. To get the exact money for each tax please use getTotalTaxes().
        See Also:
        getTotalTaxes()
      • calculateTaxTotal

        protected Money calculateTaxTotal​(Tax tax,
                                          double autoTaxCorrectionFactor)
      • getTotalCharge

        public Money getTotalCharge()
        Calculates the total of all charges which apply to the order at a whole. Please note that line item charges are not included here since they are already part of the line item total!
        See Also:
        getTotalCharges(), getTotalChargeOfType(ChargeType)
      • getTotalChargeOfType

        public Money getTotalChargeOfType​(AbstractCharge.ChargeType chargeType)
        Calculates the total of all charges of one specific type which apply to the order at a whole. Please note that line item charges are not included here since they are already part of the line item total!
        Parameters:
        chargeType - the type of charge to select
        See Also:
        getTotalCharge(), getTotalCharges()
      • getTotalDiscount

        public Money getTotalDiscount()
        Calculates the total of all discounts assigned to this order. Please note that this does not include line item discounts since they are already included in line item totals!
        See Also:
        getTotalDiscounts()
      • getTotalCharges

        public java.util.Map<OrderCharge,​Money> getTotalCharges()
        Calculates totals of all charges assigned to this order separately.
        Returns:
        a map ( OrderCharge -> Money )
      • getTotalDiscounts

        public java.util.Map<OrderDiscount,​Money> getTotalDiscounts()
        Calculates totals of all discounts assigned to this order separately.
        Returns:
        a map ( OrderDiscount -> Money )
      • calculateOrderCharge

        protected Money calculateOrderCharge​(Money currentValue,
                                             OrderCharge addCharge)
      • getTotalIncludingTaxes

        public Money getTotalIncludingTaxes()
        Calculates the order total always including taxes. This makes most sense in case of this order being in net mode when getTotal() will show order total without taxes only.
      • getLineItems

        public java.util.List<LineItem> getLineItems()
        Returns all line items attached to this order.
      • addLineItems

        public void addLineItems​(LineItem... lineItems)
        Attaches multiple line items to this order. Please note that each line item will receive a back reference to this order.
        Throws:
        CurrenciesAreNotEqualException - in case at least one line item has got a base price of different currency than the order currency
      • addLineItems

        public void addLineItems​(java.util.List<LineItem> lineItems)
        Attaches multiple line items to this order. Please note that each line item will receive a back reference to this order.
        Throws:
        CurrenciesAreNotEqualException - in case at least one line item has got a base price of different currency than the order currency
      • addLineItem

        public void addLineItem​(LineItem lineitem)
        Attaches a line items to this order. Please note that the line item will receive a back reference to this order.
        Throws:
        CurrenciesAreNotEqualException - in case the line item has got a base price of different currency than the order currency
      • addLineItem

        public void addLineItem​(int index,
                                LineItem lineitem)
        Attaches a line items to this order at the specified position. Please note that the line item will receive a back reference to this order.
        Parameters:
        index - insert the given line item into this position.
        lineitem - the line item to be added
        Throws:
        CurrenciesAreNotEqualException - in case the line item has got a base price of different currency than the order currency
      • clearLineItems

        public void clearLineItems()
        Removes all attached line items. Please note that these line items also lose their back reference to this order.
      • removeLineItem

        public void removeLineItem​(LineItem lineitem)
        Removes a single line item. Please note that the line items also lose its back reference to this order.
      • getTaxes

        public java.util.Collection<Tax> getTaxes()
        Returns all taxes assigned to this order.
      • addTaxes

        public void addTaxes​(Tax... taxes)
        Assigns multiple taxes to this order. Please note that each tax receives a back reference to this order.
        Throws:
        CurrenciesAreNotEqualException - in case there is at least one absolute tax having a different currency than the one of this order
      • addTaxes

        public void addTaxes​(java.util.Collection<Tax> taxes)
        Assigns multiple taxes to this order. Please note that each tax receives a back reference to this order.
        Throws:
        CurrenciesAreNotEqualException - in case there is at least one absolute tax having a different currency than the one of this order
      • addTax

        public void addTax​(Tax tax)
        Assigns a tax to this order. Please note that the tax receives a back reference to this order.
        Throws:
        CurrenciesAreNotEqualException - in case it's a absolute tax having a different currency than the one of this order
      • clearTaxes

        public void clearTaxes()
        Removes all attached taxes from this order. Please note that all back references to this order are cleared.
      • removeTax

        public void removeTax​(Tax tax)
        Removes the given tax from this order.
      • getDiscounts

        public java.util.List<OrderDiscount> getDiscounts()
        Returns all discounts attached to this order.
      • addDiscounts

        public void addDiscounts​(OrderDiscount... discounts)
        Assigns multiple discounts to this order. Please note that the discounts will receive a back reference to this order.
        Throws:
        CurrenciesAreNotEqualException - in case there is at least one absolute discount having a different currency than the one of this order
      • addDiscounts

        public void addDiscounts​(java.util.List<OrderDiscount> discounts)
        Assigns multiple discounts to this order. Please note that the discounts will receive a back reference to this order.
        Throws:
        CurrenciesAreNotEqualException - in case there is at least one absolute discount having a different currency than the one of this order
      • addDiscount

        public void addDiscount​(OrderDiscount discount)
        Assigns a discount to this order. Please note that the discount will receive a back reference to this order.
        Throws:
        CurrenciesAreNotEqualException - in case it's a absolute discount having a different currency than the one of this order
      • addDiscount

        public void addDiscount​(int index,
                                OrderDiscount discount)
        Assigns a discount to this order at a speific position. Please note that the discount will receive a back reference to this order.
        Throws:
        CurrenciesAreNotEqualException - in case it's a absolute discount having a different currency than the one of this order
      • clearDiscounts

        public void clearDiscounts()
        Removes all assigned discounts from this order. Please note that all back reference to this order are also cleared.
      • removeDiscount

        public void removeDiscount​(OrderDiscount orderDiscount)
        Removes a discount from this order. Please note that the back reference to this order isalso cleared.
      • getCharges

        public java.util.List<OrderCharge> getCharges()
        Returns all charges assigned to this order.
      • addCharges

        public void addCharges​(OrderCharge... charges)
        Assigns multiple charges to this order. Please note that each one will receive a back reference to this order.
        Throws:
        CurrenciesAreNotEqualException - in case at least one absolute charge is using a different currency than the one used for this order
      • addCharges

        public void addCharges​(java.util.List<OrderCharge> charges)
        Assigns multiple charges to this order. Please note that each one will receive a back reference to this order.
        Throws:
        CurrenciesAreNotEqualException - in case at least one absolute charge is using a different currency than the one used for this order
      • addCharge

        public void addCharge​(OrderCharge aoc)
        Assigns a single charge to this order. Please note that it will receive a back reference to this order.
        Throws:
        CurrenciesAreNotEqualException - in case it's a absolute charge using a different currency than the one used for this order
      • addCharge

        public void addCharge​(int index,
                              OrderCharge aoc)
        Assigns a single charge to this order at a specific position. Please note that it will receive a back reference to this order.
        Parameters:
        index - the position to add the charge at
        Throws:
        CurrenciesAreNotEqualException - in case it's a absolute charge using a different currency than the one used for this order
      • clearCharges

        public void clearCharges()
        Removes all assigned charges from this order. Please note that all back references are cleared as well.
      • removeCharge

        public void removeCharge​(OrderCharge aoc)
        Removes a charge from this order. Please note that the back reference is cleared as well.
      • hasLineItems

        public boolean hasLineItems()
        Tells whether or not this order has got line items.
      • hasCharges

        public boolean hasCharges()
        Tells whether this order has got assigned charges or not.
      • hasDisounts

        public boolean hasDisounts()
        Tells whether this order has got assigned discounts or not.
      • hasTaxes

        public boolean hasTaxes()
        Tells whether this order has got assigned taxes or not.
      • isNet

        public boolean isNet()
        Returns:
        true if this order is in net mode, returns false if the order is in gross mode.
      • isGross

        public boolean isGross()
        Returns:
        false if this order is in net mode, returns true if the order is in gross mode.
      • getCalculationStrategies

        public CalculationStrategies getCalculationStrategies()
        Delegate to all necessary strategies.
      • getCurrency

        public Currency getCurrency()
        Returns the currency which this order is being calculated for.