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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37e8c1758e8ea780f6f124747241c5c43b4047f96e6a72ebe28d3ae546034843
4
- data.tar.gz: b9d761bbedb5f77d222ac7e2d16cd5258ee60d52d7e2cc75ac941f1faae2b5f2
3
+ metadata.gz: dacc04e5464dfd8f7d38db60b2053af1fe609bc4d71d65bdd7fb83c5d460618a
4
+ data.tar.gz: 800e13698b5e92482085abd8b0928e9aed42fa23c24f5a046b2e06b4cea15889
5
5
  SHA512:
6
- metadata.gz: de2e967a7585233f87b4f3eeac7729b9d183563fc71610f355ca4329e2ff521d23473514d62e514da8e3735fe7bde4d8bc7f5dd58afd3e3bad2add31bb98630d
7
- data.tar.gz: b7fa56bbc2a8e15e20b6db16a7e1e4c4f6f555f0f19da175fe41e67785af84a809e7f3ee16ba1c7d5394e86038e18f0ac756f68ea26140169a1b9bb9bb8eb9dc
6
+ metadata.gz: 99bf549286ee85d693afcbb0fd9774fc833316fb34c6ebb14edcbd31264948c0393d9561ff262a345dedad75a9e3b6ae93cf325730b5106e89c9a02e201ffc97
7
+ data.tar.gz: dbac5444029228f95b84cf173431f65f657f49a5cfbb7d17b161765d09528a8933680a5d74fe490c11c788f68264abb51ab717c1c13d894db58554c780b0c448
@@ -1,3 +1,11 @@
1
+ ## LucaSalary 0.1.20
2
+
3
+ * Implement `year_total`
4
+
5
+ ## LucaSalary 0.1.19
6
+
7
+ * Support `payment_term` on config.yml for accounting export.
8
+
1
9
  ## LucaSalary 0.1.18
2
10
 
3
11
  * Add summary to payslip. Refactor monthly payment.
@@ -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(@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.capitalise}"
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,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
- h = {}
49
- h[:debit] = {}
50
- h[:credit] = {}
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
- 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))
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
 
@@ -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.19'
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.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-20 00:00:00.000000000 Z
11
+ date: 2020-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lucarecord