X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FMassInvoiceCreatePrint.pm;h=ef5bfaf7404431bc75e25eea4a01074379ff93f8;hb=9c19433144efc5b50d90a969aa9ac6ea65b2dbbf;hp=7fc3388e7530d7117668279498376de99ec34210;hpb=0878ce8165e72571703d06999a9972be4c5adb92;p=kivitendo-erp.git diff --git a/SL/Controller/MassInvoiceCreatePrint.pm b/SL/Controller/MassInvoiceCreatePrint.pm index 7fc3388e7..ef5bfaf74 100644 --- a/SL/Controller/MassInvoiceCreatePrint.pm +++ b/SL/Controller/MassInvoiceCreatePrint.pm @@ -13,12 +13,12 @@ use SL::Controller::Helper::GetModels; use SL::DB::DeliveryOrder; use SL::DB::Order; use SL::DB::Printer; +use SL::Helper::MassPrintCreatePDF qw(:all); use SL::Helper::CreatePDF qw(:all); use SL::Helper::Flash; use SL::Locale::String; use SL::SessionFile; use SL::System::TaskServer; - use Rose::Object::MakeMethods::Generic ( 'scalar --get_set_init' => [ qw(invoice_models invoice_ids sales_delivery_order_models printers default_printer_id today) ], @@ -56,9 +56,9 @@ sub action_create_invoices { } my $db = SL::DB::Invoice->new->db; + my @invoices; - if (!$db->do_transaction(sub { - my @invoices; + if (!$db->with_transaction(sub { foreach my $id (@sales_delivery_order_ids) { my $delivery_order = SL::DB::DeliveryOrder->new(id => $id)->load; @@ -66,17 +66,17 @@ sub action_create_invoices { push @invoices, $invoice; } - my $key = sprintf('%d-%d', Time::HiRes::gettimeofday()); - $::auth->set_session_value("MassInvoiceCreatePrint::ids-${key}" => [ map { $_->id } @invoices ]); - - flash_later('info', t8('The invoices have been created. They\'re pre-selected below.')); - $self->redirect_to(action => 'list_invoices', ids => $key); - 1; })) { $::lxdebug->message(LXDebug::WARN(), "Error: " . $db->error); $::form->error($db->error); } + + my $key = sprintf('%d-%d', Time::HiRes::gettimeofday()); + $::auth->set_session_value("MassInvoiceCreatePrint::ids-${key}" => [ map { $_->id } @invoices ]); + + flash_later('info', t8('The invoices have been created. They\'re pre-selected below.')); + $self->redirect_to(action => 'list_invoices', ids => $key); } sub action_list_invoices { @@ -130,6 +130,7 @@ sub action_create_print_all_start { record_ids => [ map { $_->id } @records[0..$num - 1] ], printer_id => $::form->{printer_id}, copy_printer_id => $::form->{copy_printer_id}, + bothsided => ($::form->{bothsided}?1:0), transdate => $::form->{transdate}, status => SL::BackgroundJob::MassRecordCreationAndPrinting->WAITING_FOR_EXECUTION(), num_created => 0, @@ -137,6 +138,7 @@ sub action_create_print_all_start { invoice_ids => [ ], conversion_errors => [ ], print_errors => [ ], + session_id => $::auth->get_session_id, )->update_next_run_at; @@ -171,7 +173,7 @@ sub action_create_print_all_download { $sfile->fh->close; my $type = 'Invoices'; - my $file_name = t8($type) . '-' . DateTime->today_local->strftime('%Y%m%d%H%M%S') . '.pdf'; + my $file_name = t8($type) . '-' . DateTime->now_local->strftime('%Y%m%d%H%M%S') . '.pdf'; $file_name =~ s{[^\w\.]+}{_}g; return $self->send_file( @@ -186,6 +188,7 @@ sub action_create_print_all_download { # sub init_printers { SL::DB::Manager::Printer->get_all_sorted } +#sub init_att { require SL::Controller::Attachments; SL::Controller::Attachments->new() } sub init_invoice_ids { [] } sub init_today { DateTime->today_local } @@ -267,30 +270,6 @@ sub setup { # helpers # -sub create_pdfs { - my ($self, %params) = @_; - - my @pdf_file_names; - foreach my $invoice (@{ $params{invoices} }) { - my %create_params = ( - template => $self->find_template(name => 'invoice', printer_id => $params{printer_id}), - variables => Form->new(''), - return => 'file_name', - variable_content_types => { longdescription => 'html', - partnotes => 'html', - notes => 'html',} - ); - - $create_params{variables}->{$_} = $params{variables}->{$_} for keys %{ $params{variables} }; - - $invoice->flatten_to_form($create_params{variables}, format_amounts => 1); - $create_params{variables}->prepare_for_printing; - - push @pdf_file_names, $self->create_pdf(%create_params); - } - - return @pdf_file_names; -} sub download_or_print_documents { my ($self, %params) = @_; @@ -299,13 +278,13 @@ sub download_or_print_documents { eval { my %pdf_params = ( - invoices => $params{invoices}, - printer_id => $params{printer_id}, + documents => $params{invoices}, variables => { type => 'invoice', formname => 'invoice', format => 'pdf', media => $params{printer_id} ? 'printer' : 'file', + printer_id => $params{printer_id}, }); @pdf_file_names = $self->create_pdfs(%pdf_params); @@ -313,7 +292,7 @@ sub download_or_print_documents { unlink @pdf_file_names; if (!$params{printer_id}) { - my $file_name = t8("Invoices") . '-' . DateTime->today_local->strftime('%Y%m%d%H%M%S') . '.pdf'; + my $file_name = t8("Invoices") . '-' . DateTime->now_local->strftime('%Y%m%d%H%M%S') . '.pdf'; $file_name =~ s{[^\w\.]+}{_}g; return $self->send_file( @@ -324,12 +303,7 @@ sub download_or_print_documents { } my $printer = SL::DB::Printer->new(id => $params{printer_id})->load; - my $command = SL::Template::create(type => 'ShellCommand', form => Form->new(''))->parse($printer->printer_command); - - open my $out, '|-', $command or die $!; - binmode $out; - print $out $merged_pdf; - close $out; + $printer->print_document(content => $merged_pdf); flash_later('info', t8('The documents have been sent to the printer \'#1\'.', $printer->printer_description)); return $self->redirect_to(action => 'list_invoices', printer_id => $params{printer_id});