Class: XeroRuby::PayrollUk::Deduction

Inherits:
Object
  • Object
show all
Defined in:
lib/xero-ruby/models/payroll_uk/deduction.rb

Defined Under Namespace

Classes: EnumAttributeValidator

Constant Summary collapse

CAPITAL_CONTRIBUTIONS =
"CapitalContributions".freeze
CHILD_CARE_VOUCHER =
"ChildCareVoucher".freeze
MAKING_GOOD =
"MakingGood".freeze
POSTGRADUATE_LOAN_DEDUCTIONS =
"PostgraduateLoanDeductions".freeze
PRIVATE_USE_PAYMENTS =
"PrivateUsePayments".freeze
SALARY_SACRIFICE =
"SalarySacrifice".freeze
STAKEHOLDER_PENSION =
"StakeholderPension".freeze
STAKEHOLDER_PENSION_POST_TAX =
"StakeholderPensionPostTax".freeze
STUDENT_LOAN_DEDUCTIONS =
"StudentLoanDeductions".freeze
UK_OTHER =
"UkOther".freeze
FIXED_AMOUNT =
"FixedAmount".freeze
PERCENTAGE_OF_GROSS =
"PercentageOfGross".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Deduction

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 147

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::PayrollUk::Deduction` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!self.class.attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::PayrollUk::Deduction`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'deduction_id')
    self.deduction_id = attributes[:'deduction_id']
  end

  if attributes.key?(:'deduction_name')
    self.deduction_name = attributes[:'deduction_name']
  end

  if attributes.key?(:'deduction_category')
    self.deduction_category = attributes[:'deduction_category']
  end

  if attributes.key?(:'liability_account_id')
    self. = attributes[:'liability_account_id']
  end

  if attributes.key?(:'current_record')
    self.current_record = attributes[:'current_record']
  end

  if attributes.key?(:'standard_amount')
    self.standard_amount = attributes[:'standard_amount']
  end

  if attributes.key?(:'reduces_super_liability')
    self.reduces_super_liability = attributes[:'reduces_super_liability']
  end

  if attributes.key?(:'reduces_tax_liability')
    self.reduces_tax_liability = attributes[:'reduces_tax_liability']
  end

  if attributes.key?(:'calculation_type')
    self.calculation_type = attributes[:'calculation_type']
  end

  if attributes.key?(:'percentage')
    self.percentage = attributes[:'percentage']
  end

  if attributes.key?(:'subject_to_nic')
    self.subject_to_nic = attributes[:'subject_to_nic']
  end

  if attributes.key?(:'subject_to_tax')
    self.subject_to_tax = attributes[:'subject_to_tax']
  end

  if attributes.key?(:'is_reduced_by_basic_rate')
    self.is_reduced_by_basic_rate = attributes[:'is_reduced_by_basic_rate']
  end

  if attributes.key?(:'apply_to_pension_calculations')
    self.apply_to_pension_calculations = attributes[:'apply_to_pension_calculations']
  end

  if attributes.key?(:'is_calculating_on_qualifying_earnings')
    self.is_calculating_on_qualifying_earnings = attributes[:'is_calculating_on_qualifying_earnings']
  end

  if attributes.key?(:'is_pension')
    self.is_pension = attributes[:'is_pension']
  end
end

Instance Attribute Details

#apply_to_pension_calculationsObject

Identifier for apply to pension calculations



71
72
73
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 71

def apply_to_pension_calculations
  @apply_to_pension_calculations
end

#calculation_typeObject

determine the calculation type whether fixed amount or percentage of gross



54
55
56
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 54

def calculation_type
  @calculation_type
end

#current_recordObject

Identifier of a record is active or not.



42
43
44
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 42

def current_record
  @current_record
end

#deduction_categoryObject

Deduction Category type



26
27
28
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 26

def deduction_category
  @deduction_category
end

#deduction_idObject

The Xero identifier for Deduction



20
21
22
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 20

def deduction_id
  @deduction_id
end

