lucasalary 0.1.18 → 0.1.24

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: 37e8c1758e8ea780f6f124747241c5c43b4047f96e6a72ebe28d3ae546034843
4
- data.tar.gz: b9d761bbedb5f77d222ac7e2d16cd5258ee60d52d7e2cc75ac941f1faae2b5f2
3
+ metadata.gz: 49f2002c8bc5ec17d605422ee282c0b7cb6053f88aa2fa3dce308e9dbbbdc5c5
4
+ data.tar.gz: e993bd468b91510ad9dc68e55b58c54be562b0dcb76f9a757d4f88b6392d860d
5
5
  SHA512:
6
- metadata.gz: de2e967a7585233f87b4f3eeac7729b9d183563fc71610f355ca4329e2ff521d23473514d62e514da8e3735fe7bde4d8bc7f5dd58afd3e3bad2add31bb98630d
7
- data.tar.gz: b7fa56bbc2a8e15e20b6db16a7e1e4c4f6f555f0f19da175fe41e67785af84a809e7f3ee16ba1c7d5394e86038e18f0ac756f68ea26140169a1b9bb9bb8eb9dc
6
+ metadata.gz: 3847524b19036ca598ae119613fd49a9983ce54cdcd37f233b02fead3c636de0f4dfb2c5f80c459c1bc9d8eda82aa8ac22ddc12326fbbcb3cc13e21f9b159804
7
+ data.tar.gz: 15758df4fb112cf71614d11315a6477ebc5506a9176c4c29867dfc7776ea549d7a15ffe38ca1b3edab2c7993c09ae3d89ef82ef0fea01fde89538854ae4a984c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## LucaSalary 0.1.24
2
+
3
+ * Fix: remove null record from `luca-salary export` JSON
4
+
5
+ ## LucaSalary 0.1.23
6
+
7
+ * Breaking change: move sum_code() to Class method
8
+
9
+ ## LucaSalary 0.1.22
10
+
11
+ * Add `luca-salary payments total` command for year total
12
+ * Fix: call localcode with calculation date
13
+
14
+ ## LucaSalary 0.1.20
15
+
16
+ * Implement `year_total`
17
+ * Breaking change: export key 'value' -> 'amount'
18
+
19
+ ## LucaSalary 0.1.19
20
+
21
+ * Support `payment_term` on config.yml for accounting export.
22
+
1
23
  ## LucaSalary 0.1.18
2
24
 
3
25
  * Add summary to payslip. Refactor monthly payment.
