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