+ if (!$::instance_conf->get_co_ustid) {
+ SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text('The VAT registration number is missing in the client configuration.'));
+ }
+
+ if (!SL::VATIDNr->validate($::instance_conf->get_co_ustid)) {
+ SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text("The VAT ID number in the client configuration is invalid."));
+ }
+
+ if (!$::instance_conf->get_company || any { my $get = "get_address_$_"; !$::instance_conf->$get } qw(street1 zipcode city)) {
+ SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text('The company\'s address information is incomplete in the client configuration.'));
+ }
+
+ if ($::instance_conf->get_address_country && !SL::Helper::ISO3166::map_name_to_alpha_2_code($::instance_conf->get_address_country)) {
+ 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.'));
+ }
+
+ if ($self->customer->country && !SL::Helper::ISO3166::map_name_to_alpha_2_code($self->customer->country)) {
+ 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.'));
+ }
+
+ if (!SL::Helper::ISO4217::map_currency_name_to_code($self->currency->name)) {
+ SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text('The currency "#1" cannot be mapped to an ISO 4217 currency code.', $self->currency->name));
+ }
+
+ my $failed_unit = first { !SL::Helper::UNECERecommendation20::map_name_to_code($_) } map { $_->unit } @{ $self->items };
+ if ($failed_unit) {
+ 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));
+ }
+
+ if ($self->direct_debit) {
+ if (!$self->customer->iban) {
+ SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text('The customer\'s bank account number (IBAN) is missing.'));
+ }
+
+ } else {
+ my $bank_accounts = SL::DB::Manager::BankAccount->get_all;
+ $result{bank_account} = scalar(@{ $bank_accounts }) == 1 ? $bank_accounts->[0] : first { $_->use_for_zugferd } @{ $bank_accounts };
+
+ if (!$result{bank_account}) {
+ SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text('No bank account flagged for Factur-X/ZUGFeRD usage was found.'));
+ }
+ }
+
+ if (_is_profile($self, PROFILE_XRECHNUNG())) {
+ if (!$self->customer->c_vendor_routing_id) {
+ SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text('The value \'our routing id at customer\' must be set in the customer\'s master data for profile #1.', 'XRechnung 2.0'));
+ }
+ }
+
+ return %result;
+}
+
+sub create_zugferd_data {
+ my ($self) = @_;
+ $self->{_zugferd} = { SL::ZUGFeRD->convert_customer_setting($self->customer->create_zugferd_invoices_for_this_customer) };
+
+ if (!$standards_ids{ $self->{_zugferd}->{profile} }) {
+ croak "Profile '" . $self->{_zugferd}->{profile} . "' is not supported";
+ }
+
+ my $output = '';
+
+ my %params = _validate_data($self);
+ $params{ptc_data} = { $self->calculate_prices_and_taxes };
+ $params{xml} = XML::Writer->new(
+ OUTPUT => \$output,
+ DATA_MODE => 1,
+ DATA_INDENT => 2,
+ ENCODING => 'utf-8',