GL: single-dbh
[kivitendo-erp.git] / SL / Controller / CsvImport / BankTransaction.pm
index 76e9020..5be8968 100644 (file)
@@ -15,6 +15,15 @@ use Rose::Object::MakeMethods::Generic
  'scalar --get_set_init' => [ qw(bank_accounts_by) ],
 );
 
+sub set_profile_defaults {
+  my ($self) = @_;
+
+  $self->controller->profile->_set_defaults(
+                       charset       => 'UTF8',  # override charset from defaults
+                       update_policy => 'skip',
+                      );
+};
+
 sub init_class {
   my ($self) = @_;
   $self->class('SL::DB::BankTransaction');
@@ -47,6 +56,7 @@ sub check_objects {
   }
 
   $self->add_info_columns({ header => $::locale->text('Bank account'), method => 'local_bank_name' });
+  $self->add_raw_data_columns("currency", "currency_id") if grep { /^currency(?:_id)?$/ } @{ $self->csv->header };
 }
 
 sub check_existing {
@@ -99,9 +109,9 @@ sub check_bank_account {
 
   my $object = $entry->{object};
 
-  # Check whether or not local_bank_account ID exists and is valid.
+  # import via id: check whether or not local_bank_account ID exists and is valid.
   if ($object->local_bank_account_id && !$self->bank_accounts_by->{id}->{ $object->local_bank_account_id }) {
-    push @{ $entry->{errors} }, $::locale->text('Error: Invalid local bank account');
+    push @{ $entry->{errors} }, $::locale->text('Error: unknown local bank account id');
     return 0;
   }
 
@@ -109,11 +119,11 @@ sub check_bank_account {
   if ($object->local_bank_account_id && $entry->{raw_data}->{local_account_number}) {
     my $bank_account = $self->bank_accounts_by->{id}->{ $object->local_bank_account_id };
     if ($bank_account->account_number ne $entry->{raw_data}->{local_account_number}) {
-      push @{ $entry->{errors} }, $::locale->text('Error: Invalid local bank account');
+      push @{ $entry->{errors} }, $::locale->text('Error: local bank account id doesn\'t match local bank account number');
       return 0;
     }
     if ($entry->{raw_data}->{local_bank_code} && $entry->{raw_data}->{local_bank_code} ne $bank_account->bank_code) {
-      push @{ $entry->{errors} }, $::locale->text('Error: Invalid local bank account');
+      push @{ $entry->{errors} }, $::locale->text('Error: local bank account id doesn\'t match local bank code');
       return 0;
     }
 
@@ -127,11 +137,11 @@ sub check_bank_account {
        $bank_account = $self->bank_accounts_by->{iban}->{ $entry->{raw_data}->{local_account_number} };
     };
     if (!$bank_account) {
-      push @{ $entry->{errors} }, $::locale->text('Error: Invalid local bank account');
+      push @{ $entry->{errors} }, $::locale->text('Error: unknown local bank account') . ": " . $entry->{raw_data}->{local_account_number};
       return 0;
     }
     if ($entry->{raw_data}->{local_bank_code} && $entry->{raw_data}->{local_bank_code} ne $bank_account->bank_code) {
-      push @{ $entry->{errors} }, $::locale->text('Error: Invalid local bank account');
+      push @{ $entry->{errors} }, $::locale->text('Error: Found local bank account number but local bank code doesn\'t match') . ": " . $entry->{raw_data}->{local_bank_code};
       return 0;
     }