lucasalary 0.1.27 → 0.1.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/exe/luca-salary +28 -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: 5f9a6cc60592a240edaa38b2fc9245efeefa74d16c2fff7abfdf8c2e9a7dbf4c
|
4
|
+
data.tar.gz: e09af61bfa146de7625f5877951ab4dfeb7b76549c443be7f1d0245b6e1e37ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9068ec38591a0a8758498371497533b4c9d37303a3089b6441d4601bd88dc685fc338b1718a5fe549c2decaa89f8dc0534afc1b1144c99b7328ff25aa5a0166
|
7
|
+
data.tar.gz: 2f15b61cd215c260aeda9c6df1c053129fd8b20ab3390564f2d23308eb0b576c7c4f6e8c7f693b5c6c57951e0a13fe8d697a44574ac93666c14e6971acf3299d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## LucaSalary 0.1.29
|
2
|
+
|
3
|
+
* `luca-salary payment list` supports interactive `--explore` w/nushell.
|
4
|
+
|
5
|
+
## LucaSalary 0.1.28
|
6
|
+
|
7
|
+
* BREAKING: `luca-salary payments total` directory structure changed. Upsert 1 record per 1 profile.
|
8
|
+
* move yearly totale methods to LucaSalary::Total
|
9
|
+
* add `luca-salary pay[ments]` short hand.
|
10
|
+
* add `luca-salary payments list --nu`.
|
11
|
+
|
1
12
|
## LucaSalary 0.1.27
|
2
13
|
|
3
14
|
* 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,9 @@ 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)
|
63
|
+
when 'explore'
|
64
|
+
LucaSupport::View.nushell(dat, :explore)
|
62
65
|
else
|
63
66
|
puts YAML.dump(dat)
|
64
67
|
end
|
@@ -86,9 +89,23 @@ when /profiles?/
|
|
86
89
|
puts 'Usage: luca-salary profile[s] create Name'
|
87
90
|
exit 1
|
88
91
|
end
|
92
|
+
when 'enc', 'encrypt'
|
93
|
+
# TODO: proxy encrypt/decrypt
|
94
|
+
OptionParser.new do |opt|
|
95
|
+
opt.banner = 'Usage: luca-salary enc|encrypt'
|
96
|
+
opt.on('--clean', 'remove plain directory') { |_v| params[:clean] = true }
|
97
|
+
args = opt.parse(ARGV)
|
98
|
+
LucaSupport::Enc.encrypt("s_profiles", cleanup: params[:clean])
|
99
|
+
end
|
100
|
+
when 'dec', 'decrypt'
|
101
|
+
OptionParser.new do |opt|
|
102
|
+
opt.banner = 'Usage: luca-salary dec|decrypt'
|
103
|
+
args = opt.parse(ARGV)
|
104
|
+
LucaSupport::Enc.decrypt("s_profiles")
|
105
|
+
end
|
89
106
|
when 'export'
|
90
107
|
LucaCmd::Payment.export(ARGV)
|
91
|
-
when /payments?/
|
108
|
+
when 'pay', /payments?/
|
92
109
|
subcmd = ARGV.shift
|
93
110
|
case subcmd
|
94
111
|
when 'create'
|
@@ -99,8 +116,10 @@ when /payments?/
|
|
99
116
|
end
|
100
117
|
when 'list'
|
101
118
|
OptionParser.new do |opt|
|
102
|
-
opt.banner = 'Usage: luca-salary payments list [--mail] year month [date]'
|
119
|
+
opt.banner = 'Usage: luca-salary payments list [--mail|--nu|--explore] year month [date]'
|
103
120
|
opt.on('--mail', 'send to managers') { |_v| params['mode'] = 'mail' }
|
121
|
+
opt.on('--nu', 'show table in nushell') { |_v| params[:output] = 'nu' }
|
122
|
+
opt.on('--explore', 'explore table in nushell') { |_v| params[:output] = 'explore' }
|
104
123
|
args = opt.parse(ARGV)
|
105
124
|
LucaCmd::Payment.list(args, params)
|
106
125
|
end
|
@@ -131,5 +150,7 @@ else
|
|
131
150
|
puts ' profiles'
|
132
151
|
puts ' payments'
|
133
152
|
puts ' export: puts payment data for LucaBook import'
|
153
|
+
puts ' encrypt: encrypt secure profiles'
|
154
|
+
puts ' decrypt: decrypt secure profiles'
|
134
155
|
exit 1
|
135
156
|
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.29
|
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-18 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
|