#deduction_nameObject

Name of the deduction



23
24
25
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 23

def deduction_name
  @deduction_name
end

#is_calculating_on_qualifying_earningsObject

Identifier of calculating on qualifying earnings



74
75
76
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 74

def is_calculating_on_qualifying_earnings
  @is_calculating_on_qualifying_earnings
end

#is_pensionObject

Identifier of applicable for pension or not



77
78
79
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 77

def is_pension
  @is_pension
end

#is_reduced_by_basic_rateObject

Identifier of reduced by basic rate applicable or not



68
69
70
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 68

def is_reduced_by_basic_rate
  @is_reduced_by_basic_rate
end

#liability_account_idObject

Xero identifier for Liability Account



39
40
41
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 39

def 
  @liability_account_id
end

#percentageObject

Percentage of gross



59
60
61
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 59

def percentage
  @percentage
end

#reduces_super_liabilityObject

Identifier of reduces super liability



48
49
50
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 48

def reduces_super_liability
  @reduces_super_liability
end

#reduces_tax_liabilityObject

Identifier of reduces tax liability



51
52
53
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 51

def reduces_tax_liability
  @reduces_tax_liability
end

#standard_amountObject

Standard amount of the deduction



45
46
47
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 45

def standard_amount
  @standard_amount
end

#subject_to_nicObject

Identifier of subject To NIC



62
63
64
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 62

def subject_to_nic
  @subject_to_nic
end

#subject_to_taxObject

Identifier of subject To Tax



65
66
67
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 65

def subject_to_tax
  @subject_to_tax
end

Class Method Details

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 102

