Interface CalculationService

All Known Implementing Classes:
DefaultCalculationService

public interface CalculationService
Service allows calculation or recalculation of the order. This includes calculation of all the entries, taxes and discount values. Information about price, taxes and discounts are fetched using dedicated strategies : FindDiscountValuesStrategy, FindTaxValuesStrategy, FindPriceStrategy. Also payment and delivery costs are resolved using strategies FindDeliveryCostStrategy and FindPaymentCostStrategy.

Whether order needs to be calculated or not is up to the implementation of OrderRequiresCalculationStrategy. All methods should be executed in transaction.

  • Method Details

    • calculate

      void calculate(AbstractOrderModel order) throws CalculationException
      Calculates the given order and all its entries unless they're already calculated and the order has not been modified.

      So this method will fetch prices, taxes and discounts (using spring configurable strategies) for uncalculated or modified entries only - all other will remain unchanged. If at least one entry has been calculated or the order itself has been modified the totals will be calculated as well.

      if you merely like to adjust totals while keeping prices, taxes and discounts you should call calculateTotals(AbstractOrderModel, boolean) instead (e.g. if just a quantity has changed or prices have been imported and cannot be found via price factory ).

      Parameters:
      order - target AbstractOrderModel
      Throws:
      CalculationException - if a pricefactory error occurred.
    • requiresCalculation

      boolean requiresCalculation(AbstractOrderModel order)
      Return Boolean.TRUE in case if order needs to be calculated. Default implementation use calculationStrategy to get this information.
    • calculate

      void calculate(AbstractOrderModel order, Date date) throws CalculationException
      Calculates the given order and all its entries unless they're already calculated and the order has not been modified.

      So this method will fetch prices, taxes and discounts (using spring configured strategies) for uncalculated or modified entries only - all other will remain unchanged. If at least one entry has been calculated or the order itself has been modified the totals will be calculated as well.

      if you merely like to adjust totals while keeping prices, taxes and discounts you should call calculateTotals(AbstractOrderModel, boolean) instead (e.g. if just a quantity has changed or prices have been imported and cannot be found via price factory ).

      Parameters:
      order - target AbstractOrderModel
      date - assumes a given date to perform calculations for - be careful with that since this method will calculate modified or uncalculated entries only, so the given date may not apply to all entries!
      Throws:
      CalculationException - if a pricefactory error occurred
    • recalculate

      void recalculate(AbstractOrderModel order) throws CalculationException
      recalculates the whole order and all its entries. this includes finding prices, taxes, discounts, payment and delivery costs by calling the currently installed price factory.

      if you merely like to adjust totals while keeping prices, taxes and discounts you should call calculateTotals(AbstractOrderModel, boolean) instead (e.g. if just a quantity has changed or prices have been imported and cannot be found via price factory ).

      Parameters:
      order - target AbstractOrderModel
      Throws:
      CalculationException - if a pricefactory error occurred.
    • recalculate

      void recalculate(AbstractOrderModel order, Date date) throws CalculationException
      recalculates the whole order and all its entries. this includes finding prices, taxes, discounts, payment and delivery costs by calling the currently installed dedicated strategies ( FindPriceStrategy, FindDeliveryCostStrategy, FindTaxValuesStrategy, etc... ).

      if you merely like to adjust totals while keeping prices, taxes and discounts you should call calculateTotals(AbstractOrderModel, boolean) instead (e.g. if just a quantity has changed or prices have been imported and cannot be found via price factory ).

      Parameters:
      order - target AbstractOrderModel
      date - the date to calculate prices for
      Throws:
      CalculationException - if a pricefactory error occurred
    • calculateTotals

      void calculateTotals(AbstractOrderModel order, boolean recalculate) throws CalculationException
      (re)calculates all totals for the given order. This does not trigger price, tax and discount calculation but takes all currently set price, tax and discount values as base.
      Parameters:
      order - target AbstractOrderModel
      recalculate - forces setting total even if order is marked as calculated
      Throws:
      CalculationException
    • calculateTotals

      void calculateTotals(AbstractOrderEntryModel entry, boolean recalculate)
      Recalculates given entries total prices and re-applies tax and discount values. This does not include finding price, taxes or discount but uses all currently set values.
      Parameters:
      entry - target AbstractOrderEntryModel
      recalculate - forces the recalculation of the abstract order entry.
    • recalculate

      void recalculate(AbstractOrderEntryModel entry) throws CalculationException
      Calculates this entry even if the entry was calculated before. This includes finding the correct base price, taxes and discount using the currently installed price factory.

      If prices should be left as currently set but the entry totals have to be consolidated (e.g. when the quantity has changed) call calculateTotals(AbstractOrderEntryModel, boolean) instead !

      Parameters:
      entry - target AbstractOrderEntryModel
      Throws:
      CalculationException - if a pricefactory error occurred