rock_books 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d37feeb3b20b730f06340d5e026dca81b564dc7cd6cb174a2d8bd0ffcbcb6441
4
- data.tar.gz: 41a1e166136c536fde00512d8e624ce49c894766cd5f18ed673f8f67fdaf8908
3
+ metadata.gz: ebc94a9d98f612b4c8c13ed48739004619b4bc4d82d484314f50001d6ee784b6
4
+ data.tar.gz: c565f0945fbecc80f4af87afc67f57a9d73e293e95f096a02c1bdbcc2e7a1afb
5
5
  SHA512:
6
- metadata.gz: 41e4511367107b2be92ff53eb28c42635884413c3fa91c010eee41a53da6ac94b3b9a8f7eccf3522610eee287008944d318f3250dcdc349544491dcb13dd515c
7
- data.tar.gz: 45239916850fd6102b50c8ca719a2d336b0704a116c0c4f2af5014c5a061c8b6a6147f95811a88fe13f51e23f345baeb3eda16b0e789b9682596945b92ddabb4
6
+ metadata.gz: 514102c4e924ee1890a3f0233b7584c63e9a988595e562b7387e2ed696e41ffffd3b48e72fd939442edeef5a146fd473bb9fe0ea2e657d3b3d57bedc748d8472
7
+ data.tar.gz: 67b889a280ed577daa98358b4a927d83bf9339a35d8e9106aa3127776a6028bda7108a55cd7ee3c4164217e8213728c4d742be44b55317e583d7d604151f1a48
@@ -1,3 +1,10 @@
1
+ ### v0.8.0
2
+
3
+ * Add metadata to PDF and HTML reports
4
+ * Add report generation timestamp and accounting period to all reports.
5
+ * Refactoring and cleanup.
6
+
7
+
1
8
  ### v0.7.1
2
9
 
3
10
  * Refactor report helpers.
@@ -65,9 +65,8 @@ class Journal
65
65
  attr_reader :short_name, :account_code, :chart_of_accounts, :date_prefix, :debit_or_credit, :doc_type, :title, :entries
66
66
 
67
67
  # short_name is a name that will appear on reports identifying the journal from which a transaction comes
68
- def initialize(chart_of_accounts, input_lines, short_name = nil)
68
+ def initialize(chart_of_accounts, input_lines)
69
69
  @chart_of_accounts = chart_of_accounts
70
- @short_name = short_name
71
70
  @entries = []
72
71
  @date_prefix = ''
73
72
  input_lines.each_with_index do |line, linenum|
@@ -4,6 +4,7 @@ require_relative 'balance_sheet'
4
4
  require_relative 'data/bs_is_data'
5
5
  require_relative 'data/receipts_report_data'
6
6
  require_relative 'income_statement'
7
+ require_relative 'index_html_page'
7
8
  require_relative 'multidoc_txn_report'
8
9
  require_relative 'receipts_report'
9
10
  require_relative 'report_context'
@@ -12,7 +13,7 @@ require_relative 'multidoc_txn_by_account_report'
12
13
  require_relative 'tx_one_account'
13
14
  require_relative 'helpers/erb_helper'
14
15
  require_relative 'helpers/text_report_helper'
15
- require_relative 'helpers/html_report_helper'
16
+ require_relative 'helpers/receipts_hyperlink_converter'
16
17
 
17
18
  require 'prawn'
18
19
 
@@ -21,7 +22,7 @@ class BookSetReporter
21
22
 
22
23
  extend Forwardable
23
24
 
24
- attr_reader :book_set, :output_dir, :filter, :context
25
+ attr_reader :book_set, :context, :filter, :output_dir
25
26
 
26
27
  def_delegator :book_set, :all_entries
27
28
  def_delegator :book_set, :journals
@@ -129,24 +130,32 @@ class BookSetReporter
129
130
  end
130
131
 
131
132
 
132
- private def create_index_html
133
- filespec = build_filespec(output_dir, 'index', 'html')
134
- File.write(filespec, index_html_content)
135
- puts "Created index.html"
133
+ private def report_metadata(doc_short_name)
134
+ {
135
+ RBCreator: "RockBooks v#{VERSION} (#{PROJECT_URL})",
136
+ RBEntity: context.entity,
137
+ RBCreated: Time.now.to_s,
138
+ RBDocumentCode: doc_short_name.to_s,
139
+ }
136
140
  end
137
141
 
138
142
 
