Mahnungsbericht: Webdav-Dateien f. Mahnlauf anzeigen
[kivitendo-erp.git] / bin / mozilla / dn.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2006
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
28 # MA 02110-1335, USA.
29 #======================================================================
30 #
31 # Dunning process module
32 #
33 #======================================================================
34
35 use POSIX qw(strftime);
36
37 use List::MoreUtils qw(none);
38
39 use SL::IS;
40 use SL::DN;
41 use SL::DB::Department;
42 use SL::DB::Dunning;
43 use SL::File;
44 use SL::Helper::Flash qw(flash);
45 use SL::Locale::String qw(t8);
46 use SL::Presenter::FileObject;
47 use SL::Presenter::WebdavObject;
48 use SL::ReportGenerator;
49
50 require "bin/mozilla/common.pl";
51 require "bin/mozilla/reportgenerator.pl";
52 require "bin/mozilla/io.pl";
53
54 use strict;
55
56 1;
57
58 sub edit_config {
59   $main::lxdebug->enter_sub();
60
61   my $form     = $main::form;
62   my %myconfig = %main::myconfig;
63   my $locale   = $main::locale;
64
65   $main::auth->assert('config');
66
67   DN->get_config(\%myconfig, \%$form);
68   $form->get_lists('charts' => { 'key'       => 'ALL_CHARTS',
69                                  'transdate' => 'current_date' });
70
71   $form->{SELECT_AR_AMOUNT} = [];
72   $form->{SELECT_AR}        = [];
73
74   foreach my $chart (@{ $form->{ALL_CHARTS} }) {
75     $chart->{LINKS} = { map { $_, 1 } split m/:/, $chart->{link} };
76
77     if ($chart->{LINKS}->{AR}) {
78       $chart->{AR_selected} = "selected" if $chart->{id} == $form->{AR};
79       push @{ $form->{SELECT_AR} }, $chart;
80     }
81
82     if ($chart->{LINKS}->{AR_amount}) {
83       $chart->{AR_amount_fee_selected}      = "selected" if $chart->{id} == $form->{AR_amount_fee};
84       $chart->{AR_amount_interest_selected} = "selected" if $chart->{id} == $form->{AR_amount_interest};
85       push @{ $form->{SELECT_AR_AMOUNT} }, $chart;
86     }
87   }
88
89   $form->{title}      = $locale->text('Edit Dunning Process Config');
90   $form->{callback} ||= build_std_url("action=edit_config");
91
92   setup_dn_edit_config_action_bar();
93
94   $form->header();
95   print $form->parse_html_template("dunning/edit_config");
96
97   $main::lxdebug->leave_sub();
98 }
99
100 sub add {
101   $main::lxdebug->enter_sub();
102
103   my $form     = $main::form;
104   my %myconfig = %main::myconfig;
105   my $locale   = $main::locale;
106
107   $main::auth->assert('dunning_edit');
108
109   DN->get_config(\%myconfig, \%$form);
110
111   $form->get_lists("departments" => "ALL_DEPARTMENTS");
112
113   $form->{SHOW_DUNNING_LEVEL_SELECTION} = $form->{DUNNING}         && scalar @{ $form->{DUNNING} };
114   $form->{SHOW_DEPARTMENT_SELECTION}    = $form->{ALL_DEPARTMENTS} && scalar @{ $form->{ALL_DEPARTMENTS} || [] };
115
116   $form->{title}    = $locale->text('Start Dunning Process');
117
118   setup_dn_add_action_bar();
119   $form->header();
120
121   print $form->parse_html_template("dunning/add");
122
123   $main::lxdebug->leave_sub();
124 }
125
126 sub show_invoices {
127   $main::lxdebug->enter_sub();
128
129   my $form     = $main::form;
130   my %myconfig = %main::myconfig;
131   my $locale   = $main::locale;
132
133   $main::auth->assert('dunning_edit');
134
135   DN->get_invoices(\%myconfig, \%$form);
136   $form->{title} = $locale->text('Start Dunning Process');
137
138   foreach my $row (@{ $form->{DUNNINGS} }) {
139     $row->{DUNNING_CONFIG} = [ map +{ %{ $_ } }, @{ $form->{DUNNING_CONFIG} } ];
140
141     if ($row->{next_dunning_config_id}) {
142       map { $_->{SELECTED} = $_->{id} == $row->{next_dunning_config_id} } @{ $row->{DUNNING_CONFIG } };
143     }
144     map { $row->{$_} = $form->format_amount(\%myconfig, $row->{$_} * 1, 2) } qw(amount open_amount fee interest);
145
146     if ($row->{'language_id'}) {
147       $row->{language} = SL::DB::Manager::Language->find_by_or_create('id' => $row->{'language_id'})->{'description'};
148     }
149   }
150
151   $form->get_lists('printers'  => 'printers',
152                    'languages' => 'languages');
153
154   $form->{type}           = 'dunning';
155   $form->{rowcount}       = scalar @{ $form->{DUNNINGS} };
156   $form->{callback}     ||= build_std_url("action=show_invoices", qw(customer invnumber ordnumber groupinvoices minamount dunning_level notes));
157
158   $form->{PRINT_OPTIONS}  = print_options('inline'          => 1,
159                                           'no_queue'        => 1,
160                                           'no_postscript'   => 1,
161                                           'no_html'         => 1,
162                                           'no_opendocument' => 1,);
163
164   setup_dn_show_invoices_action_bar();
165   $form->header();
166   print $form->parse_html_template("dunning/show_invoices");
167
168   $main::lxdebug->leave_sub();
169 }
170
171 sub save {
172   $main::lxdebug->enter_sub();
173
174   my $form     = $main::form;
175   my %myconfig = %main::myconfig;
176   my $locale   = $main::locale;
177
178   $main::auth->assert('config');
179
180   for my $i (1 .. $form->{rowcount}) {
181     if ($form->{"dunning_description_$i"} ne "") {
182       $form->isblank("dunning_level_$i", $locale->text('Dunning Level missing in row '). $i);
183       $form->isblank("dunning_description_$i", $locale->text('Dunning Description missing in row '). $i);
184       $form->isblank("terms_$i", $locale->text('Terms missing in row '). $i);
185       $form->isblank("payment_terms_$i", $locale->text('Payment Terms missing in row '). $i);
186     }
187   }
188
189   DN->save_config(\%myconfig, \%$form);
190   # saving the history
191   if(!exists $form->{addition} && $form->{id} ne "") {
192     $form->{snumbers} = qq|dunning_id_| . $form->{"dunning_id"};
193     $form->{addition} = "SAVED FOR DUNNING";
194     $form->save_history;
195   }
196   # /saving the history
197   $form->redirect($locale->text('Dunning Process Config saved!'));
198
199   $main::lxdebug->leave_sub();
200 }
201
202 sub save_dunning {
203   $main::lxdebug->enter_sub();
204
205   my $form     = $main::form;
206   my %myconfig = %main::myconfig;
207   my $locale   = $main::locale;
208
209   $main::auth->assert('dunning_edit');
210
211   my $active=1;
212   my @rows = ();
213   undef($form->{DUNNING_PDFS});
214
215   my $saved_language_id = $form->{language_id};
216
217   if ($form->{groupinvoices} || $form->{l_include_credit_notes}) {
218     my %dunnings_for;
219
220     for my $i (1 .. $form->{rowcount}) {
221       next unless ($form->{"active_$i"});
222
223       $dunnings_for{$form->{"customer_id_$i"}} ||= {};
224       my $dunning_levels = $dunnings_for{$form->{"customer_id_$i"}};
225
226       $dunning_levels->{$form->{"next_dunning_config_id_$i"}} ||= [];
227       my $level = $dunning_levels->{$form->{"next_dunning_config_id_$i"}};
228
229       push @{ $level }, { "row"                    => $i,
230                           "invoice_id"             => $form->{"inv_id_$i"},
231                           "credit_note"            => $form->{"credit_note_$i"},
232                           "customer_id"            => $form->{"customer_id_$i"},
233                           "language_id"            => $form->{"language_id_$i"},
234                           "next_dunning_config_id" => $form->{"next_dunning_config_id_$i"},
235                           "print_invoice"          => $form->{"include_invoice_$i"},
236                           "email"                  => $form->{"email_$i"}, };
237     }
238
239     foreach my $levels (values %dunnings_for) {
240       foreach my $level (values %{ $levels }) {
241         next unless scalar @{ $level };
242         if (!$form->{force_lang}) {
243           $form->{language_id} = @{$level}[0]->{language_id};
244         }
245         DN->save_dunning(\%myconfig, $form, $level);
246       }
247     }
248
249   } else {
250     for my $i (1 .. $form->{rowcount}) {
251       next unless $form->{"active_$i"};
252
253       my $level = [ { "row"                    => $i,
254                       "invoice_id"             => $form->{"inv_id_$i"},
255                       "customer_id"            => $form->{"customer_id_$i"},
256                       "language_id"            => $form->{"language_id_$i"},
257                       "next_dunning_config_id" => $form->{"next_dunning_config_id_$i"},
258                       "print_invoice"          => $form->{"include_invoice_$i"},
259                       "email"                  => $form->{"email_$i"}, } ];
260       if (!$form->{force_lang}) {
261         $form->{language_id} = @{$level}[0]->{language_id};
262       }
263       DN->save_dunning(\%myconfig, $form, $level);
264     }
265   }
266
267   $form->{language_id} = $saved_language_id;
268
269   if (scalar @{ $form->{DUNNING_PDFS} }) {
270     $form->{dunning_id} = strftime("%Y%m%d", localtime time) if scalar @{ $form->{DUNNING_PDFS}} > 1;
271     DN->melt_pdfs(\%myconfig, $form, $form->{copies});
272   }
273
274   # saving the history
275   if(!exists $form->{addition} && $form->{id} ne "") {
276     $form->{snumbers} = qq|dunning_id_| . $form->{"dunning_id"};
277     $form->{addition} = "DUNNING STARTED";
278     $form->save_history;
279   }
280   # /saving the history
281
282   if ($form->{media} eq 'printer') {
283     delete $form->{callback};
284     $form->redirect($locale->text('Dunning Process started for selected invoices!'));
285   }
286
287   $main::lxdebug->leave_sub();
288 }
289
290 sub set_email {
291   $main::lxdebug->enter_sub();
292
293   my $form     = $main::form;
294   my $locale   = $main::locale;
295
296   $main::auth->assert('dunning_edit');
297
298   $form->{"title"} = $locale->text("Set eMail text");
299   $form->header(no_layout => 1);
300   print($form->parse_html_template("dunning/set_email"));
301
302   $main::lxdebug->leave_sub();
303 }
304
305 sub search {
306   $main::lxdebug->enter_sub();
307
308   my $form     = $main::form;
309   my %myconfig = %main::myconfig;
310   my $locale   = $main::locale;
311
312   $main::auth->assert('dunning_edit');
313
314   $form->get_lists("customers"   => "ALL_CUSTOMERS",
315                    "departments" => "ALL_DEPARTMENTS");
316   $form->{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]);
317
318   DN->get_config(\%myconfig, \%$form);
319
320   $form->{SHOW_DUNNING_LEVELS}   = scalar @{ $form->{DUNNING} };
321
322   $form->{title}    = $locale->text('Dunnings');
323
324   setup_dn_search_action_bar();
325   $form->header();
326
327   print $form->parse_html_template("dunning/search");
328
329   $main::lxdebug->leave_sub();
330
331 }
332
333 sub show_dunning {
334   $main::lxdebug->enter_sub();
335
336   my $form     = $main::form;
337   my %myconfig = %main::myconfig;
338   my $locale   = $main::locale;
339   my $cgi      = $::request->{cgi};
340
341   $main::auth->assert('dunning_edit');
342
343   my @filter_field_list = qw(customer_id customer dunning_id dunning_level department_id invnumber ordnumber
344                              transdatefrom transdateto dunningfrom dunningto notes showold l_salesman salesman_id);
345
346   report_generator_set_default_sort('customername', 1);
347
348   DN->get_dunning(\%myconfig, \%$form);
349
350   if (!$form->{callback}) {
351     $form->{callback} = build_std_url("action=show_dunning", @filter_field_list);
352   }
353
354   $form->get_lists('printers'  => 'printers',
355                    'languages' => 'languages');
356
357   $form->{type}          = 'dunning';
358   $form->{PRINT_OPTIONS} = print_options('inline'          => 1,
359                                          'no_queue'        => 1,
360                                          'no_postscript'   => 1,
361                                          'no_html'         => 1,
362                                          'no_opendocument' => 1,);
363   $form->{title}         = $locale->text('Dunning overview');
364
365   my $report = SL::ReportGenerator->new(\%myconfig, $form);
366
367   $report->set_options('std_column_visibility' => 1,
368                        'title'                 => $form->{title});
369   $report->set_export_options('show_dunning', @filter_field_list, qw(sort sortdir));
370
371   my %column_defs         =  (
372     'checkbox'            => { 'text' => '', 'visible' => 'HTML' },
373     'dunning_description' => { 'text' => $locale->text('Dunning Level') },
374     'customername'        => { 'text' => $locale->text('Customername') },
375     'departmentname'      => { 'text' => $locale->text('Department') },
376     'language'            => { 'text' => $locale->text('Language') },
377     'invnumber'           => { 'text' => $locale->text('Invnumber') },
378     'transdate'           => { 'text' => $locale->text('Invdate') },
379     'duedate'             => { 'text' => $locale->text('Invoice Duedate') },
380     'amount'              => { 'text' => $locale->text('Amount') },
381     'dunning_id'          => { 'text' => $locale->text('Dunning number') },
382     'dunning_date'        => { 'text' => $locale->text('Dunning Date') },
383     'dunning_duedate'     => { 'text' => $locale->text('Dunning Duedate') },
384     'fee'                 => { 'text' => $locale->text('Total Fees') },
385     'interest'            => { 'text' => $locale->text('Interest') },
386     'salesman'            => { 'text' => $locale->text('Salesperson'), 'visible' => $form->{l_salesman} ? 1 : 0 },
387     'documents'           => { 'text' => $locale->text('Documents'),   'visible' => $::instance_conf->get_doc_storage ? 1 : 0 },
388     'webdav'              => { 'text' => $locale->text('WebDAV'),      'visible' => $::instance_conf->get_webdav      ? 1 : 0 },
389   );
390
391   $report->set_columns(%column_defs);
392   $report->set_column_order(qw(checkbox dunning_description dunning_id customername language invnumber transdate
393                                duedate amount dunning_date dunning_duedate fee interest salesman));
394   $report->set_sort_indicator($form->{sort}, $form->{sortdir});
395
396   my $edit_url  = sub { build_std_url('script=' . ($_[0]->{invoice} ? 'is' : 'ar') . '.pl', 'action=edit', 'callback') . '&id=' . $::form->escape($_[0]->{id}) };
397   my $print_url = sub { build_std_url('action=print_dunning', 'format=pdf', 'media=screen', 'dunning_id='.$_[0]->{dunning_id}, 'language_id=' . $_[0]->{language_id}) };
398   my $sort_url  = build_std_url('action=show_dunning', grep { $form->{$_} } @filter_field_list);
399
400   foreach my $name (qw(dunning_description customername invnumber transdate duedate dunning_date dunning_duedate salesman dunning_id)) {
401     my $sortdir                 = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
402     $column_defs{$name}->{link} = $sort_url . "&sort=$name&sortdir=$sortdir";
403   }
404
405   my %alignment = map { $_ => 'right' } qw(transdate duedate amount dunning_date dunning_duedate fee interest salesman dunning_id);
406
407   my ($current_dunning_rows, $previous_dunning_id, $first_row_for_dunning);
408
409   $current_dunning_rows  = [];
410   $first_row_for_dunning = 1;
411   $form->{rowcount}      = scalar @{ $form->{DUNNINGS} };
412
413   my $i = 0;
414
415   foreach my $ref (@{ $form->{DUNNINGS} }) {
416     $i++;
417
418     if ($previous_dunning_id != $ref->{dunning_id}) {
419       $report->add_data($current_dunning_rows) if (scalar @{ $current_dunning_rows });
420       $current_dunning_rows  = [];
421       $first_row_for_dunning = 1;
422     }
423
424     if ($ref->{'language_id'}) {
425       $ref->{language} = SL::DB::Manager::Language->find_by('id' => $ref->{'language_id'})->{'description'};
426     }
427
428     my $row = { };
429     foreach my $column (keys %{ $ref }) {
430       $row->{$column} = {
431         'data'  => $first_row_for_dunning || (none { $_ eq $column } qw(dunning_description customername dunning_id)) ? $ref->{$column} : '',
432
433         'align' => $alignment{$column},
434
435         'link'  => (  $column eq 'invnumber'           ? $edit_url->($ref)
436                     : $column eq 'dunning_description' ? $print_url->($ref)
437                     : $column eq 'dunning_id'          ? $print_url->($ref)
438                     :                                    ''),
439       };
440     }
441
442     $row->{checkbox} = !$first_row_for_dunning ? { } : {
443       'raw_data' =>   $cgi->hidden('-name' => "dunning_id_$i", '-value' => $ref->{dunning_id})
444                     . $cgi->checkbox('-name' => "selected_$i", '-value' => 1, '-label' => ''),
445       'valign'   => 'center',
446       'align'    => 'center',
447     };
448
449     if ($first_row_for_dunning) {
450       $row->{language} = {'raw_data' => $cgi->hidden('-name' => "language_id_$i", '-value' => $ref->{language_id})
451                                         . " $ref->{language}" };
452     } else {
453       $row->{language} = { };
454     }
455
456     if ($::instance_conf->get_doc_storage && $first_row_for_dunning) {
457       my @files  = SL::File->get_all_versions(object_id   => $ref->{dunning_id},
458                                               object_type => 'dunning',
459                                               file_type   => 'document',);
460       if (scalar @files) {
461         my $html          = join '<br>', map { SL::Presenter::FileObject::file_object($_) } @files;
462         my $text          = join "\n",   map { $_->file_name                              } @files;
463         $row->{documents} = { 'raw_data' => $html, data => $text };
464       } else {
465         $row->{documents} = { };
466       }
467     }
468     if ($::instance_conf->get_webdav && $first_row_for_dunning) {
469       my $webdav = SL::Webdav->new(
470         type     => 'dunning',
471         number   => $ref->{dunning_id},
472       );
473       my @all_objects = $webdav->get_all_objects;
474       if (scalar @all_objects) {
475         my $html          = join '<br>', map { SL::Presenter::WebdavObject::webdav_object($_) } @all_objects;
476         my $text          = join "\n",   map { $_->filename                                   } @all_objects;
477         $row->{webdav}    = { 'raw_data' => $html, data => $text };
478       } else {
479         $row->{webdav}    = { };
480       }
481     }
482
483     push @{ $current_dunning_rows }, $row;
484
485     $previous_dunning_id   = $ref->{dunning_id};
486     $first_row_for_dunning = 0;
487   }
488
489   $report->add_data($current_dunning_rows) if (scalar @{ $current_dunning_rows });
490
491   $report->set_options('raw_top_info_text'    => $form->parse_html_template('dunning/show_dunning_top'),
492                        'raw_bottom_info_text' => $form->parse_html_template('dunning/show_dunning_bottom'),
493                        'output_format'        => 'HTML',
494                        'attachment_basename'  => $locale->text('dunning_list') . strftime('_%Y%m%d', localtime time),
495     );
496
497   $report->set_options_from_form();
498
499   setup_dn_show_dunning_action_bar();
500   $report->generate_with_headers();
501
502   $main::lxdebug->leave_sub();
503
504 }
505
506 sub print_dunning {
507   $main::lxdebug->enter_sub();
508
509   my $form     = $main::form;
510
511   $main::auth->assert('dunning_edit');
512
513   $form->{rowcount}     = 1;
514   $form->{selected_1}   = 1;
515   $form->{dunning_id_1} = $form->{dunning_id};
516   $form->{language_id_1} = $form->{language_id};
517
518   print_multiple();
519
520   $main::lxdebug->leave_sub();
521 }
522
523 sub delete {
524   $main::auth->assert('dunning_edit');
525
526   my @dunning_ids = map { $::form->{"dunning_id_$_"} } grep { $::form->{"selected_$_"} } (1..$::form->{rowcount});
527
528   if (!scalar @dunning_ids) {
529     $::form->error($::locale->text('No dunnings have been selected for printing.'));
530   }
531
532   my $dunnings = SL::DB::Manager::Dunning->get_all(query => [ dunning_id => \@dunning_ids ]);
533
534   SL::DB::Dunning->new->db->with_transaction(sub {
535     for my $dunning (@$dunnings) {
536       SL::DB::Manager::Invoice->find_by(id => $dunning->trans_id)->update_attributes(dunning_config_id => undef);
537       $dunning->delete;
538     }
539   });
540
541   flash('info', t8('#1 dunnings have been deleted', scalar @$dunnings));
542
543   search();
544 }
545
546 sub print_multiple {
547   $main::lxdebug->enter_sub();
548
549   my $form     = $main::form;
550   my %myconfig = %main::myconfig;
551   my $locale   = $main::locale;
552
553   $main::auth->assert('dunning_edit');
554
555   $form->{title} = $locale->text('Print dunnings');
556
557   my @dunning_ids = map { $form->{"dunning_id_$_"} } grep { $form->{"selected_$_"} } (1..$form->{rowcount});
558   my @language_ids = map { $form->{"language_id_$_"} } grep { $form->{"selected_$_"} } (1..$form->{rowcount});
559
560   if (!scalar @dunning_ids) {
561     $form->error($locale->text('No dunnings have been selected for printing.'));
562   }
563
564   $form->{DUNNING_PDFS} = [];
565
566   my $saved_language_id = $form->{language_id};
567   my $i = 0;
568   foreach my $dunning_id (@dunning_ids) {
569     if (!$form->{force_lang}) {
570       $form->{language_id} = $language_ids[$i];
571     }
572     $form->{dunning_id} = $dunning_id;
573     DN->print_invoice_for_fees(\%myconfig, $form, $dunning_id);
574     DN->print_dunning(\%myconfig, $form, $dunning_id);
575
576     # print original dunned invoices, if they where printed on dunning run
577     my $dunnings = SL::DB::Manager::Dunning->get_all(where => [dunning_id => $dunning_id, original_invoice_printed => 1]);
578     DN->print_original_invoice(\%myconfig, $form, $dunning_id, $_->trans_id) for @$dunnings;
579
580     $i++;
581   }
582   $form->{language_id} = $saved_language_id;
583
584   if (scalar @{ $form->{DUNNING_PDFS} }) {
585     $form->{dunning_id} = strftime("%Y%m%d", localtime time) if scalar @{ $form->{DUNNING_PDFS}} > 1;
586     DN->melt_pdfs(\%myconfig, $form, $form->{copies});
587
588     if ($form->{media} eq 'printer') {
589       $form->header();
590       $form->info($locale->text('The dunnings have been printed.'));
591     }
592
593   } else {
594     $form->redirect($locale->text('Could not print dunning.'));
595   }
596
597   $main::lxdebug->leave_sub();
598 }
599
600 sub continue {
601   call_sub($main::form->{nextsub});
602 }
603
604 sub dispatcher {
605   foreach my $action (qw(delete print_multiple)) {
606     if ($::form->{"action_${action}"}) {
607       call_sub($action);
608       return;
609     }
610   }
611
612   $::form->error($::locale->text('No action defined.'));
613 }
614
615 sub setup_dn_add_action_bar {
616   my %params = @_;
617
618   for my $bar ($::request->layout->get('actionbar')) {
619     $bar->add(
620       action => [
621         t8('Search'),
622         submit    => [ '#form', { action => "show_invoices" } ],
623         accesskey => 'enter',
624       ],
625     );
626   }
627 }
628
629 sub setup_dn_show_invoices_action_bar {
630   my %params = @_;
631
632   for my $bar ($::request->layout->get('actionbar')) {
633     $bar->add(
634       action => [
635         t8('Create'),
636         submit    => [ '#form', { action => "save_dunning" } ],
637         checks    => [ [ 'kivi.check_if_entries_selected', '[name^=active_]' ] ],
638         accesskey => 'enter',
639         only_once => 1,
640       ],
641     );
642   }
643 }
644
645 sub setup_dn_search_action_bar {
646   my %params = @_;
647
648   for my $bar ($::request->layout->get('actionbar')) {
649     $bar->add(
650       action => [
651         t8('Search'),
652         submit    => [ '#form', { action => "show_dunning" } ],
653         accesskey => 'enter',
654       ],
655     );
656   }
657 }
658
659 sub setup_dn_show_dunning_action_bar {
660   my %params = @_;
661
662   for my $bar ($::request->layout->get('actionbar')) {
663     $bar->add(
664       action => [
665         t8('Print'),
666         submit    => [ '#form', { action => "print_multiple" } ],
667         checks    => [ [ 'kivi.check_if_entries_selected', '[name^=selected_]' ] ],
668         accesskey => 'enter',
669       ],
670
671       action => [
672         t8('Delete'),
673         submit  => [ '#form', { action => "delete" } ],
674         checks  => [ [ 'kivi.check_if_entries_selected', '[name^=selected_]' ] ],
675         confirm => $::locale->text('This resets the dunning process for the selected invoices. Posted dunning invoices will not be changed!'),
676       ],
677     );
678   }
679 }
680
681 sub setup_dn_edit_config_action_bar {
682   my %params = @_;
683
684   for my $bar ($::request->layout->get('actionbar')) {
685     $bar->add(
686       action => [
687         t8('Save'),
688         submit    => [ '#form', { action => "save" } ],
689         accesskey => 'enter',
690       ],
691     );
692   }
693 }
694
695 # end of main