Class DefaultCalculationService
- java.lang.Object
-
- de.hybris.platform.servicelayer.internal.service.AbstractService
-
- de.hybris.platform.servicelayer.internal.service.AbstractBusinessService
-
- de.hybris.platform.order.impl.DefaultCalculationService
-
- All Implemented Interfaces:
CalculationService,java.io.Serializable,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.InitializingBean
- Direct Known Subclasses:
DefaultC4CCalculationService,SapCartCalculationService
public class DefaultCalculationService extends AbstractBusinessService implements CalculationService
Default implementation of theCalculationService.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class de.hybris.platform.servicelayer.internal.service.AbstractService
AbstractService.SerializableDTO
-
-
Field Summary
-
Fields inherited from class de.hybris.platform.servicelayer.internal.service.AbstractBusinessService
modelService, sessionService, txManager
-
Fields inherited from class de.hybris.platform.servicelayer.internal.service.AbstractService
tenant
-
-
Constructor Summary
Constructors Constructor Description DefaultCalculationService()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidaddAbsoluteEntryTaxValue(long entryQuantity, TaxValue taxValue, java.util.Map<TaxValue,java.util.Map<java.util.Set<TaxValue>,java.lang.Double>> taxValueMap)protected voidaddRelativeEntryTaxValue(double entryTotal, TaxValue taxValue, java.util.Set<TaxValue> relativeEntryTaxValues, java.util.Map<TaxValue,java.util.Map<java.util.Set<TaxValue>,java.lang.Double>> taxValueMap)protected TaxValueapplyGrossMixedRate(TaxValue unappliedTaxValue, java.util.Map<java.util.Set<TaxValue>,java.lang.Double> taxGroups, int digits, double taxAdjustmentFactor)protected TaxValueapplyNetMixedRate(TaxValue unappliedTaxValue, java.util.Map<java.util.Set<TaxValue>,java.lang.Double> taxGroups, int digits, double taxAdjustmentFactor)voidcalculate(AbstractOrderModel order)Calculates the given order and all its entries unless they're already calculated and the order has not been modified.voidcalculate(AbstractOrderModel order, java.util.Date date)Calculates the given order and all its entries unless they're already calculated and the order has not been modified.protected TaxValuecalculateAbsoluteTotalTaxValue(CurrencyModel curr, java.lang.String currencyIso, int digits, boolean net, TaxValue taxValue, double cumulatedEntryQuantities)protected doublecalculateDiscountValues(AbstractOrderModel order, boolean recalculate)Returns the total discount for this abstract order.voidcalculateEntries(AbstractOrderModel order, boolean forceRecalculate)protected java.util.Map<TaxValue,java.util.Map<java.util.Set<TaxValue>,java.lang.Double>>calculateSubtotal(AbstractOrderModel order, boolean recalculate)voidcalculateTotals(AbstractOrderEntryModel entry, boolean recalculate)Recalculates given entries total prices and re-applies tax and discount values.voidcalculateTotals(AbstractOrderModel order, boolean recalculate)(re)calculates all totals for the given order.protected voidcalculateTotals(AbstractOrderModel order, boolean recalculate, java.util.Map<TaxValue,java.util.Map<java.util.Set<TaxValue>,java.lang.Double>> taxValueMap)calculates all totals.protected voidcalculateTotalTaxValues(AbstractOrderEntryModel entry)protected doublecalculateTotalTaxValues(AbstractOrderModel order, boolean recalculate, int digits, double taxAdjustmentFactor, java.util.Map<TaxValue,java.util.Map<java.util.Set<TaxValue>,java.lang.Double>> taxValueMap)protected java.util.ListconvertDiscountValues(AbstractOrderModel order, java.util.List dvs)PriceValueconvertPriceIfNecessary(PriceValue pv, boolean toNet, CurrencyModel toCurrency, java.util.Collection taxValues)converts a PriceValue object into a double matching the target currency and net/gross - state if necessary.protected PriceValuefindBasePrice(AbstractOrderEntryModel entry)protected java.util.List<DiscountValue>findDiscountValues(AbstractOrderEntryModel entry)protected java.util.List<DiscountValue>findGlobalDiscounts(AbstractOrderModel order)protected java.util.Collection<TaxValue>findTaxValues(AbstractOrderEntryModel entry)protected doublegetTaxCorrectionFactor(java.util.Map<TaxValue,java.util.Map<java.util.Set<TaxValue>,java.lang.Double>> taxValueMap, double subtotal, double total, AbstractOrderModel order)booleangetTaxFreeEntrySupport()Deprecated.since ages - useisTaxFreeEntrySupport()protected doublegetTaxFreeSubTotal(AbstractOrderModel order)Calculates the sub total of all order entries with NO tax values.protected java.util.Set<TaxValue>getUnappliedRelativeTaxValues(java.util.Collection<TaxValue> allTaxValues)protected booleanhasJaloStrategies()protected booleanisAllEntriesTaxed(java.util.Map<TaxValue,java.util.Map<java.util.Set<TaxValue>,java.lang.Double>> taxValueMap, double subtotal, AbstractOrderModel order)booleanisTaxFreeEntrySupport()protected booleanmustHandleTaxFreeEntries(java.util.Map<TaxValue,java.util.Map<java.util.Set<TaxValue>,java.lang.Double>> taxValueMap, double subtotal, AbstractOrderModel order)voidrecalculate(AbstractOrderEntryModel entry)Calculates this entry even if the entry was calculated before.voidrecalculate(AbstractOrderModel order)recalculates the whole order and all its entries.voidrecalculate(AbstractOrderModel order, java.util.Date date)recalculates the whole order and all its entries.protected voidrecalculateOrderEntryIfNeeded(AbstractOrderEntryModel entry, boolean forceRecalculation)protected voidrefreshOrder(AbstractOrderModel order)booleanrequiresCalculation(AbstractOrderModel order)ReturnBoolean.TRUEin case if order needs to be calculated.protected voidresetAdditionalCosts(AbstractOrderModel order, java.util.Collection<TaxValue> relativeTaxValues)protected voidresetAllValues(AbstractOrderEntryModel entry)protected java.util.MapresetAllValues(AbstractOrderModel order)protected voidsaveOrder(AbstractOrderModel order)protected voidsetCalculatedStatus(AbstractOrderEntryModel entry)protected voidsetCalculatedStatus(AbstractOrderModel order)voidsetCommonI18NService(CommonI18NService commonI18NService)voidsetFindDeliveryCostStrategy(FindDeliveryCostStrategy findDeliveryCostStrategy)voidsetFindDiscountsStrategies(java.util.List<FindDiscountValuesStrategy> findDiscountsStrategies)voidsetFindPaymentCostStrategy(FindPaymentCostStrategy findPaymentCostStrategy)voidsetFindPriceStrategy(FindPriceStrategy findPriceStrategy)voidsetFindTaxesStrategies(java.util.List<FindTaxValuesStrategy> findTaxesStrategies)voidsetOrderRequiresCalculationStrategy(OrderRequiresCalculationStrategy orderRequiresCalculationStrategy)voidsetTaxFreeEntrySupport(boolean taxFreeEntrySupport)-
Methods inherited from class de.hybris.platform.servicelayer.internal.service.AbstractBusinessService
getModelService, getSessionService, getTxManager, setModelService, setSessionService, setTxManager
-
Methods inherited from class de.hybris.platform.servicelayer.internal.service.AbstractService
afterPropertiesSet, getCurrentTenant, setBeanName, setCurrentTenant, writeReplace
-
-
-
-
Method Detail
-
calculate
public void calculate(AbstractOrderModel order) throws CalculationException
Description copied from interface:CalculationServiceCalculates 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
CalculationService.calculateTotals(AbstractOrderModel, boolean)instead (e.g. if just a quantity has changed or prices have been imported and cannot be found via price factory ).- Specified by:
calculatein interfaceCalculationService- Parameters:
order- targetAbstractOrderModel- Throws:
CalculationException- if a pricefactory error occurred.
-
requiresCalculation
public boolean requiresCalculation(AbstractOrderModel order)
Description copied from interface:CalculationServiceReturnBoolean.TRUEin case if order needs to be calculated. Default implementation use calculationStrategy to get this information.- Specified by:
requiresCalculationin interfaceCalculationService
-
setCalculatedStatus
protected void setCalculatedStatus(AbstractOrderModel order)
-
setCalculatedStatus
protected void setCalculatedStatus(AbstractOrderEntryModel entry)
-
calculate
public void calculate(AbstractOrderModel order, java.util.Date date) throws CalculationException
Description copied from interface:CalculationServiceCalculates 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
CalculationService.calculateTotals(AbstractOrderModel, boolean)instead (e.g. if just a quantity has changed or prices have been imported and cannot be found via price factory ).- Specified by:
calculatein interfaceCalculationService- Parameters:
order- targetAbstractOrderModeldate- 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
-
calculateTotals
public void calculateTotals(AbstractOrderModel order, boolean recalculate) throws CalculationException
Description copied from interface:CalculationService(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.- Specified by:
calculateTotalsin interfaceCalculationService- Parameters:
order- targetAbstractOrderModelrecalculate- forces setting total even if order is marked as calculated- Throws:
CalculationException
-
calculateTotals
protected void calculateTotals(AbstractOrderModel order, boolean recalculate, java.util.Map<TaxValue,java.util.Map<java.util.Set<TaxValue>,java.lang.Double>> taxValueMap) throws CalculationException
calculates all totals. this does not trigger price, tax and discount calculation but takes all currently set price, tax and discount values as base. this method requires the correct subtotal to be set before and the correct tax value map.- Parameters:
recalculate- if false calculation is done only if the calculated flag is not settaxValueMap- the map { tax value -> Double( sum of all entry totals for this tax ) } obtainable viacalculateSubtotal(AbstractOrderModel, boolean)- Throws:
CalculationException
-
saveOrder
protected void saveOrder(AbstractOrderModel order)
-
getTaxCorrectionFactor
protected double getTaxCorrectionFactor(java.util.Map<TaxValue,java.util.Map<java.util.Set<TaxValue>,java.lang.Double>> taxValueMap, double subtotal, double total, AbstractOrderModel order) throws CalculationException
- Throws:
CalculationException
-
mustHandleTaxFreeEntries
protected boolean mustHandleTaxFreeEntries(java.util.Map<TaxValue,java.util.Map<java.util.Set<TaxValue>,java.lang.Double>> taxValueMap, double subtotal, AbstractOrderModel order)
-
getTaxFreeSubTotal
protected double getTaxFreeSubTotal(AbstractOrderModel order)
Calculates the sub total of all order entries with NO tax values.
-
isAllEntriesTaxed
protected boolean isAllEntriesTaxed(java.util.Map<TaxValue,java.util.Map<java.util.Set<TaxValue>,java.lang.Double>> taxValueMap, double subtotal, AbstractOrderModel order)
-
recalculate
public void recalculate(AbstractOrderModel order) throws CalculationException
Description copied from interface:CalculationServicerecalculates 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
CalculationService.calculateTotals(AbstractOrderModel, boolean)instead (e.g. if just a quantity has changed or prices have been imported and cannot be found via price factory ).- Specified by:
recalculatein interfaceCalculationService- Parameters:
order- targetAbstractOrderModel- Throws:
CalculationException- if a pricefactory error occurred.
-
recalculate
public void recalculate(AbstractOrderModel order, java.util.Date date) throws CalculationException
Description copied from interface:CalculationServicerecalculates 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
CalculationService.calculateTotals(AbstractOrderModel, boolean)instead (e.g. if just a quantity has changed or prices have been imported and cannot be found via price factory ).- Specified by:
recalculatein interfaceCalculationService- Parameters:
order- targetAbstractOrderModeldate- the date to calculate prices for- Throws:
CalculationException- if a pricefactory error occurred
-
calculateEntries
public void calculateEntries(AbstractOrderModel order, boolean forceRecalculate) throws CalculationException
- Throws:
CalculationException
-
calculateTotals
public void calculateTotals(AbstractOrderEntryModel entry, boolean recalculate)
Description copied from interface:CalculationServiceRecalculates 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.- Specified by:
calculateTotalsin interfaceCalculationService- Parameters:
entry- targetAbstractOrderEntryModelrecalculate- forces the recalculation of the abstract order entry.
-
hasJaloStrategies
protected boolean hasJaloStrategies()
-
calculateTotalTaxValues
protected void calculateTotalTaxValues(AbstractOrderEntryModel entry)
-
recalculateOrderEntryIfNeeded
protected void recalculateOrderEntryIfNeeded(AbstractOrderEntryModel entry, boolean forceRecalculation) throws CalculationException
- Throws:
CalculationException
-
recalculate
public void recalculate(AbstractOrderEntryModel entry) throws CalculationException
Description copied from interface:CalculationServiceCalculates 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
CalculationService.calculateTotals(AbstractOrderEntryModel, boolean)instead !- Specified by:
recalculatein interfaceCalculationService- Parameters:
entry- targetAbstractOrderEntryModel- Throws:
CalculationException- if a pricefactory error occurred
-
refreshOrder
protected void refreshOrder(AbstractOrderModel order)
-
resetAllValues
protected void resetAllValues(AbstractOrderEntryModel entry) throws CalculationException
- Throws:
CalculationException
-
resetAllValues
protected java.util.Map resetAllValues(AbstractOrderModel order) throws CalculationException
- Throws:
CalculationException
-
resetAdditionalCosts
protected void resetAdditionalCosts(AbstractOrderModel order, java.util.Collection<TaxValue> relativeTaxValues)
-
convertPriceIfNecessary
public PriceValue convertPriceIfNecessary(PriceValue pv, boolean toNet, CurrencyModel toCurrency, java.util.Collection taxValues)
converts a PriceValue object into a double matching the target currency and net/gross - state if necessary. this is the case when the given price value has a different net/gross flag or different currency.- Parameters:
pv- the base price to converttoNet- the target net/gross statetoCurrency- the target currencytaxValues- the collection of tax values which apply to this price- Returns:
- a new PriceValue containing the converted price or pv in case no conversion was necessary
-
convertDiscountValues
protected java.util.List convertDiscountValues(AbstractOrderModel order, java.util.List dvs)
-
calculateSubtotal
protected java.util.Map<TaxValue,java.util.Map<java.util.Set<TaxValue>,java.lang.Double>> calculateSubtotal(AbstractOrderModel order, boolean recalculate)
-
calculateDiscountValues
protected double calculateDiscountValues(AbstractOrderModel order, boolean recalculate)
Returns the total discount for this abstract order.- Parameters:
recalculate-trueforces a recalculation- Returns:
- totalDiscounts
-
calculateTotalTaxValues
protected double calculateTotalTaxValues(AbstractOrderModel order, boolean recalculate, int digits, double taxAdjustmentFactor, java.util.Map<TaxValue,java.util.Map<java.util.Set<TaxValue>,java.lang.Double>> taxValueMap)
- Parameters:
recalculate-digits-taxAdjustmentFactor-taxValueMap-- Returns:
- total taxes
-
addRelativeEntryTaxValue
protected void addRelativeEntryTaxValue(double entryTotal, TaxValue taxValue, java.util.Set<TaxValue> relativeEntryTaxValues, java.util.Map<TaxValue,java.util.Map<java.util.Set<TaxValue>,java.lang.Double>> taxValueMap)
-
addAbsoluteEntryTaxValue
protected void addAbsoluteEntryTaxValue(long entryQuantity, TaxValue taxValue, java.util.Map<TaxValue,java.util.Map<java.util.Set<TaxValue>,java.lang.Double>> taxValueMap)
-
getUnappliedRelativeTaxValues
protected java.util.Set<TaxValue> getUnappliedRelativeTaxValues(java.util.Collection<TaxValue> allTaxValues)
-
calculateAbsoluteTotalTaxValue
protected TaxValue calculateAbsoluteTotalTaxValue(CurrencyModel curr, java.lang.String currencyIso, int digits, boolean net, TaxValue taxValue, double cumulatedEntryQuantities)
-
applyGrossMixedRate
protected TaxValue applyGrossMixedRate(TaxValue unappliedTaxValue, java.util.Map<java.util.Set<TaxValue>,java.lang.Double> taxGroups, int digits, double taxAdjustmentFactor)
-
applyNetMixedRate
protected TaxValue applyNetMixedRate(TaxValue unappliedTaxValue, java.util.Map<java.util.Set<TaxValue>,java.lang.Double> taxGroups, int digits, double taxAdjustmentFactor)
-
findTaxValues
protected java.util.Collection<TaxValue> findTaxValues(AbstractOrderEntryModel entry) throws CalculationException
- Throws:
CalculationException
-
findDiscountValues
protected java.util.List<DiscountValue> findDiscountValues(AbstractOrderEntryModel entry) throws CalculationException
- Throws:
CalculationException
-
findGlobalDiscounts
protected java.util.List<DiscountValue> findGlobalDiscounts(AbstractOrderModel order) throws CalculationException
- Throws:
CalculationException
-
findBasePrice
protected PriceValue findBasePrice(AbstractOrderEntryModel entry) throws CalculationException
- Throws:
CalculationException
-
setCommonI18NService
public void setCommonI18NService(CommonI18NService commonI18NService)
-
setFindTaxesStrategies
public void setFindTaxesStrategies(java.util.List<FindTaxValuesStrategy> findTaxesStrategies)
-
setFindDiscountsStrategies
public void setFindDiscountsStrategies(java.util.List<FindDiscountValuesStrategy> findDiscountsStrategies)
-
setFindPriceStrategy
public void setFindPriceStrategy(FindPriceStrategy findPriceStrategy)
-
setFindDeliveryCostStrategy
public void setFindDeliveryCostStrategy(FindDeliveryCostStrategy findDeliveryCostStrategy)
-
setFindPaymentCostStrategy
public void setFindPaymentCostStrategy(FindPaymentCostStrategy findPaymentCostStrategy)
-
setOrderRequiresCalculationStrategy
public void setOrderRequiresCalculationStrategy(OrderRequiresCalculationStrategy orderRequiresCalculationStrategy)
-
setTaxFreeEntrySupport
public void setTaxFreeEntrySupport(boolean taxFreeEntrySupport)
-
getTaxFreeEntrySupport
@Deprecated public boolean getTaxFreeEntrySupport()
Deprecated.since ages - useisTaxFreeEntrySupport()
-
isTaxFreeEntrySupport
public boolean isTaxFreeEntrySupport()
-
-