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);
}
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;
}
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;
}
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;
}
Aggregations