lucabook 0.2.18 → 0.2.19
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 +1 -1
- data/lib/luca_book/state.rb +60 -15
- data/lib/luca_book/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28e5bc747a4ba316a5badc9f7845637f4b27350cb199911c1cafc8771dc0925b
|
4
|
+
data.tar.gz: db3d419a9a20643d2235305a6c7d0ab6f776826cd062751878b3710772b03428
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0a7ecb865541848cd4a0bcbeb7cb6e590bdba4b084a62ae656a2df7303580b7294bcc728991e41c7d2d6ef00cc068c0a6c140858126c9b2ba5d0afef4d5d68b
|
7
|
+
data.tar.gz: 1fe4d3b9ce540f6424792771ed1ed9b7e40f991a281258e1b4ba415ffbab328fa148c0db917047ca5d06437c9a3126b61db2a7099bdf99b45050adda7cfa0deb
|
data/exe/luca-book
CHANGED
@@ -33,7 +33,7 @@ module LucaCmd
|
|
33
33
|
|
34
34
|
class Report
|
35
35
|
def self.balancesheet(args, params)
|
36
|
-
level = params[:level] ||
|
36
|
+
level = params[:level] || 3
|
37
37
|
legal = params[:legal] || false
|
38
38
|
args = LucaCmd.gen_range(params[:n] || 1) if args.empty?
|
39
39
|
LucaBook::State.term(*args).bs(level, legal: legal)
|
data/lib/luca_book/state.rb
CHANGED
@@ -17,10 +17,11 @@ module LucaBook
|
|
17
17
|
|
18
18
|
attr_reader :statement
|
19
19
|
|
20
|
-
def initialize(data, count = nil)
|
20
|
+
def initialize(data, count = nil, date: nil)
|
21
21
|
@data = data
|
22
22
|
@count = count
|
23
23
|
@dict = LucaRecord::Dict.load('base.tsv')
|
24
|
+
@start_date = date
|
24
25
|
@start_balance = set_balance
|
25
26
|
end
|
26
27
|
|
@@ -52,7 +53,7 @@ module LucaBook
|
|
52
53
|
date = Date.new(date.next_month.year, date.next_month.month, -1)
|
53
54
|
end
|
54
55
|
end
|
55
|
-
new
|
56
|
+
new(reports, counts, date: Date.new(from_year.to_i, from_month.to_i, -1))
|
56
57
|
end
|
57
58
|
|
58
59
|
def by_code(code, year=nil, month=nil)
|
@@ -118,18 +119,19 @@ module LucaBook
|
|
118
119
|
end
|
119
120
|
|
120
121
|
def bs(level = 3, legal: false)
|
122
|
+
@start_balance.keys.each { |k| @data.first[k] ||= 0 }
|
121
123
|
@data.map! { |data| data.select { |k, _v| k.length <= level } }
|
122
124
|
@data.map! { |data| code_sum(data).merge(data) } if legal
|
123
125
|
base = accumulate_balance(@data)
|
124
|
-
|
126
|
+
rows = [base[:debit].length, base[:credit].length].max
|
125
127
|
@statement = [].tap do |a|
|
126
|
-
|
128
|
+
rows.times do |i|
|
127
129
|
{}.tap do |res|
|
128
130
|
res['debit_label'] = base[:debit][i] ? @dict.dig(base[:debit][i].keys[0], :label) : ''
|
129
|
-
res['debit_balance'] = base[:debit][i] ? @start_balance.dig(base[:debit][i].keys[0]) + base[:debit][i].values[0] : ''
|
131
|
+
res['debit_balance'] = base[:debit][i] ? (@start_balance.dig(base[:debit][i].keys[0]) || 0) + base[:debit][i].values[0] : ''
|
130
132
|
res['debit_diff'] = base[:debit][i] ? base[:debit][i].values[0] : ''
|
131
133
|
res['credit_label'] = base[:credit][i] ? @dict.dig(base[:credit][i].keys[0], :label) : ''
|
132
|
-
res['credit_balance'] = base[:credit][i] ? @start_balance.dig(base[:credit][i].keys[0]) + base[:credit][i].values[0] : ''
|
134
|
+
res['credit_balance'] = base[:credit][i] ? (@start_balance.dig(base[:credit][i].keys[0]) || 0) + base[:credit][i].values[0] : ''
|
133
135
|
res['credit_diff'] = base[:credit][i] ? base[:credit][i].values[0] : ''
|
134
136
|
a << res
|
135
137
|
end
|
@@ -144,9 +146,9 @@ module LucaBook
|
|
144
146
|
month.each do |k, v|
|
145
147
|
h[k] = h[k].nil? ? v : h[k] + v
|
146
148
|
end
|
147
|
-
end
|
149
|
+
end
|
148
150
|
{ debit: [], credit: [] }.tap do |res|
|
149
|
-
data.each do |k, v|
|
151
|
+
data.sort.to_h.each do |k, v|
|
150
152
|
case k
|
151
153
|
when /^[0-4].*/
|
152
154
|
res[:debit] << { k => v }
|
@@ -159,11 +161,36 @@ module LucaBook
|
|
159
161
|
|
160
162
|
def pl
|
161
163
|
@statement = @data.map { |data| data.select { |k, _v| /^[A-H_].+/.match(k) } }
|
162
|
-
|
163
|
-
|
164
|
+
term = @statement.each_with_object({}) { |item, h| item.each { |k, v| h[k].nil? ? h[k] = v : h[k] += v } }
|
165
|
+
fy = @start_balance.select { |k, _v| /^[A-H].+/.match(k) }
|
166
|
+
fy = {}.tap do |h|
|
167
|
+
(term.keys + fy.keys).uniq.each do |k|
|
168
|
+
h[k] = (fy[k] || 0).to_i + (term[k] || 0).to_i
|
169
|
+
end
|
170
|
+
end
|
171
|
+
@statement << term.tap { |h| h['_d'] = 'Period Total' }
|
172
|
+
@statement << fy.tap { |h| h['_d'] = 'FY Total' }
|
164
173
|
self
|
165
174
|
end
|
166
175
|
|
176
|
+
def self.accumulate_term(start_year, start_month, end_year, end_month)
|
177
|
+
date = Date.new(start_year, start_month, 1)
|
178
|
+
last_date = Date.new(end_year, end_month, -1)
|
179
|
+
return nil if date > last_date
|
180
|
+
|
181
|
+
{}.tap do |res|
|
182
|
+
while date <= last_date do
|
183
|
+
diff, _count = net(date.year, date.month)
|
184
|
+
diff.each do |k, v|
|
185
|
+
next if /^[_]/.match(k)
|
186
|
+
|
187
|
+
res[k] = res[k].nil? ? v : res[k] + v
|
188
|
+
end
|
189
|
+
date = date.next_month
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
167
194
|
def self.accumulate_month(year, month)
|
168
195
|
monthly_record, count = net(year, month)
|
169
196
|
[total_subaccount(monthly_record), count]
|
@@ -187,18 +214,24 @@ module LucaBook
|
|
187
214
|
res['H0'] = sum_matched(report, /^[H][0-9][0-9A-Z]{1,}/)
|
188
215
|
res['HA'] = res['GA'] - res['H0']
|
189
216
|
|
190
|
-
|
217
|
+
report['9142'] = (report['9142'] || 0) + res['HA']
|
218
|
+
res['9142'] = report['9142']
|
191
219
|
res['10'] = sum_matched(report, /^[123][0-9A-Z]{2,}/)
|
192
220
|
res['40'] = sum_matched(report, /^[4][0-9A-Z]{2,}/)
|
193
221
|
res['50'] = sum_matched(report, /^[56][0-9A-Z]{2,}/)
|
194
222
|
res['70'] = sum_matched(report, /^[78][0-9A-Z]{2,}/)
|
223
|
+
res['91'] = sum_matched(report, /^91[0-9A-Z]{1,}/)
|
195
224
|
res['8ZZ'] = res['50'] + res['70']
|
196
225
|
res['9ZZ'] = sum_matched(report, /^[9][0-9A-Z]{2,}/)
|
197
226
|
|
198
227
|
res['1'] = res['10'] + res['40']
|
199
|
-
res['5'] = res['8ZZ'] + res['9ZZ']
|
228
|
+
res['5'] = res['8ZZ'] + res['9ZZ']
|
200
229
|
res['_d'] = report['_d']
|
201
230
|
|
231
|
+
report.each do |k, v|
|
232
|
+
res[k] = v if k.length == 3
|
233
|
+
end
|
234
|
+
|
202
235
|
report.each do |k, v|
|
203
236
|
if k.length >= 4
|
204
237
|
if res[k[0, 3]]
|
@@ -219,10 +252,22 @@ module LucaBook
|
|
219
252
|
end
|
220
253
|
|
221
254
|
def set_balance
|
255
|
+
pre_last = @start_date.prev_month
|
256
|
+
pre = if @start_date.month > LucaSupport::CONFIG['fy_start'].to_i
|
257
|
+
self.class.accumulate_term(pre_last.year, LucaSupport::CONFIG['fy_start'], pre_last.year, pre_last.month)
|
258
|
+
elsif @start_date.month < LucaSupport::CONFIG['fy_start'].to_i
|
259
|
+
self.class.accumulate_term(pre_last.year - 1, LucaSupport::CONFIG['fy_start'], pre_last.year, pre_last.month)
|
260
|
+
end
|
261
|
+
|
222
262
|
base = Dict.latest_balance.each_with_object({}) do |(k, v), h|
|
223
263
|
h[k] = v[:balance].to_i if v[:balance]
|
224
264
|
end
|
225
|
-
|
265
|
+
if pre
|
266
|
+
idx = (pre.keys + base.keys).uniq
|
267
|
+
base = {}.tap { |h| idx.each { |k| h[k] = (base[k] || 0) + (pre[k] || 0) } }
|
268
|
+
end
|
269
|
+
#code_sum(base).merge(self.class.total_subaccount(base))
|
270
|
+
self.class.total_subaccount(base)
|
226
271
|
end
|
227
272
|
|
228
273
|
def self.sum_matched(report, reg)
|
@@ -291,9 +336,9 @@ module LucaBook
|
|
291
336
|
# TODO: replace load_tsv -> generic load_tsv_dict
|
292
337
|
def load_start
|
293
338
|
file = Pathname(LucaSupport::Config::Pjdir) / 'data' / 'balance' / 'start.tsv'
|
294
|
-
{}.tap do |
|
339
|
+
{}.tap do |dict|
|
295
340
|
load_tsv(file) do |row|
|
296
|
-
|
341
|
+
dict[row[0]] = row[2].to_i if ! row[2].nil?
|
297
342
|
end
|
298
343
|
end
|
299
344
|
end
|
data/lib/luca_book/version.rb
CHANGED