lucabook 0.5.0 → 0.5.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59f73cb5893a8da8c079d86bc32f1d3b54d04cd6ffc3ae3b09f4272c2b908c6a
4
- data.tar.gz: 6627a57fda2a20ef8763baabee57117314724f40fd862ee11e5a647239e650e6
3
+ metadata.gz: 0aada3e712bc8c2ecd96ea0cfe499565d7c6c036decb8b0a29f90bddaf65d9b8
4
+ data.tar.gz: e7ab9a0d301a86f80b9dcd74140bbf596bfdb6ce73c11cf8aef0b4e6413e7fa7
5
5
  SHA512:
6
- metadata.gz: 11a4c3ae324b452ee28c049fc5254c3d899a1857094d338e625c8e1d163619e39d7b8cefa44b335287cf4ad0aee0a0028c9b8951a2fe83a8e4d211c0e4ab4edb
7
- data.tar.gz: 2d31fdc8cc07909fdc2517286f074f34a3a7fb31408852ca6d5453b7cc562cf8b8ad789e9897574b7e8473c775fdaaf88c6236accd3ca5fff25625392ee559a4
6
+ metadata.gz: 2a5588460f50c3ac0613c16977c1b0849fdf279c25ca18f435d1dfa62e1ad31ef69647774e95a1e01f7255158604f445e61900fd9f992be6775299b2dd5f2d28
7
+ data.tar.gz: 0a666d47c831e4f8bfa0adf5c064c544de2c2c55d45c4c407dc1e3cd62ecaa5e9f6034ba65925ac936e7375b93ef38094932f43bd99af96dbedabf3fae4a7aaa
data/exe/luca-book CHANGED
@@ -1,19 +1,12 @@
1
1
  #!/usr/bin/ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- unless Dir.exist?('data') || ARGV[0] == 'new'
5
- target = 'journals'
6
- Dir.glob('*').reject { |f| File.symlink?(f) }
7
- .find { |f| File.directory?("#{f}/data/#{target}") }.tap do |d|
8
- abort "No valid data directory, exit..." if d.nil?
9
-
10
- Dir.chdir(d)
11
- end
12
- end
4
+ REQUIRED_DIR='journals'
13
5
 
14
6
  require 'json'
15
7
  require 'optparse'
16
8
  require 'luca_book'
9
+ require 'luca_cmd'
17
10
 
18
11
  class LucaCmd
19
12
  class Journal < LucaCmd
@@ -135,12 +128,12 @@ class LucaCmd
135
128
  start = today.prev_month(count - 1)
136
129
  [start.year, start.month, today.year, today.month]
137
130
  else
138
- start_year = if today.month >= LucaSupport::CONFIG['fy_start'].to_i
131
+ start_year = if today.month >= LucaSupport::CONST.config['fy_start'].to_i
139
132
  today.year
140
133
  else
141
134
  today.year - 1
142
135
  end
143
- [start_year, LucaSupport::CONFIG['fy_start'], start_year + 1, LucaSupport::CONFIG['fy_start'].to_i - 1]
136
+ [start_year, LucaSupport::CONST.config['fy_start'], start_year + 1, LucaSupport::CONST.config['fy_start'].to_i - 1]
144
137
  end
145
138
  end
146
139
 
@@ -177,7 +170,7 @@ def new_pj(args = nil, params = {})
177
170
  LucaBook::Setup.create_project params['country'], args[0]
178
171
  end
179
172
 
180
- LucaRecord::Base.valid_project?
173
+ #LucaRecord::Base.valid_project?
181
174
  cmd = ARGV.shift
182
175
  params = {}
183
176
 
@@ -191,7 +184,9 @@ when /journals?/, 'j'
191
184
  opt.on('-c', '--config VAL', 'import definition'){ |v| params['config'] = v }
192
185
  opt.on('-j', '--json', 'import via json format'){ |_v| params['json'] = true }
193
186
  args = opt.parse!(ARGV)
194
- LucaCmd::Journal.import(args, params)
187
+ LucaCmd.check_dir(REQUIRED_DIR) do
188
+ LucaCmd::Journal.import(args, params)
189
+ end
195
190
  end
196
191
  when 'list'
197
192
  params[:recursive] = false
@@ -208,7 +203,9 @@ when /journals?/, 'j'
208
203
  opt.on('--pdf', 'output journals PDF') { |_v| params['render'] = :pdf }
