rock_books 0.4.0 → 0.7.1

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -2
  3. data/RELEASE_NOTES.md +33 -0
  4. data/assets/fonts/JetBrainsMono-Medium.ttf +0 -0
  5. data/lib/rock_books/cmd_line/command_line_interface.rb +6 -6
  6. data/lib/rock_books/cmd_line/main.rb +1 -9
  7. data/lib/rock_books/documents/book_set.rb +4 -136
  8. data/lib/rock_books/documents/chart_of_accounts.rb +29 -12
  9. data/lib/rock_books/documents/journal.rb +2 -6
  10. data/lib/rock_books/documents/journal_entry.rb +7 -2
  11. data/lib/rock_books/documents/journal_entry_builder.rb +4 -0
  12. data/lib/rock_books/helpers/book_set_loader.rb +3 -3
  13. data/lib/rock_books/reports/balance_sheet.rb +9 -43
  14. data/lib/rock_books/reports/book_set_reporter.rb +207 -0
  15. data/lib/rock_books/reports/data/bs_is_data.rb +61 -0
  16. data/lib/rock_books/reports/data/bs_is_section_data.rb +28 -0
  17. data/lib/rock_books/reports/data/journal_data.rb +37 -0
  18. data/lib/rock_books/reports/data/multidoc_txn_by_account_data.rb +40 -0
  19. data/lib/rock_books/reports/data/multidoc_txn_report_data.rb +39 -0
  20. data/lib/rock_books/reports/data/receipts_report_data.rb +47 -0
  21. data/lib/rock_books/reports/data/tx_one_account_data.rb +37 -0
  22. data/lib/rock_books/reports/helpers/erb_helper.rb +21 -0
  23. data/lib/rock_books/reports/helpers/html_report_helper.rb +35 -0
  24. data/lib/rock_books/reports/helpers/text_report_helper.rb +134 -0
  25. data/lib/rock_books/reports/income_statement.rb +9 -47
  26. data/lib/rock_books/reports/journal_report.rb +72 -0
  27. data/lib/rock_books/reports/multidoc_txn_by_account_report.rb +32 -0
  28. data/lib/rock_books/reports/multidoc_txn_report.rb +25 -0
  29. data/lib/rock_books/reports/receipts_report.rb +6 -55
  30. data/lib/rock_books/reports/templates/html/index.html.erb +141 -0
  31. data/lib/rock_books/reports/templates/html/report_page.html.erb +12 -0
  32. data/lib/rock_books/reports/templates/text/_receipt_section.txt.erb +17 -0
  33. data/lib/rock_books/reports/templates/text/_totals.txt.erb +8 -0
  34. data/lib/rock_books/reports/templates/text/balance_sheet.txt.erb +21 -0
  35. data/lib/rock_books/reports/templates/text/income_statement.txt.erb +21 -0
  36. data/lib/rock_books/reports/templates/text/journal.txt.erb +20 -0
  37. data/lib/rock_books/reports/templates/text/multidoc_txn_by_account_report.txt.erb +28 -0
  38. data/lib/rock_books/reports/templates/text/multidoc_txn_report.txt.erb +22 -0
  39. data/lib/rock_books/reports/templates/text/receipts_report.txt.erb +13 -0
  40. data/lib/rock_books/reports/templates/text/tx_one_account.txt.erb +18 -0
  41. data/lib/rock_books/reports/tx_one_account.rb +10 -45
  42. data/lib/rock_books/types/account.rb +13 -1
  43. data/lib/rock_books/types/account_type.rb +18 -7
  44. data/lib/rock_books/version.rb +1 -1
  45. data/rock_books.gemspec +5 -3
  46. metadata +64 -16
  47. data/lib/rock_books/documents/index.html.erb +0 -156
  48. data/lib/rock_books/documents/receipts.html.erb +0 -54
  49. data/lib/rock_books/reports/multidoc_transaction_report.rb +0 -66
  50. data/lib/rock_books/reports/reporter.rb +0 -118
  51. data/lib/rock_books/reports/transaction_report.rb +0 -105
  52. data/lib/rock_books/reports/tx_by_account.rb +0 -82
