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
33 34 35 36 37 38 |
# File 'app/models/accountability/account.rb', line 33 def balance accrued_credits = credits.sum(:amount) accrued_debits = debits.sum(:amount) accrued_debits - accrued_credits end |
#balanced? ⇒ Boolean
40 41 42 |
# File 'app/models/accountability/account.rb', line 40 def balanced? balance >= 0.00 end |
#billable_record_name ⇒ Object
28 29 30 31 |
# File 'app/models/accountability/account.rb', line 28 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
20 21 22 23 24 25 26 |
# File 'app/models/accountability/account.rb', line 20 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
50 51 52 53 54 55 56 57 |
# File 'app/models/accountability/account.rb', line 50 def current_statement latest_statement = statements.last return if latest_statement.nil? return if latest_statement.past? latest_statement end |
#transactions ⇒ Object
44 45 46 47 48 |
# File 'app/models/accountability/account.rb', line 44 def transactions associated_credits = credits.includes(:product, deductions: :discount).references(:order_item) Transactions.new(debits: debits, credits: associated_credits) end |