X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FBackgroundJob%2FCreatePeriodicInvoices.pm;h=ce8957770e95cdc5b7e0c35a3d0c54d3fd1b3b3d;hb=a99ac2d9b3621c82b7aeddf85e9640442c42433c;hp=1abe8c36b2e28c243843e2ae41ef4ac8776e899f;hpb=5142ae5c5b94f8d1c7784b1ec97c870d086da21e;p=kivitendo-erp.git diff --git a/SL/BackgroundJob/CreatePeriodicInvoices.pm b/SL/BackgroundJob/CreatePeriodicInvoices.pm index 1abe8c36b..ce8957770 100644 --- a/SL/BackgroundJob/CreatePeriodicInvoices.pm +++ b/SL/BackgroundJob/CreatePeriodicInvoices.pm @@ -105,29 +105,41 @@ sub _generate_time_period_variables { } sub _replace_vars { - my $object = shift; - my $vars = shift; - my $sub = shift; - my $str = $object->$sub; + 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); - if (!$vars->{$key}) { - ''; + $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($vars->{$key}->[0]); + )->format_datetime($params{vars}->{$key}->[0]); } else { - $vars->{$1}->[1]->($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; - $object->$sub($str); + $params{object}->$sub($str); } sub _create_periodic_invoice { @@ -154,10 +166,10 @@ sub _create_periodic_invoice { employee => $order->employee, # new_from sets employee to import user ); - _replace_vars($invoice, $time_period_vars, $_) for qw(notes intnotes transaction_description); + _replace_vars(object => $invoice, vars => $time_period_vars, attribute => $_) for qw(notes intnotes transaction_description); foreach my $item (@{ $invoice->items }) { - _replace_vars($item, $time_period_vars, $_) 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;