mercury_banking 0.5.36 → 0.5.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/mercury_banking/api.rb +1 -0
- data/lib/mercury_banking/cli/transactions.rb +16 -1
- data/lib/mercury_banking/reports/balance_sheet.rb +64 -16
- data/lib/mercury_banking/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd83aeec4085d1c49fe77f7ca68fbc0b7c215dc37deafba3b36a20da0e7f46c4
|
4
|
+
data.tar.gz: 102b6b607353df20f4494c758935fe3f3517a2a4c95fca8440f9598b364d4f71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06a9d7eea59264a65f07ef4073189c390b8b0d025bdbeced8af797d06f67066e14cd704db814ad61ebaedd03c0682171a5604b2be295463751808b2ddc2057b5
|
7
|
+
data.tar.gz: b4898456ae09b4cceb0bf6a23c01fe7f860073fd76d069f1b70c0e5a4fc8c266ce52999351dfc319178730cea7779c9649076c43398604aaeadf9824ce9d8d49
|
data/Gemfile.lock
CHANGED
data/lib/mercury_banking/api.rb
CHANGED
@@ -112,6 +112,7 @@ module MercuryBanking
|
|
112
112
|
account_transactions.each do |transaction|
|
113
113
|
transaction["accountName"] = account["name"]
|
114
114
|
transaction["accountId"] = account["id"]
|
115
|
+
transaction["accountNumber"] = account["accountNumber"]
|
115
116
|
end
|
116
117
|
all_transactions.concat(account_transactions)
|
117
118
|
rescue StandardError => e
|
@@ -27,7 +27,7 @@ module MercuryBanking
|
|
27
27
|
end_date = options[:end_date]
|
28
28
|
|
29
29
|
# Get format
|
30
|
-
format = options[:format]
|
30
|
+
format = options[:format] || 'all'
|
31
31
|
|
32
32
|
# Get verbose option
|
33
33
|
verbose = options[:verbose]
|
@@ -36,12 +36,20 @@ module MercuryBanking
|
|
36
36
|
accounts.each do |account|
|
37
37
|
account_id = account["id"]
|
38
38
|
account_name = account["name"]
|
39
|
+
account_number = account["accountNumber"]
|
39
40
|
|
40
41
|
puts "Fetching transactions for #{account_name} (#{account_id})..."
|
41
42
|
|
42
43
|
# Get all transactions for this account
|
43
44
|
transactions = client.get_transactions(account_id, start_date)
|
44
45
|
|
46
|
+
# Add account information to each transaction
|
47
|
+
transactions.each do |transaction|
|
48
|
+
transaction["accountName"] = account_name
|
49
|
+
transaction["accountId"] = account_id
|
50
|
+
transaction["accountNumber"] = account_number
|
51
|
+
end
|
52
|
+
|
45
53
|
# Filter by end date if specified
|
46
54
|
if end_date
|
47
55
|
end_date_obj = Date.parse(end_date)
|
@@ -135,6 +143,13 @@ module MercuryBanking
|
|
135
143
|
puts "Fetching transactions for #{account["name"]}..."
|
136
144
|
transactions = client.get_transactions(account_id, start_date)
|
137
145
|
|
146
|
+
# Add account information to each transaction
|
147
|
+
transactions.each do |transaction|
|
148
|
+
transaction["accountName"] = account["name"]
|
149
|
+
transaction["accountId"] = account["id"]
|
150
|
+
transaction["accountNumber"] = account["accountNumber"]
|
151
|
+
end
|
152
|
+
|
138
153
|
# Filter by end date if specified
|
139
154
|
if end_date
|
140
155
|
end_date_obj = Date.parse(end_date)
|
@@ -461,12 +461,27 @@ module MercuryBanking
|
|
461
461
|
end
|
462
462
|
|
463
463
|
def write_ledger_account_declarations(file, transactions)
|
464
|
-
# Get unique
|
465
|
-
|
464
|
+
# Get unique accounts from transactions
|
465
|
+
accounts = transactions.map do |t|
|
466
|
+
{
|
467
|
+
"name" => t["accountName"] || "Unknown Account",
|
468
|
+
"number" => t["accountNumber"]
|
469
|
+
}
|
470
|
+
end.uniq { |a| [a["name"], a["number"]] }
|
466
471
|
|
467
472
|
# Define accounts dynamically based on transaction data
|
468
|
-
|
469
|
-
|
473
|
+
accounts.each do |account|
|
474
|
+
account_name = account["name"]
|
475
|
+
account_number = account["number"]
|
476
|
+
|
477
|
+
# Format the account name to include the account number if available
|
478
|
+
formatted_account_name = if account_number
|
479
|
+
"#{account_name} #{account_number.to_s[-4..-1]}"
|
480
|
+
else
|
481
|
+
account_name
|
482
|
+
end
|
483
|
+
|
484
|
+
file.puts "account Assets:#{formatted_account_name}"
|
470
485
|
end
|
471
486
|
file.puts "account Expenses:Unknown"
|
472
487
|
file.puts "account Income:Unknown"
|
@@ -490,23 +505,31 @@ module MercuryBanking
|
|
490
505
|
description = transaction["bankDescription"] || transaction["externalMemo"] || "Unknown transaction"
|
491
506
|
amount = transaction["amount"]
|
492
507
|
account_name = transaction["accountName"] || "Unknown Account"
|
508
|
+
account_number = transaction["accountNumber"]
|
493
509
|
|
494
510
|
file.puts "#{date} #{description}"
|
495
511
|
file.puts " ; Transaction ID: #{transaction["id"]}"
|
496
512
|
file.puts " ; Status: #{transaction["status"]}"
|
497
513
|
file.puts " ; Reconciled: No"
|
498
514
|
|
499
|
-
write_ledger_postings(file, amount, account_name)
|
515
|
+
write_ledger_postings(file, amount, account_name, account_number)
|
500
516
|
file.puts
|
501
517
|
end
|
502
518
|
|
503
|
-
def write_ledger_postings(file, amount, account_name)
|
519
|
+
def write_ledger_postings(file, amount, account_name, account_number = nil)
|
520
|
+
# Format the account name to include the account number if available
|
521
|
+
formatted_account_name = if account_number
|
522
|
+
"#{account_name} #{account_number.to_s[-4..-1]}"
|
523
|
+
else
|
524
|
+
account_name
|
525
|
+
end
|
526
|
+
|
504
527
|
if amount > 0
|
505
528
|
file.puts " Income:Unknown $-#{format("%.2f", amount)}"
|
506
|
-
file.puts " Assets:#{
|
529
|
+
file.puts " Assets:#{formatted_account_name} $#{format("%.2f", amount)}"
|
507
530
|
else
|
508
531
|
file.puts " Expenses:Unknown $#{format("%.2f", amount.abs)}"
|
509
|
-
file.puts " Assets:#{
|
532
|
+
file.puts " Assets:#{formatted_account_name} $-#{format("%.2f", amount.abs)}"
|
510
533
|
end
|
511
534
|
end
|
512
535
|
|
@@ -529,14 +552,30 @@ module MercuryBanking
|
|
529
552
|
end
|
530
553
|
|
531
554
|
def write_beancount_account_declarations(file, transactions)
|
532
|
-
# Get unique
|
533
|
-
|
555
|
+
# Get unique accounts from transactions
|
556
|
+
accounts = transactions.map do |t|
|
557
|
+
{
|
558
|
+
"name" => t["accountName"] || "Unknown Account",
|
559
|
+
"number" => t["accountNumber"]
|
560
|
+
}
|
561
|
+
end.uniq { |a| [a["name"], a["number"]] }
|
534
562
|
|
535
563
|
# Define accounts dynamically based on transaction data
|
536
|
-
|
564
|
+
accounts.each do |account|
|
565
|
+
account_name = account["name"]
|
566
|
+
account_number = account["number"]
|
567
|
+
|
537
568
|
# Sanitize account name for beancount format
|
538
569
|
safe_account_name = account_name.gsub(/[^a-zA-Z0-9]/, '-')
|
539
|
-
|
570
|
+
|
571
|
+
# Format the account name to include the account number if available
|
572
|
+
formatted_account_name = if account_number
|
573
|
+
"#{safe_account_name}-#{account_number.to_s[-4..-1]}"
|
574
|
+
else
|
575
|
+
safe_account_name
|
576
|
+
end
|
577
|
+
|
578
|
+
file.puts "1970-01-01 open Assets:#{formatted_account_name}"
|
540
579
|
end
|
541
580
|
file.puts "1970-01-01 open Expenses:Unknown"
|
542
581
|
file.puts "1970-01-01 open Income:Unknown"
|
@@ -560,6 +599,8 @@ module MercuryBanking
|
|
560
599
|
description = transaction["bankDescription"] || transaction["externalMemo"] || "Unknown transaction"
|
561
600
|
amount = transaction["amount"]
|
562
601
|
account_name = transaction["accountName"] || "Unknown Account"
|
602
|
+
account_number = transaction["accountNumber"]
|
603
|
+
|
563
604
|
# Sanitize account name for beancount format
|
564
605
|
safe_account_name = account_name.gsub(/[^a-zA-Z0-9]/, '-')
|
565
606
|
|
@@ -568,17 +609,24 @@ module MercuryBanking
|
|
568
609
|
file.puts " ; Status: #{transaction["status"]}"
|
569
610
|
file.puts " ; Reconciled: No"
|
570
611
|
|
571
|
-
write_beancount_postings(file, amount, safe_account_name)
|
612
|
+
write_beancount_postings(file, amount, safe_account_name, account_number)
|
572
613
|
file.puts
|
573
614
|
end
|
574
615
|
|
575
|
-
def write_beancount_postings(file, amount, account_name)
|
616
|
+
def write_beancount_postings(file, amount, account_name, account_number = nil)
|
617
|
+
# Format the account name to include the account number if available
|
618
|
+
formatted_account_name = if account_number
|
619
|
+
"#{account_name}-#{account_number.to_s[-4..-1]}"
|
620
|
+
else
|
621
|
+
account_name
|
622
|
+
end
|
623
|
+
|
576
624
|
if amount > 0
|
577
625
|
file.puts " Income:Unknown -#{format("%.2f", amount)} USD"
|
578
|
-
file.puts " Assets:#{
|
626
|
+
file.puts " Assets:#{formatted_account_name} #{format("%.2f", amount)} USD"
|
579
627
|
else
|
580
628
|
file.puts " Expenses:Unknown #{format("%.2f", amount.abs)} USD"
|
581
|
-
file.puts " Assets:#{
|
629
|
+
file.puts " Assets:#{formatted_account_name} -#{format("%.2f", amount.abs)} USD"
|
582
630
|
end
|
583
631
|
end
|
584
632
|
end
|