@@ -606,6 +606,19 @@ public Invoice extractInto(Invoice zpp) throws XPathExpressionException, ParseEx
606606 if (!issueDateStr .isEmpty ()) {
607607 issueDate = parseDate (issueDateStr , "yyyy-MM-dd" );
608608 }
609+
610+ String tenderReference = extractString ("/*[local-name()=\" Invoice\" or local-name()=\" CreditNote\" ]/*[local-name()=\" OriginatorDocumentReference\" ]/*[local-name()=\" ID\" ]" ).trim ();
611+ String tenderReferenceDate = extractString ("/*[local-name()=\" Invoice\" or local-name()=\" CreditNote\" ]/*[local-name()=\" OriginatorDocumentReference\" ]/*[local-name()=\" ID\" ]" ).trim ();
612+ //if (tenderReference!=null) zpp... @todo bt-17 create a ubl with a date and set up an according xpath and if only tenderReference!=null only set that but if tenderReference!=null&&date!=null set both in zpp
613+ if ((tenderReference != null )&&(!tenderReference .isEmpty ())){
614+ if ((tenderReferenceDate != null )&&(!tenderReferenceDate .isEmpty ())){
615+ zpp .setTenderReferencedDocument (new ReferencedDocument (tenderReference , parseDate (tenderReferenceDate , "yyyy-MM-dd" )));
616+ } else {
617+ zpp .setTenderReferencedDocument (tenderReference );
618+ }
619+
620+ }
621+
609622 String dueDt = extractString ("/*[local-name()=\" Invoice\" or local-name()=\" CreditNote\" ]/*[local-name()=\" DueDate\" ]" ).trim ();
610623 if (!dueDt .isEmpty ()) {
611624 dueDate = parseDate (dueDt , "yyyy-MM-dd" );
@@ -671,6 +684,9 @@ public Invoice extractInto(Invoice zpp) throws XPathExpressionException, ParseEx
671684 NodeList headerTradeAgreementNodes = (NodeList ) xpr .evaluate (getDocument (), XPathConstants .NODESET );
672685 String buyerOrderIssuerAssignedID = null ;
673686 String sellerOrderIssuerAssignedID = null ;
687+ String additionalReferencedDocument = null ;
688+ Date additionalReferencedDocumentDate = null ;
689+
674690 for (int i = 0 ; i < headerTradeAgreementNodes .getLength (); i ++) {
675691 // XMLTools.trimOrNull(nodes.item(i)))) {
676692 Node headerTradeAgreementNode = headerTradeAgreementNodes .item (i );
@@ -696,12 +712,55 @@ public Invoice extractInto(Invoice zpp) throws XPathExpressionException, ParseEx
696712 }
697713 }
698714 }
715+ int typeC = 0 ;
716+ additionalReferencedDocument =null ;
717+ additionalReferencedDocumentDate =null ;
718+ //Reading BT-17
719+ if (headerTradeAgreementChilds .item (agreementChildIndex ).getLocalName ().equals ("AdditionalReferencedDocument" )) {
720+ NodeList additionalChilds = headerTradeAgreementChilds .item (agreementChildIndex ).getChildNodes ();
721+ for (int additionalChildIndex = 0 ; additionalChildIndex < additionalChilds .getLength (); additionalChildIndex ++) {
722+
723+ if ((additionalChilds .item (additionalChildIndex ).getLocalName () != null )
724+ && additionalChilds .item (additionalChildIndex ).getLocalName ().equals ("TypeCode" )) {
725+ typeC = Integer .parseInt (XMLTools .trimOrNull (additionalChilds .item (additionalChildIndex )));
726+ }
727+
728+ if ((additionalChilds .item (additionalChildIndex ).getLocalName () != null )
729+ && (additionalChilds .item (additionalChildIndex ).getLocalName ().equals ("IssuerAssignedID" ))) {
730+ additionalReferencedDocument = XMLTools .trimOrNull (additionalChilds .item (additionalChildIndex ));
731+ }
732+ if ((additionalChilds .item (additionalChildIndex ).getLocalName () != null )
733+ && (additionalChilds .item (additionalChildIndex ).getLocalName ().equals ("FormattedIssueDateTime" ))) {
734+
735+ NodeList FormattedIssueDateTimeChilds = additionalChilds .item (additionalChildIndex ).getChildNodes ();
736+ for (int dateChildIndex = 0 ; dateChildIndex < FormattedIssueDateTimeChilds .getLength (); dateChildIndex ++) {
737+ if ((FormattedIssueDateTimeChilds .item (dateChildIndex ).getLocalName () != null )
738+ && (FormattedIssueDateTimeChilds .item (dateChildIndex ).getLocalName ().equals ("DateTimeString" ))) {
739+ additionalReferencedDocumentDate = XMLTools .tryDate (FormattedIssueDateTimeChilds .item (dateChildIndex ));
740+ }
741+
742+ }
743+ }
744+
745+ }
746+ if (typeC == 50 ) {
747+ if (additionalReferencedDocument != null ){
748+ if (additionalReferencedDocumentDate !=null ) {
749+ zpp .setTenderReferencedDocument (new ReferencedDocument (additionalReferencedDocument , additionalReferencedDocumentDate ));
750+ } else {
751+ zpp .setTenderReferencedDocument (additionalReferencedDocument );
752+ }
753+ }
754+
755+ }
756+ }
699757 }
700758 }
701-
702759 }
703760
704761
762+
763+
705764 String currency = extractString ("//*[local-name()=\" ApplicableHeaderTradeSettlement\" ]/*[local-name()=\" InvoiceCurrencyCode\" ]|//*[local-name()=\" DocumentCurrencyCode\" ]" );
706765 zpp .setCurrency (currency );
707766
@@ -936,6 +995,7 @@ public Invoice extractInto(Invoice zpp) throws XPathExpressionException, ParseEx
936995 zpp .setDespatchAdviceReferencedDocumentID (s );
937996 }
938997 }
998+
939999 String invoiceReferencedDocumentID = extractString ("//*[local-name()=\" InvoiceReferencedDocument\" ]/*[local-name()=\" IssuerAssignedID\" ]|//*[local-name()=\" BillingReference\" ]/*[local-name()=\" InvoiceDocumentReference\" ]/*[local-name()=\" ID\" ]" );
9401000 if (!invoiceReferencedDocumentID .isEmpty ()) {
9411001 zpp .setInvoiceReferencedDocumentID (invoiceReferencedDocumentID );
0 commit comments