mirror of
https://github.com/internetee/registry.git
synced 2025-08-01 15:34:41 +02:00
Binding interface for bank statements
This commit is contained in:
parent
2dfa65645b
commit
851e5368eb
15 changed files with 113 additions and 26 deletions
|
@ -5,6 +5,10 @@ class BankStatement < ActiveRecord::Base
|
|||
|
||||
validates :bank_code, :iban, :queried_at, presence: true
|
||||
|
||||
FULLY_BINDED = 'fully_binded'
|
||||
PARTIALLY_BINDED = 'partially_binded'
|
||||
NOT_BINDED = 'not_binded'
|
||||
|
||||
def import
|
||||
import_th6_file && save
|
||||
end
|
||||
|
@ -50,7 +54,30 @@ class BankStatement < ActiveRecord::Base
|
|||
nil
|
||||
end
|
||||
|
||||
def bind_with_invoices
|
||||
bank_transactions.unbinded.each(&:bind_with_invoice)
|
||||
# TODO: Cache this to database so it can be used for searching
|
||||
def status
|
||||
if bank_transactions.unbinded.count == bank_transactions.count
|
||||
NOT_BINDED
|
||||
elsif bank_transactions.unbinded.count == 0
|
||||
FULLY_BINDED
|
||||
else
|
||||
PARTIALLY_BINDED
|
||||
end
|
||||
end
|
||||
|
||||
def not_binded?
|
||||
status == NOT_BINDED
|
||||
end
|
||||
|
||||
def partially_binded?
|
||||
status == PARTIALLY_BINDED
|
||||
end
|
||||
|
||||
def fully_binded?
|
||||
status == FULLY_BINDED
|
||||
end
|
||||
|
||||
def bind_invoices
|
||||
bank_transactions.unbinded.each(&:bind_invoice)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,10 +8,15 @@ class BankTransaction < ActiveRecord::Base
|
|||
account_activity.present?
|
||||
end
|
||||
|
||||
def binded_invoice
|
||||
return unless binded?
|
||||
account_activity.invoice
|
||||
end
|
||||
|
||||
# For successful binding, reference number, invoice id and sum must match with the invoice
|
||||
# rubocop: disable Metrics/PerceivedComplexity
|
||||
# rubocop: disable Metrics/CyclomaticComplexity
|
||||
def bind_with_invoice
|
||||
def bind_invoice
|
||||
return if binded?
|
||||
registrar = Registrar.find_by(reference_no: reference_no)
|
||||
return unless registrar
|
||||
|
|
|
@ -7,6 +7,10 @@ class Invoice < ActiveRecord::Base
|
|||
validates :invoice_type, :due_date, :currency, :seller_name,
|
||||
:seller_iban, :buyer_name, :invoice_items, :vat_prc, presence: true
|
||||
|
||||
def to_s
|
||||
I18n.t('invoice_no', no: id)
|
||||
end
|
||||
|
||||
def seller_address
|
||||
[seller_street, seller_city, seller_state, seller_zip].reject(&:blank?).compact.join(', ')
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue