correcting some tests
This commit is contained in:
@@ -145,9 +145,8 @@ public class Charge implements IZUGFeRDAllowanceCharge {
|
||||
if(totalAmount != null) {
|
||||
return totalAmount;
|
||||
} else if (percent!=null) {
|
||||
// BigDecimal singlePrice=currentItem.getValue().divide(BigDecimal.ONE.add(getPercent().divide(new BigDecimal(100))), 18, RoundingMode.HALF_UP);
|
||||
BigDecimal singlePrice=currentItem.getValue().multiply(BigDecimal.ONE.subtract(getPercent().divide(new BigDecimal(100))));
|
||||
// BigDecimal singlePriceDiff=currentItem.getValue().add(singlePrice);
|
||||
BigDecimal factor=getPercent().divide(new BigDecimal(100), 18, RoundingMode.HALF_UP);
|
||||
BigDecimal singlePrice=currentItem.getValue().multiply(factor);
|
||||
return singlePrice;
|
||||
} else {
|
||||
throw new RuntimeException("percent must be set");
|
||||
|
||||
@@ -172,6 +172,7 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
||||
* @return item sum +- charges/allowances
|
||||
*/
|
||||
public BigDecimal getTaxBasis() {
|
||||
BigDecimal debug_1=getTotal();
|
||||
return getTotal().add(getChargesForPercent(null).setScale(2, RoundingMode.HALF_UP))
|
||||
.subtract(getAllowancesForPercent(null).setScale(2, RoundingMode.HALF_UP))
|
||||
.setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
@@ -217,54 +217,23 @@ public class CalculationTest extends ResourceCase {
|
||||
}
|
||||
invoice.addItem(item);
|
||||
|
||||
// reset values for additional charge and discount used for next lines
|
||||
item_increase = BigDecimal.ZERO;
|
||||
item_discount = BigDecimal.ZERO;
|
||||
|
||||
product = new Product("BBB", "", "H84", sales_tax_percent1).setSellerAssignedID("2BBB");
|
||||
item = new Item(product, new BigDecimal("5.750"), new BigDecimal(4.00));
|
||||
if (item_increase.compareTo(BigDecimal.ZERO) > 0) {
|
||||
item.addCharge(new Charge().setPercent(item_increase).setTaxPercent(sales_tax_percent1).setReasonCode("ZZZ").setReason("Zuschlag"));
|
||||
}
|
||||
if (item_discount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
item.addAllowance(new Allowance().setPercent(item_discount).setTaxPercent(sales_tax_percent1).setReasonCode("95").setReason("Rabatt"));
|
||||
}
|
||||
invoice.addItem(item);
|
||||
|
||||
product = new Product("CCC", "", "H84", sales_tax_percent1).setSellerAssignedID("3CCC");
|
||||
item = new Item(product, new BigDecimal("6.750"), new BigDecimal(3.00));
|
||||
if (item_increase.compareTo(BigDecimal.ZERO) > 0) {
|
||||
item.addCharge(new Charge().setPercent(item_increase).setTaxPercent(sales_tax_percent1).setReasonCode("ZZZ").setReason("Zuschlag"));
|
||||
}
|
||||
if (item_discount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
item.addAllowance(new Allowance().setPercent(item_discount).setTaxPercent(sales_tax_percent1).setReasonCode("95").setReason("Rabatt"));
|
||||
}
|
||||
invoice.addItem(item);
|
||||
|
||||
product = new Product("DDD", "", "H84", sales_tax_percent1).setSellerAssignedID("4DDD");
|
||||
item = new Item(product, new BigDecimal("7.750"), new BigDecimal(2.00));
|
||||
if (item_increase.compareTo(BigDecimal.ZERO) > 0) {
|
||||
item.addCharge(new Charge().setPercent(item_increase).setTaxPercent(sales_tax_percent1).setReasonCode("ZZZ").setReason("Zuschlag"));
|
||||
}
|
||||
if (item_discount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
item.addAllowance(new Allowance().setPercent(item_discount).setTaxPercent(sales_tax_percent1).setReasonCode("95").setReason("Rabatt"));
|
||||
}
|
||||
invoice.addItem(item);
|
||||
|
||||
product = new Product("EEE", "", "H84", sales_tax_percent1).setSellerAssignedID("5EEE");
|
||||
item = new Item(product, new BigDecimal("8.750"), new BigDecimal(1.00));
|
||||
if (item_increase.compareTo(BigDecimal.ZERO) > 0) {
|
||||
item.addCharge(new Charge().setPercent(item_increase).setTaxPercent(sales_tax_percent1).setReasonCode("ZZZ").setReason("Zuschlag"));
|
||||
}
|
||||
if (item_discount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
item.addAllowance(new Allowance().setPercent(item_discount).setTaxPercent(sales_tax_percent1).setReasonCode("95").setReason("Rabatt"));
|
||||
|
||||
}
|
||||
invoice.addItem(item);
|
||||
|
||||
// reset values for additional charge and discount used on invoice level
|
||||
item_increase = BigDecimal.valueOf(3.50);
|
||||
item_discount = BigDecimal.valueOf(10.00);
|
||||
|
||||
if (total_increase_percent.compareTo(BigDecimal.ZERO) > 0) {
|
||||
invoice.addCharge(new Charge().setPercent(total_increase_percent).setTaxPercent(sales_tax_percent1).setReasonCode("ZZZ").setReason("Zuschläge"));
|
||||
@@ -273,7 +242,7 @@ public class CalculationTest extends ResourceCase {
|
||||
invoice.addAllowance(new Allowance().setPercent(total_discount_percent).setTaxPercent(sales_tax_percent1).setReasonCode("95").setReason("Rabatte"));
|
||||
}
|
||||
TransactionCalculator calculator = new TransactionCalculator(invoice);
|
||||
assertEquals(valueOf(306.38).stripTrailingZeros(), calculator.getGrandTotal().stripTrailingZeros());
|
||||
assertEquals(valueOf(101.85).stripTrailingZeros(), calculator.getGrandTotal().stripTrailingZeros());
|
||||
}
|
||||
|
||||
public void testSimpleItemPercentAllowance() {
|
||||
|
||||
@@ -39,6 +39,7 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -416,7 +417,12 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Date atStartOfDay(Date date) {
|
||||
ZoneId tz=ZoneId.ofOffset("GMT", ZoneOffset.ofHours(+2));
|
||||
LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), tz);
|
||||
LocalDateTime startOfDay = localDateTime.with(LocalTime.MIN);
|
||||
return Date.from(startOfDay.atZone(tz).toInstant());
|
||||
}
|
||||
public void testImportAllowances() {
|
||||
try {
|
||||
ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter("./target/testout-ZF2PushItemChargesAllowances.pdf");
|
||||
@@ -424,7 +430,16 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
String jsonArray = mapper.writeValueAsString(i);
|
||||
JSONAssert.assertEquals("{ \"documentCode\": \"380\", \"number\": \"123\", \"currency\": \"EUR\", \"paymentTermDescription\": \"Please remit until 30.06.2025\", \"issueDate\": 1751234400000, \"dueDate\": 1751234400000, \"sender\": { \"name\": \"Test company\", \"zip\": \"55232\", \"street\": \"teststr\", \"location\": \"teststadt\", \"country\": \"DE\", \"taxID\": \"4711\", \"vatID\": \"DE0815\", \"vatid\": \"DE0815\" }, \"recipient\": { \"name\": \"Franz Müller\", \"zip\": \"55232\", \"street\": \"teststr.12\", \"location\": \"Entenhausen\", \"country\": \"DE\", \"contact\": { \"name\": \"contact testname\", \"phone\": \"123456\", \"email\": \"contact.testemail@example.org\", \"fax\": \"0911623562\" } }, \"totalPrepaidAmount\": 0.00, \"valid\": true, \"zfitems\": [ { \"price\": 3.0000, \"quantity\": 1.0000, \"basisQuantity\": 1.0000, \"id\": \"1\", \"product\": { \"unit\": \"C62\", \"name\": \"Testprodukt\", \"taxCategoryCode\": \"S\", \"vatpercent\": 19.00, \"reverseCharge\": false, \"intraCommunitySupply\": false }, \"itemAllowances\": [ { \"totalAmount\": 0.10, \"taxPercent\": 0, \"categoryCode\": \"S\" } ], \"value\": 3.0000 }, { \"price\": 3.0000, \"quantity\": 1.0000, \"basisQuantity\": 1.0000, \"id\": \"2\", \"product\": { \"unit\": \"C62\", \"name\": \"Testprodukt\", \"taxCategoryCode\": \"S\", \"vatpercent\": 19.00, \"reverseCharge\": false, \"intraCommunitySupply\": false }, \"itemAllowances\": [ { \"percent\": 50.00, \"totalAmount\": 1, \"basisAmount\": 3.00, \"taxPercent\": 0, \"reason\": \"In love with salesperson\", \"categoryCode\": \"S\" } ], \"value\": 3.0000 }, { \"price\": 3.0000, \"quantity\": 2.0000, \"basisQuantity\": 1.0000, \"id\": \"3\", \"product\": { \"unit\": \"C62\", \"name\": \"Testprodukt\", \"taxCategoryCode\": \"S\", \"vatpercent\": 19.00, \"reverseCharge\": false, \"intraCommunitySupply\": false }, \"itemCharges\": [ { \"totalAmount\": 1.00, \"taxPercent\": 0, \"reason\": \"AnotherReason\", \"categoryCode\": \"S\" } ], \"value\": 3.0000 }, { \"price\": 3.0000, \"quantity\": 1.0000, \"basisQuantity\": 1.0000, \"id\": \"4\", \"product\": { \"unit\": \"C62\", \"name\": \"Testprodukt\", \"taxCategoryCode\": \"S\", \"vatpercent\": 19.00, \"reverseCharge\": false, \"intraCommunitySupply\": false }, \"itemCharges\": [ { \"totalAmount\": 1.00, \"taxPercent\": 0, \"reason\": \"Yet another reason\", \"categoryCode\": \"S\" } ], \"itemAllowances\": [ { \"totalAmount\": 1.00, \"taxPercent\": 0, \"reason\": \"Something completely strange\", \"categoryCode\": \"S\" } ], \"value\": 3.0000 } ], \"ownCountry\": \"DE\", \"zfcharges\": [ { \"totalAmount\": 1.00, \"taxPercent\": 19.00, \"reason\": \"AReason\", \"reasonCode\": \"ABK\", \"categoryCode\": \"S\" } ], \"ownVATID\": \"DE0815\", \"ownStreet\": \"teststr\", \"ownTaxID\": \"4711\", \"ownLocation\": \"teststadt\", \"ownZIP\": \"55232\"}",jsonArray,true);
|
||||
SimpleDateFormat iso=new SimpleDateFormat("yyyy-MM-dd");
|
||||
SimpleDateFormat german=new SimpleDateFormat("dd.MM.yyyy");
|
||||
Date now=new Date();
|
||||
Date morning=atStartOfDay(now);
|
||||
|
||||
String expectedDueDate= String.valueOf(morning.toInstant().getEpochSecond() *1000);
|
||||
String expectedIssueDate= String.valueOf(morning.toInstant().getEpochSecond() *1000);
|
||||
String expectedPaymentTermDesciption="Please remit until "+german.format(now);
|
||||
|
||||
JSONAssert.assertEquals("{ \"documentCode\": \"380\", \"number\": \"123\", \"currency\": \"EUR\", \"paymentTermDescription\": \""+expectedPaymentTermDesciption+"\", \"issueDate\": "+expectedIssueDate+", \"dueDate\": "+expectedDueDate+", \"sender\": { \"name\": \"Test company\", \"zip\": \"55232\", \"street\": \"teststr\", \"location\": \"teststadt\", \"country\": \"DE\", \"taxID\": \"4711\", \"vatID\": \"DE0815\", \"vatid\": \"DE0815\" }, \"recipient\": { \"name\": \"Franz Müller\", \"zip\": \"55232\", \"street\": \"teststr.12\", \"location\": \"Entenhausen\", \"country\": \"DE\", \"contact\": { \"name\": \"contact testname\", \"phone\": \"123456\", \"email\": \"contact.testemail@example.org\", \"fax\": \"0911623562\" } }, \"totalPrepaidAmount\": 0.00, \"valid\": true, \"zfitems\": [ { \"price\": 3.0000, \"quantity\": 1.0000, \"basisQuantity\": 1.0000, \"id\": \"1\", \"product\": { \"unit\": \"C62\", \"name\": \"Testprodukt\", \"taxCategoryCode\": \"S\", \"vatpercent\": 19.00, \"reverseCharge\": false, \"intraCommunitySupply\": false }, \"itemAllowances\": [ { \"totalAmount\": 0.10, \"taxPercent\": 0, \"categoryCode\": \"S\" } ], \"value\": 3.0000 }, { \"price\": 3.0000, \"quantity\": 1.0000, \"basisQuantity\": 1.0000, \"id\": \"2\", \"product\": { \"unit\": \"C62\", \"name\": \"Testprodukt\", \"taxCategoryCode\": \"S\", \"vatpercent\": 19.00, \"reverseCharge\": false, \"intraCommunitySupply\": false }, \"itemAllowances\": [ { \"percent\": 50.00, \"totalAmount\": 1, \"basisAmount\": 3.00, \"taxPercent\": 0, \"reason\": \"In love with salesperson\", \"categoryCode\": \"S\" } ], \"value\": 3.0000 }, { \"price\": 3.0000, \"quantity\": 2.0000, \"basisQuantity\": 1.0000, \"id\": \"3\", \"product\": { \"unit\": \"C62\", \"name\": \"Testprodukt\", \"taxCategoryCode\": \"S\", \"vatpercent\": 19.00, \"reverseCharge\": false, \"intraCommunitySupply\": false }, \"itemCharges\": [ { \"totalAmount\": 1.00, \"taxPercent\": 0, \"reason\": \"AnotherReason\", \"categoryCode\": \"S\" } ], \"value\": 3.0000 }, { \"price\": 3.0000, \"quantity\": 1.0000, \"basisQuantity\": 1.0000, \"id\": \"4\", \"product\": { \"unit\": \"C62\", \"name\": \"Testprodukt\", \"taxCategoryCode\": \"S\", \"vatpercent\": 19.00, \"reverseCharge\": false, \"intraCommunitySupply\": false }, \"itemCharges\": [ { \"totalAmount\": 1.00, \"taxPercent\": 0, \"reason\": \"Yet another reason\", \"categoryCode\": \"S\" } ], \"itemAllowances\": [ { \"totalAmount\": 1.00, \"taxPercent\": 0, \"reason\": \"Something completely strange\", \"categoryCode\": \"S\" } ], \"value\": 3.0000 } ], \"ownCountry\": \"DE\", \"zfcharges\": [ { \"totalAmount\": 1.00, \"taxPercent\": 19.00, \"reason\": \"AReason\", \"reasonCode\": \"ABK\", \"categoryCode\": \"S\" } ], \"ownVATID\": \"DE0815\", \"ownStreet\": \"teststr\", \"ownTaxID\": \"4711\", \"ownLocation\": \"teststadt\", \"ownZIP\": \"55232\"}",jsonArray,true);
|
||||
} catch (IOException e) {
|
||||
fail("IOException not expected");
|
||||
} catch (XPathExpressionException e) {
|
||||
|
||||
Reference in New Issue
Block a user