lucasalary 0.1.18 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/luca_salary/base.rb +3 -32
- data/lib/luca_salary/monthly.rb +1 -1
- data/lib/luca_salary/payment.rb +53 -11
- data/lib/luca_salary/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dacc04e5464dfd8f7d38db60b2053af1fe609bc4d71d65bdd7fb83c5d460618a
|
4
|
+
data.tar.gz: 800e13698b5e92482085abd8b0928e9aed42fa23c24f5a046b2e06b4cea15889
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99bf549286ee85d693afcbb0fd9774fc833316fb34c6ebb14edcbd31264948c0393d9561ff262a345dedad75a9e3b6ae93cf325730b5106e89c9a02e201ffc97
|
7
|
+
data.tar.gz: dbac5444029228f95b84cf173431f65f657f49a5cfbb7d17b161765d09528a8933680a5d74fe490c11c788f68264abb51ab717c1c13d894db58554c780b0c448
|
data/CHANGELOG.md
CHANGED
data/lib/luca_salary/base.rb
CHANGED
@@ -14,34 +14,9 @@ module LucaSalary
|
|
14
14
|
|
15
15
|
def initialize(date = nil)
|
16
16
|
@date = date.nil? ? Date.today : Date.parse(date)
|
17
|
-
@pjdir = Pathname(LucaSupport::Config::Pjdir)
|
18
|
-
@config = load_config(@pjdir / 'config.yml')
|
19
17
|
@dict = load_dict
|
20
18
|
end
|
21
19
|
|
22
|
-
def gen_aggregation!
|
23
|
-
LucaSalary::Profile.all do |profile|
|
24
|
-
id = profile.dig('id')
|
25
|
-
payment = {}
|
26
|
-
targetdir = @date.year.to_s + 'Z'
|
27
|
-
past_data = LucaRecord::Base.find(id, "payments/#{targetdir}")
|
28
|
-
(1..12).map do |month|
|
29
|
-
origin_dir = @date.year.to_s + [nil, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'][month]
|
30
|
-
origin = LucaRecord::Base.find(id, "payments/#{origin_dir}")
|
31
|
-
# TODO: to be updated null check
|
32
|
-
if origin == {}
|
33
|
-
month
|
34
|
-
else
|
35
|
-
origin.select { |k, _v| /^[1-4][0-9A-Fa-f]{,3}$/.match(k) }.each do |k, v|
|
36
|
-
payment[k] = payment[k] ? payment[k] + v : v
|
37
|
-
end
|
38
|
-
nil
|
39
|
-
end
|
40
|
-
end
|
41
|
-
self.class.create(past_data.merge!(payment), "payments/#{targetdir}")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
20
|
def select_code(dat, code)
|
46
21
|
dat.filter { |k, _v| /^#{code}[0-9A-Fa-f]{,3}$/.match(k.to_s) }
|
47
22
|
end
|
@@ -76,19 +51,15 @@ module LucaSalary
|
|
76
51
|
|
77
52
|
private
|
78
53
|
|
79
|
-
def datadir
|
80
|
-
@pjdir / 'data'
|
81
|
-
end
|
82
|
-
|
83
54
|
def load_dict
|
84
|
-
LucaRecord::Dict.load_tsv_dict(
|
55
|
+
LucaRecord::Dict.load_tsv_dict(Pathname(PJDIR) / 'dict' / 'code.tsv')
|
85
56
|
end
|
86
57
|
|
87
58
|
def set_driver
|
88
|
-
code =
|
59
|
+
code = CONFIG['country']
|
89
60
|
if code
|
90
61
|
require "luca_salary/#{code.downcase}"
|
91
|
-
Kernel.const_get "LucaSalary::#{code.
|
62
|
+
Kernel.const_get "LucaSalary::#{code.capitalise}"
|
92
63
|
else
|
93
64
|
nil
|
94
65
|
end
|
data/lib/luca_salary/monthly.rb
CHANGED
@@ -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::
|
17
|
+
@pjdir = Pathname(LucaSupport::PJDIR)
|
18
18
|
@config = load_config(@pjdir + 'config.yml')
|
19
19
|
@driver = set_driver
|
20
20
|
end
|
data/lib/luca_salary/payment.rb
CHANGED
@@ -13,7 +13,7 @@ module LucaSalary
|
|
13
13
|
|
14
14
|
def initialize(date = nil)
|
15
15
|
@date = Date.parse(date)
|
16
|
-
@pjdir = Pathname(LucaSupport::
|
16
|
+
@pjdir = Pathname(LucaSupport::PJDIR)
|
17
17
|
@dict = LucaRecord::Dict.load_tsv_dict(@pjdir / 'dict' / 'code.tsv')
|
18
18
|
end
|
19
19
|
|
@@ -44,10 +44,51 @@ module LucaSalary
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
def self.year_total(year)
|
48
|
+
Profile.all do |profile|
|
49
|
+
id = profile.dig('id')
|
50
|
+
payment = { 'profile_id' => id }
|
51
|
+
# payment = {}
|
52
|
+
(1..12).each do |month|
|
53
|
+
search(year, month, nil, id).each do |origin|
|
54
|
+
# TODO: to be updated null check
|
55
|
+
if origin == {}
|
56
|
+
month
|
57
|
+
else
|
58
|
+
origin.select { |k, _v| /^[1-4][0-9A-Fa-f]{,3}$/.match(k) }.each do |k, v|
|
59
|
+
payment[k] = payment[k] ? payment[k] + v : v
|
60
|
+
end
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
payment = local_convert(payment)
|
66
|
+
create(payment, date: Date.new(year, 12, 31), codes: [id], basedir: 'payments/total')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.local_convert(payment)
|
71
|
+
return payment if CONFIG['country'].nil?
|
72
|
+
|
73
|
+
require "luca_salary/#{CONFIG['country'].downcase}"
|
74
|
+
klass = Kernel.const_get("LucaSalary::#{CONFIG['country'].capitalize}")
|
75
|
+
klass.year_total(payment)
|
76
|
+
rescue
|
77
|
+
return payment
|
78
|
+
end
|
79
|
+
|
80
|
+
# Export json for LucaBook.
|
81
|
+
# Accrual_date can be change with `payment_term` on config.yml. Default value is 0.
|
82
|
+
# `payment_term: 1` means payment on the next month of calculation target.
|
83
|
+
#
|
47
84
|
def export_json
|
48
|
-
|
49
|
-
|
50
|
-
|
85
|
+
accrual_date = if LucaSupport::CONFIG['payment_term']
|
86
|
+
pt = LucaSupport::CONFIG['payment_term']
|
87
|
+
Date.new(@date.prev_month(pt).year, @date.prev_month(pt).month, -1)
|
88
|
+
else
|
89
|
+
Date.new(@date.year, @date.month, -1)
|
90
|
+
end
|
91
|
+
h = { debit: {}, credit: {} }
|
51
92
|
accumulate.each do |k, v|
|
52
93
|
next if @dict.dig(k, :acct_label).nil?
|
53
94
|
|
@@ -56,13 +97,14 @@ module LucaSalary
|
|
56
97
|
h[pos][acct_label] = h[pos].key?(acct_label) ? h[pos][acct_label] + v : v
|
57
98
|
end
|
58
99
|
[].tap do |res|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
100
|
+
{}.tap do |item|
|
101
|
+
item['date'] = "#{accrual_date.year}-#{accrual_date.month}-#{accrual_date.day}"
|
102
|
+
item['debit'] = h[:debit].map { |k, v| { 'label' => k, 'value' => v } }
|
103
|
+
item['credit'] = h[:credit].map { |k, v| { 'label' => k, 'value' => v } }
|
104
|
+
item['x-editor'] = 'LucaSalary'
|
105
|
+
res << item
|
106
|
+
end
|
107
|
+
puts JSON.dump(readable(res))
|
66
108
|
end
|
67
109
|
end
|
68
110
|
|
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.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chuma Takahiro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lucarecord
|