Skip to content

Commit

Permalink
Merges+Fixt
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Schmaltz committed Jun 19, 2024
1 parent b84aab8 commit 0e716b5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 187 deletions.
45 changes: 18 additions & 27 deletions library/src/main/java/org/mustangproject/Item.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package org.mustangproject;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.fop.util.XMLUtil;
import org.mustangproject.ZUGFeRD.IReferencedDocument;
import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge;
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/***
* describes any invoice line
Expand All @@ -32,11 +33,9 @@ public class Item implements IZUGFeRDExportableItem {

/***
* default constructor
*
* @param product contains the products name, tax rate, and unit
* @param price the base price of one item the product
* @param quantity the number, dimensions or the weight of the delivered product
* or good in this context
* @param quantity the number, dimensions or the weight of the delivered product or good in this context
*/
public Item(Product product, BigDecimal price, BigDecimal quantity) {
this.price = price;
Expand All @@ -45,8 +44,9 @@ public Item(Product product, BigDecimal price, BigDecimal quantity) {
}

/***
* empty constructor do not use, but might be used e.g. by jackson
*/
* empty constructor
* do not use, but might be used e.g. by jackson
* */
public Item() {
}

Expand Down Expand Up @@ -274,7 +274,6 @@ public Item addReferencedLineID(String s) {

/***
* BT 132 (issue https://github.com/ZUGFeRD/mustangproject/issues/247)
*
* @return the line ID of the order (BT132)
*/
@Override
Expand Down Expand Up @@ -303,7 +302,6 @@ public BigDecimal getGrossPrice() {

/***
* the list price without VAT (sic!), refer to EN16931-1 for definition
*
* @param grossPrice the list price without VAT
* @return fluent setter
*/
Expand Down Expand Up @@ -400,7 +398,6 @@ public Item setProduct(Product product) {

/***
* Adds a item level addition to the price (will be multiplied by quantity)
*
* @see org.mustangproject.Charge
* @param izac a relative or absolute charge
* @return fluent setter
Expand All @@ -412,7 +409,6 @@ public Item addCharge(IZUGFeRDAllowanceCharge izac) {

/***
* Adds a item level reduction the price (will be multiplied by quantity)
*
* @see org.mustangproject.Allowance
* @param izac a relative or absolute allowance
* @return fluent setter
Expand All @@ -424,7 +420,6 @@ public Item addAllowance(IZUGFeRDAllowanceCharge izac) {

/***
* adds item level freetext fields (includednote)
*
* @param text UTF8 plain text
* @return fluent setter
*/
Expand All @@ -437,9 +432,7 @@ public Item addNote(String text) {
}

/***
* adds item level Referenced documents along with their typecodes and
* issuerassignedIDs
*
* adds item level Referenced documents along with their typecodes and issuerassignedIDs
* @param doc the ReferencedDocument to add
* @return fluent setter
*/
Expand All @@ -460,9 +453,9 @@ public IReferencedDocument[] getReferencedDocuments() {
}

/***
* specify a item level delivery period (apart from the document level delivery
* period, and the document level delivery day, which is probably anyway
* required)
* specify a item level delivery period
* (apart from the document level delivery period, and the document level
* delivery day, which is probably anyway required)
*
* @param from start date
* @param to end date
Expand All @@ -475,19 +468,17 @@ public Item setDetailedDeliveryPeriod(Date from, Date to) {
}

/***
* specifies the item level delivery period (there is also one on document
* level), this will be included in a BillingSpecifiedPeriod element
*
* specifies the item level delivery period (there is also one on document level),
* this will be included in a BillingSpecifiedPeriod element
* @return the beginning of the delivery period
*/
public Date getDetailedDeliveryPeriodFrom() {
return detailedDeliveryPeriodFrom;
}

/***
* specifies the item level delivery period (there is also one on document
* level), this will be included in a BillingSpecifiedPeriod element
*
* specifies the item level delivery period (there is also one on document level),
* this will be included in a BillingSpecifiedPeriod element
* @return the end of the delivery period
*/
public Date getDetailedDeliveryPeriodTo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,166 +328,12 @@ public Invoice extractInto(Invoice zpp) throws XPathExpressionException, ParseEx
if (nodes.getLength() != 0) {
for (int i = 0; i < nodes.getLength(); i++) {

String price = "0";
String name = "";
String description = "";
SchemedID gid = null;
String quantity = "0";
String vatPercent = null;
String lineTotal = "0";
String unitCode = "0";

ArrayList<ReferencedDocument> rdocs = null;

// nodes.item(i).getTextContent())) {
Node currentItemNode = nodes.item(i);
NodeList itemChilds = currentItemNode.getChildNodes();
for (int itemChildIndex = 0; itemChildIndex < itemChilds.getLength(); itemChildIndex++) {
String lineTrade = itemChilds.item(itemChildIndex).getLocalName();
if ((lineTrade != null) && (lineTrade.equals("SpecifiedLineTradeAgreement")
|| lineTrade.equals("SpecifiedSupplyChainTradeAgreement"))) {
NodeList tradeLineChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int tradeLineChildIndex = 0; tradeLineChildIndex < tradeLineChilds
.getLength(); tradeLineChildIndex++) {

if ((tradeLineChilds.item(tradeLineChildIndex).getLocalName() != null) && tradeLineChilds
.item(tradeLineChildIndex).getLocalName().equals("AdditionalReferencedDocument")) {
String IssuerAssignedID = "";
String TypeCode = "";
String ReferenceTypeCode = "";

NodeList refDocChilds = tradeLineChilds.item(tradeLineChildIndex).getChildNodes();
for (int refDocIndex = 0; refDocIndex < refDocChilds.getLength(); refDocIndex++) {
String localName = refDocChilds.item(refDocIndex).getLocalName();
if ((localName != null) && (localName.equals("IssuerAssignedID"))) {
IssuerAssignedID = refDocChilds.item(refDocIndex).getTextContent();
}
if ((localName != null) && (localName.equals("TypeCode"))) {
TypeCode = refDocChilds.item(refDocIndex).getTextContent();
}
if ((localName != null) && (localName.equals("ReferenceTypeCode"))) {
ReferenceTypeCode = refDocChilds.item(refDocIndex).getTextContent();
}
}

ReferencedDocument rd = new ReferencedDocument(IssuerAssignedID, TypeCode,
ReferenceTypeCode);
if (rdocs == null) {
rdocs = new ArrayList<ReferencedDocument>();
}
rdocs.add(rd);

}

if ((tradeLineChilds.item(tradeLineChildIndex).getLocalName() != null) && tradeLineChilds
.item(tradeLineChildIndex).getLocalName().equals("NetPriceProductTradePrice")) {
NodeList netChilds = tradeLineChilds.item(tradeLineChildIndex).getChildNodes();
for (int netIndex = 0; netIndex < netChilds.getLength(); netIndex++) {
if ((netChilds.item(netIndex).getLocalName() != null)
&& (netChilds.item(netIndex).getLocalName().equals("ChargeAmount"))) {
price = netChilds.item(netIndex).getTextContent();// ChargeAmount

}
}
}
}
}
if ((lineTrade != null) && (lineTrade.equals("SpecifiedLineTradeDelivery")
|| lineTrade.equals("SpecifiedSupplyChainTradeDelivery"))) {
NodeList tradeLineChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int tradeLineChildIndex = 0; tradeLineChildIndex < tradeLineChilds
.getLength(); tradeLineChildIndex++) {
String tradeName = tradeLineChilds.item(tradeLineChildIndex).getLocalName();
if ((tradeName != null)
&& (tradeName.equals("BilledQuantity") || tradeName.equals("RequestedQuantity")
|| tradeName.equals("DespatchedQuantity"))) {
// RequestedQuantity is for Order-X, BilledQuantity for FX and ZF
quantity = tradeLineChilds.item(tradeLineChildIndex).getTextContent();
unitCode = tradeLineChilds.item(tradeLineChildIndex).getAttributes()
.getNamedItem("unitCode").getNodeValue();
}
}
}
if ((lineTrade != null) && (lineTrade.equals("SpecifiedTradeProduct"))) {
NodeList tradeProductChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int tradeProductChildIndex = 0; tradeProductChildIndex < tradeProductChilds
.getLength(); tradeProductChildIndex++) {
if ((tradeProductChilds.item(tradeProductChildIndex).getLocalName() != null)
&& (tradeProductChilds.item(tradeProductChildIndex).getLocalName()
.equals("Name"))) {
name = tradeProductChilds.item(tradeProductChildIndex).getTextContent();
}
if ((tradeProductChilds.item(tradeProductChildIndex).getLocalName() != null)
&& (tradeProductChilds.item(tradeProductChildIndex).getLocalName()
.equals("GlobalID"))) {
if (tradeProductChilds.item(tradeProductChildIndex).getAttributes()
.getNamedItem("schemeID") != null) {
gid = new SchemedID()
.setScheme(tradeProductChilds.item(tradeProductChildIndex).getAttributes()
.getNamedItem("schemeID").getNodeValue())
.setId(tradeProductChilds.item(tradeProductChildIndex).getTextContent());
}

}
}
}
if ((lineTrade != null) && (lineTrade.equals("SpecifiedLineTradeSettlement")
|| lineTrade.equals("SpecifiedSupplyChainTradeSettlement"))) {
NodeList tradeSettlementChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int tradeSettlementChildIndex = 0; tradeSettlementChildIndex < tradeSettlementChilds
.getLength(); tradeSettlementChildIndex++) {

String tradeSettlementName = tradeSettlementChilds.item(tradeSettlementChildIndex)
.getLocalName();
if (tradeSettlementName != null) {
if (tradeSettlementName.equals("ApplicableTradeTax")) {
NodeList taxChilds = tradeSettlementChilds.item(tradeSettlementChildIndex)
.getChildNodes();
for (int taxChildIndex = 0; taxChildIndex < taxChilds
.getLength(); taxChildIndex++) {
String taxChildName = taxChilds.item(taxChildIndex).getLocalName();
if ((taxChildName != null) && (taxChildName.equals("RateApplicablePercent")
|| taxChildName.equals("ApplicablePercent"))) {
vatPercent = taxChilds.item(taxChildIndex).getTextContent();
}
}
}

if (tradeSettlementName.equals("SpecifiedTradeSettlementLineMonetarySummation")) {
NodeList totalChilds = tradeSettlementChilds.item(tradeSettlementChildIndex)
.getChildNodes();
for (int totalChildIndex = 0; totalChildIndex < totalChilds
.getLength(); totalChildIndex++) {
if ((totalChilds.item(totalChildIndex).getLocalName() != null) && (totalChilds
.item(totalChildIndex).getLocalName().equals("LineTotalAmount"))) {
lineTotal = totalChilds.item(totalChildIndex).getTextContent();
}
}
}
}
}
}
}
BigDecimal prc = new BigDecimal(price.trim());
BigDecimal qty = new BigDecimal(quantity.trim());
if ((recalcPrice) && (!qty.equals(BigDecimal.ZERO))) {
prc = new BigDecimal(lineTotal.trim()).divide(qty, 4, RoundingMode.HALF_UP);
}
Product p = new Product(name, description, unitCode,
vatPercent == null ? null : new BigDecimal(vatPercent.trim()));
if (gid != null) {
p.addGlobalID(gid);
}
Item it = new Item(p, prc, qty);
if (rdocs != null) {
for (ReferencedDocument rdoc : rdocs) {
it.addReferencedDocument(rdoc);
}
}
Item it = new Item(currentItemNode.getChildNodes(), recalcPrice);
zpp.addItem(it);

}

// item level charges+allowances are not yet handled but a lower item price will
// be read,
// so the invoice remains arithmetically correct
Expand Down
13 changes: 9 additions & 4 deletions library/src/test/java/org/mustangproject/ZUGFeRD/UBLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,30 @@
*/
package org.mustangproject.ZUGFeRD;

import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.ParseException;
import java.util.Date;

import javax.xml.xpath.XPathExpressionException;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.mustangproject.BankDetails;
import org.mustangproject.CII.CIIToUBL;
import org.mustangproject.Contact;
import org.mustangproject.Invoice;
import org.mustangproject.Item;
import org.mustangproject.Product;
import org.mustangproject.TradeParty;

import javax.xml.xpath.XPathExpressionException;
import org.mustangproject.CII.CIIToUBL;

public class UBLTest extends ResourceCase {
final String TARGET_XML = "./target/testout-1Lieferschein.xml";
Expand Down Expand Up @@ -112,6 +116,7 @@ public void testEdgeInvoiceImportUBL() {
invoice = zii.extractInvoice();
} catch (XPathExpressionException | ParseException | FileNotFoundException e) {
hasExceptions = true;
e.printStackTrace();
}
assertFalse(hasExceptions);
// Reading ZUGFeRD
Expand Down

0 comments on commit 0e716b5

Please sign in to comment.