139
- private def prawn_create_document(pdf_filespec, text)
140
- Prawn::Document.generate(pdf_filespec) do
143
+ private def prawn_create_document(pdf_filespec, report_text, doc_short_name)
144
+ Prawn::Document.generate(pdf_filespec, info: report_metadata(doc_short_name)) do
141
145
  font(FONT_FILESPEC, size: 10)
142
146
 
143
147
  utf8_nonbreaking_space = "\uC2A0"
144
148
  unicode_nonbreaking_space = "\u00A0"
145
- text(text.gsub(' ', unicode_nonbreaking_space))
149
+ text(report_text.gsub(' ', unicode_nonbreaking_space))
146
150
  end
147
151
  end
148
152
 
149
153
 
154
+ private def html_metadata_comment(doc_short_name)
155
+ "\n" + report_metadata(doc_short_name).ai(plain: true) + "\n"
156
+ end
157
+
158
+
150
159
  private def write_report(short_name, text_report)
151
160
 
152
161
  txt_filespec = build_filespec(output_dir, short_name, 'txt')
@@ -155,12 +164,16 @@ class BookSetReporter
155
164
 
156
165
  create_text_report = -> { File.write(txt_filespec, text_report) }
157
166
 
158
- create_pdf_report = -> { prawn_create_document(pdf_filespec, text_report) }
167
+ create_pdf_report = -> { prawn_create_document(pdf_filespec, text_report, short_name) }
159
168
 
160
169
  create_html_report = -> do
161
- data = { report_body: text_report, title: "#{short_name} Report -- RockBooks" }
170
+ data = {
171
+ report_body: text_report,
172
+ title: "#{short_name} Report -- RockBooks",
173
+ metadata_comment: html_metadata_comment(short_name)
174
+ }
162
175
  html_raw_report = ErbHelper.render_hashes("html/report_page.html.erb", data, {})
163
- html_report = HtmlReportHelper.convert_receipts_to_hyperlinks(html_raw_report, html_filespec)
176
+ html_report = ReceiptsHyperlinkConverter.convert(html_raw_report, html_filespec)
164
177
  File.write(html_filespec, html_report)
165
178
  end
166
179
 
@@ -195,13 +208,11 @@ class BookSetReporter
195
208
  end
196
209
 
197
210
 
198
- private def index_html_content
199
- erb_filespec = File.join(File.dirname(__FILE__), 'templates', 'html', 'index.html.erb')
200
- erb = ERB.new(File.read(erb_filespec))
201
- erb.result_with_hash(
202
- journals: journals,
203
- chart_of_accounts: chart_of_accounts,
204
- run_options: run_options)
211
+ private def create_index_html
212
+ filespec = build_filespec(output_dir, 'index', 'html')
213
+ content = IndexHtmlPage.new(context, html_metadata_comment('index.html'), run_options).generate
214
+ File.write(filespec, content)
215
+ puts "Created index.html"
205
216
  end
206
217
  end
207
218
  end