209
204
  opt.on_tail('List records. If you specify code and/or month, search on each criteria.')
210
205
  args = opt.parse!(ARGV)
211
- LucaCmd::Journal.list(args, params)
206
+ LucaCmd.check_dir(REQUIRED_DIR) do
207
+ LucaCmd::Journal.list(args, params)
208
+ end
212
209
  end
213
210
  when 'set'
214
211
  OptionParser.new do |opt|
@@ -218,7 +215,9 @@ when /journals?/, 'j'
218
215
  opt.on('--val VAL', 'header value') { |v| params[:value] = v }
219
216
  opt.on_tail('set header to journals on specified code.')
220
217
  args = opt.parse!(ARGV)
221
- LucaCmd::Journal.add_header(args, params)
218
+ LucaCmd.check_dir(REQUIRED_DIR) do
219
+ LucaCmd::Journal.add_header(args, params)
220
+ end
222
221
  end
223
222
  when 'stats'
224
223
  params[:recursive] = false
@@ -231,7 +230,9 @@ when /journals?/, 'j'
231
230
  opt.on('--explore', 'explore table in nushell') { |_v| params[:output] = 'explore' }
232
231
  opt.on('-o', '--output VAL', 'output serialized data') { |v| params[:output] = v }
233
232
  args = opt.parse!(ARGV)
234
- LucaCmd::Journal.stats(args, params)
233
+ LucaCmd.check_dir(REQUIRED_DIR) do
234
+ LucaCmd::Journal.stats(args, params)
235
+ end
235
236
  end
236
237
  else
237
238
  puts 'Proper subcommand needed.'
@@ -259,7 +260,9 @@ when /reports?/, 'r'
259
260
  opt.on('-o VAL', '--output VAL', 'specify file name') { |v| params[:output] = v }
260
261
  opt.on('--lastyear', 'report last Financial Year') { |_v| params[:lastyear] = true }
261
262
  args = opt.parse!(ARGV)
262
- LucaCmd::Report.xbrl(args, params)
263
+ LucaCmd.check_dir(REQUIRED_DIR) do
264
+ LucaCmd::Report.xbrl(args, params)
265
+ end
263
266
  end
264
267
  when 'bs'
265
268
  OptionParser.new do |opt|
@@ -270,7 +273,9 @@ when /reports?/, 'r'
270
273
  opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
271
274
  opt.on('-o', '--output VAL', 'output serialized data') { |v| params[:output] = v }
272
275
  args = opt.parse!(ARGV)
273
- LucaCmd::Report.balancesheet(args, params)
276
+ LucaCmd.check_dir(REQUIRED_DIR) do
277
+ LucaCmd::Report.balancesheet(args, params)
278
+ end
274
279
  end
275
280
  when 'pl'
276
281
  OptionParser.new do |opt|
@@ -281,7 +286,9 @@ when /reports?/, 'r'
281
286
  opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
282
287
  opt.on('-o', '--output VAL', 'output serialized data') { |v| params[:output] = v }
283
288
  args = opt.parse!(ARGV)
284
- LucaCmd::Report.profitloss(args, params)
289
+ LucaCmd.check_dir(REQUIRED_DIR) do
290
+ LucaCmd::Report.profitloss(args, params)
291
+ end
285
292
  end
286
293
  when 'mail'
287
294
  OptionParser.new do |opt|
@@ -290,7 +297,9 @@ when /reports?/, 'r'
290
297
  opt.on('--fy', 'adjust start date to Financial Year') { |_v| params[:financialyear] = true }
291
298
  opt.on('-n VAL', 'report count') { |v| params[:n] = v.to_i }
292
299
  args = opt.parse!(ARGV)
293
- LucaCmd::Report.report_mail(args, params)
300
+ LucaCmd.check_dir(REQUIRED_DIR) do
301
+ LucaCmd::Report.report_mail(args, params)
302
+ end
294
303
  end
295
304
  else
296
305
  puts 'Proper subcommand needed.'
@@ -309,15 +318,22 @@ when /balance/
309
318
  OptionParser.new do |opt|
310
319
  opt.banner = 'Usage: luca-book balance update YYYY [M]'
311
320
  args = opt.parse!(ARGV)
312
- LucaCmd::Dict.update_balance(args, params)
321
+ LucaCmd.check_dir(REQUIRED_DIR) do
322
+ LucaCmd::Dict.update_balance(args, params)
323
+ end
313
324
  end
