Auftragsimport - Methoden ausgelagert
[kivitendo-erp.git] / SL / Controller / MassInvoiceCreatePrint.pm
index 0714757..cd96a73 100644 (file)
@@ -21,7 +21,7 @@ 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 js) ],
+  'scalar --get_set_init' => [ qw(invoice_models invoice_ids sales_delivery_order_models printers default_printer_id today) ],
 );
 
 __PACKAGE__->run_before('setup');
@@ -118,7 +118,7 @@ sub action_create_print_all_start {
 
   $self->sales_delivery_order_models->disable_plugin('paginated');
 
-  my @records           = @{ $self->sales_delivery_order_models->get };
+  my @records          = @{ $self->sales_delivery_order_models->get };
   my $num              = min(scalar(@records), $::form->{number_of_invoices} // scalar(@records));
 
   my $job              = SL::DB::BackgroundJob->new(
@@ -129,12 +129,15 @@ sub action_create_print_all_start {
   )->set_data(
     record_ids         => [ map { $_->id } @records[0..$num - 1] ],
     printer_id         => $::form->{printer_id},
+    copy_printer_id    => $::form->{copy_printer_id},
+    transdate          => $::form->{transdate},
     status             => SL::BackgroundJob::MassRecordCreationAndPrinting->WAITING_FOR_EXECUTION(),
     num_created        => 0,
     num_printed        => 0,
     invoice_ids        => [ ],
     conversion_errors  => [ ],
     print_errors       => [ ],
+    session_id         => $::auth->get_session_id,
 
   )->update_next_run_at;
 
@@ -183,9 +186,9 @@ sub action_create_print_all_download {
 # filters
 #
 
-sub init_js       { SL::ClientJS->new(controller => $_[0]) }
 sub init_printers { SL::DB::Manager::Printer->get_all_sorted }
 sub init_invoice_ids { [] }
+sub init_today         { DateTime->today_local }
 
 sub init_sales_delivery_order_models {
   my ($self) = @_;
@@ -214,7 +217,6 @@ sub _init_sales_delivery_order_models {
    query        => [
       '!customer_id' => undef,
       or             => [ closed    => undef, closed    => 0 ],
-      or             => [ delivered => undef, delivered => 0 ],
     ],
   );
 }
@@ -275,6 +277,9 @@ sub create_pdfs {
       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} };
@@ -344,8 +349,8 @@ sub make_filter_summary {
 
   my @filters = (
     [ $filter->{customer}{"name:substr::ilike"}, t8('Customer') ],
-    [ $filter->{"transdate:date::ge"},           t8('Delivery Date') . " " . t8('From Date') ],
-    [ $filter->{"transdate:date::le"},           t8('Delivery Date') . " " . t8('To Date')   ],
+    [ $filter->{"transdate:date::ge"},           t8('Transdate') . " " . t8('From Date') ],
+    [ $filter->{"transdate:date::le"},           t8('Transdate') . " " . t8('To Date')   ],
   );
 
   for (@filters) {
@@ -384,7 +389,6 @@ From a reverse engineering point of view the actions in this controller were wri
 background job existed, therefore if anything goes boom take a look at the single steps done via gui
 in this controller and after that take a deeper look at the MassRecordCreationAndPrinting job.
 
-
 =head1 FUNCTIONS
 
 =over 2
@@ -428,10 +432,6 @@ Action for watching status, default is refreshing every 5 seconds
 If the above is done (did I already said: boring linear?). Documents will
 be either printed or downloaded.
 
-=item C<init_js>
-
-Inits js/kivi.MassInvoiceCreatePrint;
-
 =item C<init_printers>
 
 Gets all printer commands
@@ -440,6 +440,12 @@ Gets all printer commands
 
 Gets a list of (empty) invoice ids
 
+=item C<init_today>
+
+Gets the current day. Currently used in custom code.
+Has to be initialised (get_set_init) and can be used as default for
+a date tag like C<[% L.date_tag("transdate", SELF.today, id=transdate) %]>.
+
 =item C<init_sales_delivery_order_models>
 
 Calls _init_sales_delivery_order_models with a param
@@ -455,8 +461,9 @@ Gets all invoice_models via the ids in invoice_ids (at the beginning no ids exis
 
 =item C<init_default_printer_id>
 
-Gets the default printer for sales_invoices. Maybe this function is not used, but
-might be useful in the next version (working in client project).
+Gets the default printer for sales_invoices. Currently this function is not called, but
+might be useful in the next version.Calling template code and Controller already expect a default:
+C<L.select_tag("", printers, title_key="description", default=SELF.default_printer_id, id="cpa_printer_id") %]>
 
 =item C<setup>
 
@@ -482,16 +489,11 @@ Using BackgroundJobs to mass create / transfer stuff is the way to do it. The or
 was taken from one client project (mosu) with some extra (maybe not standard compliant) customized
 stuff (using cvars for extra filters and a very compressed Controller for linking (ODSalesOrder.pm)).
 
-Filtering needs to be extended for Delivery Order Number (Natural Sort).
-
-A second printer (copy) needs to be implemented.
-
-Both todos are marked in the template code.
-
 
 =head1 AUTHOR
 
 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
 
 Jan Büren E<lt>jan@kivitendo-premium.deE<gt>
+
 =cut