rock_books 0.5.0 → 0.8.0

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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -2
  3. data/RELEASE_NOTES.md +35 -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 -143
  8. data/lib/rock_books/documents/chart_of_accounts.rb +29 -12
  9. data/lib/rock_books/documents/journal.rb +3 -8
  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 +218 -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/receipts_hyperlink_converter.rb +47 -0
  24. data/lib/rock_books/reports/helpers/text_report_helper.rb +142 -0
  25. data/lib/rock_books/reports/income_statement.rb +9 -47
  26. data/lib/rock_books/reports/index_html_page.rb +25 -0
  27. data/lib/rock_books/reports/journal_report.rb +72 -0
  28. data/lib/rock_books/reports/multidoc_txn_by_account_report.rb +32 -0
  29. data/lib/rock_books/reports/multidoc_txn_report.rb +25 -0
  30. data/lib/rock_books/reports/receipts_report.rb +6 -55
  31. data/lib/rock_books/reports/templates/html/index.html.erb +144 -0
  32. data/lib/rock_books/reports/templates/html/report_page.html.erb +13 -0
  33. data/lib/rock_books/reports/templates/text/_receipt_section.txt.erb +17 -0
  34. data/lib/rock_books/reports/templates/text/_totals.txt.erb +8 -0
  35. data/lib/rock_books/reports/templates/text/balance_sheet.txt.erb +22 -0
  36. data/lib/rock_books/reports/templates/text/income_statement.txt.erb +22 -0
  37. data/lib/rock_books/reports/templates/text/journal.txt.erb +20 -0
  38. data/lib/rock_books/reports/templates/text/multidoc_txn_by_account_report.txt.erb +30 -0
  39. data/lib/rock_books/reports/templates/text/multidoc_txn_report.txt.erb +24 -0
  40. data/lib/rock_books/reports/templates/text/receipts_report.txt.erb +15 -0
  41. data/lib/rock_books/reports/templates/text/tx_one_account.txt.erb +20 -0
  42. data/lib/rock_books/reports/tx_one_account.rb +10 -45
  43. data/lib/rock_books/types/account.rb +13 -1
  44. data/lib/rock_books/types/account_type.rb +18 -7
  45. data/lib/rock_books/version.rb +2 -1
  46. data/rock_books.gemspec +5 -3
  47. metadata +65 -17
  48. data/lib/rock_books/documents/index.html.erb +0 -156
  49. data/lib/rock_books/documents/receipts.html.erb +0 -54
  50. data/lib/rock_books/helpers/html_helper.rb +0 -29
  51. data/lib/rock_books/reports/multidoc_transaction_report.rb +0 -66
  52. data/lib/rock_books/reports/reporter.rb +0 -118
  53. data/lib/rock_books/reports/transaction_report.rb +0 -105
  54. data/lib/rock_books/reports/tx_by_account.rb +0 -82