data/README.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Luca Salary
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/lucasalary.svg)](https://badge.fury.io/rb/lucasalary)
4
+ [![doc](https://img.shields.io/badge/doc-rubydoc-green.svg)](https://www.rubydoc.info/gems/lucasalary/index)
5
+ ![license](https://img.shields.io/github/license/chumaltd/luca)
4
6
 
5
- Salary calculation framework
7
+ LucaSalary is Abstraction framework coworking with each country module. As income tax differs in each county, most of implementation need to be developed separately.
8
+ At this time, [Japan module](https://github.com/chumaltd/luca-salary-jp) is under development as a practical reference.
9
+
10
+ ## Usage
11
+
12
+ Create blank profile of employees.
13
+
14
+ ```
15
+ $ luca-salary profiles create EmployeeName
16
+ ```
17
+
18
+ Profile is in YAML format. Need to describe along with each country requirement.
19
+ Once profiles completed, monthly payment records can be generated as follows:
20
+
21
+ ```
22
+ $ luca-salary payments create yyyy m
23
+ ```
24
+
25
+ Report is available with generated data as follows:
26
+
27
+ ```
28
+ $ luca-salary payments list [--mail] yyyy m
29
+ ```
data/exe/luca-salary CHANGED
@@ -39,6 +39,10 @@ module LucaCmd
39
39
  LucaSalary::Monthly.new.report(params.dig('mode'))
40
40
  end
41
41
  end
42
+
43
+ def self.total(args = nil, _params = nil)
44
+ LucaSalary::Payment.year_total(args.first.to_i)
45
+ end
42
46
  end
43
47
  end
44
48
 
@@ -80,6 +84,12 @@ when /payments?/
80
84
  args = opt.parse(ARGV)
81
85
  LucaCmd::Payment.list(args, params)
82
86
  end
87
+ when 'total'
88
+ OptionParser.new do |opt|
89
+ opt.banner = 'Usage: luca-salary payments total year'
90
+ args = opt.parse(ARGV)
91
+ LucaCmd::Payment.total(args)
92
+ end
83
93
  else
84
94
  puts 'Proper subcommand needed.'
85
95
  puts
@@ -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
@@ -62,13 +37,13 @@ module LucaSalary
62
37
  {}.tap do |h|
63
38
  (1..4).each do |n|
64
39
  code = n.to_s
65
- h[code] = sum_code(obj, code)
40
+ h[code] = self.class.sum_code(obj, code)
66
41
  end
67
42
  h['5'] = h['1'] - h['2'] - h['3'] + h['4']
68
43
  end
69
44
  end
70
45
 
71
- def sum_code(obj, code, exclude = nil)
46
+ def self.sum_code(obj, code, exclude = nil)
72
47
  target = obj.select { |k, _v| /^#{code}[0-9A-Fa-f]{,3}$/.match(k) }
73
48
  target = target.reject { |k, _v| exclude.include?(k) } if exclude
74
49
  target.values.inject(:+) || 0
@@ -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(@pjdir / 'dict' / 'code.tsv')
55
+ LucaRecord::Dict.load_tsv_dict(Pathname(PJDIR) / 'dict' / 'code.tsv')
85
56
  end
86
57
 
87
58
  def set_driver
88
- code = @config['countryCode']
59
+ code = CONFIG['country']
89
60
  if code
90
61
  require "luca_salary/#{code.downcase}"
91
- Kernel.const_get "LucaSalary::#{code.upcase}"
62
+ Kernel.const_get "LucaSalary::#{code.capitalize}"
92
63
  else
93
64
  nil
94
65
  end
@@ -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::Config::Pjdir)
17
+ @pjdir = Pathname(LucaSupport::PJDIR)
18
18
  @config = load_config(@pjdir + 'config.yml')
19
19
  @driver = set_driver
20
20
  end
@@ -13,7 +13,7 @@ module LucaSalary
13
13
 
14
14
  def initialize(date = nil)
15
15
  @date = Date.parse(date)
16
- @pjdir = Pathname(LucaSupport::Config::Pjdir)
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,52 @@ 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
+ date = Date.new(year, 12, 31)
66
+ payment = local_convert(payment, date)
67
+ create(payment, date: date, codes: [id], basedir: 'payments/total')
68
+ end
69
+ end
70
+
71
+ def self.local_convert(payment, date)
72
+ return payment if CONFIG['country'].nil?
73
+
74
+ require "luca_salary/#{CONFIG['country'].downcase}"
75
+ klass = Kernel.const_get("LucaSalary::#{CONFIG['country'].capitalize}")
76
+ klass.year_total(payment, date)
77
+ rescue NameError
78
+ return payment
79
+ end
80
+
81
+ # Export json for LucaBook.
82
+ # Accrual_date can be change with `payment_term` on config.yml. Default value is 0.
83
+ # `payment_term: 1` means payment on the next month of calculation target.
84
+ #
47
85
  def export_json
48
- h = {}
49
- h[:debit] = {}
50
- h[:credit] = {}
86
+ accrual_date = if LucaSupport::CONFIG['payment_term']
87
+ pt = LucaSupport::CONFIG['payment_term']
88
+ Date.new(@date.prev_month(pt).year, @date.prev_month(pt).month, -1)
89
+ else
90
+ Date.new(@date.year, @date.month, -1)
91
+ end
92
+ h = { debit: {}, credit: {} }
51
93
  accumulate.each do |k, v|
52
94
  next if @dict.dig(k, :acct_label).nil?
53
95
 
@@ -56,13 +98,14 @@ module LucaSalary
56
98
  h[pos][acct_label] = h[pos].key?(acct_label) ? h[pos][acct_label] + v : v
57
99
  end
58
100
  [].tap do |res|
59
- item = {}
60
- item['date'] = "#{@date.year}-#{@date.month}-#{@date.day}"
61
- item['debit'] = h[:debit].map { |k, v| { 'label' => k, 'value' => v } }
62
- item['credit'] = h[:credit].map { |k, v| { 'label' => k, 'value' => v } }
63
- item['x-editor'] = 'LucaSalary'
64
- res << item
65
- puts JSON.dump(LucaSupport::Code.readable(res))
101
+ {}.tap do |item|
102
+ item['date'] = "#{accrual_date.year}-#{accrual_date.month}-#{accrual_date.day}"
103
+ item['debit'] = h[:debit].reject { |_k, v| v.nil? }.map { |k, v| { 'label' => k, 'amount' => v } }
104
+ item['credit'] = h[:credit].reject { |_k, v| v.nil? }.map { |k, v| { 'label' => k, 'amount' => v } }
105
+ item['x-editor'] = 'LucaSalary'
106
+ res << item
107
+ end
108
+ puts JSON.dump(readable(res))
66
109
  end
67
110
  end
68
111
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucaSalary
4
- VERSION = '0.1.18'
4
+ VERSION = '0.1.24'
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.1.18
4
+ version: 0.1.24
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-20 00:00:00.000000000 Z
11
+ date: 2022-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lucarecord
@@ -68,7 +68,7 @@ dependencies:
68
68
  version: 12.3.3
69
69
  description: 'Salary calculation framework
70
70
 
71
- '
71
+ '
72
72
  email:
73
73
  - co.chuma@gmail.com
74
74
  executables:
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 3.1.2
111
+ rubygems_version: 3.3.5
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: Salary calculation framework