def self.attribute_map
  {
    :'deduction_id' => :'deductionId',
    :'deduction_name' => :'deductionName',
    :'deduction_category' => :'deductionCategory',
    :'liability_account_id' => :'liabilityAccountId',
    :'current_record' => :'currentRecord',
    :'standard_amount' => :'standardAmount',
    :'reduces_super_liability' => :'reducesSuperLiability',
    :'reduces_tax_liability' => :'reducesTaxLiability',
    :'calculation_type' => :'calculationType',
    :'percentage' => :'percentage',
    :'subject_to_nic' => :'subjectToNIC',
    :'subject_to_tax' => :'subjectToTax',
    :'is_reduced_by_basic_rate' => :'isReducedByBasicRate',
    :'apply_to_pension_calculations' => :'applyToPensionCalculations',
    :'is_calculating_on_qualifying_earnings' => :'isCalculatingOnQualifyingEarnings',
    :'is_pension' => :'isPension'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



310
311
312
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 310

def self.build_from_hash(attributes)
  new.build_from_hash(attributes)
end

.openapi_typesObject

Attribute type mapping.



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 124

def self.openapi_types
  {
    :'deduction_id' => :'String',
    :'deduction_name' => :'String',
    :'deduction_category' => :'String',
    :'liability_account_id' => :'String',
    :'current_record' => :'Boolean',
    :'standard_amount' => :'BigDecimal',
    :'reduces_super_liability' => :'Boolean',
    :'reduces_tax_liability' => :'Boolean',
    :'calculation_type' => :'String',
    :'percentage' => :'BigDecimal',
    :'subject_to_nic' => :'Boolean',
    :'subject_to_tax' => :'Boolean',
    :'is_reduced_by_basic_rate' => :'Boolean',
    :'apply_to_pension_calculations' => :'Boolean',
    :'is_calculating_on_qualifying_earnings' => :'Boolean',
    :'is_pension' => :'Boolean'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 274

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      deduction_id == o.deduction_id &&
      deduction_name == o.deduction_name &&
      deduction_category == o.deduction_category &&
       == o. &&
      current_record == o.current_record &&
      standard_amount == o.standard_amount &&
      reduces_super_liability == o.reduces_super_liability &&
      reduces_tax_liability == o.reduces_tax_liability &&
      calculation_type == o.calculation_type &&
      percentage == o.percentage &&
      subject_to_nic == o.subject_to_nic &&
      subject_to_tax == o.subject_to_tax &&
      is_reduced_by_basic_rate == o.is_reduced_by_basic_rate &&
      apply_to_pension_calculations == o.apply_to_pension_calculations &&
      is_calculating_on_qualifying_earnings == o.is_calculating_on_qualifying_earnings &&
      is_pension == o.is_pension
end

#_deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • string

    type Data type

  • string

    value Value to be deserialized

Returns:

  • (Object)

    Deserialized data



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 338

def _deserialize(type, value)
  case type.to_sym
  when :DateTime
    DateTime.parse(parse_date(value))
  when :Date
    Date.parse(parse_date(value))
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :BigDecimal
    BigDecimal(value.to_s)
  when :Boolean
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    XeroRuby::PayrollUk.const_get(type).build_from_hash(value)
  end
end

#_to_hash(value, downcase: false) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • value (Object)

    Any valid value

Returns:

  • (Hash)

    Returns the value in the form of hash



411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 411

def _to_hash(value, downcase: false)
  if value.is_a?(Array)
    value.map do |v|
      v.to_hash(downcase: downcase)
    end
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash(downcase: downcase)
  else
    value
  end
end

#build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 317

def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  self.class.openapi_types.each_pair do |key, type|
    if type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[self.class.attribute_map[key]].is_a?(Array)
        self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
    end # or else data not found in attributes(hash), not an issue as the data can be optional
  end

  self
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


297
298
299
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 297

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



303
304
305
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 303

def hash
  [deduction_id, deduction_name, deduction_category, , current_record, standard_amount, reduces_super_liability, reduces_tax_liability, calculation_type, percentage, subject_to_nic, subject_to_tax, is_reduced_by_basic_rate, apply_to_pension_calculations, is_calculating_on_qualifying_earnings, is_pension].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 227

def list_invalid_properties
  invalid_properties = Array.new
  if @deduction_name.nil?
    invalid_properties.push('invalid value for "deduction_name", deduction_name cannot be nil.')
  end

  if @liability_account_id.nil?
    invalid_properties.push('invalid value for "liability_account_id", liability_account_id cannot be nil.')
  end

  invalid_properties
end

#parse_date(datestring) ⇒ Object



427
428
429
430
431
432
433
434
435
436
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 427

def parse_date(datestring)
  if datestring.include?('Date')
    date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
    original, date, timezone = *date_pattern.match(datestring)
    date = (date.to_i / 1000)
    Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
  else # handle date 'types' for small subset of payroll API's
    Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
  end
end

#to_attributesObject

Returns the object in the form of hash with snake_case



403
404
405
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 403

def to_attributes
  to_hash(downcase: true)
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • (Hash)

    Returns the object in the form of hash



385
386
387
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 385

def to_body
  to_hash
end

#to_hash(downcase: false) ⇒ Hash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



391
392
393
394
395
396
397
398
399
400
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 391

def to_hash(downcase: false)
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    next if value.nil?
    key = downcase ? attr : param
    hash[key] = _to_hash(value, downcase: downcase)
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



379
380
381
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 379

def to_s
  to_hash.to_s
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



242
243
244
245
246
247
248
249
250
# File 'lib/xero-ruby/models/payroll_uk/deduction.rb', line 242

def valid?
  return false if @deduction_name.nil?
  deduction_category_validator = EnumAttributeValidator.new('String', ["CapitalContributions", "ChildCareVoucher", "MakingGood", "PostgraduateLoanDeductions", "PrivateUsePayments", "SalarySacrifice", "StakeholderPension", "StakeholderPensionPostTax", "StudentLoanDeductions", "UkOther"])
  return false unless deduction_category_validator.valid?(@deduction_category)
  return false if @liability_account_id.nil?
  calculation_type_validator = EnumAttributeValidator.new('String', ["FixedAmount", "PercentageOfGross"])
  return false unless calculation_type_validator.valid?(@calculation_type)
  true
end