@@ -0,0 +1,25 @@
1
+ require_relative 'report_context'
2
+
3
+
4
+ module RockBooks
5
+ class IndexHtmlPage
6
+
7
+ include TextReportHelper
8
+
9
+ attr_reader :context, :data
10
+
11
+ def initialize(report_context, metadata, run_options)
12
+ @context = report_context
13
+ @data = {
14
+ metadata: metadata,
15
+ journals: context.journals,
16
+ chart_of_accounts: context.chart_of_accounts,
17
+ run_options: run_options,
18
+ }
19
+ end
20
+
21
+ def generate
22
+ ErbHelper.render_hashes('html/index.html.erb', data, template_presentation_context)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,72 @@
1
+ require_relative 'data/journal_data'
2
+ require_relative 'helpers/erb_helper'
3
+ require_relative 'helpers/text_report_helper'
4
+
5
+ module RockBooks
6
+
7
+ class JournalReport
8
+
9
+ include TextReportHelper
10
+ include ErbHelper
11
+
12
+ attr_accessor :context, :report_data
13
+
14
+
15
+ def initialize(report_data, report_context, filter = nil)
16
+ @report_data = report_data
17
+ @context = report_context
18
+ end
19
+
20
+
21
+ def generate
22
+ presentation_context = template_presentation_context.merge(fn_format_entry: method(:format_entry))
23
+ ErbHelper.render_hashes('text/journal.txt.erb', report_data, presentation_context)
24
+ end
25
+
26
+
27
+ private def format_entry_first_acct_amount(entry)
28
+ entry.date.to_s \
29
+ + ' ' \
30
+ + format_acct_amount(entry.acct_amounts.last) \
31
+ + "\n"
32
+ end
33
+
34
+
35
+ # Formats an entry like this, with entry description added on additional line(s) if it exists:
36
+ # 2018-05-21 $120.00 701 Office Supplies
37
+ private def format_entry_no_split(entry)
38
+ output = format_entry_first_acct_amount(entry)
39
+
40
+ if entry.description && entry.description.length > 0
41
+ output += entry.description
42
+ end
43
+ output
44
+ end
45
+
46
+
47
+ # Formats an entry like this, with entry description added on additional line(s) if it exists::
48
+ # 2018-05-21 $120.00 95.00 701 Office Supplies
49
+ # 25.00 751 Gift to Customer
50
+ private def format_entry_with_split(entry)
51
+ output = format_entry_first_acct_amount(entry)
52
+ indent = ' ' * 12
53
+
54
+ entry.acct_amounts[1..-1].each do |acct_amount|
55
+ output << indent << format_acct_amount(acct_amount) << "\n"
56
+ end
57
+
58
+ if entry.description && entry.description.length > 0
59
+ output << entry.description
60
+ end
61
+ end
62
+
63
+
64
+ private def format_entry(entry)
65
+ if entry.acct_amounts.size > 2
66
+ format_entry_with_split(entry)
67
+ else
68
+ format_entry_no_split(entry)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,32 @@
1
+ require_relative '../documents/chart_of_accounts'
2
+ require_relative 'helpers/erb_helper'
3
+ require_relative 'helpers/text_report_helper'
4
+ require_relative 'report_context'
5
+ require_relative 'data/multidoc_txn_by_account_data'
6
+
7
+ module RockBooks
8
+
9
+ class MultidocTransactionByAccountReport
10
+
11
+ include TextReportHelper
12
+ include ErbHelper
13
+
14
+ attr_reader :context, :data
15
+
16
+
17
+ def initialize(data, report_context)
18
+ @data = data
19
+ @context = report_context
20
+ end
21
+
22
+ def account_total_line(account_code, account_total)
23
+ account_name = context.chart_of_accounts.name_for_code(account_code)
24
+ sprintf("%.2f Total for account: %s - %s", account_total, account_code, account_name)
25
+ end
26
+
27
+ def generate
28
+ presentation_context = template_presentation_context.merge({ fn_account_total_line: method(:account_total_line) })
29
+ ErbHelper.render_hashes('text/multidoc_txn_by_account_report.txt.erb', data, presentation_context)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'data/multidoc_txn_report_data'
2
+ require_relative '../documents/journal'
3
+ require_relative 'helpers/erb_helper'
4
+ require_relative 'helpers/text_report_helper'
5
+ require_relative 'report_context'
6
+
7
+ module RockBooks
8
+
9
+ class MultidocTransactionReport
10
+
11
+ include TextReportHelper
12
+ include ErbHelper
13
+
14
+ attr_reader :context, :data
15
+
16
+ def initialize(report_data, report_context)
17
+ @data = report_data
18
+ @context = report_context
19
+ end
20
+
21
+ def generate
22
+ ErbHelper.render_hashes('text/multidoc_txn_report.txt.erb', data, template_presentation_context)
23
+ end
24
+ end
25
+ end
@@ -4,67 +4,18 @@ require_relative 'report_context'
4
4
  module RockBooks
5
5
  class ReceiptsReport
6
6
 
7
- include Reporter
7
+ include TextReportHelper
8
8
 
9
- attr_reader :context, :missing, :existing, :unused
9
+ attr_reader :context, :data
10
10
 
11
-
12
- def initialize(report_context, missing, existing, unused)
11
+ def initialize(report_context, data)
13
12
  @context = report_context
14
- @missing = missing
15
- @existing = existing
16
- @unused = unused
17
- end
18
-
19
-
20
- def generate_header
21
- lines = [banner_line]
22
- lines << center(context.entity || 'Unspecified Entity')
23
- lines << "#{center("Receipts Report")}"
24
- lines << banner_line
25
- lines.join("\n")
26
- end
27
-
28
-
29
- def receipt_info_line(info)
30
- "%-16.16s %s\n" % [info[:journal], info[:receipt]]
31
- end
32
-
33
-
34
- def column_headings
35
- format_string = "%-16.16s %s\n"
36
- (format_string % ['Journal', 'Receipt Filespec']) << (format_string % %w(------- ----------------)) << "\n"
37
- end
38
-
39
-
40
- def report_one_section(name, list)
41
- output = ''
42
- output << "\n\n\n#{name} Receipts:\n\n" << column_headings
43
- if list.empty?
44
- output << "[None]\n\n\n"
45
- else
46
- list.each { |receipt| output << receipt_info_line(receipt) }
47
- end
48
- output
13
+ @data = data
49
14
  end
50
15
 
51
16
 
