Class: BizTxnAcctRoot
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- BizTxnAcctRoot
- Includes:
- ErpTechSvcs::Utils::DefaultNestedSetMethods
- Defined in:
- app/models/biz_txn_acct_root.rb
Overview
create_table :biz_txn_acct_roots do |t| t.string :description t.string :internal_identifier t.integer :status t.integer :biz_txn_acct_id t.string :biz_txn_acct_type t.string :external_identifier t.string :external_id_source t.string :type
t.integer :parent_id
t.integer :lft
t.integer :rgt
t.references :biz_txn_acct_type
t.
end
add_index :biz_txn_acct_roots, [:biz_txn_acct_id, :biz_txn_acct_type], :name => "btai_2" add_index :biz_txn_acct_roots, :biz_txn_acct_type_id, :name => "btai_3" add_index :biz_txn_acct_roots, :parent_id add_index :biz_txn_acct_roots, :lft add_index :biz_txn_acct_roots, :rgt
Class Method Summary collapse
-
.apply_filters(filters, statement = nil) ⇒ ActiveRecord::Relation
Filter records.
-
.iid(internal_identifier) ⇒ Object
Look up account by internal identifier.
-
.scope_by_dba_organization(dba_organization) ⇒ ActiveRecord::Relation
(also: scope_by_dba)
scope by dba organization.
-
.scope_by_party(party, options = {}) ⇒ ActiveRecord::Relation
scope by party.
Instance Method Summary collapse
- #add_party_with_role(party, biz_txn_acct_pty_rtype, description = nil) ⇒ Object
- #find_parties_by_role(biz_txn_acct_pty_rtype) ⇒ Object
- #to_data_hash ⇒ Object
- #to_label ⇒ Object
- #to_s ⇒ Object
Class Method Details
.apply_filters(filters, statement = nil) ⇒ ActiveRecord::Relation
Filter records
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 |
# File 'app/models/biz_txn_acct_root.rb', line 50 def apply_filters(filters, statement=nil) unless statement statement = self end # filter by parent if filters[:parent] if filters[:parent].is_integer? statement = statement.where(biz_txn_acct_roots: {parent_id: filters[:parent]}) else statement = statement.where(biz_txn_acct_roots: {parent_id: BizTxnAcctRoot.iid(filters[:parent])}) end end # filter by query which will filter on description if filters[:query] statement = statement.where('description like ?', "%#{filters[:query].strip}%") end # filter by BizTxnAcctType unless filters[:biz_txn_acct_type_iids].blank? statement = statement.joins(:biz_txn_acct_type).where(biz_txn_acct_type: {internal_identifier: filters[:biz_txn_acct_type_iids]}) end # filter by Status unless filters[:status].blank? statement = statement.with_current_status(filters[:status].split(',')) end unless filters[:parties].blank? data = JSON.parse(filters[:parties]) statement = statement.scope_by_party(data['party_ids'].split(','), {role_types: data['role_types']}) end statement end |
.iid(internal_identifier) ⇒ Object
Look up account by internal identifier
128 129 130 |
# File 'app/models/biz_txn_acct_root.rb', line 128 def iid(internal_identifier) where('internal_identifier = ?', internal_identifier).first end |
.scope_by_dba_organization(dba_organization) ⇒ ActiveRecord::Relation Also known as: scope_by_dba
scope by dba organization
93 94 95 |
# File 'app/models/biz_txn_acct_root.rb', line 93 def scope_by_dba_organization(dba_organization) scope_by_party(dba_organization, {role_types: 'dba_org'}) end |
.scope_by_party(party, options = {}) ⇒ ActiveRecord::Relation
scope by party
or an array of Party ids comma separated or an Array
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/biz_txn_acct_root.rb', line 108 def scope_by_party(party, ={}) statement = joins(:biz_txn_acct_party_roles) .where(biz_txn_acct_party_roles: {party_id: party}).uniq if [:role_types] role_types = [:role_types] unless role_types.is_a? Array role_types = role_types.split(',') end statement = statement.joins(biz_txn_acct_party_roles: :biz_txn_acct_pty_rtype) .where(biz_txn_acct_pty_rtypes: {internal_identifier: role_types}) end statement end |
Instance Method Details
#add_party_with_role(party, biz_txn_acct_pty_rtype, description = nil) ⇒ Object
141 142 143 144 145 146 147 148 149 150 |
# File 'app/models/biz_txn_acct_root.rb', line 141 def add_party_with_role(party, biz_txn_acct_pty_rtype, description=nil) biz_txn_acct_pty_rtype = BizTxnAcctPtyRtype.iid(biz_txn_acct_pty_rtype) if biz_txn_acct_pty_rtype.is_a? String raise "BizTxnAcctPtyRtype #{biz_txn_acct_pty_rtype.to_s} does not exist" if biz_txn_acct_pty_rtype.nil? # get description from biz_txn_acct_pty_rtype if not passed description = biz_txn_acct_pty_rtype.description unless description self.biz_txn_acct_party_roles << BizTxnAcctPartyRole.create(:party => party, :description => description, :biz_txn_acct_pty_rtype => biz_txn_acct_pty_rtype) self.save end |
#find_parties_by_role(biz_txn_acct_pty_rtype) ⇒ Object
152 153 154 155 156 157 158 159 |
# File 'app/models/biz_txn_acct_root.rb', line 152 def find_parties_by_role(biz_txn_acct_pty_rtype) biz_txn_acct_pty_rtype = BizTxnAcctPtyRtype.iid(biz_txn_acct_pty_rtype) if biz_txn_acct_pty_rtype.is_a? String raise "BizTxnAcctPtyRtype #{biz_txn_acct_pty_rtype.to_s} does not exist" if biz_txn_acct_pty_rtype.nil? Party.joins('inner join biz_txn_acct_party_roles on biz_txn_acct_party_roles.party_id = parties.id') .where('biz_txn_acct_pty_rtype_id = ?', biz_txn_acct_pty_rtype.id) .where('biz_txn_acct_root_id = ?', self.id) end |
#to_data_hash ⇒ Object
161 162 163 |
# File 'app/models/biz_txn_acct_root.rb', line 161 def to_data_hash to_hash(only: [:id, :description, :internal_identifier]) end |
#to_label ⇒ Object
133 134 135 |
# File 'app/models/biz_txn_acct_root.rb', line 133 def to_label "#{description}" end |
#to_s ⇒ Object
137 138 139 |
# File 'app/models/biz_txn_acct_root.rb', line 137 def to_s "#{description}" end |