use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupOfferProcessorImpl method compareAndAdjustFulfillmentGroupOffers.
protected boolean compareAndAdjustFulfillmentGroupOffers(PromotableOrder order, boolean fgOfferApplied) {
Money regularOrderDiscountShippingTotal = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getOrderCurrency());
regularOrderDiscountShippingTotal = regularOrderDiscountShippingTotal.add(order.calculateSubtotalWithoutAdjustments());
for (PromotableFulfillmentGroup fg : order.getFulfillmentGroups()) {
regularOrderDiscountShippingTotal = regularOrderDiscountShippingTotal.add(fg.getFinalizedPriceWithAdjustments());
}
Money discountOrderRegularShippingTotal = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getOrderCurrency());
discountOrderRegularShippingTotal = discountOrderRegularShippingTotal.add(order.calculateSubtotalWithAdjustments());
for (PromotableFulfillmentGroup fg : order.getFulfillmentGroups()) {
discountOrderRegularShippingTotal = discountOrderRegularShippingTotal.add(fg.calculatePriceWithoutAdjustments());
}
if (discountOrderRegularShippingTotal.lessThan(regularOrderDiscountShippingTotal)) {
// order/item offer is better; remove totalitarian fulfillment group offer and process other fg offers
order.removeAllCandidateFulfillmentOfferAdjustments();
fgOfferApplied = false;
} else {
// totalitarian fg offer is better; remove all order/item offers
order.removeAllCandidateOrderOfferAdjustments();
order.removeAllCandidateItemOfferAdjustments();
order.getOrder().setSubTotal(order.calculateSubtotalWithAdjustments());
}
return fgOfferApplied;
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class ItemOfferProcessorImpl method calculatePotentialSavings.
/**
* This method determines the potential savings for each item offer as if it was the only item offer being applied.
* @param itemOffers
* @param order
*/
protected void calculatePotentialSavings(List<PromotableCandidateItemOffer> itemOffers, PromotableOrder order) {
if (itemOffers.size() > 1) {
for (PromotableCandidateItemOffer itemOffer : itemOffers) {
Money potentialSavings = new Money(order.getOrderCurrency());
Offer offer = itemOffer.getOffer();
BigDecimal calculatedWeightedPercent = new BigDecimal(0);
markQualifiersAndTargets(order, itemOffer);
for (PromotableOrderItemPriceDetail detail : order.getAllPromotableOrderItemPriceDetails()) {
PromotableOrderItem item = detail.getPromotableOrderItem();
for (PromotionDiscount discount : detail.getPromotionDiscounts()) {
Money itemSavings = calculatePotentialSavingsForOrderItem(itemOffer, item, discount.getQuantity());
potentialSavings = potentialSavings.add(itemSavings);
if (useCalculatePercent(offer)) {
BigDecimal discountPercent = calculatePercent(item.calculateTotalWithoutAdjustments(), itemSavings);
calculatedWeightedPercent = calculatedWeightedPercent.add(discountPercent);
} else if (hasQualifierAndQualifierRestricted(offer)) {
BigDecimal discountPercent = calculateWeightedPercent(discount, item, itemSavings);
calculatedWeightedPercent = calculatedWeightedPercent.add(discountPercent);
}
}
// Reset state back for next offer
detail.getPromotionDiscounts().clear();
detail.getPromotionQualifiers().clear();
}
itemOffer.setPotentialSavings(potentialSavings);
if (usePercentOffValue(offer)) {
itemOffer.setWeightedPercentSaved(offer.getValue());
} else if (useCalculatePercent(offer) || hasQualifierAndQualifierRestricted(offer)) {
itemOffer.setWeightedPercentSaved(calculatedWeightedPercent);
}
if (itemOffer.getUses() == 0) {
itemOffer.setPotentialSavingsQtyOne(potentialSavings);
} else {
itemOffer.setPotentialSavingsQtyOne(potentialSavings.divide(itemOffer.getUses()));
}
}
}
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class OrderOfferProcessorImpl method compareAndAdjustOrderAndItemOffers.
/**
* Called when the system must determine whether to apply order or item adjustments.
* @param promotableOrder
* @param orderOffersApplied
*/
protected void compareAndAdjustOrderAndItemOffers(PromotableOrder promotableOrder) {
Money orderAdjustmentTotal = promotableOrder.calculateOrderAdjustmentTotal();
Money itemAdjustmentTotal = promotableOrder.calculateItemAdjustmentTotal();
if (orderAdjustmentTotal.greaterThanOrEqual(itemAdjustmentTotal)) {
promotableOrder.removeAllCandidateItemOfferAdjustments();
} else {
promotableOrder.removeAllCandidateOrderOfferAdjustments();
}
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class PromotableFulfillmentGroupImpl method chooseSaleOrRetailAdjustments.
/**
* This method will check to see if the salePriceAdjustments or retailPriceAdjustments are better
* and remove those that should not apply.
* @return
*/
public void chooseSaleOrRetailAdjustments() {
this.useSaleAdjustments = Boolean.FALSE;
Money saleAdjustmentPrice = calculateSaleAdjustmentPrice();
Money retailAdjustmentPrice = calculateRetailAdjustmentPrice();
if (saleAdjustmentPrice.lessThan(retailAdjustmentPrice)) {
this.useSaleAdjustments = Boolean.TRUE;
adjustedPrice = saleAdjustmentPrice;
} else {
adjustedPrice = retailAdjustmentPrice;
}
if (useSaleAdjustments) {
removeRetailOnlyAdjustments();
}
removeZeroDollarAdjustments(useSaleAdjustments);
finalizeAdjustments(useSaleAdjustments);
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class PromotableOfferUtility method computeAdjustmentValue.
public static Money computeAdjustmentValue(Money currentPriceDetailValue, BigDecimal offerUnitValue, OfferHolder offerHolder, PromotionRounding rounding) {
Offer offer = offerHolder.getOffer();
BroadleafCurrency currency = offerHolder.getCurrency();
OfferDiscountType discountType = offer.getDiscountType();
Money adjustmentValue;
if (currency != null) {
adjustmentValue = new Money(currency);
} else {
adjustmentValue = new Money();
}
if (OfferDiscountType.AMOUNT_OFF.equals(discountType)) {
adjustmentValue = new Money(offerUnitValue, currency);
}
if (OfferDiscountType.FIX_PRICE.equals(discountType)) {
adjustmentValue = currentPriceDetailValue.subtract(new Money(offerUnitValue, currency));
}
if (OfferDiscountType.PERCENT_OFF.equals(discountType)) {
BigDecimal offerValue = currentPriceDetailValue.getAmount().multiply(offerUnitValue.divide(new BigDecimal("100"), 5, RoundingMode.HALF_EVEN));
if (rounding.isRoundOfferValues()) {
offerValue = offerValue.setScale(rounding.getRoundingScale(), rounding.getRoundingMode());
}
adjustmentValue = new Money(offerValue, currency);
}
if (currentPriceDetailValue.lessThan(adjustmentValue)) {
adjustmentValue = currentPriceDetailValue;
}
return adjustmentValue;
}
Aggregations