Class: Accountability::Account
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Accountability::Account
- Defined in:
- app/models/accountability/account.rb
Instance Method Summary collapse
- #balance ⇒ Object
- #balanced? ⇒ Boolean
- #billable_record_name ⇒ Object
- #build_billing_configuration_with_active_merchant_data(billing_configuration_params, **options) ⇒ Object
- #current_statement ⇒ Object
- #transactions ⇒ Object
Methods inherited from ApplicationRecord
Instance Method Details
#balance ⇒ Object
32 33 34 35 36 37 |
# File 'app/models/accountability/account.rb', line 32 def balance accrued_credits = credits.sum(:amount) accrued_debits = debits.sum(:amount) accrued_debits - accrued_credits end |
#balanced? ⇒ Boolean
39 40 41 |
# File 'app/models/accountability/account.rb', line 39 def balanced? balance >= 0.00 end |
#billable_record_name ⇒ Object
27 28 29 30 |
# File 'app/models/accountability/account.rb', line 27 def billable_record_name name_method = Configuration.billable_name_column billable.public_send(name_method) end |
#build_billing_configuration_with_active_merchant_data(billing_configuration_params, **options) ⇒ Object
19 20 21 22 23 24 25 |
# File 'app/models/accountability/account.rb', line 19 def build_billing_configuration_with_active_merchant_data(billing_configuration_params, **) billing_configuration = billing_configurations.build(billing_configuration_params) # We don't want to run this too often as it does create a charge against the card when verify_card is true. # so we'll only run this when the config is valid. billing_configuration.store_active_merchant_data(**) if billing_configuration.valid? billing_configuration end |
#current_statement ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'app/models/accountability/account.rb', line 49 def current_statement latest_statement = statements.last return if latest_statement.nil? return if latest_statement.past? latest_statement end |
#transactions ⇒ Object
43 44 45 46 47 |
# File 'app/models/accountability/account.rb', line 43 def transactions associated_credits = credits.includes(:product, deductions: :discount).references(:order_item) Transactions.new(debits: debits, credits: associated_credits) end |