Class: BankTransaction
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- BankTransaction
- Includes:
- LocalizeInput
- Defined in:
- app/models/bank_transaction.rb
Instance Attribute Summary collapse
-
#amount ⇒ Number
Amount credited.
-
#date ⇒ Date
Date of the transaction.
-
#external_id ⇒ String
Unique Identifier of the transaction within the bank account.
-
#iban ⇒ String
Internation Bank Account Number of the sending/receiving account.
-
#image ⇒ Binary
Optional PNG image for e.g.
-
#receipt ⇒ String
Optional additional more detailed description of the transaction.
-
#reference ⇒ String
140 character long reference field as defined by SEPA.
-
#text ⇒ String
Short description of the transaction.
Instance Method Summary collapse
Methods included from LocalizeInput
Instance Attribute Details
#amount ⇒ Number
Returns Amount credited.
20 |
# File 'app/models/bank_transaction.rb', line 20 belongs_to :bank_account |
#date ⇒ Date
Returns Date of the transaction.
20 |
# File 'app/models/bank_transaction.rb', line 20 belongs_to :bank_account |
#external_id ⇒ String
Returns Unique Identifier of the transaction within the bank account.
20 |
# File 'app/models/bank_transaction.rb', line 20 belongs_to :bank_account |
#iban ⇒ String
Returns Internation Bank Account Number of the sending/receiving account.
20 |
# File 'app/models/bank_transaction.rb', line 20 belongs_to :bank_account |
#image ⇒ Binary
Returns Optional PNG image for e.g. scan of paper receipt.
20 |
# File 'app/models/bank_transaction.rb', line 20 belongs_to :bank_account |
#receipt ⇒ String
Returns Optional additional more detailed description of the transaction.
20 |
# File 'app/models/bank_transaction.rb', line 20 belongs_to :bank_account |
#reference ⇒ String
Returns 140 character long reference field as defined by SEPA.
20 |
# File 'app/models/bank_transaction.rb', line 20 belongs_to :bank_account |
#text ⇒ String
Returns Short description of the transaction.
20 |
# File 'app/models/bank_transaction.rb', line 20 belongs_to :bank_account |
Instance Method Details
#assign_to_invoice ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/models/bank_transaction.rb', line 37 def assign_to_invoice return false unless supplier content = text || '' content += "\n" + reference if reference.present? invoices = supplier.invoices.unpaid.select { |i| content.include? i.number } invoices_sum = invoices.map(&:amount).sum return false if amount != -invoices_sum transaction do link = FinancialLink.new invoices.each { |i| i.update!(financial_link: link, paid_on: date) } update_attribute :financial_link, link end true end |
#assign_to_ordergroup ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/models/bank_transaction.rb', line 55 def assign_to_ordergroup m = BankTransactionReference.parse(reference) return unless m return false if m[:parts].values.sum != amount group = Ordergroup.find_by_id(m[:group]) return false unless group usr = m[:user] ? User.find_by_id(m[:user]) : group.users.first return false unless usr transaction do note = "ID=#{id} (#{amount})" link = FinancialLink.new m[:parts].each do |short, value| ftt = FinancialTransactionType.find_by_name_short(short) return false unless ftt group.add_financial_transaction! value, note, usr, ftt, link if value > 0 end update_attribute :financial_link, link end true end |
#image_url ⇒ Object
33 34 35 |
# File 'app/models/bank_transaction.rb', line 33 def image_url 'data:image/png;base64,' + Base64.encode64(image) end |