From e61601fdd7dbddca1778845d25fd88c13ebe42ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Wed, 9 Sep 2020 12:25:29 +0300 Subject: [PATCH] BankTransaction: Find reference numbers with any length from description --- app/models/bank_transaction.rb | 5 +++-- app/models/billing/reference_no.rb | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index 69cf6fc2a..76ed9ae27 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -121,7 +121,8 @@ class BankTransaction < ApplicationRecord end def ref_number_from_description - match_data = /(\d{7})/.match(description) - match_data[0] if match_data.present? + (Billing::ReferenceNo::MULTI_REGEXP.match(description) || []).captures.each do |match| + break match if match.length == 7 || Registrar.where(reference_no: match).present? + end end end diff --git a/app/models/billing/reference_no.rb b/app/models/billing/reference_no.rb index 23812214c..849c06b85 100644 --- a/app/models/billing/reference_no.rb +++ b/app/models/billing/reference_no.rb @@ -1,6 +1,7 @@ module Billing class ReferenceNo REGEXP = /\A\d{2,20}\z/ + MULTI_REGEXP = /(\d{2,20})/ def self.generate base = Base.generate