rock_books 0.7.1 → 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.
- checksums.yaml +4 -4
- data/RELEASE_NOTES.md +7 -0
- data/lib/rock_books/documents/journal.rb +1 -2
- data/lib/rock_books/reports/book_set_reporter.rb +30 -19
- data/lib/rock_books/reports/helpers/receipts_hyperlink_converter.rb +47 -0
- data/lib/rock_books/reports/helpers/text_report_helper.rb +8 -0
- data/lib/rock_books/reports/index_html_page.rb +25 -0
- data/lib/rock_books/reports/templates/html/index.html.erb +5 -2
- data/lib/rock_books/reports/templates/html/report_page.html.erb +1 -0
- data/lib/rock_books/reports/templates/text/balance_sheet.txt.erb +1 -0
- data/lib/rock_books/reports/templates/text/income_statement.txt.erb +2 -1
- data/lib/rock_books/reports/templates/text/journal.txt.erb +2 -2
- data/lib/rock_books/reports/templates/text/multidoc_txn_by_account_report.txt.erb +2 -0
- data/lib/rock_books/reports/templates/text/multidoc_txn_report.txt.erb +2 -0
- data/lib/rock_books/reports/templates/text/receipts_report.txt.erb +2 -0
- data/lib/rock_books/reports/templates/text/tx_one_account.txt.erb +2 -0
- data/lib/rock_books/version.rb +2 -1
- metadata +4 -3
- data/lib/rock_books/reports/helpers/html_report_helper.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebc94a9d98f612b4c8c13ed48739004619b4bc4d82d484314f50001d6ee784b6
|
4
|
+
data.tar.gz: c565f0945fbecc80f4af87afc67f57a9d73e293e95f096a02c1bdbcc2e7a1afb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 514102c4e924ee1890a3f0233b7584c63e9a988595e562b7387e2ed696e41ffffd3b48e72fd939442edeef5a146fd473bb9fe0ea2e657d3b3d57bedc748d8472
|
7
|
+
data.tar.gz: 67b889a280ed577daa98358b4a927d83bf9339a35d8e9106aa3127776a6028bda7108a55cd7ee3c4164217e8213728c4d742be44b55317e583d7d604151f1a48
|
data/RELEASE_NOTES.md
CHANGED
@@ -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
|
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/
|
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, :
|
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
|
133
|
-
|
134
|
-
|
135
|
-
|
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,
|
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(
|
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 = {
|
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 =
|
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
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
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><%=
|
35
|
-
<
|
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,6 +1,7 @@
|
|
1
1
|
<%= banner_line %>
|
2
2
|
<%= fn_center.(entity || 'Unspecified Entity') %>
|
3
|
-
<%= fn_center.("Income Statement -- #{
|
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.(
|
11
|
-
) %>
|
11
|
+
<%= fn_center.(generated) %>
|
12
12
|
<%= banner_line %>
|
13
13
|
|
14
14
|
|
@@ -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 %>
|
data/lib/rock_books/version.rb
CHANGED
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.
|
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-
|
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/
|
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
|