From 34d546758e9a076149bb1499a5449747fcf17aea Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 3 Mar 2020 13:58:50 +0100 Subject: [PATCH] ZUGFeRD: Zahlungsbedingungen: Skonto-Basis-Betrag mit ausgeben --- SL/DB/Helper/ZUGFeRD.pm | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/SL/DB/Helper/ZUGFeRD.pm b/SL/DB/Helper/ZUGFeRD.pm index 826cef1a9..3770b7e4b 100644 --- a/SL/DB/Helper/ZUGFeRD.pm +++ b/SL/DB/Helper/ZUGFeRD.pm @@ -209,7 +209,7 @@ sub _taxes { } } -sub _format_payment_terms_description { +sub _calculate_payment_terms_values { my ($self) = @_; my (%vars, %amounts, %formatted_amounts); @@ -243,9 +243,19 @@ sub _format_payment_terms_description { $formatted_amounts{$_} = $::form->format_amount(\%::myconfig, $amounts{$_}, 2); } + return ( + vars => \%vars, + amounts => \%amounts, + formatted_amounts => \%formatted_amounts, + ); +} + +sub _format_payment_terms_description { + my ($self, %params) = @_; + my $description = ($self->payment_terms->translated_attribute('description_long_invoice', $self->language_id) // '') || $self->payment_terms->description_long_invoice; - $description =~ s{<\%$_\%>}{ $vars{$_} }ge for keys %vars; - $description =~ s{<\%$_\%>}{ $formatted_amounts{$_} }ge for keys %formatted_amounts; + $description =~ s{<\%$_\%>}{ $params{vars}->{$_} }ge for keys %{ $params{vars} }; + $description =~ s{<\%$_\%>}{ $params{formatted_amounts}->{$_} }ge for keys %{ $params{formatted_amounts} }; return $description; } @@ -255,10 +265,12 @@ sub _payment_terms { return unless $self->payment_terms; + my %payment_terms_vars = _calculate_payment_terms_values($self); + # $params{xml}->startTag("ram:SpecifiedTradePaymentTerms"); - $params{xml}->dataElement("ram:Description", _u8(_format_payment_terms_description($self))); + $params{xml}->dataElement("ram:Description", _u8(_format_payment_terms_description($self, %payment_terms_vars))); # $params{xml}->startTag("ram:DueDateDateTime"); @@ -267,9 +279,12 @@ sub _payment_terms { # if ($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'); + # $params{xml}->startTag("ram:ApplicableTradePaymentDiscountTerms"); $params{xml}->dataElement("ram:BasisPeriodMeasure", $self->payment_terms->terms_skonto, "unitCode" => "DAY"); + $params{xml}->dataElement("ram:BasisAmount", _r2($payment_terms_vars{amounts}->{invtotal}), currencyID => $currency_id); $params{xml}->dataElement("ram:CalculationPercent", _r2($self->payment_terms->percent_skonto * 100)); $params{xml}->endTag; # -- 2.20.1