Class: BankAccount
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- BankAccount
- Defined in:
- app/models/bank_account.rb
Overview
Represents a bank account associated with either an employee or a company.
Constant Summary collapse
- SOURCE =
{ EMPLOYEE: 'Employee', COMPANY: 'Company' }
- ENCRYPTED_FIELDS =
%w[ institution_no branch_no account_no ]
Instance Attribute Summary collapse
-
#account_no ⇒ String
The account number of the bank account.
-
#active ⇒ Boolean
Whether the bank account is active.
-
#address_line_1 ⇒ String
The first line of the address of the bank account.
-
#address_line_2 ⇒ String
The second line of the address of the bank account.
-
#bank_account_id ⇒ Integer
The primary key of the bank account.
-
#branch_no ⇒ String
The branch number of the bank account.
-
#city ⇒ String
The city of the bank account.
-
#currency_id ⇒ Integer
The ID of the currency associated with the bank account.
-
#description ⇒ String
The description of the bank account.
-
#google_address ⇒ String
The Google address of the bank account.
-
#institution_no ⇒ String
The institution number of the bank account.
-
#is_default ⇒ Boolean
Whether the bank account is the default account.
-
#name ⇒ String
The name of the bank account.
-
#postal_code ⇒ String
The postal code of the bank account.
-
#province_id ⇒ Integer
The ID of the province associated with the bank account.
-
#reference_id ⇒ Integer
The ID of the reference (employee or company).
-
#source ⇒ String
The source of the bank account, either ‘Employee’ or ‘Company’.
Class Method Summary collapse
-
.find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ⇒ BankAccount
Finds a bank account using a stored procedure.
Instance Method Summary collapse
-
#address_line1 ⇒ String
Returns the first line of the address of the bank account.
-
#address_line2 ⇒ String
Returns the second line of the address of the bank account.
-
#insert_update_procedure(user_name:) ⇒ BankAccount
Inserts or updates a bank account using a stored procedure.
-
#reference ⇒ Employee, Company
Returns the reference (employee or company) associated with the bank account.
Methods inherited from ApplicationRecord
define_decrypted_attribute, define_decrypted_attributes, #errors_in_bullet_points, primary_connection, special_connection
Instance Attribute Details
#account_no ⇒ String
Returns the account number of the bank account.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/bank_account.rb', line 37 class BankAccount < ApplicationRecord SOURCE = { EMPLOYEE: 'Employee', COMPANY: 'Company' } self.table_name = 'BANK_ACCOUNTS' self.primary_key = 'bank_account_id' ENCRYPTED_FIELDS = %w[ institution_no branch_no account_no ] define_decrypted_attributes(ENCRYPTED_FIELDS) has_many :integration_references, as: :reference, dependent: :destroy validates :source, inclusion: { in: SOURCE.values } validates :name, presence: true, length: { maximum: 50 }, uniqueness: { scope: %i[source reference_id] } validates :description, length: { maximum: 100 }, allow_blank: true validates :currency_id, presence: true validates :branch_no, length: { is: 5 }, numericality: { only_integer: true } validates :institution_no, length: { in: 3..4 }, numericality: { only_integer: true } validates :account_no, length: { in: 7..17 }, numericality: { only_integer: true } validates :reference_id, presence: true validate :not_default_and_inactive belongs_to :currency belongs_to :province # Inserts or updates a bank account using a stored procedure. # # @param user_name [String] the name of the user performing the operation # @return [BankAccount] the inserted or updated bank account # @example # bank_account = BankAccount.new( # source: 'Employee', # reference_id: 1, # name: 'John Doe', # description: 'Personal account', # currency_id: 1, # branch_no: '12345', # institution_no: '001', # account_no: '123456789', # is_default: true, # active: true # ) # bank_account.insert_update_procedure(user_name: 'admin') def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end class << self # Finds a bank account using a stored procedure. # # @param reference_id [Integer] the ID of the reference (employee or company) # @param bank_account_id [Integer] the ID of the bank account # @param source [String] the source of the bank account, either 'Employee' or 'Company' # @param active [Boolean] whether the bank account is active # @return [BankAccount] the found bank account # # @example Find an active bank account for an employee # bank_account = BankAccount.find_by_procedure( # reference_id: 1, # bank_account_id: 1, # source: 'Employee', # active: true # ) def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end end # Returns the reference (employee or company) associated with the bank account. # # @return [Employee, Company] the reference associated with the bank account # @example # reference = bank_account.reference def reference source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id) end # Returns the first line of the address of the bank account. # # @return [String] the first line of the address # @example # address_line1 = bank_account.address_line1 def address_line1 address_line_1 end # Returns the second line of the address of the bank account. # # @return [String] the second line of the address # @example # address_line2 = bank_account.address_line2 def address_line2 address_line_2 end private # Validates that the bank account is not default and inactive at the same time. # # @return [void] def not_default_and_inactive errors.add(:base, I18n.t('messages.not_default_and_inactive')) if is_default && !active end end |
#active ⇒ Boolean
Returns whether the bank account is active.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/bank_account.rb', line 37 class BankAccount < ApplicationRecord SOURCE = { EMPLOYEE: 'Employee', COMPANY: 'Company' } self.table_name = 'BANK_ACCOUNTS' self.primary_key = 'bank_account_id' ENCRYPTED_FIELDS = %w[ institution_no branch_no account_no ] define_decrypted_attributes(ENCRYPTED_FIELDS) has_many :integration_references, as: :reference, dependent: :destroy validates :source, inclusion: { in: SOURCE.values } validates :name, presence: true, length: { maximum: 50 }, uniqueness: { scope: %i[source reference_id] } validates :description, length: { maximum: 100 }, allow_blank: true validates :currency_id, presence: true validates :branch_no, length: { is: 5 }, numericality: { only_integer: true } validates :institution_no, length: { in: 3..4 }, numericality: { only_integer: true } validates :account_no, length: { in: 7..17 }, numericality: { only_integer: true } validates :reference_id, presence: true validate :not_default_and_inactive belongs_to :currency belongs_to :province # Inserts or updates a bank account using a stored procedure. # # @param user_name [String] the name of the user performing the operation # @return [BankAccount] the inserted or updated bank account # @example # bank_account = BankAccount.new( # source: 'Employee', # reference_id: 1, # name: 'John Doe', # description: 'Personal account', # currency_id: 1, # branch_no: '12345', # institution_no: '001', # account_no: '123456789', # is_default: true, # active: true # ) # bank_account.insert_update_procedure(user_name: 'admin') def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end class << self # Finds a bank account using a stored procedure. # # @param reference_id [Integer] the ID of the reference (employee or company) # @param bank_account_id [Integer] the ID of the bank account # @param source [String] the source of the bank account, either 'Employee' or 'Company' # @param active [Boolean] whether the bank account is active # @return [BankAccount] the found bank account # # @example Find an active bank account for an employee # bank_account = BankAccount.find_by_procedure( # reference_id: 1, # bank_account_id: 1, # source: 'Employee', # active: true # ) def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end end # Returns the reference (employee or company) associated with the bank account. # # @return [Employee, Company] the reference associated with the bank account # @example # reference = bank_account.reference def reference source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id) end # Returns the first line of the address of the bank account. # # @return [String] the first line of the address # @example # address_line1 = bank_account.address_line1 def address_line1 address_line_1 end # Returns the second line of the address of the bank account. # # @return [String] the second line of the address # @example # address_line2 = bank_account.address_line2 def address_line2 address_line_2 end private # Validates that the bank account is not default and inactive at the same time. # # @return [void] def not_default_and_inactive errors.add(:base, I18n.t('messages.not_default_and_inactive')) if is_default && !active end end |
#address_line_1 ⇒ String
Returns the first line of the address of the bank account.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/bank_account.rb', line 37 class BankAccount < ApplicationRecord SOURCE = { EMPLOYEE: 'Employee', COMPANY: 'Company' } self.table_name = 'BANK_ACCOUNTS' self.primary_key = 'bank_account_id' ENCRYPTED_FIELDS = %w[ institution_no branch_no account_no ] define_decrypted_attributes(ENCRYPTED_FIELDS) has_many :integration_references, as: :reference, dependent: :destroy validates :source, inclusion: { in: SOURCE.values } validates :name, presence: true, length: { maximum: 50 }, uniqueness: { scope: %i[source reference_id] } validates :description, length: { maximum: 100 }, allow_blank: true validates :currency_id, presence: true validates :branch_no, length: { is: 5 }, numericality: { only_integer: true } validates :institution_no, length: { in: 3..4 }, numericality: { only_integer: true } validates :account_no, length: { in: 7..17 }, numericality: { only_integer: true } validates :reference_id, presence: true validate :not_default_and_inactive belongs_to :currency belongs_to :province # Inserts or updates a bank account using a stored procedure. # # @param user_name [String] the name of the user performing the operation # @return [BankAccount] the inserted or updated bank account # @example # bank_account = BankAccount.new( # source: 'Employee', # reference_id: 1, # name: 'John Doe', # description: 'Personal account', # currency_id: 1, # branch_no: '12345', # institution_no: '001', # account_no: '123456789', # is_default: true, # active: true # ) # bank_account.insert_update_procedure(user_name: 'admin') def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end class << self # Finds a bank account using a stored procedure. # # @param reference_id [Integer] the ID of the reference (employee or company) # @param bank_account_id [Integer] the ID of the bank account # @param source [String] the source of the bank account, either 'Employee' or 'Company' # @param active [Boolean] whether the bank account is active # @return [BankAccount] the found bank account # # @example Find an active bank account for an employee # bank_account = BankAccount.find_by_procedure( # reference_id: 1, # bank_account_id: 1, # source: 'Employee', # active: true # ) def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end end # Returns the reference (employee or company) associated with the bank account. # # @return [Employee, Company] the reference associated with the bank account # @example # reference = bank_account.reference def reference source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id) end # Returns the first line of the address of the bank account. # # @return [String] the first line of the address # @example # address_line1 = bank_account.address_line1 def address_line1 address_line_1 end # Returns the second line of the address of the bank account. # # @return [String] the second line of the address # @example # address_line2 = bank_account.address_line2 def address_line2 address_line_2 end private # Validates that the bank account is not default and inactive at the same time. # # @return [void] def not_default_and_inactive errors.add(:base, I18n.t('messages.not_default_and_inactive')) if is_default && !active end end |
#address_line_2 ⇒ String
Returns the second line of the address of the bank account.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/bank_account.rb', line 37 class BankAccount < ApplicationRecord SOURCE = { EMPLOYEE: 'Employee', COMPANY: 'Company' } self.table_name = 'BANK_ACCOUNTS' self.primary_key = 'bank_account_id' ENCRYPTED_FIELDS = %w[ institution_no branch_no account_no ] define_decrypted_attributes(ENCRYPTED_FIELDS) has_many :integration_references, as: :reference, dependent: :destroy validates :source, inclusion: { in: SOURCE.values } validates :name, presence: true, length: { maximum: 50 }, uniqueness: { scope: %i[source reference_id] } validates :description, length: { maximum: 100 }, allow_blank: true validates :currency_id, presence: true validates :branch_no, length: { is: 5 }, numericality: { only_integer: true } validates :institution_no, length: { in: 3..4 }, numericality: { only_integer: true } validates :account_no, length: { in: 7..17 }, numericality: { only_integer: true } validates :reference_id, presence: true validate :not_default_and_inactive belongs_to :currency belongs_to :province # Inserts or updates a bank account using a stored procedure. # # @param user_name [String] the name of the user performing the operation # @return [BankAccount] the inserted or updated bank account # @example # bank_account = BankAccount.new( # source: 'Employee', # reference_id: 1, # name: 'John Doe', # description: 'Personal account', # currency_id: 1, # branch_no: '12345', # institution_no: '001', # account_no: '123456789', # is_default: true, # active: true # ) # bank_account.insert_update_procedure(user_name: 'admin') def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end class << self # Finds a bank account using a stored procedure. # # @param reference_id [Integer] the ID of the reference (employee or company) # @param bank_account_id [Integer] the ID of the bank account # @param source [String] the source of the bank account, either 'Employee' or 'Company' # @param active [Boolean] whether the bank account is active # @return [BankAccount] the found bank account # # @example Find an active bank account for an employee # bank_account = BankAccount.find_by_procedure( # reference_id: 1, # bank_account_id: 1, # source: 'Employee', # active: true # ) def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end end # Returns the reference (employee or company) associated with the bank account. # # @return [Employee, Company] the reference associated with the bank account # @example # reference = bank_account.reference def reference source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id) end # Returns the first line of the address of the bank account. # # @return [String] the first line of the address # @example # address_line1 = bank_account.address_line1 def address_line1 address_line_1 end # Returns the second line of the address of the bank account. # # @return [String] the second line of the address # @example # address_line2 = bank_account.address_line2 def address_line2 address_line_2 end private # Validates that the bank account is not default and inactive at the same time. # # @return [void] def not_default_and_inactive errors.add(:base, I18n.t('messages.not_default_and_inactive')) if is_default && !active end end |
#bank_account_id ⇒ Integer
Returns the primary key of the bank account.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/bank_account.rb', line 37 class BankAccount < ApplicationRecord SOURCE = { EMPLOYEE: 'Employee', COMPANY: 'Company' } self.table_name = 'BANK_ACCOUNTS' self.primary_key = 'bank_account_id' ENCRYPTED_FIELDS = %w[ institution_no branch_no account_no ] define_decrypted_attributes(ENCRYPTED_FIELDS) has_many :integration_references, as: :reference, dependent: :destroy validates :source, inclusion: { in: SOURCE.values } validates :name, presence: true, length: { maximum: 50 }, uniqueness: { scope: %i[source reference_id] } validates :description, length: { maximum: 100 }, allow_blank: true validates :currency_id, presence: true validates :branch_no, length: { is: 5 }, numericality: { only_integer: true } validates :institution_no, length: { in: 3..4 }, numericality: { only_integer: true } validates :account_no, length: { in: 7..17 }, numericality: { only_integer: true } validates :reference_id, presence: true validate :not_default_and_inactive belongs_to :currency belongs_to :province # Inserts or updates a bank account using a stored procedure. # # @param user_name [String] the name of the user performing the operation # @return [BankAccount] the inserted or updated bank account # @example # bank_account = BankAccount.new( # source: 'Employee', # reference_id: 1, # name: 'John Doe', # description: 'Personal account', # currency_id: 1, # branch_no: '12345', # institution_no: '001', # account_no: '123456789', # is_default: true, # active: true # ) # bank_account.insert_update_procedure(user_name: 'admin') def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end class << self # Finds a bank account using a stored procedure. # # @param reference_id [Integer] the ID of the reference (employee or company) # @param bank_account_id [Integer] the ID of the bank account # @param source [String] the source of the bank account, either 'Employee' or 'Company' # @param active [Boolean] whether the bank account is active # @return [BankAccount] the found bank account # # @example Find an active bank account for an employee # bank_account = BankAccount.find_by_procedure( # reference_id: 1, # bank_account_id: 1, # source: 'Employee', # active: true # ) def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end end # Returns the reference (employee or company) associated with the bank account. # # @return [Employee, Company] the reference associated with the bank account # @example # reference = bank_account.reference def reference source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id) end # Returns the first line of the address of the bank account. # # @return [String] the first line of the address # @example # address_line1 = bank_account.address_line1 def address_line1 address_line_1 end # Returns the second line of the address of the bank account. # # @return [String] the second line of the address # @example # address_line2 = bank_account.address_line2 def address_line2 address_line_2 end private # Validates that the bank account is not default and inactive at the same time. # # @return [void] def not_default_and_inactive errors.add(:base, I18n.t('messages.not_default_and_inactive')) if is_default && !active end end |
#branch_no ⇒ String
Returns the branch number of the bank account.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/bank_account.rb', line 37 class BankAccount < ApplicationRecord SOURCE = { EMPLOYEE: 'Employee', COMPANY: 'Company' } self.table_name = 'BANK_ACCOUNTS' self.primary_key = 'bank_account_id' ENCRYPTED_FIELDS = %w[ institution_no branch_no account_no ] define_decrypted_attributes(ENCRYPTED_FIELDS) has_many :integration_references, as: :reference, dependent: :destroy validates :source, inclusion: { in: SOURCE.values } validates :name, presence: true, length: { maximum: 50 }, uniqueness: { scope: %i[source reference_id] } validates :description, length: { maximum: 100 }, allow_blank: true validates :currency_id, presence: true validates :branch_no, length: { is: 5 }, numericality: { only_integer: true } validates :institution_no, length: { in: 3..4 }, numericality: { only_integer: true } validates :account_no, length: { in: 7..17 }, numericality: { only_integer: true } validates :reference_id, presence: true validate :not_default_and_inactive belongs_to :currency belongs_to :province # Inserts or updates a bank account using a stored procedure. # # @param user_name [String] the name of the user performing the operation # @return [BankAccount] the inserted or updated bank account # @example # bank_account = BankAccount.new( # source: 'Employee', # reference_id: 1, # name: 'John Doe', # description: 'Personal account', # currency_id: 1, # branch_no: '12345', # institution_no: '001', # account_no: '123456789', # is_default: true, # active: true # ) # bank_account.insert_update_procedure(user_name: 'admin') def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end class << self # Finds a bank account using a stored procedure. # # @param reference_id [Integer] the ID of the reference (employee or company) # @param bank_account_id [Integer] the ID of the bank account # @param source [String] the source of the bank account, either 'Employee' or 'Company' # @param active [Boolean] whether the bank account is active # @return [BankAccount] the found bank account # # @example Find an active bank account for an employee # bank_account = BankAccount.find_by_procedure( # reference_id: 1, # bank_account_id: 1, # source: 'Employee', # active: true # ) def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end end # Returns the reference (employee or company) associated with the bank account. # # @return [Employee, Company] the reference associated with the bank account # @example # reference = bank_account.reference def reference source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id) end # Returns the first line of the address of the bank account. # # @return [String] the first line of the address # @example # address_line1 = bank_account.address_line1 def address_line1 address_line_1 end # Returns the second line of the address of the bank account. # # @return [String] the second line of the address # @example # address_line2 = bank_account.address_line2 def address_line2 address_line_2 end private # Validates that the bank account is not default and inactive at the same time. # # @return [void] def not_default_and_inactive errors.add(:base, I18n.t('messages.not_default_and_inactive')) if is_default && !active end end |
#city ⇒ String
Returns the city of the bank account.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/bank_account.rb', line 37 class BankAccount < ApplicationRecord SOURCE = { EMPLOYEE: 'Employee', COMPANY: 'Company' } self.table_name = 'BANK_ACCOUNTS' self.primary_key = 'bank_account_id' ENCRYPTED_FIELDS = %w[ institution_no branch_no account_no ] define_decrypted_attributes(ENCRYPTED_FIELDS) has_many :integration_references, as: :reference, dependent: :destroy validates :source, inclusion: { in: SOURCE.values } validates :name, presence: true, length: { maximum: 50 }, uniqueness: { scope: %i[source reference_id] } validates :description, length: { maximum: 100 }, allow_blank: true validates :currency_id, presence: true validates :branch_no, length: { is: 5 }, numericality: { only_integer: true } validates :institution_no, length: { in: 3..4 }, numericality: { only_integer: true } validates :account_no, length: { in: 7..17 }, numericality: { only_integer: true } validates :reference_id, presence: true validate :not_default_and_inactive belongs_to :currency belongs_to :province # Inserts or updates a bank account using a stored procedure. # # @param user_name [String] the name of the user performing the operation # @return [BankAccount] the inserted or updated bank account # @example # bank_account = BankAccount.new( # source: 'Employee', # reference_id: 1, # name: 'John Doe', # description: 'Personal account', # currency_id: 1, # branch_no: '12345', # institution_no: '001', # account_no: '123456789', # is_default: true, # active: true # ) # bank_account.insert_update_procedure(user_name: 'admin') def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end class << self # Finds a bank account using a stored procedure. # # @param reference_id [Integer] the ID of the reference (employee or company) # @param bank_account_id [Integer] the ID of the bank account # @param source [String] the source of the bank account, either 'Employee' or 'Company' # @param active [Boolean] whether the bank account is active # @return [BankAccount] the found bank account # # @example Find an active bank account for an employee # bank_account = BankAccount.find_by_procedure( # reference_id: 1, # bank_account_id: 1, # source: 'Employee', # active: true # ) def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end end # Returns the reference (employee or company) associated with the bank account. # # @return [Employee, Company] the reference associated with the bank account # @example # reference = bank_account.reference def reference source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id) end # Returns the first line of the address of the bank account. # # @return [String] the first line of the address # @example # address_line1 = bank_account.address_line1 def address_line1 address_line_1 end # Returns the second line of the address of the bank account. # # @return [String] the second line of the address # @example # address_line2 = bank_account.address_line2 def address_line2 address_line_2 end private # Validates that the bank account is not default and inactive at the same time. # # @return [void] def not_default_and_inactive errors.add(:base, I18n.t('messages.not_default_and_inactive')) if is_default && !active end end |
#currency_id ⇒ Integer
Returns the ID of the currency associated with the bank account.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/bank_account.rb', line 37 class BankAccount < ApplicationRecord SOURCE = { EMPLOYEE: 'Employee', COMPANY: 'Company' } self.table_name = 'BANK_ACCOUNTS' self.primary_key = 'bank_account_id' ENCRYPTED_FIELDS = %w[ institution_no branch_no account_no ] define_decrypted_attributes(ENCRYPTED_FIELDS) has_many :integration_references, as: :reference, dependent: :destroy validates :source, inclusion: { in: SOURCE.values } validates :name, presence: true, length: { maximum: 50 }, uniqueness: { scope: %i[source reference_id] } validates :description, length: { maximum: 100 }, allow_blank: true validates :currency_id, presence: true validates :branch_no, length: { is: 5 }, numericality: { only_integer: true } validates :institution_no, length: { in: 3..4 }, numericality: { only_integer: true } validates :account_no, length: { in: 7..17 }, numericality: { only_integer: true } validates :reference_id, presence: true validate :not_default_and_inactive belongs_to :currency belongs_to :province # Inserts or updates a bank account using a stored procedure. # # @param user_name [String] the name of the user performing the operation # @return [BankAccount] the inserted or updated bank account # @example # bank_account = BankAccount.new( # source: 'Employee', # reference_id: 1, # name: 'John Doe', # description: 'Personal account', # currency_id: 1, # branch_no: '12345', # institution_no: '001', # account_no: '123456789', # is_default: true, # active: true # ) # bank_account.insert_update_procedure(user_name: 'admin') def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end class << self # Finds a bank account using a stored procedure. # # @param reference_id [Integer] the ID of the reference (employee or company) # @param bank_account_id [Integer] the ID of the bank account # @param source [String] the source of the bank account, either 'Employee' or 'Company' # @param active [Boolean] whether the bank account is active # @return [BankAccount] the found bank account # # @example Find an active bank account for an employee # bank_account = BankAccount.find_by_procedure( # reference_id: 1, # bank_account_id: 1, # source: 'Employee', # active: true # ) def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end end # Returns the reference (employee or company) associated with the bank account. # # @return [Employee, Company] the reference associated with the bank account # @example # reference = bank_account.reference def reference source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id) end # Returns the first line of the address of the bank account. # # @return [String] the first line of the address # @example # address_line1 = bank_account.address_line1 def address_line1 address_line_1 end # Returns the second line of the address of the bank account. # # @return [String] the second line of the address # @example # address_line2 = bank_account.address_line2 def address_line2 address_line_2 end private # Validates that the bank account is not default and inactive at the same time. # # @return [void] def not_default_and_inactive errors.add(:base, I18n.t('messages.not_default_and_inactive')) if is_default && !active end end |
#description ⇒ String
Returns the description of the bank account.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/bank_account.rb', line 37 class BankAccount < ApplicationRecord SOURCE = { EMPLOYEE: 'Employee', COMPANY: 'Company' } self.table_name = 'BANK_ACCOUNTS' self.primary_key = 'bank_account_id' ENCRYPTED_FIELDS = %w[ institution_no branch_no account_no ] define_decrypted_attributes(ENCRYPTED_FIELDS) has_many :integration_references, as: :reference, dependent: :destroy validates :source, inclusion: { in: SOURCE.values } validates :name, presence: true, length: { maximum: 50 }, uniqueness: { scope: %i[source reference_id] } validates :description, length: { maximum: 100 }, allow_blank: true validates :currency_id, presence: true validates :branch_no, length: { is: 5 }, numericality: { only_integer: true } validates :institution_no, length: { in: 3..4 }, numericality: { only_integer: true } validates :account_no, length: { in: 7..17 }, numericality: { only_integer: true } validates :reference_id, presence: true validate :not_default_and_inactive belongs_to :currency belongs_to :province # Inserts or updates a bank account using a stored procedure. # # @param user_name [String] the name of the user performing the operation # @return [BankAccount] the inserted or updated bank account # @example # bank_account = BankAccount.new( # source: 'Employee', # reference_id: 1, # name: 'John Doe', # description: 'Personal account', # currency_id: 1, # branch_no: '12345', # institution_no: '001', # account_no: '123456789', # is_default: true, # active: true # ) # bank_account.insert_update_procedure(user_name: 'admin') def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end class << self # Finds a bank account using a stored procedure. # # @param reference_id [Integer] the ID of the reference (employee or company) # @param bank_account_id [Integer] the ID of the bank account # @param source [String] the source of the bank account, either 'Employee' or 'Company' # @param active [Boolean] whether the bank account is active # @return [BankAccount] the found bank account # # @example Find an active bank account for an employee # bank_account = BankAccount.find_by_procedure( # reference_id: 1, # bank_account_id: 1, # source: 'Employee', # active: true # ) def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end end # Returns the reference (employee or company) associated with the bank account. # # @return [Employee, Company] the reference associated with the bank account # @example # reference = bank_account.reference def reference source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id) end # Returns the first line of the address of the bank account. # # @return [String] the first line of the address # @example # address_line1 = bank_account.address_line1 def address_line1 address_line_1 end # Returns the second line of the address of the bank account. # # @return [String] the second line of the address # @example # address_line2 = bank_account.address_line2 def address_line2 address_line_2 end private # Validates that the bank account is not default and inactive at the same time. # # @return [void] def not_default_and_inactive errors.add(:base, I18n.t('messages.not_default_and_inactive')) if is_default && !active end end |
#google_address ⇒ String
Returns the Google address of the bank account.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/bank_account.rb', line 37 class BankAccount < ApplicationRecord SOURCE = { EMPLOYEE: 'Employee', COMPANY: 'Company' } self.table_name = 'BANK_ACCOUNTS' self.primary_key = 'bank_account_id' ENCRYPTED_FIELDS = %w[ institution_no branch_no account_no ] define_decrypted_attributes(ENCRYPTED_FIELDS) has_many :integration_references, as: :reference, dependent: :destroy validates :source, inclusion: { in: SOURCE.values } validates :name, presence: true, length: { maximum: 50 }, uniqueness: { scope: %i[source reference_id] } validates :description, length: { maximum: 100 }, allow_blank: true validates :currency_id, presence: true validates :branch_no, length: { is: 5 }, numericality: { only_integer: true } validates :institution_no, length: { in: 3..4 }, numericality: { only_integer: true } validates :account_no, length: { in: 7..17 }, numericality: { only_integer: true } validates :reference_id, presence: true validate :not_default_and_inactive belongs_to :currency belongs_to :province # Inserts or updates a bank account using a stored procedure. # # @param user_name [String] the name of the user performing the operation # @return [BankAccount] the inserted or updated bank account # @example # bank_account = BankAccount.new( # source: 'Employee', # reference_id: 1, # name: 'John Doe', # description: 'Personal account', # currency_id: 1, # branch_no: '12345', # institution_no: '001', # account_no: '123456789', # is_default: true, # active: true # ) # bank_account.insert_update_procedure(user_name: 'admin') def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end class << self # Finds a bank account using a stored procedure. # # @param reference_id [Integer] the ID of the reference (employee or company) # @param bank_account_id [Integer] the ID of the bank account # @param source [String] the source of the bank account, either 'Employee' or 'Company' # @param active [Boolean] whether the bank account is active # @return [BankAccount] the found bank account # # @example Find an active bank account for an employee # bank_account = BankAccount.find_by_procedure( # reference_id: 1, # bank_account_id: 1, # source: 'Employee', # active: true # ) def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end end # Returns the reference (employee or company) associated with the bank account. # # @return [Employee, Company] the reference associated with the bank account # @example # reference = bank_account.reference def reference source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id) end # Returns the first line of the address of the bank account. # # @return [String] the first line of the address # @example # address_line1 = bank_account.address_line1 def address_line1 address_line_1 end # Returns the second line of the address of the bank account. # # @return [String] the second line of the address # @example # address_line2 = bank_account.address_line2 def address_line2 address_line_2 end private # Validates that the bank account is not default and inactive at the same time. # # @return [void] def not_default_and_inactive errors.add(:base, I18n.t('messages.not_default_and_inactive')) if is_default && !active end end |
#institution_no ⇒ String
Returns the institution number of the bank account.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/bank_account.rb', line 37 class BankAccount < ApplicationRecord SOURCE = { EMPLOYEE: 'Employee', COMPANY: 'Company' } self.table_name = 'BANK_ACCOUNTS' self.primary_key = 'bank_account_id' ENCRYPTED_FIELDS = %w[ institution_no branch_no account_no ] define_decrypted_attributes(ENCRYPTED_FIELDS) has_many :integration_references, as: :reference, dependent: :destroy validates :source, inclusion: { in: SOURCE.values } validates :name, presence: true, length: { maximum: 50 }, uniqueness: { scope: %i[source reference_id] } validates :description, length: { maximum: 100 }, allow_blank: true validates :currency_id, presence: true validates :branch_no, length: { is: 5 }, numericality: { only_integer: true } validates :institution_no, length: { in: 3..4 }, numericality: { only_integer: true } validates :account_no, length: { in: 7..17 }, numericality: { only_integer: true } validates :reference_id, presence: true validate :not_default_and_inactive belongs_to :currency belongs_to :province # Inserts or updates a bank account using a stored procedure. # # @param user_name [String] the name of the user performing the operation # @return [BankAccount] the inserted or updated bank account # @example # bank_account = BankAccount.new( # source: 'Employee', # reference_id: 1, # name: 'John Doe', # description: 'Personal account', # currency_id: 1, # branch_no: '12345', # institution_no: '001', # account_no: '123456789', # is_default: true, # active: true # ) # bank_account.insert_update_procedure(user_name: 'admin') def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end class << self # Finds a bank account using a stored procedure. # # @param reference_id [Integer] the ID of the reference (employee or company) # @param bank_account_id [Integer] the ID of the bank account # @param source [String] the source of the bank account, either 'Employee' or 'Company' # @param active [Boolean] whether the bank account is active # @return [BankAccount] the found bank account # # @example Find an active bank account for an employee # bank_account = BankAccount.find_by_procedure( # reference_id: 1, # bank_account_id: 1, # source: 'Employee', # active: true # ) def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end end # Returns the reference (employee or company) associated with the bank account. # # @return [Employee, Company] the reference associated with the bank account # @example # reference = bank_account.reference def reference source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id) end # Returns the first line of the address of the bank account. # # @return [String] the first line of the address # @example # address_line1 = bank_account.address_line1 def address_line1 address_line_1 end # Returns the second line of the address of the bank account. # # @return [String] the second line of the address # @example # address_line2 = bank_account.address_line2 def address_line2 address_line_2 end private # Validates that the bank account is not default and inactive at the same time. # # @return [void] def not_default_and_inactive errors.add(:base, I18n.t('messages.not_default_and_inactive')) if is_default && !active end end |
#is_default ⇒ Boolean
Returns whether the bank account is the default account.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/bank_account.rb', line 37 class BankAccount < ApplicationRecord SOURCE = { EMPLOYEE: 'Employee', COMPANY: 'Company' } self.table_name = 'BANK_ACCOUNTS' self.primary_key = 'bank_account_id' ENCRYPTED_FIELDS = %w[ institution_no branch_no account_no ] define_decrypted_attributes(ENCRYPTED_FIELDS) has_many :integration_references, as: :reference, dependent: :destroy validates :source, inclusion: { in: SOURCE.values } validates :name, presence: true, length: { maximum: 50 }, uniqueness: { scope: %i[source reference_id] } validates :description, length: { maximum: 100 }, allow_blank: true validates :currency_id, presence: true validates :branch_no, length: { is: 5 }, numericality: { only_integer: true } validates :institution_no, length: { in: 3..4 }, numericality: { only_integer: true } validates :account_no, length: { in: 7..17 }, numericality: { only_integer: true } validates :reference_id, presence: true validate :not_default_and_inactive belongs_to :currency belongs_to :province # Inserts or updates a bank account using a stored procedure. # # @param user_name [String] the name of the user performing the operation # @return [BankAccount] the inserted or updated bank account # @example # bank_account = BankAccount.new( # source: 'Employee', # reference_id: 1, # name: 'John Doe', # description: 'Personal account', # currency_id: 1, # branch_no: '12345', # institution_no: '001', # account_no: '123456789', # is_default: true, # active: true # ) # bank_account.insert_update_procedure(user_name: 'admin') def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end class << self # Finds a bank account using a stored procedure. # # @param reference_id [Integer] the ID of the reference (employee or company) # @param bank_account_id [Integer] the ID of the bank account # @param source [String] the source of the bank account, either 'Employee' or 'Company' # @param active [Boolean] whether the bank account is active # @return [BankAccount] the found bank account # # @example Find an active bank account for an employee # bank_account = BankAccount.find_by_procedure( # reference_id: 1, # bank_account_id: 1, # source: 'Employee', # active: true # ) def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end end # Returns the reference (employee or company) associated with the bank account. # # @return [Employee, Company] the reference associated with the bank account # @example # reference = bank_account.reference def reference source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id) end # Returns the first line of the address of the bank account. # # @return [String] the first line of the address # @example # address_line1 = bank_account.address_line1 def address_line1 address_line_1 end # Returns the second line of the address of the bank account. # # @return [String] the second line of the address # @example # address_line2 = bank_account.address_line2 def address_line2 address_line_2 end private # Validates that the bank account is not default and inactive at the same time. # # @return [void] def not_default_and_inactive errors.add(:base, I18n.t('messages.not_default_and_inactive')) if is_default && !active end end |
#name ⇒ String
Returns the name of the bank account.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/bank_account.rb', line 37 class BankAccount < ApplicationRecord SOURCE = { EMPLOYEE: 'Employee', COMPANY: 'Company' } self.table_name = 'BANK_ACCOUNTS' self.primary_key = 'bank_account_id' ENCRYPTED_FIELDS = %w[ institution_no branch_no account_no ] define_decrypted_attributes(ENCRYPTED_FIELDS) has_many :integration_references, as: :reference, dependent: :destroy validates :source, inclusion: { in: SOURCE.values } validates :name, presence: true, length: { maximum: 50 }, uniqueness: { scope: %i[source reference_id] } validates :description, length: { maximum: 100 }, allow_blank: true validates :currency_id, presence: true validates :branch_no, length: { is: 5 }, numericality: { only_integer: true } validates :institution_no, length: { in: 3..4 }, numericality: { only_integer: true } validates :account_no, length: { in: 7..17 }, numericality: { only_integer: true } validates :reference_id, presence: true validate :not_default_and_inactive belongs_to :currency belongs_to :province # Inserts or updates a bank account using a stored procedure. # # @param user_name [String] the name of the user performing the operation # @return [BankAccount] the inserted or updated bank account # @example # bank_account = BankAccount.new( # source: 'Employee', # reference_id: 1, # name: 'John Doe', # description: 'Personal account', # currency_id: 1, # branch_no: '12345', # institution_no: '001', # account_no: '123456789', # is_default: true, # active: true # ) # bank_account.insert_update_procedure(user_name: 'admin') def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end class << self # Finds a bank account using a stored procedure. # # @param reference_id [Integer] the ID of the reference (employee or company) # @param bank_account_id [Integer] the ID of the bank account # @param source [String] the source of the bank account, either 'Employee' or 'Company' # @param active [Boolean] whether the bank account is active # @return [BankAccount] the found bank account # # @example Find an active bank account for an employee # bank_account = BankAccount.find_by_procedure( # reference_id: 1, # bank_account_id: 1, # source: 'Employee', # active: true # ) def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end end # Returns the reference (employee or company) associated with the bank account. # # @return [Employee, Company] the reference associated with the bank account # @example # reference = bank_account.reference def reference source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id) end # Returns the first line of the address of the bank account. # # @return [String] the first line of the address # @example # address_line1 = bank_account.address_line1 def address_line1 address_line_1 end # Returns the second line of the address of the bank account. # # @return [String] the second line of the address # @example # address_line2 = bank_account.address_line2 def address_line2 address_line_2 end private # Validates that the bank account is not default and inactive at the same time. # # @return [void] def not_default_and_inactive errors.add(:base, I18n.t('messages.not_default_and_inactive')) if is_default && !active end end |
#postal_code ⇒ String
Returns the postal code of the bank account.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/bank_account.rb', line 37 class BankAccount < ApplicationRecord SOURCE = { EMPLOYEE: 'Employee', COMPANY: 'Company' } self.table_name = 'BANK_ACCOUNTS' self.primary_key = 'bank_account_id' ENCRYPTED_FIELDS = %w[ institution_no branch_no account_no ] define_decrypted_attributes(ENCRYPTED_FIELDS) has_many :integration_references, as: :reference, dependent: :destroy validates :source, inclusion: { in: SOURCE.values } validates :name, presence: true, length: { maximum: 50 }, uniqueness: { scope: %i[source reference_id] } validates :description, length: { maximum: 100 }, allow_blank: true validates :currency_id, presence: true validates :branch_no, length: { is: 5 }, numericality: { only_integer: true } validates :institution_no, length: { in: 3..4 }, numericality: { only_integer: true } validates :account_no, length: { in: 7..17 }, numericality: { only_integer: true } validates :reference_id, presence: true validate :not_default_and_inactive belongs_to :currency belongs_to :province # Inserts or updates a bank account using a stored procedure. # # @param user_name [String] the name of the user performing the operation # @return [BankAccount] the inserted or updated bank account # @example # bank_account = BankAccount.new( # source: 'Employee', # reference_id: 1, # name: 'John Doe', # description: 'Personal account', # currency_id: 1, # branch_no: '12345', # institution_no: '001', # account_no: '123456789', # is_default: true, # active: true # ) # bank_account.insert_update_procedure(user_name: 'admin') def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end class << self # Finds a bank account using a stored procedure. # # @param reference_id [Integer] the ID of the reference (employee or company) # @param bank_account_id [Integer] the ID of the bank account # @param source [String] the source of the bank account, either 'Employee' or 'Company' # @param active [Boolean] whether the bank account is active # @return [BankAccount] the found bank account # # @example Find an active bank account for an employee # bank_account = BankAccount.find_by_procedure( # reference_id: 1, # bank_account_id: 1, # source: 'Employee', # active: true # ) def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end end # Returns the reference (employee or company) associated with the bank account. # # @return [Employee, Company] the reference associated with the bank account # @example # reference = bank_account.reference def reference source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id) end # Returns the first line of the address of the bank account. # # @return [String] the first line of the address # @example # address_line1 = bank_account.address_line1 def address_line1 address_line_1 end # Returns the second line of the address of the bank account. # # @return [String] the second line of the address # @example # address_line2 = bank_account.address_line2 def address_line2 address_line_2 end private # Validates that the bank account is not default and inactive at the same time. # # @return [void] def not_default_and_inactive errors.add(:base, I18n.t('messages.not_default_and_inactive')) if is_default && !active end end |
#province_id ⇒ Integer
Returns the ID of the province associated with the bank account.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/bank_account.rb', line 37 class BankAccount < ApplicationRecord SOURCE = { EMPLOYEE: 'Employee', COMPANY: 'Company' } self.table_name = 'BANK_ACCOUNTS' self.primary_key = 'bank_account_id' ENCRYPTED_FIELDS = %w[ institution_no branch_no account_no ] define_decrypted_attributes(ENCRYPTED_FIELDS) has_many :integration_references, as: :reference, dependent: :destroy validates :source, inclusion: { in: SOURCE.values } validates :name, presence: true, length: { maximum: 50 }, uniqueness: { scope: %i[source reference_id] } validates :description, length: { maximum: 100 }, allow_blank: true validates :currency_id, presence: true validates :branch_no, length: { is: 5 }, numericality: { only_integer: true } validates :institution_no, length: { in: 3..4 }, numericality: { only_integer: true } validates :account_no, length: { in: 7..17 }, numericality: { only_integer: true } validates :reference_id, presence: true validate :not_default_and_inactive belongs_to :currency belongs_to :province # Inserts or updates a bank account using a stored procedure. # # @param user_name [String] the name of the user performing the operation # @return [BankAccount] the inserted or updated bank account # @example # bank_account = BankAccount.new( # source: 'Employee', # reference_id: 1, # name: 'John Doe', # description: 'Personal account', # currency_id: 1, # branch_no: '12345', # institution_no: '001', # account_no: '123456789', # is_default: true, # active: true # ) # bank_account.insert_update_procedure(user_name: 'admin') def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end class << self # Finds a bank account using a stored procedure. # # @param reference_id [Integer] the ID of the reference (employee or company) # @param bank_account_id [Integer] the ID of the bank account # @param source [String] the source of the bank account, either 'Employee' or 'Company' # @param active [Boolean] whether the bank account is active # @return [BankAccount] the found bank account # # @example Find an active bank account for an employee # bank_account = BankAccount.find_by_procedure( # reference_id: 1, # bank_account_id: 1, # source: 'Employee', # active: true # ) def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end end # Returns the reference (employee or company) associated with the bank account. # # @return [Employee, Company] the reference associated with the bank account # @example # reference = bank_account.reference def reference source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id) end # Returns the first line of the address of the bank account. # # @return [String] the first line of the address # @example # address_line1 = bank_account.address_line1 def address_line1 address_line_1 end # Returns the second line of the address of the bank account. # # @return [String] the second line of the address # @example # address_line2 = bank_account.address_line2 def address_line2 address_line_2 end private # Validates that the bank account is not default and inactive at the same time. # # @return [void] def not_default_and_inactive errors.add(:base, I18n.t('messages.not_default_and_inactive')) if is_default && !active end end |
#reference_id ⇒ Integer
Returns the ID of the reference (employee or company).
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/bank_account.rb', line 37 class BankAccount < ApplicationRecord SOURCE = { EMPLOYEE: 'Employee', COMPANY: 'Company' } self.table_name = 'BANK_ACCOUNTS' self.primary_key = 'bank_account_id' ENCRYPTED_FIELDS = %w[ institution_no branch_no account_no ] define_decrypted_attributes(ENCRYPTED_FIELDS) has_many :integration_references, as: :reference, dependent: :destroy validates :source, inclusion: { in: SOURCE.values } validates :name, presence: true, length: { maximum: 50 }, uniqueness: { scope: %i[source reference_id] } validates :description, length: { maximum: 100 }, allow_blank: true validates :currency_id, presence: true validates :branch_no, length: { is: 5 }, numericality: { only_integer: true } validates :institution_no, length: { in: 3..4 }, numericality: { only_integer: true } validates :account_no, length: { in: 7..17 }, numericality: { only_integer: true } validates :reference_id, presence: true validate :not_default_and_inactive belongs_to :currency belongs_to :province # Inserts or updates a bank account using a stored procedure. # # @param user_name [String] the name of the user performing the operation # @return [BankAccount] the inserted or updated bank account # @example # bank_account = BankAccount.new( # source: 'Employee', # reference_id: 1, # name: 'John Doe', # description: 'Personal account', # currency_id: 1, # branch_no: '12345', # institution_no: '001', # account_no: '123456789', # is_default: true, # active: true # ) # bank_account.insert_update_procedure(user_name: 'admin') def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end class << self # Finds a bank account using a stored procedure. # # @param reference_id [Integer] the ID of the reference (employee or company) # @param bank_account_id [Integer] the ID of the bank account # @param source [String] the source of the bank account, either 'Employee' or 'Company' # @param active [Boolean] whether the bank account is active # @return [BankAccount] the found bank account # # @example Find an active bank account for an employee # bank_account = BankAccount.find_by_procedure( # reference_id: 1, # bank_account_id: 1, # source: 'Employee', # active: true # ) def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end end # Returns the reference (employee or company) associated with the bank account. # # @return [Employee, Company] the reference associated with the bank account # @example # reference = bank_account.reference def reference source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id) end # Returns the first line of the address of the bank account. # # @return [String] the first line of the address # @example # address_line1 = bank_account.address_line1 def address_line1 address_line_1 end # Returns the second line of the address of the bank account. # # @return [String] the second line of the address # @example # address_line2 = bank_account.address_line2 def address_line2 address_line_2 end private # Validates that the bank account is not default and inactive at the same time. # # @return [void] def not_default_and_inactive errors.add(:base, I18n.t('messages.not_default_and_inactive')) if is_default && !active end end |
#source ⇒ String
Returns the source of the bank account, either ‘Employee’ or ‘Company’.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/bank_account.rb', line 37 class BankAccount < ApplicationRecord SOURCE = { EMPLOYEE: 'Employee', COMPANY: 'Company' } self.table_name = 'BANK_ACCOUNTS' self.primary_key = 'bank_account_id' ENCRYPTED_FIELDS = %w[ institution_no branch_no account_no ] define_decrypted_attributes(ENCRYPTED_FIELDS) has_many :integration_references, as: :reference, dependent: :destroy validates :source, inclusion: { in: SOURCE.values } validates :name, presence: true, length: { maximum: 50 }, uniqueness: { scope: %i[source reference_id] } validates :description, length: { maximum: 100 }, allow_blank: true validates :currency_id, presence: true validates :branch_no, length: { is: 5 }, numericality: { only_integer: true } validates :institution_no, length: { in: 3..4 }, numericality: { only_integer: true } validates :account_no, length: { in: 7..17 }, numericality: { only_integer: true } validates :reference_id, presence: true validate :not_default_and_inactive belongs_to :currency belongs_to :province # Inserts or updates a bank account using a stored procedure. # # @param user_name [String] the name of the user performing the operation # @return [BankAccount] the inserted or updated bank account # @example # bank_account = BankAccount.new( # source: 'Employee', # reference_id: 1, # name: 'John Doe', # description: 'Personal account', # currency_id: 1, # branch_no: '12345', # institution_no: '001', # account_no: '123456789', # is_default: true, # active: true # ) # bank_account.insert_update_procedure(user_name: 'admin') def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end class << self # Finds a bank account using a stored procedure. # # @param reference_id [Integer] the ID of the reference (employee or company) # @param bank_account_id [Integer] the ID of the bank account # @param source [String] the source of the bank account, either 'Employee' or 'Company' # @param active [Boolean] whether the bank account is active # @return [BankAccount] the found bank account # # @example Find an active bank account for an employee # bank_account = BankAccount.find_by_procedure( # reference_id: 1, # bank_account_id: 1, # source: 'Employee', # active: true # ) def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end end # Returns the reference (employee or company) associated with the bank account. # # @return [Employee, Company] the reference associated with the bank account # @example # reference = bank_account.reference def reference source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id) end # Returns the first line of the address of the bank account. # # @return [String] the first line of the address # @example # address_line1 = bank_account.address_line1 def address_line1 address_line_1 end # Returns the second line of the address of the bank account. # # @return [String] the second line of the address # @example # address_line2 = bank_account.address_line2 def address_line2 address_line_2 end private # Validates that the bank account is not default and inactive at the same time. # # @return [void] def not_default_and_inactive errors.add(:base, I18n.t('messages.not_default_and_inactive')) if is_default && !active end end |
Class Method Details
.find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ⇒ BankAccount
Finds a bank account using a stored procedure.
126 127 128 129 130 131 132 133 134 |
# File 'app/models/bank_account.rb', line 126 def find_by_procedure(reference_id:, bank_account_id:, source: 'Company', active: true) ActiveRecord::Base.execute_procedure( 'pr_get_bank_account', source, reference_id, bank_account_id, active )[0] end |
Instance Method Details
#address_line1 ⇒ String
Returns the first line of the address of the bank account.
151 152 153 |
# File 'app/models/bank_account.rb', line 151 def address_line1 address_line_1 end |
#address_line2 ⇒ String
Returns the second line of the address of the bank account.
160 161 162 |
# File 'app/models/bank_account.rb', line 160 def address_line2 address_line_2 end |
#insert_update_procedure(user_name:) ⇒ BankAccount
Inserts or updates a bank account using a stored procedure.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/models/bank_account.rb', line 86 def insert_update_procedure(user_name:) ActiveRecord::Base.execute_procedure( :pr_insert_update_one_bank_account, bank_account_id, source, reference_id, description, currency_id, name, google_address, address_line_1, address_line_2, city, province_id, postal_code, attributes['institution_no'] || decrypted_institution_no, attributes['branch_no'] || decrypted_branch_no, attributes['account_no'] || decrypted_account_no, is_default, active, user_name )[0] end |