corrected taxrate issue in rateApplicablePercent
This commit is contained in:
@@ -33,23 +33,38 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected BigDecimal getCharges() {
|
/***
|
||||||
|
* returns total of charges for this tax rate
|
||||||
|
* @param percent a specific rate, or null for any rate
|
||||||
|
* @return the total amount
|
||||||
|
*/
|
||||||
|
protected BigDecimal getChargesForPercent(BigDecimal percent) {
|
||||||
BigDecimal res = new BigDecimal(0);
|
BigDecimal res = new BigDecimal(0);
|
||||||
IZUGFeRDAllowanceCharge[] charges = trans.getZFCharges();
|
IZUGFeRDAllowanceCharge[] charges = trans.getZFCharges();
|
||||||
if ((charges != null) && (charges.length > 0)) {
|
if ((charges != null) && (charges.length > 0)) {
|
||||||
for (IZUGFeRDAllowanceCharge currentCharge : charges) {
|
for (IZUGFeRDAllowanceCharge currentCharge : charges) {
|
||||||
res = res.add(currentCharge.getTotalAmount(this));
|
if ((percent==null)||(currentCharge.getTaxPercent().equals(percent))) {
|
||||||
|
res = res.add(currentCharge.getTotalAmount(this));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected BigDecimal getAllowances() {
|
|
||||||
|
/***
|
||||||
|
* returns total of allowances for this tax rate
|
||||||
|
* @param percent a specific rate, or null for any rate
|
||||||
|
* @return the total amount
|
||||||
|
*/
|
||||||
|
protected BigDecimal getAllowancesForPercent(BigDecimal percent) {
|
||||||
BigDecimal res = new BigDecimal(0);
|
BigDecimal res = new BigDecimal(0);
|
||||||
IZUGFeRDAllowanceCharge[] allowances = trans.getZFAllowances();
|
IZUGFeRDAllowanceCharge[] allowances = trans.getZFAllowances();
|
||||||
if ((allowances != null) && (allowances.length > 0)) {
|
if ((allowances != null) && (allowances.length > 0)) {
|
||||||
for (IZUGFeRDAllowanceCharge currentAllowance : allowances) {
|
for (IZUGFeRDAllowanceCharge currentAllowance : allowances) {
|
||||||
res = res.add(currentAllowance.getTotalAmount(this));
|
if ((percent==null)||(currentAllowance.getTaxPercent().equals(percent))) {
|
||||||
|
res = res.add(currentAllowance.getTotalAmount(this));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
@@ -65,7 +80,7 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected BigDecimal getTaxBasis() {
|
protected BigDecimal getTaxBasis() {
|
||||||
BigDecimal res = getTotal().add(getCharges()).subtract(getAllowances());
|
BigDecimal res = getTotal().add(getChargesForPercent(null)).subtract(getAllowancesForPercent(null));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ import org.dom4j.io.XMLWriter;
|
|||||||
import org.mustangproject.FileAttachment;
|
import org.mustangproject.FileAttachment;
|
||||||
import org.mustangproject.XMLTools;
|
import org.mustangproject.XMLTools;
|
||||||
|
|
||||||
public class ZUGFeRD2PullProvider implements IXMLProvider {
|
public class ZUGFeRD2PullProvider implements IXMLProvider {
|
||||||
|
|
||||||
//// MAIN CLASS
|
//// MAIN CLASS
|
||||||
protected SimpleDateFormat zugferdDateFormat = new SimpleDateFormat("yyyyMMdd");
|
protected SimpleDateFormat zugferdDateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||||
@@ -193,7 +193,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
|||||||
@Override
|
@Override
|
||||||
public void generateXML(IExportableTransaction trans) {
|
public void generateXML(IExportableTransaction trans) {
|
||||||
this.trans = trans;
|
this.trans = trans;
|
||||||
this.calc=new TransactionCalculator(trans);
|
this.calc = new TransactionCalculator(trans);
|
||||||
|
|
||||||
boolean hasDueDate = false;
|
boolean hasDueDate = false;
|
||||||
String taxCategoryCode = "";
|
String taxCategoryCode = "";
|
||||||
@@ -236,10 +236,10 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
|||||||
if (trans.getDocumentCode() != null) {
|
if (trans.getDocumentCode() != null) {
|
||||||
typecode = trans.getDocumentCode();
|
typecode = trans.getDocumentCode();
|
||||||
}
|
}
|
||||||
String notes="";
|
String notes = "";
|
||||||
if (trans.getNotes()!=null) {
|
if (trans.getNotes() != null) {
|
||||||
for (String currentNote:trans.getNotes()) {
|
for (String currentNote : trans.getNotes()) {
|
||||||
notes=notes+"<ram:IncludedNote><ram:Content>" + XMLTools.encodeXML(currentNote) + "</ram:Content></ram:IncludedNote>";
|
notes = notes + "<ram:IncludedNote><ram:Content>" + XMLTools.encodeXML(currentNote) + "</ram:Content></ram:IncludedNote>";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -280,10 +280,10 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
|||||||
if (currentItem.getProduct().getTaxExemptionReason() != null) {
|
if (currentItem.getProduct().getTaxExemptionReason() != null) {
|
||||||
exemptionReason = "<ram:ExemptionReason>" + XMLTools.encodeXML(currentItem.getProduct().getTaxExemptionReason()) + "</ram:ExemptionReason>";
|
exemptionReason = "<ram:ExemptionReason>" + XMLTools.encodeXML(currentItem.getProduct().getTaxExemptionReason()) + "</ram:ExemptionReason>";
|
||||||
}
|
}
|
||||||
notes="";
|
notes = "";
|
||||||
if (currentItem.getNotes()!=null) {
|
if (currentItem.getNotes() != null) {
|
||||||
for (String currentNote:currentItem.getNotes()) {
|
for (String currentNote : currentItem.getNotes()) {
|
||||||
notes=notes+"<ram:IncludedNote><ram:Content>" + XMLTools.encodeXML(currentNote) + "</ram:Content></ram:IncludedNote>";
|
notes = notes + "<ram:IncludedNote><ram:Content>" + XMLTools.encodeXML(currentNote) + "</ram:Content></ram:IncludedNote>";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -294,7 +294,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
|||||||
+ notes
|
+ notes
|
||||||
+ " </ram:AssociatedDocumentLineDocument>\n"
|
+ " </ram:AssociatedDocumentLineDocument>\n"
|
||||||
|
|
||||||
+ " <ram:SpecifiedTradeProduct>\n";
|
+ " <ram:SpecifiedTradeProduct>\n";
|
||||||
// + " <GlobalID schemeID=\"0160\">4012345001235</GlobalID>\n"
|
// + " <GlobalID schemeID=\"0160\">4012345001235</GlobalID>\n"
|
||||||
if (currentItem.getProduct().getSellerAssignedID() != null) {
|
if (currentItem.getProduct().getSellerAssignedID() != null) {
|
||||||
xml = xml + " <ram:SellerAssignedID>"
|
xml = xml + " <ram:SellerAssignedID>"
|
||||||
@@ -490,36 +490,46 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((trans.getZFCharges() != null) && (trans.getZFCharges().length > 0)) {
|
if ((trans.getZFCharges() != null) && (trans.getZFCharges().length > 0)) {
|
||||||
xml = xml + " <ram:SpecifiedTradeAllowanceCharge>\n" +
|
|
||||||
" <ram:ChargeIndicator>\n" +
|
|
||||||
" <udt:Indicator>true</udt:Indicator>\n" +
|
|
||||||
" </ram:ChargeIndicator>\n" +
|
|
||||||
" <ram:ActualAmount>" + currencyFormat(calc.getCharges()) + "</ram:ActualAmount>\n" +
|
|
||||||
" <ram:Reason>Charge</ram:Reason>\n" +
|
|
||||||
" <ram:CategoryTradeTax>\n" +
|
|
||||||
" <ram:TypeCode>VAT</ram:TypeCode>\n" +
|
|
||||||
" <ram:CategoryCode>S</ram:CategoryCode>\n" +
|
|
||||||
" <ram:RateApplicablePercent>19.00</ram:RateApplicablePercent>\n" +
|
|
||||||
" </ram:CategoryTradeTax>\n" +
|
|
||||||
" </ram:SpecifiedTradeAllowanceCharge> \n";
|
|
||||||
|
|
||||||
|
for (BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) {
|
||||||
|
if (!calc.getChargesForPercent(currentTaxPercent).equals(new BigDecimal(0))) {
|
||||||
|
|
||||||
|
|
||||||
|
xml = xml + " <ram:SpecifiedTradeAllowanceCharge>\n" +
|
||||||
|
" <ram:ChargeIndicator>\n" +
|
||||||
|
" <udt:Indicator>true</udt:Indicator>\n" +
|
||||||
|
" </ram:ChargeIndicator>\n" +
|
||||||
|
" <ram:ActualAmount>" + currencyFormat(calc.getChargesForPercent(currentTaxPercent)) + "</ram:ActualAmount>\n" +
|
||||||
|
" <ram:Reason>Charge</ram:Reason>\n" +
|
||||||
|
" <ram:CategoryTradeTax>\n" +
|
||||||
|
" <ram:TypeCode>VAT</ram:TypeCode>\n" +
|
||||||
|
" <ram:CategoryCode>S</ram:CategoryCode>\n" +
|
||||||
|
" <ram:RateApplicablePercent>" + vatFormat(currentTaxPercent) + "</ram:RateApplicablePercent>\n" +
|
||||||
|
" </ram:CategoryTradeTax>\n" +
|
||||||
|
" </ram:SpecifiedTradeAllowanceCharge> \n";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((trans.getZFAllowances() != null) && (trans.getZFAllowances().length > 0)) {
|
if ((trans.getZFAllowances() != null) && (trans.getZFAllowances().length > 0)) {
|
||||||
xml = xml + " <ram:SpecifiedTradeAllowanceCharge>\n" +
|
for (BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) {
|
||||||
" <ram:ChargeIndicator>\n" +
|
if (!calc.getAllowancesForPercent(currentTaxPercent).equals(new BigDecimal(0))) {
|
||||||
" <udt:Indicator>false</udt:Indicator>\n" +
|
xml = xml + " <ram:SpecifiedTradeAllowanceCharge>\n" +
|
||||||
" </ram:ChargeIndicator>\n" +
|
" <ram:ChargeIndicator>\n" +
|
||||||
" <ram:ActualAmount>" + currencyFormat(calc.getAllowances()) + "</ram:ActualAmount>\n" +
|
" <udt:Indicator>false</udt:Indicator>\n" +
|
||||||
" <ram:Reason>Allowance</ram:Reason>\n" +
|
" </ram:ChargeIndicator>\n" +
|
||||||
" <ram:CategoryTradeTax>\n" +
|
" <ram:ActualAmount>" + currencyFormat(calc.getAllowancesForPercent(currentTaxPercent)) + "</ram:ActualAmount>\n" +
|
||||||
" <ram:TypeCode>VAT</ram:TypeCode>\n" +
|
" <ram:Reason>Allowance</ram:Reason>\n" +
|
||||||
" <ram:CategoryCode>S</ram:CategoryCode>\n" +
|
" <ram:CategoryTradeTax>\n" +
|
||||||
" <ram:RateApplicablePercent>19.00</ram:RateApplicablePercent>\n" +
|
" <ram:TypeCode>VAT</ram:TypeCode>\n" +
|
||||||
" </ram:CategoryTradeTax>\n" +
|
" <ram:CategoryCode>S</ram:CategoryCode>\n" +
|
||||||
" </ram:SpecifiedTradeAllowanceCharge> \n";
|
" <ram:RateApplicablePercent>" + vatFormat(currentTaxPercent) + "</ram:RateApplicablePercent>\n" +
|
||||||
|
" </ram:CategoryTradeTax>\n" +
|
||||||
|
" </ram:SpecifiedTradeAllowanceCharge> \n";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -547,9 +557,9 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String allowanceTotalLine = "<ram:AllowanceTotalAmount>" + currencyFormat(calc.getAllowances()) + "</ram:AllowanceTotalAmount>";
|
String allowanceTotalLine = "<ram:AllowanceTotalAmount>" + currencyFormat(calc.getAllowancesForPercent(null)) + "</ram:AllowanceTotalAmount>";
|
||||||
|
|
||||||
String chargesTotalLine = "<ram:ChargeTotalAmount>" + currencyFormat(calc.getCharges()) + "</ram:ChargeTotalAmount>";
|
String chargesTotalLine = "<ram:ChargeTotalAmount>" + currencyFormat(calc.getChargesForPercent(null)) + "</ram:ChargeTotalAmount>";
|
||||||
|
|
||||||
xml = xml + " <ram:SpecifiedTradeSettlementHeaderMonetarySummation>\n"
|
xml = xml + " <ram:SpecifiedTradeSettlementHeaderMonetarySummation>\n"
|
||||||
+ " <ram:LineTotalAmount>" + currencyFormat(calc.getTotal()) + "</ram:LineTotalAmount>\n" //$NON-NLS-2$
|
+ " <ram:LineTotalAmount>" + currencyFormat(calc.getTotal()) + "</ram:LineTotalAmount>\n" //$NON-NLS-2$
|
||||||
|
|||||||
@@ -256,9 +256,11 @@ public class ZF2PushTest extends TestCase {
|
|||||||
.setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).ignorePDFAErrors()
|
.setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).ignorePDFAErrors()
|
||||||
.load(SOURCE_PDF)) {
|
.load(SOURCE_PDF)) {
|
||||||
|
|
||||||
ze.setTransaction(new Invoice().addNote("document level 1/2").addNote("document level 2/2").setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID(taxID)).setOwnVATID("DE0815").setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE4711").setContact(new Contact("Franz Müller", "01779999999", "franz@mueller.de", "teststr. 12", "55232", "Entenhausen", "DE"))).setNumber(number).addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), price, new BigDecimal(1.0)).addNote("item level 1/1"))
|
ze.setTransaction(new Invoice().setCurrency("CHF").addNote("document level 1/2").addNote("document level 2/2").setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID(taxID)).setOwnVATID("DE0815").setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE4711").setContact(new Contact("Franz Müller", "01779999999", "franz@mueller.de", "teststr. 12", "55232", "Entenhausen", "DE"))).setNumber(number).addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(16)), price, new BigDecimal(1.0)).addNote("item level 1/1"))
|
||||||
|
.addCharge(new Charge(new BigDecimal(0.5)).setTaxPercent(new BigDecimal(16)))
|
||||||
|
.addAllowance(new Allowance(new BigDecimal(0.2)).setTaxPercent(new BigDecimal(16)))
|
||||||
);
|
);
|
||||||
|
|
||||||
String theXML = new String(ze.getProvider().getXML());
|
String theXML = new String(ze.getProvider().getXML());
|
||||||
assertTrue(theXML.contains("<rsm:CrossIndustryInvoice"));
|
assertTrue(theXML.contains("<rsm:CrossIndustryInvoice"));
|
||||||
ze.export(TARGET_PUSHEDGE);
|
ze.export(TARGET_PUSHEDGE);
|
||||||
|
|||||||
Reference in New Issue
Block a user