Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 7afe92af

Von Moritz Bunkus vor mehr als 8 Jahren hinzugefügt

  • ID 7afe92aff55c96742fbffb54e382f17f9fe4d907
  • Vorgänger b61d4f49
  • Nachfolger 611491d9

Brieffunktion: Umstellung Druck auf Template Toolkit

Damit wird auch alter Backendcode wie IS->get_customer() nicht mehr
benötigt.

Unterschiede anzeigen:

SL/Controller/Letter.pm
178 178
  my $display_form = $::form->{display_form} || "display_form";
179 179
  my $letter       = $self->_update;
180 180

  
181
  $self->export_letter_to_form($letter);
182
  $::form->{formname} = "letter";
183
  $::form->{type}     = "letter";
184
  $::form->{format}   = "pdf";
185

  
186
  my $language_saved      = $::form->{language_id};
187
  my $greeting_saved      = $::form->{greeting};
188
  my $cp_id_saved         = $::form->{cp_id};
189

  
190
  $::form->{customer_id} = $self->letter->customer_id;
191
  IS->customer_details(\%::myconfig, $::form);
192

  
193
  if (!$cp_id_saved) {
194
    # No contact was selected. Delete all contact variables because
195
    # IS->customer_details() and IR->vendor_details() get the default
196
    # contact anyway.
197
    map({ delete($::form->{$_}); } grep(/^cp_/, keys(%{ $::form })));
198
  }
199

  
200
  $::form->{greeting} = $greeting_saved;
201
  $::form->{language_id} = $language_saved;
202

  
203
  if ($::form->{cp_id}) {
204
    CT->get_contact(\%::myconfig, $::form);
205
  }
206

  
207
  $::form->{cp_contact_formal} = ($::form->{cp_greeting} ? "$::form->{cp_greeting} " : '') . ($::form->{cp_givenname} ? "$::form->{cp_givenname} " : '') . $::form->{cp_name};
208

  
209
  $::form->get_employee_data('prefix' => 'employee', 'id' => $letter->{employee_id});
210
  $::form->get_employee_data('prefix' => 'salesman', 'id' => $letter->{salesman_id});
211

  
212 181
  my ($template_file, @template_files) = SL::Helper::CreatePDF->find_template(
213 182
    name        => 'letter',
214 183
    printer_id  => $::form->{printer_id},
......
221 190
    $::form->error($::locale->text('Cannot find matching template for this print request. Please contact your template maintainer. I tried these: #1.', join ', ', map { "'$_'"} @template_files));
222 191
  }
223 192

  
224
  my %create_params = (
225
    template  => $template_file,
226
    variables => $::form,
227
    return    => 'file_name',
228
    variable_content_types => {
229
      body                 => 'html',
230
    },
231
  );
232

  
233
  my $pdf_file_name;
193
  my %result;
234 194
  eval {
235
    $pdf_file_name          = SL::Helper::CreatePDF->create_pdf(%create_params);
195
    %result = SL::Template::LaTeX->parse_and_create_pdf(
196
      $template_file,
197
      SELF          => $self,
198
      FORM          => $::form,
199
      letter        => $letter,
200
      template_meta => {
201
        formname  => 'letter',
202
        language  => SL::DB::Language->new,
203
        extension => 'pdf',
204
        format    => $::form->{format},
205
        media     => $::form->{media},
206
        printer   => SL::DB::Manager::Printer->find_by_or_create(id => $::form->{printer_id} || undef),
207
        today     => DateTime->today,
208
      },
209
    );
210

  
211
    die $result{error} if $result{error};
236 212

  
237
    $::form->{letternumber} = $self->letter->letternumber;
213
    $::form->{type}         = 'letter';
214
    $::form->{formname}     = 'letter';
215
    $::form->{letternumber} = $letter->letternumber;
238 216
    my $attachment_name     = $::form->generate_attachment_filename;
239 217

  
240 218
    if ($::instance_conf->get_webdav_documents) {
......
242 220
        filename => $attachment_name,
243 221
        webdav   => SL::Webdav->new(
244 222
          type   => 'letter',
245
          number => $self->letter->letternumber,
223
          number => $letter->letternumber,
246 224
        ),
247 225
      );
248 226

  
249
      $webdav_file->store(file => $pdf_file_name);
227
      $webdav_file->store(file => $result{file_name});
250 228
    }
251 229

  
252 230
    # set some form defaults for printing webdav copy variables
......
255 233
      my $signature        = $::myconfig{signature};
256 234
      $mail->{$_}          = $params{email}->{$_} for qw(to cc subject message bcc);
257 235
      $mail->{from}        = qq|"$::myconfig{name}" <$::myconfig{email}>|;
258
      $mail->{attachments} = [{ filename => $pdf_file_name,
236
      $mail->{attachments} = [{ filename => $result{file_name},
259 237
                                name     => $params{email}->{attachment_filename} }];
260 238
      $mail->{message}    .=  "\n-- \n$signature";
261 239
      $mail->{message}     =~ s/\r//g;
262 240

  
263 241
      $mail->send;
264
      unlink $pdf_file_name;
242
      unlink $result{file_name};
265 243

  
266 244
      flash_later('info', t8('The email has been sent.'));
267
      $self->redirect_to(action => 'edit', 'letter.id' => $self->letter->id);
245
      $self->redirect_to(action => 'edit', 'letter.id' => $letter->id);
268 246

  
269 247
      return 1;
270 248
    }
271 249

  
272 250
    if (!$::form->{printer_id} || $::form->{media} eq 'screen') {
273
      $self->send_file($pdf_file_name, name => $attachment_name);
274
      unlink $pdf_file_name;
251
      $self->send_file($result{file_name}, name => $attachment_name);
252
      unlink $result{file_name};
275 253

  
276 254
      return 1;
277 255
    }
......
279 257
    my $printer = SL::DB::Printer->new(id => $::form->{printer_id})->load;
280 258
    $printer->print_document(
281 259
      copies    => $::form->{copies},
282
      file_name => $pdf_file_name,
260
      file_name => $result{file_name},
283 261
    );
284 262

  
285
    unlink $pdf_file_name;
263
    unlink $result{file_name};
286 264

  
287 265
    flash_later('info', t8('The documents have been sent to the printer \'#1\'.', $printer->printer_description));
288
    $self->redirect_to(action => 'edit', 'letter.id' => $self->letter->id, media => 'printer', printer_id => $::form->{printer_id});
266
    $self->redirect_to(action => 'edit', 'letter.id' => $letter->id, media => 'printer', printer_id => $::form->{printer_id});
289 267
    1;
290 268
  } or do {
291
    unlink $pdf_file_name if $pdf_file_name;
269
    unlink $result{file_name} if $result{file_name};
292 270
    $::form->error(t8("Creating the PDF failed:") . " " . $@);
293 271
  };
294 272
}

Auch abrufbar als: Unified diff