Relative charges/allowances on document level
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.mustangproject;
|
||||
|
||||
import org.mustangproject.ZUGFeRD.IAbsoluteValueProvider;
|
||||
import org.mustangproject.ZUGFeRD.IExportableTransaction;
|
||||
import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge;
|
||||
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem;
|
||||
@@ -55,27 +56,16 @@ public class Charge implements IZUGFeRDAllowanceCharge {
|
||||
|
||||
|
||||
@Override
|
||||
public BigDecimal getTotalAmount(IZUGFeRDExportableItem currentItem) {
|
||||
public BigDecimal getTotalAmount(IAbsoluteValueProvider currentItem) {
|
||||
if (totalAmount!=null) {
|
||||
return totalAmount;
|
||||
} else if (percent!=null) {
|
||||
return currentItem.getPrice().multiply(getPercent().divide(new BigDecimal(100)));
|
||||
return currentItem.getValue().multiply(getPercent().divide(new BigDecimal(100)));
|
||||
} else {
|
||||
throw new RuntimeException("Either totalAmount or percent must be set");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getTotalAmount(IExportableTransaction currentTrans) {
|
||||
// if (totalAmount!=null) {
|
||||
return totalAmount;
|
||||
// } else //if (percent!=null) {
|
||||
// to be implemented return currentItem.get().multiply(getPercent().divide(new BigDecimal(100)));
|
||||
//} else {
|
||||
// throw new RuntimeException("Either totalAmount or percent must be set");
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
public BigDecimal getPercent() {
|
||||
return percent;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/** **********************************************************************
|
||||
*
|
||||
* Copyright 2018 Jochen Staerk
|
||||
*
|
||||
* Use is subject to license terms.
|
||||
*
|
||||
* 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;
|
||||
|
||||
public interface IAbsoluteValueProvider {
|
||||
|
||||
public BigDecimal getValue();
|
||||
|
||||
}
|
||||
@@ -32,7 +32,7 @@ import java.util.Date;
|
||||
|
||||
import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants;
|
||||
|
||||
public interface IExportableTransaction {
|
||||
public interface IExportableTransaction {
|
||||
|
||||
/**
|
||||
* appears in /rsm:CrossIndustryDocument/rsm:HeaderExchangedDocument/ram:Name
|
||||
|
||||
@@ -24,8 +24,7 @@ import java.math.BigDecimal;
|
||||
*/
|
||||
public interface IZUGFeRDAllowanceCharge {
|
||||
|
||||
BigDecimal getTotalAmount(IZUGFeRDExportableItem currentItem);
|
||||
BigDecimal getTotalAmount(IExportableTransaction trans);
|
||||
BigDecimal getTotalAmount(IAbsoluteValueProvider trans);
|
||||
|
||||
String getReason();
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.mustangproject.ZUGFeRD.model.TaxCategoryCodeTypeConstants;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public interface IZUGFeRDExportableItem {
|
||||
public interface IZUGFeRDExportableItem extends IAbsoluteValueProvider{
|
||||
|
||||
IZUGFeRDExportableProduct getProduct();
|
||||
|
||||
@@ -46,6 +46,10 @@ public interface IZUGFeRDExportableItem {
|
||||
*/
|
||||
BigDecimal getPrice();
|
||||
|
||||
@Override
|
||||
default BigDecimal getValue() {
|
||||
return getPrice();
|
||||
}
|
||||
/**
|
||||
* how many get billed
|
||||
*
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.dom4j.io.XMLWriter;
|
||||
import org.mustangproject.Invoice;
|
||||
import org.mustangproject.XMLTools;
|
||||
|
||||
public class ZUGFeRD2PullProvider implements IXMLProvider {
|
||||
public class ZUGFeRD2PullProvider implements IXMLProvider, IAbsoluteValueProvider {
|
||||
|
||||
//// MAIN CLASS
|
||||
protected SimpleDateFormat zugferdDateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||
@@ -96,7 +96,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
//move
|
||||
private BigDecimal getTotalPrepaid() {
|
||||
if (trans.getTotalPrepaidAmount() == null) {
|
||||
return new BigDecimal(0);
|
||||
@@ -121,7 +121,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
||||
IZUGFeRDAllowanceCharge[] charges = trans.getZFCharges();
|
||||
if ((charges != null) && (charges.length > 0)) {
|
||||
for (IZUGFeRDAllowanceCharge currentCharge : charges) {
|
||||
res = res.add(currentCharge.getTotalAmount(trans));
|
||||
res = res.add(currentCharge.getTotalAmount(this));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
@@ -132,7 +132,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
||||
IZUGFeRDAllowanceCharge[] allowances = trans.getZFAllowances();
|
||||
if ((allowances != null) && (allowances.length > 0)) {
|
||||
for (IZUGFeRDAllowanceCharge currentAllowance : allowances) {
|
||||
res = res.add(currentAllowance.getTotalAmount(trans));
|
||||
res = res.add(currentAllowance.getTotalAmount(this));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
@@ -183,7 +183,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
||||
if (theAmount == null) {
|
||||
theAmount = new VATAmount(new BigDecimal(0), new BigDecimal(0), "S");
|
||||
}
|
||||
theAmount.setBasis(theAmount.getBasis().add(currentCharge.getTotalAmount(trans)));
|
||||
theAmount.setBasis(theAmount.getBasis().add(currentCharge.getTotalAmount(this)));
|
||||
BigDecimal factor = currentCharge.getTaxPercent().divide(new BigDecimal(100));
|
||||
theAmount.setCalculated(theAmount.getBasis().multiply(factor));
|
||||
hm.put(currentCharge.getTaxPercent(), theAmount);
|
||||
@@ -196,7 +196,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
||||
if (theAmount == null) {
|
||||
theAmount = new VATAmount(new BigDecimal(0), new BigDecimal(0), "S");
|
||||
}
|
||||
theAmount.setBasis(theAmount.getBasis().subtract(currentAllowance.getTotalAmount(trans)));
|
||||
theAmount.setBasis(theAmount.getBasis().subtract(currentAllowance.getTotalAmount(this)));
|
||||
BigDecimal factor = currentAllowance.getTaxPercent().divide(new BigDecimal(100));
|
||||
theAmount.setCalculated(theAmount.getBasis().multiply(factor));
|
||||
|
||||
@@ -207,7 +207,6 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
||||
|
||||
return hm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile getProfile() {
|
||||
return profile;
|
||||
@@ -466,7 +465,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
||||
+ XMLTools.encodeXML(trans.getContractReferencedDocument()) + "</ram:IssuerAssignedID>\n"
|
||||
+ " </ram:ContractReferencedDocument>\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
xml = xml + " </ram:ApplicableHeaderTradeAgreement>\n"
|
||||
+ " <ram:ApplicableHeaderTradeDelivery>\n";
|
||||
@@ -701,4 +700,8 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
||||
return paymentTermsXml;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getValue() {
|
||||
return getTotal();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user