Class: FinancialTxn
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- FinancialTxn
- Defined in:
- app/models/financial_txn.rb
Overview
Table Definition ########################### create_table :financial_txns do |t| t.integer :money_id t.date :apply_date
t.
end
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
-
#to_data_hash ⇒ Hash
converts this record a hash data representation.
Class Method Details
.apply_filters(filters, statement = nil) ⇒ ActiveRecord::Relation
Filter records
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/financial_txn.rb', line 24 def apply_filters(filters, statement=nil) unless statement statement = FinancialTxn end statement = statement.joins(:biz_txn_event) biz_txn_event_tbl = BizTxnEvent.arel_table # filter by query which will filter on description if filters[:query] statement = statement.where('biz_txn_events.description like ?', "%#{filters[:query].strip}%") end # filter by WorkEffortType unless filters[:biz_txn_type_iids].blank? statement = statement.where(biz_txn_events: {biz_txn_type_id: BizTxnType.where(internal_identifier: filters[:biz_txn_type_iids])}) 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
71 72 73 74 75 76 77 78 |
# File 'app/models/financial_txn.rb', line 71 def scope_by_dba_organization(dba_organization) dba_org_role_type = BizTxnPartyRoleType.find_or_create('dba_org', 'DBA Organization') joins(:biz_txn_event) .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' => dba_organization) .where('biz_txn_party_roles.biz_txn_party_role_type_id' => dba_org_role_type) end |
.scope_by_party(party, options = {}) ⇒ ActiveRecord::Relation
scope by party
or an array of Party ids comma separated or an Array
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/models/financial_txn.rb', line 91 def scope_by_party(party, ={}) statement = joins(:biz_txn_event) .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
#to_data_hash ⇒ Hash
converts this record a hash data representation
115 116 117 118 119 120 121 |
# File 'app/models/financial_txn.rb', line 115 def to_data_hash data = to_hash(only: [:id, :description, :apply_date]) data[:amount] = self.money.nil? ? 0 : self.money.amount data end |