-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
intf.XRechnung.pas
1941 lines (1828 loc) · 88.3 KB
/
intf.XRechnung.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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
License XRechnung-for-Delphi
Copyright (C) 2024 Landrix Software GmbH & Co. KG
Sven Harazim, [email protected]
Version 3.0.2
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
}
unit intf.XRechnung;
interface
//setzt ZUGFeRD-for-Delphi voraus
//https://github.com/LandrixSoftware/ZUGFeRD-for-Delphi
{.$DEFINE ZUGFeRD_Support}
uses
System.SysUtils,System.Classes,System.Types
,System.StrUtils,System.DateUtils,System.Contnrs
,Xml.XMLDoc,Xml.XMLIntf
{$IFDEF ZUGFeRD_Support}
,intf.ZUGFeRDInvoiceDescriptor
,intf.ZUGFeRDCurrencyCodes
,intf.ZUGFeRDTaxRegistrationSchemeID
,intf.ZUGFeRDInvoiceTypes
,intf.ZUGFeRDCountryCodes
,intf.ZUGFeRDPaymentMeansTypeCodes
,intf.ZUGFeRDTaxCategoryCodes
,intf.ZUGFeRDSpecialServiceDescriptionCodes
,intf.ZUGFeRDAllowanceOrChargeIdentificationCodes
,intf.ZUGFeRDQuantityCodes
,intf.ZUGFeRDGlobalIDSchemeIdentifiers
{$ENDIF}
,intf.XRechnung_2_3
,intf.XRechnung_3_0
,intf.Invoice
;
type
TXRechnungHelper = class(TObject)
public
class function DateFromStrUBLFormat(const _Val : String) : TDateTime;
class function DateFromStrUNCEFACTFormat(const _Val : String) : TDateTime;
class function DateToStrUBLFormat(const _Val : TDateTime) : String;
class function DateToStrUNCEFACTFormat(const _Val : TDateTime) : String;
class function AmountToStr(_Val : Currency) : String;
class function AmountFromStr(_Val : String) : Currency;
class function UnitPriceAmountToStr(_Val : Currency) : String;
class function UnitPriceAmountFromStr(_Val : String) : Currency;
class function FloatToStr(_Val : double; _DecimalPlaces : Integer = 2) : String;
class function FloatFromStr(_Val : String) : double;
class function PercentageToStr(_Val : double) : String;
class function PercentageFromStr(_Val : String) : double;
class function QuantityToStr(_Val : double) : String;
class function QuantityFromStr(_Val : String) : double;
class function InvoiceTypeCodeToStr(_Val : TInvoiceTypeCode) : String;
class function InvoiceTypeCodeFromStr(const _Val : String) : TInvoiceTypeCode;
class function InvoicePaymentMeansCodeToStr(_Val : TInvoicePaymentMeansCode) : String;
class function InvoicePaymentMeansCodeFromStr(_Val : String) : TInvoicePaymentMeansCode;
class function InvoiceUnitCodeToStr(_Val : TInvoiceUnitCode) : String; //mehr Konvertierungen in Res\intf.XRechnung.unusedUnits.pas
class function InvoiceUnitCodeFromStr(_Val : String) : TInvoiceUnitCode; //mehr Konvertierungen in Res\intf.XRechnung.unusedUnits.pas
class function InvoiceAllowanceOrChargeIdentCodeToStr(_Val : TInvoiceAllowanceOrChargeIdentCode) : String;
class function InvoiceAllowanceOrChargeIdentCodeFromStr(_Val : String) : TInvoiceAllowanceOrChargeIdentCode;
class function InvoiceSpecialServiceDescriptionCodeToStr(_Val : TInvoiceSpecialServiceDescriptionCode) : String;
class function InvoiceSpecialServiceDescriptionCodeFromStr(_Val : String) : TInvoiceSpecialServiceDescriptionCode;
class function InvoiceDutyTaxFeeCategoryCodeToStr(_Val : TInvoiceDutyTaxFeeCategoryCode) : String;
class function InvoiceDutyTaxFeeCategoryCodeFromStr(_Val : String) : TInvoiceDutyTaxFeeCategoryCode;
class function InvoiceAttachmentTypeToStr(_Val : TInvoiceAttachmentType) : String;
class function InvoiceAttachmentTypeFromStr(_Val : String) : TInvoiceAttachmentType;
class function InvoiceNoteSubjectCodeToStr(_Val : TInvoiceNoteSubjectCode) : String;
class function InvoiceNoteSubjectCodeFromStr(_Val : String) : TInvoiceNoteSubjectCode;
class procedure ReadPaymentTerms(_Invoice: TInvoice; _PaymentTermsText: String);
end;
TXRechnungVersion = (XRechnungVersion_Unknown,
XRechnungVersion_230_UBL_Deprecated,
XRechnungVersion_230_UNCEFACT_Deprecated,
XRechnungVersion_30x_UBL,
XRechnungVersion_30x_UNCEFACT,
ZUGFeRDExtendedVersion_232,
XRechnungVersion_ReadingSupport_ZUGFeRDFacturX);
TXRechnungValidationHelper = class(TObject)
public
class function GetXRechnungVersion(const _Filename : String) : TXRechnungVersion; overload;
class function GetXRechnungVersion(_Xml : IXMLDocument) : TXRechnungVersion; overload;
class function GetXRechnungVersion(_Stream: TStream) : TXRechnungVersion; overload;
class function GetXRechnungVersionFromString(const _XML: String) : TXRechnungVersion;
//First thoughts on the topic
//class function Validate(_XSDFilename, _XmlFilename: String) : Boolean;
end;
{$IFDEF ZUGFeRD_Support}
TZUGFeRDAdditionalContent = class
public
ZUGFeRDInvoice : TZUGFeRDInvoiceDescriptor;
InvoiceeTradePartyFound : Boolean;
InvoiceeTradeParty : TInvoiceAccountingParty;
SpecifiedLogisticsServiceChargeFound : Boolean;
constructor Create;
destructor Destroy; override;
procedure Clear;
end;
{$ENDIF}
TXRechnungInvoiceAdapter = class
private
class procedure SaveDocument(_Invoice: TInvoice;_Version : TXRechnungVersion; _Xml : IXMLDocument);
class function LoadFromXMLDocument(_Invoice: TInvoice; _XmlDocument: IXMLDocument; out _Error : String {$IFDEF ZUGFeRD_Support};_AdditionalContent : TZUGFeRDAdditionalContent = nil{$ENDIF}) : Boolean;
public
class function ConsistencyCheck(_Invoice : TInvoice; _Version : TXRechnungVersion) : Boolean;
class procedure SaveToStream(_Invoice : TInvoice; _Version : TXRechnungVersion; _Stream : TStream);
class procedure SaveToFile(_Invoice : TInvoice; _Version : TXRechnungVersion; const _Filename : String);
class procedure SaveToXMLStr(_Invoice : TInvoice; _Version : TXRechnungVersion; out _XML : String);
class function LoadFromStream(_Invoice : TInvoice; _Stream : TStream; out _Error : String {$IFDEF ZUGFeRD_Support};_AdditionalContent : TZUGFeRDAdditionalContent = nil{$ENDIF}) : Boolean;
class function LoadFromFile(_Invoice : TInvoice; const _Filename : String; out _Error : String {$IFDEF ZUGFeRD_Support};_AdditionalContent : TZUGFeRDAdditionalContent = nil{$ENDIF}) : Boolean;
class function LoadFromXMLStr(_Invoice : TInvoice; const _XML : String; out _Error : String {$IFDEF ZUGFeRD_Support};_AdditionalContent : TZUGFeRDAdditionalContent = nil{$ENDIF}) : Boolean;
end;
implementation
uses intf.XRechnungHelper;
{$IFDEF ZUGFeRD_Support}
type
TZUGFeRDInvoiceAdapter = class
private
class function LoadFromInvoiceDescriptor(_Invoice: TInvoice; _InvoiceDescriptor: TZUGFeRDInvoiceDescriptor; out _Error : String) : Boolean;
class function LoadAdditionalContentFromXMLDocument(_AdditionalContent : TZUGFeRDAdditionalContent; _InvoiceDescriptor: TZUGFeRDInvoiceDescriptor) : Boolean;
public
class function LoadFromXMLDocument(_Invoice: TInvoice; _XmlDocument: IXMLDocument; out _Error : String; _AdditionalContent : TZUGFeRDAdditionalContent = nil) : Boolean;
class function LoadFromStream(_Invoice : TInvoice; _Stream : TStream; out _Error : String) : Boolean;
class function LoadFromFile(_Invoice : TInvoice; const _Filename : String; out _Error : String) : Boolean;
class function LoadFromXMLStr(_Invoice : TInvoice; const _XML : String; out _Error : String) : Boolean;
end;
{$ENDIF}
{ TXRechnungInvoiceAdapter }
class procedure TXRechnungInvoiceAdapter.SaveToStream(_Invoice: TInvoice;
_Version : TXRechnungVersion; _Stream: TStream);
var
xml : IXMLDocument;
begin
if _Invoice = nil then
exit;
if _Stream = nil then
exit;
xml := NewXMLDocument;
try
TXRechnungInvoiceAdapter.SaveDocument(_Invoice,_Version,xml);
xml.SaveToStream(_Stream);
finally
xml := nil;
end;
end;
class procedure TXRechnungInvoiceAdapter.SaveToXMLStr(_Invoice: TInvoice;
_Version : TXRechnungVersion; out _XML: String);
var
xml : IXMLDocument;
begin
xml := NewXMLDocument;
try
TXRechnungInvoiceAdapter.SaveDocument(_Invoice,_Version,xml);
xml.SaveToXML(_XML);
finally
xml := nil;
end;
end;
class procedure TXRechnungInvoiceAdapter.SaveToFile(_Invoice: TInvoice;
_Version : TXRechnungVersion;const _Filename: String);
var
xml : IXMLDocument;
begin
if _Invoice = nil then
exit;
if _Filename = '' then
exit;
if not System.SysUtils.DirectoryExists(ExtractFilePath(_Filename)) then
exit;
xml := NewXMLDocument;
try
TXRechnungInvoiceAdapter.SaveDocument(_Invoice,_Version,xml);
xml.SaveToFile(_Filename);
finally
xml := nil;
end;
end;
class function TXRechnungInvoiceAdapter.ConsistencyCheck(_Invoice: TInvoice;
_Version: TXRechnungVersion): Boolean;
var
lCount,i : Integer;
begin
Result := true;
//Mindestens eine Zahlungsanweisung notwendig
if (_Invoice.PaymentTypes.Count = 0) then
begin
Result := false;
exit;
end;
//In XRechnung nicht unterstuetzte Rechnungsarten
if (_Version in [TXRechnungVersion.XRechnungVersion_230_UBL_Deprecated,
TXRechnungVersion.XRechnungVersion_230_UNCEFACT_Deprecated,
TXRechnungVersion.XRechnungVersion_30x_UBL,
TXRechnungVersion.XRechnungVersion_30x_UNCEFACT]) then
if (_Invoice.InvoiceTypeCode in [itc_DebitnoteRelatedToFinancialAdjustments,
itc_SelfBilledCreditNote,
itc_DebitNote,
itc_PrepaymentInvoice,
itc_Cancellation
]) then
begin
Result := false;
exit;
end;
//Nur maximal eine Referenzrechnung in ZUGFeRD erlaubt
if (_Version in [TXRechnungVersion.XRechnungVersion_230_UNCEFACT_Deprecated,
TXRechnungVersion.XRechnungVersion_30x_UNCEFACT]) then
if _Invoice.PrecedingInvoiceReferences.Count > 1 then
begin
Result := false;
exit;
end;
//Nur eine Lastschrift pro Rechnung
lCount := 0;
for i := 0 to _Invoice.PaymentTypes.Count-1 do
if _Invoice.PaymentTypes[i].PaymentMeansCode = ipmc_SEPADirectDebit then
inc(lCount);
if lCount > 1 then
begin
Result := false;
exit;
end;
//Nur eine Kreditkarte pro Rechnung
lCount := 0;
for i := 0 to _Invoice.PaymentTypes.Count-1 do
if _Invoice.PaymentTypes[i].PaymentMeansCode = ipmc_CreditCard then
inc(lCount);
if lCount > 1 then
begin
Result := false;
exit;
end;
//Beide Steuernummern beim Kaeufer nicht vorgesehen
if (_Invoice.AccountingCustomerParty.VATCompanyID <> '') and
(_Invoice.AccountingCustomerParty.VATCompanyNumber <> '') then
begin
Result := false;
exit;
end;
end;
class function TXRechnungInvoiceAdapter.LoadFromFile(_Invoice: TInvoice;
const _Filename: String; out _Error : String
{$IFDEF ZUGFeRD_Support};_AdditionalContent : TZUGFeRDAdditionalContent = nil{$ENDIF}) : Boolean;
var
xml : IXMLDocument;
begin
Result := false;
if _Invoice = nil then
exit;
if _Filename = '' then
exit;
if not System.SysUtils.FileExists(_Filename) then
exit;
xml := TXMLDocument.Create(nil);
try
xml.LoadFromFile(_Filename);
Result := TXRechnungInvoiceAdapter.LoadFromXMLDocument(_Invoice,xml,_Error{$IFDEF ZUGFeRD_Support},_AdditionalContent{$ENDIF});
finally
xml := nil;
end;
end;
class function TXRechnungInvoiceAdapter.LoadFromStream(_Invoice: TInvoice;
_Stream: TStream; out _Error : String
{$IFDEF ZUGFeRD_Support};_AdditionalContent : TZUGFeRDAdditionalContent = nil{$ENDIF}) : Boolean;
var
xml : IXMLDocument;
begin
Result := false;
if _Invoice = nil then
exit;
if _Stream = nil then
exit;
xml := TXMLDocument.Create(nil);
try
xml.LoadFromStream(_Stream);
Result := TXRechnungInvoiceAdapter.LoadFromXMLDocument(_Invoice,xml,_Error{$IFDEF ZUGFeRD_Support},_AdditionalContent{$ENDIF});
finally
xml := nil;
end;
end;
class function TXRechnungInvoiceAdapter.LoadFromXMLDocument(
_Invoice: TInvoice; _XmlDocument: IXMLDocument;
out _Error: String
{$IFDEF ZUGFeRD_Support};_AdditionalContent : TZUGFeRDAdditionalContent = nil{$ENDIF}): Boolean;
begin
Result := false;
if _Invoice = nil then
exit;
if _XmlDocument = nil then
exit;
case TXRechnungValidationHelper.GetXRechnungVersion(_XmlDocument) of
XRechnungVersion_230_UBL_Deprecated : Result := TXRechnungInvoiceAdapter230.LoadDocumentUBL(_Invoice,_XmlDocument,_Error);
XRechnungVersion_30x_UBL : Result := TXRechnungInvoiceAdapter301.LoadDocumentUBL(_Invoice,_XmlDocument,_Error);
XRechnungVersion_230_UNCEFACT_Deprecated : Result := TXRechnungInvoiceAdapter230.LoadDocumentUNCEFACT(_Invoice,_XmlDocument,_Error);
XRechnungVersion_30x_UNCEFACT : Result := TXRechnungInvoiceAdapter301.LoadDocumentUNCEFACT(_Invoice,_XmlDocument,_Error);
{$IFNDEF ZUGFeRD_Support}
ZUGFeRDExtendedVersion_232,
XRechnungVersion_ReadingSupport_ZUGFeRDFacturX : Result := TXRechnungInvoiceAdapter301.LoadDocumentUNCEFACT(_Invoice,_XmlDocument,_Error);
else exit;
{$ELSE}
else
Result := TZUGFeRDInvoiceAdapter.LoadFromXMLDocument(_Invoice,_XmlDocument,_Error,_AdditionalContent);
{$ENDIF}
end;
end;
class function TXRechnungInvoiceAdapter.LoadFromXMLStr(_Invoice: TInvoice;
const _XML: String; out _Error : String
{$IFDEF ZUGFeRD_Support};_AdditionalContent : TZUGFeRDAdditionalContent = nil{$ENDIF}) : Boolean;
var
xml : IXMLDocument;
begin
Result := false;
if _Invoice = nil then
exit;
if _XML = '' then
exit;
xml := TXMLDocument.Create(nil);
try
xml.LoadFromXML(_XML);
Result := TXRechnungInvoiceAdapter.LoadFromXMLDocument(_Invoice,xml,_Error{$IFDEF ZUGFeRD_Support},_AdditionalContent{$ENDIF});
finally
xml := nil;
end;
end;
class procedure TXRechnungInvoiceAdapter.SaveDocument(_Invoice: TInvoice;
_Version : TXRechnungVersion; _Xml: IXMLDocument);
begin
case _Version of
XRechnungVersion_230_UBL_Deprecated : TXRechnungInvoiceAdapter230.SaveDocumentUBL(_Invoice,_Xml);
XRechnungVersion_30x_UBL : TXRechnungInvoiceAdapter301.SaveDocumentUBL(_Invoice,_Xml);
XRechnungVersion_230_UNCEFACT_Deprecated : TXRechnungInvoiceAdapter230.SaveDocumentUNCEFACT(_Invoice,_Xml);
XRechnungVersion_30x_UNCEFACT : TXRechnungInvoiceAdapter301.SaveDocumentUNCEFACT(_Invoice,_Xml,true);
ZUGFeRDExtendedVersion_232 : TXRechnungInvoiceAdapter301.SaveDocumentUNCEFACT(_Invoice,_Xml,false);
else raise Exception.Create('XRechnung - wrong version');
end;
end;
{ TXRechnungHelper }
class function TXRechnungHelper.AmountFromStr(_Val: String): Currency;
var
fs : TFormatSettings;
begin
fs.ThousandSeparator := ',';
fs.DecimalSeparator := '.';
Result := StrToCurrDef(_Val,0,fs);
end;
class function TXRechnungHelper.AmountToStr(
_Val: Currency): String;
begin
Result := System.StrUtils.ReplaceText(Format('%.2f',[_Val]),',','.');
end;
class function TXRechnungHelper.UnitPriceAmountFromStr(
_Val: String): Currency;
var
fs : TFormatSettings;
begin
Result := 0;
if _Val = '' then
exit;
fs.ThousandSeparator := ',';
fs.DecimalSeparator := '.';
Result := StrToCurrDef(_Val,0,fs);
end;
class function TXRechnungHelper.UnitPriceAmountToStr(
_Val: Currency): String;
begin
Result := System.StrUtils.ReplaceText(Format('%.2f',[_Val]),',','.');
end;
class function TXRechnungHelper.DateFromStrUBLFormat(const _Val : String) : TDateTime;
begin
Result := 0;
if Length(_Val) <> 10 then
exit;
Result := EncodeDate(StrToIntDef(Copy(_Val,1,4),1899),StrToIntDef(Copy(_Val,6,2),12),StrToIntDef(Copy(_Val,9,2),30));
end;
class function TXRechnungHelper.DateFromStrUNCEFACTFormat(const _Val : String) : TDateTime;
begin
Result := 0;
if Length(_Val) <> 8 then
exit;
Result := EncodeDate(StrToIntDef(Copy(_Val,1,4),1899),StrToIntDef(Copy(_Val,5,2),12),StrToIntDef(Copy(_Val,7,2),30));
end;
class function TXRechnungHelper.DateToStrUBLFormat(
const _Val: TDateTime): String;
begin
Result := FormatDateTime('yyyy-mm-dd',_Val);
end;
class function TXRechnungHelper.DateToStrUNCEFACTFormat(
const _Val: TDateTime): String;
begin
Result := FormatDateTime('yyyymmdd',_Val);
end;
class function TXRechnungHelper.FloatFromStr(_Val: String): double;
var
fs : TFormatSettings;
begin
fs.ThousandSeparator := ',';
fs.DecimalSeparator := '.';
Result := StrToFloatDef(_Val,0,fs);
end;
class function TXRechnungHelper.FloatToStr(
_Val: double; _DecimalPlaces : Integer = 2): String;
begin
if _DecimalPlaces < 0 then
_DecimalPlaces := 0;
Result := System.StrUtils.ReplaceText(Format('%.'+IntToStr(_DecimalPlaces)+'f',[_Val]),',','.');
end;
class function TXRechnungHelper.InvoiceAllowanceOrChargeIdentCodeFromStr(
_Val: String): TInvoiceAllowanceOrChargeIdentCode;
begin
if SameText(_Val,'41') then
Result := iacic_BonusForWorksAheadOfSchedule else
if SameText(_Val,'42') then
Result := iacic_OtherBonus else
if SameText(_Val,'60') then
Result := iacic_ManufacturersConsumerDiscount else
if SameText(_Val,'62') then
Result := iacic_DueToMilitaryStatus else
if SameText(_Val,'63') then
Result := iacic_DueToWorkAccident else
if SameText(_Val,'64') then
Result := iacic_SpecialAgreement else
if SameText(_Val,'65') then
Result := iacic_ProductionErrorDiscount else
if SameText(_Val,'66') then
Result := iacic_NewOutletDiscount else
if SameText(_Val,'67') then
Result := iacic_SampleDiscount else
if SameText(_Val,'68') then
Result := iacic_EndOfRangeDiscount else
if SameText(_Val,'70') then
Result := iacic_IncotermDiscount else
if SameText(_Val,'71') then
Result := iacic_PointOfSalesThresholdAllowance else
if SameText(_Val,'88') then
Result := iacic_MaterialSurchargeDeduction else
if SameText(_Val,'95') then
Result := iacic_Discount else
if SameText(_Val,'100') then
Result := iacic_SpecialRebate else
if SameText(_Val,'102') then
Result := iacic_FixedLongTerm else
if SameText(_Val,'103') then
Result := iacic_Temporary else
if SameText(_Val,'104') then
Result := iacic_Standard else
if SameText(_Val,'105') then
Result := iacic_YearlyTurnover else
Result := iacic_None;
end;
class function TXRechnungHelper.InvoiceAllowanceOrChargeIdentCodeToStr(
_Val: TInvoiceAllowanceOrChargeIdentCode): String;
begin
case _Val of
//iacic_HandlingCommission: Result := '1';
//iacic_AmendmentCommission: Result := '2';
//iacic_AcceptanceCommission: Result := '3';
//iacic_CommissionForObtainingAcceptance: Result := '4';
//iacic_CommissionOnDelivery: Result := '5';
//iacic_AdvisingCommission: Result := '6';
//iacic_ConfirmationCommission: Result := '7';
//iacic_DeferredPaymentCommission: Result := '8';
//iacic_CommissionForTakingUpDocuments: Result := '9';
//iacic_OpeningCommission: Result := '10';
//iacic_FeeForPaymentUnderReserve: Result := '11';
//iacic_DiscrepancyFee: Result := '12';
//iacic_DomicilationCommission: Result := '13';
//iacic_CommissionForReleaseOfGoods: Result := '14';
//iacic_CollectionCommission: Result := '15';
//iacic_NegotiationCommission: Result := '16';
//iacic_ReturnCommission: Result := '17';
//iacic_BLSplittingCharges: Result := '18';
//iacic_TrustCommission: Result := '19';
//iacic_TransferCommission: Result := '20';
//iacic_CommissionForOpeningIrrevocableDocumentaryCredits: Result := '21';
//iacic_PreadviceCommission: Result := '22';
//iacic_SupervisoryCommission: Result := '23';
//iacic_ModelCharges: Result := '24';
//iacic_RiskCommission: Result := '25';
//iacic_GuaranteeCommission: Result := '26';
//iacic_ReimbursementCommission: Result := '27';
//iacic_StampDuty: Result := '28';
//iacic_Brokerage: Result := '29';
//iacic_BankCharges: Result := '30';
//iacic_BankChargesInformation: Result := '31';
//iacic_CourierFee: Result := '32';
//iacic_PhoneFee: Result := '33';
//iacic_PostageFee: Result := '34';
//iacic_SWIFTFee: Result := '35';
//iacic_TelexFee: Result := '36';
//iacic_PenaltyForLateDeliveryOfDocuments: Result := '37';
//iacic_PenaltyForLateDeliveryOfValuationOfWorks: Result := '38';
//iacic_PenaltyForExecutionOfWorksBehindSchedule: Result := '39';
//iacic_OtherPenalties: Result := '40';
iacic_BonusForWorksAheadOfSchedule: Result := '41';
iacic_OtherBonus: Result := '42';
//iacic_ProjectManagementCost: Result := '44';
//iacic_ProRataRetention: Result := '45';
//iacic_ContractualRetention: Result := '46';
//iacic_OtherRetentions: Result := '47';
//iacic_InterestOnArrears: Result := '48';
//iacic_Interest: Result := '49';
//iacic_ChargePerCreditCover: Result := '50';
//iacic_ChargePerUnusedCreditCover: Result := '51';
//iacic_MinimumCommission: Result := '52';
//iacic_FactoringCommission: Result := '53';
//iacic_ChamberOfCommerceCharge: Result := '54';
//iacic_TransferCharges: Result := '55';
//iacic_RepatriationCharges: Result := '56';
//iacic_MiscellaneousCharges: Result := '57';
//iacic_ForeignExchangeCharges: Result := '58';
//iacic_AgreedDebitInterestCharge: Result := '59';
iacic_ManufacturersConsumerDiscount: Result := '60';
//iacic_FaxAdviceCharge: Result := '61';
iacic_DueToMilitaryStatus: Result := '62';
iacic_DueToWorkAccident: Result := '63';
iacic_SpecialAgreement: Result := '64';
iacic_ProductionErrorDiscount: Result := '65';
iacic_NewOutletDiscount: Result := '66';
iacic_SampleDiscount: Result := '67';
iacic_EndOfRangeDiscount: Result := '68';
//iacic_ChargeForACustomerSpecificFinish: Result := '69';
iacic_IncotermDiscount: Result := '70';
iacic_PointOfSalesThresholdAllowance: Result := '71';
//iacic_TechnicalModificationCosts: Result := '72';
//iacic_JoborderProductionCosts: Result := '73';
//iacic_OffpremisesCosts: Result := '74';
//iacic_AdditionalProcessingCosts: Result := '75';
//iacic_AttestingCharge: Result := '76';
//iacic_RushDeliverySurcharge: Result := '77';
//iacic_SpecialConstructionCosts: Result := '78';
//iacic_FreightCharges: Result := '79';
//iacic_PackingCharge: Result := '80';
//iacic_RepairCharge: Result := '81';
//iacic_LoadingCharge: Result := '82';
//iacic_SetupCharge: Result := '83';
//iacic_TestingCharge: Result := '84';
//iacic_WarehousingCharge: Result := '85';
//iacic_GoldSurcharge: Result := '86';
//iacic_CopperSurcharge: Result := '87';
iacic_MaterialSurchargeDeduction: Result := '88';
//iacic_LeadSurcharge: Result := '89';
//iacic_PriceIndexSurcharge: Result := '90';
//iacic_PlatinumSurcharge: Result := '91';
//iacic_SilverSurcharge: Result := '92';
//iacic_WolframSurcharge: Result := '93';
//iacic_AluminumSurcharge: Result := '94';
iacic_Discount: Result := '95';
//iacic_Insurance: Result := '96';
//iacic_MinimumOrderMinimumBillingCharge: Result := '97';
//iacic_MaterialSurchargeSspecialMaterials: Result := '98';
//iacic_Surcharge: Result := '99';
iacic_SpecialRebate: Result := '100';
//iacic_CarbonFootprintCharge: Result := '101';
iacic_FixedLongTerm: Result := '102';
iacic_Temporary: Result := '103';
iacic_Standard: Result := '104';
iacic_YearlyTurnover: Result := '105';
//iacic_WithheldTaxesAndSocialSecurityContributions: Result := '106';
else Result := '';
end;
end;
class function TXRechnungHelper.InvoiceAttachmentTypeToStr(_Val: TInvoiceAttachmentType): String;
begin
case _Val of
iat_application_pdf: Result := 'application/pdf';
iat_image_png: Result := 'image/png';
iat_image_jpeg: Result := 'image/jpeg';
iat_text_csv: Result := 'text/csv';
iat_application_vnd_openxmlformats_officedocument_spreadsheetml_sheet: Result := 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
iat_application_vnd_oasis_opendocument_spreadsheet: Result := 'application/vnd.oasis.opendocument.spreadsheet';
iat_application_xml: Result := 'application/xml';
else Result := '';
end;
end;
class function TXRechnungHelper.InvoiceAttachmentTypeFromStr(_Val: String): TInvoiceAttachmentType;
begin
if SameText(_Val,'application/pdf') then
Result := iat_application_pdf else
if SameText(_Val,'image/png') then
Result := iat_image_png else
if SameText(_Val,'image/jpeg') then
Result := iat_image_jpeg else
if SameText(_Val,'text/csv') then
Result := iat_text_csv else
if SameText(_Val,'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') then
Result := iat_application_vnd_openxmlformats_officedocument_spreadsheetml_sheet else
if SameText(_Val,'application/vnd.oasis.opendocument.spreadsheet') then
Result := iat_application_vnd_oasis_opendocument_spreadsheet else
if SameText(_Val,'application/xml') then Result := iat_application_xml else
Result := iat_application_None
end;
class function TXRechnungHelper.InvoiceDutyTaxFeeCategoryCodeFromStr(
_Val: String): TInvoiceDutyTaxFeeCategoryCode;
begin
if SameText(_Val,'AE') then
Result := idtfcc_AE_VATReverseCharge
else
if SameText(_Val,'E') then
Result := idtfcc_E_ExemptFromTax
else
if SameText(_Val,'G') then
Result := idtfcc_G_FreeExportItemTaxNotCharged
else
if SameText(_Val,'K') then
Result := idtfcc_K_VATExemptForEEAIntracommunitySupplyOfGoodsAndServices
else
if SameText(_Val,'L') then
Result := idtfcc_L_CanaryIslandsGeneralIndirectTax
else
if SameText(_Val,'M') then
Result := idtfcc_M_TaxForProductionServicesAndImportationInCeutaAndMelilla
else
if SameText(_Val,'O') then
Result := idtfcc_O_ServicesOutsideScopeOfTax
else
if SameText(_Val,'S') then
Result := idtfcc_S_StandardRate
else
if SameText(_Val,'Z') then
Result := idtfcc_Z_ZeroRatedGoods
else
Result := idtfcc_None;
end;
class function TXRechnungHelper.InvoiceDutyTaxFeeCategoryCodeToStr(_Val: TInvoiceDutyTaxFeeCategoryCode): String;
begin
case _Val of
//idtfcc_A_MixedTaxRate: Result := 'A';
//idtfcc_AA_LowerRate: Result := 'AA';
//idtfcc_AB_ExemptForResale: Result := 'AB';
//idtfcc_AC_ValueAddedTaxVATNotNowDueForPayment: Result := 'AC';
//idtfcc_AD_ValueAddedTaxVATDueFromAPreviousInvoice: Result := 'AD';
idtfcc_AE_VATReverseCharge: Result := 'AE';
//idtfcc_B_TransferredVAT: Result := 'B';
//idtfcc_C_DutyPaidBySupplier: Result := 'C';
//idtfcc_D_ValueAddedTaxVATMmarginSchemeTravelAgents: Result := 'D';
idtfcc_E_ExemptFromTax: Result := 'E';
//idtfcc_F_ValueAddedTaxVATMmarginSchemeSecondhandGoods: Result := 'F';
idtfcc_G_FreeExportItemTaxNotCharged: Result := 'G';
//idtfcc_H_HigherRate: Result := 'H';
//idtfcc_I_ValueAddedTaxVATMarginSchemeWorksOfArt: Result := 'I';
//idtfcc_J_ValueAddedTaxVATMarginSchemeCollectorsItemsAndAntiques: Result := 'J';
idtfcc_K_VATExemptForEEAIntracommunitySupplyOfGoodsAndServices: Result := 'K';
idtfcc_L_CanaryIslandsGeneralIndirectTax: Result := 'L';
idtfcc_M_TaxForProductionServicesAndImportationInCeutaAndMelilla: Result := 'M';
idtfcc_O_ServicesOutsideScopeOfTax: Result := 'O';
idtfcc_S_StandardRate: Result := 'S';
idtfcc_Z_ZeroRatedGoods: Result := 'Z';
else Result := '';
end;
end;
class function TXRechnungHelper.InvoiceNoteSubjectCodeFromStr(
_Val: String): TInvoiceNoteSubjectCode;
begin
if SameText(_Val,'AAI') then
Result := insc_AAI
else
if SameText(_Val,'AAJ') then
Result := insc_AAJ
else
if SameText(_Val,'AAK') then
Result := insc_AAK
else
if SameText(_Val,'SUR') then
Result := insc_SUR
else
if SameText(_Val,'REG') then
Result := insc_REG
else
if SameText(_Val,'ABL') then
Result := insc_ABL
else
if SameText(_Val,'TXD') then
Result := insc_TXD
else
if SameText(_Val,'CUS') then
Result := insc_CUS
else
if SameText(_Val,'PMT') then
Result := insc_PMT
else
Result := insc_None;
end;
class function TXRechnungHelper.InvoiceNoteSubjectCodeToStr(
_Val: TInvoiceNoteSubjectCode): String;
begin
case _Val of
insc_AAI: Result := 'AAI';
insc_AAJ: Result := 'AAJ';
insc_AAK: Result := 'AAK';
insc_SUR: Result := 'SUR';
insc_REG: Result := 'REG';
insc_ABL: Result := 'ABL';
insc_TXD: Result := 'TXD';
insc_CUS: Result := 'CUS';
insc_PMT: Result := 'PMT';
else Result := '';
end;
end;
class function TXRechnungHelper.InvoicePaymentMeansCodeFromStr(
_Val: String): TInvoicePaymentMeansCode;
begin
if SameText(_Val,'10') then
Result := ipmc_InCash
else
if SameText(_Val,'20') then
Result := ipmc_Cheque
else
if SameText(_Val,'30') then
Result := ipmc_CreditTransfer
else
if SameText(_Val,'54') then
Result := ipmc_CreditCard
else
if SameText(_Val,'58') then
Result := ipmc_SEPACreditTransfer
else
if SameText(_Val,'59') then
Result := ipmc_SEPADirectDebit
else
if SameText(_Val,'68') then
Result := ipmc_OnlinePaymentService
else
if SameText(_Val,'ZZZ') then
Result := ipmc_MutuallyDefined
else
if SameText(_Val,'1') then
Result := ipmc_InstrumentNotDefined
else
Result := ipmc_NotImplemented;
end;
class function TXRechnungHelper.InvoicePaymentMeansCodeToStr(_Val: TInvoicePaymentMeansCode): String;
begin
case _Val of
ipmc_InCash: Result := '10';
ipmc_Cheque: Result := '20';
ipmc_CreditTransfer: Result := '30';
ipmc_CreditCard: Result := '54';
ipmc_SEPACreditTransfer: Result := '58';
ipmc_SEPADirectDebit: Result := '59';
ipmc_OnlinePaymentService: Result := '68';
ipmc_MutuallyDefined: Result := 'ZZZ';
else Result := '1'; //ipmc_InstrumentNotDefined
end;
end;
class function TXRechnungHelper.InvoiceSpecialServiceDescriptionCodeFromStr(
_Val: String): TInvoiceSpecialServiceDescriptionCode;
begin
if SameText(_Val,'AA') then
Result := issdc_AA_Advertising else
if SameText(_Val,'AAA') then
Result := issdc_AAA_Telecommunication else
if SameText(_Val,'ABK') then
Result := issdc_ABK_Miscellaneous else
if SameText(_Val,'ABL') then
Result := issdc_ABL_AdditionalPackaging else
if SameText(_Val,'ADR') then
Result := issdc_ADR_OtherServices else
if SameText(_Val,'ADT') then
Result := issdc_ADT_Pickup else
if SameText(_Val,'FC') then
Result := issdc_FC_FreightService else
if SameText(_Val,'FI') then
Result := issdc_FI_Financing else
if SameText(_Val,'LA') then
Result := issdc_LA_Labelling else
if SameText(_Val,'PC') then
Result := issdc_PC_Packing else
Result := issdc_None;
end;
class function TXRechnungHelper.InvoiceSpecialServiceDescriptionCodeToStr(
_Val: TInvoiceSpecialServiceDescriptionCode): String;
begin
case _Val of
issdc_AA_Advertising: Result := 'AA';
issdc_AAA_Telecommunication: Result := 'AAA';
issdc_ABK_Miscellaneous: Result := 'ABK';
issdc_ABL_AdditionalPackaging: Result := 'ABL';
issdc_ADR_OtherServices: Result := 'ADR';
issdc_ADT_Pickup: Result := 'ADT';
issdc_FC_FreightService: Result := 'FC';
issdc_FI_Financing: Result := 'FI';
issdc_LA_Labelling: Result := 'LA';
issdc_PC_Packing: Result := 'PC';
else Result := '';
end;
end;
class function TXRechnungHelper.InvoiceTypeCodeFromStr(const _Val: String): TInvoiceTypeCode;
begin
if SameText(_Val,'326') then
Result := itc_PartialInvoice
else
if SameText(_Val,'380') then
Result := itc_CommercialInvoice
else
if SameText(_Val,'384') then
Result := itc_CorrectedInvoice
else
if SameText(_Val,'389') then
Result := itc_SelfbilledInvoice
else
if SameText(_Val,'381') then
Result := itc_CreditNote
else
if SameText(_Val,'875') then
Result := itc_PartialConstructionInvoice
else
if SameText(_Val,'876') then
Result := itc_PartialFinalConstructionInvoice
else
if SameText(_Val,'877') then
Result := itc_FinalConstructionInvoice
else
Result := itc_None;
end;
class function TXRechnungHelper.InvoiceTypeCodeToStr(_Val: TInvoiceTypeCode): String;
begin
case _Val of
itc_PartialInvoice: Result := '326';
itc_CommercialInvoice: Result := '380';
itc_CorrectedInvoice: Result := '384';
itc_SelfbilledInvoice: Result := '389';
itc_CreditNote: Result := '381';
itc_PartialConstructionInvoice: Result := '875';
itc_PartialFinalConstructionInvoice: Result := '876';
itc_FinalConstructionInvoice: Result := '877';
else Result := '';
end;
end;
class function TXRechnungHelper.InvoiceUnitCodeFromStr(
_Val: String): TInvoiceUnitCode;
begin
if SameText(_Val,'H87') then
Result := iuc_piece else
if SameText(_Val,'LS') then
Result := iuc_flaterate else
if SameText(_Val,'NAR') then
Result := iuc_number_of_articles else
if SameText(_Val,'SET') then
Result := iuc_set else
if SameText(_Val,'WEE') then
Result := iuc_week else
if SameText(_Val,'MON') then
Result := iuc_month else
if SameText(_Val,'DAY') then
Result := iuc_day else
if SameText(_Val,'TNE') then
Result := iuc_tonne_metric_ton else
if SameText(_Val,'MTK') then
Result := iuc_square_metre else
if SameText(_Val,'MTQ') then
Result := iuc_cubic_metre else
if SameText(_Val,'MTR') then
Result := iuc_metre else
if SameText(_Val,'MMK') then
Result := iuc_square_millimetre else
if SameText(_Val,'MMQ') then
Result := iuc_cubic_millimetre else
if SameText(_Val,'MMT') then
Result := iuc_millimetre else
if SameText(_Val,'MIN') then
Result := iuc_minute_unit_of_time else
if SameText(_Val,'SEC') then
Result := iuc_second_unit_of_time else
if SameText(_Val,'LTR') then
Result := iuc_litre else
if SameText(_Val,'HUR') then
Result := iuc_hour else
if SameText(_Val,'GRM') then
Result := iuc_gram else
if SameText(_Val,'KGM') then
Result := iuc_kilogram else
if SameText(_Val,'KMT') then
Result := iuc_kilometre else
if SameText(_Val,'KWH') then
Result := iuc_kilowatt_hour else
if SameText(_Val,'P1') then
Result := iuc_percent else
if SameText(_Val,'XPK') then
Result := iuc_packaging else
Result := iuc_one; //C62
end;
class function TXRechnungHelper.InvoiceUnitCodeToStr(_Val: TInvoiceUnitCode): String;
begin
//mehr Konvertierungen in Res\intf.XRechnung.unusedUnits.pas
case _Val of
iuc_one : Result := 'C62';
iuc_piece : Result := 'H87';
iuc_flaterate : Result := 'LS';
iuc_number_of_articles : Result := 'NAR';
iuc_set : Result := 'SET';
iuc_week : Result := 'WEE';
iuc_month : Result := 'MON';
iuc_day : Result := 'DAY';
iuc_tonne_metric_ton : Result := 'TNE';
iuc_square_metre : Result := 'MTK';
iuc_cubic_metre : Result := 'MTQ';
iuc_metre : Result := 'MTR';
iuc_square_millimetre : Result := 'MMK';
iuc_cubic_millimetre : Result := 'MMQ';
iuc_millimetre : Result := 'MMT';
iuc_minute_unit_of_time : Result := 'MIN';
iuc_second_unit_of_time : Result := 'SEC';
iuc_litre : Result := 'LTR';
iuc_hour : Result := 'HUR';
iuc_kilogram : Result := 'KGM';
iuc_gram : Result := 'GRM';
iuc_kilometre : Result := 'KMT';
iuc_kilowatt_hour : Result := 'KWH';
iuc_percent : Result := 'P1';
iuc_packaging : Result := 'XPK';
end;
end;
class function TXRechnungHelper.PercentageFromStr(_Val: String): double;
var
fs : TFormatSettings;
begin
fs.ThousandSeparator := ',';
fs.DecimalSeparator := '.';
Result := StrToFloatDef(_Val,0,fs);
end;
class function TXRechnungHelper.PercentageToStr(_Val: double): String;
begin