Module: MercuryBanking::CLI::Reconciliation::ReconcileAllCommand
- Defined in:
- lib/mercury_banking/cli/reconciliation.rb
Overview
Module for reconcile_all command
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/mercury_banking/cli/reconciliation.rb', line 248 def self.included(base) base.class_eval do desc 'reconcile_all ACCOUNT_ID_OR_NUMBER', 'Mark all transactions as reconciled up to a specified date' method_option :date, type: :string, desc: 'Date up to which to reconcile transactions (YYYY-MM-DD). Defaults to current date.' method_option :start, type: :string, default: '2020-01-01', desc: 'Start date for transactions (YYYY-MM-DD)' method_option :dry_run, type: :boolean, default: false, desc: 'Show what would be reconciled without making changes' method_option :json, type: :boolean, default: false, desc: 'Output in JSON format' method_option :debug, type: :boolean, default: false, desc: 'Show debug information' def reconcile_all(account_identifier) with_api_client do |client| # Resolve account identifier to account ID account_id = resolve_account_id(client, account_identifier) account = client.get_account(account_id) # Get the date up to which to reconcile transactions reconcile_date = [:date] ? Date.parse([:date]) : Date.today start_date = [:start] # Get transactions for the account transactions = client.get_transactions(account_id, start_date) # Filter transactions up to the reconcile date transactions_to_reconcile = transactions.select do |t| transaction_date = Date.parse(t["postedAt"] || t["createdAt"]) transaction_date <= reconcile_date end # Get current reconciliation status reconciliation = MercuryBanking::Reconciliation.new status = reconciliation.get_reconciliation_status(account_id, transactions_to_reconcile) # Filter for unreconciled transactions unreconciled = status.reject { |t| t[:reconciled] } # Display debug information if requested display_debug_info(account_id, account, reconcile_date, transactions_to_reconcile, unreconciled) if [:debug] # Display reconciliation information display_reconciliation_info(account, reconcile_date, start_date, unreconciled, ) # If this is a dry run, don't actually reconcile anything if [:dry_run] puts "DRY RUN: No transactions will be reconciled" return end # Reconcile transactions reconcile_transactions(account_id, unreconciled, reconciliation, ) end end end end |