Unterstützung für die XML-Ausgabe von Lastschriften
[kivitendo-erp.git] / bin / mozilla / sepa.pl
1 use strict;
2
3 use List::MoreUtils qw(any none uniq);
4 use List::Util qw(first);
5 use POSIX qw(strftime);
6
7 use SL::BankAccount;
8 use SL::Chart;
9 use SL::CT;
10 use SL::Form;
11 use SL::ReportGenerator;
12 use SL::SEPA;
13 use SL::SEPA::XML;
14
15 require "bin/mozilla/common.pl";
16 require "bin/mozilla/reportgenerator.pl";
17
18 sub bank_transfer_add {
19   $main::lxdebug->enter_sub();
20
21   my $form          = $main::form;
22   my $locale        = $main::locale;
23   my $vc            = $form->{vc} eq 'customer' ? 'customer' : 'vendor';
24
25   $form->{title}    = $vc eq 'customer' ? $::locale->text('Prepare bank collection via SEPA XML') : $locale->text('Prepare bank transfer via SEPA XML');
26
27   my $bank_accounts = SL::BankAccount->list();
28
29   if (!scalar @{ $bank_accounts }) {
30     $form->error($locale->text('You have not added bank accounts yet.'));
31   }
32
33   my $invoices = SL::SEPA->retrieve_open_invoices(vc => $vc);
34
35   if (!scalar @{ $invoices }) {
36     $form->show_generic_information($locale->text('Either there are no open invoices, or you have already initiated bank transfers ' .
37                                                   'with the open amounts for those that are still open.'));
38     $main::lxdebug->leave_sub();
39     return;
40   }
41
42   my $bank_account_label_sub = sub { $locale->text('Account number #1, bank code #2, #3', $_[0]->{account_number}, $_[0]->{bank_code}, $_[0]->{bank}) };
43
44   $form->header();
45   print $form->parse_html_template('sepa/bank_transfer_add',
46                                    { 'INVOICES'           => $invoices,
47                                      'BANK_ACCOUNTS'      => $bank_accounts,
48                                      'bank_account_label' => $bank_account_label_sub,
49                                      'vc'                 => $vc,
50                                    });
51
52   $main::lxdebug->leave_sub();
53 }
54
55 sub bank_transfer_create {
56   $main::lxdebug->enter_sub();
57
58   my $form          = $main::form;
59   my $locale        = $main::locale;
60   my $myconfig      = \%main::myconfig;
61   my $vc            = $form->{vc} eq 'customer' ? 'customer' : 'vendor';
62
63   $form->{title}    = $vc eq 'customer' ? $::locale->text('Create bank collection via SEPA XML') : $locale->text('Create bank transfer via SEPA XML');
64
65   my $bank_accounts = SL::BankAccount->list();
66
67   if (!scalar @{ $bank_accounts }) {
68     $form->error($locale->text('You have not added bank accounts yet.'));
69   }
70
71   my $bank_account = first { $form->{bank_account}->{id} == $_->{id} } @{ $bank_accounts };
72
73   if (!$bank_account) {
74     $form->error($locale->text('The selected bank account does not exist anymore.'));
75   }
76
77   my $arap_id        = $vc eq 'customer' ? 'ar_id' : 'ap_id';
78   my $invoices       = SL::SEPA->retrieve_open_invoices(vc => $vc);
79
80   my %invoices_map   = map { $_->{id} => $_ } @{ $invoices };
81   my @bank_transfers =
82     map  +{ %{ $invoices_map{ $_->{$arap_id} } }, %{ $_ } },
83     grep  { $_->{selected} && (0 < $_->{amount}) && $invoices_map{ $_->{$arap_id} } }
84     map   { $_->{amount} = $form->parse_amount($myconfig, $_->{amount}); $_ }
85           @{ $form->{bank_transfers} || [] };
86
87   if (!scalar @bank_transfers) {
88     $form->error($locale->text('You have selected none of the invoices.'));
89   }
90
91   my ($vc_bank_info);
92   my $error_message;
93
94   if ($form->{confirmation}) {
95     $vc_bank_info = { map { $_->{id} => $_ } @{ $form->{vc_bank_info} || [] } };
96
97     foreach my $info (values %{ $vc_bank_info }) {
98       if (any { !$info->{$_} } qw(iban bic)) {
99         $error_message = $locale->text('The bank information must not be empty.');
100         last;
101       }
102     }
103   }
104
105   if ($error_message || !$form->{confirmation}) {
106     my @vc_ids                 = uniq map { $_->{"${vc}_id"} } @bank_transfers;
107     $vc_bank_info            ||= CT->get_bank_info('vc' => $vc,
108                                                    'id' => \@vc_ids);
109     my @vc_bank_info           = sort { lc $a->{name} cmp lc $b->{name} } values %{ $vc_bank_info };
110
111     my $bank_account_label_sub = sub { $locale->text('Account number #1, bank code #2, #3', $_[0]->{account_number}, $_[0]->{bank_code}, $_[0]->{bank}) };
112
113     $form->{jsscript}          = 1;
114
115     $form->header();
116     print $form->parse_html_template('sepa/bank_transfer_create',
117                                      { 'BANK_TRANSFERS'     => \@bank_transfers,
118                                        'BANK_ACCOUNTS'      => $bank_accounts,
119                                        'VC_BANK_INFO'       => \@vc_bank_info,
120                                        'bank_account'       => $bank_account,
121                                        'bank_account_label' => $bank_account_label_sub,
122                                        'error_message'      => $error_message,
123                                        'vc'                 => $vc,
124                                      });
125
126   } else {
127     foreach my $bank_transfer (@bank_transfers) {
128       foreach (qw(iban bic)) {
129         $bank_transfer->{"vc_${_}"}  = $vc_bank_info->{ $bank_transfer->{"${vc}_id"} }->{$_};
130         $bank_transfer->{"our_${_}"} = $bank_account->{$_};
131       }
132
133       $bank_transfer->{chart_id} = $bank_account->{chart_id};
134     }
135
136     my $id = SL::SEPA->create_export('employee'       => $form->{login},
137                                      'bank_transfers' => \@bank_transfers,
138                                      'vc'             => $vc);
139
140     $form->header();
141     print $form->parse_html_template('sepa/bank_transfer_created', { 'id' => $id, 'vc' => $vc });
142   }
143
144   $main::lxdebug->leave_sub();
145 }
146
147 sub bank_transfer_search {
148   $main::lxdebug->enter_sub();
149
150   my $form   = $main::form;
151   my $locale = $main::locale;
152   my $vc     = $form->{vc} eq 'customer' ? 'customer' : 'vendor';
153
154   $form->{title}    = $vc eq 'customer' ? $::locale->text('List of bank collections') : $locale->text('List of bank transfers');
155   $form->{jsscript} = 1;
156
157   $form->header();
158   print $form->parse_html_template('sepa/bank_transfer_search', { vc => $vc });
159
160   $main::lxdebug->leave_sub();
161 }
162
163
164 sub bank_transfer_list {
165   $main::lxdebug->enter_sub();
166
167   my $form   = $main::form;
168   my $locale = $main::locale;
169   my $cgi    = $main::cgi;
170   my $vc     = $form->{vc} eq 'customer' ? 'customer' : 'vendor';
171
172   $form->{title}     = $vc eq 'customer' ? $::locale->text('List of bank collections') : $locale->text('List of bank transfers');
173
174   $form->{sort}    ||= 'id';
175   $form->{sortdir}   = '1' if (!defined $form->{sortdir});
176
177   $form->{callback}  = build_std_url('action=bank_transfer_list', 'sort', 'sortdir', 'vc');
178
179   my %filter         = map  +( $_ => $form->{"f_${_}"} ),
180                        grep  { $form->{"f_${_}"} }
181                              (qw(vc invnumber),
182                               map { ("${_}_date_from", "${_}_date_to") }
183                                   qw(export requested_execution execution));
184   $filter{executed}  = $form->{l_executed} ? 1 : 0 if ($form->{l_executed} != $form->{l_not_executed});
185   $filter{closed}    = $form->{l_closed}   ? 1 : 0 if ($form->{l_open}     != $form->{l_closed});
186
187   my $exports        = SL::SEPA->list_exports('filter'    => \%filter,
188                                               'sortorder' => $form->{sort},
189                                               'sortdir'   => $form->{sortdir},
190                                               'vc'        => $vc);
191
192   my $open_available = any { !$_->{closed} } @{ $exports };
193
194   my $report         = SL::ReportGenerator->new(\%main::myconfig, $form);
195
196   my @hidden_vars    = ('vc', grep { m/^[fl]_/ && $form->{$_} } keys %{ $form });
197
198   my $href           = build_std_url('action=bank_transfer_list', @hidden_vars);
199
200   my %column_defs = (
201     'selected'    => { 'text' => $cgi->checkbox(-name => 'select_all', -id => 'select_all', -label => ''), },
202     'id'          => { 'text' => $locale->text('Number'), },
203     'export_date' => { 'text' => $locale->text('Export date'), },
204     'employee'    => { 'text' => $locale->text('Employee'), },
205     'executed'    => { 'text' => $locale->text('Executed'), },
206     'closed'      => { 'text' => $locale->text('Closed'), },
207   );
208
209   my @columns = qw(selected id export_date employee executed closed);
210
211   foreach my $name (qw(id export_date employee executed closed)) {
212     my $sortdir                 = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
213     $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
214   }
215
216   $column_defs{selected}->{visible} = $open_available                                ? 'HTML' : 0;
217   $column_defs{executed}->{visible} = $form->{l_executed} && $form->{l_not_executed} ? 1 : 0;
218   $column_defs{closed}->{visible}   = $form->{l_closed}   && $form->{l_open}         ? 1 : 0;
219
220   my @options = ();
221   push @options, ($vc eq 'customer' ? $::locale->text('Customer') : $locale->text('Vendor')) . ' : ' . $form->{f_vc} if ($form->{f_vc});
222   push @options, $locale->text('Invoice number')                . ' : ' . $form->{f_invnumber}                     if ($form->{f_invnumber});
223   push @options, $locale->text('Export date from')              . ' : ' . $form->{f_export_date_from}              if ($form->{f_export_date_from});
224   push @options, $locale->text('Export date to')                . ' : ' . $form->{f_export_date_to}                if ($form->{f_export_date_to});
225   push @options, $locale->text('Requested execution date from') . ' : ' . $form->{f_requested_execution_date_from} if ($form->{f_requested_execution_date_from});
226   push @options, $locale->text('Requested execution date to')   . ' : ' . $form->{f_requested_execution_date_to}   if ($form->{f_requested_execution_date_to});
227   push @options, $locale->text('Execution date from')           . ' : ' . $form->{f_execution_date_from}           if ($form->{f_execution_date_from});
228   push @options, $locale->text('Execution date to')             . ' : ' . $form->{f_execution_date_to}             if ($form->{f_execution_date_to});
229   push @options, $form->{l_executed} ? $locale->text('executed') : $locale->text('not yet executed')               if ($form->{l_executed} != $form->{l_not_executed});
230   push @options, $form->{l_closed}   ? $locale->text('closed')   : $locale->text('open')                           if ($form->{l_open}     != $form->{l_closed});
231
232   $report->set_options('top_info_text'         => join("\n", @options),
233                        'raw_top_info_text'     => $form->parse_html_template('sepa/bank_transfer_list_top'),
234                        'raw_bottom_info_text'  => $form->parse_html_template('sepa/bank_transfer_list_bottom', { 'show_buttons' => $open_available, vc => $vc }),
235                        'std_column_visibility' => 1,
236                        'output_format'         => 'HTML',
237                        'title'                 => $form->{title},
238                        'attachment_basename'   => $locale->text('banktransfers') . strftime('_%Y%m%d', localtime time),
239     );
240   $report->set_options_from_form();
241
242   $report->set_columns(%column_defs);
243   $report->set_column_order(@columns);
244   $report->set_export_options('bank_transfer_list', @hidden_vars);
245   $report->set_sort_indicator($form->{sort}, $form->{sortdir});
246
247   my $edit_url = build_std_url('action=bank_transfer_edit', 'callback');
248
249   foreach my $export (@{ $exports }) {
250     my $row = { map { $_ => { 'data' => $export->{$_} } } keys %{ $export } };
251
252     map { $row->{$_}->{data} = $export->{$_} ? $locale->text('yes') : $locale->text('no') } qw(executed closed);
253
254     $row->{id}->{link} = $edit_url . '&id=' . E($export->{id}) . '&vc=' . E($vc);
255
256     if (!$export->{closed}) {
257       $row->{selected}->{raw_data} =
258           $cgi->hidden(-name => "exports[+].id", -value => $export->{id})
259         . $cgi->checkbox(-name => "exports[].selected", -value => 1, -label => '');
260     }
261
262     $report->add_data($row);
263   }
264
265   $report->generate_with_headers();
266
267   $main::lxdebug->leave_sub();
268 }
269
270 sub bank_transfer_edit {
271   $main::lxdebug->enter_sub();
272
273   my $form   = $main::form;
274   my $locale = $main::locale;
275   my $vc     = $form->{vc} eq 'customer' ? 'customer' : 'vendor';
276
277   my @ids    = ();
278   if (!$form->{mode} || ($form->{mode} eq 'single')) {
279     push @ids, $form->{id};
280   } else {
281     @ids = map $_->{id}, grep { $_->{selected} } @{ $form->{exports} || [] };
282
283     if (!@ids) {
284       $form->show_generic_error($locale->text('You have not selected any export.'), 'back_button' => 1);
285     }
286   }
287
288   my $export;
289
290   foreach my $id (@ids) {
291     my $curr_export = SL::SEPA->retrieve_export('id' => $id, 'details' => 1, 'vc' => $vc);
292
293     foreach my $item (@{ $curr_export->{items} }) {
294       map { $item->{"export_${_}"} = $curr_export->{$_} } grep { !ref $curr_export->{$_} } keys %{ $curr_export };
295     }
296
297     if (!$export) {
298       $export = $curr_export;
299     } else {
300       push @{ $export->{items} }, @{ $curr_export->{items} };
301     }
302   }
303
304   if ($form->{mode} && ($form->{mode} eq 'multi')) {
305     $export->{items} = [ grep { !$_->{export_closed} && !$_->{executed} } @{ $export->{items} } ];
306
307     if (!@{ $export->{items} }) {
308       $form->show_generic_error($locale->text('All the selected exports have already been closed, or all of their items have already been executed.'), 'back_button' => 1);
309     }
310
311   } elsif (!$export) {
312     $form->error($locale->text('That export does not exist.'));
313   }
314
315   $form->{jsscript} = 1;
316   $form->{title}    = $locale->text('View SEPA export');
317   $form->header();
318   print $form->parse_html_template('sepa/bank_transfer_edit',
319                                    { 'ids'                       => \@ids,
320                                      'export'                    => $export,
321                                      'current_date'              => $form->current_date(\%main::myconfig),
322                                      'show_post_payments_button' => any { !$_->{export_closed} && !$_->{executed} } @{ $export->{items} },
323                                    });
324
325   $main::lxdebug->leave_sub();
326 }
327
328 sub bank_transfer_post_payments {
329   $main::lxdebug->enter_sub();
330
331   my $form   = $main::form;
332   my $locale = $main::locale;
333   my $vc     = $form->{vc} eq 'customer' ? 'customer' : 'vendor';
334
335   my @items  = grep { $_->{selected} } @{ $form->{items} || [] };
336
337   if (!@items) {
338     $form->show_generic_error($locale->text('You have not selected any item.'), 'back_button' => 1);
339   }
340   my @export_ids    = uniq map { $_->{sepa_export_id} } @items;
341   my %exports       = map { $_ => SL::SEPA->retrieve_export('id' => $_, 'details' => 1, vc => $vc) } @export_ids;
342   my @items_to_post = ();
343
344   foreach my $item (@items) {
345     my $export = $exports{ $item->{sepa_export_id} };
346     next if (!$export || $export->{closed} || $export->{executed});
347
348     push @items_to_post, $item if (none { ($_->{id} == $item->{id}) && $_->{executed} } @{ $export->{items} });
349   }
350
351   if (!@items_to_post) {
352     $form->show_generic_error($locale->text('All the selected exports have already been closed, or all of their items have already been executed.'), 'back_button' => 1);
353   }
354
355   if (any { !$_->{execution_date} } @items_to_post) {
356     $form->show_generic_error($locale->text('You have to specify an execution date for each antry.'), 'back_button' => 1);
357   }
358
359   SL::SEPA->post_payment('items' => \@items_to_post, vc => $vc);
360
361   $form->show_generic_information($locale->text('The payments have been posted.'));
362
363   $main::lxdebug->leave_sub();
364 }
365
366 sub bank_transfer_payment_list_as_pdf {
367   $main::lxdebug->enter_sub();
368
369   my $form       = $main::form;
370   my %myconfig   = %main::myconfig;
371   my $locale     = $main::locale;
372   my $vc         = $form->{vc} eq 'customer' ? 'customer' : 'vendor';
373
374   my @ids        = @{ $form->{items} || [] };
375   my @export_ids = uniq map { $_->{export_id} } @ids;
376
377   $form->show_generic_error($locale->text('Multi mode not supported.'), 'back_button' => 1) if 1 != scalar @export_ids;
378
379   my $export = SL::SEPA->retrieve_export('id' => $export_ids[0], 'details' => 1, vc => $vc);
380   my @items  = ();
381
382   foreach my $id (@ids) {
383     my $item = first { $_->{id} == $id->{id} } @{ $export->{items} };
384     push @items, $item if $item;
385   }
386
387   $form->show_generic_error($locale->text('No transfers were executed in this export.'), 'back_button' => 1) if 1 > scalar @items;
388
389   my $report         =  SL::ReportGenerator->new(\%main::myconfig, $form);
390
391   my %column_defs    =  (
392     'invnumber'      => { 'text' => $locale->text('Invoice'),                                                                  },
393     'vc_name'        => { 'text' => $vc eq 'customer' ? $locale->text('Customer')         : $locale->text('Vendor'),           },
394     'our_iban'       => { 'text' => $vc eq 'customer' ? $locale->text('Destination IBAN') : $locale->text('Source IBAN'),      },
395     'our_bic'        => { 'text' => $vc eq 'customer' ? $locale->text('Destination BIC')  : $locale->text('Source BIC'),       },
396     'vc_iban'        => { 'text' => $vc eq 'customer' ? $locale->text('Source IBAN')      : $locale->text('Destination IBAN'), },
397     'vc_bic'         => { 'text' => $vc eq 'customer' ? $locale->text('Source BIC')       : $locale->text('Destination BIC'),  },
398     'amount'         => { 'text' => $locale->text('Amount'),                                                                   },
399     'reference'      => { 'text' => $locale->text('Reference'),                                                                },
400     'execution_date' => { 'text' => $locale->text('Execution date'),                                                           },
401   );
402
403   map { $column_defs{$_}->{align} = 'right' } qw(amount execution_date);
404
405   my @columns        =  qw(invnumber vc_name our_iban our_bic vc_iban vc_bic amount reference execution_date);
406
407   $report->set_options('std_column_visibility' => 1,
408                        'output_format'         => 'PDF',
409                        'title'                 =>  $vc eq 'customer' ? $locale->text('Bank collection payment list for export #1', $export->{id}) : $locale->text('Bank transfer payment list for export #1', $export->{id}),
410                        'attachment_basename'   => ($vc eq 'customer' ? $locale->text('bank_collection_payment_list_#1', $export->{id}) : $locale->text('bank_transfer_payment_list_#1', $export->{id})) . strftime('_%Y%m%d', localtime time),
411     );
412
413   $report->set_columns(%column_defs);
414   $report->set_column_order(@columns);
415
416   foreach my $item (@items) {
417     my $row                = { map { $_ => { 'data' => $item->{$_} } } @columns };
418     $row->{amount}->{data} = $form->format_amount(\%myconfig, $item->{amount}, 2);
419
420     $report->add_data($row);
421   }
422
423   $report->generate_with_headers();
424
425   $main::lxdebug->leave_sub();
426 }
427
428 # TODO
429 sub bank_transfer_download_sepa_xml {
430   $main::lxdebug->enter_sub();
431
432   my $form     =  $main::form;
433   my $myconfig = \%main::myconfig;
434   my $locale   =  $main::locale;
435   my $cgi      =  $main::cgi;
436   my $vc       = $form->{vc} eq 'customer' ? 'customer' : 'vendor';
437
438   if (!$myconfig->{company}) {
439     $form->show_generic_error($locale->text('You have to enter a company name in your user preferences (see the "Program" menu, "Preferences").'), 'back_button' => 1);
440   }
441
442   if (($vc eq 'customer') && !$myconfig->{sepa_creditor_id}) {
443     $form->show_generic_error($locale->text('You have to enter the SEPA creditor ID in your user preferences (see the "Program" menu, "Preferences").'), 'back_button' => 1);
444   }
445
446   my @ids;
447   if ($form->{mode} && ($form->{mode} eq 'multi')) {
448      @ids = map $_->{id}, grep { $_->{selected} } @{ $form->{exports} || [] };
449
450   } else {
451     @ids = ($form->{id});
452   }
453
454   if (!@ids) {
455     $form->show_generic_error($locale->text('You have not selected any export.'), 'back_button' => 1);
456   }
457
458   my @items = ();
459
460   foreach my $id (@ids) {
461     my $export = SL::SEPA->retrieve_export('id' => $id, 'details' => 1, vc => $vc);
462     push @items, grep { !$_->{executed} } @{ $export->{items} } if ($export && !$export->{closed});
463   }
464
465   if (!@items) {
466     $form->show_generic_error($locale->text('All the selected exports have already been closed, or all of their items have already been executed.'), 'back_button' => 1);
467   }
468
469   my $message_id = strftime('MSG%Y%m%d%H%M%S', localtime) . sprintf('%06d', $$);
470
471   my $sepa_xml   = SL::SEPA::XML->new('company'     => $myconfig->{company},
472                                       'creditor_id' => $myconfig->{sepa_creditor_id},
473                                       'src_charset' => $main::dbcharset || 'ISO-8859-15',
474                                       'message_id'  => $message_id,
475                                       'grouped'     => 1,
476                                       'collection'  => $vc eq 'customer',
477     );
478
479   foreach my $item (@items) {
480     my $requested_execution_date;
481     if ($item->{requested_execution_date}) {
482       my ($yy, $mm, $dd)        = $locale->parse_date($myconfig, $item->{requested_execution_date});
483       $requested_execution_date = sprintf '%04d-%02d-%02d', $yy, $mm, $dd;
484     }
485
486     if ($vc eq 'customer') {
487       my ($yy, $mm, $dd)      = $locale->parse_date($myconfig, $item->{reference_date});
488       $item->{reference_date} = sprintf '%04d-%02d-%02d', $yy, $mm, $dd;
489     }
490
491     $sepa_xml->add_transaction({ 'src_iban'       => $item->{our_iban},
492                                  'src_bic'        => $item->{our_bic},
493                                  'dst_iban'       => $item->{vc_iban},
494                                  'dst_bic'        => $item->{vc_bic},
495                                  'company'        => $item->{vc_name},
496                                  'amount'         => $item->{amount},
497                                  'reference'      => $item->{reference},
498                                  'reference_date' => $item->{reference_date},
499                                  'execution_date' => $requested_execution_date,
500                                  'end_to_end_id'  => $item->{end_to_end_id} });
501   }
502
503   my $xml = $sepa_xml->to_xml();
504
505   print $cgi->header('-type'                => 'application/octet-stream',
506                      '-content-disposition' => 'attachment; filename="SEPA_' . $message_id . ($vc eq 'customer' ? '.cdd' : '.cct') . '"',
507                      '-content-length'      => length $xml);
508   print $xml;
509
510   $main::lxdebug->leave_sub();
511 }
512
513 sub bank_transfer_mark_as_closed_step1 {
514   $main::lxdebug->enter_sub();
515
516   my $form       = $main::form;
517   my $locale     = $main::locale;
518   my $vc         = $form->{vc} eq 'customer' ? 'customer' : 'vendor';
519
520   my @export_ids = map { $_->{id} } grep { $_->{selected} } @{ $form->{exports} || [] };
521
522   if (!@export_ids) {
523     $form->show_generic_error($locale->text('You have not selected any export.'), 'back_button' => 1);
524   }
525
526   my @open_export_ids = ();
527   foreach my $id (@export_ids) {
528     my $export = SL::SEPA->retrieve_export('id' => $id, vc => $vc);
529     push @open_export_ids, $id if (!$export->{closed});
530   }
531
532   if (!@open_export_ids) {
533     $form->show_generic_error($locale->text('All of the exports you have selected were already closed.'), 'back_button' => 1);
534   }
535
536   $form->{title} = $locale->text('Close SEPA exports');
537   $form->header();
538   print $form->parse_html_template('sepa/bank_transfer_mark_as_closed_step1', { 'OPEN_EXPORT_IDS' => \@open_export_ids, vc => $vc });
539
540   $main::lxdebug->leave_sub();
541 }
542
543 sub bank_transfer_mark_as_closed_step2 {
544   $main::lxdebug->enter_sub();
545
546   my $form       = $main::form;
547   my $locale     = $main::locale;
548
549   map { SL::SEPA->close_export('id' => $_); } @{ $form->{open_export_ids} || [] };
550
551   $form->{title} = $locale->text('Close SEPA exports');
552   $form->header();
553   $form->show_generic_information($locale->text('The selected exports have been closed.'));
554
555   $main::lxdebug->leave_sub();
556 }
557
558 sub dispatcher {
559   my $form = $main::form;
560
561   foreach my $action (qw(bank_transfer_create bank_transfer_edit bank_transfer_list
562                          bank_transfer_post_payments bank_transfer_download_sepa_xml
563                          bank_transfer_mark_as_closed_step1 bank_transfer_mark_as_closed_step2
564                          bank_transfer_payment_list_as_pdf)) {
565     if ($form->{"action_${action}"}) {
566       call_sub($action);
567       return;
568     }
569   }
570
571   $form->error($main::locale->text('No action defined.'));
572 }
573
574 1;