«
Zurück
|
Weiter
»
Revision f9422f02
Von Werner Hahn vor 1 Tag hinzugefügt
- ID f9422f02f97d4de7deca35c4de0758e5b006873e
- Vorgänger 48fa6dcc
SL/XMLInvoice/CrossIndustryInvoice.pm | ||
---|---|---|
5 | 5 |
|
6 | 6 |
use parent qw(SL::XMLInvoice::Base); |
7 | 7 |
|
8 |
use constant ITEMS_XPATH => '//ram:IncludedSupplyChainTradeLineItem'; |
|
9 | 8 |
|
10 | 9 |
=head1 NAME |
11 | 10 |
|
... | ... | |
51 | 50 |
=head1 AUTHOR |
52 | 51 |
|
53 | 52 |
Johannes Grassler <info@computer-grassler.de> |
53 |
Werner Hahn <wh@futureworldsearch.net> |
|
54 | 54 |
|
55 | 55 |
=cut |
56 | 56 |
|
... | ... | |
73 | 73 |
return 0; |
74 | 74 |
} |
75 | 75 |
|
76 |
sub namespaces { |
|
77 |
my ($self, $dom) = @_; |
|
78 |
my $rootnode = $dom->documentElement; |
|
79 |
my @nodes = $rootnode->findnodes('namespace::*'); |
|
80 |
my %namespaces = map { $_->getData => $_->getLocalName} @nodes; |
|
81 |
return \%namespaces; |
|
82 |
} |
|
83 |
|
|
76 | 84 |
# XML XPath expressions for global metadata |
77 | 85 |
sub scalar_xpaths { |
86 |
my ($self) = @_; |
|
87 |
|
|
88 |
my $rsm = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'}; |
|
89 |
my $ram = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'}; |
|
90 |
my $udt = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100'}; |
|
91 |
$ram .= ":" if $ram; |
|
92 |
$rsm .= ":" if $rsm; |
|
93 |
$udt .= ":" if $udt; |
|
94 |
|
|
78 | 95 |
return { |
79 |
currency => '//ram:InvoiceCurrencyCode',
|
|
80 |
direct_debit => '//ram:SpecifiedTradeSettlementPaymentMeans/ram:TypeCode',
|
|
81 |
duedate => '//ram:DueDateDateTime/udt:DateTimeString',
|
|
82 |
gross_total => '//ram:DuePayableAmount',
|
|
83 |
iban => '//ram:SpecifiedTradeSettlementPaymentMeans/ram:PayeePartyCreditorFinancialAccount/ram:IBANID',
|
|
84 |
invnumber => '//rsm:ExchangedDocument/ram:ID',
|
|
85 |
net_total => '//ram:SpecifiedTradeSettlementHeaderMonetarySummation' . '//ram:TaxBasisTotalAmount',
|
|
86 |
transdate => '//ram:IssueDateTime/udt:DateTimeString',
|
|
87 |
taxnumber => '//ram:SellerTradeParty/ram:SpecifiedTaxRegistration/ram:ID[@schemeID="FC"]',
|
|
88 |
type => '//rsm:ExchangedDocument/ram:TypeCode',
|
|
89 |
ustid => '//ram:SellerTradeParty/ram:SpecifiedTaxRegistration/ram:ID[@schemeID="VA"]',
|
|
90 |
vendor_name => '//ram:SellerTradeParty/ram:Name',
|
|
96 |
currency => '//' . $ram . 'InvoiceCurrencyCode',
|
|
97 |
direct_debit => '//' . $ram . 'SpecifiedTradeSettlementPaymentMeans/' . $ram . 'TypeCode',
|
|
98 |
duedate => '//' . $ram . 'DueDateDateTime/' . $udt . 'DateTimeString',
|
|
99 |
gross_total => '//' . $ram . 'DuePayableAmount',
|
|
100 |
iban => '//' . $ram . 'SpecifiedTradeSettlementPaymentMeans/' . $ram . 'PayeePartyCreditorFinancialAccount/' . $ram . 'IBANID',
|
|
101 |
invnumber => '//' . $rsm . 'ExchangedDocument/' . $ram . 'ID',
|
|
102 |
net_total => '//' . $ram . 'SpecifiedTradeSettlementHeaderMonetarySummation' . '//' . $ram . 'TaxBasisTotalAmount',
|
|
103 |
transdate => '//' . $ram . 'IssueDateTime/' . $udt . 'DateTimeString',
|
|
104 |
taxnumber => '//' . $ram . 'SellerTradeParty/' . $ram . 'SpecifiedTaxRegistration/' . $ram . 'ID[@schemeID="FC"]',
|
|
105 |
type => '//' . $rsm . 'ExchangedDocument/' . $ram . 'TypeCode',
|
|
106 |
ustid => '//' . $ram . 'SellerTradeParty/' . $ram . 'SpecifiedTaxRegistration/' . $ram . 'ID[@schemeID="VA"]',
|
|
107 |
vendor_name => '//' . $ram . 'SellerTradeParty/' . $ram . 'Name',
|
|
91 | 108 |
}; |
92 | 109 |
} |
93 | 110 |
|
94 | 111 |
sub item_xpaths { |
112 |
my ($self) = @_; |
|
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; |
|
95 | 119 |
return { |
96 |
'currency' => undef, # Only global currency in CrossIndustryInvoice |
|
97 |
'price' => './ram:SpecifiedLineTradeAgreement/ram:NetPriceProductTradePrice',
|
|
98 |
'description' => './ram:SpecifiedTradeProduct/ram:Name',
|
|
99 |
'quantity' => './ram:SpecifiedLineTradeDelivery/ram:BilledQuantity',
|
|
100 |
'subtotal' => './ram:SpecifiedLineTradeSettlement/ram:SpecifiedTradeSettlementLineMonetarySummation/ram:LineTotalAmount',
|
|
101 |
'tax_rate' => './ram:SpecifiedLineTradeSettlement/ram:ApplicableTradeTax/ram:RateApplicablePercent',
|
|
102 |
'tax_scheme' => './ram:SpecifiedLineTradeSettlement/ram:ApplicableTradeTax/ram:TypeCode',
|
|
103 |
'vendor_partno' => './ram:SpecifiedTradeProduct/ram:SellerAssignedID',
|
|
120 |
'currency' => undef, # Only global currency in CrossIndustryInvoice
|
|
121 |
'price' => './' . $ram . 'SpecifiedLineTradeAgreement/' . $ram . 'NetPriceProductTradePrice',
|
|
122 |
'description' => './' . $ram . 'SpecifiedTradeProduct/' . $ram . 'Name',
|
|
123 |
'quantity' => './' . $ram . 'SpecifiedLineTradeDelivery/' . $ram . 'BilledQuantity',
|
|
124 |
'subtotal' => './' . $ram . 'SpecifiedLineTradeSettlement/' . $ram . 'SpecifiedTradeSettlementLineMonetarySummation/' . $ram . 'LineTotalAmount',
|
|
125 |
'tax_rate' => './' . $ram . 'SpecifiedLineTradeSettlement/' . $ram . 'ApplicableTradeTax/' . $ram . 'RateApplicablePercent',
|
|
126 |
'tax_scheme' => './' . $ram . 'SpecifiedLineTradeSettlement/' . $ram . 'ApplicableTradeTax/' . $ram . 'TypeCode',
|
|
127 |
'vendor_partno' => './' . $ram . 'SpecifiedTradeProduct/' . $ram . 'SellerAssignedID',
|
|
104 | 128 |
}; |
105 | 129 |
} |
106 | 130 |
|
131 |
sub items_xpath { |
|
132 |
my ($self) = @_; |
|
133 |
my $rsm = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'}; |
|
134 |
my $ram = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'}; |
|
135 |
my $udt = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100'}; |
|
136 |
$ram .= ":" if $ram; |
|
137 |
$rsm .= ":" if $rsm; |
|
138 |
$udt .= ":" if $udt; |
|
139 |
return '//' . $ram . 'IncludedSupplyChainTradeLineItem'; |
|
140 |
} |
|
107 | 141 |
|
108 | 142 |
# Metadata accessor method |
109 | 143 |
sub metadata { |
... | ... | |
143 | 177 |
$self->{_metadata} = {}; |
144 | 178 |
$self->{_items} = (); |
145 | 179 |
|
180 |
my $ram = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'}; |
|
181 |
$ram .= ":" if $ram; |
|
182 |
my $udt = $self->{namespaces}->{'urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100'}; |
|
183 |
#foreach my $namespace (@{$self->{namespaces}}( |
|
146 | 184 |
# Retrieve scalar metadata from DOM |
147 | 185 |
foreach my $key ( keys %{$self->scalar_xpaths} ) { |
148 | 186 |
my $xpath = ${$self->scalar_xpaths}{$key}; |
... | ... | |
152 | 190 |
next; |
153 | 191 |
} |
154 | 192 |
my $value = $self->{dom}->findnodes($xpath); |
193 |
unless ($udt) { |
|
194 |
$value = $self->{dom}->findnodes('//' . $ram . 'DueDateDateTime','DateTimeString') if $key eq 'duedate'; |
|
195 |
$value = $self->{dom}->findnodes('//' . $ram . 'IssueDateTime','DateTimeString') if $key eq 'transdate'; |
|
196 |
} |
|
155 | 197 |
if ( $value ) { |
156 | 198 |
# Get rid of extraneous white space |
157 | 199 |
$value = $value->string_value; |
... | ... | |
163 | 205 |
} |
164 | 206 |
} |
165 | 207 |
|
166 |
|
|
167 | 208 |
# Convert payment code metadata field to Boolean |
168 | 209 |
# See https://service.unece.org/trade/untdid/d16b/tred/tred4461.htm for other valid codes. |
169 | 210 |
${$self->{_metadata}}{'direct_debit'} = ${$self->{_metadata}}{'direct_debit'} == 59 ? 1 : 0; |
... | ... | |
171 | 212 |
my @items; |
172 | 213 |
$self->{_items} = \@items; |
173 | 214 |
|
174 |
foreach my $item ( $self->{dom}->findnodes(ITEMS_XPATH) ) {
|
|
215 |
foreach my $item ( $self->{dom}->findnodes($self->items_xpath) ) {
|
|
175 | 216 |
my %line_item; |
176 | 217 |
foreach my $key ( keys %{$self->item_xpaths} ) { |
177 | 218 |
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.