From 8abdaf4026ee63628e524146ded609df44fc92af Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 5 Feb 2015 10:54:40 +0100 Subject: [PATCH] =?utf8?q?CreatePeriodicInvoices:=20HTML-Formatierung=20in?= =?utf8?q?=20Langtexten=20ber=C3=BCcksichtigen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Beim Ersetzen der Variablen muss das Format des Textes (HTML oder normaler Text) berücksichtigt werden, damit Formatierungen richtig angewandt und die Platzhalter überhaupt erst gefunden werden. Behebt Redmine #32. --- SL/BackgroundJob/CreatePeriodicInvoices.pm | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/SL/BackgroundJob/CreatePeriodicInvoices.pm b/SL/BackgroundJob/CreatePeriodicInvoices.pm index 6624d6a3e..ce8957770 100644 --- a/SL/BackgroundJob/CreatePeriodicInvoices.pm +++ b/SL/BackgroundJob/CreatePeriodicInvoices.pm @@ -108,22 +108,35 @@ sub _replace_vars { my (%params) = @_; my $sub = $params{attribute}; my $str = $params{object}->$sub; + my $sub_fmt = lc($params{attribute_format} // 'text'); - $str =~ s{ <\% ([a-z0-9_]+) ( \s+ format \s*=\s* (.*?) \s* )? \%>}{ + my ($start_tag, $end_tag) = $sub_fmt eq 'html' ? ('<%', '%>') : ('<%', '%>'); + + $str =~ s{ ${start_tag} ([a-z0-9_]+) ( \s+ format \s*=\s* (.*?) \s* )? ${end_tag} }{ my ($key, $format) = ($1, $3); + $key = $::locale->unquote_special_chars('html', $key) if $sub_fmt eq 'html'; + my $new_value; + if (!$params{vars}->{$key}) { - ''; + $new_value = ''; } elsif ($format) { - DateTime::Format::Strptime->new( + $format = $::locale->unquote_special_chars('html', $format) if $sub_fmt eq 'html'; + + $new_value = DateTime::Format::Strptime->new( pattern => $format, locale => 'de_DE', time_zone => 'local', )->format_datetime($params{vars}->{$key}->[0]); } else { - $params{vars}->{$1}->[1]->($params{vars}->{$1}->[0]); + $new_value = $params{vars}->{$1}->[1]->($params{vars}->{$1}->[0]); } + + $new_value = $::locale->quote_special_chars('html', $new_value) if $sub_fmt eq 'html'; + + $new_value; + }eigx; $params{object}->$sub($str); @@ -156,7 +169,7 @@ sub _create_periodic_invoice { _replace_vars(object => $invoice, vars => $time_period_vars, attribute => $_) for qw(notes intnotes transaction_description); foreach my $item (@{ $invoice->items }) { - _replace_vars(object => $item, vars => $time_period_vars, attribute => $_) for qw(description longdescription); + _replace_vars(object => $item, vars => $time_period_vars, attribute => $_, attribute_format => ($_ eq 'longdescription' ? 'html' : 'text')) for qw(description longdescription); } $invoice->post(ar_id => $config->ar_chart_id) || die; -- 2.20.1