Revision 58521016
Von Johannes Grassler vor mehr als 1 Jahr hinzugefügt
scripts/xmlinvoice-cli.pl | ||
---|---|---|
1 |
#!/usr/bin/perl |
|
2 |
|
|
3 |
# Script for test driving SL::XMLInvoice. Use on extracted XML invoice payloads |
|
4 |
# (faktur-x.xml) from ZUGFeRD invoices or XRechnung invoices. PDF extraction is |
|
5 |
# not supported. |
|
6 |
|
|
7 |
BEGIN { |
|
8 |
use FindBin; |
|
9 |
|
|
10 |
unshift(@INC, $FindBin::Bin . '/../modules/override'); # Use our own versions of various modules (e.g. YAML). |
|
11 |
push (@INC, $FindBin::Bin . '/..'); |
|
12 |
} |
|
13 |
|
|
14 |
use SL::XMLInvoice; |
|
15 |
|
|
16 |
use utf8; |
|
17 |
|
|
18 |
if ( scalar(@ARGV) == 0 ) |
|
19 |
{ |
|
20 |
die "usage: $0 <xml invoice file> [ ... <xml invoice file> ]\n"; |
|
21 |
} |
|
22 |
|
|
23 |
foreach my $xml_file ( @ARGV) { |
|
24 |
my $xml_data = ""; |
|
25 |
|
|
26 |
open F, $xml_file or die "Couldn't open $xml_file for reading: $!\n"; |
|
27 |
|
|
28 |
while (my $line = <F> ) { $xml_data .= $line; } |
|
29 |
close F; |
|
30 |
|
|
31 |
my $parser = SL::XMLInvoice->new($xml_data); |
|
32 |
|
|
33 |
if ( ${$parser}{'result'} != SL::XMLInvoice->RES_OK ) |
|
34 |
{ |
|
35 |
die "Parser creation failed: ${$parser}{'message'}\n"; |
|
36 |
} |
|
37 |
|
|
38 |
foreach my $key ( keys %{$parser->metadata} ) |
|
39 |
{ |
|
40 |
print "$key: |" . $parser->metadata->{$key} . "|\n"; |
|
41 |
} |
|
42 |
|
|
43 |
foreach my $item ( @{$parser->items} ) { |
|
44 |
my %line_item = %{$item}; |
|
45 |
foreach my $field ( keys %line_item ) { |
|
46 |
print " $field: |$line_item{$field}|\n"; |
|
47 |
} |
|
48 |
print "\n"; |
|
49 |
} |
|
50 |
} |
Auch abrufbar als: Unified diff
SL::XMLInvoice: Testskript hinzugefuegt
scripts/xmlinvoice-cli.pl kann verwendet werden um
SL::XMLInvoice direkt an der Kommandozeile zu testen.