lucabook 0.4.5 → 0.5.1

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: bc7304203698a38027accd15c692ae271e6e35cadecf4382a07fec093e2498b1
4
- data.tar.gz: 12294609a4306921c552a7bbd1695fce2a10f1d689016c4b479ec3aa6880441f
3
+ metadata.gz: 46ce22e0f8c712f87dcc973fc9354b8a15be9e744654bf900658a2c43b6c061a
4
+ data.tar.gz: 5a2e0b5e7efa1a3b091d222b9332381660e9beb3a80c4083a79e7487f4187cf4
5
5
  SHA512:
6
- metadata.gz: f01f815713717ad5d12b10dd741560ca179c49865cd596e836ed60c699a2d3ea7dead69802d5f207f3dacde11ea51b54a99120ffdbce182825be4c28412c52ad
7
- data.tar.gz: c36a05d9b0cae4ec3ae33ad8a07e139b66b642858a940cd68e6d688f2939d9154c618a93060278b75f7115713e5317d5edd9e49ecab1d1198f85ecc2f31ee90f
6
+ metadata.gz: 7b7125906c0f3456b6fc302ed8c8bbefadcb3be4e1fd128417556e1705dd703d24c37a88f71c2a402274cfcda0ca5c780171d0551d64d7b033e49e167e2df0ac
7
+ data.tar.gz: 6de5301ba82946dd0d38d7842a8f96752c75de6c396dfc82458967b1337b076f967b8786bfc545b53b7351ec6b1191bfabb6143f6d6198517985aaff66586034
data/exe/luca-book CHANGED
@@ -1,8 +1,12 @@
1
1
  #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ REQUIRED_DIR='journals'
2
5
 
3
6
  require 'json'
4
7
  require 'optparse'
5
8
  require 'luca_book'
9
+ require 'luca_cmd'
6
10
 
7
11
  class LucaCmd
8
12
  class Journal < LucaCmd
@@ -124,12 +128,12 @@ class LucaCmd
124
128
  start = today.prev_month(count - 1)
125
129
  [start.year, start.month, today.year, today.month]
126
130
  else
127
- start_year = if today.month >= LucaSupport::CONFIG['fy_start'].to_i
131
+ start_year = if today.month >= LucaSupport::CONST.config['fy_start'].to_i
128
132
  today.year
129
133
  else
130
134
  today.year - 1
131
135
  end
132
- [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]
133
137
  end
134
138
  end
135
139
 
@@ -166,7 +170,7 @@ def new_pj(args = nil, params = {})
166
170
  LucaBook::Setup.create_project params['country'], args[0]
167
171
  end
168
172
 
169
- LucaRecord::Base.valid_project?
173
+ #LucaRecord::Base.valid_project?
170
174
  cmd = ARGV.shift
171
175
  params = {}
172
176
 
@@ -180,7 +184,9 @@ when /journals?/, 'j'
180
184
  opt.on('-c', '--config VAL', 'import definition'){ |v| params['config'] = v }
181
185
  opt.on('-j', '--json', 'import via json format'){ |_v| params['json'] = true }
182
186
  args = opt.parse!(ARGV)
183
- LucaCmd::Journal.import(args, params)
187
+ LucaCmd.check_dir(REQUIRED_DIR) do
188
+ LucaCmd::Journal.import(args, params)
189
+ end
184
190
  end
185
191
  when 'list'
186
192
  params[:recursive] = false
@@ -197,7 +203,9 @@ when /journals?/, 'j'
197
203
  opt.on('--pdf', 'output journals PDF') { |_v| params['render'] = :pdf }
198
204
  opt.on_tail('List records. If you specify code and/or month, search on each criteria.')
199
205
  args = opt.parse!(ARGV)
200
- LucaCmd::Journal.list(args, params)
206
+ LucaCmd.check_dir(REQUIRED_DIR) do
207
+ LucaCmd::Journal.list(args, params)
208
+ end
201
209
  end
202
210
  when 'set'
203
211
  OptionParser.new do |opt|
@@ -207,7 +215,9 @@ when /journals?/, 'j'
207
215
  opt.on('--val VAL', 'header value') { |v| params[:value] = v }
208
216
  opt.on_tail('set header to journals on specified code.')
209
217
  args = opt.parse!(ARGV)
210
- LucaCmd::Journal.add_header(args, params)
218
+ LucaCmd.check_dir(REQUIRED_DIR) do
219
+ LucaCmd::Journal.add_header(args, params)
220
+ end
211
221
  end
212
222
  when 'stats'
213
223
  params[:recursive] = false
@@ -220,7 +230,9 @@ when /journals?/, 'j'
220
230
  opt.on('--explore', 'explore table in nushell') { |_v| params[:output] = 'explore' }
221
231
  opt.on('-o', '--output VAL', 'output serialized data') { |v| params[:output] = v }
222
232
  args = opt.parse!(ARGV)
