Add model and views for bank accounts
This commit is contained in:
parent
4b1e9a6f53
commit
f0a55fb951
24 changed files with 351 additions and 1 deletions
12
app/models/bank_account.rb
Normal file
12
app/models/bank_account.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
class BankAccount < ActiveRecord::Base
|
||||
|
||||
has_many :bank_transactions, dependent: :destroy
|
||||
|
||||
normalize_attributes :name, :iban, :description
|
||||
|
||||
validates :name, :presence => true, :uniqueness => true, :length => { :minimum => 2 }
|
||||
validates :iban, :presence => true, :uniqueness => true
|
||||
validates_format_of :iban, :with => /\A[A-Z]{2}[0-9]{2}[0-9A-Z]{,30}\z/
|
||||
validates_numericality_of :balance, :message => I18n.t('bank_account.model.invalid_balance')
|
||||
|
||||
end
|
||||
34
app/models/bank_transaction.rb
Normal file
34
app/models/bank_transaction.rb
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
class BankTransaction < ActiveRecord::Base
|
||||
|
||||
# @!attribute external_id
|
||||
# @return [String] Unique Identifier of the transaction within the bank account.
|
||||
# @!attribute date
|
||||
# @return [Date] Date of the transaction.
|
||||
# @!attribute amount
|
||||
# @return [Number] Amount credited.
|
||||
# @!attribute iban
|
||||
# @return [String] Internation Bank Account Number of the sending/receiving account.
|
||||
# @!attribute reference
|
||||
# @return [String] 140 character long reference field as defined by SEPA.
|
||||
# @!attribute text
|
||||
# @return [String] Short description of the transaction.
|
||||
# @!attribute receipt
|
||||
# @return [String] Optional additional more detailed description of the transaction.
|
||||
# @!attribute image
|
||||
# @return [Binary] Optional PNG image for e.g. scan of paper receipt.
|
||||
|
||||
belongs_to :bank_account
|
||||
belongs_to :financial_link
|
||||
belongs_to :supplier, foreign_key: 'iban', primary_key: 'iban'
|
||||
belongs_to :user, foreign_key: 'iban', primary_key: 'iban'
|
||||
|
||||
validates_presence_of :date, :amount, :bank_account_id
|
||||
validates_numericality_of :amount
|
||||
|
||||
# Replace numeric seperator with database format
|
||||
localize_input_of :amount
|
||||
|
||||
def image_url
|
||||
'data:image/png;base64,' + Base64.encode64(self.image)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
class FinancialLink < ActiveRecord::Base
|
||||
has_many :bank_transactions
|
||||
has_many :financial_transactions
|
||||
has_many :invoices
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue