Class: Ecom::Core::OvertimeSheet
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Ecom::Core::OvertimeSheet
- Defined in:
- app/models/ecom/core/overtime_sheet.rb
Class Method Summary collapse
-
.create_new(date, project_id) ⇒ Object
Overtime sheet should be created using the method below only.
- .exists_for_date?(date, project_id) ⇒ Boolean
- .open_exists?(project_id) ⇒ Boolean
- .open_for_date_exists?(date, project_id) ⇒ Boolean
Class Method Details
.create_new(date, project_id) ⇒ 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.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/ecom/core/overtime_sheet.rb', line 36 def self.create_new(date, project_id) if OvertimeSheet.exists_for_date?(date, project_id) raise 'There is already an overtime sheet for the selected date.' end if OvertimeSheet.open_exists?(project_id) 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: StatusConstants::OPEN, project_id: project_id) end |
.exists_for_date?(date, project_id) ⇒ Boolean
27 28 29 |
# File 'app/models/ecom/core/overtime_sheet.rb', line 27 def self.exists_for_date?(date, project_id) OvertimeSheet.by_project(project_id).by_date(date).exists? end |
.open_exists?(project_id) ⇒ Boolean
19 20 21 |
# File 'app/models/ecom/core/overtime_sheet.rb', line 19 def self.open_exists?(project_id) OvertimeSheet.open(project_id).exists? end |
.open_for_date_exists?(date, project_id) ⇒ Boolean
23 24 25 |
# File 'app/models/ecom/core/overtime_sheet.rb', line 23 def self.open_for_date_exists?(date, project_id) OvertimeSheet.open(project_id).where(date: date).exists? end |