lucasalary 0.5.0 → 0.6.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: f3d46b29fc75775cfd085328382e37a0ab39dc7b3894e6dc522e5432066528c6
4
- data.tar.gz: 79b01908f796138a7b9a12f2db808602091c160aadb55d76951d1d0173bd1dc2
3
+ metadata.gz: c67611f8fd2fd2ae358b490cb0edf52bb7f3e2e67be665fa980d13d4867b84cc
4
+ data.tar.gz: 4f9549a73cda4e61e22e4fc32bf45e8449eac786570b8f476046399d3a151aed
5
5
  SHA512:
6
- metadata.gz: 037ae90e0072d75746b3a3f0a063ff8c6fc1532eae086e247fedc7a985872134643dad43738e5cc674b5f2e1ab1d0d8e1ddb678cbf34f4c2e425005bfbc7023e
7
- data.tar.gz: bbdc6a4a67c4e9bead499016efd3d5076ee1f8a09d99d9faa9218bde77d2b6120cdf083044090f7673ca29ee50056a3409443200abfd71e75286ab5aa2316021
6
+ metadata.gz: fb07bfd39efd6c6fd9c5d2bb309914f1a383f57b370ed28eded86ba1d008db0a1f8938c3a06a795a067e0d6d3298824c294b1bb0a19c12d7f55d2f21e15bac3f
7
+ data.tar.gz: 5c9cb0834e0e258743f854e233705275910e495490e007fc9cc1c1bcf57ff49b8cd8b95a293a51a61c6ddda50f5a1c10603640b9a920cb86bde133ddd14f8229
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## LucaSalary 0.6.1
2
+
3
+ * Reworked global constants w/LucaRecord v0.7
4
+ * Removed bundler from test suite avoiding casual native build
5
+ * add `luca-salary version` subcommand
6
+
7
+ ## LucaSalary 0.6.0
8
+
9
+ * BREAKING: monthly payment now passes calculation date to local modules.
10
+ * BREAKING: year total calculation now passes profiles to local modules.
11
+
1
12
  ## LucaSalary 0.5.0
2
13
 
3
14
  * `luca-salary` command now searches valid sub directory.
data/exe/luca-salary CHANGED
@@ -1,23 +1,16 @@
1
1
  #!/usr/bin/ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- unless Dir.exist?('data') || ARGV[0] == 'new'
5
- target = 'profiles'
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='profiles'
13
5
 
14
6
  require 'json'
15
7
  require 'optparse'
16
8
  require 'luca_salary'
17
9
  require 'luca_salary/monthly'
18
10
  require 'luca_support' #TODO: test use only
11
+ require 'luca_cmd'
19
12
 
20
- module LucaCmd
13
+ class LucaCmd
21
14
  class Profile
22
15
  def self.create(args = nil, _params = nil)
23
16
  LucaSalary::Profile.gen_profile!(args.first)
@@ -79,7 +72,6 @@ module LucaCmd
79
72
  end
80
73
  end
81
74
 
82
- LucaRecord::Base.valid_project?
83
75
  cmd = ARGV.shift
84
76
  params = {}
85
77
 
@@ -91,7 +83,9 @@ when /profiles?/
91
83
  OptionParser.new do |opt|
92
84
  opt.banner = 'Usage: luca-salary profiles create Name'
93
85
  args = opt.parse(ARGV)
94
- LucaCmd::Profile.create(args)
86
+ LucaCmd.check_dir(REQUIRED_DIR) do
87
+ LucaCmd::Profile.create(args)
88
+ end
95
89
  end
96
90
  else
97
91
  puts 'Proper subcommand needed.'
@@ -105,16 +99,22 @@ when 'enc', 'encrypt'
105
99
  opt.banner = 'Usage: luca-salary enc|encrypt'
106
100
  opt.on('--clean', 'remove plain directory') { |_v| params[:clean] = true }
107
101
  args = opt.parse(ARGV)
108
- LucaSupport::Enc.encrypt("s_profiles", cleanup: params[:clean])
102
+ LucaCmd.check_dir(REQUIRED_DIR) do
103
+ LucaSupport::Enc.encrypt("s_profiles", cleanup: params[:clean])
104
+ end
109
105
  end
110
106
  when 'dec', 'decrypt'
111
107
  OptionParser.new do |opt|
112
108
  opt.banner = 'Usage: luca-salary dec|decrypt'
113
109
  args = opt.parse(ARGV)
114
- LucaSupport::Enc.decrypt("s_profiles")
110
+ LucaCmd.check_dir(REQUIRED_DIR) do
111
+ LucaSupport::Enc.decrypt("s_profiles")
112
+ end
115
113
  end
