Merge branch 'master' of github.com:kivitendo/kivitendo-erp
[kivitendo-erp.git] / bin / mozilla / sepa.pl
index f6041fb..18f48b2 100755 (executable)
@@ -40,6 +40,13 @@ sub bank_transfer_add {
     return;
   }
 
+  # Only include those per default that require manual action from our
+  # side. For sales invoices these are the ones for which direct debit
+  # has been selected. For purchase invoices it's the other way
+  # around: if direct debit is active then the vendor will collect
+  # from us automatically and we don't have to send money manually.
+  $_->{checked} = ($vc eq 'customer' ? $_->{direct_debit} : !$_->{direct_debit}) for @{ $invoices };
+
   my $bank_account_label_sub = sub { $locale->text('Account number #1, bank code #2, #3', $_[0]->{account_number}, $_[0]->{bank_code}, $_[0]->{bank}) };
 
   my $translation_list = GenericTranslations->list(translation_type => 'sepa_remittance_info_pfx');
@@ -113,7 +120,7 @@ sub bank_transfer_create {
   }
 
   if ($error_message || !$form->{confirmation}) {
-    my @vc_ids                 = uniq map { $_->{"${vc}_id"} } @bank_transfers;
+    my @vc_ids                 = uniq map { $_->{vc_id} } @bank_transfers;
     $vc_bank_info            ||= CT->get_bank_info('vc' => $vc,
                                                    'id' => \@vc_ids);
     my @vc_bank_info           = sort { lc $a->{name} cmp lc $b->{name} } values %{ $vc_bank_info };
@@ -136,7 +143,7 @@ sub bank_transfer_create {
   } else {
     foreach my $bank_transfer (@bank_transfers) {
       foreach (qw(iban bic)) {
-        $bank_transfer->{"vc_${_}"}  = $vc_bank_info->{ $bank_transfer->{"${vc}_id"} }->{$_};
+        $bank_transfer->{"vc_${_}"}  = $vc_bank_info->{ $bank_transfer->{vc_id} }->{$_};
         $bank_transfer->{"our_${_}"} = $bank_account->{$_};
       }
 
@@ -176,7 +183,7 @@ sub bank_transfer_list {
 
   my $form   = $main::form;
   my $locale = $main::locale;
-  my $cgi    = $main::cgi;
+  my $cgi    = $::request->{cgi};
   my $vc     = $form->{vc} eq 'customer' ? 'customer' : 'vendor';
 
   $form->{title}     = $vc eq 'customer' ? $::locale->text('List of bank collections') : $locale->text('List of bank transfers');
@@ -248,6 +255,7 @@ sub bank_transfer_list {
                        'attachment_basename'   => $locale->text('banktransfers') . strftime('_%Y%m%d', localtime time),
     );
   $report->set_options_from_form();
+  $locale->set_numberformat_wo_thousands_separator(\%::myconfig) if lc($report->{options}->{output_format}) eq 'csv';
 
   $report->set_columns(%column_defs);
   $report->set_column_order(@columns);
@@ -442,7 +450,7 @@ sub bank_transfer_download_sepa_xml {
   my $form     =  $main::form;
   my $myconfig = \%main::myconfig;
   my $locale   =  $main::locale;
-  my $cgi      =  $main::cgi;
+  my $cgi      =  $::request->{cgi};
   my $vc       = $form->{vc} eq 'customer' ? 'customer' : 'vendor';
 
   if (!$myconfig->{company}) {
@@ -480,7 +488,7 @@ sub bank_transfer_download_sepa_xml {
 
   my $sepa_xml   = SL::SEPA::XML->new('company'     => $myconfig->{company},
                                       'creditor_id' => $myconfig->{sepa_creditor_id},
-                                      'src_charset' => $main::dbcharset || 'ISO-8859-15',
+                                      'src_charset' => $::lx_office_conf{system}->{dbcharset} || 'ISO-8859-15',
                                       'message_id'  => $message_id,
                                       'grouped'     => 1,
                                       'collection'  => $vc eq 'customer',
@@ -503,6 +511,7 @@ sub bank_transfer_download_sepa_xml {
                                  'dst_iban'       => $item->{vc_iban},
                                  'dst_bic'        => $item->{vc_bic},
                                  'company'        => $item->{vc_name},
+                                 'company_number' => $item->{vc_number},
                                  'amount'         => $item->{amount},
                                  'reference'      => $item->{reference},
                                  'reference_date' => $item->{reference_date},