]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/CsvImport/BankTransaction.pm
kivitendo 3.9.2-0.2
[mfinanz.git] / SL / Controller / CsvImport / BankTransaction.pm
index 77063738c63c3a59113f565db731b0510c1ffaa5..1d447a34a6208fa0eafea32b8a19df6857e0f24f 100644 (file)
@@ -50,6 +50,7 @@ sub check_objects {
     $self->check_currency($entry, take_default => 1);
     $self->join_purposes($entry);
     $self->join_remote_names($entry);
+    $self->extract_end_to_end_id($entry);
     $self->check_existing($entry) unless @{ $entry->{errors} };
   } continue {
     $i++;
@@ -57,6 +58,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 };
+  $self->add_info_columns({ header => $::locale->text('End to end ID'), method => 'end_to_end_id' });
 }
 
 sub check_existing {
@@ -76,7 +78,16 @@ sub check_existing {
     # * amount
     # * local_bank_account_id (case flatrate bank charges for two accounts in one bank: same purpose, transdate, remote_account_number(empty), amount. Just different local_bank_account_id)
     my $num;
-    if ( $num = SL::DB::Manager::BankTransaction->get_all_count(query =>[ remote_account_number => $object->remote_account_number, transdate => $object->transdate, purpose => $object->purpose, amount => $object->amount, local_bank_account_id => $object->local_bank_account_id] ) ) {
+
+    my @conditions;
+
+    if ($object->end_to_end_id && $::instance_conf->get_check_bt_duplicates_endtoend) {
+      push @conditions, ( end_to_end_id => $object->end_to_end_id );
+    } else {
+      push @conditions, ( purpose => $object->purpose );
+    }
+
+    if ( $num = SL::DB::Manager::BankTransaction->get_all_count(query =>[ remote_account_number => $object->remote_account_number, transdate => $object->transdate, amount => $object->amount, local_bank_account_id => $object->local_bank_account_id, @conditions] ) ) {
       push(@{$entry->{errors}}, $::locale->text('Skipping due to existing bank transaction in database'));
     };
   } else {
@@ -111,7 +122,8 @@ sub _displayable_columns {
    { name => 'purpose10',             description => $::locale->text('Purpose (if field names purpose, purpose1, purpose2 ... exist they will all combined into the field "purpose")') },
    { name => 'purpose11',             description => $::locale->text('Purpose (if field names purpose, purpose1, purpose2 ... exist they will all combined into the field "purpose")') },
    { name => 'purpose12',             description => $::locale->text('Purpose (if field names purpose, purpose1, purpose2 ... exist they will all combined into the field "purpose")') },
-   { name => 'purpose13',             description => $::locale->text('Purpose (if field names purpose, purpose1, purpose2 ... exist they will all combined into the field "purpose")') }
+   { name => 'purpose13',             description => $::locale->text('Purpose (if field names purpose, purpose1, purpose2 ... exist they will all combined into the field "purpose")') },
+   { name => 'qr_reference',          description => $::locale->text('QR reference') }
  );
 }
 
@@ -167,6 +179,13 @@ sub check_bank_account {
     $object->local_bank_account_id($bank_account->id);
     $entry->{info_data}->{local_bank_name} = $bank_account->name;
   }
+
+  # Check if local bank account is marked for bank import
+  if ($object->local_bank_account_id && !$self->bank_accounts_by->{id}->{ $object->local_bank_account_id }->use_with_bank_import) {
+    push @{ $entry->{errors} }, $::locale->text('Error: local bank account is not marked for bank import, check settings under System -> Bank Accounts');
+    return 0;
+  }
+
   return $object->local_bank_account_id ? 1 : 0;
 }
 
@@ -195,6 +214,19 @@ sub join_remote_names {
   $object->remote_name($remote_name);
 }
 
+sub extract_end_to_end_id {
+  my ($self, $entry) = @_;
+
+  my $object = $entry->{object};
+
+  return if $object->purpose !~ m{\b(?:end\W?to\W?end:|eref\+) *([^ ]+)}i;
+
+  my $id = $1;
+
+  $object->end_to_end_id($id) if $id !~ m{notprovided}i;
+  $entry->{info_data}->{end_to_end_id} = $object->end_to_end_id;
+}
+
 sub check_auth {
   $::auth->assert('config') if ! $::auth->assert('bank_transaction',1);
 }