Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 8abdaf40

Von Moritz Bunkus vor etwa 9 Jahren hinzugefügt

  • ID 8abdaf4026ee63628e524146ded609df44fc92af
  • Vorgänger 111861a5
  • Nachfolger df193cf0

CreatePeriodicInvoices: HTML-Formatierung in Langtexten berücksichtigen

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.

Unterschiede anzeigen:

SL/BackgroundJob/CreatePeriodicInvoices.pm
108 108
  my (%params) = @_;
109 109
  my $sub      = $params{attribute};
110 110
  my $str      = $params{object}->$sub;
111
  my $sub_fmt  = lc($params{attribute_format} // 'text');
111 112

  
112
  $str =~ s{ <\% ([a-z0-9_]+) ( \s+ format \s*=\s* (.*?) \s* )? \%>}{
113
  my ($start_tag, $end_tag) = $sub_fmt eq 'html' ? ('&lt;%', '%&gt;') : ('<%', '%>');
114

  
115
  $str =~ s{ ${start_tag} ([a-z0-9_]+) ( \s+ format \s*=\s* (.*?) \s* )? ${end_tag} }{
113 116
    my ($key, $format) = ($1, $3);
117
    $key               = $::locale->unquote_special_chars('html', $key) if $sub_fmt eq 'html';
118
    my $new_value;
119

  
114 120
    if (!$params{vars}->{$key}) {
115
      '';
121
      $new_value = '';
116 122

  
117 123
    } elsif ($format) {
118
      DateTime::Format::Strptime->new(
124
      $format    = $::locale->unquote_special_chars('html', $format) if $sub_fmt eq 'html';
125

  
126
      $new_value = DateTime::Format::Strptime->new(
119 127
        pattern     => $format,
120 128
        locale      => 'de_DE',
121 129
        time_zone   => 'local',
122 130
      )->format_datetime($params{vars}->{$key}->[0]);
123 131

  
124 132
    } else {
125
      $params{vars}->{$1}->[1]->($params{vars}->{$1}->[0]);
133
      $new_value = $params{vars}->{$1}->[1]->($params{vars}->{$1}->[0]);
126 134
    }
135

  
136
    $new_value = $::locale->quote_special_chars('html', $new_value) if $sub_fmt eq 'html';
137

  
138
    $new_value;
139

  
127 140
  }eigx;
128 141

  
129 142
  $params{object}->$sub($str);
......
156 169
    _replace_vars(object => $invoice, vars => $time_period_vars, attribute => $_) for qw(notes intnotes transaction_description);
157 170

  
158 171
    foreach my $item (@{ $invoice->items }) {
159
      _replace_vars(object => $item, vars => $time_period_vars, attribute => $_) for qw(description longdescription);
172
      _replace_vars(object => $item, vars => $time_period_vars, attribute => $_, attribute_format => ($_ eq 'longdescription' ? 'html' : 'text')) for qw(description longdescription);
160 173
    }
161 174

  
162 175
    $invoice->post(ar_id => $config->ar_chart_id) || die;

Auch abrufbar als: Unified diff