52
- def generate_report
53
- output = generate_header
54
- output << report_one_section('Missing', missing)
55
-
56
- output << "\n\n\nUnused Receipts:\n\n"
57
- if unused.empty?
58
- output << "[None]\n\n\n"
59
- else
60
- unused.each { |filespec| output << filespec << "\n" }
61
- end
62
-
63
- output << report_one_section('Existing', existing)
64
- output
17
+ def generate
18
+ ErbHelper.render_hashes('text/receipts_report.txt.erb', data, template_presentation_context)
65
19
  end
66
-
67
- alias_method :to_s, :generate_report
68
- alias_method :call, :generate_report
69
20
  end
70
21
  end
@@ -0,0 +1,144 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <!-- <%= metadata %> -->
4
+ <head>
5
+
6
+ <meta charset="utf-8">
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
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
11
+ <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
12
+
13
+ <style>
14
+ body {
15
+ padding: 36px;
16
+ background-color: #88c1f7;
17
+ color: #01182d;
18
+ }
19
+
20
+ h2 {
21
+ margin-top: 32px;
22
+ margin-bottom: 12px;
23
+ }
24
+
25
+ .this_page_style {
26
+ background-color: #88c1f7;
27
+ color: #01182d;
28
+ border: 0px;
29
+ }
30
+ </style>
31
+ </head>
32
+
33
+ <body>
34
+
35
+ <h1><%= entity %></h1>
36
+ <h1><%= accounting_period %></h1>
37
+ <p class="muted"><%= generated %></p>
38
+ <!-- <p class="muted">Reports Generated at <%#= DateTime.now.strftime('%Y-%m-%d %H:%M:%S') %> by RockBooks version <%#=RockBooks::VERSION %></p>-->
39
+
40
+ <h2>Financial Statements</h2>
41
+ <div id="financial-statements">
42
+ <a href='balance_sheet.html' class="btn btn-primary">Balance Sheet</a>
43
+ <a href='income_statement.html' class="btn btn-primary">Income Statement</a>
44
+ </div>
45
+
46
+
47
+ <h2>Supporting Documents</h2>
48
+ <div id="supporting-documents" style="display: inline ">
49
+ <%
50
+ subdir_link = ->(name, caption) do
51
+ dir_name = File.expand_path(File.join(Dir.pwd, name))
52
+ if Dir.exist?(dir_name)
53
+ %Q{<a href=#{dir_name} class="btn btn-primary">#{caption}</a>}
54
+ end
55
+ end
56
+ %>
57
+ <%= subdir_link.('invoices', 'Invoices') %>
58
+ <%= subdir_link.('receipts', 'Receipts') %>
59
+ <%= subdir_link.('statements', 'Statements') %>
60
+ <%= subdir_link.('worksheets', 'Worksheets') %>
61
+ </div>
62
+
63
+
64
+ <h2>All Transactions Reports</h2>
65
+ <div id="all-transactions">
66
+ <a href="all_txns_by_acct.html" class="btn btn-primary">By Account</a>
67
+ <a href="all_txns_by_amount.html" class="btn btn-primary">By Amount</a>
68
+ <a href="all_txns_by_date.html" class="btn btn-primary">By Date</a>
69
+ </div>
70
+
71
+ <% collapsible_heading = ->(caption, href) do %Q{
72
+ <br /><br />
73
+ <div class="collapsible-heading">
74
+ <div class="container-fluid">
75
+ <div class="row">
76
+
77
+ <div class="col-sm2" style="margin-right: 12px;">
78
+ <a class="btn btn-primary" data-toggle="collapse" href="#{href}" role="button" aria-expanded="false" aria-controls="collapseExample">
79
+ +/-
80
+ </a>
81
+ </div>
82
+
83
+ <div class="col-sm10">
84
+ <h2 style="margin: 0px;">#{caption}</h2>
85
+ </div>
86
+ </div>
87
+ </div>
88
+ </div>
89
+ } end %>
90
+
91
+ <%= collapsible_heading.('Journal Reports', '#journal-reports') %>
92
+
93
+ <div class="collapse" id="journal-reports">
94
+ <div class="card card-body this_page_style">
95
+ <ul>
96
+ <% journals.each do |journal|
97
+ filespec = journal.short_name + '.html' %>
98
+ <li><a href="<%= filespec %>" class="this_page_style"><%= journal.title %></a></li>
99
+ <% end %>
100
+ </ul>
101
+ </div>
102
+ </div>
103
+
104
+ <%= collapsible_heading.('Individual Accounts', '#individual-accounts') %>
105
+
106
+ <div class="collapse" id="individual-accounts">
107
+ <div class="card card-body this_page_style">
108
+ <ul>
109
+ <%
110
+ chart_of_accounts.accounts.each do |account|
111
+ filespec = File.join('single-account', "acct_#{account.code}.html")
112
+ caption = "#{account.name} (#{account.code})"
113
+ %>
114
+ <li><a href="<%= filespec %>" class="this_page_style"><%= caption %></a></li>
115
+ <% end %>
116
+ </ul>
117
+ </div>
118
+ </div>
119
+
120
+ <%= collapsible_heading.('Other', '#other') %>
121
+
122
+ <div class="collapse" id="other">
123
+ <div class="card card-body this_page_style">
124
+ <ul>
125
+ <% if run_options.do_receipts %>
126
+ <li><a href="receipts.html" class="this_page_style">Missing and Existing Receipts</a></li>
127
+ <% end %>
128
+ </ul>
129
+ </div>
130
+ </div>
131
+
132
+ <%= collapsible_heading.('Reports in PDF and Text Formats', '#other-formats') %>
133
+
134
+ <div class="collapse" id="other-formats">
135
+ <div class="card card-body this_page_style">
136
+ <ul>
137
+ <li><a href="../pdf" class="this_page_style">PDF Format</a></li>
138
+ <li><a href="../txt" class="this_page_style">Text Format</a></li>
139
+ </ul>
140
+ </div>
141
+ </div>
142
+
143
+ </body>
144
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <!-- <%= metadata_comment %> -->
4
+ <head>
5
+ <title><%= title %></title>
6
+ <meta name="generator" content="RockBooks Accounting"/>
7
+ </head>
8
+ <body>
9
+ <pre>
10
+ <%= report_body %>
11
+ </pre>
12
+ </body>
13
+ </html>
@@ -0,0 +1,17 @@
1
+ <% receipt_info_line = ->(info) { sprintf("%-16.16s %s", info[:journal], info[:receipt]) } -%>
2
+ <% format_heading_line = ->(str1, str2) { sprintf("%-16.16s %s", str1, str2) } -%>
3
+
4
+
5
+
6
+ <%= name %> Receipts:
7
+
8
+ <%= format_heading_line.('Journal', 'Receipt Filespec') %>
9
+ <%= format_heading_line.('-------', '----------------') %>
10
+
11
+ <% if list.empty? -%>
12
+ [None]
13
+ <% else -%>
14
+ <% list.each do |receipt| -%>
15
+ <%= receipt_info_line.(receipt) %>
16
+ <% end -%>
17
+ <% end -%>
@@ -0,0 +1,8 @@
1
+ Totals
2
+ ------
3
+
4
+ <% totals.keys.sort.each do |acct_code| -%>
5
+ <%= sprintf(line_item_format_string, totals[acct_code], acct_code, fn_acct_name.(acct_code)) %>
6
+ <% end -%>
7
+ ------------
8
+ <%= fn_total_with_ok_or_discrepancy.(grand_total) %>
@@ -0,0 +1,22 @@
1
+ <%= banner_line %>
2
+ <%= fn_center.(entity || 'Unspecified Entity') %>
3
+ <%= fn_center.("Balance Sheet for Period Ending #{end_date}") %>
4
+ <%= fn_center.(generated) %>
5
+ <%= banner_line %>
6
+
7
+ <% %i(asset liability equity).each do |section_type| -%>
8
+ <%= fn_section_heading.(section_type) %>
9
+
10
+ <% section_data = sections[section_type] -%>
11
+ <% section_data[:acct_totals].each do |code, amount| -%>
12
+ <%= line_item_format_string % [amount, code, fn_acct_name.(code)] %>
13
+ <% end -%>
14
+ ------------
15
+ <%= sprintf(line_item_format_string, section_data[:total], '', '') %>
16
+ <% end %>
17
+
18
+
19
+ Assets - (Liabilities + Equity)
20
+
21
+ <%= fn_total_with_ok_or_discrepancy.(grand_total) %>
22
+ ============
@@ -0,0 +1,22 @@
1
+ <%= banner_line %>
2
+ <%= fn_center.(entity || 'Unspecified Entity') %>
3
+ <%= fn_center.("Income Statement -- #{accounting_period}") %>
4
+ <%= fn_center.(generated) %>
5
+ <%= banner_line %>
6
+
7
+ <% %i(income expense).each do |section_type| -%>
8
+ <%= fn_section_heading.(section_type) %>
9
+
10
+ <% section_data = sections[section_type] -%>
11
+ <% section_data[:acct_totals].each do |code, amount| -%>
12
+ <%= line_item_format_string % [amount, code, fn_acct_name.(code)] %>
13
+ <% end -%>
14
+ ------------
15
+ <%= sprintf(line_item_format_string, section_data[:total], '', '') %>
16
+ <% end %>
17
+
18
+
19
+ Net Income
20
+
21
+ <%= sprintf(line_item_format_string, net_income, '', '') %>
22
+ ============