use of org.broadleafcommerce.core.order.domain.FulfillmentGroup in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentItemPricingActivity method fixOrderSavingsRoundingIssues.
/**
* It is possible due to rounding that the order adjustments do not match the
* total. This method fixes by adding or removing the pennies.
* @param order
* @param partialOrderItemMap
*/
protected void fixOrderSavingsRoundingIssues(Order order, Money totalOrderAdjustmentDistributed) {
if (!order.getHasOrderAdjustments()) {
return;
}
Money orderAdjustmentTotal = order.getOrderAdjustmentsValue();
Money amountDiff = orderAdjustmentTotal.subtract(totalOrderAdjustmentDistributed);
if (!(amountDiff.getAmount().compareTo(BigDecimal.ZERO) == 0)) {
long numApplicationsNeeded = countNumberOfUnits(amountDiff);
Money unitAmount = getUnitAmount(amountDiff);
for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
for (FulfillmentGroupItem fgItem : fulfillmentGroup.getFulfillmentGroupItems()) {
numApplicationsNeeded = numApplicationsNeeded - applyDifferenceToProratedAdj(fgItem, numApplicationsNeeded, unitAmount);
if (numApplicationsNeeded == 0) {
break;
}
}
}
}
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroup in project BroadleafCommerce by BroadleafCommerce.
the class TotalActivity method execute.
@Override
public ProcessContext<Order> execute(ProcessContext<Order> context) throws Exception {
Order order = context.getSeedData();
setTaxSums(order);
Money total = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getCurrency());
total = total.add(order.getSubTotal());
total = total.subtract(order.getOrderAdjustmentsValue());
total = total.add(order.getTotalShipping());
// There may not be any taxes on the order
if (order.getTotalTax() != null) {
total = total.add(order.getTotalTax());
}
Money fees = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getCurrency());
for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
Money fgTotal = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getCurrency());
fgTotal = fgTotal.add(fulfillmentGroup.getMerchandiseTotal());
fgTotal = fgTotal.add(fulfillmentGroup.getShippingPrice());
fgTotal = fgTotal.add(fulfillmentGroup.getTotalTax());
for (FulfillmentGroupFee fulfillmentGroupFee : fulfillmentGroup.getFulfillmentGroupFees()) {
fgTotal = fgTotal.add(fulfillmentGroupFee.getAmount());
fees = fees.add(fulfillmentGroupFee.getAmount());
}
fulfillmentGroup.setTotal(fgTotal);
}
total = total.add(fees);
order.setTotal(total);
context.setSeedData(order);
return context;
}
Aggregations