+sub _existing_record_link {
+ my ($bt, $invoice) = @_;
+
+ # check whether a record link from banktransaction $bt already exists to
+ # invoice $invoice, returns 1 if that is the case
+
+ die unless $bt->isa("SL::DB::BankTransaction") && ( $invoice->isa("SL::DB::Invoice") || $invoice->isa("SL::DB::PurchaseInvoice") );
+
+ my $linked_record_to_table = $invoice->is_sales ? 'Invoice' : 'PurchaseInvoice';
+ my $linked_records = $bt->linked_records( direction => 'to', to => $linked_record_to_table, query => [ id => $invoice->id ] );
+
+ return @$linked_records ? 1 : 0;
+};
+
+