Search in sources :

Example 1 with FulfillmentGroupFee

use of org.broadleafcommerce.core.order.domain.FulfillmentGroupFee in project BroadleafCommerce by BroadleafCommerce.

the class TotalActivity method setTaxSums.

protected void setTaxSums(Order order) {
    if (order.getTaxOverride()) {
        Money zeroMoney = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getCurrency());
        for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
            if (fg.getTaxes() != null) {
                fg.getTaxes().clear();
            }
            fg.setTotalTax(zeroMoney);
            for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
                if (fgi.getTaxes() != null) {
                    fgi.getTaxes().clear();
                }
                fgi.setTotalTax(zeroMoney);
            }
            for (FulfillmentGroupFee fee : fg.getFulfillmentGroupFees()) {
                if (fee.getTaxes() != null) {
                    fee.getTaxes().clear();
                }
                fee.setTotalTax(zeroMoney);
            }
            fg.setTotalFulfillmentGroupTax(zeroMoney);
            fg.setTotalItemTax(zeroMoney);
            fg.setTotalFeeTax(zeroMoney);
        }
        order.setTotalTax(zeroMoney);
        return;
    }
    Money orderTotalTax = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getCurrency());
    for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
        Money fgTotalFgTax = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getCurrency());
        Money fgTotalItemTax = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getCurrency());
        Money fgTotalFeeTax = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getCurrency());
        // Add in all FG specific taxes (such as shipping tax)
        if (fg.getTaxes() != null) {
            for (TaxDetail tax : fg.getTaxes()) {
                fgTotalFgTax = fgTotalFgTax.add(tax.getAmount());
            }
        }
        for (FulfillmentGroupItem item : fg.getFulfillmentGroupItems()) {
            Money itemTotalTax = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getCurrency());
            // Add in all taxes for this item
            if (item.getTaxes() != null) {
                for (TaxDetail tax : item.getTaxes()) {
                    itemTotalTax = itemTotalTax.add(tax.getAmount());
                }
            }
            item.setTotalTax(itemTotalTax);
            fgTotalItemTax = fgTotalItemTax.add(itemTotalTax);
        }
        for (FulfillmentGroupFee fee : fg.getFulfillmentGroupFees()) {
            Money feeTotalTax = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getCurrency());
            // Add in all taxes for this fee
            if (fee.getTaxes() != null) {
                for (TaxDetail tax : fee.getTaxes()) {
                    feeTotalTax = feeTotalTax.add(tax.getAmount());
                }
            }
            fee.setTotalTax(feeTotalTax);
            fgTotalFeeTax = fgTotalFeeTax.add(feeTotalTax);
        }
        Money fgTotalTax = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getCurrency()).add(fgTotalFgTax).add(fgTotalItemTax).add(fgTotalFeeTax);
        // Set the fulfillment group tax sums
        fg.setTotalFulfillmentGroupTax(fgTotalFgTax);
        fg.setTotalItemTax(fgTotalItemTax);
        fg.setTotalFeeTax(fgTotalFeeTax);
        fg.setTotalTax(fgTotalTax);
        orderTotalTax = orderTotalTax.add(fgTotalTax);
    }
    order.setTotalTax(orderTotalTax);
}
Also used : Money(org.broadleafcommerce.common.money.Money) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) FulfillmentGroupFee(org.broadleafcommerce.core.order.domain.FulfillmentGroupFee) TaxDetail(org.broadleafcommerce.core.order.domain.TaxDetail)

Example 2 with FulfillmentGroupFee

use of org.broadleafcommerce.core.order.domain.FulfillmentGroupFee in project BroadleafCommerce by BroadleafCommerce.

the class SimpleTaxProvider method calculateTaxForOrder.

