1 package SL::DB::Helper::ZUGFeRD;
6 use parent qw(Exporter);
7 our @EXPORT = qw(create_zugferd_data create_zugferd_xmp_data);
9 use SL::DB::BankAccount;
10 use SL::DB::GenericTranslation;
13 use SL::Helper::ISO3166;
14 use SL::Helper::ISO4217;
15 use SL::Helper::UNECERecommendation20;
19 use Encode qw(encode);
20 use List::MoreUtils qw(any pairwise);
21 use List::Util qw(first sum);
25 my @line_names = qw(LineOne LineTwo LineThree);
29 return encode('UTF-8', $value // '');
34 return $::form->round_amount($value, 2);
39 my $type = $self->invoice_type;
42 return $type eq 'ar_transaction' ? $::locale->text('Invoice') : $self->displayable_type;
47 my $type = $self->invoice_type;
49 # 326 (Partial invoice)
50 # 380 (Commercial invoice)
51 # 384 (Corrected Invoice)
53 # 389 (Credit note, self billed invoice)
55 return $type eq 'credit_note' ? 381
56 : $type eq 'invoice_storno' ? 457
57 : $type eq 'credit_note_storno' ? 458
64 # Mapping from kivitendo's units to UN/ECE Recommendation 20 & 21.
65 my $code = SL::Helper::UNECERecommendation20::map_name_to_code($unit);
66 return $code if $code;
68 $::lxdebug->message(LXDebug::WARN(), "ZUGFeRD unit name mapping: no UN/ECE Recommendation 20/21 unit known for kivitendo unit '$unit'; using 'C62'");
73 sub _parse_our_address {
75 my @street = grep { $_ } ($::instance_conf->get_address_street1, $::instance_conf->get_address_street2);
77 push @result, [ 'PostcodeCode', $::instance_conf->get_address_zipcode ] if $::instance_conf->get_address_zipcode;
78 push @result, grep { $_->[1] } pairwise { [ $a, $b] } @line_names, @street;
79 push @result, [ 'CityName', $::instance_conf->get_address_city ] if $::instance_conf->get_address_city;
80 push @result, [ 'CountryID', SL::Helper::ISO3166::map_name_to_alpha_2_code($::instance_conf->get_address_country) // 'DE' ];
85 sub _customer_postal_trade_address {
88 # <ram:PostalTradeAddress>
89 $params{xml}->startTag("ram:PostalTradeAddress");
91 my @parts = grep { $_ } map { $params{customer}->$_ } qw(department_1 department_2 street);
93 $params{xml}->dataElement("ram:PostcodeCode", _u8($params{customer}->zipcode));
94 $params{xml}->dataElement("ram:" . $_->[0], _u8($_->[1])) for grep { $_->[1] } pairwise { [ $a, $b] } @line_names, @parts;
95 $params{xml}->dataElement("ram:CityName", _u8($params{customer}->city));
96 $params{xml}->dataElement("ram:CountryID", _u8(SL::Helper::ISO3166::map_name_to_alpha_2_code($params{customer}->country) // 'DE'));
98 # </ram:PostalTradeAddress>
101 sub _tax_rate_and_code {
102 my ($taxzone, $tax) = @_;
104 my ($tax_rate, $tax_code) = @_;
106 if ($taxzone->description =~ m{Au.*erhalb}) {
110 } elsif ($taxzone->description =~ m{EU mit}) {
115 $tax_rate = $tax->rate * 100;
116 $tax_code = !$tax_rate ? 'Z' : 'S';
119 return (rate => $tax_rate, code => $tax_code);
123 my ($self, %params) = @_;
125 my $item_ptc = $params{ptc_data}->{items}->[$params{line_number}];
127 my $taxkey = $item_ptc->{taxkey_id} ? SL::DB::TaxKey->load_cached($item_ptc->{taxkey_id}) : undef;
128 my $tax = $item_ptc->{taxkey_id} ? SL::DB::Tax->load_cached($taxkey->tax_id) : undef;
129 my %tax_info = _tax_rate_and_code($self->taxzone, $tax);
131 # <ram:IncludedSupplyChainTradeLineItem>
132 $params{xml}->startTag("ram:IncludedSupplyChainTradeLineItem");
134 # <ram:AssociatedDocumentLineDocument>
135 $params{xml}->startTag("ram:AssociatedDocumentLineDocument");
136 $params{xml}->dataElement("ram:LineID", $params{line_number} + 1);
137 $params{xml}->endTag;
139 $params{xml}->startTag("ram:SpecifiedTradeProduct");
140 $params{xml}->dataElement("ram:SellerAssignedID", _u8($params{item}->part->partnumber));
141 $params{xml}->dataElement("ram:Name", _u8($params{item}->description));
142 $params{xml}->endTag;
144 $params{xml}->startTag("ram:SpecifiedLineTradeAgreement");
145 $params{xml}->startTag("ram:NetPriceProductTradePrice");
146 $params{xml}->dataElement("ram:ChargeAmount", _r2($item_ptc->{sellprice}));
147 $params{xml}->endTag;
148 $params{xml}->endTag;
149 # </ram:SpecifiedLineTradeAgreement>
151 # <ram:SpecifiedLineTradeDelivery>
152 $params{xml}->startTag("ram:SpecifiedLineTradeDelivery");
153 $params{xml}->dataElement("ram:BilledQuantity", $params{item}->qty, unitCode => _unit_code($params{item}->unit));
154 $params{xml}->endTag;
155 # </ram:SpecifiedLineTradeDelivery>
157 # <ram:SpecifiedLineTradeSettlement>
158 $params{xml}->startTag("ram:SpecifiedLineTradeSettlement");
160 # <ram:ApplicableTradeTax>
161 $params{xml}->startTag("ram:ApplicableTradeTax");
162 $params{xml}->dataElement("ram:TypeCode", "VAT");
163 $params{xml}->dataElement("ram:CategoryCode", $tax_info{code});
164 $params{xml}->dataElement("ram:RateApplicablePercent", _r2($tax_info{rate}));
165 $params{xml}->endTag;
166 # </ram:ApplicableTradeTax>
168 # <ram:SpecifiedTradeSettlementLineMonetarySummation>
169 $params{xml}->startTag("ram:SpecifiedTradeSettlementLineMonetarySummation");
170 $params{xml}->dataElement("ram:LineTotalAmount", _r2($item_ptc->{linetotal}));
171 $params{xml}->endTag;
172 # </ram:SpecifiedTradeSettlementLineMonetarySummation>
174 $params{xml}->endTag;
175 # </ram:SpecifiedLineTradeSettlement>
177 $params{xml}->endTag;
178 # <ram:IncludedSupplyChainTradeLineItem>
181 sub _specified_trade_settlement_payment_means {
182 my ($self, %params) = @_;
184 # <ram:SpecifiedTradeSettlementPaymentMeans>
185 $params{xml}->startTag('ram:SpecifiedTradeSettlementPaymentMeans');
186 $params{xml}->dataElement('ram:TypeCode', $self->direct_debit ? 59 : 58); # 59 = SEPA direct debit, 58 = SEPA credit transfer
188 if ($self->direct_debit) {
189 $params{xml}->startTag('ram:PayerPartyDebtorFinancialAccount');
190 $params{xml}->dataElement('ram:IBANID', $self->customer->iban);
191 $params{xml}->endTag;
194 $params{xml}->startTag('ram:PayeePartyCreditorFinancialAccount');
195 $params{xml}->dataElement('ram:IBANID', $params{bank_account}->iban);
196 $params{xml}->endTag;
199 $params{xml}->endTag;
200 # </ram:SpecifiedTradeSettlementPaymentMeans>
204 my ($self, %params) = @_;
208 foreach my $item (@{ $params{ptc_data}->{items} }) {
209 $taxkey_info{$item->{taxkey_id}} //= {
213 my $info = $taxkey_info{$item->{taxkey_id}};
214 $info->{taxkey} //= SL::DB::TaxKey->load_cached($item->{taxkey_id});
215 $info->{tax} //= SL::DB::Tax->load_cached($info->{taxkey}->tax_id);
216 $info->{linetotal} += $item->{linetotal};
219 foreach my $taxkey_id (sort keys %taxkey_info) {
220 my $info = $taxkey_info{$taxkey_id};
221 my %tax_info = _tax_rate_and_code($self->taxzone, $info->{tax});
223 # <ram:ApplicableTradeTax>
224 $params{xml}->startTag("ram:ApplicableTradeTax");
225 $params{xml}->dataElement("ram:CalculatedAmount", _r2($params{ptc_data}->{taxes_by_tax_id}->{$info->{taxkey}->tax_id}));
226 $params{xml}->dataElement("ram:TypeCode", "VAT");
227 $params{xml}->dataElement("ram:BasisAmount", _r2($info->{linetotal}));
228 $params{xml}->dataElement("ram:CategoryCode", $tax_info{code});
229 $params{xml}->dataElement("ram:RateApplicablePercent", _r2($tax_info{rate}));
230 $params{xml}->endTag;
231 # </ram:ApplicableTradeTax>
235 sub _calculate_payment_terms_values {
238 my (%vars, %amounts, %formatted_amounts);
240 local $::myconfig{numberformat} = $::myconfig{numberformat};
241 local $::myconfig{dateformat} = $::myconfig{dateformat};
243 if ($self->language_id) {
244 my $language = SL::DB::Language->load_cached($self->language_id);
245 $::myconfig{dateformat} = $language->output_dateformat if $language->output_dateformat;
246 $::myconfig{numberformat} = $language->output_numberformat if $language->output_numberformat;
249 $vars{currency} = $self->currency->name if $self->currency;
250 $vars{$_} = $self->customer->$_ for qw(account_number bank bank_code bic iban mandate_date_of_signature mandator_id);
251 $vars{$_} = $self->payment_terms->$_ for qw(terms_netto terms_skonto percent_skonto);
252 $vars{payment_description} = $self->payment_terms->description;
253 $vars{netto_date} = $self->payment_terms->calc_date(reference_date => $self->transdate, due_date => $self->duedate, terms => 'net')->to_kivitendo;
254 $vars{skonto_date} = $self->payment_terms->calc_date(reference_date => $self->transdate, due_date => $self->duedate, terms => 'discount')->to_kivitendo;
256 $amounts{invtotal} = $self->amount;
257 $amounts{total} = $self->amount - $self->paid;
259 $amounts{skonto_in_percent} = 100.0 * $vars{percent_skonto};
260 $amounts{skonto_amount} = $amounts{invtotal} * $vars{percent_skonto};
261 $amounts{invtotal_wo_skonto} = $amounts{invtotal} * (1 - $vars{percent_skonto});
262 $amounts{total_wo_skonto} = $amounts{total} * (1 - $vars{percent_skonto});
264 foreach (keys %amounts) {
265 $amounts{$_} = $::form->round_amount($amounts{$_}, 2);
266 $formatted_amounts{$_} = $::form->format_amount(\%::myconfig, $amounts{$_}, 2);
271 amounts => \%amounts,
272 formatted_amounts => \%formatted_amounts,
276 sub _format_payment_terms_description {
277 my ($self, %params) = @_;
279 my $description = ($self->payment_terms->translated_attribute('description_long_invoice', $self->language_id) // '') || $self->payment_terms->description_long_invoice;
280 $description =~ s{<\%$_\%>}{ $params{vars}->{$_} }ge for keys %{ $params{vars} };
281 $description =~ s{<\%$_\%>}{ $params{formatted_amounts}->{$_} }ge for keys %{ $params{formatted_amounts} };
287 my ($self, %params) = @_;
289 return unless $self->payment_terms;
291 my %payment_terms_vars = _calculate_payment_terms_values($self);
293 # <ram:SpecifiedTradePaymentTerms>
294 $params{xml}->startTag("ram:SpecifiedTradePaymentTerms");
296 $params{xml}->dataElement("ram:Description", _u8(_format_payment_terms_description($self, %payment_terms_vars)));
298 # <ram:DueDateDateTime>
299 $params{xml}->startTag("ram:DueDateDateTime");
300 $params{xml}->dataElement("udt:DateTimeString", $self->duedate->strftime('%Y%m%d'), format => "102");
301 $params{xml}->endTag;
302 # </ram:DueDateDateTime>
304 if ($self->payment_terms->percent_skonto && $self->payment_terms->terms_skonto) {
305 my $currency_id = _u8(SL::Helper::ISO4217::map_currency_name_to_code($self->currency->name) // 'EUR');
307 # <ram:ApplicableTradePaymentDiscountTerms>
308 $params{xml}->startTag("ram:ApplicableTradePaymentDiscountTerms");
309 $params{xml}->dataElement("ram:BasisPeriodMeasure", $self->payment_terms->terms_skonto, unitCode => "DAY");
310 $params{xml}->dataElement("ram:BasisAmount", _r2($payment_terms_vars{amounts}->{invtotal}), currencyID => $currency_id);
311 $params{xml}->dataElement("ram:CalculationPercent", _r2($self->payment_terms->percent_skonto * 100));
312 $params{xml}->endTag;
313 # </ram:ApplicableTradePaymentDiscountTerms>
316 $params{xml}->endTag;
317 # </ram:SpecifiedTradePaymentTerms>
321 my ($self, %params) = @_;
323 # <ram:SpecifiedTradeSettlementHeaderMonetarySummation>
324 $params{xml}->startTag("ram:SpecifiedTradeSettlementHeaderMonetarySummation");
326 $params{xml}->dataElement("ram:LineTotalAmount", _r2($self->netamount));
327 $params{xml}->dataElement("ram:TaxBasisTotalAmount", _r2($self->netamount));
328 $params{xml}->dataElement("ram:TaxTotalAmount", _r2(sum(values %{ $params{ptc_data}->{taxes_by_tax_id} })), currencyID => "EUR");
329 $params{xml}->dataElement("ram:GrandTotalAmount", _r2($self->amount));
330 $params{xml}->dataElement("ram:TotalPrepaidAmount", _r2($self->paid));
331 $params{xml}->dataElement("ram:DuePayableAmount", _r2($self->amount - $self->paid));
333 $params{xml}->endTag;
334 # </ram:SpecifiedTradeSettlementHeaderMonetarySummation>
337 sub _exchanged_document_context {
338 my ($self, %params) = @_;
340 # <rsm:ExchangedDocumentContext>
341 $params{xml}->startTag("rsm:ExchangedDocumentContext");
343 if ($self->customer->create_zugferd_invoices_for_this_customer == 2) {
344 $params{xml}->startTag("ram:TestIndicator");
345 $params{xml}->dataElement("udt:Indicator", "true");
346 $params{xml}->endTag;
349 $params{xml}->startTag("ram:GuidelineSpecifiedDocumentContextParameter");
350 $params{xml}->dataElement("ram:ID", "urn:cen.eu:en16931:2017#conformant#urn:zugferd.de:2p0:extended");
351 $params{xml}->endTag;
352 $params{xml}->endTag;
353 # </rsm:ExchangedDocumentContext>
357 my ($self, %params) = @_;
359 $params{xml}->startTag("ram:IncludedNote");
360 $params{xml}->dataElement("ram:Content", _u8($params{note}));
361 $params{xml}->endTag;
364 sub _exchanged_document {
365 my ($self, %params) = @_;
367 # <rsm:ExchangedDocument>
368 $params{xml}->startTag("rsm:ExchangedDocument");
370 $params{xml}->dataElement("ram:ID", _u8($self->invnumber));
371 $params{xml}->dataElement("ram:Name", _u8(_type_name($self)));
372 $params{xml}->dataElement("ram:TypeCode", _u8(_type_code($self)));
374 # <ram:IssueDateTime>
375 $params{xml}->startTag("ram:IssueDateTime");
376 $params{xml}->dataElement("udt:DateTimeString", $self->transdate->strftime('%Y%m%d'), format => "102");
377 $params{xml}->endTag;
378 # </ram:IssueDateTime>
380 if ($self->language && (($self->language->template_code // '') =~ m{^(de|en)}i)) {
381 $params{xml}->dataElement("ram:LanguageID", uc($1));
384 my $std_notes = SL::DB::Manager::GenericTranslation->get_all(
386 translation_type => 'ZUGFeRD/notes',
388 language_id => undef,
389 language_id => $self->language_id,
391 '!translation' => undef,
392 '!translation' => '',
396 my $std_note = first { $_->language_id == $self->language_id } @{ $std_notes };
397 $std_note //= first { !defined $_->language_id } @{ $std_notes };
399 my $notes = $self->notes_as_stripped_html;
401 _included_note($self, %params, note => $self->transaction_description) if $self->transaction_description;
402 _included_note($self, %params, note => $notes) if $notes;
403 _included_note($self, %params, note => $std_note->translation) if $std_note;
405 $params{xml}->endTag;
406 # </rsm:ExchangedDocument>
409 sub _specified_tax_registration {
410 my ($ustid_nr, %params) = @_;
412 # <ram:SpecifiedTaxRegistration>
413 $params{xml}->startTag("ram:SpecifiedTaxRegistration");
414 $params{xml}->dataElement("ram:ID", _u8(SL::VATIDNr->normalize($ustid_nr)), schemeID => "VA");
415 $params{xml}->endTag;
416 # </ram:SpecifiedTaxRegistration>
419 sub _seller_trade_party {
420 my ($self, %params) = @_;
422 my @our_address = _parse_our_address();
424 my $sales_person = $self->salesman;
425 my $sales_person_auth = SL::DB::Manager::AuthUser->find_by(login => $sales_person->login);
426 my %sales_person_cfg = $sales_person_auth ? %{ $sales_person_auth->config_values } : ();
427 $sales_person_cfg{email} ||= $sales_person->deleted_email;
428 $sales_person_cfg{tel} ||= $sales_person->deleted_tel;
430 # <ram:SellerTradeParty>
431 $params{xml}->startTag("ram:SellerTradeParty");
432 $params{xml}->dataElement("ram:ID", _u8($self->customer->c_vendor_id)) if ($self->customer->c_vendor_id // '') ne '';
433 $params{xml}->dataElement("ram:Name", _u8($::instance_conf->get_company));
435 # <ram:DefinedTradeContact>
436 $params{xml}->startTag("ram:DefinedTradeContact");
438 $params{xml}->dataElement("ram:PersonName", _u8($sales_person_cfg{name} || $sales_person_cfg{login}));
440 if ($sales_person_cfg{tel}) {
441 $params{xml}->startTag("ram:TelephoneUniversalCommunication");
442 $params{xml}->dataElement("ram:CompleteNumber", _u8($sales_person_cfg{tel}));
443 $params{xml}->endTag;
446 if ($sales_person_cfg{email}) {
447 $params{xml}->startTag("ram:EmailURIUniversalCommunication");
448 $params{xml}->dataElement("ram:URIID", _u8($sales_person_cfg{email}));
449 $params{xml}->endTag;
452 $params{xml}->endTag;
453 # </ram:DefinedTradeContact>
456 # <ram:PostalTradeAddress>
457 $params{xml}->startTag("ram:PostalTradeAddress");
458 foreach my $element (@our_address) {
459 $params{xml}->dataElement("ram:" . $element->[0], _u8($element->[1]));
461 $params{xml}->endTag;
462 # </ram:PostalTradeAddress>
465 _specified_tax_registration($::instance_conf->get_co_ustid, %params);
467 $params{xml}->endTag;
468 # </ram:SellerTradeParty>
471 sub _buyer_trade_party {
472 my ($self, %params) = @_;
474 # <ram:BuyerTradeParty>
475 $params{xml}->startTag("ram:BuyerTradeParty");
476 $params{xml}->dataElement("ram:ID", _u8($self->customer->customernumber));
477 $params{xml}->dataElement("ram:Name", _u8($self->customer->name));
479 _customer_postal_trade_address(%params, customer => $self->customer);
480 _specified_tax_registration($self->customer->ustid, %params);
482 $params{xml}->endTag;
483 # </ram:BuyerTradeParty>
486 sub _included_supply_chain_trade_line_item {
487 my ($self, %params) = @_;
490 foreach my $item (@{ $self->items }) {
491 _line_item($self, %params, item => $item, line_number => $line_number);
496 sub _applicable_header_trade_agreement {
497 my ($self, %params) = @_;
499 # <ram:ApplicableHeaderTradeAgreement>
500 $params{xml}->startTag("ram:ApplicableHeaderTradeAgreement");
502 _seller_trade_party($self, %params);
503 _buyer_trade_party($self, %params);
505 if ($self->cusordnumber) {
506 # <ram:BuyerOrderReferencedDocument>
507 $params{xml}->startTag("ram:BuyerOrderReferencedDocument");
508 $params{xml}->dataElement("ram:IssuerAssignedID", _u8($self->cusordnumber));
509 $params{xml}->endTag;
510 # </ram:BuyerOrderReferencedDocument>
513 $params{xml}->endTag;
514 # </ram:ApplicableHeaderTradeAgreement>
517 sub _applicable_header_trade_delivery {
518 my ($self, %params) = @_;
520 # <ram:ApplicableHeaderTradeDelivery>
521 $params{xml}->startTag("ram:ApplicableHeaderTradeDelivery");
522 # <ram:ActualDeliverySupplyChainEvent>
523 $params{xml}->startTag("ram:ActualDeliverySupplyChainEvent");
525 $params{xml}->startTag("ram:OccurrenceDateTime");
526 $params{xml}->dataElement("udt:DateTimeString", ($self->deliverydate // $self->transdate)->strftime('%Y%m%d'), format => "102");
527 $params{xml}->endTag;
529 $params{xml}->endTag;
530 # </ram:ActualDeliverySupplyChainEvent>
531 $params{xml}->endTag;
532 # </ram:ApplicableHeaderTradeDelivery>
535 sub _applicable_header_trade_settlement {
536 my ($self, %params) = @_;
538 # <ram:ApplicableHeaderTradeSettlement>
539 $params{xml}->startTag("ram:ApplicableHeaderTradeSettlement");
540 $params{xml}->dataElement("ram:InvoiceCurrencyCode", _u8(SL::Helper::ISO4217::map_currency_name_to_code($self->currency->name) // 'EUR'));
542 _specified_trade_settlement_payment_means($self, %params);
543 _taxes($self, %params);
544 _payment_terms($self, %params);
545 _totals($self, %params);
547 $params{xml}->endTag;
548 # </ram:ApplicableHeaderTradeSettlement>
551 sub _supply_chain_trade_transaction {
552 my ($self, %params) = @_;
554 # <rsm:SupplyChainTradeTransaction>
555 $params{xml}->startTag("rsm:SupplyChainTradeTransaction");
557 _included_supply_chain_trade_line_item($self, %params);
558 _applicable_header_trade_agreement($self, %params);
559 _applicable_header_trade_delivery($self, %params);
560 _applicable_header_trade_settlement($self, %params);
562 $params{xml}->endTag;
563 # </rsm:SupplyChainTradeTransaction>
570 my $prefix = $::locale->text('The ZUGFeRD invoice data cannot be generated because the data validation failed.') . ' ';
572 if (!$::instance_conf->get_co_ustid) {
573 SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text('The VAT registration number is missing in the client configuration.'));
576 if (!SL::VATIDNr->validate($::instance_conf->get_co_ustid)) {
577 SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text("The VAT ID number in the client configuration is invalid."));
580 if (!$::instance_conf->get_company || any { my $get = "get_address_$_"; !$::instance_conf->$get } qw(street1 zipcode city)) {
581 SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text('The company\'s address information is incomplete in the client configuration.'));
584 if ($::instance_conf->get_address_country && !SL::Helper::ISO3166::map_name_to_alpha_2_code($::instance_conf->get_address_country)) {
585 SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text('The country from the company\'s address in the client configuration cannot be mapped to an ISO 3166-1 alpha 2 code.'));
588 if ($self->customer->country && !SL::Helper::ISO3166::map_name_to_alpha_2_code($self->customer->country)) {
589 SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text('The country from the customer\'s address cannot be mapped to an ISO 3166-1 alpha 2 code.'));
592 if (!SL::Helper::ISO4217::map_currency_name_to_code($self->currency->name)) {
593 SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text('The currency "#1" cannot be mapped to an ISO 4217 currency code.', $self->currency->name));
596 my $failed_unit = first { !SL::Helper::UNECERecommendation20::map_name_to_code($_) } map { $_->unit } @{ $self->items };
598 SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text('One of the units used (#1) cannot be mapped to a known unit code from the UN/ECE Recommendation 20 list.', $failed_unit));
601 if ($self->direct_debit) {
602 if (!$self->customer->iban) {
603 SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text('The customer\'s bank account number (IBAN) is missing.'));
607 my $bank_accounts = SL::DB::Manager::BankAccount->get_all;
608 $result{bank_account} = scalar(@{ $bank_accounts }) == 1 ? $bank_accounts->[0] : first { $_->use_for_zugferd } @{ $bank_accounts };
610 if (!$result{bank_account}) {
611 SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text('No bank account flagged for ZUGFeRD usage was found.'));
618 sub create_zugferd_data {
623 my %params = _validate_data($self);
624 $params{ptc_data} = { $self->calculate_prices_and_taxes };
625 $params{xml} = XML::Writer->new(
632 $params{xml}->xmlDecl();
634 # <rsm:CrossIndustryInvoice>
635 $params{xml}->startTag("rsm:CrossIndustryInvoice",
636 "xmlns:a" => "urn:un:unece:uncefact:data:standard:QualifiedDataType:100",
637 "xmlns:rsm" => "urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100",
638 "xmlns:qdt" => "urn:un:unece:uncefact:data:standard:QualifiedDataType:10",
639 "xmlns:ram" => "urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100",
640 "xmlns:xs" => "http://www.w3.org/2001/XMLSchema",
641 "xmlns:udt" => "urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100");
643 _exchanged_document_context($self, %params);
644 _exchanged_document($self, %params);
645 _supply_chain_trade_transaction($self, %params);
647 $params{xml}->endTag;
648 # </rsm:CrossIndustryInvoice>
653 sub create_zugferd_xmp_data {
657 conformance_level => 'EXTENDED',
658 document_file_name => 'ZUGFeRD-invoice.xml',
659 document_type => 'INVOICE',