closes #985
This commit is contained in:
@@ -172,7 +172,6 @@ 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);
|
||||
@@ -252,57 +251,45 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
||||
return hm;
|
||||
}
|
||||
|
||||
protected List<VATAmount> getVATAmountList()
|
||||
{
|
||||
protected List<VATAmount> getVATAmountList() {
|
||||
final List<VATAmount> vatAmounts = new ArrayList<>();
|
||||
final String vatDueDateTypeCode = this.trans.getVATDueDateTypeCode();
|
||||
for (final IZUGFeRDExportableItem currentItem : this.trans.getZFItems())
|
||||
{
|
||||
for (final IZUGFeRDExportableItem currentItem : this.trans.getZFItems()) {
|
||||
BigDecimal percent = null;
|
||||
if (currentItem.getProduct() != null)
|
||||
{
|
||||
if (currentItem.getProduct() != null) {
|
||||
percent = currentItem.getProduct().getVATPercent();
|
||||
}
|
||||
if (percent != null)
|
||||
{
|
||||
final LineCalculator lc = currentItem.getCalculation();
|
||||
final VATAmount itemVATAmount = new VATAmount(lc.getItemTotalNetAmount(), lc.getItemTotalVATAmount(),
|
||||
currentItem.getProduct().getTaxCategoryCode(), vatDueDateTypeCode, percent);
|
||||
final String reasonText = currentItem.getProduct().getTaxExemptionReason();
|
||||
if (reasonText != null)
|
||||
{
|
||||
itemVATAmount.setVatExemptionReasonText(reasonText);
|
||||
}
|
||||
final Optional<VATAmount> currentVatAmount = this.getCurrentVatAmount(vatAmounts, currentItem.getProduct().getTaxCategoryCode(), percent);
|
||||
if (currentVatAmount.isEmpty())
|
||||
{
|
||||
vatAmounts.add(itemVATAmount);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.mergeAdding(currentVatAmount.get(), itemVATAmount);
|
||||
}
|
||||
if (percent == null) {
|
||||
percent = ZERO;
|
||||
}
|
||||
final LineCalculator lc = currentItem.getCalculation();
|
||||
final VATAmount itemVATAmount = new VATAmount(lc.getItemTotalNetAmount(), lc.getItemTotalVATAmount(),
|
||||
currentItem.getProduct().getTaxCategoryCode(), vatDueDateTypeCode, percent);
|
||||
final String reasonText = currentItem.getProduct().getTaxExemptionReason();
|
||||
if (reasonText != null) {
|
||||
itemVATAmount.setVatExemptionReasonText(reasonText);
|
||||
}
|
||||
final Optional<VATAmount> currentVatAmount = this.getCurrentVatAmount(vatAmounts, currentItem.getProduct().getTaxCategoryCode(), percent);
|
||||
if (currentVatAmount.isEmpty()) {
|
||||
vatAmounts.add(itemVATAmount);
|
||||
} else {
|
||||
this.mergeAdding(currentVatAmount.get(), itemVATAmount);
|
||||
}
|
||||
}
|
||||
|
||||
final IZUGFeRDAllowanceCharge[] charges = this.trans.getZFCharges();
|
||||
if (charges != null) {
|
||||
for (final IZUGFeRDAllowanceCharge currentCharge : charges)
|
||||
{
|
||||
for (final IZUGFeRDAllowanceCharge currentCharge : charges) {
|
||||
final BigDecimal taxPercent = currentCharge.getTaxPercent();
|
||||
if (taxPercent != null)
|
||||
{
|
||||
if (taxPercent != null) {
|
||||
final String vatCategoryCode = currentCharge.getCategoryCode() != null ? currentCharge.getCategoryCode() : "S";
|
||||
final Optional<VATAmount> currentChargeVatAmount = this.getCurrentVatAmount(vatAmounts, vatCategoryCode, taxPercent);
|
||||
final BigDecimal chargeBasis = currentCharge.getTotalAmount(this);
|
||||
final VATAmount chargeVatAmount = new VATAmount(chargeBasis, chargeBasis.multiply(taxPercent.divide(new BigDecimal(100))), vatCategoryCode,
|
||||
vatDueDateTypeCode, taxPercent);
|
||||
if (currentChargeVatAmount.isEmpty())
|
||||
{
|
||||
if (currentChargeVatAmount.isEmpty()) {
|
||||
vatAmounts.add(chargeVatAmount);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
this.mergeAdding(currentChargeVatAmount.get(), chargeVatAmount);
|
||||
}
|
||||
}
|
||||
@@ -310,11 +297,9 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
||||
}
|
||||
final IZUGFeRDAllowanceCharge[] allowances = this.trans.getZFAllowances();
|
||||
if (allowances != null) {
|
||||
for (final IZUGFeRDAllowanceCharge currentAllowance : allowances)
|
||||
{
|
||||
for (final IZUGFeRDAllowanceCharge currentAllowance : allowances) {
|
||||
final BigDecimal taxPercent = currentAllowance.getTaxPercent();
|
||||
if (taxPercent != null)
|
||||
{
|
||||
if (taxPercent != null) {
|
||||
final String vatCategoryCode = currentAllowance.getCategoryCode() != null ? currentAllowance.getCategoryCode() : "S";
|
||||
final Optional<VATAmount> currentAllowanceVatAmount = this.getCurrentVatAmount(vatAmounts, vatCategoryCode, taxPercent);
|
||||
final BigDecimal allowanceNegativeBasis = currentAllowance.getTotalAmount(this).multiply(BigDecimal.valueOf(-1));
|
||||
@@ -322,12 +307,9 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
||||
allowanceNegativeBasis.multiply(taxPercent.divide(new BigDecimal(100))),
|
||||
currentAllowance.getCategoryCode() != null ? currentAllowance.getCategoryCode() : "S",
|
||||
vatDueDateTypeCode, taxPercent);
|
||||
if (currentAllowanceVatAmount.isEmpty())
|
||||
{
|
||||
if (currentAllowanceVatAmount.isEmpty()) {
|
||||
vatAmounts.add(allowanceVATAmount);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
this.mergeAdding(currentAllowanceVatAmount.get(), allowanceVATAmount);
|
||||
}
|
||||
}
|
||||
@@ -335,19 +317,17 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
||||
}
|
||||
return vatAmounts;
|
||||
}
|
||||
|
||||
public void mergeAdding(VATAmount vatAmount, VATAmount toAdd)
|
||||
{
|
||||
|
||||
public void mergeAdding(VATAmount vatAmount, VATAmount toAdd) {
|
||||
vatAmount.setBasis(vatAmount.getBasis().add(toAdd.getBasis()));
|
||||
vatAmount.setCalculated(vatAmount.getCalculated().add(toAdd.getCalculated()));
|
||||
if (toAdd.getVatExemptionReasonText() != null && !toAdd.getVatExemptionReasonText().isBlank())
|
||||
{
|
||||
if (toAdd.getVatExemptionReasonText() != null && !toAdd.getVatExemptionReasonText().isBlank()) {
|
||||
Optional.ofNullable(vatAmount.getVatExemptionReasonText()).filter(reasonText -> !reasonText.equals(toAdd.getVatExemptionReasonText())).ifPresentOrElse(
|
||||
text -> vatAmount.setVatExemptionReasonText(String.join(", ", text, toAdd.getVatExemptionReasonText())),
|
||||
() -> vatAmount.setVatExemptionReasonText(toAdd.getVatExemptionReasonText()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BigDecimal getValue() {
|
||||
return getTotal();
|
||||
@@ -360,13 +340,12 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
||||
public BigDecimal getAllowanceTotal() {
|
||||
return getAllowancesForPercent(null).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
private Optional<VATAmount> getCurrentVatAmount(List<VATAmount> vatAmounts, String vatCategoryCode, BigDecimal percentage)
|
||||
{
|
||||
|
||||
private Optional<VATAmount> getCurrentVatAmount(List<VATAmount> vatAmounts, String vatCategoryCode, BigDecimal percentage) {
|
||||
return vatAmounts.stream()
|
||||
.filter(va -> Objects.equals(vatCategoryCode, va.getCategoryCode())
|
||||
&& Optional.ofNullable(percentage).map(p -> va.getApplicablePercent() == null && p == null || p.compareTo(va.getApplicablePercent()) == 0)
|
||||
.orElse(true))
|
||||
.orElse(true))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ public class VATrelatedTest extends ResourceCase {
|
||||
assertTrue(theXML.contains("<rsm:CrossIndustryInvoice"));
|
||||
ze.export(TARGET_PDF_Z);
|
||||
} catch (IOException e) {
|
||||
fail("IOException should not be raised");
|
||||
fail("IOException "+e.getMessage()+" should not be raised");
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user