Class: Ecom::Core::OvertimeSheet
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Ecom::Core::OvertimeSheet
- Defined in:
- app/models/ecom/core/overtime_sheet.rb
Constant Summary collapse
- OPEN =
'Open'.freeze
- SUBMITTED =
'Submitted'.freeze
- APPROVED =
'Approved'.freeze
Class Method Summary collapse
-
.create_new(date) ⇒ Object
Overtime sheet should be created using the method below only.
- .open_exists? ⇒ Boolean
- .open_for_date_exists?(date) ⇒ Boolean
Class Method Details
.create_new(date) ⇒ Object
Overtime sheet should be created using the method below only. This is because we need to check if there is an open overtime already, and also that we have only one open overtime sheet at a time.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/ecom/core/overtime_sheet.rb', line 29 def self.create_new(date) if OvertimeSheet.open_for_date_exists?(date) raise 'There is already an open overtime sheet for the selected date.' end if OvertimeSheet.open_exists? raise 'There is already an open overtime sheet. It has to be submitted before creating a new one.' end OvertimeSheet.create(date: date, opened_at: Time.now, status: OPEN) end |
.open_exists? ⇒ Boolean
16 17 18 |
# File 'app/models/ecom/core/overtime_sheet.rb', line 16 def self.open_exists? OvertimeSheet.open.exists? end |
.open_for_date_exists?(date) ⇒ Boolean
20 21 22 |
# File 'app/models/ecom/core/overtime_sheet.rb', line 20 def self.open_for_date_exists?(date) OvertimeSheet.open.for_date(date).exists? end |