223
- LucaCmd::Journal.stats(args, params)
233
+ LucaCmd.check_dir(REQUIRED_DIR) do
234
+ LucaCmd::Journal.stats(args, params)
235
+ end
224
236
  end
225
237
  else
226
238
  puts 'Proper subcommand needed.'
@@ -248,7 +260,9 @@ when /reports?/, 'r'
248
260
  opt.on('-o VAL', '--output VAL', 'specify file name') { |v| params[:output] = v }
249
261
  opt.on('--lastyear', 'report last Financial Year') { |_v| params[:lastyear] = true }
250
262
  args = opt.parse!(ARGV)
251
- LucaCmd::Report.xbrl(args, params)
263
+ LucaCmd.check_dir(REQUIRED_DIR) do
264
+ LucaCmd::Report.xbrl(args, params)
265
+ end
252
266
  end
253
267
  when 'bs'
254
268
  OptionParser.new do |opt|
@@ -259,7 +273,9 @@ when /reports?/, 'r'
259
273
  opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
260
274
  opt.on('-o', '--output VAL', 'output serialized data') { |v| params[:output] = v }
261
275
  args = opt.parse!(ARGV)
262
- LucaCmd::Report.balancesheet(args, params)
276
+ LucaCmd.check_dir(REQUIRED_DIR) do
277
+ LucaCmd::Report.balancesheet(args, params)
278
+ end
263
279
  end
264
280
  when 'pl'
265
281
  OptionParser.new do |opt|
@@ -270,7 +286,9 @@ when /reports?/, 'r'
270
286
  opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
271
287
  opt.on('-o', '--output VAL', 'output serialized data') { |v| params[:output] = v }
272
288
  args = opt.parse!(ARGV)
273
- LucaCmd::Report.profitloss(args, params)
289
+ LucaCmd.check_dir(REQUIRED_DIR) do
290
+ LucaCmd::Report.profitloss(args, params)
291
+ end
274
292
  end
275
293
  when 'mail'
276
294
  OptionParser.new do |opt|
@@ -279,7 +297,9 @@ when /reports?/, 'r'
279
297
  opt.on('--fy', 'adjust start date to Financial Year') { |_v| params[:financialyear] = true }
280
298
  opt.on('-n VAL', 'report count') { |v| params[:n] = v.to_i }
281
299
  args = opt.parse!(ARGV)
282
- LucaCmd::Report.report_mail(args, params)
300
+ LucaCmd.check_dir(REQUIRED_DIR) do
301
+ LucaCmd::Report.report_mail(args, params)
302
+ end
283
303
  end
284
304
  else
285
305
  puts 'Proper subcommand needed.'
@@ -298,15 +318,22 @@ when /balance/
298
318
  OptionParser.new do |opt|
299
319
  opt.banner = 'Usage: luca-book balance update YYYY [M]'
300
320
  args = opt.parse!(ARGV)
301
- LucaCmd::Dict.update_balance(args, params)
321
+ LucaCmd.check_dir(REQUIRED_DIR) do
322
+ LucaCmd::Dict.update_balance(args, params)
323
+ end
302
324
  end
303
325
  when 'export'
304
326
  OptionParser.new do |opt|
305
327
  opt.banner = 'Usage: luca-book balance export YYYY M d'
306
328
  args = opt.parse!(ARGV)
307
- LucaCmd::Dict.export_balance(args, params)
329
+ LucaCmd.check_dir(REQUIRED_DIR) do
330
+ LucaCmd::Dict.export_balance(args, params)
331
+ end
308
332
  end
309
333
  end
334
+ when 'version'
335
+ puts "luca-book: version #{LucaBook::VERSION}"
336
+ exit 0
310
337
  else
311
338
  puts 'Proper subcommand needed.'
312
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,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'bigdecimal'
4
- require 'luca_support/config'
5
4
 
6
5
  module LucaBook
7
6
  module Util
@@ -45,7 +44,7 @@ module LucaBook
45
44
 
46
45
  def current_fy(date = nil, to: nil)
47
46
  date ||= Date.today
48
- start_month = LucaSupport::CONFIG['fy_start']
47
+ start_month = CONST.config['fy_start']
49
48
  start_year = date.month >= start_month ? date.year : date.year - 1
50
49
  @start_date = Date.new(start_year, start_month, 1)
51
50
  @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.4.5'
4
+ VERSION = '0.5.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.4.5
4
+ version: 0.5.1
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-18 00:00:00.000000000 Z
11
+ date: 2024-01-10 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.5.4
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.5.4
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
@@ -116,15 +116,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  requirements:
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
119
- version: 2.6.0
119
+ version: 3.0.0
120
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubygems_version: 3.3.5
127
- signing_key:
126
+ rubygems_version: 3.4.10
127
+ signing_key:
128
128
  specification_version: 4
129
129
  summary: Book keep
130
130
  test_files: []