Class: BankAccount

Inherits:
ApplicationRecord show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

define_decrypted_attribute, define_decrypted_attributes, #errors_in_bullet_points, primary_connection, special_connection

Instance Attribute Details

#account_noString

Returns the account number of the bank account.

Returns:

  • (String)

    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,
      ,
      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'] || ,
      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,
        ,
        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

#activeBoolean

Returns whether the bank account is active.

Returns:

  • (Boolean)

    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,
      ,
      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'] || ,
      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,
        ,
        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_1String

Returns the first line of the address of the bank account.

Returns:

  • (String)

    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,
      ,
      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'] || ,
      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,
        ,
        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_2String

Returns the second line of the address of the bank account.

Returns:

  • (String)

    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,
      ,
      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'] || ,
      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,
        ,
        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_idInteger

Returns the primary key of the bank account.

Returns:

  • (Integer)

    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,
      ,
      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'] || ,
      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,
        ,
        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_noString

Returns the branch number of the bank account.

Returns:

  • (String)

    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,
      ,
      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'] || ,
      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,
        ,
        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

#cityString

Returns the city of the bank account.

Returns:

  • (String)

    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,
      ,
      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'] || ,
      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,
        ,
        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_idInteger

Returns the ID of the currency associated with the bank account.

Returns:

  • (Integer)

    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,
      ,
      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'] || ,
      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,
        ,
        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

#descriptionString

Returns the description of the bank account.

Returns:

  • (String)

    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,
      ,
      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'] || ,
      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,
        ,
        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_addressString

Returns the Google address of the bank account.

Returns:

  • (String)

    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,
      ,
      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'] || ,
      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,
        ,
        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_noString

Returns the institution number of the bank account.

Returns:

  • (String)

    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,
      ,
      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'] || ,
      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,
        ,
        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_defaultBoolean

Returns whether the bank account is the default account.

Returns:

  • (Boolean)

    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,
      ,
      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'] || ,
      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,
        ,
        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

#nameString

Returns the name of the bank account.

Returns:

  • (String)

    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,
      ,
      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'] || ,
      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,
        ,
        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_codeString

Returns the postal code of the bank account.

Returns:

  • (String)

    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,
      ,
      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'] || ,
      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,
        ,
        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_idInteger

Returns the ID of the province associated with the bank account.

Returns:

  • (Integer)

    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,
      ,
      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'] || ,
      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,
        ,
        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_idInteger

Returns the ID of the reference (employee or company).

Returns:

  • (Integer)

    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,
      ,
      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'] || ,
      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,
        ,
        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

#sourceString

Returns the source of the bank account, either ‘Employee’ or ‘Company’.

Returns:

  • (String)

    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,
      ,
      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'] || ,
      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,
        ,
        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.

Examples:

Find an active bank account for an employee

 = BankAccount.find_by_procedure(
  reference_id: 1,
  bank_account_id: 1,
  source: 'Employee',
  active: true
)

Parameters:

  • reference_id (Integer)

    the ID of the reference (employee or company)

  • bank_account_id (Integer)

    the ID of the bank account

  • source (String) (defaults to: 'Company')

    the source of the bank account, either ‘Employee’ or ‘Company’

  • active (Boolean) (defaults to: true)

    whether the bank account is active

Returns:



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,
    ,
    active
  )[0]
end

Instance Method Details

#address_line1String

Returns the first line of the address of the bank account.

Examples:

address_line1 = .address_line1

Returns:

  • (String)

    the first line of the address



151
152
153
# File 'app/models/bank_account.rb', line 151

def address_line1
  address_line_1
end

#address_line2String

Returns the second line of the address of the bank account.

Examples:

address_line2 = .address_line2

Returns:

  • (String)

    the second line of the address



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.

Examples:

 = 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
)
.insert_update_procedure(user_name: 'admin')

Parameters:

  • user_name (String)

    the name of the user performing the operation

Returns:

  • (BankAccount)

    the inserted or updated bank account



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,
    ,
    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'] || ,
    is_default,
    active,
    user_name
  )[0]
end

#referenceEmployee, Company

Returns the reference (employee or company) associated with the bank account.

Examples:

reference = .reference

Returns:



142
143
144
# File 'app/models/bank_account.rb', line 142

def reference
  source == SOURCE[:EMPLOYEE] ? Employee.find(reference_id) : Company.find(reference_id)
end