kirico 1.0.5 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@
4
4
  module Kirico
5
5
  class DataRecord22257041 < ApplicationRecord
6
6
  DOC_CODE = '22257041'
7
- COVERED_MONTHS = %i(apr may jun).freeze
7
+ COVERED_MONTHS = %i[apr may jun].freeze
8
8
 
9
9
  attribute :area_code, String
10
10
  attribute :office_code, String
@@ -37,12 +37,12 @@ module Kirico
37
37
  define_in_k_method :old_monthly_standard_income_hel_ins, :old_monthly_standard_income_pns_ins
38
38
 
39
39
  validates :area_code, charset: { accept: [:numeric] }, sjis_bytesize: { is: 2 }
40
- validates :office_code, charset: { accept: %i(numeric latin katakana) }, sjis_bytesize: { in: 1..4 }
40
+ validates :office_code, charset: { accept: %i[numeric latin katakana] }, sjis_bytesize: { in: 1..4 }
41
41
  validates :ip_code, charset: { accept: [:numeric] }, sjis_bytesize: { in: 1..6 }
42
42
  validates :applied_at, timeliness: { on_or_after: -> { Date.new(1989, 1, 8) }, type: :date }
43
43
  validates :ip_name_yomi, charset: { accept: [:katakana] }, sjis_bytesize: { in: 1..25 }, space_divider: { space: :half_width }
44
44
  validates :ip_name, charset: { accept: [:all] }, sjis_bytesize: { in: 0..24 }, allow_blank: true, space_divider: { space: :full_width }
45
- validates :gender_type, inclusion: { in: %i(gender_type_1 gender_type_2 gender_type_3 gender_type_5 gender_type_6 gender_type_7) }
45
+ validates :gender_type, inclusion: { in: %i[gender_type_1 gender_type_2 gender_type_3 gender_type_5 gender_type_6 gender_type_7] }
46
46
  validates :old_monthly_standard_income_hel_ins, numericality: { greater_than_or_equal_to: 1_000, less_than_or_equal_to: 9_999_999 }, allow_blank: true
47
47
  validates :old_monthly_standard_income_pns_ins, numericality: { greater_than_or_equal_to: 1_000, less_than_or_equal_to: 9_999_999 }, allow_blank: true
48
48
  validates :old_applied_at, timeliness: { on_or_after: -> { Date.new(1989, 1, 8) }, type: :date }
@@ -54,9 +54,9 @@ module Kirico
54
54
  validates "#{month}_income_goods", numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 9_999_999 }
55
55
  end
56
56
  validates :avg_adjustment, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 9_999_999 }, allow_blank: true
57
- validates :ip_type, inclusion: { in: %i(ip_type_0 ip_type_1 ip_type_2) }
57
+ validates :ip_type, inclusion: { in: %i[ip_type_0 ip_type_1 ip_type_2] }
58
58
  validates :retroacted_payment, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 9_999_999 }, allow_blank: true
59
- validates :income_updated_type, inclusion: { in: %i(income_updated_type_0 income_updated_type_1) }, allow_blank: true
59
+ validates :income_updated_type, inclusion: { in: %i[income_updated_type_0 income_updated_type_1] }, allow_blank: true
60
60
  validates :income_diff_amount, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 9_999_999 }, allow_blank: true
61
61
  validates :income_updated_at, timeliness: { on_or_after: -> { Date.new(1989, 1, 8) }, type: :date }, allow_blank: true
62
62
  validates :memo, charset: { accept: [:all] }, sjis_bytesize: { in: 0..75 }, allow_blank: true
@@ -132,6 +132,7 @@ module Kirico
132
132
  # - 算定対象月が存在しない場合は「0」を返す
133
133
  def income_average
134
134
  return 0 if target_months.empty?
135
+
135
136
  total = target_months.map do |month|
136
137
  send("#{month}_income_currency").to_i + send("#{month}_income_goods").to_i
137
138
  end.inject(:+)
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ # 賞与支払届データレコード
4
+ module Kirico
5
+ class DataRecord2265700 < ApplicationRecord
6
+ DOC_CODE = '2265700'
7
+
8
+ attribute :prefecture_code, String
9
+ attribute :area_code, String
10
+ attribute :office_code, String
11
+ attribute :ip_code, String
12
+ attribute :ip_name_yomi, String
13
+ attribute :ip_name, String
14
+ attribute :birth_at, Date
15
+ attribute :bonus_payment_at, Date
16
+ attribute :payment_in_currency, Integer
17
+ attribute :payment_in_goods, Integer
18
+ attribute :my_number, String
19
+ attribute :area_code_of_basic_pension_number, String
20
+ attribute :serial_number_of_basic_pension_number, String
21
+ attribute :seventy_years_and_over, Integer
22
+ attribute :work_in_multiple_company, Integer
23
+ attribute :first_payment_day_of_multiple_payments_within_the_same_month, String
24
+ attribute :submit_only_seventy_years_and_over, Integer
25
+
26
+ define_format_date_method :birth_at, :bonus_payment_at
27
+ define_code_mapper_method :birth_at_era_nengo, :bonus_payment_at_era_nengo
28
+
29
+ validates :prefecture_code, charset: { accept: [:numeric] }, sjis_bytesize: { is: 2 }
30
+ validates :area_code, charset: { accept: [:numeric] }, sjis_bytesize: { is: 2 }
31
+ validates :office_code, charset: { accept: %i[numeric latin katakana] }, sjis_bytesize: { in: 1..4 }
32
+ validates :ip_code, charset: { accept: [:numeric] }, sjis_bytesize: { in: 1..6 }
33
+ validates :ip_name_yomi, charset: { accept: [:katakana] }, sjis_bytesize: { in: 1..25 }, space_divider: { space: :half_width }
34
+ validates :ip_name, charset: { accept: [:all] }, sjis_bytesize: { in: 0..24 }, allow_blank: true, space_divider: { space: :full_width }
35
+ validates :bonus_payment_at, timeliness: { on_or_after: -> { Date.new(1989, 1, 8) }, type: :date }
36
+ validates :payment_in_currency, numericality: { greater_than_or_equal_to: 0 }
37
+ validates :payment_in_goods, numericality: { greater_than_or_equal_to: 0 }
38
+ validates :my_number, charset: { accept: [:numeric] }, sjis_bytesize: { is: 12 }, allow_nil: true
39
+ validates :area_code_of_basic_pension_number, charset: { accept: [:numeric] }, sjis_bytesize: { is: 4 }, allow_nil: true
40
+ validates :serial_number_of_basic_pension_number, charset: { accept: [:numeric] }, sjis_bytesize: { is: 6 }, allow_nil: true
41
+ validates :seventy_years_and_over, inclusion: { in: [1] }, allow_nil: true
42
+ validates :work_in_multiple_company, inclusion: { in: [1] }, allow_nil: true
43
+ validates :first_payment_day_of_multiple_payments_within_the_same_month, charset: { accept: [:numeric] }, sjis_bytesize: { is: 2 }, allow_nil: true
44
+ validates :submit_only_seventy_years_and_over, inclusion: { in: [1] }, allow_nil: true
45
+ validate :seventy_years_and_over_employee_need_to_input_my_number_or_basic_pension_number
46
+
47
+ def initialize
48
+ yield(self) if block_given?
49
+ end
50
+
51
+ def to_csv
52
+ [
53
+ DOC_CODE,
54
+ prefecture_code,
55
+ area_code,
56
+ office_code,
57
+ ip_code,
58
+ ip_name_yomi,
59
+ ip_name,
60
+ mapped_birth_at_era_nengo,
61
+ fmt_era_ymd_birth_at,
62
+ mapped_bonus_payment_at_era_nengo,
63
+ fmt_era_ymd_bonus_payment_at,
64
+ adjusted_payment_in_currency,
65
+ adjusted_payment_in_goods,
66
+ bonus_total(payment_in_currency, payment_in_goods),
67
+ my_number,
68
+ area_code_of_basic_pension_number,
69
+ serial_number_of_basic_pension_number,
70
+ seventy_years_and_over,
71
+ work_in_multiple_company,
72
+ first_payment_day_of_multiple_payments_within_the_same_month,
73
+ submit_only_seventy_years_and_over
74
+ ].map { |attr| attr.to_s.encode('CP932') }.join(',')
75
+ end
76
+
77
+ def bonus_total(currency, goods)
78
+ total = currency.to_i + goods.to_i
79
+ total >= 10_000_000 ? 9_999_000 : total.floor(-3)
80
+ end
81
+
82
+ def adjusted_payment_in_currency
83
+ payment_in_currency < 10_000_000 ? payment_in_currency : 9_999_999
84
+ end
85
+
86
+ def adjusted_payment_in_goods
87
+ payment_in_goods < 10_000_000 ? payment_in_goods : 9_999_999
88
+ end
89
+
90
+ private
91
+
92
+ def seventy_years_and_over_employee_need_to_input_my_number_or_basic_pension_number
93
+ return if seventy_years_and_over.nil?
94
+
95
+ errors.add(:base, '70歳以上被用者の場合、マイナンバー、もしくは基礎年金番号の入力は必須です。') if my_number.nil? && area_code_of_basic_pension_number.nil? && serial_number_of_basic_pension_number.nil?
96
+ end
97
+ end
98
+ end
@@ -4,14 +4,17 @@ require 'kirico/models/base_fd_management_record'
4
4
 
