Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 333003d3

Von Moritz Bunkus vor fast 5 Jahren hinzugefügt

  • ID 333003d332756c5f53a33720aea7b714dfd335c8
  • Vorgänger e5f53eb5
  • Nachfolger dc78c225

ZUGFeRD: Validierung diverser nötiger Parameter

Unterschiede anzeigen:

SL/DB/Helper/ZUGFeRD.pm
15 15

  
16 16
use Carp;
17 17
use Encode qw(encode);
18
use List::MoreUtils qw(pairwise);
18
use List::MoreUtils qw(any pairwise);
19 19
use List::Util qw(first sum);
20 20
use Template;
21 21
use XML::Writer;
......
515 515
  #   </rsm:SupplyChainTradeTransaction>
516 516
}
517 517

  
518
sub _validate_data {
519
  my ($self) = @_;
520

  
521
  my $prefix = $::locale->text('The ZUGFeRD invoice data cannot be generated because the data validation failed.') . ' ';
522

  
523
  if (!$::instance_conf->get_co_ustid) {
524
    SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text('The VAT registration number is missing in the client configuration.'));
525
  }
526

  
527
  if (!$::instance_conf->get_company || any { my $get = "get_address_$_"; !$::instance_conf->$get } qw(street1 zipcode city)) {
528
    SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text('The company\'s address information is incomplete in the client configuration.'));
529
  }
530

  
531
  if ($::instance_conf->get_address_country && !SL::Helper::ISO3166::map_name_to_alpha_2_code($::instance_conf->get_address_country)) {
532
    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.'));
533
  }
534

  
535
  if ($self->customer->country && !SL::Helper::ISO3166::map_name_to_alpha_2_code($self->customer->country)) {
536
    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.'));
537
  }
538

  
539
  if (!SL::Helper::ISO4217::map_currency_name_to_code($self->currency->name)) {
540
    SL::X::ZUGFeRDValidation->throw(message => $prefix . $::locale->text('The currency "#1" cannot be mapped to an ISO 4217 currency code.', $self->currency->name));
541
  }
542

  
543
  my $failed_unit = first { !SL::Helper::UNECERecommendation20::map_name_to_code($_) } map { $_->unit } @{ $self->items };
544
  if ($failed_unit) {
545
    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));
546
  }
547
}
548

  
518 549
sub create_zugferd_data {
519 550
  my ($self) = @_;
520 551

  
552
  _validate_data($self);
553

  
521 554
  my %ptc_data = $self->calculate_prices_and_taxes;
522 555
  my $output   = '';
523 556
  my $xml      = XML::Writer->new(

Auch abrufbar als: Unified diff