Class: MercuryBanking::CLI::Financials::FinancialsCommand

Inherits:
Thor
  • Object
show all
Includes:
BalanceSheetHelper, Base, Formatters::ExportFormatter
Defined in:
lib/mercury_banking/cli/financials.rb

Overview

Define the financials command class

Class Attribute Summary collapse

Instance Method Summary collapse

Methods included from BalanceSheetHelper

#display_balance_cross_check, #get_mercury_balances

Methods included from Formatters::ExportFormatter

#export_to_beancount, #export_to_csv, #export_to_hledger, #export_to_ledger, #sort_transactions_chronologically, #verify_ledger_file

Methods included from Base

#api_key, #command_exists?, #get_api_key, #log_transfer, #with_api_client

Class Attribute Details

.parent_classObject

Returns the value of attribute parent_class.



206
207
208
# File 'lib/mercury_banking/cli/financials.rb', line 206

def parent_class
  @parent_class
end

Instance Method Details

#balancecheckObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/mercury_banking/cli/financials.rb', line 118

def balancecheck
  with_api_client do |client|
    accounts = client.accounts

    unless options[:ledger_file] && File.exist?(options[:ledger_file])
      puts "Error: You must provide a valid ledger file to check. Use --ledger-file option."
      return
    end

    # Get balances from the ledger file
    ledger_file = options[:ledger_file]
    format = options[:format] || File.extname(ledger_file).delete('.').downcase
    
    # Get ledger balances
    ledger_balances = get_ledger_balances(ledger_file, format)
    
    if ledger_balances.empty?
      puts "No account balances found in the ledger file."
      return
    end

    # Get current balances for all Mercury accounts
    mercury_balances = get_mercury_balances(accounts)

    # Display cross-check between Mercury and ledger balances
    display_balance_cross_check(mercury_balances, ledger_balances, options[:verbose])
  end
end