Class: EmployeePayrollTransaction

Inherits:
ApplicationRecord show all
Includes:
EmployeePayrollTransactionProcedures
Defined in:
app/models/employee_payroll_transaction.rb

Constant Summary collapse

TYPES =
{
  REVENUE: 'revenue',
  DEDUCTION: 'deduction',
  NONE: 'none'
}

Instance Method Summary collapse

Methods inherited from ApplicationRecord

define_decrypted_attribute, define_decrypted_attributes, #errors_in_bullet_points, primary_connection, special_connection

Instance Method Details

#amount_should_match_tag_typeObject



33
34
35
36
37
38
39
# File 'app/models/employee_payroll_transaction.rb', line 33

def amount_should_match_tag_type
  if tag_type == 'revenue' && amount < 0
    errors.add(:amount, 'Revenue should be positive')
  elsif tag_type == 'deduction' && amount > 0
    errors.add(:amount, 'Deduction should be negative')
  end
end

#locked?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
# File 'app/models/employee_payroll_transaction.rb', line 22

def locked?
  return false unless payroll_transaction_detail

  payroll_transaction_header = payroll_transaction_detail.payroll_transaction_header
  payroll_transaction_header.locked?
end

#match_amount_to_tag_typeObject



41
42
43
44
45
46
47
# File 'app/models/employee_payroll_transaction.rb', line 41

def match_amount_to_tag_type
  if (tag_type == TYPES[:REVENUE] && amount < 0) ||
     (tag_type == TYPES[:DEDUCTION] && amount > 0) ||
     (tag_type == TYPES[:NONE] && amount < 0)
    self.amount = -amount
  end
end

#modifyable?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/employee_payroll_transaction.rb', line 29

def modifyable?
  allow_modification || payroll_transaction_detail.manually_unlocked
end

#unlock(user_name:) ⇒ Object



57
58
59
60
61
62
63
64
# File 'app/models/employee_payroll_transaction.rb', line 57

def unlock(user_name:)
  ActiveRecord::Base.execute_procedure(
    'pr_update_payroll_transaction_detail',
    payroll_transaction_detail_id,
    true, # manually unlock
    user_name
  )
end

#update_procedureObject



49
50
51
52
53
54
55
# File 'app/models/employee_payroll_transaction.rb', line 49

def update_procedure
  ActiveRecord::Base.execute_procedure(
    'pr_update_employee_payroll_transaction',
    employee_payroll_transaction_id,
    amount
  )
end