Skip to content

Commit

Permalink
IN ARBEIT - issue QMT-1461: Rechnungseingang - ZUGFeRD-Rechnungen
Browse files Browse the repository at this point in the history
importieren
http://sws-jira/browse/QMT-1461
  • Loading branch information
StefanSchmaltz committed Oct 13, 2022
1 parent 524165b commit 589e94a
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
* @see TransactionCalculator
*/
public class LineCalculator {
private BigDecimal price;
private BigDecimal priceGross;
private BigDecimal itemTotalNetAmount;
private BigDecimal itemTotalVATAmount;
private final BigDecimal price;
private final BigDecimal priceGross;
private final BigDecimal itemTotalNetAmount;
private final BigDecimal itemTotalVATAmount;
private BigDecimal allowance = BigDecimal.ZERO;
private BigDecimal charge = BigDecimal.ZERO;
private BigDecimal allowanceItemTotal = BigDecimal.ZERO;
Expand All @@ -33,7 +33,10 @@ public LineCalculator(IZUGFeRDExportableItem currentItem) {
}
}

BigDecimal multiplicator = currentItem.getProduct().getVATPercent().divide(BigDecimal.valueOf(100));
BigDecimal vatPercent = currentItem.getProduct().getVATPercent();
if (vatPercent == null)
vatPercent = BigDecimal.ZERO;
BigDecimal multiplicator = vatPercent.divide(BigDecimal.valueOf(100));
priceGross = currentItem.getPrice(); // see https://github.com/ZUGFeRD/mustangproject/issues/159
price = priceGross.subtract(allowance).add(charge);
itemTotalNetAmount = currentItem.getQuantity().multiply(getPrice()).divide(currentItem.getBasisQuantity())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,16 @@ protected HashMap<BigDecimal, VATAmount> getVATPercentAmountMap() {

for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) {
BigDecimal percent = currentItem.getProduct().getVATPercent();
LineCalculator lc = new LineCalculator(currentItem);
VATAmount itemVATAmount = new VATAmount(lc.getItemTotalNetAmount(), lc.getItemTotalVATAmount(),
currentItem.getProduct().getTaxCategoryCode());
VATAmount current = hm.get(percent.stripTrailingZeros());
if (current == null) {
hm.put(percent.stripTrailingZeros(), itemVATAmount);
} else {
hm.put(percent.stripTrailingZeros(), current.add(itemVATAmount));
if (percent != null) {
LineCalculator lc = new LineCalculator(currentItem);
VATAmount itemVATAmount = new VATAmount(lc.getItemTotalNetAmount(), lc.getItemTotalVATAmount(),
currentItem.getProduct().getTaxCategoryCode());
VATAmount current = hm.get(percent.stripTrailingZeros());
if (current == null) {
hm.put(percent.stripTrailingZeros(), itemVATAmount);
} else {
hm.put(percent.stripTrailingZeros(), current.add(itemVATAmount));
}
}
}

Expand All @@ -199,16 +201,18 @@ protected HashMap<BigDecimal, VATAmount> getVATPercentAmountMap() {
if ((allowances != null) && (allowances.length > 0)) {
for (IZUGFeRDAllowanceCharge currentAllowance : allowances) {
BigDecimal taxPercent = currentAllowance.getTaxPercent();
VATAmount theAmount = hm.get(taxPercent.stripTrailingZeros());
if (theAmount == null) {
theAmount = new VATAmount(BigDecimal.ZERO, BigDecimal.ZERO,
currentAllowance.getCategoryCode() != null ? currentAllowance.getCategoryCode() : "S");
}
theAmount.setBasis(theAmount.getBasis().subtract(currentAllowance.getTotalAmount(this)));
BigDecimal factor = taxPercent.divide(new BigDecimal(100));
theAmount.setCalculated(theAmount.getBasis().multiply(factor));
if (taxPercent != null) {
VATAmount theAmount = hm.get(taxPercent.stripTrailingZeros());
if (theAmount == null) {
theAmount = new VATAmount(BigDecimal.ZERO, BigDecimal.ZERO,
currentAllowance.getCategoryCode() != null ? currentAllowance.getCategoryCode() : "S");
}
theAmount.setBasis(theAmount.getBasis().subtract(currentAllowance.getTotalAmount(this)));
BigDecimal factor = taxPercent.divide(new BigDecimal(100));
theAmount.setCalculated(theAmount.getBasis().multiply(factor));

hm.put(taxPercent.stripTrailingZeros(), theAmount);
hm.put(taxPercent.stripTrailingZeros(), theAmount);
}
}
}

Expand All @@ -220,4 +224,12 @@ public BigDecimal getValue() {
return getTotal();
}

public BigDecimal getChargeTotal() {
return getChargesForPercent(null).setScale(2, RoundingMode.HALF_UP);
}

public BigDecimal getAllowanceTotal() {
return getAllowancesForPercent(null).setScale(2, RoundingMode.HALF_UP);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -310,16 +310,19 @@ public void generateXML(IExportableTransaction trans) {
xml += "<ram:SpecifiedTradeSettlementMonetarySummation>"
+ "<ram:LineTotalAmount currencyID=\"" + trans.getCurrency() + "\">" + currencyFormat(calc.getTotal()) + "</ram:LineTotalAmount>"
// currencyID=\"EUR\"
+ "<ram:ChargeTotalAmount currencyID=\"" + trans.getCurrency() + "\">0.00</ram:ChargeTotalAmount>" // currencyID=\"EUR\"
+ "<ram:AllowanceTotalAmount currencyID=\"" + trans.getCurrency() + "\">0.00</ram:AllowanceTotalAmount>" //
+ "<ram:ChargeTotalAmount currencyID=\"" + trans.getCurrency() + "\">"
+ currencyFormat(calc.getChargeTotal()) + "</ram:ChargeTotalAmount>" // currencyID=\"EUR\"
+ "<ram:AllowanceTotalAmount currencyID=\"" + trans.getCurrency() + "\">"
+ currencyFormat(calc.getAllowanceTotal()) + "</ram:AllowanceTotalAmount>" //
// currencyID=\"EUR\"
// + " <ChargeTotalAmount currencyID=\"EUR\">5.80</ChargeTotalAmount>"
// + " <AllowanceTotalAmount currencyID=\"EUR\">14.73</AllowanceTotalAmount>"
+ "<ram:TaxBasisTotalAmount currencyID=\"" + trans.getCurrency() + "\">" + currencyFormat(calc.getTotal()) + "</ram:TaxBasisTotalAmount>"
+ "<ram:TaxBasisTotalAmount currencyID=\"" + trans.getCurrency() + "\">"
+ currencyFormat(calc.getTaxBasis()) + "</ram:TaxBasisTotalAmount>"
// //
// currencyID=\"EUR\"
+ "<ram:TaxTotalAmount currencyID=\"" + trans.getCurrency() + "\">"
+ currencyFormat(calc.getGrandTotal().subtract(calc.getTotal())) + "</ram:TaxTotalAmount>"
+ currencyFormat(calc.getGrandTotal().subtract(calc.getTaxBasis())) + "</ram:TaxTotalAmount>"
+ "<ram:GrandTotalAmount currencyID=\"" + trans.getCurrency() + "\">" + currencyFormat(calc.getGrandTotal()) + "</ram:GrandTotalAmount>"
// //
// currencyID=\"EUR\"
Expand Down
Loading

0 comments on commit 589e94a

Please sign in to comment.