«
Zurück
|
Weiter
»
Revision f9422f02
Von Werner Hahn vor 1 Tag hinzugefügt
- ID f9422f02f97d4de7deca35c4de0758e5b006873e
- Vorgänger 48fa6dcc
SL/XMLInvoice/CrossIndustryDocument.pm | ||
---|---|---|
5 | 5 |
|
6 | 6 |
use parent qw(SL::XMLInvoice::Base); |
7 | 7 |
|
8 |
use constant ITEMS_XPATH => '//ram:IncludedSupplyChainTradeLineItem'; |
|
9 |
|
|
10 | 8 |
=head1 NAME |
11 | 9 |
|
12 | 10 |
SL::XMLInvoice::CrossIndustryDocument - XML parser for UN/CEFACT Cross Industry Document |
... | ... | |
51 | 49 |
=head1 AUTHOR |
52 | 50 |
|
53 | 51 |
Johannes Grassler <info@computer-grassler.de> |
52 |
Werner Hahn <wh@futureworldsearch.net> |
|
54 | 53 |
|
55 | 54 |
=cut |
56 | 55 |
|
... | ... | |
73 | 72 |
return 0; |
74 | 73 |
} |
75 | 74 |
|
75 |
sub namespaces { |
|
76 |
my ($self, $dom) = @_; |
|
77 |
my $rootnode = $dom->documentElement; |
|
78 |
my @nodes = $rootnode->findnodes('namespace::*'); |
|
79 |
my @namespaces = map {[ $_->getData, $_->getLocalName]} @nodes; |
|
80 |
return \@namespaces; |
|
81 |
} |
|
82 |
|
|
76 | 83 |
# XML XPath expressions for global metadata |
77 | 84 |
sub scalar_xpaths { |
85 |
my ($self) = @_; |
|
86 |
|
|
87 |
my $rsm = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'}; |
|
88 |
my $ram = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'}; |
|
89 |
my $udt = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100'}; |
|
90 |
$ram .= ":" if $ram; |
|
91 |
$rsm .= ":" if $rsm; |
|
92 |
$udt .= ":" if $udt; |
|
93 |
|
|
78 | 94 |
return { |
79 |
currency => ['//ram:InvoiceCurrencyCode'],
|
|
80 |
direct_debit => ['//ram:SpecifiedTradeSettlementPaymentMeans/ram:TypeCode'],
|
|
81 |
duedate => ['//ram:DueDateDateTime/udt:DateTimeString', '//ram:EffectiveSpecifiedPeriod/ram:CompleteDateTime/udt:DateTimeString'],
|
|
82 |
gross_total => ['//ram:DuePayableAmount'],
|
|
83 |
iban => ['//ram:SpecifiedTradeSettlementPaymentMeans/ram:PayeePartyCreditorFinancialAccount/ram:IBANID'],
|
|
84 |
invnumber => ['//rsm:HeaderExchangedDocument/ram:ID'],
|
|
85 |
net_total => ['//ram:TaxBasisTotalAmount'],
|
|
86 |
transdate => ['//ram:IssueDateTime/udt:DateTimeString'],
|
|
87 |
taxnumber => ['//ram:SellerTradeParty/ram:SpecifiedTaxRegistration/ram:ID[@schemeID="FC"]'],
|
|
88 |
type => ['//rsm:HeaderExchangedDocument/ram:TypeCode'],
|
|
89 |
ustid => ['//ram:SellerTradeParty/ram:SpecifiedTaxRegistration/ram:ID[@schemeID="VA"]'],
|
|
90 |
vendor_name => ['//ram:SellerTradeParty/ram:Name'],
|
|
95 |
currency => ['//' . $ram . 'InvoiceCurrencyCode'],
|
|
96 |
direct_debit => ['//' . $ram . 'SpecifiedTradeSettlementPaymentMeans/' . $ram . 'TypeCode'],
|
|
97 |
duedate => ['//' . $ram . 'DueDateDateTime/' . $udt . 'DateTimeString', '//' . $ram . 'EffectiveSpecifiedPeriod/' . $ram . 'CompleteDateTime/' . $udt . 'DateTimeString'],
|
|
98 |
gross_total => ['//' . $ram . 'DuePayableAmount'],
|
|
99 |
iban => ['//' . $ram . 'SpecifiedTradeSettlementPaymentMeans/' . $ram . 'PayeePartyCreditorFinancialAccount/' . $ram . 'IBANID'],
|
|
100 |
invnumber => ['//' . $rsm . 'HeaderExchangedDocument/' . $ram . 'ID'],
|
|
101 |
net_total => ['//' . $ram . 'TaxBasisTotalAmount'],
|
|
102 |
transdate => ['//' . $ram . 'IssueDateTime/' . $udt . 'DateTimeString'],
|
|
103 |
taxnumber => ['//' . $ram . 'SellerTradeParty/' . $ram . 'SpecifiedTaxRegistration/' . $ram . 'ID[@schemeID="FC"]'],
|
|
104 |
type => ['//' . $rsm . 'HeaderExchangedDocument/' . $ram . 'TypeCode'],
|
|
105 |
ustid => ['//' . $ram . 'SellerTradeParty/' . $ram . 'SpecifiedTaxRegistration/' . $ram . 'ID[@schemeID="VA"]'],
|
|
106 |
vendor_name => ['//' . $ram . 'SellerTradeParty/' . $ram . 'Name'],
|
|
91 | 107 |
}; |
92 | 108 |
} |
93 | 109 |
|
94 | 110 |
sub item_xpaths { |
111 |
my ($self) = @_; |
|
112 |
|
|
113 |
my $rsm = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'}; |
|
114 |
my $ram = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'}; |
|
115 |
my $udt = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100'}; |
|
116 |
$ram .= ":" if $ram; |
|
117 |
$rsm .= ":" if $rsm; |
|
118 |
$udt .= ":" if $udt; |
|
119 |
|
|
95 | 120 |
return { |
96 |
'currency' => ['./ram:SpecifiedSupplyChainTradeAgreement/ram:GrossPriceProductTradePrice/ram:ChargeAmount[attribute::currencyID]',
|
|
97 |
'./ram:SpecifiedSupplyChainTradeAgreement/ram:GrossPriceProductTradePrice/ram:BasisAmount'],
|
|
98 |
'price' => ['./ram:SpecifiedSupplyChainTradeAgreement/ram:GrossPriceProductTradePrice/ram:ChargeAmount',
|
|
99 |
'./ram:SpecifiedSupplyChainTradeAgreement/ram:GrossPriceProductTradePrice/ram:BasisAmount'],
|
|
100 |
'description' => ['./ram:SpecifiedTradeProduct/ram:Name'],
|
|
101 |
'quantity' => ['./ram:SpecifiedSupplyChainTradeDelivery/ram:BilledQuantity',],
|
|
102 |
'subtotal' => ['./ram:SpecifiedSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementMonetarySummation/ram:LineTotalAmount'],
|
|
103 |
'tax_rate' => ['./ram:SpecifiedSupplyChainTradeSettlement/ram:ApplicableTradeTax/ram:ApplicablePercent'],
|
|
104 |
'tax_scheme' => ['./ram:SpecifiedSupplyChainTradeSettlement/ram:ApplicableTradeTax/ram:TypeCode'],
|
|
105 |
'vendor_partno' => ['./ram:SpecifiedTradeProduct/ram:SellerAssignedID'],
|
|
121 |
'currency' => ['./' . $ram . ':SpecifiedSupplyChainTradeAgreement/' . $ram . ':GrossPriceProductTradePrice/' . $ram . ':ChargeAmount[attribute::currencyID]',
|
|
122 |
'./' . $ram . ':SpecifiedSupplyChainTradeAgreement/' . $ram . ':GrossPriceProductTradePrice/' . $ram . ':BasisAmount'],
|
|
123 |
'price' => ['./' . $ram . ':SpecifiedSupplyChainTradeAgreement/' . $ram . ':GrossPriceProductTradePrice/' . $ram . ':ChargeAmount',
|
|
124 |
'./' . $ram . ':SpecifiedSupplyChainTradeAgreement/' . $ram . ':GrossPriceProductTradePrice/' . $ram . ':BasisAmount'],
|
|
125 |
'description' => ['./' . $ram . ':SpecifiedTradeProduct/' . $ram . ':Name'],
|
|
126 |
'quantity' => ['./' . $ram . ':SpecifiedSupplyChainTradeDelivery/' . $ram . ':BilledQuantity',],
|
|
127 |
'subtotal' => ['./' . $ram . ':SpecifiedSupplyChainTradeSettlement/' . $ram . ':SpecifiedTradeSettlementMonetarySummation/' . $ram . ':LineTotalAmount'],
|
|
128 |
'tax_rate' => ['./' . $ram . ':SpecifiedSupplyChainTradeSettlement/' . $ram . ':ApplicableTradeTax/' . $ram . ':ApplicablePercent'],
|
|
129 |
'tax_scheme' => ['./' . $ram . ':SpecifiedSupplyChainTradeSettlement/' . $ram . ':ApplicableTradeTax/' . $ram . ':TypeCode'],
|
|
130 |
'vendor_partno' => ['./' . $ram . ':SpecifiedTradeProduct/' . $ram . ':SellerAssignedID'],
|
|
106 | 131 |
}; |
107 | 132 |
} |
108 | 133 |
|
134 |
sub items_xpath { |
|
135 |
my ($self) = @_; |
|
136 |
my $rsm = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'}; |
|
137 |
my $ram = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'}; |
|
138 |
my $udt = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100'}; |
|
139 |
$ram .= ":" if $ram; |
|
140 |
$rsm .= ":" if $rsm; |
|
141 |
$udt .= ":" if $udt; |
|
142 |
return '//' . $ram . 'IncludedSupplyChainTradeLineItem'; |
|
143 |
} |
|
109 | 144 |
|
110 | 145 |
# Metadata accessor method |
111 | 146 |
sub metadata { |
... | ... | |
145 | 180 |
$self->{_metadata} = {}; |
146 | 181 |
$self->{_items} = (); |
147 | 182 |
|
183 |
my $ram = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'}; |
|
184 |
$ram .= ":" if $ram; |
|
185 |
my $udt = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100'}; |
|
148 | 186 |
# Retrieve scalar metadata from DOM |
149 | 187 |
foreach my $key ( keys %{$self->scalar_xpaths} ) { |
150 | 188 |
foreach my $xpath ( @{${$self->scalar_xpaths}{$key}} ) { |
... | ... | |
154 | 192 |
next; |
155 | 193 |
} |
156 | 194 |
my $value = $self->{dom}->findnodes($xpath); |
195 |
unless ($udt) { |
|
196 |
$value = $self->{dom}->findnodes('//' . $ram . 'DueDateDateTime','DateTimeString') if $key eq 'duedate'; |
|
197 |
$value = $self->{dom}->findnodes('//' . $ram . 'IssueDateTime','DateTimeString') if $key eq 'transdate'; |
|
198 |
} |
|
157 | 199 |
if ( $value ) { |
158 | 200 |
# Get rid of extraneous white space |
159 | 201 |
$value = $value->string_value; |
... | ... | |
175 | 217 |
my @items; |
176 | 218 |
$self->{_items} = \@items; |
177 | 219 |
|
178 |
foreach my $item ( $self->{dom}->findnodes(ITEMS_XPATH)) {
|
|
220 |
foreach my $item ( $self->{dom}->findnodes($self->items_xpath)) {
|
|
179 | 221 |
my %line_item; |
180 | 222 |
foreach my $key ( keys %{$self->item_xpaths} ) { |
181 | 223 |
foreach my $xpath ( @{${$self->item_xpaths}{$key}} ) { |
Auch abrufbar als: Unified diff
XMLInvoice: gültige namespaces aus der xml holen ...
Die namespaces CrossIndustryInvoice, ReusableAggregateBusinessInformationEntity, UnqualifiedDataType
können beliebig sein und sind von ZUGfERD nicht festgelegt.
Deswegen werden die ns jetzt vorher ausgelesen.