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
Instance Method Summary collapse
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 |
Instance Method Details
#approve ⇒ Object
56 57 58 59 60 61 62 |
# File 'app/models/ecom/core/overtime_sheet.rb', line 56 def approve raise 'Overtime sheet is not submitted and cannot be approved' unless status == StatusConstants::SUBMITTED self.status = StatusConstants::APPROVED self.approved_at = DateTime.now save end |
#submit ⇒ Object
48 49 50 51 52 53 54 |
# File 'app/models/ecom/core/overtime_sheet.rb', line 48 def submit raise 'Overtime sheet is not open and cannot be submitted' if status != StatusConstants::OPEN self.submitted_at = DateTime.now self.status = StatusConstants::SUBMITTED save end |