1 package SL::BackgroundJob::MassDeliveryOrderPrinting;
6 use parent qw(SL::BackgroundJob::Base);
8 use SL::DB::DeliveryOrder;
9 use SL::DB::Order; # origin order to delivery_order
13 use SL::Helper::MassPrintCreatePDF qw(:all);
14 use SL::Helper::CreatePDF qw(:all);
15 use SL::Helper::File qw(store_pdf append_general_pdf_attachments);
17 use constant WAITING_FOR_EXECUTION => 0;
18 use constant PRINTING_DELIVERY_ORDERS => 1;
19 use constant DONE => 2;
23 # record_ids => [ 123, 124, 127, ],
27 # printed_ids => [ 234, 235, ],
28 # conversion_errors => [ { id => 124, number => 'A981723', message => "Stuff went boom" }, ],
29 # print_errors => [ { id => 234, number => 'L87123123', message => "Printer is out of coffee" }, ],
30 # pdf_file_name => 'qweqwe.pdf',
31 # session_id => $::auth->get_session_id,
35 sub convert_deliveryorders_to_pdf {
38 my $job_obj = $self->{job_obj};
39 my $db = $job_obj->db;
41 $job_obj->set_data(status => PRINTING_DELIVERY_ORDERS())->save;
42 my $data = $job_obj->data_as_hash;
44 my $printer_id = $data->{printer_id};
45 if ( $data->{media} ne 'printer' ) {
47 $data->{media} = 'file';
50 type => 'delivery_order',
51 formname => $data->{formname},
52 format => $data->{format},
53 media => $data->{media},
54 printer_id => $printer_id,
55 copies => $data->{copies},
59 foreach my $delivery_order_id (@{ $data->{record_ids} }) {
60 my $number = $delivery_order_id;
61 my $delivery_order = SL::DB::DeliveryOrder->new(id => $delivery_order_id)->load;
64 $number = $delivery_order->donumber;
67 variables => \%variables,
68 document => $delivery_order,
69 return => 'file_name',
72 push @pdf_file_names, $self->create_massprint_pdf(%params);
74 $data->{num_created}++;
79 push @{ $data->{conversion_errors} }, { id => $delivery_order->id, number => $number, message => $@ };
82 $job_obj->update_attributes(data_as_hash => $data);
85 $self->merge_massprint_pdf(file_names => \@pdf_file_names, type => 'delivery_order' ) if scalar(@pdf_file_names) > 0;
89 my ($self, $job_obj) = @_;
91 $self->{job_obj} = $job_obj;
93 $self->convert_deliveryorders_to_pdf;
96 my $data = $job_obj->data_as_hash;
97 $data->{num_printed} = $data->{num_created};
98 $job_obj->update_attributes(data_as_hash => $data);
99 $job_obj->set_data(status => DONE())->save;