@@ -0,0 +1,47 @@
1
+ module RockBooks
2
+ class ReceiptsHyperlinkConverter
3
+
4
+ def self.convert(html_string, html_filespec)
5
+ ReceiptsHyperlinkConverter.new(html_string, html_filespec).convert
6
+ end
7
+
8
+ RECEIPT_REGEX = /Receipt:\s*(\S*)/
9
+
10
+ attr_reader :html_string, :num_dirs_up
11
+
12
+ def initialize(html_string, html_filespec)
13
+ @html_string = html_string
14
+ @num_dirs_up = html_filespec.include?('/single-account/') ? 3 : 2
15
+ end
16
+
17
+
18
+ def convert
19
+ html_string.split("\n").map do |line|
20
+ matches = RECEIPT_REGEX.match(line)
21
+ if matches
22
+ listed_receipt_filespec = matches[1]
23
+ receipt_anchor_line(line, listed_receipt_filespec)
24
+ else
25
+ line
26
+ end
27
+ end.join("\n")
28
+ end
29
+
30
+
31
+ # If the HTML file being created is in DATA_DIR/rockbooks-reports/html/single-account, then
32
+ # the processed link should be '../../../receipts/[receipt_filespec]'
33
+ # else it's in DATA_DIR/rockbooks-reports/html, and
34
+ # the processed link should be '../../receipts/[receipt_filespec]'
35
+ private def processed_receipt_filespec(listed_receipt_filespec)
36
+ File.join(('../' * num_dirs_up), 'receipts', listed_receipt_filespec)
37
+ end
38
+
39
+ private def receipt_anchor_line(line, listed_receipt_filespec)
40
+ line.gsub( \
41
+ /Receipt:\s*#{listed_receipt_filespec}/, \
42
+ %Q{Receipt: <a href="#{processed_receipt_filespec(listed_receipt_filespec)}">#{listed_receipt_filespec}</a>})
43
+ end
44
+
45
+ end
46
+ end
47
+
@@ -110,8 +110,15 @@ module TextReportHelper
110
110
  end
111
111
 
112
112
 
113
+ # e.g. "Generated at 2021-01-09 18:22:18 by RockBooks version 0.7.1"
114
+ def generation_info_display_string
115
+ "Reports Generated at #{DateTime.now.strftime('%Y-%m-%d %H:%M:%S')} by RockBooks version #{RockBooks::VERSION}"
116
+ end
117
+
118
+
113
119
  def template_presentation_context
114
120
  {
121
+ accounting_period: "#{start_date} to #{end_date}",
115
122
  banner_line: banner_line,
116
123
  end_date: end_date,
117
124
  entity: context.entity,
@@ -123,6 +130,7 @@ module TextReportHelper
123
130
  fn_format_multidoc_entry: method(:format_multidoc_entry),
124
131
  fn_section_heading: method(:section_heading),
125
132
  fn_total_with_ok_or_discrepancy: method(:total_with_ok_or_discrepancy),
133
+ generated: "Generated at #{DateTime.now.strftime('%Y-%m-%d %H:%M:%S')} by RockBooks version #{RockBooks::VERSION}",
126
134
  line_item_format_string: line_item_format_string,
127
135
  short_name_format_string: SHORT_NAME_FORMAT_STRING,
128
136
  start_date: start_date,
@@ -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
@@ -1,5 +1,6 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
+ <!-- <%= metadata %> -->
3
4
  <head>
4
5
 
5
6
  <meta charset="utf-8">
@@ -31,8 +32,10 @@
31
32
 
32
33
  <body>
33
34
 
34
- <h1><%= chart_of_accounts.entity %></h1>
35
- <p class="muted">Reports Generated at <%= DateTime.now.strftime('%Y-%m-%d %H:%M:%S') %> by RockBooks version <%=RockBooks::VERSION %></p>
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>-->
36
39
 
37
40
  <h2>Financial Statements</h2>
38
41
  <div id="financial-statements">
@@ -1,5 +1,6 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
+ <!-- <%= metadata_comment %> -->
3
4
  <head>
4
5
  <title><%= title %></title>
5
6
  <meta name="generator" content="RockBooks Accounting"/>
@@ -1,6 +1,7 @@
1
1
  <%= banner_line %>
2
2
  <%= fn_center.(entity || 'Unspecified Entity') %>
3
3
  <%= fn_center.("Balance Sheet for Period Ending #{end_date}") %>
4
+ <%= fn_center.(generated) %>
4
5
  <%= banner_line %>
5
6
 
6
7
  <% %i(asset liability equity).each do |section_type| -%>
@@ -1,6 +1,7 @@
1
1
  <%= banner_line %>
2
2
  <%= fn_center.(entity || 'Unspecified Entity') %>
3
- <%= fn_center.("Income Statement -- #{start_date} to #{end_date}") %>
3
+ <%= fn_center.("Income Statement -- #{accounting_period}") %>
4
+ <%= fn_center.(generated) %>
4
5
  <%= banner_line %>
5
6
 
6
7
  <% %i(income expense).each do |section_type| -%>
@@ -1,14 +1,14 @@
1
1
  <%= banner_line %>
2
2
  <%= fn_center.(entity || 'Unspecified Entity') %>
3
3
  <%= fn_center.(title) %>
4
+ <%= fn_center.(accounting_period) %>
4
5
  <% if code && name -%>
5
6
  <%= fn_center.("Account: #{name} (#{code})") %>
6
7
  <% end -%>
7
8
  <% if short_name -%>
8
9
  <%= fn_center.("Journal Short Name: #{short_name}") %>
9
10
  <% end -%>
10
- <%= fn_center.("#{start_date} to #{end_date}"
11
- ) %>
11
+ <%= fn_center.(generated) %>
12
12
  <%= banner_line %>
13
13
 
14
14
 
@@ -1,6 +1,8 @@
1
1
  <%= banner_line %>
2
2
  <%= fn_center.(entity || 'Unspecified Entity') %>
3
3
  <%= fn_center.('Multi Document Transaction Report by Account') %>
4
+ <%= fn_center.(accounting_period) %>
5
+ <%= fn_center.(generated) %>
4
6
 
5
7
  <%= fn_center.('Source Documents') %>
6
8
 
@@ -1,6 +1,8 @@
1
1
  <%= banner_line %>
2
2
  <%= fn_center.(entity || 'Unspecified Entity') %>
3
3
  <%= fn_center.('Multi Document Transaction Report') %>
4
+ <%= fn_center.(accounting_period) %>
5
+ <%= fn_center.(generated) %>
4
6
 
5
7
  <%= fn_center.('Source Documents') %>
6
8
 
@@ -4,6 +4,8 @@ end -%>
4
4
  <%= banner_line %>
5
5
  <%= fn_center.(entity || 'Unspecified Entity') %>
6
6
  <%= fn_center.('Receipts Report') %>
7
+ <%= fn_center.(accounting_period) %>
8
+ <%= fn_center.(generated) %>
7
9
  <%= banner_line %>
8
10
 
9
11
  <% # Unlike existing and missing, which arrays of hashes with keys :receipt and :journal, unused is an array of receipt filespecs %>
@@ -2,6 +2,8 @@
2
2
  <%= fn_center.(entity || 'Unspecified Entity') %>
3
3
  <%= fn_center.("Transactions for Account #{account_string}") %>
4
4
  <%= fn_center.(sprintf("Total: %.2f", total)) %>
5
+ <%= fn_center.(accounting_period) %>
6
+ <%= fn_center.(generated) %>
5
7
  <%= banner_line %>
6
8
 
7
9
 
@@ -1,3 +1,4 @@
1
1
  module RockBooks
2
- VERSION = "0.7.1"
2
+ VERSION = '0.8.0'
3
+ PROJECT_URL = 'https://github.com/keithrbennett/rock_books'
3
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rock_books
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Bennett
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-03 00:00:00.000000000 Z
11
+ date: 2021-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: amazing_print
@@ -156,9 +156,10 @@ files:
156
156
  - lib/rock_books/reports/data/receipts_report_data.rb
157
157
  - lib/rock_books/reports/data/tx_one_account_data.rb
158
158
  - lib/rock_books/reports/helpers/erb_helper.rb
159
- - lib/rock_books/reports/helpers/html_report_helper.rb
159
+ - lib/rock_books/reports/helpers/receipts_hyperlink_converter.rb
160
160
  - lib/rock_books/reports/helpers/text_report_helper.rb
161
161
  - lib/rock_books/reports/income_statement.rb
162
+ - lib/rock_books/reports/index_html_page.rb
162
163
  - lib/rock_books/reports/journal_report.rb
163
164
  - lib/rock_books/reports/multidoc_txn_by_account_report.rb
164
165
  - lib/rock_books/reports/multidoc_txn_report.rb
@@ -1,35 +0,0 @@
1
- module RockBooks
2
- module HtmlReportHelper
3
-
4
- def self.convert_receipts_to_hyperlinks(original_html_string, html_filespec)
5
- html_lines = original_html_string.split("\n")
6
- content_changed = false
7
-
8
- # If the HTML file being created is in DATA_DIR/rockbooks-reports/html/single-account, then
9
- # the processed link should be '../../../receipts/[receipt_filespec]'
10
- # else it's in DATA_DIR/rockbooks-reports/html, and
11
- # the processed link should be '../../receipts/[receipt_filespec]'
12
- processed_receipt_filespec = ->(listed_receipt_filespec) do
13
- num_dirs_up = html_filespec.include?('/single-account/') ? 3 : 2
14
- File.join(('../' * num_dirs_up), 'receipts', listed_receipt_filespec)
15
- end
16
-
17
- receipt_anchor_line = ->(line, listed_receipt_filespec) do
18
- line.gsub( \
19
- /Receipt:\s*#{listed_receipt_filespec}/, \
20
- %Q{Receipt: <a href="#{processed_receipt_filespec.(listed_receipt_filespec)}">#{listed_receipt_filespec}</a>})
21
- end
22
-
23
- html_lines.each_with_index do |line, index|
24
- matches = /Receipt:\s*(\S*)/.match(line)
25
- if matches
26
- listed_receipt_filespec = matches[1]
27
- html_lines[index] = receipt_anchor_line.(line, listed_receipt_filespec)
28
- content_changed = true
29
- end
30
- end
31
-
32
- content_changed ? html_lines.join("\n") : original_html_string
33
- end
34
- end
35
- end