314
325
  when 'export'
315
326
  OptionParser.new do |opt|
316
327
  opt.banner = 'Usage: luca-book balance export YYYY M d'
317
328
  args = opt.parse!(ARGV)
318
- LucaCmd::Dict.export_balance(args, params)
329
+ LucaCmd.check_dir(REQUIRED_DIR) do
330
+ LucaCmd::Dict.export_balance(args, params)
331
+ end
319
332
  end
320
333
  end
334
+ when 'version'
335
+ puts "luca-book: version #{LucaBook::VERSION}"
336
+ exit 0
321
337
  else
322
338
  puts 'Proper subcommand needed.'
323
339
  puts
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'luca_book/util'
4
- require 'luca_support/config'
4
+ require 'luca_support/const'
5
5
 
6
6
  module LucaBook
7
7
  module Accumulator
@@ -38,7 +38,7 @@ module LucaBook
38
38
  res['10'] = sum_matched(report, /^[12][0-9A-Z]{2,}/)
39
39
  jp_4v = sum_matched(report, /^[4][V]{2,}/) # deferred assets for JP GAAP
40
40
  res['30'] = sum_matched(report, /^[34][0-9A-Z]{2,}/) - jp_4v
41
- res['4V'] = jp_4v if LucaSupport::CONFIG['country'] == 'jp'
41
+ res['4V'] = jp_4v if LucaSupport::CONST.config['country'] == 'jp'
42
42
  res['50'] = sum_matched(report, /^[56][0-9A-Z]{2,}/)
43
43
  res['70'] = sum_matched(report, /^[78][0-9A-Z]{2,}/)
44
44
  res['91'] = sum_matched(report, /^91[0-9A-Z]{1,}/)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'luca_support/code'
4
- require 'luca_support/config'
4
+ require 'luca_support/const'
5
5
  require 'luca_support/range'
6
6
  require 'luca_record/dict'
7
7
  require 'luca_record/io'
@@ -102,9 +102,9 @@ module LucaBook
102
102
  end
103
103
 
104
104
  def self.latest_balance_path(date)