@@ -0,0 +1,18 @@
1
+ <%= banner_line %>
2
+ <%= fn_center.(entity || 'Unspecified Entity') %>
3
+ <%= fn_center.("Transactions for Account #{account_string}") %>
4
+ <%= fn_center.(sprintf("Total: %.2f", total)) %>
5
+ <%= banner_line %>
6
+
7
+
8
+ <% if entries.empty? %>
9
+ There were no transactions for this account.
10
+
11
+
12
+ <% else -%>
13
+ <% entries.each do |entry| -%>
14
+ <%= fn_format_multidoc_entry.(entry) %>
15
+ <% end -%>
16
+
17
+ <%= fn_erb_render_binding.('text/_totals.txt.erb', binding) %>
18
+ <% end %>
@@ -1,63 +1,28 @@
1
+ require_relative 'data/tx_one_account_data'
1
2
  require_relative '../documents/chart_of_accounts'
2
3
  require_relative '../documents/journal'
3
- require_relative 'reporter'
4
+ require_relative 'helpers/erb_helper'
5
+ require_relative 'helpers/text_report_helper'
4
6
  require_relative 'report_context'
5
7
 
6
8
  module RockBooks
7
9
 
8
10
  class TxOneAccount
9
11
 
10
- include Reporter
12
+ include TextReportHelper
13
+ include ErbHelper
11
14
 
12
- attr_reader :context, :account_code, :account
15
+ attr_reader :context, :account_code, :data
13
16
 
14
17
 
15
- def initialize(report_context, account_code)
18
+ def initialize(data, report_context)
19
+ @data = data
16
20
  @context = report_context
17
- @account_code = account_code
18
- @account = context.chart_of_accounts.account_for_code(account_code)
19
21
  end
20
22
 
21
23
 
22
- def generate_header(account_total)
23
- lines = [banner_line]
24
- lines << center(context.entity || 'Unspecified Entity')
25
- lines << center("Transactions for Account #{account_code_name_type_string(account)}")
26
- lines << center("Total: %.2f" % account_total)
27
- lines << banner_line
28
- lines << ''
29
- lines << ''
30
- lines << ''
31
- lines.join("\n")
24
+ def generate
25
+ ErbHelper.render_hashes('text/tx_one_account.txt.erb', data, template_presentation_context)
32
26
  end
33
-
34
-
35
- def process_account(entries)
36
- entries.each_with_object('') do |entry, output|
37
- output << format_multidoc_entry(entry) << "\n"
38
- output << "\n" if entry.description && entry.description.length > 0
39
- end
40
- end
41
-
42
-
43
- def generate_report
44
- entries = Journal.entries_in_documents(context.journals, JournalEntryFilters.account_code(account_code))
45
- account_total = JournalEntry.total_for_code(entries, account_code)
46
- output = generate_header(account_total)
47
-
48
- if entries.empty?
49
- output << "There were no transactions for this account.\n\n\n\n"
50
- else
51
- output << process_account(entries)
52
- totals = AcctAmount.aggregate_amounts_by_account(JournalEntry.entries_acct_amounts(entries))
53
- output << generate_and_format_totals('Totals', totals)
54
- end
55
-
56
- output
57
- end
58
-
59
- alias_method :to_s, :generate_report
60
- alias_method :call, :generate_report
61
27
  end
62
-
63
28
  end
@@ -2,6 +2,18 @@ module RockBooks
2
2
 
3
3
  # The ChartOfAccount holds the set of all these accounts for the entity.
4
4
  class Account < Struct.new(:code, :type, :name)
5
- end
6
5
 
6
+ PERMITTED_CODE_CHAR_REGEX = /[\w\-\.]$/ # word chars (letters, numbers, underscores), hyphens, periods
7
+
8
+ def validate_code(code)
9
+ unless PERMITTED_CODE_CHAR_REGEX.match(code)
10
+ raise "Code {#{code}} may only contain letters, numbers, underscores, hyphens, and periods."
11
+ end
12
+ end
13
+
14
+ def initialize(code, type, name)
15
+ validate_code(code)
16
+ super
17
+ end
18
+ end
7
19
  end
@@ -12,7 +12,7 @@ module RockBooks
12
12
 
13
13
  ALL_TYPES = [ASSET, LIABILITY, EQUITY, INCOME, EXPENSE]
14
14
 
