@@ -235,8 +235,20 @@ class function TXRechnungInvoiceAdapter301.LoadDocumentUBL(_Invoice: TInvoice;
235235 end ;
236236 if TXRechnungXMLHelper.SelectNode(xml,' //cac:DespatchDocumentReference/cbc:ID' ,node) then
237237 _Invoice.DeliveryReceiptNumber := node.Text;
238+ if TXRechnungXMLHelper.SelectNode(xml,' //cac:ReceiptDocumentReference/cbc:ID' ,node) then
239+ _Invoice.ReceiptDocumentReference := node.Text;
240+
241+ if TXRechnungXMLHelper.SelectNodes(xml,' //cac:OriginatorDocumentReference' ,nodes) then
242+ for i := 0 to nodes.length-1 do
243+ with _Invoice.Attachments.AddAttachment(iat_application_None) do
244+ begin
245+ ID := TXRechnungXMLHelper.SelectNodeText(nodes.item[i],' .//cbc:ID' );
246+ TypeCode := iatc_50;
247+ end ;
248+
238249 if TXRechnungXMLHelper.SelectNode(xml,' //cac:ContractDocumentReference/cbc:ID' ,node) then
239250 _Invoice.ContractDocumentReference := node.Text;
251+
240252 if TXRechnungXMLHelper.SelectNodes(xml,' //cac:AdditionalDocumentReference' ,nodes) then
241253 for i := 0 to nodes.length-1 do
242254 with _Invoice.Attachments.AddAttachment(iat_application_None) do
@@ -728,6 +740,10 @@ class function TXRechnungInvoiceAdapter301.LoadDocumentUNCEFACT(_Invoice: TInvoi
728740 if TXRechnungXMLHelper.SelectNode(nodeApplicableHeaderTradeAgreement,' .//ram:DespatchAdviceReferencedDocument' ,node2) then
729741 if TXRechnungXMLHelper.SelectNode(node2,' .//ram:IssuerAssignedID' ,node3) then
730742 _Invoice.DeliveryReceiptNumber := Node3.text;
743+
744+ if TXRechnungXMLHelper.SelectNode(nodeApplicableHeaderTradeAgreement,' .//ram:ReceivingAdviceReferencedDocument' ,node2) then
745+ if TXRechnungXMLHelper.SelectNode(node2,' .//ram:IssuerAssignedID' ,node3) then
746+ _Invoice.ReceiptDocumentReference := Node3.text;
731747 end ;
732748 if TXRechnungXMLHelper.SelectNode(nodeSupplyChainTradeTransaction,' .//ram:ApplicableHeaderTradeSettlement' ,nodeApplicableHeaderTradeAgreement) then
733749 begin
@@ -837,7 +853,8 @@ class function TXRechnungInvoiceAdapter301.LoadDocumentUNCEFACT(_Invoice: TInvoi
837853 end ;
838854 // Restliche Skontoeintraege finden
839855 for i := 0 to nodes.length-1 do
840- if (TXRechnungXMLHelper.FindNode(nodes[i],' .//ram:ApplicableTradePaymentDiscountTerms/ram:CalculationPercent' )) then
856+ if (TXRechnungXMLHelper.FindNode(nodes[i],' .//ram:ApplicableTradePaymentDiscountTerms/ram:CalculationPercent' ) or
857+ TXRechnungXMLHelper.FindNode(nodes[i],' .//ram:ApplicableTradePaymentDiscountTerms/ram:ActualDiscountAmount' )) then
841858 begin
842859 if _Invoice.PaymentTermsType in [iptt_None,iptt_Net] then
843860 _Invoice.PaymentTermsType := iptt_CashDiscount1
@@ -853,7 +870,13 @@ class function TXRechnungInvoiceAdapter301.LoadDocumentUNCEFACT(_Invoice: TInvoi
853870 _Invoice.PaymentTermCashDiscount1Percent := 0 ;
854871 _Invoice.PaymentTermCashDiscount1Base := 0 ;
855872 if TXRechnungXMLHelper.SelectNode(nodes[i],' .//ram:ApplicableTradePaymentDiscountTerms/ram:BasisPeriodMeasure' ,node3) then
856- _Invoice.PaymentTermCashDiscount1Days := StrToIntDef(node3.text,0 )
873+ begin
874+ _Invoice.PaymentTermCashDiscount1Days := StrToIntDef(node3.text,0 );
875+ // Sonderfall beim Einlesen von ZUGFeRD, wird intern von TInvoice nicht unterstuetzt
876+ // Das Basisdatum + Skontotage wird auf das Rechnungsdatum + Skontotage umgerechnet
877+ if TXRechnungXMLHelper.SelectNode(nodes[i],' .//ram:ApplicableTradePaymentDiscountTerms/ram:BasisDateTime/udt:DateTimeString' ,node3) then
878+ _Invoice.PaymentTermCashDiscount1Days := DaysBetween(Trunc(_Invoice.InvoiceIssueDate),Trunc(TXRechnungHelper.DateFromStrUNCEFACTFormat(node3.text))+_Invoice.PaymentTermCashDiscount1Days);
879+ end
857880 else
858881 if TXRechnungXMLHelper.FindNode(nodes[i],' .//ram:DueDateDateTime' ) then
859882 begin
@@ -875,7 +898,13 @@ class function TXRechnungInvoiceAdapter301.LoadDocumentUNCEFACT(_Invoice: TInvoi
875898 _Invoice.PaymentTermCashDiscount2Percent := 0 ;
876899 _Invoice.PaymentTermCashDiscount2Base := 0 ;
877900 if TXRechnungXMLHelper.SelectNode(nodes[i],' .//ram:ApplicableTradePaymentDiscountTerms/ram:BasisPeriodMeasure' ,node3) then
878- _Invoice.PaymentTermCashDiscount2Days := StrToIntDef(node3.text,0 )
901+ begin
902+ _Invoice.PaymentTermCashDiscount2Days := StrToIntDef(node3.text,0 );
903+ // Sonderfall beim Einlesen von ZUGFeRD, wird intern von TInvoice nicht unterstuetzt
904+ // Das Basisdatum + Skontotage wird auf das Rechnungsdatum + Skontotage umgerechnet
905+ if TXRechnungXMLHelper.SelectNode(nodes[i],' .//ram:ApplicableTradePaymentDiscountTerms/ram:BasisDateTime/udt:DateTimeString' ,node3) then
906+ _Invoice.PaymentTermCashDiscount2Days := DaysBetween(Trunc(_Invoice.InvoiceIssueDate),Trunc(TXRechnungHelper.DateFromStrUNCEFACTFormat(node3.text))+_Invoice.PaymentTermCashDiscount2Days);
907+ end
879908 else
880909 if TXRechnungXMLHelper.FindNode(nodes[i],' .//ram:DueDateDateTime' ) then
881910 begin
@@ -1156,18 +1185,29 @@ class procedure TXRechnungInvoiceAdapter301.SaveDocumentUBL(_Invoice: TInvoice;
11561185 end ;
11571186 if _Invoice.DeliveryReceiptNumber <> ' ' then
11581187 xRoot.AddChild(' cac:DespatchDocumentReference' ).AddChild(' cbc:ID' ).Text := _Invoice.DeliveryReceiptNumber;
1188+ if _Invoice.ReceiptDocumentReference <> ' ' then
1189+ xRoot.AddChild(' cac:ReceiptDocumentReference' ).AddChild(' cbc:ID' ).Text := _Invoice.ReceiptDocumentReference;
1190+
1191+ for i := 0 to _Invoice.Attachments.Count -1 do
1192+ if (_Invoice.Attachments[i].TypeCode = iatc_50) then // BT-17
1193+ if (_Invoice.Attachments[i].ID <> ' ' ) then
1194+ xRoot.AddChild(' cac:OriginatorDocumentReference' ).AddChild(' cbc:ID' ).Text := _Invoice.Attachments[i].ID;
1195+
11591196 if _Invoice.ContractDocumentReference <> ' ' then
11601197 xRoot.AddChild(' cac:ContractDocumentReference' ).AddChild(' cbc:ID' ).Text := _Invoice.ContractDocumentReference;
11611198
11621199 for i := 0 to _Invoice.Attachments.Count -1 do
1200+ if (_Invoice.Attachments[i].TypeCode <> iatc_50) then // BT-17 extra
11631201 begin
11641202 with xRoot.AddChild(' cac:AdditionalDocumentReference' ) do
11651203 begin
11661204 AddChild(' cbc:ID' ).Text := _Invoice.Attachments[i].ID;
1167- if _Invoice.Attachments[i].TypeCode = iatc_130 then
1205+ if ( _Invoice.Attachments[i].TypeCode in [ iatc_130{ ,iatc_916 } ]) then // 916 gibt derzeit Fehler bei UBL, ggf. spaeter wieder aktivieren
11681206 AddChild(' cbc:DocumentTypeCode' ).Text := TXRechnungHelper.InvoiceAttachmentTypeCodeToStr(_Invoice.Attachments[i].TypeCode);
11691207 if _Invoice.Attachments[i].DocumentDescription <> ' ' then
11701208 AddChild(' cbc:DocumentDescription' ).Text := _Invoice.Attachments[i].DocumentDescription;
1209+ if (_Invoice.Attachments[i].ContainsBinaryObject) or
1210+ (_Invoice.Attachments[i].ExternalReference <> ' ' ) then
11711211 with AddChild(' cac:Attachment' ) do
11721212 begin
11731213 if _Invoice.Attachments[i].ContainsBinaryObject then
@@ -1206,6 +1246,7 @@ class procedure TXRechnungInvoiceAdapter301.SaveDocumentUBL(_Invoice: TInvoice;
12061246 Attributes[' schemeID' ] := ' SEPA' ;
12071247 Text := _Invoice.AccountingSupplierParty.BankAssignedCreditorIdentifier;
12081248 end ;
1249+ if _Invoice.AccountingSupplierParty.Name <> ' ' then
12091250 with AddChild(' cac:PartyName' ) do
12101251 begin
12111252 AddChild(' cbc:Name' ).Text := _Invoice.AccountingSupplierParty.Name ;
@@ -1266,6 +1307,7 @@ class procedure TXRechnungInvoiceAdapter301.SaveDocumentUBL(_Invoice: TInvoice;
12661307 Attributes[' schemeID' ] := ' 0088' ;
12671308 Text := _Invoice.AccountingCustomerParty.IdentifierSellerBuyer;
12681309 end ;
1310+ if _Invoice.AccountingCustomerParty.Name <> ' ' then
12691311 with AddChild(' cac:PartyName' ) do
12701312 begin
12711313 AddChild(' cbc:Name' ).Text := _Invoice.AccountingCustomerParty.Name ;
@@ -1969,6 +2011,12 @@ class procedure TXRechnungInvoiceAdapter301.SaveDocumentUNCEFACT(
19692011 begin
19702012 Text := _Invoice.DeliveryReceiptNumber;
19712013 end ;
2014+ if (_Invoice.ReceiptDocumentReference <> ' ' ) then
2015+ with AddChild(' ram:ReceivingAdviceReferencedDocument' )
2016+ .AddChild(' ram:IssuerAssignedID' ) do
2017+ begin
2018+ Text := _Invoice.ReceiptDocumentReference;
2019+ end ;
19722020 end ;
19732021 with AddChild(' ram:ApplicableHeaderTradeSettlement' ) do
19742022 begin
0 commit comments