Merge pull request #11 from AlexanderSchmidt/master
Validation error fixes and support for allowances, charges and service charges
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.rayman2200</groupId>
|
||||
<artifactId>mustang-sample-project</artifactId>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.mustangproject.ZUGFeRD</groupId>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2015 AlexanderSchmidt.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mustangproject.ZUGFeRD;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author AlexanderSchmidt
|
||||
*/
|
||||
public interface IZUGFeRDAllowanceCharge {
|
||||
BigDecimal getTotalAmount();
|
||||
|
||||
String getReason();
|
||||
|
||||
BigDecimal getTaxPercent();
|
||||
|
||||
}
|
||||
@@ -13,7 +13,8 @@ import java.math.BigDecimal;
|
||||
public interface IZUGFeRDExportableItem {
|
||||
|
||||
IZUGFeRDExportableProduct getProduct();
|
||||
|
||||
IZUGFeRDAllowanceCharge[] getItemAllowances();
|
||||
IZUGFeRDAllowanceCharge[] getItemCharges();
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,6 +45,10 @@ public interface IZUGFeRDExportableTransaction {
|
||||
* @return
|
||||
*/
|
||||
Date getDueDate();
|
||||
|
||||
IZUGFeRDAllowanceCharge[] getZFAllowances();
|
||||
IZUGFeRDAllowanceCharge[] getZFCharges();
|
||||
IZUGFeRDAllowanceCharge[] getZFLogisticsServiceCharges();
|
||||
|
||||
IZUGFeRDExportableItem[] getZFItems();
|
||||
|
||||
|
||||
@@ -11,32 +11,36 @@ import java.math.BigDecimal;
|
||||
* */
|
||||
public class VATAmount {
|
||||
|
||||
public VATAmount(BigDecimal basis, BigDecimal calculated) {
|
||||
super();
|
||||
this.basis = basis;
|
||||
this.calculated = calculated;
|
||||
}
|
||||
public VATAmount(BigDecimal basis, BigDecimal calculated) {
|
||||
super();
|
||||
this.basis = basis;
|
||||
this.calculated = calculated;
|
||||
}
|
||||
|
||||
BigDecimal basis, calculated;
|
||||
BigDecimal basis, calculated;
|
||||
|
||||
public BigDecimal getBasis() {
|
||||
return basis;
|
||||
}
|
||||
public BigDecimal getBasis() {
|
||||
return basis;
|
||||
}
|
||||
|
||||
public void setBasis(BigDecimal basis) {
|
||||
this.basis = basis;
|
||||
}
|
||||
public void setBasis(BigDecimal basis) {
|
||||
this.basis = basis;
|
||||
}
|
||||
|
||||
public BigDecimal getCalculated() {
|
||||
return calculated;
|
||||
}
|
||||
public BigDecimal getCalculated() {
|
||||
return calculated;
|
||||
}
|
||||
|
||||
public void setCalculated(BigDecimal calculated) {
|
||||
this.calculated = calculated;
|
||||
}
|
||||
|
||||
public VATAmount add(VATAmount v) {
|
||||
return new VATAmount(basis.add(v.getBasis()), calculated.add(v.getCalculated()));
|
||||
}
|
||||
public void setCalculated(BigDecimal calculated) {
|
||||
this.calculated = calculated;
|
||||
}
|
||||
|
||||
public VATAmount add(VATAmount v) {
|
||||
return new VATAmount(basis.add(v.getBasis()), calculated.add(v.getCalculated()));
|
||||
}
|
||||
|
||||
public VATAmount subtract(VATAmount v) {
|
||||
return new VATAmount(basis.subtract(v.getBasis()), calculated.subtract(v.getCalculated()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -72,29 +72,46 @@ public class ZUGFeRDExporter {
|
||||
* doc.save(PDFfilename);
|
||||
*
|
||||
* @author jstaerk
|
||||
* @throws javax.xml.bind.JAXBException
|
||||
*
|
||||
*/
|
||||
public ZUGFeRDExporter() throws JAXBException {
|
||||
jaxbContext = JAXBContext.newInstance("org.mustangproject.ZUGFeRD.model");
|
||||
marshaller = jaxbContext.createMarshaller();
|
||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
||||
marshaller.setProperty("jaxb.encoding", "UTF-8");
|
||||
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
|
||||
}
|
||||
|
||||
private class LineCalc {
|
||||
|
||||
private IZUGFeRDExportableItem currentItem = null;
|
||||
private BigDecimal totalGross;
|
||||
private BigDecimal itemTotalNetAmount;
|
||||
private BigDecimal itemTotalVATAmount;
|
||||
private BigDecimal itemNetAmount;
|
||||
|
||||
public LineCalc(IZUGFeRDExportableItem currentItem) {
|
||||
this.currentItem = currentItem;
|
||||
BigDecimal multiplicator = currentItem.getProduct().getVATPercent().divide(new BigDecimal(100)).add(new BigDecimal(1));
|
||||
BigDecimal totalAllowance = BigDecimal.ZERO;
|
||||
BigDecimal totalCharge = BigDecimal.ZERO;
|
||||
|
||||
if(currentItem.getItemAllowances() != null){
|
||||
for(IZUGFeRDAllowanceCharge itemAllowance : currentItem.getItemAllowances()){
|
||||
totalAllowance = itemAllowance.getTotalAmount().add(totalAllowance);
|
||||
}
|
||||
}
|
||||
|
||||
if(currentItem.getItemCharges() != null){
|
||||
for(IZUGFeRDAllowanceCharge itemCharge : currentItem.getItemCharges()){
|
||||
totalCharge = itemCharge.getTotalAmount().add(totalCharge);
|
||||
}
|
||||
}
|
||||
|
||||
BigDecimal multiplicator = currentItem.getProduct().getVATPercent().divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP).add(BigDecimal.ONE);
|
||||
// priceGross=currentItem.getPrice().multiply(multiplicator);
|
||||
totalGross = currentItem.getPrice().multiply(multiplicator).multiply(currentItem.getQuantity());
|
||||
itemTotalNetAmount = currentItem.getQuantity().multiply(currentItem.getPrice()).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
totalGross = currentItem.getPrice().multiply(currentItem.getQuantity()).subtract(totalAllowance).add(totalCharge).multiply(multiplicator);
|
||||
itemTotalNetAmount = currentItem.getPrice().multiply(currentItem.getQuantity()).subtract(totalAllowance).add(totalCharge).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
itemTotalVATAmount = totalGross.subtract(itemTotalNetAmount);
|
||||
itemNetAmount = currentItem.getPrice().multiply(currentItem.getQuantity()).subtract(totalAllowance).add(totalCharge).divide(currentItem.getQuantity(), 4, BigDecimal.ROUND_HALF_UP);
|
||||
}
|
||||
|
||||
public BigDecimal getItemTotalNetAmount() {
|
||||
@@ -104,12 +121,83 @@ public class ZUGFeRDExporter {
|
||||
public BigDecimal getItemTotalVATAmount() {
|
||||
return itemTotalVATAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getItemNetAmount(){
|
||||
return itemNetAmount;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class Totals{
|
||||
private BigDecimal totalNetAmount;
|
||||
private BigDecimal totalGrossAmount;
|
||||
private BigDecimal lineTotalAmount;
|
||||
private BigDecimal totalTaxAmount;
|
||||
|
||||
public Totals(){
|
||||
BigDecimal res = BigDecimal.ZERO;
|
||||
for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) {
|
||||
LineCalc lc = new LineCalc(currentItem);
|
||||
res = res.add(lc.getItemTotalNetAmount());
|
||||
}
|
||||
// Set line total
|
||||
this.lineTotalAmount = res;
|
||||
|
||||
if(trans.getZFAllowances() != null){
|
||||
for (IZUGFeRDAllowanceCharge headerAllowance : trans.getZFAllowances()){
|
||||
res = res.subtract(headerAllowance.getTotalAmount());
|
||||
}
|
||||
}
|
||||
|
||||
if(trans.getZFLogisticsServiceCharges()!= null){
|
||||
for (IZUGFeRDAllowanceCharge logisticsServiceCharge : trans.getZFLogisticsServiceCharges()){
|
||||
res = res.add(logisticsServiceCharge.getTotalAmount());
|
||||
}
|
||||
}
|
||||
|
||||
if(trans.getZFCharges()!= null){
|
||||
for (IZUGFeRDAllowanceCharge charge : trans.getZFCharges()){
|
||||
res = res.add(charge.getTotalAmount());
|
||||
}
|
||||
}
|
||||
|
||||
// Set total net amount
|
||||
this.totalNetAmount = res;
|
||||
|
||||
HashMap<BigDecimal, VATAmount> VATPercentAmountMap = getVATPercentAmountMap();
|
||||
for (BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) {
|
||||
VATAmount amount = VATPercentAmountMap.get(currentTaxPercent);
|
||||
res = res.add(amount.getCalculated());
|
||||
}
|
||||
|
||||
// Set total gross amount
|
||||
this.totalGrossAmount = res;
|
||||
|
||||
this.totalTaxAmount = this.totalGrossAmount.subtract(this.totalNetAmount);
|
||||
}
|
||||
|
||||
public BigDecimal getTotalNet(){
|
||||
return totalNetAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getTotalGross(){
|
||||
return totalGrossAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getLineTotal(){
|
||||
return lineTotalAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getTaxTotal(){
|
||||
return totalTaxAmount;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//// MAIN CLASS
|
||||
private String conformanceLevel = "U";
|
||||
private String versionStr = "1.2.0";
|
||||
private String versionStr = "1.3.0";
|
||||
|
||||
// BASIC, COMFORT etc - may be set from outside.
|
||||
private String ZUGFeRDConformanceLevel = null;
|
||||
@@ -335,9 +423,13 @@ public class ZUGFeRDExporter {
|
||||
private final Marshaller marshaller;
|
||||
private static final SimpleDateFormat germanDateFormat = new SimpleDateFormat("dd.MM.yyyy"); //$NON-NLS-1$
|
||||
private static final SimpleDateFormat zugferdDateFormat = new SimpleDateFormat("yyyyMMdd"); //$NON-NLS-1$
|
||||
|
||||
private Totals totals;
|
||||
|
||||
private String getZugferdXMLForTransaction(IZUGFeRDExportableTransaction trans) throws JAXBException {
|
||||
this.trans = trans;
|
||||
|
||||
this.totals = new Totals();
|
||||
|
||||
CrossIndustryDocumentType invoice = xmlFactory.createCrossIndustryDocumentType();
|
||||
|
||||
@@ -388,6 +480,10 @@ public class ZUGFeRDExporter {
|
||||
documentCodeType.setValue(DocumentCodeType.INVOICE);
|
||||
document.setTypeCode(documentCodeType);
|
||||
|
||||
TextType name = xmlFactory.createTextType();
|
||||
name.setValue("RECHNUNG");
|
||||
document.getName().add(name);
|
||||
|
||||
if (trans.getOwnOrganisationFullPlaintextInfo() != null) {
|
||||
NoteType regularInfo = xmlFactory.createNoteType();
|
||||
CodeType regularInfoSubjectCode = xmlFactory.createCodeType();
|
||||
@@ -534,6 +630,16 @@ public class ZUGFeRDExporter {
|
||||
tradeSettlement.getSpecifiedTradeSettlementPaymentMeans().add(this.getPaymentData());
|
||||
tradeSettlement.getApplicableTradeTax().addAll(this.getTradeTax());
|
||||
tradeSettlement.getSpecifiedTradePaymentTerms().addAll(this.getPaymentTerms());
|
||||
if(trans.getZFAllowances() != null){
|
||||
tradeSettlement.getSpecifiedTradeAllowanceCharge().addAll(this.getHeaderAllowances());
|
||||
}
|
||||
if(trans.getZFLogisticsServiceCharges()!= null){
|
||||
tradeSettlement.getSpecifiedLogisticsServiceCharge().addAll(this.getHeaderLogisticsServiceCharges());
|
||||
}
|
||||
if(trans.getZFCharges()!= null){
|
||||
tradeSettlement.getSpecifiedTradeAllowanceCharge().addAll(this.getHeaderCharges());
|
||||
}
|
||||
|
||||
tradeSettlement.setSpecifiedTradeSettlementMonetarySummation(this.getMonetarySummation());
|
||||
|
||||
return tradeSettlement;
|
||||
@@ -603,6 +709,148 @@ public class ZUGFeRDExporter {
|
||||
return tradeTaxTypes;
|
||||
}
|
||||
|
||||
private Collection<TradeAllowanceChargeType> getHeaderAllowances() {
|
||||
List<TradeAllowanceChargeType> headerAllowances = new ArrayList<TradeAllowanceChargeType>();
|
||||
|
||||
for (IZUGFeRDAllowanceCharge iAllowance : trans.getZFAllowances()) {
|
||||
|
||||
TradeAllowanceChargeType allowance = xmlFactory.createTradeAllowanceChargeType();
|
||||
|
||||
IndicatorType chargeIndicator = xmlFactory.createIndicatorType();
|
||||
chargeIndicator.setIndicator(false);
|
||||
allowance.setChargeIndicator(chargeIndicator);
|
||||
|
||||
AmountType actualAmount = xmlFactory.createAmountType();
|
||||
actualAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
actualAmount.setValue(currencyFormat(iAllowance.getTotalAmount()));
|
||||
allowance.getActualAmount().add(actualAmount);
|
||||
|
||||
TextType reason = xmlFactory.createTextType();
|
||||
reason.setValue(iAllowance.getReason());
|
||||
allowance.setReason(reason);
|
||||
|
||||
TradeTaxType tradeTax = xmlFactory.createTradeTaxType();
|
||||
|
||||
PercentType vatPercent = xmlFactory.createPercentType();
|
||||
vatPercent.setValue(currencyFormat(iAllowance.getTaxPercent()));
|
||||
tradeTax.setApplicablePercent(vatPercent);
|
||||
|
||||
/* Only in extended
|
||||
AmountType basisAmount = xmlFactory.createAmountType();
|
||||
basisAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
basisAmount.setValue(amount.getBasis());
|
||||
allowance.setBasisAmount(basisAmount);
|
||||
*/
|
||||
TaxCategoryCodeType taxType = xmlFactory.createTaxCategoryCodeType();
|
||||
taxType.setValue(TaxCategoryCodeType.STANDARDRATE);
|
||||
tradeTax.setCategoryCode(taxType);
|
||||
|
||||
TaxTypeCodeType taxCode = xmlFactory.createTaxTypeCodeType();
|
||||
taxCode.setValue(TaxTypeCodeType.SALESTAX);
|
||||
tradeTax.setTypeCode(taxCode);
|
||||
|
||||
allowance.getCategoryTradeTax().add(tradeTax);
|
||||
headerAllowances.add(allowance);
|
||||
|
||||
}
|
||||
|
||||
return headerAllowances;
|
||||
}
|
||||
|
||||
private Collection<TradeAllowanceChargeType> getHeaderCharges() {
|
||||
List<TradeAllowanceChargeType> headerCharges = new ArrayList<TradeAllowanceChargeType>();
|
||||
|
||||
for (IZUGFeRDAllowanceCharge iCharge : trans.getZFCharges()) {
|
||||
|
||||
TradeAllowanceChargeType charge = xmlFactory.createTradeAllowanceChargeType();
|
||||
|
||||
IndicatorType chargeIndicator = xmlFactory.createIndicatorType();
|
||||
chargeIndicator.setIndicator(true);
|
||||
charge.setChargeIndicator(chargeIndicator);
|
||||
|
||||
AmountType actualAmount = xmlFactory.createAmountType();
|
||||
actualAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
actualAmount.setValue(currencyFormat(iCharge.getTotalAmount()));
|
||||
charge.getActualAmount().add(actualAmount);
|
||||
|
||||
TextType reason = xmlFactory.createTextType();
|
||||
reason.setValue(iCharge.getReason());
|
||||
charge.setReason(reason);
|
||||
|
||||
TradeTaxType tradeTax = xmlFactory.createTradeTaxType();
|
||||
|
||||
PercentType vatPercent = xmlFactory.createPercentType();
|
||||
vatPercent.setValue(currencyFormat(iCharge.getTaxPercent()));
|
||||
tradeTax.setApplicablePercent(vatPercent);
|
||||
|
||||
/* Only in extended
|
||||
AmountType basisAmount = xmlFactory.createAmountType();
|
||||
basisAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
basisAmount.setValue(amount.getBasis());
|
||||
allowance.setBasisAmount(basisAmount);
|
||||
*/
|
||||
TaxCategoryCodeType taxType = xmlFactory.createTaxCategoryCodeType();
|
||||
taxType.setValue(TaxCategoryCodeType.STANDARDRATE);
|
||||
tradeTax.setCategoryCode(taxType);
|
||||
|
||||
TaxTypeCodeType taxCode = xmlFactory.createTaxTypeCodeType();
|
||||
taxCode.setValue(TaxTypeCodeType.SALESTAX);
|
||||
tradeTax.setTypeCode(taxCode);
|
||||
|
||||
charge.getCategoryTradeTax().add(tradeTax);
|
||||
headerCharges.add(charge);
|
||||
|
||||
}
|
||||
|
||||
return headerCharges;
|
||||
}
|
||||
|
||||
private Collection<LogisticsServiceChargeType> getHeaderLogisticsServiceCharges() {
|
||||
List<LogisticsServiceChargeType> headerServiceCharge = new ArrayList<LogisticsServiceChargeType>();
|
||||
|
||||
for (IZUGFeRDAllowanceCharge iServiceCharge : trans.getZFLogisticsServiceCharges()) {
|
||||
|
||||
LogisticsServiceChargeType serviceCharge = xmlFactory.createLogisticsServiceChargeType();
|
||||
|
||||
AmountType actualAmount = xmlFactory.createAmountType();
|
||||
actualAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
actualAmount.setValue(currencyFormat(iServiceCharge.getTotalAmount()));
|
||||
serviceCharge.getAppliedAmount().add(actualAmount);
|
||||
|
||||
TextType reason = xmlFactory.createTextType();
|
||||
reason.setValue(iServiceCharge.getReason());
|
||||
serviceCharge.getDescription().add(reason);
|
||||
|
||||
TradeTaxType tradeTax = xmlFactory.createTradeTaxType();
|
||||
|
||||
PercentType vatPercent = xmlFactory.createPercentType();
|
||||
vatPercent.setValue(currencyFormat(iServiceCharge.getTaxPercent()));
|
||||
tradeTax.setApplicablePercent(vatPercent);
|
||||
|
||||
/* Only in extended
|
||||
AmountType basisAmount = xmlFactory.createAmountType();
|
||||
basisAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
basisAmount.setValue(amount.getBasis());
|
||||
allowance.setBasisAmount(basisAmount);
|
||||
*/
|
||||
TaxCategoryCodeType taxType = xmlFactory.createTaxCategoryCodeType();
|
||||
taxType.setValue(TaxCategoryCodeType.STANDARDRATE);
|
||||
tradeTax.setCategoryCode(taxType);
|
||||
|
||||
TaxTypeCodeType taxCode = xmlFactory.createTaxTypeCodeType();
|
||||
taxCode.setValue(TaxTypeCodeType.SALESTAX);
|
||||
tradeTax.setTypeCode(taxCode);
|
||||
|
||||
|
||||
|
||||
serviceCharge.getAppliedTradeTax().add(tradeTax);
|
||||
headerServiceCharge.add(serviceCharge);
|
||||
|
||||
}
|
||||
|
||||
return headerServiceCharge;
|
||||
}
|
||||
|
||||
private Collection<TradePaymentTermsType> getPaymentTerms() {
|
||||
List<TradePaymentTermsType> paymentTerms = new ArrayList<TradePaymentTermsType>();
|
||||
|
||||
@@ -622,43 +870,72 @@ public class ZUGFeRDExporter {
|
||||
paymentTerms.add(paymentTerm);
|
||||
|
||||
return paymentTerms;
|
||||
}
|
||||
}
|
||||
|
||||
private TradeSettlementMonetarySummationType getMonetarySummation() {
|
||||
TradeSettlementMonetarySummationType monetarySummation = xmlFactory.createTradeSettlementMonetarySummationType();
|
||||
|
||||
// AllowanceTotalAmount = sum of all allowances
|
||||
AmountType allowanceTotalAmount = xmlFactory.createAmountType();
|
||||
allowanceTotalAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
allowanceTotalAmount.setValue(currencyFormat(BigDecimal.ZERO));
|
||||
monetarySummation.getAllowanceTotalAmount().add(allowanceTotalAmount);
|
||||
if(trans.getZFAllowances() != null){
|
||||
BigDecimal totalHeaderAllowance = BigDecimal.ZERO;
|
||||
for(IZUGFeRDAllowanceCharge headerAllowance : trans.getZFAllowances()){
|
||||
totalHeaderAllowance = headerAllowance.getTotalAmount().add(totalHeaderAllowance);
|
||||
}
|
||||
allowanceTotalAmount.setValue(currencyFormat(totalHeaderAllowance));
|
||||
}else{
|
||||
allowanceTotalAmount.setValue(currencyFormat(BigDecimal.ZERO));
|
||||
}
|
||||
monetarySummation.getAllowanceTotalAmount().add(allowanceTotalAmount);
|
||||
|
||||
// ChargeTotalAmount = sum of all Logistic service charges + normal charges
|
||||
BigDecimal totalCharge = BigDecimal.ZERO;
|
||||
AmountType totalChargeAmount = xmlFactory.createAmountType();
|
||||
totalChargeAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
if(trans.getZFLogisticsServiceCharges()!= null){
|
||||
for(IZUGFeRDAllowanceCharge logisticsServiceCharge : trans.getZFLogisticsServiceCharges()){
|
||||
totalCharge = logisticsServiceCharge.getTotalAmount().add(totalCharge);
|
||||
}
|
||||
}
|
||||
if(trans.getZFCharges()!= null){
|
||||
for(IZUGFeRDAllowanceCharge charge : trans.getZFCharges()){
|
||||
totalCharge = charge.getTotalAmount().add(totalCharge);
|
||||
}
|
||||
}
|
||||
|
||||
totalChargeAmount.setValue(currencyFormat(totalCharge));
|
||||
|
||||
monetarySummation.getChargeTotalAmount().add(totalChargeAmount);
|
||||
|
||||
AmountType chargeTotalAmount = xmlFactory.createAmountType();
|
||||
/*AmountType chargeTotalAmount = xmlFactory.createAmountType();
|
||||
chargeTotalAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
chargeTotalAmount.setValue(currencyFormat(BigDecimal.ZERO));
|
||||
monetarySummation.getChargeTotalAmount().add(chargeTotalAmount);
|
||||
monetarySummation.getChargeTotalAmount().add(chargeTotalAmount);*/
|
||||
|
||||
AmountType lineTotalAmount = xmlFactory.createAmountType();
|
||||
lineTotalAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
lineTotalAmount.setValue(currencyFormat(this.getTotal()));
|
||||
lineTotalAmount.setValue(currencyFormat(totals.getLineTotal()));
|
||||
monetarySummation.getLineTotalAmount().add(lineTotalAmount);
|
||||
|
||||
AmountType taxBasisTotalAmount = xmlFactory.createAmountType();
|
||||
taxBasisTotalAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
taxBasisTotalAmount.setValue(currencyFormat(this.getTotal()));
|
||||
taxBasisTotalAmount.setValue(currencyFormat(totals.getTotalNet()));
|
||||
monetarySummation.getTaxBasisTotalAmount().add(taxBasisTotalAmount);
|
||||
|
||||
AmountType taxTotalAmount = xmlFactory.createAmountType();
|
||||
taxTotalAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
taxTotalAmount.setValue(currencyFormat(this.getTotalGross().subtract(this.getTotal())));
|
||||
taxTotalAmount.setValue(currencyFormat(totals.getTaxTotal()));
|
||||
monetarySummation.getTaxTotalAmount().add(taxTotalAmount);
|
||||
|
||||
AmountType grandTotalAmount = xmlFactory.createAmountType();
|
||||
grandTotalAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
grandTotalAmount.setValue(currencyFormat(this.getTotalGross()));
|
||||
grandTotalAmount.setValue(currencyFormat(totals.getTotalGross()));
|
||||
monetarySummation.getGrandTotalAmount().add(grandTotalAmount);
|
||||
|
||||
AmountType duePayableAmount = xmlFactory.createAmountType();
|
||||
duePayableAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
duePayableAmount.setValue(currencyFormat(this.getTotalGross()));
|
||||
duePayableAmount.setValue(currencyFormat(totals.getTotalGross()));
|
||||
monetarySummation.getDuePayableAmount().add(duePayableAmount);
|
||||
|
||||
return monetarySummation;
|
||||
@@ -688,9 +965,43 @@ public class ZUGFeRDExporter {
|
||||
|
||||
AmountType grossChargeAmount = xmlFactory.createAmountType();
|
||||
grossChargeAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
grossChargeAmount.setValue(currencyFormat(currentItem.getPrice()));
|
||||
grossChargeAmount.setValue(priceFormat(currentItem.getPrice()));
|
||||
grossTradePrice.getChargeAmount().add(grossChargeAmount);
|
||||
tradeAgreement.getGrossPriceProductTradePrice().add(grossTradePrice);
|
||||
|
||||
if(currentItem.getItemAllowances() != null){
|
||||
for(IZUGFeRDAllowanceCharge itemAllowance : currentItem.getItemAllowances()){
|
||||
TradeAllowanceChargeType eItemAllowance = xmlFactory.createTradeAllowanceChargeType();
|
||||
IndicatorType chargeIndicator = xmlFactory.createIndicatorType();
|
||||
chargeIndicator.setIndicator(false);
|
||||
eItemAllowance.setChargeIndicator(chargeIndicator);
|
||||
AmountType actualAmount = xmlFactory.createAmountType();
|
||||
actualAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
actualAmount.setValue(priceFormat(itemAllowance.getTotalAmount().divide(currentItem.getQuantity(), 4, BigDecimal.ROUND_HALF_UP)));
|
||||
eItemAllowance.getActualAmount().add(actualAmount);
|
||||
TextType reason = xmlFactory.createTextType();
|
||||
reason.setValue(itemAllowance.getReason());
|
||||
eItemAllowance.setReason(reason);
|
||||
grossTradePrice.getAppliedTradeAllowanceCharge().add(eItemAllowance);
|
||||
}
|
||||
}
|
||||
|
||||
if(currentItem.getItemCharges() != null){
|
||||
for(IZUGFeRDAllowanceCharge itemCharge : currentItem.getItemCharges()){
|
||||
TradeAllowanceChargeType eItemCharge = xmlFactory.createTradeAllowanceChargeType();
|
||||
AmountType actualAmount = xmlFactory.createAmountType();
|
||||
actualAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
actualAmount.setValue(priceFormat(itemCharge.getTotalAmount().divide(currentItem.getQuantity(), 4, BigDecimal.ROUND_HALF_UP)));
|
||||
eItemCharge.getActualAmount().add(actualAmount);
|
||||
TextType reason = xmlFactory.createTextType();
|
||||
reason.setValue(itemCharge.getReason());
|
||||
eItemCharge.setReason(reason);
|
||||
IndicatorType chargeIndicator = xmlFactory.createIndicatorType();
|
||||
chargeIndicator.setIndicator(true);
|
||||
eItemCharge.setChargeIndicator(chargeIndicator);
|
||||
grossTradePrice.getAppliedTradeAllowanceCharge().add(eItemCharge);
|
||||
}
|
||||
}
|
||||
|
||||
TradePriceType netTradePrice = xmlFactory.createTradePriceType();
|
||||
QuantityType netQuantity = xmlFactory.createQuantityType();
|
||||
@@ -700,7 +1011,7 @@ public class ZUGFeRDExporter {
|
||||
|
||||
AmountType netChargeAmount = xmlFactory.createAmountType();
|
||||
netChargeAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||
netChargeAmount.setValue(currencyFormat(currentItem.getPrice()));
|
||||
netChargeAmount.setValue(priceFormat(lc.getItemNetAmount()));
|
||||
netTradePrice.getChargeAmount().add(netChargeAmount);
|
||||
tradeAgreement.getNetPriceProductTradePrice().add(netTradePrice);
|
||||
|
||||
@@ -715,6 +1026,15 @@ public class ZUGFeRDExporter {
|
||||
|
||||
SupplyChainTradeSettlementType tradeSettlement = xmlFactory.createSupplyChainTradeSettlementType();
|
||||
TradeTaxType tradeTax = xmlFactory.createTradeTaxType();
|
||||
|
||||
TaxCategoryCodeType taxCategoryCode = xmlFactory.createTaxCategoryCodeType();
|
||||
taxCategoryCode.setValue(TaxCategoryCodeType.STANDARDRATE);
|
||||
tradeTax.setCategoryCode(taxCategoryCode);
|
||||
|
||||
TaxTypeCodeType taxCode = xmlFactory.createTaxTypeCodeType();
|
||||
taxCode.setValue(TaxTypeCodeType.SALESTAX);
|
||||
tradeTax.setTypeCode(taxCode);
|
||||
|
||||
PercentType taxPercent = xmlFactory.createPercentType();
|
||||
taxPercent.setValue(vatFormat(currentItem.getProduct().getVATPercent()));
|
||||
tradeTax.setApplicablePercent(taxPercent);
|
||||
@@ -746,27 +1066,6 @@ public class ZUGFeRDExporter {
|
||||
|
||||
}
|
||||
|
||||
private BigDecimal getTotalGross() {
|
||||
|
||||
BigDecimal res = getTotal();
|
||||
HashMap<BigDecimal, VATAmount> VATPercentAmountMap = getVATPercentAmountMap();
|
||||
for (BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) {
|
||||
VATAmount amount = VATPercentAmountMap.get(currentTaxPercent);
|
||||
res = res.add(amount.getCalculated());
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private BigDecimal getTotal() {
|
||||
BigDecimal res = new BigDecimal(0);
|
||||
for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) {
|
||||
LineCalc lc = new LineCalc(currentItem);
|
||||
res = res.add(lc.getItemTotalNetAmount());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* which taxes have been used with which amounts in this transaction, empty
|
||||
* for no taxes, or e.g. 19=>190 and 7=>14 if 1000 Eur were applicable to
|
||||
@@ -777,6 +1076,10 @@ public class ZUGFeRDExporter {
|
||||
*
|
||||
*/
|
||||
private HashMap<BigDecimal, VATAmount> getVATPercentAmountMap() {
|
||||
return getVATPercentAmountMap(false);
|
||||
}
|
||||
|
||||
private HashMap<BigDecimal, VATAmount> getVATPercentAmountMap(Boolean itemOnly){
|
||||
HashMap<BigDecimal, VATAmount> hm = new HashMap<BigDecimal, VATAmount>();
|
||||
|
||||
for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) {
|
||||
@@ -788,11 +1091,51 @@ public class ZUGFeRDExporter {
|
||||
hm.put(percent, itemVATAmount);
|
||||
} else {
|
||||
hm.put(percent, current.add(itemVATAmount));
|
||||
|
||||
}
|
||||
}
|
||||
if(itemOnly){
|
||||
return hm;
|
||||
}
|
||||
if(trans.getZFAllowances() != null){
|
||||
for (IZUGFeRDAllowanceCharge headerAllowance : trans.getZFAllowances()){
|
||||
BigDecimal percent = headerAllowance.getTaxPercent();
|
||||
VATAmount itemVATAmount = new VATAmount(headerAllowance.getTotalAmount(), headerAllowance.getTotalAmount().multiply(percent).divide(new BigDecimal(100)));
|
||||
VATAmount current = hm.get(percent);
|
||||
if (current == null) {
|
||||
hm.put(percent, itemVATAmount);
|
||||
} else {
|
||||
hm.put(percent, current.subtract(itemVATAmount));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(trans.getZFLogisticsServiceCharges()!= null){
|
||||
for (IZUGFeRDAllowanceCharge logisticsServiceCharge : trans.getZFLogisticsServiceCharges()){
|
||||
BigDecimal percent = logisticsServiceCharge.getTaxPercent();
|
||||
VATAmount itemVATAmount = new VATAmount(logisticsServiceCharge.getTotalAmount(), logisticsServiceCharge.getTotalAmount().multiply(percent).divide(new BigDecimal(100)));
|
||||
VATAmount current = hm.get(percent);
|
||||
if (current == null) {
|
||||
hm.put(percent, itemVATAmount);
|
||||
} else {
|
||||
hm.put(percent, current.add(itemVATAmount));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(trans.getZFCharges()!= null){
|
||||
for (IZUGFeRDAllowanceCharge charge : trans.getZFCharges()){
|
||||
BigDecimal percent = charge.getTaxPercent();
|
||||
VATAmount itemVATAmount = new VATAmount(charge.getTotalAmount(), charge.getTotalAmount().multiply(percent).divide(new BigDecimal(100)));
|
||||
VATAmount current = hm.get(percent);
|
||||
if (current == null) {
|
||||
hm.put(percent, itemVATAmount);
|
||||
} else {
|
||||
hm.put(percent, current.add(itemVATAmount));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hm;
|
||||
return hm;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -811,7 +1154,7 @@ public class ZUGFeRDExporter {
|
||||
// create a dummy file stream, this would probably normally be a
|
||||
// FileInputStream
|
||||
|
||||
byte[] zugferdRaw = getZugferdXMLForTransaction(trans).getBytes("UTF-8"); //$NON-NLS-1$
|
||||
byte[] zugferdRaw = getZugferdXMLForTransaction(trans).getBytes(); //$NON-NLS-1$
|
||||
|
||||
if ((zugferdRaw[0] == (byte) 0xEF) && (zugferdRaw[1] == (byte) 0xBB) && (zugferdRaw[2] == (byte) 0xBF)) {
|
||||
// I don't like BOMs, lets remove it
|
||||
|
||||
@@ -149,6 +149,21 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
|
||||
return "Zahlbar ohne Abzug bis zum " + germanDateFormat.format(getDueDate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZUGFeRDAllowanceCharge[] getZFAllowances() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZUGFeRDAllowanceCharge[] getZFCharges() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZUGFeRDAllowanceCharge[] getZFLogisticsServiceCharges() {
|
||||
return null;
|
||||
}
|
||||
|
||||
class Contact implements IZUGFeRDExportableContact
|
||||
{
|
||||
|
||||
@@ -236,6 +251,16 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
|
||||
this.product = product;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZUGFeRDAllowanceCharge[] getItemAllowances() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZUGFeRDAllowanceCharge[] getItemCharges() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Product implements IZUGFeRDExportableProduct
|
||||
|
||||
@@ -148,6 +148,24 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
|
||||
return "Zahlbar ohne Abzug bis zum " + germanDateFormat.format(getDueDate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZUGFeRDAllowanceCharge[] getZFAllowances() {
|
||||
return null;
|
||||
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZUGFeRDAllowanceCharge[] getZFCharges() {
|
||||
return null;
|
||||
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZUGFeRDAllowanceCharge[] getZFLogisticsServiceCharges() {
|
||||
return null;
|
||||
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
class Contact implements IZUGFeRDExportableContact
|
||||
{
|
||||
|
||||
@@ -234,6 +252,16 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
|
||||
{
|
||||
this.product = product;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZUGFeRDAllowanceCharge[] getItemAllowances() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZUGFeRDAllowanceCharge[] getItemCharges() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
24
nbactions.xml
Normal file
24
nbactions.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<actions>
|
||||
<action>
|
||||
<actionName>CUSTOM-Generate mvn-repo</actionName>
|
||||
<displayName>Generate mvn-repo</displayName>
|
||||
<goals>
|
||||
<goal>site:deploy</goal>
|
||||
</goals>
|
||||
</action>
|
||||
<action>
|
||||
<actionName>CUSTOM-mvn-repo</actionName>
|
||||
<displayName>mvn-repo</displayName>
|
||||
<goals>
|
||||
<goal>site</goal>
|
||||
</goals>
|
||||
</action>
|
||||
<action>
|
||||
<actionName>CUSTOM-deploy</actionName>
|
||||
<displayName>deploy</displayName>
|
||||
<goals>
|
||||
<goal>deploy</goal>
|
||||
</goals>
|
||||
</action>
|
||||
</actions>
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.rayman2200</groupId>
|
||||
<artifactId>mustang-sample-project</artifactId>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pdfa3-samples</artifactId>
|
||||
|
||||
12
pom.xml
12
pom.xml
@@ -2,13 +2,13 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.github.rayman2200</groupId>
|
||||
<artifactId>mustang-sample-project</artifactId>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://github.com/Rayman2200/PDFA3.git</connection>
|
||||
<developerConnection>scm:git:https://github.com/Rayman2200/PDFA3.git</developerConnection>
|
||||
<url>https://github.com/Rayman2200/PDFA3</url>
|
||||
<connection>scm:git:https://github.com/AlexanderSchmidt/PDFA3.git</connection>
|
||||
<developerConnection>scm:git:https://github.com/AlexanderSchmidt/PDFA3.git</developerConnection>
|
||||
<url>https://github.com/AlexanderSchmidt/PDFA3.git</url>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.pdfbox</groupId>
|
||||
<artifactId>pdfbox</artifactId>
|
||||
<version>1.8.8</version>
|
||||
<version>1.8.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
@@ -77,7 +77,7 @@
|
||||
</includes>
|
||||
<merge>true</merge>
|
||||
<repositoryName>PDFA3</repositoryName> <!-- github repo name -->
|
||||
<repositoryOwner>Rayman2200</repositoryOwner> <!-- github username -->
|
||||
<repositoryOwner>AlexanderSchmidt</repositoryOwner> <!-- github username -->
|
||||
</configuration>
|
||||
<executions>
|
||||
<!-- run site-maven-plugin's 'site' target as part of the build's normal
|
||||
|
||||
Reference in New Issue
Block a user