15
- TYPE_HASH = {
15
+ LETTER_TO_TYPE = {
16
16
  'A' => ASSET,
17
17
  'L' => LIABILITY,
18
18
  'O' => EQUITY,
@@ -20,14 +20,25 @@ module RockBooks
20
20
  'E' => EXPENSE
21
21
  }
22
22
 
23
- # Converts strings
24
- def self.to_type(string)
25
- type = TYPE_HASH[string[0].upcase]
26
- if type.nil?
23
+ SYMBOL_TO_TYPE = {
24
+ :asset => ASSET,
25
+ :liability => LIABILITY,
26
+ :equity => EQUITY,
27
+ :income => INCOME,
28
+ :expense => EXPENSE
29
+ }
30
+
31
+ # Converts type upper case letter representation to a type object (e.g. 'A' => ASSET)
32
+ def self.letter_to_type(string)
33
+ key = string[0].upcase
34
+ LETTER_TO_TYPE.fetch(key) do
27
35
  raise Error.new("Account type of #{string} not valid. " +
28
- "Must be one of #{TYPE_HASH.keys} (#{ALL_TYPES.map(&:singular_name)})")
36
+ "Must be one of #{LETTER_TO_TYPE.keys} (#{ALL_TYPES.map(&:singular_name)})")
29
37
  end
30
- type
38
+ end
39
+
40
+ def self.symbol_to_type(symbol)
41
+ SYMBOL_TO_TYPE[symbol]
31
42
  end
32
43
  end
33
44
  end
@@ -1,3 +1,3 @@
1
1
  module RockBooks
2
- VERSION = "0.4.0"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -30,10 +30,12 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_dependency 'awesome_print', '> 0'
33
+ spec.add_dependency 'amazing_print', '> 0'
34
+ spec.add_dependency 'os', '> 1.0.0'
34
35
  spec.add_dependency 'pry', '> 0.0.0'
36
+ spec.add_dependency 'prawn', '>= 2.1'
35
37
 
36
- spec.add_development_dependency "bundler", "~> 1.16"
37
- spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "bundler", "~> 2.0"
39
+ spec.add_development_dependency "rake", ">= 12.3.3"
38
40
  spec.add_development_dependency "rspec", "~> 3.0"
39
41
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rock_books
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Bennett
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-30 00:00:00.000000000 Z
11
+ date: 2021-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: awesome_print
14
+ name: amazing_print
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">"
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: os
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: pry
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,34 +52,48 @@ dependencies:
38
52
  - - ">"
39
53
  - !ruby/object:Gem::Version
40
54
  version: 0.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: prawn
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '2.1'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: bundler
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
73
  - - "~>"
46
74
  - !ruby/object:Gem::Version
47
- version: '1.16'
75
+ version: '2.0'
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
80
  - - "~>"
53
81
  - !ruby/object:Gem::Version
54
- version: '1.16'
82
+ version: '2.0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rake
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
- - - "~>"
87
+ - - ">="
60
88
  - !ruby/object:Gem::Version
61
- version: '10.0'
89
+ version: 12.3.3
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
- - - "~>"
94
+ - - ">="
67
95
  - !ruby/object:Gem::Version
68
- version: '10.0'
96
+ version: 12.3.3
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: rspec
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -97,6 +125,7 @@ files:
97
125
  - README.md
98
126
  - RELEASE_NOTES.md
99
127
  - Rakefile
128
+ - assets/fonts/JetBrainsMono-Medium.ttf
100
129
  - bin/console
101
130
  - bin/setup
102
131
  - exe/rock_books
@@ -105,11 +134,9 @@ files:
105
134
  - lib/rock_books/cmd_line/main.rb
106
135
  - lib/rock_books/documents/book_set.rb
107
136
  - lib/rock_books/documents/chart_of_accounts.rb
108
- - lib/rock_books/documents/index.html.erb
109
137
  - lib/rock_books/documents/journal.rb
110
138
  - lib/rock_books/documents/journal_entry.rb
111
139
  - lib/rock_books/documents/journal_entry_builder.rb
112
- - lib/rock_books/documents/receipts.html.erb
113
140
  - lib/rock_books/errors/account_not_found_error.rb
114
141
  - lib/rock_books/errors/date_range_error.rb
115
142
  - lib/rock_books/errors/error.rb
