lucabook 0.2.20 → 0.2.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/luca-book +38 -15
- data/lib/luca_book/list.rb +2 -2
- data/lib/luca_book/state.rb +41 -19
- data/lib/luca_book/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f7366698bee6b770fbae39f8fe650e1f460b04dec25c8036c84013f970adaa3
|
4
|
+
data.tar.gz: 8ecbf412b31f001f0cfa2de27ceb879463d17f28e3db552770866b44c0b73114
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e30fabd50119ad470c90512bcf066b3992b5df2d67139f437a5f4336d73c843fb65dab2a70b5914c190155de68f82ec722840e0f056079061634f77bb5da4964
|
7
|
+
data.tar.gz: 3e8775200e05f8bfe0923b53690fa5245441ea4d71768246a7309ee503294d847a466e82da85568d3071f47eccd4f9783a79199b4d4eb630c961de84488a31ed
|
data/exe/luca-book
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
+
require 'json'
|
3
4
|
require 'optparse'
|
4
5
|
require 'luca_book'
|
5
6
|
|
6
|
-
|
7
|
-
class Journal
|
7
|
+
class LucaCmd
|
8
|
+
class Journal < LucaCmd
|
8
9
|
def self.import(args, params)
|
9
10
|
if params['config']
|
10
11
|
LucaBook::Import.new(args[0], params['config']).import_csv
|
@@ -17,43 +18,56 @@ module LucaCmd
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def self.list(args, params)
|
20
|
-
args =
|
21
|
+
args = gen_range(params[:n] || 1) if args.empty?
|
21
22
|
if params['code']
|
22
|
-
LucaBook::List.term(*args, code: params['code']).list_on_code
|
23
|
+
render(LucaBook::List.term(*args, code: params['code']).list_on_code, params)
|
23
24
|
else
|
24
|
-
LucaBook::List.term(*args).list_journals
|
25
|
+
render(LucaBook::List.term(*args).list_journals, params)
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
29
|
def self.stats(args, params)
|
29
|
-
args =
|
30
|
-
|
30
|
+
args = gen_range(params[:n]) if args.empty?
|
31
|
+
if params['code']
|
32
|
+
render(LucaBook::State.by_code(params['code'], *args), params)
|
33
|
+
else
|
34
|
+
render(LucaBook::State.term(*args).stats(params[:level]), params)
|
35
|
+
end
|
31
36
|
end
|
32
37
|
end
|
33
38
|
|
34
|
-
class Report
|
39
|
+
class Report < LucaCmd
|
35
40
|
def self.balancesheet(args, params)
|
36
41
|
level = params[:level] || 3
|
37
42
|
legal = params[:legal] || false
|
38
|
-
args =
|
39
|
-
LucaBook::State.term(*args).bs(level, legal: legal)
|
43
|
+
args = gen_range(params[:n] || 1) if args.empty?
|
44
|
+
render(LucaBook::State.term(*args).bs(level, legal: legal), params)
|
40
45
|
end
|
41
46
|
|
42
47
|
def self.profitloss(args, params)
|
43
48
|
level = params[:level] || 2
|
44
|
-
args =
|
45
|
-
LucaBook::State.term(*args).pl(level)
|
49
|
+
args = gen_range(params[:n]) if args.empty?
|
50
|
+
render(LucaBook::State.term(*args).pl(level), params)
|
46
51
|
end
|
47
52
|
end
|
48
53
|
|
49
|
-
|
50
|
-
|
51
|
-
def gen_range(count)
|
54
|
+
def self.gen_range(count)
|
52
55
|
count ||= 3
|
53
56
|
today = Date.today
|
54
57
|
start = today.prev_month(count - 1)
|
55
58
|
[start.year, start.month, today.year, today.month]
|
56
59
|
end
|
60
|
+
|
61
|
+
def self.render(dat, params)
|
62
|
+
case params[:output]
|
63
|
+
when 'json'
|
64
|
+
puts JSON.dump(dat)
|
65
|
+
when 'nu'
|
66
|
+
LucaSupport::View.nushell(YAML.dump(dat))
|
67
|
+
else
|
68
|
+
puts YAML.dump(dat)
|
69
|
+
end
|
70
|
+
end
|
57
71
|
end
|
58
72
|
|
59
73
|
def new_pj(args = nil, params = {})
|
@@ -81,6 +95,8 @@ when /journals?/, 'j'
|
|
81
95
|
opt.banner = 'Usage: luca-book journals list [options] [YYYY M]'
|
82
96
|
opt.on('-c', '--code VAL', 'search with code') { |v| params['code'] = v }
|
83
97
|
opt.on('-n VAL', 'report count') { |v| params[:n] = v.to_i }
|
98
|
+
opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
|
99
|
+
opt.on('-o', '--output VAL', 'output serialized data') { |v| params[:output] = v }
|
84
100
|
opt.on_tail('List records. If you specify code and/or month, search on each criteria.')
|
85
101
|
args = opt.parse!(ARGV)
|
86
102
|
LucaCmd::Journal.list(args, params)
|
@@ -88,7 +104,10 @@ when /journals?/, 'j'
|
|
88
104
|
when 'stats'
|
89
105
|
OptionParser.new do |opt|
|
90
106
|
opt.banner = 'Usage: luca-book journals stats [options] [YYYY M]'
|
107
|
+
opt.on('-c', '--code VAL', 'search with code') { |v| params['code'] = v }
|
91
108
|
opt.on('-n VAL', 'report count') { |v| params[:n] = v.to_i }
|
109
|
+
opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
|
110
|
+
opt.on('-o', '--output VAL', 'output serialized data') { |v| params[:output] = v }
|
92
111
|
args = opt.parse!(ARGV)
|
93
112
|
LucaCmd::Journal.stats(args, params)
|
94
113
|
end
|
@@ -116,6 +135,8 @@ when /reports?/, 'r'
|
|
116
135
|
opt.banner = 'Usage: luca-book reports bs [options] [YYYY M]'
|
117
136
|
opt.on('-l', '--level VAL', 'account level') { |v| params[:level] = v.to_i }
|
118
137
|
opt.on('--legal', 'show legal mandatory account') { |_v| params[:legal] = true }
|
138
|
+
opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
|
139
|
+
opt.on('-o', '--output VAL', 'output serialized data') { |v| params[:output] = v }
|
119
140
|
args = opt.parse!(ARGV)
|
120
141
|
LucaCmd::Report.balancesheet(args, params)
|
121
142
|
end
|
@@ -124,6 +145,8 @@ when /reports?/, 'r'
|
|
124
145
|
opt.banner = 'Usage: luca-book reports pl [options] [YYYY M YYYY M]'
|
125
146
|
opt.on('-l', '--level VAL', 'account level') { |v| params[:level] = v.to_i }
|
126
147
|
opt.on('-n VAL', 'report count') { |v| params[:n] = v.to_i }
|
148
|
+
opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
|
149
|
+
opt.on('-o', '--output VAL', 'output serialized data') { |v| params[:output] = v }
|
127
150
|
args = opt.parse!(ARGV)
|
128
151
|
LucaCmd::Report.profitloss(args, params)
|
129
152
|
end
|
data/lib/luca_book/list.rb
CHANGED
@@ -47,7 +47,7 @@ module LucaBook
|
|
47
47
|
res['note'] = dat[:note]
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
50
|
+
readable(@data)
|
51
51
|
end
|
52
52
|
|
53
53
|
def list_journals
|
@@ -65,7 +65,7 @@ module LucaBook
|
|
65
65
|
res['note'] = dat[:note]
|
66
66
|
end
|
67
67
|
end
|
68
|
-
|
68
|
+
readable(@data)
|
69
69
|
end
|
70
70
|
|
71
71
|
def accumulate_code
|
data/lib/luca_book/state.rb
CHANGED
@@ -56,21 +56,33 @@ module LucaBook
|
|
56
56
|
new(reports, counts, date: Date.new(from_year.to_i, from_month.to_i, -1))
|
57
57
|
end
|
58
58
|
|
59
|
-
def by_code(code,
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
59
|
+
def self.by_code(code, from_year, from_month, to_year = from_year, to_month = from_month)
|
60
|
+
date = Date.new(from_year.to_i, from_month.to_i, -1)
|
61
|
+
last_date = Date.new(to_year.to_i, to_month.to_i, -1)
|
62
|
+
raise 'invalid term specified' if date > last_date
|
63
|
+
|
64
|
+
reports = [].tap do |r|
|
65
|
+
while date <= last_date do
|
66
|
+
diff = {}.tap do |h|
|
67
|
+
g = gross(date.year, date.month, code)
|
68
|
+
sum = g.dig(:debit).nil? ? BigDecimal('0') : Util.calc_diff(g[:debit], code)
|
69
|
+
sum -= g.dig(:credit).nil? ? BigDecimal('0') : Util.calc_diff(g[:credit], code)
|
70
|
+
h['code'] = code
|
71
|
+
h['label'] = LucaRecord::Dict.load('base.tsv').dig(code, :label)
|
72
|
+
h['net'] = sum
|
73
|
+
h['debit_amount'] = g[:debit]
|
74
|
+
h['debit_count'] = g[:debit_count]
|
75
|
+
h['credit_amount'] = g[:credit]
|
76
|
+
h['credit_count'] = g[:credit_count]
|
77
|
+
h['_d'] = date.to_s
|
78
|
+
end
|
79
|
+
r << diff
|
80
|
+
date = Date.new(date.next_month.year, date.next_month.month, -1)
|
81
|
+
end
|
73
82
|
end
|
83
|
+
#YAML.dump(LucaSupport::Code.readable(reports)) #.tap{ |data| puts data }
|
84
|
+
#new(reports, counts, date: Date.new(from_year.to_i, from_month.to_i, -1))
|
85
|
+
LucaSupport::Code.readable(reports)
|
74
86
|
end
|
75
87
|
|
76
88
|
def records_with_balance(year, month, code, balance)
|
@@ -114,7 +126,6 @@ module LucaBook
|
|
114
126
|
end
|
115
127
|
keys.map! { |k| k[0, level] }.uniq.select! { |k| k.length <= level } if level
|
116
128
|
@count.prepend({}.tap { |header| keys.each { |k| header[k] = @dict.dig(k, :label) }})
|
117
|
-
puts YAML.dump(@count)
|
118
129
|
@count
|
119
130
|
end
|
120
131
|
|
@@ -137,8 +148,7 @@ module LucaBook
|
|
137
148
|
end
|
138
149
|
end
|
139
150
|
end
|
140
|
-
|
141
|
-
self
|
151
|
+
readable(@statement)
|
142
152
|
end
|
143
153
|
|
144
154
|
def accumulate_balance(monthly_diffs)
|
@@ -182,7 +192,7 @@ module LucaBook
|
|
182
192
|
end
|
183
193
|
@statement << term.tap { |h| h['_d'] = 'Period Total' }
|
184
194
|
@statement << fy.tap { |h| h['_d'] = 'FY Total' }
|
185
|
-
|
195
|
+
readable(code2label)
|
186
196
|
end
|
187
197
|
|
188
198
|
def self.accumulate_term(start_year, start_month, end_year, end_month)
|
@@ -297,7 +307,7 @@ module LucaBook
|
|
297
307
|
|
298
308
|
sum = { debit: {}, credit: {}, debit_count: {}, credit_count: {} }
|
299
309
|
idx_memo = []
|
300
|
-
|
310
|
+
search(year, month, nil, code) do |f, _path|
|
301
311
|
CSV.new(f, headers: false, col_sep: "\t", encoding: 'UTF-8')
|
302
312
|
.each_with_index do |row, i|
|
303
313
|
break if i >= rows
|
@@ -305,17 +315,23 @@ module LucaBook
|
|
305
315
|
case i
|
306
316
|
when 0
|
307
317
|
idx_memo = row.map(&:to_s)
|
318
|
+
next if code && !idx_memo.include?(code)
|
319
|
+
|
308
320
|
idx_memo.each do |r|
|
309
321
|
sum[:debit][r] ||= BigDecimal('0')
|
310
322
|
sum[:debit_count][r] ||= 0
|
311
323
|
end
|
312
324
|
when 1
|
325
|
+
next if code && !idx_memo.include?(code)
|
326
|
+
|
313
327
|
row.each_with_index do |r, j|
|
314
328
|
sum[:debit][idx_memo[j]] += BigDecimal(r.to_s)
|
315
329
|
sum[:debit_count][idx_memo[j]] += 1
|
316
330
|
end
|
317
331
|
when 2
|
318
332
|
idx_memo = row.map(&:to_s)
|
333
|
+
break if code && !idx_memo.include?(code)
|
334
|
+
|
319
335
|
idx_memo.each do |r|
|
320
336
|
sum[:credit][r] ||= BigDecimal('0')
|
321
337
|
sum[:credit_count][r] ||= 0
|
@@ -330,6 +346,12 @@ module LucaBook
|
|
330
346
|
end
|
331
347
|
end
|
332
348
|
end
|
349
|
+
if code
|
350
|
+
sum[:debit] = sum[:debit][code] || BigDecimal('0')
|
351
|
+
sum[:credit] = sum[:credit][code] || BigDecimal('0')
|
352
|
+
sum[:debit_count] = sum[:debit_count][code] || 0
|
353
|
+
sum[:credit_count] = sum[:credit_count][code] || 0
|
354
|
+
end
|
333
355
|
sum
|
334
356
|
end
|
335
357
|
|
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.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chuma Takahiro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lucarecord
|