From e2f0105f947c01d3d45be41833f3a7e39eef2f7b Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 26 Nov 2020 15:44:00 +0100 Subject: [PATCH] =?utf8?q?Factur-X/ZUGFeRD:=20Unterst=C3=BCtztung=20f?= =?utf8?q?=C3=BCr=20Profil=20=C2=BBXRechnung=202.0.0=C2=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DB/Helper/ZUGFeRD.pm | 32 +++++++++++++++++++++++++++++--- SL/ZUGFeRD.pm | 5 ++++- locale/de/all | 3 +++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/SL/DB/Helper/ZUGFeRD.pm b/SL/DB/Helper/ZUGFeRD.pm index 017bbc535..f989d3d94 100644 --- a/SL/DB/Helper/ZUGFeRD.pm +++ b/SL/DB/Helper/ZUGFeRD.pm @@ -27,6 +27,9 @@ my @line_names = qw(LineOne LineTwo LineThree); my %standards_ids = ( PROFILE_FACTURX_EXTENDED() => 'urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended', + PROFILE_XRECHNUNG() => 'urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.0', +); + sub _is_profile { my ($self, @profiles) = @_; return any { $self->{_zugferd}->{profile} == $_ } @profiles; @@ -288,6 +291,17 @@ sub _format_payment_terms_description { $description =~ s{<\%$_\%>}{ $params{vars}->{$_} }ge for keys %{ $params{vars} }; $description =~ s{<\%$_\%>}{ $params{formatted_amounts}->{$_} }ge for keys %{ $params{formatted_amounts} }; + if (_is_profile($self, PROFILE_XRECHNUNG())) { + my @terms; + + if ($self->payment_terms->terms_skonto && ($self->payment_terms->percent_skonto * 1)) { + push @terms, sprintf("#SKONTO#TAGE=\%d#PROZENT=\%.2f#\n", $self->payment_terms->terms_skonto, $self->payment_terms->percent_skonto * 100); + } + + $description =~ s{#}{_}g; + $description = join('', @terms) . $description; + } + return $description; } @@ -309,7 +323,9 @@ sub _payment_terms { $params{xml}->endTag; # - if ($self->payment_terms->percent_skonto && $self->payment_terms->terms_skonto) { + if ( _is_profile($self, PROFILE_FACTURX_EXTENDED()) + && $self->payment_terms->percent_skonto + && $self->payment_terms->terms_skonto) { my $currency_id = _u8(SL::Helper::ISO4217::map_currency_name_to_code($self->currency->name) // 'EUR'); # @@ -376,7 +392,7 @@ sub _exchanged_document { $params{xml}->startTag("rsm:ExchangedDocument"); $params{xml}->dataElement("ram:ID", _u8($self->invnumber)); - $params{xml}->dataElement("ram:Name", _u8(_type_name($self))); + $params{xml}->dataElement("ram:Name", _u8(_type_name($self))) if _is_profile($self, PROFILE_FACTURX_EXTENDED()); $params{xml}->dataElement("ram:TypeCode", _u8(_type_code($self))); # @@ -385,7 +401,9 @@ sub _exchanged_document { $params{xml}->endTag; # - if ($self->language && (($self->language->template_code // '') =~ m{^(de|en)}i)) { + if ( _is_profile($self, PROFILE_FACTURX_EXTENDED()) + && $self->language + && (($self->language->template_code // '') =~ m{^(de|en)}i)) { $params{xml}->dataElement("ram:LanguageID", uc($1)); } @@ -507,6 +525,8 @@ sub _applicable_header_trade_agreement { # $params{xml}->startTag("ram:ApplicableHeaderTradeAgreement"); + $params{xml}->dataElement("ram:BuyerReference", _u8($self->customer->c_vendor_routing_id)) if $self->customer->c_vendor_routing_id; + _seller_trade_party($self, %params); _buyer_trade_party($self, %params); @@ -620,6 +640,12 @@ sub _validate_data { } } + 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; } diff --git a/SL/ZUGFeRD.pm b/SL/ZUGFeRD.pm index 02d73de30..38d762311 100644 --- a/SL/ZUGFeRD.pm +++ b/SL/ZUGFeRD.pm @@ -12,11 +12,12 @@ use XML::LibXML; use SL::Locale::String qw(t8); use parent qw(Exporter); -our @EXPORT_PROFILES = qw(PROFILE_FACTURX_EXTENDED); +our @EXPORT_PROFILES = qw(PROFILE_FACTURX_EXTENDED PROFILE_XRECHNUNG); our @EXPORT_OK = (@EXPORT_PROFILES); our %EXPORT_TAGS = (PROFILES => \@EXPORT_PROFILES); use constant PROFILE_FACTURX_EXTENDED => 0; +use constant PROFILE_XRECHNUNG => 1; use constant RES_OK => 0; use constant RES_ERR_FILE_OPEN => 1; @@ -29,6 +30,8 @@ our @customer_settings = ( [ 0, t8('Do not create Factur-X/ZUGFeRD invoices') ], [ PROFILE_FACTURX_EXTENDED() * 2 + 1, t8('Create with profile \'Factur-X 1.0.05/ZUGFeRD 2.1.1 extended\'') ], [ PROFILE_FACTURX_EXTENDED() * 2 + 2, t8('Create with profile \'Factur-X 1.0.05/ZUGFeRD 2.1.1 extended\' (test mode)') ], + [ PROFILE_XRECHNUNG() * 2 + 1, t8('Create with profile \'XRechnung 2.0.0\'') ], + [ PROFILE_XRECHNUNG() * 2 + 2, t8('Create with profile \'XRechnung 2.0.0\' (test mode)') ], ); sub convert_customer_setting { diff --git a/locale/de/all b/locale/de/all index 922117213..19609099d 100755 --- a/locale/de/all +++ b/locale/de/all @@ -779,6 +779,8 @@ $self->{texts} = { 'Create tables' => 'Tabellen anlegen', 'Create with profile \'Factur-X 1.0.05/ZUGFeRD 2.1.1 extended\'' => 'Mit Profil »Factur-X 1.0.05/ZUGFeRD 2.1.1 extended«', 'Create with profile \'Factur-X 1.0.05/ZUGFeRD 2.1.1 extended\' (test mode)' => 'Mit Profil »Factur-X 1.0.05/ZUGFeRD 2.1.1 extended« (Test-Modus)', + 'Create with profile \'XRechnung 2.0.0\'' => 'Mit Profil »XRechnung 2.0.0«', + 'Create with profile \'XRechnung 2.0.0\' (test mode)' => 'Mit Profil »XRechnung 2.0.0« (Test-Modus)', 'Created by' => 'Erstellt von', 'Created for' => 'Erstellt für', 'Created on' => 'Erstellt am', @@ -3556,6 +3558,7 @@ $self->{texts} = { 'The user has been deleted.' => 'Der Benutzer wurde gelöscht.', 'The user has been saved.' => 'Der Benutzer wurde gespeichert.', 'The value \'#1\' is not a valid IBAN.' => 'Der Wert \'#1\' ist keine gültige IBAN.', + 'The value \'our routing id at customer\' must be set in the customer\'s master data for profile #1.' => 'Der Wert »unsere Leitweg-ID beim Kunden« muss in den Kundenstammdaten gesetzt sein für Profil #1.', 'The variable name must only consist of letters, numbers and underscores. It must begin with a letter. Example: send_christmas_present' => 'Der Variablenname darf nur aus Zeichen (keine Umlaute), Ziffern und Unterstrichen bestehen. Er muss mit einem Buchstaben beginnen. Beispiel: weihnachtsgruss_verschicken', 'The vendor name is missing.' => 'Der Liefeantenname fehlt.', 'The version number is missing.' => 'Die Versionsnummer fehlt.', -- 2.20.1