lucabook 0.3.0 → 0.4.1

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: b14674db9c7c07b4e523d4603f98e745ab680951822041666e7d957409aabfaf
4
- data.tar.gz: 1a62eb8f39388727ab65bfa1f5242ac84a8c482a051715e944215d126b7bf93f
3
+ metadata.gz: fe62638b0f400b25938ba7515e0f33089fa2d8044e07622ef03333bc478159cb
4
+ data.tar.gz: 79b319cb365b2ee19e340d4abb4496e25aec430c021063409bd239de5443abad
5
5
  SHA512:
6
- metadata.gz: 6f5005cc3efbc02170c73418e760a5ac39b87480fbdc78caf5cc5f2604ab009ea8cf6437a90473a675c8716e77de2d6eefeb77b0a7ee0de3337016ee78d7e83d
7
- data.tar.gz: ed2ef276ea1e82f8c074fcde7ab2a9ee7fe29ea952098e58ac486f65b8ddc22a1e87218f0ecc6cee19e56832fd1acd14f7945adfefa6931bf93db7ec0532adc4
6
+ metadata.gz: d3cd9de1187394edda17a34c2aeeb7ea4c1804097084ad264ae685af17821df373ff607a5ef2d95797792e800740838a476550190636eaf94515266d6974280d
7
+ data.tar.gz: 9864cdeacb8220c049fbca8a7ac1bbf1214085343cf454a99714a83758f7c261990a997e41a27c7ea4d5ba3c9cf87bcb53b1da22bfa0dcc940a0f27211770f98
data/exe/luca-book CHANGED
@@ -78,20 +78,42 @@ class LucaCmd
78
78
  def self.balancesheet(args, params)
79
79
  level = params[:level] || 3
80
80
  legal = params[:legal] || false
81
- args = gen_range(params[:n] || 1) if args.empty?
82
- render(LucaBook::State.range(*args).bs(level, legal: legal), params)
81
+ render(LucaBook::State.range(*parse_range_args(args, params)).bs(level, legal: legal), params)
83
82
  end
84
83
 
85
84
  def self.profitloss(args, params)
86
85
  level = params[:level] || 2
87
- args = gen_range(params[:n]) if args.empty?
88
- render(LucaBook::State.range(*args).pl(level), params)
86
+ render(LucaBook::State.range(*parse_range_args(args, params)).pl(level), params)
89
87
  end
90
88
 
91
89
  def self.report_mail(args, params)
92
90
  level = params[:level] || 3
93
- args = gen_range(params[:n] || 12) if args.empty?
94
- render(LucaBook::State.range(*args).report_mail(level), params)
91
+ render(LucaBook::State.range(*parse_range_args(args, params)).report_mail(level), params)
92
+ end
93
+ end
94
+
95
+ def self.parse_range_args(args, params)
96
+ case args.length
97
+ when 4
98
+ args
99
+ when 2
100
+ if params[:financialyear]
101
+ date = Date.new(args[0].to_i, args[1].to_i)
102
+ r = LucaBook::Util.current_fy(date, to: date)
103
+ [r[0].year, r[0].month, r[1].year, r[1].month]
104
+ else
105
+ args
106
+ end
107
+ when 0
108
+ if params[:n]
109
+ gen_range(params[:n])
110
+ elsif params[:financialyear]
111
+ date = Date.today
112
+ r = LucaBook::Util.current_fy(date)
113
+ [r[0].year, r[0].month, date.year, date.month]
114
+ else
115
+ [Date.today.year, Date.today.month]
116
+ end
95
117
  end
96
118
  end
97
119
 
@@ -223,6 +245,7 @@ when /reports?/, 'r'
223
245
  OptionParser.new do |opt|
224
246
  opt.banner = 'Usage: luca-book r[eports] bs [options] [YYYY M]'
225
247
  opt.on('-l', '--level VAL', 'account level') { |v| params[:level] = v.to_i }
248
+ opt.on('--fy', 'adjust start date to Financial Year') { |_v| params[:financialyear] = true }
226
249
  opt.on('--legal', 'show legal mandatory account') { |_v| params[:legal] = true }
227
250
  opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
228
251
  opt.on('-o', '--output VAL', 'output serialized data') { |v| params[:output] = v }
