-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
intf.ZUGFeRDInvoiceDescriptor1Reader.pas
483 lines (421 loc) · 28.4 KB
/
intf.ZUGFeRDInvoiceDescriptor1Reader.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
{* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.}
unit intf.ZUGFeRDInvoiceDescriptor1Reader;
interface
uses
System.SysUtils, System.Classes, System.DateUtils
,Xml.XMLDoc, Xml.XMLIntf
,Xml.Win.msxmldom, Winapi.MSXMLIntf, Winapi.msxml
,intf.ZUGFeRDXmlHelper
,intf.ZUGFeRDInvoiceDescriptorReader
,intf.ZUGFeRDInvoiceDescriptor
,intf.ZUGFeRDExceptions
,intf.ZUGFeRDTradeLineItem,intf.ZUGFeRDParty
,intf.ZUGFeRDProfile,intf.ZUGFeRDInvoiceTypes
,intf.ZUGFeRDSubjectCodes
,intf.ZUGFeRDGlobalID,intf.ZUGFeRDGlobalIDSchemeIdentifiers
,intf.ZUGFeRDCountryCodes
,intf.ZUGFeRDTaxRegistrationSchemeID
,intf.ZUGFeRDContact
,intf.ZUGFeRDDeliveryNoteReferencedDocument
,intf.ZUGFeRDCurrencyCodes
,intf.ZUGFeRDPaymentMeans,intf.ZUGFeRDPaymentMeansTypeCodes
,intf.ZUGFeRDBankAccount
,intf.ZUGFeRDTaxTypes,intf.ZUGFeRDTaxCategoryCodes
,intf.ZUGFeRDTaxExemptionReasonCodes
,intf.ZUGFeRDPaymentTerms
,intf.ZUGFeRDQuantityCodes
,intf.ZUGFeRDAssociatedDocument
,intf.ZUGFeRDNote
,intf.ZUGFeRDContentCodes
,intf.ZUGFeRDBuyerOrderReferencedDocument
,intf.ZUGFeRDReferenceTypeCodes
,intf.ZUGFeRDContractReferencedDocument
,intf.ZUGFeRDSpecialServiceDescriptionCodes
,intf.ZUGFeRDAllowanceOrChargeIdentificationCodes
;
type
TZUGFeRDInvoiceDescriptor1Reader = class(TZUGFeRDInvoiceDescriptorReader)
private
function GetValidURIs : TArray<string>;
function _parseTradeLineItem(tradeLineItem : IXmlDomNode) : TZUGFeRDTradeLineItem;
function _nodeAsParty(basenode: IXmlDomNode; const xpath: string) : TZUGFeRDParty;
public
function IsReadableByThisReaderVersion(stream: TStream): Boolean; override;
function IsReadableByThisReaderVersion(xmldocument: IXMLDocument): Boolean; override;
/// <summary>
/// Parses the ZUGFeRD invoice from the given stream.
///
/// Make sure that the stream is open, otherwise an IllegalStreamException exception is thrown.
/// Important: the stream will not be closed by this function.
/// </summary>
/// <param name="stream"></param>
/// <returns>The parsed ZUGFeRD invoice</returns>
function Load(stream: TStream): TZUGFeRDInvoiceDescriptor; override;
function Load(xmldocument : IXMLDocument): TZUGFeRDInvoiceDescriptor; override;
end;
implementation
{ TZUGFeRDInvoiceDescriptor1Reader }
function TZUGFeRDInvoiceDescriptor1Reader.GetValidURIs : TArray<string>;
begin
Result := TArray<string>.Create(
'urn:ferd:invoice:1.0:basic',
'urn:ferd:invoice:1.0:comfort',
'urn:ferd:invoice:1.0:extended',
'urn:ferd:CrossIndustryDocument:invoice:1p0:basic',
'urn:ferd:CrossIndustryDocument:invoice:1p0:comfort',
'urn:ferd:CrossIndustryDocument:invoice:1p0:extended'
);
end;
function TZUGFeRDInvoiceDescriptor1Reader.IsReadableByThisReaderVersion(
stream: TStream): Boolean;
begin
Result := IsReadableByThisReaderVersion(stream, GetValidURIs);
end;
function TZUGFeRDInvoiceDescriptor1Reader.IsReadableByThisReaderVersion(
xmldocument: IXMLDocument): Boolean;
begin
Result := IsReadableByThisReaderVersion(xmldocument, GetValidURIs);
end;
function TZUGFeRDInvoiceDescriptor1Reader.Load(Stream: TStream): TZUGFeRDInvoiceDescriptor;
var
xml : IXMLDocument;
begin
if Stream = nil then
raise TZUGFeRDIllegalStreamException.Create('Cannot read from stream');
xml := NewXMLDocument;
try
xml.LoadFromStream(stream,TXMLEncodingType.xetUTF_8);
xml.Active := True;
Result := Load(xml);
finally
xml := nil;
end;
end;
function TZUGFeRDInvoiceDescriptor1Reader.Load(xmldocument : IXMLDocument): TZUGFeRDInvoiceDescriptor;
var
doc : IXMLDOMDocument2;
nodes : IXMLDOMNodeList;
i : Integer;
begin
doc := TZUGFeRDXmlHelper.PrepareDocumentForXPathQuerys(xmldocument);
//XmlNamespaceManager nsmgr = _GenerateNamespaceManagerFromNode(doc.DocumentElement);
Result := TZUGFeRDInvoiceDescriptor.Create;
Result.IsTest := _nodeAsBool(doc.documentElement,'//*[local-name()="SpecifiedExchangedDocumentContext"]/ram:TestIndicator');
Result.BusinessProcess := _nodeAsString(doc.DocumentElement, '//*[local-name()="BusinessProcessSpecifiedDocumentContextParameter"]/ram:ID');//, nsmgr),
Result.Profile := TZUGFeRDProfileExtensions.FromString(_nodeAsString(doc.DocumentElement, '//ram:GuidelineSpecifiedDocumentContextParameter/ram:ID'));//, nsmgr)),
Result.Name := _nodeAsString(doc.DocumentElement, '//*[local-name()="HeaderExchangedDocument"]/ram:Name');//, nsmgr)),
Result.Type_ := TZUGFeRDInvoiceTypeExtensions.FromString(_nodeAsString(doc.DocumentElement, '//*[local-name()="HeaderExchangedDocument"]/ram:TypeCode'));//, nsmgr)),
Result.InvoiceNo := _nodeAsString(doc.DocumentElement, '//*[local-name()="HeaderExchangedDocument"]/ram:ID');//, nsmgr),
Result.InvoiceDate := _nodeAsDateTime(doc.DocumentElement, '//*[local-name()="HeaderExchangedDocument"]/ram:IssueDateTime/udt:DateTimeString');//", nsmgr)
nodes := doc.selectNodes('//*[local-name()="HeaderExchangedDocument"]/ram:IncludedNote');
for i := 0 to nodes.length-1 do
begin
var content : String := _nodeAsString(nodes[i], './/ram:Content');
var _subjectCode : String := _nodeAsString(nodes[i], './/ram:SubjectCode');
var subjectCode : TZUGFeRDSubjectCodes := TZUGFeRDSubjectCodesExtensions.FromString(_subjectCode);
var contentCode : TZUGFeRDContentCodes := TZUGFeRDContentCodesExtensions.FromString(_nodeAsString(nodes[i], './/ram:ContentCode'));
Result.AddNote(content, subjectCode, contentCode);
end;
Result.ReferenceOrderNo := _nodeAsString(doc, '//ram:ApplicableSupplyChainTradeAgreement/ram:BuyerReference');
Result.Seller := _nodeAsParty(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeAgreement/ram:SellerTradeParty');
nodes := doc.selectNodes('//ram:ApplicableSupplyChainTradeAgreement/ram:SellerTradeParty/ram:SpecifiedTaxRegistration');
for i := 0 to nodes.length-1 do
begin
var id : String := _nodeAsString(nodes[i], './/ram:ID');
var schemeID : String := _nodeAsString(nodes[i], './/ram:ID/@schemeID');
Result.AddSellerTaxRegistration(id, TZUGFeRDTaxRegistrationSchemeIDExtensions.FromString(schemeID));
end;
if (doc.selectSingleNode('//ram:SellerTradeParty/ram:DefinedTradeContact') <> nil) then
begin
Result.SellerContact := TZUGFeRDContact.Create;
Result.SellerContact.Name := _nodeAsString(doc.DocumentElement, '//ram:SellerTradeParty/ram:DefinedTradeContact/ram:PersonName');
Result.SellerContact.OrgUnit := _nodeAsString(doc.DocumentElement, '//ram:SellerTradeParty/ram:DefinedTradeContact/ram:DepartmentName');
Result.SellerContact.PhoneNo := _nodeAsString(doc.DocumentElement, '//ram:SellerTradeParty/ram:DefinedTradeContact/ram:TelephoneUniversalCommunication/ram:CompleteNumber');
Result.SellerContact.FaxNo := _nodeAsString(doc.DocumentElement, '//ram:SellerTradeParty/ram:DefinedTradeContact/ram:FaxUniversalCommunication/ram:CompleteNumber');
Result.SellerContact.EmailAddress := _nodeAsString(doc.DocumentElement, '//ram:SellerTradeParty/ram:DefinedTradeContact/ram:EmailURIUniversalCommunication/ram:URIID');
end;
Result.Buyer := _nodeAsParty(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeAgreement/ram:BuyerTradeParty');
nodes := doc.selectNodes('//ram:ApplicableSupplyChainTradeAgreement/ram:BuyerTradeParty/ram:SpecifiedTaxRegistration');
for i := 0 to nodes.length-1 do
begin
var id : String := _nodeAsString(nodes[i], './/ram:ID');
var schemeID : String := _nodeAsString(nodes[i], './/ram:ID/@schemeID');
Result.AddBuyerTaxRegistration(id, TZUGFeRDTaxRegistrationSchemeIDExtensions.FromString(schemeID));
end;
if (doc.SelectSingleNode('//ram:BuyerTradeParty/ram:DefinedTradeContact') <> nil) then
begin
Result.BuyerContact := TZUGFeRDContact.Create;
Result.SetBuyerContact(
_nodeAsString(doc.DocumentElement, '//ram:BuyerTradeParty/ram:DefinedTradeContact/ram:PersonName'),
_nodeAsString(doc.DocumentElement, '//ram:BuyerTradeParty/ram:DefinedTradeContact/ram:DepartmentName'),
_nodeAsString(doc.DocumentElement, '//ram:BuyerTradeParty/ram:DefinedTradeContact/ram:EmailURIUniversalCommunication/ram:URIID'),
_nodeAsString(doc.DocumentElement, '//ram:BuyerTradeParty/ram:DefinedTradeContact/ram:TelephoneUniversalCommunication/ram:CompleteNumber'),
_nodeAsString(doc.DocumentElement, '//ram:BuyerTradeParty/ram:DefinedTradeContact/ram:FaxUniversalCommunication/ram:CompleteNumber')
);
end;
Result.ShipTo := _nodeAsParty(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeDelivery/ram:ShipToTradeParty');
Result.ShipFrom := _nodeAsParty(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeDelivery/ram:ShipFromTradeParty');
Result.ActualDeliveryDate:=_nodeAsDateTime(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeDelivery/ram:ActualDeliverySupplyChainEvent/ram:OccurrenceDateTime/udt:DateTimeString');
var _deliveryNoteNo : String := _nodeAsString(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeDelivery/ram:DeliveryNoteReferencedDocument/ram:ID');
var _deliveryNoteDate : TDateTime := _nodeAsDateTime(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeDelivery/ram:DeliveryNoteReferencedDocument/ram:IssueDateTime/udt:DateTimeString');
if (_deliveryNoteDate < 100) then
begin
_deliveryNoteDate := _nodeAsDateTime(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeDelivery/ram:DeliveryNoteReferencedDocument/ram:IssueDateTime');
end;
if ((_deliveryNoteDate > 100) or (_deliveryNoteNo <> '')) then
begin
Result.DeliveryNoteReferencedDocument := TZUGFeRDDeliveryNoteReferencedDocument.Create;
Result.SetDeliveryNoteReferenceDocument(_deliveryNoteNo,_deliveryNoteDate);
end;
Result.Invoicee := _nodeAsParty(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeSettlement/ram:InvoiceeTradeParty');
Result.Payee := _nodeAsParty(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeSettlement/ram:PayeeTradeParty');
Result.PaymentReference := _nodeAsString(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeSettlement/ram:PaymentReference');
Result.Currency := TZUGFeRDCurrencyCodesExtensions.FromString(_nodeAsString(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeSettlement/ram:InvoiceCurrencyCode'));
// TODO: Multiple SpecifiedTradeSettlementPaymentMeans can exist for each account/institution (with different SEPA?)
var _tempPaymentMeans : TZUGFeRDPaymentMeans := TZUGFeRDPaymentMeans.Create;
_tempPaymentMeans.TypeCode := TZUGFeRDPaymentMeansTypeCodesExtensions.FromString(_nodeAsString(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:TypeCode'));
_tempPaymentMeans.Information := _nodeAsString(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:Information');
_tempPaymentMeans.SEPACreditorIdentifier := _nodeAsString(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:ID');
Result.PaymentMeans := _tempPaymentMeans;
//TODO udt:DateTimeString
Result.BillingPeriodStart := _nodeAsDateTime(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeSettlement/ram:BillingSpecifiedPeriod/ram:StartDateTime');
Result.BillingPeriodEnd := _nodeAsDateTime(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeSettlement/ram:BillingSpecifiedPeriod/ram:EndDateTime');
//Result.BillingPeriodStart := _nodeAsDateTime(doc.DocumentElement, "//ram:ApplicableHeaderTradeSettlement/ram:BillingSpecifiedPeriod/ram:StartDateTime');
//Result.BillingPeriodEnd := _nodeAsDateTime(doc.DocumentElement, "//ram:ApplicableHeaderTradeSettlement/ram:BillingSpecifiedPeriod/ram:EndDateTime');
var creditorFinancialAccountNodes : IXMLDOMNodeList := doc.SelectNodes('//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:PayeePartyCreditorFinancialAccount');
var creditorFinancialInstitutions : IXMLDOMNodeList := doc.SelectNodes('//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:PayeeSpecifiedCreditorFinancialInstitution');
if (creditorFinancialAccountNodes.length = creditorFinancialInstitutions.length) then
for i := 0 to creditorFinancialAccountNodes.length-1 do
begin
var _account : TZUGFeRDBankAccount := TZUGFeRDBankAccount.Create;
_account.ID := _nodeAsString(creditorFinancialAccountNodes[i], './/ram:ProprietaryID');
_account.IBAN := _nodeAsString(creditorFinancialAccountNodes[i], './/ram:IBANID');
_account.BIC := _nodeAsString(creditorFinancialInstitutions[i], './/ram:BICID');
_account.Bankleitzahl := _nodeAsString(creditorFinancialInstitutions[i], './/ram:GermanBankleitzahlID');
_account.BankName := _nodeAsString(creditorFinancialInstitutions[i], './/ram:Name');
_account.Name := _nodeAsString(creditorFinancialInstitutions[i], './/ram:AccountName');
Result.CreditorBankAccounts.Add(_account);
end;
var debitorFinancialAccountNodes : IXMLDOMNodeList := doc.SelectNodes('//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:PayerPartyDebtorFinancialAccount');
var debitorFinancialInstitutions : IXMLDOMNodeList := doc.SelectNodes('//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:PayerSpecifiedDebtorFinancialInstitution');
//TODO Index prüfen in der Schleife, bei csharp stand 0 drin
if (debitorFinancialAccountNodes.length = debitorFinancialInstitutions.length) then
begin
for i := 0 to debitorFinancialAccountNodes.length-1 do
begin
var _account : TZUGFeRDBankAccount := TZUGFeRDBankAccount.Create;
_account.ID := _nodeAsString(debitorFinancialAccountNodes[i], './/ram:ProprietaryID');
_account.IBAN := _nodeAsString(debitorFinancialAccountNodes[i], './/ram:IBANID');
_account.BIC := _nodeAsString(debitorFinancialInstitutions[i], './/ram:BICID');
_account.Bankleitzahl := _nodeAsString(debitorFinancialInstitutions[i], './/ram:GermanBankleitzahlID');
_account.BankName := _nodeAsString(debitorFinancialInstitutions[i], './/ram:Name');
Result.DebitorBankAccounts.Add(_account);
end;
end;
nodes := doc.SelectNodes('//ram:ApplicableSupplyChainTradeSettlement/ram:ApplicableTradeTax');
for i := 0 to nodes.length-1 do
begin
Result.AddApplicableTradeTax(_nodeAsDecimal(nodes[i], './/ram:BasisAmount', 0),
_nodeAsDecimal(nodes[i], './/ram:ApplicablePercent', 0),
TZUGFeRDTaxTypesExtensions.FromString(_nodeAsString(nodes[i], './/ram:TypeCode')),
TZUGFeRDTaxCategoryCodesExtensions.FromString(_nodeAsString(nodes[i], './/ram:CategoryCode')));
end;
nodes := doc.SelectNodes('//ram:SpecifiedTradeAllowanceCharge');
for i := 0 to nodes.length-1 do
begin
Result.AddTradeAllowanceCharge(not _nodeAsBool(nodes[i], './/ram:ChargeIndicator'), // wichtig: das not (!) beachten
_nodeAsDecimal(nodes[i], './/ram:BasisAmount', 0),
Result.Currency,
_nodeAsDecimal(nodes[i], './/ram:ActualAmount', 0),
_nodeAsString(nodes[i], './/ram:Reason'),
TZUGFeRDSpecialServiceDescriptionCodesExtensions.FromString(_nodeAsString(nodes[i], './ram:ReasonCode')),
TZUGFeRDAllowanceOrChargeIdentificationCodesExtensions.FromString(_nodeAsString(nodes[i], './ram:ReasonCode')),
TZUGFeRDTaxTypesExtensions.FromString(_nodeAsString(nodes[i], './/ram:CategoryTradeTax/ram:TypeCode')),
TZUGFeRDTaxCategoryCodesExtensions.FromString(_nodeAsString(nodes[i], './/ram:CategoryTradeTax/ram:CategoryCode')),
_nodeAsDecimal(nodes[i], './/ram:CategoryTradeTax/ram:ApplicablePercent', 0));
end;
nodes := doc.SelectNodes('//ram:SpecifiedLogisticsServiceCharge');
for i := 0 to nodes.length-1 do
begin
Result.AddLogisticsServiceCharge(_nodeAsDecimal(nodes[i], './/ram:AppliedAmount', 0),
_nodeAsString(nodes[i], './/ram:Description'),
TZUGFeRDTaxTypesExtensions.FromString(_nodeAsString(nodes[i], './/ram:AppliedTradeTax/ram:TypeCode')),
TZUGFeRDTaxCategoryCodesExtensions.FromString(_nodeAsString(nodes[i], './/ram:AppliedTradeTax/ram:CategoryCode')),
_nodeAsDecimal(nodes[i], './/ram:AppliedTradeTax/ram:ApplicablePercent', 0));
end;
nodes := doc.SelectNodes('//ram:SpecifiedTradePaymentTerms');
for i := 0 to nodes.length-1 do
begin
var paymentTerm : TZUGFeRDPaymentTerms := TZUGFeRDPaymentTerms.Create;
paymentTerm.Description := _nodeAsString(nodes[i], './/ram:Description');
paymentTerm.DueDate:= _nodeAsDateTime(nodes[i], './/ram:DueDateDateTime');
paymentTerm.DirectDebitMandateID := _nodeAsString(nodes[i], './/ram:DirectDebitMandateID');
//TODO paymentTerm.PartialPaymentAmount
//TODO paymentTerm.ApplicableTradePaymentPenaltyTerms
paymentTerm.ApplicableTradePaymentDiscountTerms.BasisAmount := _nodeAsDecimal(nodes[i], './/ram:ApplicableTradePaymentDiscountTerms/ram:BasisAmount');
paymentTerm.ApplicableTradePaymentDiscountTerms.CalculationPercent := _nodeAsDouble(nodes[i], './/ram:ApplicableTradePaymentDiscountTerms/ram:CalculationPercent');
Result.PaymentTermsList.Add(paymentTerm);
end;
Result.LineTotalAmount:= _nodeAsDecimal(doc.DocumentElement, '//ram:SpecifiedTradeSettlementMonetarySummation/ram:LineTotalAmount', 0);
Result.ChargeTotalAmount:= _nodeAsDecimal(doc.DocumentElement, '//ram:SpecifiedTradeSettlementMonetarySummation/ram:ChargeTotalAmount', 0);
Result.AllowanceTotalAmount:= _nodeAsDecimal(doc.DocumentElement, '//ram:SpecifiedTradeSettlementMonetarySummation/ram:AllowanceTotalAmount', 0);
Result.TaxBasisAmount:= _nodeAsDecimal(doc.DocumentElement, '//ram:SpecifiedTradeSettlementMonetarySummation/ram:TaxBasisTotalAmount',0);
Result.TaxTotalAmount:= _nodeAsDecimal(doc.DocumentElement, '//ram:SpecifiedTradeSettlementMonetarySummation/ram:TaxTotalAmount', 0);
Result.GrandTotalAmount:= _nodeAsDecimal(doc.DocumentElement, '//ram:SpecifiedTradeSettlementMonetarySummation/ram:GrandTotalAmount', 0);
Result.RoundingAmount:= _nodeAsDecimal(doc.DocumentElement, '//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:RoundingAmount', 0);
Result.TotalPrepaidAmount:= _nodeAsDecimal(doc.DocumentElement, '//ram:SpecifiedTradeSettlementMonetarySummation/ram:TotalPrepaidAmount', 0);
Result.DuePayableAmount:= _nodeAsDecimal(doc.DocumentElement, '//ram:SpecifiedTradeSettlementMonetarySummation/ram:DuePayableAmount', 0);
if (doc.DocumentElement.SelectSingleNode('//ram:ApplicableSupplyChainTradeAgreement/ram:BuyerOrderReferencedDocument/ram:IssueDateTime/udt:DateTimeString') <> nil) then
Result.OrderDate:= _nodeAsDateTime(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeAgreement/ram:BuyerOrderReferencedDocument/ram:IssueDateTime/udt:DateTimeString')
else
Result.OrderDate:= _nodeAsDateTime(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeAgreement/ram:BuyerOrderReferencedDocument/ram:IssueDateTime');
Result.OrderNo := _nodeAsString(doc.DocumentElement, '//ram:ApplicableSupplyChainTradeAgreement/ram:BuyerOrderReferencedDocument/ram:ID');
nodes := doc.SelectNodes('//ram:IncludedSupplyChainTradeLineItem');
for i := 0 to nodes.length-1 do
Result.TradeLineItems.Add(_parseTradeLineItem(nodes[i]));
end;
function TZUGFeRDInvoiceDescriptor1Reader._nodeAsParty(basenode: IXmlDomNode;
const xpath: string) : TZUGFeRDParty;
var
node : IXmlDomNode;
lineOne,lineTwo : String;
begin
Result := nil;
if (baseNode = nil) then
exit;
node := baseNode.SelectSingleNode(xpath);
if (node = nil) then
exit;
Result := TZUGFeRDParty.Create;
Result.ID.ID := _nodeAsString(node, 'ram:ID');
Result.ID.SchemeID := TZUGFeRDGlobalIDSchemeIdentifiers.Unknown;
Result.GlobalID.ID := _nodeAsString(node, 'ram:GlobalID');
Result.GlobalID.SchemeID := TZUGFeRDGlobalIDSchemeIdentifiersExtensions.FromString(_nodeAsString(node, 'ram:GlobalID/@schemeID'));
Result.Name := _nodeAsString(node, 'ram:Name');
Result.Description := _nodeAsString(node, 'ram:Description'); // Seller only BT-33
Result.Postcode := _nodeAsString(node, 'ram:PostalTradeAddress/ram:PostcodeCode');
Result.City := _nodeAsString(node, 'ram:PostalTradeAddress/ram:CityName');
Result.Country := TZUGFeRDCountryCodesExtensions.FromString(_nodeAsString(node, 'ram:PostalTradeAddress/ram:CountryID'));
if (not lineTwo.IsEmpty) then
begin
Result.ContactName := lineOne;
Result.Street := lineTwo;
end else
begin
Result.Street := lineOne;
Result.ContactName := '';
end;
end;
function TZUGFeRDInvoiceDescriptor1Reader._parseTradeLineItem(
tradeLineItem: IXmlDomNode): TZUGFeRDTradeLineItem;
var
nodes : IXMLDOMNodeList;
i : Integer;
begin
Result := nil;
if (tradeLineItem = nil) then
exit;
//var s : String := _nodeAsString(tradeLineItem, './/ram:ApplicableTradeTax/ram:TypeCode');
//var t : TZUGFeRDTaxTypes := TZUGFeRDTaxTypesExtensions.FromString(_nodeAsString(tradeLineItem, './/ram:ApplicableTradeTax/ram:TypeCode'));
Result := TZUGFeRDTradeLineItem.Create;
Result.GlobalID.ID := _nodeAsString(tradeLineItem, './/ram:SpecifiedTradeProduct/ram:GlobalID');
Result.GlobalID.SchemeID := TZUGFeRDGlobalIDSchemeIdentifiersExtensions.FromString(_nodeAsString(tradeLineItem, './/ram:SpecifiedTradeProduct/ram:GlobalID/@schemeID'));
Result.SellerAssignedID := _nodeAsString(tradeLineItem, './/ram:SpecifiedTradeProduct/ram:SellerAssignedID');
Result.BuyerAssignedID := _nodeAsString(tradeLineItem, './/ram:SpecifiedTradeProduct/ram:BuyerAssignedID');
Result.Name := _nodeAsString(tradeLineItem, './/ram:SpecifiedTradeProduct/ram:Name');
Result.Description := _nodeAsString(tradeLineItem, './/ram:SpecifiedTradeProduct/ram:Description');
Result.UnitQuantity:=_nodeAsDecimal(tradeLineItem, './/ram:BasisQuantity', 0);
Result.BilledQuantity := _nodeAsDecimal(tradeLineItem, './/ram:BilledQuantity', 0);
Result.PackageQuantity := _nodeAsDecimal(tradeLineItem, './/ram:PackageQuantity', 0);
Result.ChargeFreeQuantity := _nodeAsDecimal(tradeLineItem, './/ram:ChargeFreeQuantity', 0);
// Result.LineTotalAmount.SetValue(_nodeAsDecimal(tradeLineItem, './/ram:LineTotalAmount', 0));
Result.LineTotalAmount:= _nodeAsDecimal(tradeLineItem, './/ram:LineTotalAmount', 0);
Result.TaxCategoryCode := TZUGFeRDTaxCategoryCodesExtensions.FromString(_nodeAsString(tradeLineItem, './/ram:ApplicableTradeTax/ram:CategoryCode'));
Result.TaxType := TZUGFeRDTaxTypesExtensions.FromString(_nodeAsString(tradeLineItem, './/ram:ApplicableTradeTax/ram:TypeCode'));
Result.TaxPercent := _nodeAsDecimal(tradeLineItem, './/ram:ApplicableTradeTax/ram:ApplicablePercent', 0);
Result.NetUnitPrice:= _nodeAsDecimal(tradeLineItem, './/ram:NetPriceProductTradePrice/ram:ChargeAmount', 0);
Result.GrossUnitPrice:= _nodeAsDecimal(tradeLineItem, './/ram:GrossPriceProductTradePrice/ram:ChargeAmount', 0);
Result.UnitCode := TZUGFeRDQuantityCodesExtensions.FromString(_nodeAsString(tradeLineItem, './/ram:BasisQuantity/@unitCode'));
Result.PackageUnitCode := TZUGFeRDQuantityCodesExtensions.FromString(_nodeAsString(tradeLineItem, './/ram:PackageQuantity/@unitCode'));
Result.ChargeFreeUnitCode := TZUGFeRDQuantityCodesExtensions.FromString(_nodeAsString(tradeLineItem, './/ram:ChargeFreeQuantity/@unitCode'));
Result.BillingPeriodStart:= _nodeAsDateTime(tradeLineItem, './/ram:BillingSpecifiedPeriod/ram:StartDateTime/udt:DateTimeString');
Result.BillingPeriodEnd:= _nodeAsDateTime(tradeLineItem, './/ram:BillingSpecifiedPeriod/ram:EndDateTime/udt:DateTimeString');
if (tradeLineItem.SelectSingleNode('.//ram:AssociatedDocumentLineDocument') <> nil) then
begin
Result.AssociatedDocument := TZUGFeRDAssociatedDocument.Create(_nodeAsString(tradeLineItem, './/ram:AssociatedDocumentLineDocument/ram:LineID'));
nodes := tradeLineItem.SelectNodes('.//ram:AssociatedDocumentLineDocument/ram:IncludedNote');
for i := 0 to nodes.length-1 do
begin
var noteItem : TZUGFeRDNote := TZUGFeRDNote.Create(
_nodeAsString(nodes[i], './/ram:Content'),
TZUGFeRDSubjectCodesExtensions.FromString(_nodeAsString(nodes[i], './/ram:SubjectCode')),
TZUGFeRDContentCodesExtensions.FromString(_nodeAsString(nodes[i], './/ram:ContentCode'))
);
Result.AssociatedDocument.Notes.Add(noteItem);
end;
end;
nodes := tradeLineItem.SelectNodes('.//ram:SpecifiedSupplyChainTradeAgreement/ram:GrossPriceProductTradePrice/ram:AppliedTradeAllowanceCharge');
for i := 0 to nodes.length-1 do
begin
var chargeIndicator : Boolean := _nodeAsBool(nodes[i], './ram:ChargeIndicator/udt:Indicator');
var basisAmount : Currency := _nodeAsDecimal(nodes[i], './ram:BasisAmount',0);
var basisAmountCurrency : String := _nodeAsString(nodes[i], './ram:BasisAmount/@currencyID');
var actualAmount : Currency := _nodeAsDecimal(nodes[i], './ram:ActualAmount',0);
var actualAmountCurrency : String := _nodeAsString(nodes[i], './ram:ActualAmount/@currencyID');
var reason : String := _nodeAsString(nodes[i], './ram:Reason');
Result.AddTradeAllowanceCharge(not chargeIndicator, // wichtig: das not beachten
TZUGFeRDCurrencyCodesExtensions.FromString(basisAmountCurrency),
basisAmount,
actualAmount,
reason,
TZUGFeRDSpecialServiceDescriptionCodes.Unknown,
TZUGFeRDAllowanceOrChargeIdentificationCodes.Unknown);
end;
if (Result.UnitCode = TZUGFeRDQuantityCodes.Unknown) then
begin
// UnitCode alternativ aus BilledQuantity extrahieren
Result.UnitCode := TZUGFeRDQuantityCodesExtensions.FromString(_nodeAsString(tradeLineItem, './/ram:BilledQuantity/@unitCode'));
end;
if (tradeLineItem.SelectSingleNode('.//ram:SpecifiedSupplyChainTradeAgreement/ram:BuyerOrderReferencedDocument/ram:ID') <> nil) then
begin
Result.BuyerOrderReferencedDocument := TZUGFeRDBuyerOrderReferencedDocument.Create;
Result.BuyerOrderReferencedDocument.ID := _nodeAsString(tradeLineItem, './/ram:SpecifiedSupplyChainTradeAgreement/ram:BuyerOrderReferencedDocument/ram:ID');
Result.BuyerOrderReferencedDocument.IssueDateTime:= _nodeAsDateTime(tradeLineItem, './/ram:SpecifiedSupplyChainTradeAgreement/ram:BuyerOrderReferencedDocument/ram:IssueDateTime');
end;
if (tradeLineItem.SelectSingleNode('.//ram:SpecifiedSupplyChainTradeDelivery/ram:DeliveryNoteReferencedDocument/ram:ID') <> nil) then
begin
Result.DeliveryNoteReferencedDocument := TZUGFeRDDeliveryNoteReferencedDocument.Create;
Result.DeliveryNoteReferencedDocument.ID := _nodeAsString(tradeLineItem, './/ram:SpecifiedSupplyChainTradeDelivery/ram:DeliveryNoteReferencedDocument/ram:ID');
Result.DeliveryNoteReferencedDocument.IssueDateTime:= _nodeAsDateTime(tradeLineItem, './/ram:SpecifiedSupplyChainTradeDelivery/ram:DeliveryNoteReferencedDocument/ram:IssueDateTime');
end;
if (tradeLineItem.SelectSingleNode('.//ram:SpecifiedSupplyChainTradeDelivery/ram:ActualDeliverySupplyChainEvent/ram:OccurrenceDateTime') <> nil) then
begin
Result.ActualDeliveryDate:= _nodeAsDateTime(tradeLineItem, './/ram:SpecifiedSupplyChainTradeDelivery/ram:ActualDeliverySupplyChainEvent/ram:OccurrenceDateTime/udt:DateTimeString');
end;
//Get all referenced AND embedded documents
nodes := tradeLineItem.SelectNodes('.//ram:SpecifiedSupplyChainTradeAgreement/ram:AdditionalReferencedDocument');
for i := 0 to nodes.length-1 do
begin
Result.AddAdditionalReferencedDocument(
_nodeAsString(nodes[i], 'ram:ID'),
_nodeAsDateTime(nodes[i], 'ram:IssueDateTim'),
TZUGFeRDReferenceTypeCodesExtensions.FromString(_nodeAsString(nodes[i], 'ram:ReferenceTypeCode'))
);
end;
end;
end.