5
5
  module Kirico
6
6
  class FDManagementRecord < BaseFDManagementRecord
7
+ attribute :prefecture_code, String
7
8
  attribute :area_code, String
8
9
  attribute :office_code, String
9
10
 
11
+ validates :prefecture_code, charset: { accept: [:numeric] }, sjis_bytesize: { is: 2 }
10
12
  validates :area_code, charset: { accept: [:numeric] }, sjis_bytesize: { is: 2 }
11
- validates :office_code, charset: { accept: %i(numeric latin katakana) }, sjis_bytesize: { in: 1..4 }
13
+ validates :office_code, charset: { accept: %i[numeric latin katakana] }, sjis_bytesize: { in: 1..4 }
12
14
 
13
15
  def to_csv
14
16
  [
17
+ prefecture_code,
15
18
  area_code,
16
19
  office_code,
17
20
  fd_seq_number,
@@ -18,7 +18,7 @@ module Kirico
18
18
  validates :fd, :company_count, :company, :records, presence: true
19
19
  validate :validate_children
20
20
 
21
- def initialize(fd:, company_count: Kirico::CompanyCount.new, company:, records: [])
21
+ def initialize(fd:, company:, company_count: Kirico::CompanyCount.new, records: [])
22
22
  @fd = fd
23
23
  @company_count = company_count
24
24
  @company = company
@@ -41,9 +41,10 @@ module Kirico
41
41
 
42
42
  # 子のエラーを自身のエラーとして設定する
43
43
  def validate_children
44
- %i(fd company company_count).each do |attribute|
44
+ %i[fd company company_count].each do |attribute|
45
45
  rec = send(attribute)
46
46
  next if rec.nil? || rec.valid?
47
+
47
48
  rec.errors.full_messages.each do |msg|
48
49
  errors.add(attribute, msg)
49
50
  end
@@ -52,6 +53,7 @@ module Kirico
52
53
  # 2行以上存在する場合は、何行目でエラーが起きたのかを知りたい
53
54
  records.each.with_index(1) do |rec, i|
54
55
  next if rec.valid?
56
+
55
57
  row = I18n.t('errors.row_counter', num: i) if records.length > 1
56
58
  rec.errors.full_messages.each do |msg|
57
59
  errors.add(:records, "#{row}#{msg}")
@@ -104,6 +104,7 @@ module Kirico
104
104
  define_method("mapped_#{attr_name}") do
105
105
  value = send(attr_name)
106
106
  return if value.nil?
107
+
107
108
  class_name = self.class.name.underscore
108
109
  @mappers ||= YAML.load_file(File.join(__dir__, 'mappers.yml'))
109
110
  @mappers['mappers'][class_name.to_s].try(:[], attr_name.to_s).try(:[], value.to_s)
@@ -15,6 +15,23 @@ mappers:
15
15
  T: 3
16
16
  S: 5
17
17
  H: 7
18
+ # 月額変更届
19
+ kirico/data_record2221700:
20
+ birth_at_era_nengo:
21
+ M: 1
22
+ T: 3
23
+ S: 5
24
+ H: 7
25
+ R: 9
26
+ applied_at_era_nengo:
27
+ H: 7
28
+ R: 9
29
+ old_applied_at_era_nengo:
30
+ H: 7
31
+ R: 9
32
+ income_updated_type:
33
+ income_updated_type_0: 1
34
+ income_updated_type_1: 2
18
35
  # 算定基礎届
19
36
  kirico/data_record22257041:
20
37
  birth_at_era_nengo:
@@ -51,3 +68,47 @@ mappers:
51
68
  income_updated_type:
52
69
  income_updated_type_0: 0
53
70
  income_updated_type_1: 1
71
+ # 2018年3月以降 算定基礎届
72
+ kirico/data_record2225700:
73
+ birth_at_era_nengo:
74
+ M: 1
75
+ T: 3
76
+ S: 5
77
+ H: 7
78
+ R: 9
79
+ applied_at_era_nengo:
80
+ M: 1
81
+ T: 3
82
+ S: 5
83
+ H: 7
84
+ R: 9
85
+ old_applied_at_era_nengo:
86
+ M: 1
87
+ T: 3
88
+ S: 5
89
+ H: 7
90
+ R: 9
91
+ income_updated_at_era_nengo:
92
+ M: 1
93
+ T: 3
94
+ S: 5
95
+ H: 7
96
+ R: 9
97
+ ip_type:
98
+ ip_type_0: 0
99
+ ip_type_1: 1
100
+ ip_type_2: 2
101
+ income_updated_type:
102
+ income_updated_type_0: 1
103
+ income_updated_type_1: 2
104
+ # 賞与支払届
105
+ kirico/data_record2265700:
106
+ birth_at_era_nengo:
107
+ M: 1
108
+ T: 3
109
+ S: 5
110
+ H: 7
111
+ R: 9
112
+ bonus_payment_at_era_nengo:
113
+ H: 7
114
+ R: 9
@@ -9,7 +9,7 @@ module Kirico
9
9
 
10
10
  attribute :name, String
11
11
 
12
- validates :name, charset: { accept: %i(katakana kanji) }, sjis_bytesize: { in: 1..25 }, space_divider: { space: :both_width }
12
+ validates :name, charset: { accept: %i[katakana kanji] }, sjis_bytesize: { in: 1..25 }, space_divider: { space: :both_width }
13
13
 
14
14
  def to_csv
15
15
  [name, COUNT].map { |attr| attr.to_s.encode('CP932') }.join(',')
@@ -7,10 +7,11 @@ module Kirico
7
7
  class SrFDManagementRecord < BaseFDManagementRecord
8
8
  attribute :sr_code, String
9
9
 
10
- validates :sr_code, charset: { accept: [:numeric] }, sjis_bytesize: { is: 4 }
10
+ validates :sr_code, charset: { accept: [:numeric] }, sjis_bytesize: { is: 8 }
11
11
 
12
12
  def to_csv
13
13
  [
14
+ '',
14
15
  '',
15
16
  sr_code,
16
17
  fd_seq_number,
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_model'
4
- require 'active_model/validator'
5
4
 
6
5
  # 文字種別を検証する
7
6
  #
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_model'
4
- require 'active_model/validator'
5
4
 
6
5
  # SJIS 換算の文字長を検証する
7
6
  # SJIS 変換不可文字が設定された場合は 1 文字としてカウントする
@@ -15,19 +14,18 @@ module Kirico
15
14
  MESSAGES = { is: :wrong_length_in_bytes, minimum: :too_short_in_bytes, maximum: :too_long_in_bytes }.freeze
16
15
  CHECKS = { is: :==, minimum: :>=, maximum: :<= }.freeze
17
16
 
18
- RESERVED_OPTIONS = %i(minimum maximum within is too_short too_long)
17
+ RESERVED_OPTIONS = %i[minimum maximum within is too_short too_long]
19
18
 
20
19
  def initialize(options)
21
- range = (options.delete(:in) || options.delete(:within))
20
+ range = options.delete(:in) || options.delete(:within)
22
21
  if range
23
22
  raise ArgumentError, ':in and :within must be a Range' unless range.is_a?(Range)
23
+
24
24
  options[:minimum] = range.min
25
25
  options[:maximum] = range.max
26
26
  end
27
27
 
28
- if options[:allow_blank] == false && options[:minimum].nil? && options[:is].nil?
29
- options[:minimum] = 1
30
- end
28
+ options[:minimum] = 1 if options[:allow_blank] == false && options[:minimum].nil? && options[:is].nil?
31
29
 
32
30
  super
33
31
  end
@@ -35,16 +33,12 @@ module Kirico
35
33
  def check_validity!
36
34
  keys = CHECKS.keys & options.keys
37
35
 
38
- if keys.empty?
39
- raise ArgumentError, 'Range unspecified. Specify the :in, :within, :maximum, :minimum, or :is option.'
40
- end
36
+ raise ArgumentError, 'Range unspecified. Specify the :in, :within, :maximum, :minimum, or :is option.' if keys.empty?
41
37
 
42
38
  keys.each do |key|
43
39
  value = options[key]
44
40
 
45
- unless (value.is_a?(Integer) && value >= 0) || value == Float::INFINITY
46
- raise ArgumentError, ":#{key} must be a nonnegative Integer or Infinity"
47
- end
41
+ raise ArgumentError, ":#{key} must be a nonnegative Integer or Infinity" unless (value.is_a?(Integer) && value >= 0) || value == Float::INFINITY
48
42
  end
49
43
  end
50
44
 
@@ -57,16 +51,14 @@ module Kirico
57
51
  check_value = options[key]
58
52
  next unless check_value
59
53
 
60
- if !value.nil? || skip_nil_check?(key)
61
- next if value_length.send(validity_check, check_value)
62
- end
54
+ next if (!value.nil? || skip_nil_check?(key)) && value_length.send(validity_check, check_value)
63
55
 
64
56
  errors_options[:count] = check_value
65
57
 
66
58
  default_message = options[MESSAGES[key]]
67
59
  errors_options[:message] ||= default_message if default_message
68
60
 
69
- record.errors.add(attribute, MESSAGES[key], errors_options)
61
+ record.errors.add(attribute, MESSAGES[key], **errors_options)
70
62
  end
71
63
  end
72
64
 
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_model'
4
- require 'active_model/validator'
5
- require 'active_model/validations/format'
6
4
 
7
5
  # 文字種別を検証する
8
6
  #
@@ -38,7 +36,7 @@ module Kirico
38
36
  }.freeze
39
37
 
40
38
  def check_validity!
41
- raise ArgumentError, "Invalid space option #{space_option}. Specify the :full_width, half_width, or :both_width." unless CHECKS.keys.include?(space_option)
39
+ raise ArgumentError, "Invalid space option #{space_option}. Specify the :full_width, half_width, or :both_width." unless CHECKS.key?(space_option)
42
40
  end
43
41
 
44
42
  def validate_each(record, attribute, value)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kirico
4
- VERSION = '1.0.5'
4
+ VERSION = '1.2.0'
5
5
  end
data/lib/kirico.rb CHANGED
@@ -8,6 +8,9 @@ require 'kirico/models/company'
8
8
  require 'kirico/models/data_identifier'
9
9
  require 'kirico/models/data_record22187041'
10
10
  require 'kirico/models/data_record22257041'
11
+ require 'kirico/models/data_record2221700'
12
+ require 'kirico/models/data_record2225700'
13
+ require 'kirico/models/data_record2265700'
11
14
  require 'kirico/models/fd_management_record'
12
15
  require 'kirico/models/helper'
13
16
  require 'kirico/models/form'