Revision b74a00e5
Von Jan Büren vor mehr als 9 Jahren hinzugefügt
SL/BackgroundJob/MassRecordCreationAndPrinting.pm | ||
---|---|---|
22 | 22 |
# my $data = { |
23 | 23 |
# record_ids => [ 123, 124, 127, ], |
24 | 24 |
# printer_id => 4711, |
25 |
# copy_printer_id => 4711, |
|
26 |
# transdate => $today || $custom_transdate, |
|
25 | 27 |
# num_created => 0, |
26 | 28 |
# num_printed => 0, |
27 | 29 |
# invoice_ids => [ 234, 235, ], |
... | ... | |
48 | 50 |
$number = $sales_delivery_order->donumber; |
49 | 51 |
|
50 | 52 |
if (!$db->do_transaction(sub { |
51 |
$invoice = $sales_delivery_order->convert_to_invoice(item_filter => \&delivery_order_item_filter, queue_sort => 1) || die $db->error;
|
|
52 |
# $delivery_order->post_save_sanity_check; # just a hint at e8521eee (#90 od)
|
|
53 |
$invoice = $sales_delivery_order->convert_to_invoice(sub { $data->{transdate} ? ('attributes' => { transdate => $data->{transdate} }) :
|
|
54 |
undef }->() ) || die $db->error;
|
|
53 | 55 |
1; |
54 | 56 |
})) { |
55 | 57 |
die $db->error; |
... | ... | |
166 | 168 |
sub print_pdfs { |
167 | 169 |
my ($self) = @_; |
168 | 170 |
|
169 |
my $job_obj = $self->{job_obj}; |
|
170 |
my $data = $job_obj->data_as_hash; |
|
171 |
my $printer_id = $data->{printer_id}; |
|
171 |
my $job_obj = $self->{job_obj}; |
|
172 |
my $data = $job_obj->data_as_hash; |
|
173 |
my $printer_id = $data->{printer_id}; |
|
174 |
my $copy_printer_id = $data->{copy_printer_id}; |
|
172 | 175 |
|
173 | 176 |
return if !$printer_id; |
174 | 177 |
|
175 |
my $printer = SL::DB::Printer->new(id => $printer_id)->load; |
|
176 |
my $command = SL::Template::create(type => 'ShellCommand', form => Form->new(''))->parse($printer->printer_command); |
|
177 | 178 |
my $out; |
178 | 179 |
|
179 |
if (!open $out, '|-', $command) { |
|
180 |
push @{ $data->{print_errors} }, { message => $::locale->text('Could not execute printer command: #1', $!) }; |
|
181 |
$job_obj->update_attributes(data_as_hash => $data); |
|
182 |
return; |
|
180 |
foreach my $local_printer_id ($printer_id, $copy_printer_id) { |
|
181 |
next unless $local_printer_id; |
|
182 |
my $printer = SL::DB::Printer->new(id => $local_printer_id)->load; |
|
183 |
my $command = SL::Template::create(type => 'ShellCommand', form => Form->new(''))->parse($printer->printer_command); |
|
184 |
if (!open $out, '|-', $command) { |
|
185 |
push @{ $data->{print_errors} }, { message => $::locale->text('Could not execute printer command: #1', $!) }; |
|
186 |
$job_obj->update_attributes(data_as_hash => $data); |
|
187 |
return; |
|
188 |
} |
|
189 |
binmode $out; |
|
190 |
print $out $self->{merged_pdf}; |
|
191 |
close $out; |
|
183 | 192 |
} |
184 | 193 |
|
185 |
binmode $out; |
|
186 |
print $out $self->{merged_pdf}; |
|
187 |
close $out; |
|
188 | 194 |
} |
189 | 195 |
|
190 | 196 |
sub run { |
... | ... | |
228 | 234 |
)->set_data( |
229 | 235 |
record_ids => [ map { $_->id } @records[0..$num - 1] ], |
230 | 236 |
printer_id => $::form->{printer_id}, |
237 |
copy_printer_id => $::form->{copy_printer_id}, |
|
238 |
transdate => $::form->{transdate} || undef, |
|
231 | 239 |
status => SL::BackgroundJob::MassRecordCreationAndPrinting->WAITING_FOR_EXECUTION(), |
232 | 240 |
num_created => 0, |
233 | 241 |
num_printed => 0, |
... | ... | |
266 | 274 |
|
267 | 275 |
Converts the source objects (DeliveryOrder) to destination objects (Invoice). |
268 | 276 |
On success objects will be saved. |
277 |
If param C<data->{transdate}> is set, this will be the transdate. No safety checks are done. |
|
278 |
The original conversion from order to delivery order had a post_save_sanity_check |
|
279 |
C<$delivery_order-E<gt>post_save_sanity_check; # just a hint at e8521eee (#90 od)> |
|
280 |
The params of convert_to_invoice are created on the fly with a anonym sub, as a alternative check |
|
281 |
perlsecret Enterprise ()x!! |
|
269 | 282 |
|
270 | 283 |
=item C<convert_invoices_to_pdf> |
271 | 284 |
|
... | ... | |
273 | 286 |
|
274 | 287 |
=item C<print_pdfs> |
275 | 288 |
|
276 |
Sent the pdf to the printer command (if checked). |
|
289 |
Sent the pdf to the printer command. |
|
290 |
If param C<data->{copy_printer_id}> is set, the pdf will be sent to a second printer command. |
|
277 | 291 |
|
278 | 292 |
=back |
279 | 293 |
|
... | ... | |
282 | 296 |
Currently the calculation from the gui (form) differs from the calculation via convert (PTC). |
283 | 297 |
Furthermore mass conversion with foreign currencies could lead to problems (daily rate check). |
284 | 298 |
|
299 |
=head1 TODO |
|
300 |
|
|
301 |
It would be great to extend this Job for general background printing. The original project |
|
302 |
code converted sales order to delivery orders (84e7c540) this could be merged in unstable. |
|
303 |
The states should be CONVERTING_SOURCE_RECORDS, PRINTING_DESTINATION_RECORDS etc |
|
304 |
|
|
285 | 305 |
=head1 AUTHOR |
286 | 306 |
|
287 | 307 |
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt> |
SL/Controller/MassInvoiceCreatePrint.pm | ||
---|---|---|
21 | 21 |
|
22 | 22 |
use Rose::Object::MakeMethods::Generic |
23 | 23 |
( |
24 |
'scalar --get_set_init' => [ qw(invoice_models invoice_ids sales_delivery_order_models printers default_printer_id) ], |
|
24 |
'scalar --get_set_init' => [ qw(invoice_models invoice_ids sales_delivery_order_models printers default_printer_id today) ],
|
|
25 | 25 |
); |
26 | 26 |
|
27 | 27 |
__PACKAGE__->run_before('setup'); |
... | ... | |
118 | 118 |
|
119 | 119 |
$self->sales_delivery_order_models->disable_plugin('paginated'); |
120 | 120 |
|
121 |
my @records = @{ $self->sales_delivery_order_models->get };
|
|
121 |
my @records = @{ $self->sales_delivery_order_models->get }; |
|
122 | 122 |
my $num = min(scalar(@records), $::form->{number_of_invoices} // scalar(@records)); |
123 | 123 |
|
124 | 124 |
my $job = SL::DB::BackgroundJob->new( |
... | ... | |
129 | 129 |
)->set_data( |
130 | 130 |
record_ids => [ map { $_->id } @records[0..$num - 1] ], |
131 | 131 |
printer_id => $::form->{printer_id}, |
132 |
copy_printer_id => $::form->{copy_printer_id}, |
|
133 |
transdate => $::form->{transdate}, |
|
132 | 134 |
status => SL::BackgroundJob::MassRecordCreationAndPrinting->WAITING_FOR_EXECUTION(), |
133 | 135 |
num_created => 0, |
134 | 136 |
num_printed => 0, |
... | ... | |
185 | 187 |
|
186 | 188 |
sub init_printers { SL::DB::Manager::Printer->get_all_sorted } |
187 | 189 |
sub init_invoice_ids { [] } |
190 |
sub init_today { DateTime->today_local } |
|
188 | 191 |
|
189 | 192 |
sub init_sales_delivery_order_models { |
190 | 193 |
my ($self) = @_; |
... | ... | |
434 | 437 |
|
435 | 438 |
Gets a list of (empty) invoice ids |
436 | 439 |
|
440 |
=item C<init_today> |
|
441 |
|
|
442 |
Gets the current day. Currently used in custom code. |
|
443 |
Has to be initialised (get_set_init) and can be used as default for |
|
444 |
a date tag like C<[% L.date_tag("transdate", SELF.today, id=transdate) %]>. |
|
445 |
|
|
437 | 446 |
=item C<init_sales_delivery_order_models> |
438 | 447 |
|
439 | 448 |
Calls _init_sales_delivery_order_models with a param |
... | ... | |
449 | 458 |
|
450 | 459 |
=item C<init_default_printer_id> |
451 | 460 |
|
452 |
Gets the default printer for sales_invoices. Maybe this function is not used, but |
|
453 |
might be useful in the next version (working in client project). |
|
461 |
Gets the default printer for sales_invoices. Currently this function is not called, but |
|
462 |
might be useful in the next version.Calling template code and Controller already expect a default: |
|
463 |
C<L.select_tag("", printers, title_key="description", default=SELF.default_printer_id, id="cpa_printer_id") %]> |
|
454 | 464 |
|
455 | 465 |
=item C<setup> |
456 | 466 |
|
... | ... | |
476 | 486 |
was taken from one client project (mosu) with some extra (maybe not standard compliant) customized |
477 | 487 |
stuff (using cvars for extra filters and a very compressed Controller for linking (ODSalesOrder.pm)). |
478 | 488 |
|
479 |
Filtering needs to be extended for Delivery Order Number (Natural Sort). |
|
480 |
|
|
481 |
A second printer (copy) needs to be implemented. |
|
482 |
|
|
483 |
Both todos are marked in the template code. |
|
484 |
|
|
485 | 489 |
|
486 | 490 |
=head1 AUTHOR |
487 | 491 |
|
js/kivi.MassInvoiceCreatePrint.js | ||
---|---|---|
43 | 43 |
|
44 | 44 |
var data = { |
45 | 45 |
number_of_invoices: $('#cpa_number_of_invoices').val(), |
46 |
printer_id: $('#cpa_printer_id').val() |
|
46 |
printer_id: $('#cpa_printer_id').val(), |
|
47 |
copy_printer_id: $('#cpa_copy_printer_id').val(), |
|
48 |
transdate: $('#transdate').val() |
|
47 | 49 |
}; |
48 | 50 |
kivi.submit_ajax_form('controller.pl?action=MassInvoiceCreatePrint/create_print_all_start', '[name^=filter\\.]', data); |
49 | 51 |
}; |
Auch abrufbar als: Unified diff
Massendruck weitere Optionen (zweiter Druckbefehl) implementiert
transdate, copy_printer_id (id des zweiten Druckbefehls) als optionale
Parameter beim Aufruf der Konvertierung inkl. Ausdruck in der API
bereitgestellt.
Details: perldoc SL/Controller/MassInvoiceCreatePrint.pm