X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FBackgroundJob%2FCreatePeriodicInvoices.pm;h=dc7fd79e371f304c39ac7af0e34055734af6625e;hb=cf889668782d1ffbb76b9f28e1d36848544fa3b3;hp=226883cc31254795901b76e5b3e10a8df8622c55;hpb=47d35d063516eaa1a058109cf46cf2eb25c852a2;p=kivitendo-erp.git diff --git a/SL/BackgroundJob/CreatePeriodicInvoices.pm b/SL/BackgroundJob/CreatePeriodicInvoices.pm index 226883cc3..dc7fd79e3 100644 --- a/SL/BackgroundJob/CreatePeriodicInvoices.pm +++ b/SL/BackgroundJob/CreatePeriodicInvoices.pm @@ -50,15 +50,15 @@ sub run { _log_msg("Invoice " . $invoice->invnumber . " posted for config ID " . $config->id . ", period start date " . $::locale->format_date(\%::myconfig, $date) . "\n"); push @new_invoices, $invoice; - push @invoices_to_print, $invoice if $config->print; + push @invoices_to_print, [ $invoice, $config ] if $config->print; # last; } } - map { _print_invoice($_) } @invoices_to_print; + map { _print_invoice(@{ $_ }) } @invoices_to_print; - _send_email(\@new_invoices, \@invoices_to_print) if @new_invoices; + _send_email(\@new_invoices, [ map { $_->[0] } @invoices_to_print ]) if @new_invoices; return 1; } @@ -219,6 +219,31 @@ sub _send_email { $mail->send; } +sub _print_invoice { + my ($invoice, $config) = @_; + + return unless $config->print && $config->printer_id && $config->printer->printer_command; + + my $form = Form->new; + $invoice->flatten_to_form($form, format_amounts => 1); + + $form->{printer_code} = $config->printer->template_code; + $form->{copies} = $config->copies; + $form->{formname} = $form->{type}; + $form->{format} = 'pdf'; + $form->{media} = 'printer'; + $form->{OUT} = "| " . $config->printer->printer_command; + + $form->prepare_for_printing; + + $form->throw_on_error(sub { + eval { + $form->parse_template(\%::myconfig, $::userspath); + 1; + } || die $EVAL_ERROR->{error}; + }); +} + 1; __END__ @@ -247,10 +272,6 @@ each date. Strings like month names are hardcoded to German in this file. -=item * - -Implement printing the invoices if requested. - =back =head1 AUTHOR