Class: BizTxnEvent
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- BizTxnEvent
- Defined in:
- app/models/biz_txn_event.rb
Overview
Table Definition ########################### create_table :biz_txn_events do |t| t.column :description, :string t.column :biz_txn_acct_root_id, :integer t.column :biz_txn_type_id, :integer t.column :entered_date, :datetime t.column :post_date, :datetime t.column :biz_txn_record_id, :integer t.column :biz_txn_record_type, :string t.column :external_identifier, :string t.column :external_id_source, :string t.timestamps end
add_index :biz_txn_events, :biz_txn_acct_root_id add_index :biz_txn_events, :biz_txn_type_id add_index :biz_txn_events, [:biz_txn_record_id, :biz_txn_record_type], :name => "btai_1"
Class Method Summary collapse
-
.apply_filters(filters, statement = nil) ⇒ ActiveRecord::Relation
Filter records.
-
.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
-
#account_root ⇒ BizTxnAcctRoot
get biz_txn_acct_root.
-
#amount ⇒ BigDecimal | nil
get the amount of this txn if it responds to amount.
-
#amount_string ⇒ String | nil
get the amount of this txn as a string if it responds to amount_string.
-
#create_dependent_txns ⇒ Object
template method to create dependent BizTxnEvents.
-
#dba_organization ⇒ Party
(also: #dba_org)
Get the dba_organization related to this BizTxnEvent.
- #destroy_biz_txn_relationships ⇒ Object
-
#find_party_by_role_type(role_type) ⇒ Party | nil
gets the first party related to this BizTxnEvent with the given BizTxnPartyRoleType.
-
#to_data_hash ⇒ Hash
converts this record a hash data representation.
-
#to_label ⇒ String
returns description of this BizTxnEvent.
-
#to_s ⇒ String
returns description of this BizTxnEvent.
-
#txn_type_iid ⇒ Object
helps when looping through transactions comparing types.
Class Method Details
.apply_filters(filters, statement = nil) ⇒ ActiveRecord::Relation
Filter records
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 |
# File 'app/models/biz_txn_event.rb', line 55 def apply_filters(filters, statement=nil) unless statement statement = self end biz_txn_event_tbl = BizTxnEvent.arel_table # filter by query which will filter on description if filters[:query] statement = statement.where('description like ?', "%#{filters[:query].strip}%") end # filter by WorkEffortType unless filters[:biz_txn_type_iids].blank? statement = statement.where(biz_txn_type_id: BizTxnType.where(internal_identifier: filters[:biz_txn_type_iids])) end # filter by Status unless filters[:status].blank? statement = statement.with_current_status(filters[:status].split(',')) end # filter by start_at unless filters[:start_date].blank? statement = statement.where(biz_txn_event_tbl[:entered_date].gteq(Time.parse(filters[:start_date]))) end # filter by end_at unless filters[:end_date].blank? statement = statement.where(biz_txn_event_tbl[:entered_date].lteq(Time.parse(filters[:end_date]))) 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 |
.scope_by_dba_organization(dba_organization) ⇒ ActiveRecord::Relation Also known as: scope_by_dba
scope by dba organization
105 106 107 |
# File 'app/models/biz_txn_event.rb', line 105 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
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/models/biz_txn_event.rb', line 120 def scope_by_party(party, ={}) statement = joins("inner join biz_txn_party_roles on biz_txn_party_roles.biz_txn_event_id = biz_txn_events.id") .where("biz_txn_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("inner join biz_txn_party_role_types on biz_txn_party_role_types.id = biz_txn_party_roles.biz_txn_party_role_type_id") .where(biz_txn_party_role_types: {internal_identifier: role_types}) end statement end |
Instance Method Details
#account_root ⇒ BizTxnAcctRoot
get biz_txn_acct_root
167 168 169 |
# File 'app/models/biz_txn_event.rb', line 167 def account_root biz_txn_acct_root end |
#amount ⇒ BigDecimal | nil
get the amount of this txn if it responds to amount
174 175 176 177 178 179 180 |
# File 'app/models/biz_txn_event.rb', line 174 def amount if biz_txn_record.respond_to? :amount biz_txn_record.amount else nil end end |
#amount_string ⇒ String | nil
get the amount of this txn as a string if it responds to amount_string
185 186 187 188 189 190 191 |
# File 'app/models/biz_txn_event.rb', line 185 def amount_string if biz_txn_record.respond_to? :amount_string biz_txn_record.amount_string else "n/a" end end |
#create_dependent_txns ⇒ Object
template method to create dependent BizTxnEvents
241 242 243 |
# File 'app/models/biz_txn_event.rb', line 241 def create_dependent_txns #Template Method end |
#dba_organization ⇒ Party Also known as: dba_org
Get the dba_organization related to this BizTxnEvent
142 143 144 145 146 147 148 149 150 |
# File 'app/models/biz_txn_event.rb', line 142 def dba_organization dba_org_role_type = BizTxnPartyRoleType.find_or_create('dba_org', 'DBA Organization') biz_txn_party_role = biz_txn_party_roles.where('biz_txn_party_roles.biz_txn_party_role_type_id' => dba_org_role_type).first if biz_txn_party_role biz_txn_party_role.party end end |
#destroy_biz_txn_relationships ⇒ Object
154 155 156 |
# File 'app/models/biz_txn_event.rb', line 154 def destroy_biz_txn_relationships BizTxnRelationship.where("txn_event_id_from = ? or txn_event_id_to = ?", self.id, self.id).destroy_all end |
#find_party_by_role_type(role_type) ⇒ Party | nil
gets the first party related to this BizTxnEvent with the given BizTxnPartyRoleType
197 198 199 200 201 202 203 204 205 |
# File 'app/models/biz_txn_event.rb', line 197 def find_party_by_role_type(role_type) role_type = role_type.is_a?(String) ? BizTxnPartyRoleType.iid(role_type) : role_type biz_txn_party_role = biz_txn_party_roles.where(:biz_txn_party_role_type_id => role_type.id).first if biz_txn_party_role biz_txn_party_role.party end end |
#to_data_hash ⇒ Hash
converts this record a hash data representation
224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'app/models/biz_txn_event.rb', line 224 def to_data_hash data = to_hash(only: [:id, :description, :entered_date, :post_date, :external_identifier, :external_id_source, :created_at, :updated_at]) data[:status] = self.try(:current_status_application).try(:to_data_hash) data end |
#to_label ⇒ String
returns description of this BizTxnEvent
210 211 212 |
# File 'app/models/biz_txn_event.rb', line 210 def to_label "#{description}" end |
#to_s ⇒ String
returns description of this BizTxnEvent
217 218 219 |
# File 'app/models/biz_txn_event.rb', line 217 def to_s "#{description}" end |
#txn_type_iid ⇒ Object
helps when looping through transactions comparing types
160 161 162 |
# File 'app/models/biz_txn_event.rb', line 160 def txn_type_iid biz_txn_type.internal_identifier if biz_txn_type end |