@Override
public Order calculateTaxForOrder(Order order, ModuleConfiguration config) throws TaxException {
    if (!order.getCustomer().isTaxExempt()) {
        for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
            // Set taxes on the fulfillment group items
            for (FulfillmentGroupItem fgItem : fulfillmentGroup.getFulfillmentGroupItems()) {
                if (isItemTaxable(fgItem)) {
                    BigDecimal factor = determineItemTaxRate(fulfillmentGroup.getAddress());
                    if (factor != null && factor.compareTo(BigDecimal.ZERO) != 0) {
                        TaxDetail tax;
                        checkDetail: {
                            for (TaxDetail detail : fgItem.getTaxes()) {
                                if (detail.getType().equals(TaxType.COMBINED)) {
                                    tax = detail;
                                    break checkDetail;
                                }
                            }
                            tax = entityConfig.createEntityInstance(TaxDetail.class.getName(), TaxDetail.class);
                            tax.setType(TaxType.COMBINED);
                            fgItem.getTaxes().add(tax);
                        }
                        tax.setRate(factor);
                        tax.setAmount(fgItem.getTotalItemTaxableAmount().multiply(factor));
                    }
                }
            }
            for (FulfillmentGroupFee fgFee : fulfillmentGroup.getFulfillmentGroupFees()) {
                if (isFeeTaxable(fgFee)) {
                    BigDecimal factor = determineItemTaxRate(fulfillmentGroup.getAddress());
                    if (factor != null && factor.compareTo(BigDecimal.ZERO) != 0) {
                        TaxDetail tax;
                        checkDetail: {
                            for (TaxDetail detail : fgFee.getTaxes()) {
                                if (detail.getType().equals(TaxType.COMBINED)) {
                                    tax = detail;
                                    break checkDetail;
                                }
                            }
                            tax = entityConfig.createEntityInstance(TaxDetail.class.getName(), TaxDetail.class);
                            tax.setType(TaxType.COMBINED);
                            fgFee.getTaxes().add(tax);
                        }
                        tax.setRate(factor);
                        tax.setAmount(fgFee.getAmount().multiply(factor));
                    }
                }
            }
            BigDecimal factor = determineTaxRateForFulfillmentGroup(fulfillmentGroup);
            if (factor != null && factor.compareTo(BigDecimal.ZERO) != 0) {
                TaxDetail tax;
                checkDetail: {
                    for (TaxDetail detail : fulfillmentGroup.getTaxes()) {
                        if (detail.getType().equals(TaxType.COMBINED)) {
                            tax = detail;
                            break checkDetail;
                        }
                    }
                    tax = entityConfig.createEntityInstance(TaxDetail.class.getName(), TaxDetail.class);
                    tax.setType(TaxType.COMBINED);
                    fulfillmentGroup.getTaxes().add(tax);
                }
                tax.setRate(factor);
                tax.setAmount(fulfillmentGroup.getFulfillmentPrice().multiply(factor));
            }
        }
    }
    return order;
}
Also used : FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) TaxDetail(org.broadleafcommerce.core.order.domain.TaxDetail) FulfillmentGroupFee(org.broadleafcommerce.core.order.domain.FulfillmentGroupFee) BigDecimal(java.math.BigDecimal)

Example 3 with FulfillmentGroupFee

use of org.broadleafcommerce.core.order.domain.FulfillmentGroupFee in project BroadleafCommerce by BroadleafCommerce.

the class ConsolidateFulfillmentFeesActivity method execute.

@Override
public ProcessContext<Order> execute(ProcessContext<Order> context) throws Exception {
    Order order = context.getSeedData();
    for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
        // create and associate all the Fulfillment Fees
        for (FulfillmentGroupItem item : fulfillmentGroup.getFulfillmentGroupItems()) {
            List<SkuFee> fees = null;
            if (item.getOrderItem() instanceof BundleOrderItem) {
                fees = ((BundleOrderItem) item.getOrderItem()).getSku().getFees();
            } else if (item.getOrderItem() instanceof DiscreteOrderItem) {
                fees = ((DiscreteOrderItem) item.getOrderItem()).getSku().getFees();
            }
            if (fees != null) {
                for (SkuFee fee : fees) {
                    if (SkuFeeType.FULFILLMENT.equals(fee.getFeeType())) {
                        if (shouldApplyFeeToFulfillmentGroup(fee, fulfillmentGroup)) {
                            FulfillmentGroupFee fulfillmentFee = fulfillmentGroupService.createFulfillmentGroupFee();
                            fulfillmentFee.setName(fee.getName());
                            fulfillmentFee.setTaxable(fee.getTaxable());
                            fulfillmentFee.setAmount(fee.getAmount());
                            fulfillmentFee.setFulfillmentGroup(fulfillmentGroup);
                            fulfillmentGroup.addFulfillmentGroupFee(fulfillmentFee);
                        }
                    }
                }
            }
        }
        if (fulfillmentGroup.getFulfillmentGroupFees().size() > 0) {
            fulfillmentGroup = fulfillmentGroupService.save(fulfillmentGroup);
        }
    }
    context.setSeedData(order);
    return context;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) SkuFee(org.broadleafcommerce.core.catalog.domain.SkuFee) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) FulfillmentGroupFee(org.broadleafcommerce.core.order.domain.FulfillmentGroupFee)

Example 4 with FulfillmentGroupFee

use of org.broadleafcommerce.core.order.domain.FulfillmentGroupFee 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;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) FulfillmentGroupFee(org.broadleafcommerce.core.order.domain.FulfillmentGroupFee)

Aggregations

FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)4 FulfillmentGroupFee (org.broadleafcommerce.core.order.domain.FulfillmentGroupFee)4 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)3 Money (org.broadleafcommerce.common.money.Money)2 Order (org.broadleafcommerce.core.order.domain.Order)2 TaxDetail (org.broadleafcommerce.core.order.domain.TaxDetail)2 BigDecimal (java.math.BigDecimal)1 SkuFee (org.broadleafcommerce.core.catalog.domain.SkuFee)1 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)1 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)1