105
- start_year = date.month >= LucaSupport::CONFIG['fy_start'] ? date.year : date.year - 1
106
- latest = Date.new(start_year, LucaSupport::CONFIG['fy_start'], 1).prev_month
107
- dict_dir = Pathname(LucaSupport::PJDIR) / 'data' / 'balance'
105
+ start_year = date.month >= LucaSupport::CONST.config['fy_start'] ? date.year : date.year - 1
106
+ latest = Date.new(start_year, LucaSupport::CONST.config['fy_start'], 1).prev_month
107
+ dict_dir = Pathname(LucaSupport::CONST.pjdir) / 'data' / 'balance'
108
108
  fileglob = %Q(start-#{latest.year}-#{format("%02d", latest.month)}-*)
109
109
  path = Dir.glob(fileglob, base: dict_dir)[0] || 'start.tsv'
110
110
  dict_dir / path
@@ -115,8 +115,8 @@ module LucaBook
115
115
  end
116
116
 
117
117
  def self.generate_balance(year, month = nil)
118
- start_date = Date.new((year.to_i - 1), LucaSupport::CONFIG['fy_start'], 1)
119
- month ||= LucaSupport::CONFIG['fy_start'] - 1
118
+ start_date = Date.new((year.to_i - 1), LucaSupport::CONST.config['fy_start'], 1)
119
+ month ||= LucaSupport::CONST.config['fy_start'] - 1
120
120
  end_date = Date.new(year.to_i, month, -1)
121
121
  labels = load('base.tsv')
122
122
  bs = load_balance(start_date, end_date)
@@ -133,7 +133,7 @@ module LucaBook
133
133
  f << [code, labels.dig(code, :label), LucaSupport::Code.readable(balance)]
134
134
  end
135
135
  end
136
- dict_dir = Pathname(LucaSupport::PJDIR) / 'data' / 'balance'
136
+ dict_dir = Pathname(LucaSupport::CONST.pjdir) / 'data' / 'balance'
137
137
  filepath = dict_dir / "start-#{end_date.to_s}.tsv"
138
138
 
139
139
  File.open(filepath, 'w') { |f| f.write csv }
@@ -7,7 +7,7 @@ require 'luca_support'
7
7
  require 'luca_record'
8
8
 
9
9
  begin
10
- require "luca_book/import_#{LucaSupport::CONFIG['country']}"
10
+ require "luca_book/import_#{LucaSupport::CONST.config['country']}"
11
11
  rescue LoadError => e
12
12
  e.message
13
13
  end
@@ -90,6 +90,8 @@ module LucaBook
90
90
  default_label = debit ? @config[:default_debit] : @config[:default_credit]
91
91
  code, options = search_code(row[@config[:label]], default_label, amount)
92
92
  counter_code = @code_map.dig(@config[:counter_label])
93
+ raise "No valid counter code found for label: #{@config[:counter_label] || 'No label specified'}" if counter_code.nil?
94
+
93
95
  if options
94
96
  x_customer = options[:'x-customer'] if options[:'x-customer']
95
97
  data, data_c = tax_extension(code, counter_code, amount, options) if respond_to? :tax_extension
@@ -6,7 +6,7 @@ require 'fileutils'
6
6
  module LucaBook
7
7
  class Setup
8
8
  # create project skeleton under specified directory
9
- def self.create_project(country = nil, dir = LucaSupport::PJDIR)
9
+ def self.create_project(country = nil, dir = LucaSupport::CONST.pjdir)
10
10
  FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
11
11
  Dir.chdir(dir) do
12
12
  %w[data/journals data/balance dict].each do |subdir|
@@ -116,7 +116,7 @@ module LucaBook
116
116
 
117
117
  # TODO: pl/bs may not be immutable
118
118
  def report_mail(level = 3)
119
- @company = CONFIG.dig('company', 'name')
119
+ @company = LucaSupport::CONST.config.dig('company', 'name')
120
120
  {}.tap do |res|
121
121
  pl(level).reverse.each do |month|
122
122
  month.each do |k, v|
@@ -130,10 +130,10 @@ module LucaBook
130
130
  @bs = bs
131
131
 
132
132
  mail = Mail.new
133
- mail.to = CONFIG.dig('mail', 'preview') || CONFIG.dig('mail', 'from')
133
+ mail.to = LucaSupport::CONST.config.dig('mail', 'preview') || LucaSupport.CONST.config.dig('mail', 'from')
134
134
  mail.subject = 'Financial Report available'
135
135
  mail.html_part = Mail::Part.new(body: render_erb(search_template('monthly-report.html.erb')), content_type: 'text/html; charset=UTF-8')
136
- LucaSupport::Mail.new(mail, PJDIR).deliver
136
+ LucaSupport::Mail.new(mail, LucaSupport.CONST.pjdir).deliver
137
137
  end
138
138
 
139
139
  def bs(level = 3, legal: false)
@@ -217,13 +217,13 @@ module LucaBook
217
217
  h[k] = BigDecimal(v[:balance].to_s) if v[:balance]
218
218
  h[k] ||= BigDecimal('0') if k.length == 2
219
219
  end
220
- if month == CONFIG['fy_start'].to_i
220
+ if month == LucaSupport::CONST.config['fy_start'].to_i
221
221
  return recursive ? total_subaccount(base) : base
222
222
  end
223
223
 
224
224
  pre_last = start_date.prev_month
225
- year -= 1 if month <= CONFIG['fy_start'].to_i
226
- pre = accumulate_term(year, CONFIG['fy_start'], pre_last.year, pre_last.month)
225
+ year -= 1 if month <= LucaSupport::CONST.config['fy_start'].to_i
226
+ pre = accumulate_term(year, LucaSupport::CONST.config['fy_start'], pre_last.year, pre_last.month)
227
227
  total = {}.tap do |h|
228
228
  (pre.keys + base.keys).uniq.each do |k|
229
229
  h[k] = (base[k] || BigDecimal('0')) + (pre[k] || BigDecimal('0'))
@@ -235,8 +235,8 @@ module LucaBook
235
235
  def render_xbrl(filename = nil)
236
236
  set_bs(3, legal: true)
237
237
  set_pl(3)
238
- country_suffix = CONFIG['country'] || 'en'
239
- @company = CGI.escapeHTML(CONFIG.dig('company', 'name'))
238
+ country_suffix = LucaSupport::CONST.config['country'] || 'en'
239
+ @company = CGI.escapeHTML(LucaSupport::CONST.config.dig('company', 'name'))
240
240
  @balance_sheet_selected = 'true'
241
241
  @pl_selected = 'true'
242
242
  @capital_change_selected = 'true'
@@ -263,11 +263,11 @@ module LucaBook
263
263
  return nil if readable(amount).zero? && prior_amount.nil?
264
264
 
265
265
  prior = if prior_amount.nil?
266
- /^[9]/.match(code) ? "<#{tag} decimals=\"0\" unitRef=\"#{Code.currency_code(CONFIG['country'])}\" contextRef=\"Prior1YearNonConsolidatedInstant\">0</#{tag}>\n" : ''
266
+ /^[9]/.match(code) ? "<#{tag} decimals=\"0\" unitRef=\"#{Code.currency_code(LucaSupport::CONST.config['country'])}\" contextRef=\"Prior1YearNonConsolidatedInstant\">0</#{tag}>\n" : ''
267
267
  else
268
- "<#{tag} decimals=\"0\" unitRef=\"#{Code.currency_code(CONFIG['country'])}\" contextRef=\"Prior1YearNonConsolidatedInstant\">#{readable(prior_amount)}</#{tag}>\n"
268
+ "<#{tag} decimals=\"0\" unitRef=\"#{Code.currency_code(LucaSupport::CONST.config['country'])}\" contextRef=\"Prior1YearNonConsolidatedInstant\">#{readable(prior_amount)}</#{tag}>\n"
269
269
  end
270
- current = "<#{tag} decimals=\"0\" unitRef=\"#{Code.currency_code(CONFIG['country'])}\" contextRef=\"#{context}\">#{readable(amount)}</#{tag}>"
270
+ current = "<#{tag} decimals=\"0\" unitRef=\"#{Code.currency_code(LucaSupport::CONST.config['country'])}\" contextRef=\"#{context}\">#{readable(amount)}</#{tag}>"
271
271
 
272
272
  prior + current
273
273
  end
@@ -318,9 +318,9 @@ module LucaBook
318
318
  end
319
319
 
320
320
  def legal_items
321
- return [] unless CONFIG['country']
321
+ return [] unless LucaSupport::CONST.config['country']
322
322
 
323
- case CONFIG['country']
323
+ case LucaSupport::CONST.config['country']
324
324
  when 'jp'
325
325
  ['31', '32', '33', '91', '911', '912', '913', '9131', '9132', '914', '9141', '9142', '915', '916', '92', '93']
326
326
  end
@@ -374,7 +374,7 @@ module LucaBook
374
374
  tag = ex_dict.dig("#{code}:#{code}")&.dig(:xbrl_id)
375
375
  changes << [tag, readable(diff)] if tag
376
376
  end
377
- currency = %Q(unitRef="#{Code.currency_code(CONFIG['country'])}")
377
+ currency = %Q(unitRef="#{Code.currency_code(LucaSupport::CONST.config['country'])}")
378
378
  context = 'contextRef="CurrentYearNonConsolidatedDuration"'
379
379
  changes.map { |tag, amount| %Q(<#{tag} decimals="0" #{currency} #{context}>#{amount}</#{tag}>) }
380
380
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'bigdecimal'
4
- require 'luca_support/config'
4
+ require 'luca_support/const'
5
5
 
6
6
  module LucaBook
7
7
  module Util
@@ -45,7 +45,7 @@ module LucaBook
45
45
 
46
46
  def current_fy(date = nil, to: nil)
47
47
  date ||= Date.today
48
- start_month = LucaSupport::CONFIG['fy_start']
48
+ start_month = LucaSupport::CONST.config['fy_start']
49
49
  start_year = date.month >= start_month ? date.year : date.year - 1
50
50
  @start_date = Date.new(start_year, start_month, 1)
51
51
  @end_date = Date.new(start_year + 1, start_month - 1, -1)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucaBook
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.2'
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.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuma Takahiro
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-20 00:00:00.000000000 Z
11
+ date: 2024-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lucarecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.0
19
+ version: 0.7.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.6.0
26
+ version: 0.7.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +108,7 @@ licenses:
108
108
  metadata:
109
109
  homepage_uri: https://github.com/chumaltd/luca/tree/master/lucabook
110
110
  source_code_uri: https://github.com/chumaltd/luca/tree/master/lucabook
111
- post_install_message:
111
+ post_install_message:
112
112
  rdoc_options: []
113
113
  require_paths:
114
114
  - lib
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  requirements: []
126
126
  rubygems_version: 3.4.10
127
- signing_key:
127
+ signing_key:
128
128
  specification_version: 4
129
129
  summary: Book keep
130
130
  test_files: []