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