// 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;