116
114
  when 'export'
117
- LucaCmd::Payment.export(ARGV)
115
+ LucaCmd.check_dir(REQUIRED_DIR) do
116
+ LucaCmd::Payment.export(ARGV)
117
+ end
118
118
  when 'pay', /payments?/
119
119
  subcmd = ARGV.shift
120
120
  case subcmd
@@ -122,7 +122,9 @@ when 'pay', /payments?/
122
122
  OptionParser.new do |opt|
123
123
  opt.banner = 'Usage: luca-salary payments create year month [date]'
124
124
  args = opt.parse(ARGV)
125
- LucaCmd::Payment.create(args)
125
+ LucaCmd.check_dir(REQUIRED_DIR) do
126
+ LucaCmd::Payment.create(args)
127
+ end
126
128
  end
127
129
  when 'list'
128
130
  OptionParser.new do |opt|
@@ -131,21 +133,27 @@ when 'pay', /payments?/
131
133
  opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
132
134
  opt.on('--explore', 'explore table in nushell') { |_v| params[:output] = 'explore' }
133
135
  args = opt.parse(ARGV)
134
- LucaCmd::Payment.list(args, params)
136
+ LucaCmd.check_dir(REQUIRED_DIR) do
137
+ LucaCmd::Payment.list(args, params)
138
+ end
135
139
  end
136
140
  when 'report'
137
141
  OptionParser.new do |opt|
138
142
  opt.banner = 'Usage: luca-salary payments report [--nu] year month [year month]'
139
143
  opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
140
144
  args = opt.parse(ARGV)
141
- LucaCmd::Payment.report(args, params)
145
+ LucaCmd.check_dir(REQUIRED_DIR) do
146
+ LucaCmd::Payment.report(args, params)
147
+ end
142
148
  end
143
149
  when 'total'
144
150
  OptionParser.new do |opt|
145
151
  opt.banner = 'Usage: luca-salary payments total [--adjust] year [month]'
146
152
  opt.on('--adjust', 'Apply year total adjustment to payslip of year/month') { |_v| params['mode'] = 'adjust' }
147
153
  args = opt.parse(ARGV)
148
- LucaCmd::Payment.total(args, params)
154
+ LucaCmd.check_dir(REQUIRED_DIR) do
155
+ LucaCmd::Payment.total(args, params)
156
+ end
149
157
  end
150
158
  else
151
159
  puts 'Proper subcommand needed.'
@@ -153,6 +161,9 @@ when 'pay', /payments?/
153
161
  puts 'Usage: luca-salary payment[s] (create|list) [--help|options]'
154
162
  exit 1
155
163
  end
164
+ when 'version'
165
+ puts "luca-salary: version #{LucaSalary::VERSION}"
166
+ exit 0
156
167
  else
157
168
  puts 'Proper subcommand needed.'
158
169
  puts
@@ -54,11 +54,11 @@ module LucaSalary
54
54
  private
55
55
 
56
56
  def load_dict
57
- LucaRecord::Dict.load_tsv_dict(Pathname(PJDIR) / 'dict' / 'code.tsv')
57
+ LucaRecord::Dict.load_tsv_dict(Pathname(LucaRecord::CONST.pjdir) / 'dict' / 'code.tsv')
58
58
  end
59
59
 
60
60
  def set_driver
61
- code = CONFIG['country']
61
+ code = LucaRecord::CONST.config['country']
62
62
  if code
63
63
  require "luca_salary/#{code.downcase}"
64
64
  Kernel.const_get "LucaSalary::#{code.capitalize}"
@@ -14,7 +14,7 @@ module LucaSalary
14
14
 
15
15
  def initialize(date = nil)
16
16
  @date = date.nil? ? Date.today : Date.parse(date)
17
- @pjdir = Pathname(LucaSupport::PJDIR)
17
+ @pjdir = Pathname(LucaRecord::CONST.pjdir)
18
18
  @config = load_config(@pjdir + 'config.yml')
19
19
  @driver = set_driver
20
20
  end
@@ -25,12 +25,12 @@ module LucaSalary
25
25
  country = @driver.new(@pjdir, @config, @date)
26
26
  # TODO: handle retirement
27
27
  LucaSalary::Profile.all do |profile|
28
- current_profile = parse_current(profile)
28
+ current_profile = parse_current(Profile.find_secure(profile['id']))
29
29
  if self.class.search(@date.year, @date.month, @date.day, current_profile['id']).count > 0
30
30
  puts "payment record already exists: #{current_profile['id']}"
31
31
  return nil
32
32
  end
