lucabook 0.2.28 → 0.2.29
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/exe/luca-book +4 -0
- data/lib/luca_book/list.rb +115 -1
- data/lib/luca_book/templates/journals.html.erb +23 -0
- data/lib/luca_book/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6e3ddc43f78a55be0357756cc617efd9fc798836cd771e4814a058e62abc6eb
|
4
|
+
data.tar.gz: b5b6d3419d2dbfcee9f859744c7513830a6576868a6a51241ea0ee04633c0c5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2c7c3b7043a60f39379be1c6e36b02367e2ec31261b0268768934c2f258cba62d3fc042f6286c5ac62b15289a89d1ac6e05143dcb9f2ecc04b5aa8d37bb9a89
|
7
|
+
data.tar.gz: 653e43c3f11785dabf83e8997810ae3316b8549b8370854e42bcc170ba54729dc50762e11e0733fbff2994fc15a37d6ac1eeb60c2581885f451acafeb57f5cdc
|
data/exe/luca-book
CHANGED
@@ -26,6 +26,8 @@ class LucaCmd
|
|
26
26
|
else
|
27
27
|
render(LucaBook::List.term(*args, code: params['code'], recursive: params[:recursive]).list_by_code(params[:recursive]), params)
|
28
28
|
end
|
29
|
+
elsif params['render']
|
30
|
+
puts LucaBook::List.term(*args).render_html(params['render'])
|
29
31
|
else
|
30
32
|
render(LucaBook::List.term(*args).list_journals, params)
|
31
33
|
end
|
@@ -141,6 +143,8 @@ when /journals?/, 'j'
|
|
141
143
|
opt.on('-n VAL', 'report count') { |v| params[:n] = v.to_i }
|
142
144
|
opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
|
143
145
|
opt.on('-o', '--output VAL', 'output serialized data') { |v| params[:output] = v }
|
146
|
+
opt.on('--html', 'output journals html') { |_v| params['render'] = :html }
|
147
|
+
opt.on('--pdf', 'output journals PDF') { |_v| params['render'] = :pdf }
|
144
148
|
opt.on_tail('List records. If you specify code and/or month, search on each criteria.')
|
145
149
|
args = opt.parse!(ARGV)
|
146
150
|
LucaCmd::Journal.list(args, params)
|
data/lib/luca_book/list.rb
CHANGED
@@ -101,10 +101,120 @@ module LucaBook #:nodoc:
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
+
def render_html(file_type = :html)
|
105
|
+
start_balance = set_balance(true)
|
106
|
+
@journals = group_by_code.map do |account|
|
107
|
+
balance = start_balance[account[:code]] || BigDecimal('0')
|
108
|
+
table = []
|
109
|
+
table << %Q(<h2 class="title">#{@@dict.dig(account[:code], :label)}</h2>)
|
110
|
+
|
111
|
+
account[:vouchers].map { |voucher| filter_by_code(voucher, account[:code]) }.flatten
|
112
|
+
.unshift({ balance: readable(balance) })
|
113
|
+
.map { |row|
|
114
|
+
balance += Util.pn_debit(account[:code]) * ((row.dig(:amount, :debit) || 0) - (row.dig(:amount, :credit) || 0))
|
115
|
+
row[:balance] = readable(balance)
|
116
|
+
row
|
117
|
+
}
|
118
|
+
.map { |row| render_line(row) }
|
119
|
+
.each_slice(28) do |rows|
|
120
|
+
table << table_header
|
121
|
+
table << rows.join("\n")
|
122
|
+
table << table_footer
|
123
|
+
table << %Q(<hr class='pgbr' />)
|
124
|
+
end
|
125
|
+
table[0..-2].join("\n")
|
126
|
+
end
|
127
|
+
|
128
|
+
case file_type
|
129
|
+
when :html
|
130
|
+
render_erb(search_template('journals.html.erb'))
|
131
|
+
when :pdf
|
132
|
+
erb2pdf(search_template('journals.html.erb'))
|
133
|
+
else
|
134
|
+
raise 'This filetype is not supported.'
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def table_header
|
139
|
+
%Q(<table>
|
140
|
+
<thead>
|
141
|
+
<th>Date<br />No</th>
|
142
|
+
<th>Counter account</th>
|
143
|
+
<th>Sub account<br />Note</th>
|
144
|
+
<th>Debit</th>
|
145
|
+
<th>Credit</th>
|
146
|
+
<th>Balance</th>
|
147
|
+
</thead>
|
148
|
+
<tbody>)
|
149
|
+
end
|
150
|
+
|
151
|
+
def table_footer
|
152
|
+
%Q(</tbody>
|
153
|
+
</table>)
|
154
|
+
end
|
155
|
+
|
156
|
+
def filter_by_code(voucher, code)
|
157
|
+
[:debit, :credit].each_with_object([]) do |balance, lines|
|
158
|
+
voucher[balance].each do |record|
|
159
|
+
next unless /^#{code}/.match(record[:code])
|
160
|
+
|
161
|
+
counter_balance = (balance == :debit) ? :credit : :debit
|
162
|
+
view = { code: record[:code], amount: {} }
|
163
|
+
view[:date], view[:txid] = decode_id(voucher[:id])
|
164
|
+
view[:label] = @@dict.dig(record[:code], :label) if record[:code].length >= 4
|
165
|
+
view[:amount][balance] = readable(record[:amount])
|
166
|
+
view[:counter_code] = voucher.dig(counter_balance, 0, :code)
|
167
|
+
view[:counter_label] = @@dict.dig(view[:counter_code], :label) || ''
|
168
|
+
view[:counter_label] += ' sundry a/c' if voucher[counter_balance].length > 1
|
169
|
+
view[:note] = voucher[:note]
|
170
|
+
lines << view
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def render_line(view)
|
176
|
+
%Q(<tr>
|
177
|
+
<td class="date">#{view[:date]}<br /><div>#{view[:txid]}</div></td>
|
178
|
+
<td class="counter">#{view[:counter_label]}</td>
|
179
|
+
<td class="note">#{view[:label]}<br /><div class="note">#{view[:note]}</div></td>
|
180
|
+
<td class="debit amount">#{view.dig(:amount, :debit)}</td>
|
181
|
+
<td class="credit amount">#{view.dig(:amount, :credit)}</td>
|
182
|
+
<td class="balance">#{view[:balance]}</td>
|
183
|
+
</tr>)
|
184
|
+
end
|
185
|
+
|
186
|
+
def group_by_code(level = 3)
|
187
|
+
list_accounts.map do |code|
|
188
|
+
vouchers = @data.filter do |voucher|
|
189
|
+
codes = [:debit, :credit].map do |balance|
|
190
|
+
voucher[balance].map { |record| record[:code][0, level] }
|
191
|
+
end
|
192
|
+
codes.flatten.include?(code)
|
193
|
+
end
|
194
|
+
{ code: code, vouchers: vouchers }
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def list_accounts(level = 3)
|
199
|
+
return nil if level < 3
|
200
|
+
|
201
|
+
list = @data.each_with_object([]) do |voucher, codes|
|
202
|
+
[:debit, :credit].each do |balance|
|
203
|
+
voucher[balance].each do |record|
|
204
|
+
next if record[:code].length < level
|
205
|
+
|
206
|
+
codes << record[:code][0, level]
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
list.uniq.sort
|
211
|
+
end
|
212
|
+
|
104
213
|
private
|
105
214
|
|
106
215
|
def set_balance(recursive = false)
|
107
|
-
return
|
216
|
+
return LucaBook::State.start_balance(@start.year, @start.month, recursive: recursive) if @code.nil?
|
217
|
+
return BigDecimal('0') if /^[A-H]/.match(@code)
|
108
218
|
|
109
219
|
LucaBook::State.start_balance(@start.year, @start.month, recursive: recursive)[@code] || BigDecimal('0')
|
110
220
|
end
|
@@ -145,5 +255,9 @@ module LucaBook #:nodoc:
|
|
145
255
|
end
|
146
256
|
end
|
147
257
|
end
|
258
|
+
|
259
|
+
def lib_path
|
260
|
+
__dir__
|
261
|
+
end
|
148
262
|
end
|
149
263
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<meta charset="utf-8">
|
4
|
+
<style>
|
5
|
+
body { size: A4 }
|
6
|
+
.pgbr { page-break-after: always; visibility: hidden }
|
7
|
+
.title { margin-bottom: 1.5rem; text-align: center }
|
8
|
+
div.note { font-size: .8em }
|
9
|
+
table { border-collapse: collapse; max-width: 92%; margin: 1em auto }
|
10
|
+
th, td { border-bottom: solid 1px #555; }
|
11
|
+
td div { break-before: avoid-page; break-after: avoid-page; break-inside: avoid-page }
|
12
|
+
td { padding-top: .3em; padding-bottom: .3em; break-inside: avoid-page }
|
13
|
+
td.date { min-width: 7em; text-align: right; padding-right: 1em }
|
14
|
+
td.counter { min-width: 8.5em; padding-right: .5em }
|
15
|
+
td.note { min-width: 12em }
|
16
|
+
td.amount { text-align: right; min-width: 7em }
|
17
|
+
td.balance { text-align: right; min-width: 10em; padding-right: 1em }
|
18
|
+
</style>
|
19
|
+
</head>
|
20
|
+
<body>
|
21
|
+
<%= @journals.join("<hr class='pgbr' />\n") %>
|
22
|
+
</body>
|
23
|
+
</html>
|
data/lib/luca_book/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lucabook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.29
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chuma Takahiro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lucarecord
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- lib/luca_book/templates/dict-en.tsv
|
96
96
|
- lib/luca_book/templates/dict-jp-edinet.tsv
|
97
97
|
- lib/luca_book/templates/dict-jp.tsv
|
98
|
+
- lib/luca_book/templates/journals.html.erb
|
98
99
|
- lib/luca_book/templates/monthly-report.html.erb
|
99
100
|
- lib/luca_book/test.rb
|
100
101
|
- lib/luca_book/util.rb
|