@@ -120,13 +147,34 @@ files:
120
147
  - lib/rock_books/helpers/book_set_loader.rb
121
148
  - lib/rock_books/helpers/parse_helper.rb
122
149
  - lib/rock_books/reports/balance_sheet.rb
150
+ - lib/rock_books/reports/book_set_reporter.rb
151
+ - lib/rock_books/reports/data/bs_is_data.rb
152
+ - lib/rock_books/reports/data/bs_is_section_data.rb
153
+ - lib/rock_books/reports/data/journal_data.rb
154
+ - lib/rock_books/reports/data/multidoc_txn_by_account_data.rb
155
+ - lib/rock_books/reports/data/multidoc_txn_report_data.rb
156
+ - lib/rock_books/reports/data/receipts_report_data.rb
157
+ - lib/rock_books/reports/data/tx_one_account_data.rb
158
+ - lib/rock_books/reports/helpers/erb_helper.rb
159
+ - lib/rock_books/reports/helpers/html_report_helper.rb
160
+ - lib/rock_books/reports/helpers/text_report_helper.rb
123
161
  - lib/rock_books/reports/income_statement.rb
124
- - lib/rock_books/reports/multidoc_transaction_report.rb
162
+ - lib/rock_books/reports/journal_report.rb
163
+ - lib/rock_books/reports/multidoc_txn_by_account_report.rb
164
+ - lib/rock_books/reports/multidoc_txn_report.rb
125
165
  - lib/rock_books/reports/receipts_report.rb
126
166
  - lib/rock_books/reports/report_context.rb
127
- - lib/rock_books/reports/reporter.rb
128
- - lib/rock_books/reports/transaction_report.rb
129
- - lib/rock_books/reports/tx_by_account.rb
167
+ - lib/rock_books/reports/templates/html/index.html.erb
168
+ - lib/rock_books/reports/templates/html/report_page.html.erb
169
+ - lib/rock_books/reports/templates/text/_receipt_section.txt.erb
170
+ - lib/rock_books/reports/templates/text/_totals.txt.erb
171
+ - lib/rock_books/reports/templates/text/balance_sheet.txt.erb
172
+ - lib/rock_books/reports/templates/text/income_statement.txt.erb
173
+ - lib/rock_books/reports/templates/text/journal.txt.erb
174
+ - lib/rock_books/reports/templates/text/multidoc_txn_by_account_report.txt.erb
175
+ - lib/rock_books/reports/templates/text/multidoc_txn_report.txt.erb
176
+ - lib/rock_books/reports/templates/text/receipts_report.txt.erb
177
+ - lib/rock_books/reports/templates/text/tx_one_account.txt.erb
130
178
  - lib/rock_books/reports/tx_one_account.rb
131
179
  - lib/rock_books/types/account.rb
132
180
  - lib/rock_books/types/account_type.rb
@@ -415,7 +463,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
415
463
  - !ruby/object:Gem::Version
416
464
  version: '0'
417
465
  requirements: []
418
- rubygems_version: 3.0.6
466
+ rubygems_version: 3.2.3
419
467
  signing_key:
420
468
  specification_version: 4
421
469
  summary: Very basic accounting package.