@@ -233,6 +256,7 @@ when /reports?/, 'r'
233
256
  OptionParser.new do |opt|
234
257
  opt.banner = 'Usage: luca-book r[eports] pl [options] [YYYY M YYYY M]'
235
258
  opt.on('-l', '--level VAL', 'account level') { |v| params[:level] = v.to_i }
259
+ opt.on('--fy', 'adjust start date to Financial Year') { |_v| params[:financialyear] = true }
236
260
  opt.on('-n VAL', 'report count') { |v| params[:n] = v.to_i }
237
261
  opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
238
262
  opt.on('-o', '--output VAL', 'output serialized data') { |v| params[:output] = v }
@@ -243,6 +267,7 @@ when /reports?/, 'r'
243
267
  OptionParser.new do |opt|
244
268
  opt.banner = 'Usage: luca-book r[eports] mail [options] [YYYY M YYYY M]'
245
269
  opt.on('-l', '--level VAL', 'account level') { |v| params[:level] = v.to_i }
270
+ opt.on('--fy', 'adjust start date to Financial Year') { |_v| params[:financialyear] = true }
246
271
  opt.on('-n VAL', 'report count') { |v| params[:n] = v.to_i }
247
272
  args = opt.parse!(ARGV)
248
273
  LucaCmd::Report.report_mail(args, params)
@@ -74,17 +74,41 @@ module LucaBook
74
74
 
75
75
  # for assert purpose
76
76
  #
77
- def gross(start_year, start_month, end_year = nil, end_month = nil, code: nil, date_range: nil, rows: 4, recursive: false)
77
+ # header: { customer: 'some-customer' }
78
+ #
79
+ def gross(start_year, start_month, end_year = nil, end_month = nil, code: nil, date_range: nil, rows: 4, recursive: false, header: nil)
78
80
  if ! date_range.nil?
79
81
  raise if date_range.class != Range
80
82
  # TODO: date based range search
81
83
  end
84
+ scan_headers = header&.map { |k, v|
85
+ [:customer, :editor].include?(k) ? [ "x-#{k.to_s}", v ] : nil
86
+ }&.compact&.to_h
82
87
 
83
88
  end_year ||= start_year
84
89
  end_month ||= start_month
85
90
  sum = { debit: {}, credit: {}, debit_count: {}, credit_count: {} }
86
91
  idx_memo = []
87
- term(start_year, start_month, end_year, end_month, code, 'journals') do |f, _path|
92
+
93
+ enm = if scan_headers.nil? || scan_headers.empty?
94
+ term(start_year, start_month, end_year, end_month, code, 'journals')
95
+ else
96
+ Enumerator.new do |y|
97
+ term(start_year, start_month, end_year, end_month, code, 'journals') do |f, path|
98
+ 4.times { f.gets } # skip to headers
99
+ CSV.new(f, headers: false, col_sep: "\t", encoding: 'UTF-8')
100
+ .each do |line|
101
+ break if line.empty?
102
+
103
+ if scan_headers.keys.include? line[0]
104
+ f.rewind
105
+ y << [f, path]
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ enm.each do |f, _path|
88
112
  CSV.new(f, headers: false, col_sep: "\t", encoding: 'UTF-8')
89
113
  .each_with_index do |row, i|
90
114
  break if i >= rows
@@ -142,8 +166,8 @@ module LucaBook
142
166
 
143
167
  # netting vouchers in specified term
144
168
  #
145
- def net(start_year, start_month, end_year = nil, end_month = nil, code: nil, date_range: nil, recursive: false)
146
- g = gross(start_year, start_month, end_year, end_month, code: code, date_range: date_range, recursive: recursive)
169
+ def net(start_year, start_month, end_year = nil, end_month = nil, code: nil, date_range: nil, recursive: false, header: nil)
170
+ g = gross(start_year, start_month, end_year, end_month, code: code, date_range: date_range, recursive: recursive, header: header)
147
171
  idx = (g[:debit].keys + g[:credit].keys).uniq.sort
148
172
  count = {}
149
173
  diff = {}.tap do |sum|
