wip
This commit is contained in:
@@ -20,14 +20,24 @@ public class LineCalculator {
|
||||
|
||||
if (currentItem.getItemAllowances() != null && currentItem.getItemAllowances().length > 0) {
|
||||
for (IZUGFeRDAllowanceCharge allowance : currentItem.getItemAllowances()) {
|
||||
BigDecimal factor=BigDecimal.ONE;
|
||||
BigDecimal singleAllowance=allowance.getTotalAmount(currentItem);
|
||||
addAllowance(singleAllowance.multiply(currentItem.getQuantity()));
|
||||
if ((allowance.getPercent()!=null)&&(allowance.getPercent().compareTo(BigDecimal.ZERO)!=0)) {
|
||||
factor=allowance.getPercent().divide(new BigDecimal(100), 18, RoundingMode.HALF_UP);
|
||||
}
|
||||
addAllowance(singleAllowance.multiply(factor));
|
||||
|
||||
}
|
||||
}
|
||||
if (currentItem.getItemCharges() != null && currentItem.getItemCharges().length > 0) {
|
||||
for (IZUGFeRDAllowanceCharge charge : currentItem.getItemCharges()) {
|
||||
BigDecimal factor=BigDecimal.ONE;
|
||||
BigDecimal singleCharge=charge.getTotalAmount(currentItem);
|
||||
addCharge(singleCharge.multiply(currentItem.getQuantity()));
|
||||
if ((charge.getPercent()!=null)&&(charge.getPercent().compareTo(BigDecimal.ZERO)!=0)) {
|
||||
factor=charge.getPercent().divide(new BigDecimal(100), 18, RoundingMode.HALF_UP).multiply(currentItem.getQuantity());
|
||||
}
|
||||
addCharge(singleCharge.multiply(factor));
|
||||
|
||||
}
|
||||
}
|
||||
if (currentItem.getItemTotalAllowances() != null && currentItem.getItemTotalAllowances().length > 0) {
|
||||
@@ -52,9 +62,10 @@ public class LineCalculator {
|
||||
}
|
||||
|
||||
price=currentItem.getPrice();
|
||||
BigDecimal delta=charge.subtract(allowanceItemTotal).subtract(allowance);
|
||||
delta=delta.divide(currentItem.getQuantity(), 18, RoundingMode.HALF_UP);
|
||||
priceGross=currentItem.getPrice().add(delta);
|
||||
priceGross=price;
|
||||
// BigDecimal delta=charge.subtract(allowanceItemTotal).subtract(allowance);
|
||||
// delta=delta.divide(currentItem.getQuantity(), 18, RoundingMode.HALF_UP);
|
||||
// priceGross=currentItem.getPrice().add(delta);
|
||||
// Division/Zero occurred here.
|
||||
// Used the setScale only because that's also done in getBasisQuantity
|
||||
BigDecimal basisQuantity = currentItem.getBasisQuantity().compareTo(BigDecimal.ZERO) == 0
|
||||
|
||||
@@ -262,6 +262,45 @@ public class CalculationTest extends ResourceCase {
|
||||
assertEquals(new BigDecimal(5), calculator.getGrandTotal().stripTrailingZeros());
|
||||
}
|
||||
|
||||
public void testSimpleItemTotalAllowance() {
|
||||
SimpleDateFormat sqlDate = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
Invoice invoice = new Invoice();
|
||||
invoice.setDocumentName("Rechnung");
|
||||
invoice.setNumber("777777");
|
||||
try {
|
||||
invoice.setIssueDate(sqlDate.parse("2020-12-31"));
|
||||
invoice.setDetailedDeliveryPeriod(sqlDate.parse("2020-12-01 - 2020-12-31".split(" - ")[0]), sqlDate.parse("2020-12-01 - 2020-12-31".split(" - ")[1]));
|
||||
invoice.setDeliveryDate(sqlDate.parse("2020-12-31"));
|
||||
invoice.setDueDate(sqlDate.parse("2021-01-15"));
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Failed to set dates", e);
|
||||
|
||||
}
|
||||
TradeParty sender = new TradeParty("Maier GmbH", "Musterweg 5", "11111", "Testung", "DE");
|
||||
sender.addVATID("DE2222222222");
|
||||
invoice.setSender(sender);
|
||||
|
||||
/* trade party (recipient) */
|
||||
TradeParty recipient = new TradeParty("Teston GmbH" + " " + "Zentrale" + " " + "", "Testweg 5", "11111", "Testung", "DE");
|
||||
recipient.setID("111111");
|
||||
recipient.addVATID("DE111111111");
|
||||
invoice.setRecipient(recipient);
|
||||
|
||||
/* item */
|
||||
Product product;
|
||||
Item item;
|
||||
|
||||
product = new Product("AAA", "", "H84", BigDecimal.ZERO);
|
||||
item = new Item(product, new BigDecimal("1.00"), new BigDecimal(5.00));
|
||||
|
||||
item.addAllowance(new Allowance(new BigDecimal(1)).setTaxPercent(BigDecimal.ZERO));
|
||||
invoice.addItem(item);
|
||||
|
||||
TransactionCalculator calculator = new TransactionCalculator(invoice);
|
||||
assertEquals(new BigDecimal(4), calculator.getGrandTotal().stripTrailingZeros());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* LineCalculator should not throw an exception when calculating a non-terminating decimal expansion
|
||||
|
||||
Reference in New Issue
Block a user