@@ -1,156 +0,0 @@
1
- <!DOCTYPE html>
2
-
3
-
4
- <html>
5
-
6
- <head>
7
-
8
- <!--Bootstrap:-->
9
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
10
-
11
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
12
- <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
13
-
14
- <style>
15
- body {
16
- padding: 18px;
17
- background-color: #e7f7cd;
18
- color: darkgreen;
19
- }
20
-
21
- h2 {
22
- margin-top: 32px;
23
- margin-bottom: 12px;
24
- }
25
-
26
- .this_page_style {
27
- background-color: #e7f7cd;
28
- color: darkgreen;
29
- border: 0px;
30
- }
31
-
32
-
33
-
34
- </style>
35
-
36
- </head>
37
-
38
- <body>
39
-
40
- <h1><%= chart_of_accounts.entity %></h1>
41
- <p class="muted">Reports Generated at <%= DateTime.now.strftime('%Y-%m-%d %H:%M:%S') %> by RockBooks version <%=RockBooks::VERSION %></p>
42
-
43
-
44
- <h2>Financial Statements</h2>
45
- <div id="financial-statements">
46
- <a href='balance_sheet.html' class="btn btn-success">Balance Sheet</a>
47
- <a href='income_statement.html' class="btn btn-success">Income Statement</a>
48
- </div>
49
-
50
-
51
- <h2>Supporting Documents</h2>
52
- <div id="supporting-documents" style="display: inline ">
53
- <%
54
- subdir_link = ->(name, caption) do
55
- dir_name = File.expand_path(File.join(Dir.pwd, name))
56
- if Dir.exist?(dir_name)
57
- %Q{<a href=#{dir_name} class="btn btn-success">#{caption}</a>}
58
- end
59
- end
60
- %>
61
- <%= subdir_link.('invoices', 'Invoices') %>
62
- <%= subdir_link.('receipts', 'Receipts') %>
63
- <%= subdir_link.('statements', 'Statements') %>
64
- <%= subdir_link.('worksheets', 'Worksheets') %>
65
- </div>
66
-
67
-
68
- <h2>All Transactions Reports</h2>
69
- <div id="all-transactions">
70
- <a href="all_txns_by_acct.html" class="btn btn-success">By Account</a>
71
- <a href="all_txns_by_amount.html" class="btn btn-success">By Amount</a>
72
- <a href="all_txns_by_date.html" class="btn btn-success">By Date</a>
73
- </div>
74
-
75
- <% collapsible_heading = ->(caption, href) do
76
- %Q{<br /><br />
77
- <div class="collapsible-heading">
78
- <div class="container-fluid">
79
- <div class="row">
80
-
81
- <div class="col-sm2" style="margin-right: 12px;">
82
- <a class="btn btn-success" data-toggle="collapse" href="#{href}" role="button" aria-expanded="false" aria-controls="collapseExample">
83
- +/-
84
- </a>
85
- </div>
86
-
87
- <div class="col-sm10">
88
- <h2 style="margin: 0px;">#{caption}</h2>
89
- </div>
90
- </div>
91
- </div>
92
- </div>
93
- }
94
- end
95
- %>
96
-
97
- <%= collapsible_heading.('Journal Reports', '#journal-reports') %>
98
-
99
- </div>
100
- <div class="collapse" id="journal-reports">
101
- <div class="card card-body this_page_style">
102
- <ul>
103
- <% journals.each do |journal|
104
- filespec = journal.short_name + '.html'
105
- caption = "#{journal.title} -- #{journal.short_name} -- #{journal.account_code}"%>
106
- <li><a href="<%= filespec %>" class="this_page_style" target="_blank"><%= caption %></a></li>
107
- <% end %>
108
- </ul>
109
- </div>
110
- </div>
111
-
112
-
113
- <%= collapsible_heading.('Individual Accounts', '#individual-accounts') %>
114
-
115
- <div class="collapse" id="individual-accounts">
116
- <div class="card card-body this_page_style">
117
- <ul>
118
-
119
- <%
120
- chart_of_accounts.accounts.each do |account|
121
- filespec = File.join('single-account', "acct_#{account.code}.html")
122
- caption = "#{account.name} (#{account.code})"
123
- %>
124
- <li><a href="<%= filespec %>" class="this_page_style"><%= caption %></a></li>
125
- <% end %>
126
- </ul>
127
- </div>
128
- </div>
129
- </div>
130
-
131
-
132
- <%= collapsible_heading.('Other', '#other') %>
133
-
134
- <div class="collapse" id="other">
135
- <div class="card card-body this_page_style">
136
- <ul>
137
- <% if run_options.do_receipts %>
138
- <li><a href="receipts.html" class="this_page_style">Missing and Existing Receipts</a></li>
139
- <% end %>
140
- </ul>
141
- </div>
142
- </div>
143
-
144
- <%= collapsible_heading.('Reports in PDF and Text Formats', '#other-formats') %>
145
-
146
- <div class="collapse" id="other-formats">
147
- <div class="card card-body this_page_style">
148
- <ul>
149
- <li><a href="../pdf" class="this_page_style" target="_blank">PDF Format</a></li>
150
- <li><a href="../txt" class="this_page_style" target="_blank">Text Format</a></li>
151
- </ul>
152
- </div>
153
- </div>
154
-
155
- </body>
156
- </html>