lucasalary 0.1.27 → 0.1.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/exe/luca-salary +25 -7
- data/lib/luca_salary/monthly.rb +1 -1
- data/lib/luca_salary/payment.rb +0 -47
- data/lib/luca_salary/total.rb +66 -2
- data/lib/luca_salary/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13c3b82fd0dbc0628ded542e7e41034b61c72b70d2b95c6db395e802a5d1a868
|
4
|
+
data.tar.gz: 2c9867511fc9db6f1f1855bac932eed3ea52b89f5a64646200348b05139f01a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ff1f112099e366cb6b6950a37eaed47d632d338cd3c497fd293b4a8ca2bba50c734032208ef4e7f43c963a990b63d890dc9cc34fc458ae5efc414db6146088b
|
7
|
+
data.tar.gz: 73b50ab1845ed285aaf131056de8c05a0d3e6f4c0ca293b542675418fda8ec3a904216ff116ad920cbca6b77e9b7503d891692a31d7cf368973dfac924cf2b1a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## LucaSalary 0.1.28
|
2
|
+
|
3
|
+
* BREAKING: `luca-salary payments total` directory structure changed. Upsert 1 record per 1 profile.
|
4
|
+
* move yearly totale methods to LucaSalary::Total
|
5
|
+
* add `luca-salary pay[ments]` short hand.
|
6
|
+
* add `luca-salary payments list --nu`.
|
7
|
+
|
1
8
|
## LucaSalary 0.1.27
|
2
9
|
|
3
10
|
* Implement LucaSalary::Total for Year totaling.
|
data/exe/luca-salary
CHANGED
@@ -5,6 +5,7 @@ require 'json'
|
|
5
5
|
require 'optparse'
|
6
6
|
require 'luca_salary'
|
7
7
|
require 'luca_salary/monthly'
|
8
|
+
require 'luca_support' #TODO: test use only
|
8
9
|
|
9
10
|
module LucaCmd
|
10
11
|
class Profile
|
@@ -35,9 +36,9 @@ module LucaCmd
|
|
35
36
|
def self.list(args = nil, params = nil)
|
36
37
|
if args
|
37
38
|
args << 28 if args.length == 2 # specify safe last day
|
38
|
-
LucaSalary::Monthly.new(args.join('-')).report(params.dig('mode'))
|
39
|
+
render(LucaSalary::Monthly.new(args.join('-')).report(params.dig('mode')), params)
|
39
40
|
else
|
40
|
-
LucaSalary::Monthly.new.report(params.dig('mode'))
|
41
|
+
render(LucaSalary::Monthly.new.report(params.dig('mode')), params)
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
@@ -47,9 +48,9 @@ module LucaCmd
|
|
47
48
|
|
48
49
|
def self.total(args = nil, params = nil)
|
49
50
|
if params['mode'] == 'adjust'
|
50
|
-
LucaSalary::
|
51
|
+
LucaSalary::Total.year_adjust(args[0].to_i, args[1].to_i)
|
51
52
|
else
|
52
|
-
LucaSalary::
|
53
|
+
LucaSalary::Total.accumulator(args.first.to_i)
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
@@ -58,7 +59,7 @@ module LucaCmd
|
|
58
59
|
when 'json'
|
59
60
|
puts JSON.dump(dat)
|
60
61
|
when 'nu'
|
61
|
-
LucaSupport::View.nushell(
|
62
|
+
LucaSupport::View.nushell(dat)
|
62
63
|
else
|
63
64
|
puts YAML.dump(dat)
|
64
65
|
end
|
@@ -86,9 +87,23 @@ when /profiles?/
|
|
86
87
|
puts 'Usage: luca-salary profile[s] create Name'
|
87
88
|
exit 1
|
88
89
|
end
|
90
|
+
when 'enc', 'encrypt'
|
91
|
+
# TODO: proxy encrypt/decrypt
|
92
|
+
OptionParser.new do |opt|
|
93
|
+
opt.banner = 'Usage: luca-salary enc|encrypt'
|
94
|
+
opt.on('--clean', 'remove plain directory') { |_v| params[:clean] = true }
|
95
|
+
args = opt.parse(ARGV)
|
96
|
+
LucaSupport::Enc.encrypt("s_profiles", cleanup: params[:clean])
|
97
|
+
end
|
98
|
+
when 'dec', 'decrypt'
|
99
|
+
OptionParser.new do |opt|
|
100
|
+
opt.banner = 'Usage: luca-salary dec|decrypt'
|
101
|
+
args = opt.parse(ARGV)
|
102
|
+
LucaSupport::Enc.decrypt("s_profiles")
|
103
|
+
end
|
89
104
|
when 'export'
|
90
105
|
LucaCmd::Payment.export(ARGV)
|
91
|
-
when /payments?/
|
106
|
+
when 'pay', /payments?/
|
92
107
|
subcmd = ARGV.shift
|
93
108
|
case subcmd
|
94
109
|
when 'create'
|
@@ -99,8 +114,9 @@ when /payments?/
|
|
99
114
|
end
|
100
115
|
when 'list'
|
101
116
|
OptionParser.new do |opt|
|
102
|
-
opt.banner = 'Usage: luca-salary payments list [--mail] year month [date]'
|
117
|
+
opt.banner = 'Usage: luca-salary payments list [--mail|--nu] year month [date]'
|
103
118
|
opt.on('--mail', 'send to managers') { |_v| params['mode'] = 'mail' }
|
119
|
+
opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
|
104
120
|
args = opt.parse(ARGV)
|
105
121
|
LucaCmd::Payment.list(args, params)
|
106
122
|
end
|
@@ -131,5 +147,7 @@ else
|
|
131
147
|
puts ' profiles'
|
132
148
|
puts ' payments'
|
133
149
|
puts ' export: puts payment data for LucaBook import'
|
150
|
+
puts ' encrypt: encrypt secure profiles'
|
151
|
+
puts ' decrypt: decrypt secure profiles'
|
134
152
|
exit 1
|
135
153
|
end
|
data/lib/luca_salary/monthly.rb
CHANGED
data/lib/luca_salary/payment.rb
CHANGED
@@ -46,53 +46,6 @@ module LucaSalary
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
def self.year_total(year)
|
50
|
-
Profile.all do |profile|
|
51
|
-
id = profile.dig('id')
|
52
|
-
slips = term(year, 1, year, 12, id)
|
53
|
-
payment, _count = accumulate(slips)
|
54
|
-
payment['profile_id'] = id
|
55
|
-
date = Date.new(year, 12, 31)
|
56
|
-
payment = local_convert(payment, date)
|
57
|
-
create(payment, date: date, codes: [id], basedir: 'payments/total')
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.local_convert(payment, date)
|
62
|
-
return payment if CONFIG['country'].nil?
|
63
|
-
|
64
|
-
require "luca_salary/#{CONFIG['country'].downcase}"
|
65
|
-
klass = Kernel.const_get("LucaSalary::#{CONFIG['country'].capitalize}")
|
66
|
-
klass.year_total(payment, date)
|
67
|
-
rescue NameError
|
68
|
-
return payment
|
69
|
-
end
|
70
|
-
|
71
|
-
# Apply adjustment for yearly refund.
|
72
|
-
# Search Year Total records 6 months before specified payslip month.
|
73
|
-
#
|
74
|
-
def self.year_adjust(year, month)
|
75
|
-
target_month = Date.new(year, month, 1)
|
76
|
-
total_st = target_month.prev_month(6)
|
77
|
-
search(year, month).each do |slip, path|
|
78
|
-
term(total_st.year, total_st.month, year, month, slip['profile_id'], "#{@dirname}/total/") do |total|
|
79
|
-
slip['3A1'] = total['3A1']
|
80
|
-
slip['4A1'] = total['4A1']
|
81
|
-
end
|
82
|
-
# Recalculate sum
|
83
|
-
['3', '4'].each do |key|
|
84
|
-
slip[key] = 0
|
85
|
-
slip[key] = LucaSalary::Base.sum_code(slip, key)
|
86
|
-
slip['5'] = slip['1'] - slip['2'] - slip['3'] + slip['4']
|
87
|
-
end
|
88
|
-
update_record(
|
89
|
-
@dirname,
|
90
|
-
path,
|
91
|
-
YAML.dump(LucaSupport::Code.readable(slip.sort.to_h))
|
92
|
-
)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
49
|
# Export json for LucaBook.
|
97
50
|
# Accrual_date can be change with `payment_term` on config.yml. Default value is 0.
|
98
51
|
# `payment_term: 1` means payment on the next month of calculation target.
|
data/lib/luca_salary/total.rb
CHANGED
@@ -4,18 +4,82 @@ require 'luca_support'
|
|
4
4
|
require 'luca_record'
|
5
5
|
|
6
6
|
module LucaSalary
|
7
|
+
# == Total
|
8
|
+
# Yearly summary records are stored in 'payments/total' by each profile.
|
9
|
+
#
|
7
10
|
class Total < LucaRecord::Base
|
11
|
+
include Accumulator
|
8
12
|
@dirname = 'payments/total'
|
9
13
|
|
10
14
|
attr_reader :slips
|
11
15
|
|
12
16
|
def initialize(year)
|
13
17
|
@date = Date.new(year.to_i, 12, -1)
|
14
|
-
@slips = Total.
|
15
|
-
slip['profile'] = parse_current(Profile.find_secure(slip['
|
18
|
+
@slips = Total.search(year, 12).map do |slip|
|
19
|
+
slip['profile'] = parse_current(Profile.find_secure(slip['id']))
|
16
20
|
slip
|
17
21
|
end
|
18
22
|
@dict = LucaRecord::Dict.load_tsv_dict(Pathname(LucaSupport::PJDIR) / 'dict' / 'code.tsv')
|
19
23
|
end
|
24
|
+
|
25
|
+
def self.accumulator(year)
|
26
|
+
Profile.all do |profile|
|
27
|
+
id = profile.dig('id')
|
28
|
+
slips = term(year, 1, year, 12, id, 'payments')
|
29
|
+
payment, _count = accumulate(slips)
|
30
|
+
payment['id'] = id
|
31
|
+
date = Date.new(year, 12, 31)
|
32
|
+
payment = local_convert(payment, date)
|
33
|
+
upsert(payment, basedir: "payments/total/#{year}#{LucaSupport::Code.encode_month(12)}")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.local_convert(payment, date)
|
38
|
+
return payment if CONFIG['country'].nil?
|
39
|
+
|
40
|
+
require "luca_salary/#{CONFIG['country'].downcase}"
|
41
|
+
klass = Kernel.const_get("LucaSalary::#{CONFIG['country'].capitalize}")
|
42
|
+
klass.year_total(payment, date)
|
43
|
+
rescue NameError
|
44
|
+
return payment
|
45
|
+
end
|
46
|
+
|
47
|
+
# Apply adjustment for yearly refund.
|
48
|
+
# Search Year Total records 6 months before specified payslip month.
|
49
|
+
#
|
50
|
+
def self.year_adjust(year, month)
|
51
|
+
total_dirs = Array(0..6)
|
52
|
+
.map{ |i| LucaSupport::Code.encode_dirname(Date.new(year, month, 1).prev_month(i)) }
|
53
|
+
.map do |subdir|
|
54
|
+
search_path = "#{@dirname}/#{subdir}"
|
55
|
+
Dir.exist?(abs_path(search_path)) ? search_path : nil
|
56
|
+
end
|
57
|
+
total_path = total_dirs.compact.first
|
58
|
+
if total_path.nil?
|
59
|
+
puts "No Year total directory exists. exit"
|
60
|
+
exit 1
|
61
|
+
end
|
62
|
+
|
63
|
+
search(year, month, nil, nil, 'payments').each do |slip, path|
|
64
|
+
begin
|
65
|
+
find(slip['profile_id'], total_path) do |total|
|
66
|
+
['3A1', '4A1'].each { |cd| slip[cd] = total[cd] }
|
67
|
+
end
|
68
|
+
rescue
|
69
|
+
# skip no adjust profile
|
70
|
+
end
|
71
|
+
# Recalculate sum
|
72
|
+
['3', '4'].each do |key|
|
73
|
+
slip[key] = 0
|
74
|
+
slip[key] = LucaSalary::Base.sum_code(slip, key)
|
75
|
+
end
|
76
|
+
slip['5'] = slip['1'] - slip['2'] - slip['3'] + slip['4']
|
77
|
+
update_record(
|
78
|
+
'payments',
|
79
|
+
path,
|
80
|
+
YAML.dump(LucaSupport::Code.readable(slip.sort.to_h))
|
81
|
+
)
|
82
|
+
end
|
83
|
+
end
|
20
84
|
end
|
21
85
|
end
|
data/lib/luca_salary/version.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chuma Takahiro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-11 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:
|
19
|
+
version: 0.5.4
|
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:
|
26
|
+
version: 0.5.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '0'
|
113
113
|
requirements: []
|
114
|
-
rubygems_version: 3.
|
114
|
+
rubygems_version: 3.3.5
|
115
115
|
signing_key:
|
116
116
|
specification_version: 4
|
117
117
|
summary: Salary calculation framework
|