33
- h = country.calc_payment(current_profile)
33
+ h = country.calc_payment(current_profile, @date)
34
34
  h['profile_id'] = current_profile['id']
35
35
  self.class.create(h, date: @date, codes: Array(current_profile['id']))
36
36
  end
@@ -15,7 +15,7 @@ module LucaSalary
15
15
 
16
16
  def initialize(date = nil)
17
17
  @date = Date.parse(date)
18
- @pjdir = Pathname(LucaSupport::PJDIR)
18
+ @pjdir = Pathname(LucaRecord::CONST.pjdir)
19
19
  @dict = LucaRecord::Dict.load_tsv_dict(@pjdir / 'dict' / 'code.tsv')
20
20
  end
21
21
 
@@ -51,8 +51,8 @@ module LucaSalary
51
51
  # `payment_term: 1` means payment on the next month of calculation target.
52
52
  #
53
53
  def export_json
54
- accrual_date = if LucaSupport::CONFIG['payment_term']
55
- pt = LucaSupport::CONFIG['payment_term']
54
+ accrual_date = if LucaRecord::CONST.config['payment_term']
55
+ pt = LucaRecord::CONST.config['payment_term']
56
56
  Date.new(@date.prev_month(pt).year, @date.prev_month(pt).month, -1)
57
57
  else
58
58
  Date.new(@date.year, @date.month, -1)
@@ -14,7 +14,7 @@ module LucaSalary
14
14
  @count = count
15
15
  @start_date = start_d
16
16
  @end_date = end_d
17
- @dict = LucaRecord::Dict.load_tsv_dict(Pathname(LucaSupport::PJDIR) / 'dict' / 'code.tsv')
17
+ @dict = LucaRecord::Dict.load_tsv_dict(Pathname(LucaRecord::CONST.pjdir) / 'dict' / 'code.tsv')
18
18
  end
19
19
 
20
20
  def self.range(from_year, from_month, to_year = from_year, to_month = from_month)
@@ -19,7 +19,7 @@ module LucaSalary
19
19
  slip['profile'] = parse_current(Profile.find_secure(slip['id']))
20
20
  slip
21
21
  end
22
- @dict = LucaRecord::Dict.load_tsv_dict(Pathname(LucaSupport::PJDIR) / 'dict' / 'code.tsv')
22
+ @dict = LucaRecord::Dict.load_tsv_dict(Pathname(LucaRecord::CONST.pjdir) / 'dict' / 'code.tsv')
23
23
  end
24
24
 
25
25
  def self.accumulator(year)
@@ -29,17 +29,17 @@ module LucaSalary
29
29
  payment, _count = accumulate(slips)
30
30
  payment['id'] = id
31
31
  date = Date.new(year, 12, 31)
32
- payment = local_convert(payment, date)
32
+ payment = local_convert(Profile.find_secure(id), payment, date)
33
33
  upsert(payment, basedir: "payments/total/#{year}#{LucaSupport::Code.encode_month(12)}")
34
34
  end
35
35
  end
36
36
 
37
- def self.local_convert(payment, date)
38
- return payment if CONFIG['country'].nil?
37
+ def self.local_convert(profile, payment, date)
38
+ return payment if LucaRecord::CONST.config['country'].nil?
39
39
 
40
- require "luca_salary/#{CONFIG['country'].downcase}"
41
- klass = Kernel.const_get("LucaSalary::#{CONFIG['country'].capitalize}")
42
- klass.year_total(payment, date)
40
+ require "luca_salary/#{LucaRecord::CONST.config['country'].downcase}"
41
+ klass = Kernel.const_get("LucaSalary::#{LucaRecord::CONST.config['country'].capitalize}")
42
+ klass.year_total(profile, payment, date)
43
43
  rescue NameError
44
44
  return payment
45
45
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucaSalary
4
- VERSION = '0.5.0'
4
+ VERSION = '0.6.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucasalary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.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-20 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.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
@@ -96,7 +96,7 @@ metadata:
96
96
  homepage_uri: https://github.com/chumaltd/luca/tree/master/lucasalary
97
97
  source_code_uri: https://github.com/chumaltd/luca/tree/master/lucasalary
98
98
  changelog_uri: https://github.com/chumaltd/luca/tree/master/lucasalary/CHANGELOG.md
99
- post_install_message:
99
+ post_install_message:
100
100
  rdoc_options: []
101
101
  require_paths:
102
102
  - lib
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  requirements: []
114
114
  rubygems_version: 3.4.10
115
- signing_key:
115
+ signing_key:
116
116
  specification_version: 4
117
117
  summary: Salary calculation framework
118
118
  test_files: []