@@ -54,6 +54,12 @@ module LucaBook
54
54
  d['debit'].each { |h| h['code'] = code_map.dig(h['label']) || DEBIT_DEFAULT }
55
55
  d['credit'].each { |h| h['code'] = code_map.dig(h['label']) || CREDIT_DEFAULT }
56
56
 
57
+ LucaBook::Journal::ACCEPTED_HEADERS.each do |header|
58
+ next if d[header].nil?
59
+ d['headers'] ||= {}
60
+ d['headers'][header] = d[header]
61
+ d[header].delete
62
+ end
57
63
  LucaBook::Journal.create(d)
58
64
  end
59
65
  end
@@ -19,7 +19,7 @@ code label xbrl_id consumption_tax income_tax
19
19
  1502 未収法人税
20
20
  1503 未収都道府県住民税
21
21
  1504 未収地方事業税
22
- 1505 未収市民税
22
+ 1505 未収市町村住民税
23
23
  160 棚卸資産 jppfs_cor:Inventories
24
24
  161 商品 jppfs_cor:Merchandize
25
25
  162 製品 jppfs_cor:FinishedGoods
@@ -85,8 +85,8 @@ code label xbrl_id consumption_tax income_tax
85
85
  515 未払法人税等 jppfs_cor:IncomeTaxesPayable
86
86
  5151 未払法人税
87
87
  5152 未払地方事業税
88
- 5153 未払都道府県民税
89
- 5154 未払市民税
88
+ 5153 未払都道府県住民税
89
+ 5154 未払市町村住民税
90
90
  516 未払消費税等 jppfs_cor:AccruedConsumptionTaxes
91
91
  517 未払費用 jppfs_cor:AccruedExpenses
92
92
  518 前受金 jppfs_cor:AdvancesReceived
@@ -191,4 +191,8 @@ G13 災害損失 jppfs_cor:LossOnDisasterEL
191
191
  GA 税引前利益 jppfs_cor:IncomeBeforeIncomeTaxes
192
192
  H0 法人税等 jppfs_cor:IncomeTaxes
193
193
  H11 法人税、住民税及び事業税 jppfs_cor:IncomeTaxesCurrent
194
+ H111 法人税
195
+ H112 都道府県住民税
196
+ H113 市町村住民税
197
+ H114 地方事業税
194
198
  HA 当期利益 jppfs_cor:ProfitLoss
@@ -19,7 +19,7 @@ code label xbrl_id consumption_tax income_tax
19
19
  1502 未収法人税
20
20
  1503 未収都道府県住民税
21
21
  1504 未収地方事業税
22
- 1505 未収市民税
22
+ 1505 未収市町村住民税
23
23
  160 棚卸資産
24
24
  161 商品 jpfr-t-cte:Merchandise
25
25
  162 製品 jpfr-t-cte:FinishedGoods
@@ -85,8 +85,8 @@ code label xbrl_id consumption_tax income_tax
85
85
  515 未払法人税等 jpfr-t-cte:IncomeTaxesPayable
86
86
  5151 未払法人税
87
87
  5152 未払地方事業税
88
- 5153 未払都道府県民税
89
- 5154 未払市民税
88
+ 5153 未払都道府県住民税
89
+ 5154 未払市町村住民税
90
90
  516 未払消費税等 jpfr-t-cte:AccruedConsumptionTaxes
91
91
  517 未払費用 jpfr-t-cte:AccruedExpenses
92
92
  518 前受金 jpfr-t-cte:AdvancesReceived
@@ -191,4 +191,8 @@ G13 災害損失 jpfr-t-cte:LossOnDisasterEL
191
191
  GA 税引前利益 jpfr-t-cte:IncomeBeforeIncomeTaxes
192
192
  H0 法人税等 jpfr-t-cte:IncomeTaxes
193
193
  H11 法人税、住民税及び事業税 jpfr-t-cte:IncomeTaxesCurrent
194
+ H111 法人税
195
+ H112 都道府県住民税
196
+ H113 市町村住民税
197
+ H114 地方事業税
194
198
  HA 当期利益 jpfr-t-cte:NetIncome
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucaBook
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.1'
5
5
  end
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.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuma Takahiro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-17 00:00:00.000000000 Z
11
+ date: 2022-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lucarecord