ecom_core 1.1.8 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3c37e72f220d44c53d4755665e74b1686cf2564b849fc3f2c4c841262e67b4f
4
- data.tar.gz: d5c2e34ef00245ae8e71a19222df308c5a4ccd2b25c33d805431c6afe7e5d215
3
+ metadata.gz: 8709c2c3e2b254d5f9ad43731d7b8211dbec9c1c575540b9e5467cc572253574
4
+ data.tar.gz: 277e6297a78b839ba8d182d53e121e1226e958656e1672eb0033e686efc8d72e
5
5
  SHA512:
6
- metadata.gz: dbcf516b21e2758bd8c338a12f03a07b34e074681faec9213b849e86db236a110ea2cb80333c1dd405948f0d389969b08d7ff1a655ce33b4a0e7ef75e6c28c36
7
- data.tar.gz: 982a4664a200653053ae74380f2d2f8a53b7dc077543d0aec4b202b17ec2d64a28dad16bf7b9cd66204f2599744e21f977154f5e165a828a3e65e5eb7d0480a2
6
+ metadata.gz: 160eb086e465388d14de00a33449fc7bfdb335cc69a90dbcb3cd4689f09143dde9e2db67548087e2baeecd46cf97184395c5aab35a1625f34185ed3d472a9cde
7
+ data.tar.gz: dacf08a193c3eb2a8106b555653183e48ce8b7bf25273040c7d740f9c292ade85e3abb7a09e18e18580d7b6069285cfcec75df9ae6d1ffdac9035da3b9be7ada
@@ -1,10 +1,57 @@
1
1
  module Ecom
2
2
  module Core
3
3
  class AttendanceSheet < ApplicationRecord
4
- validates :date, presence: true, uniqueness: true
4
+ OPEN = 'Open'.freeze
5
+ CLOSED = 'Closed'.freeze
5
6
 
7
+ validates :date, :opened_at, presence: true, uniqueness: true
8
+ validates :status, inclusion: [OPEN, CLOSED]
9
+
10
+ has_many :attendance_sheet_entries
11
+
12
+ scope :open, -> { find_by(status: OPEN) }
13
+
14
+ def self.exists_for_today?
15
+ AttendanceSheet.where(date: Date.today).exists?
16
+ end
17
+
18
+ def self.open_exists_for_today?
19
+ where(status: OPEN, date: Date.today).exists?
20
+ end
21
+
22
+ # Attendance sheet should be created using the
23
+ # method below only. This is because we need to
24
+ # check if there is an open attendance already,
25
+ # and also that we have only one attendace sheet
26
+ # per day.
6
27
  def self.create_current
7
- AttendanceSheet.where(date: Date.today).first_or_create
28
+ raise 'Attendance sheet already created for the day.' if AttendanceSheet.exists_for_today?
29
+
30
+ AttendanceSheet.create(date: Date.today, opened_at: Time.now, status: OPEN)
31
+ end
32
+
33
+ def self.close_current
34
+ sheet = AttendanceSheet.find_by(date: Date.today, status: OPEN)
35
+
36
+ raise 'There is no attendance sheet to close.' if sheet.nil?
37
+
38
+ sheet.closed_at = Time.now
39
+ sheet.status = CLOSED
40
+ sheet.save
41
+ sheet
42
+ end
43
+
44
+ # This method should be used by privileged users
45
+ # to close the attendance sheet after the date has
46
+ # passed. Normally, timekeepers need to open and close
47
+ # an attendance sheet of a date on the specific date.
48
+ def self.close
49
+ raise 'There is no attendance sheet to close.' unless AttendanceSheet.open_exists_for_today?
50
+
51
+ sheet = AttendanceSheet.open
52
+ sheet.closed_at = Time.now
53
+ sheet.save
54
+ sheet
8
55
  end
9
56
  end
10
57
  end
@@ -0,0 +1,8 @@
1
+ module Ecom
2
+ module Core
3
+ class AttendanceSheetEntry < ApplicationRecord
4
+ belongs_to :attendance_sheet
5
+ belongs_to :crew
6
+ end
7
+ end
8
+ end
@@ -8,7 +8,6 @@ module Ecom
8
8
  if: proc { |c| c.employment_date.nil? }
9
9
 
10
10
  belongs_to :crew_type
11
- has_many :crew_times, class_name: 'Ecom::Core::CrewTime'
12
11
 
13
12
  validates :name, :qualification, presence: true
14
13
  validates :employment, inclusion: [PERMANENT, TEMPORARY]
@@ -1,8 +1,7 @@
1
1
  module Ecom
2
2
  module Core
3
3
  class CrewTime < ApplicationRecord
4
- belongs_to :crew
5
- belongs_to :attendance_sheet
4
+ belongs_to :attendance_sheet_entry
6
5
  belongs_to :overtime_type, optional: true
7
6
 
8
7
  validates :hours, :converted_hours, presence: true
@@ -2,9 +2,10 @@ class CreateEcomCoreAttendanceSheets < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  create_table :ecom_core_attendance_sheets do |t|
4
4
  t.date :date, null: false, unique: true
5
- t.time :opened_at
5
+ t.time :opened_at, null: false
6
6
  t.time :closed_at
7
7
  t.string :remark
8
+ t.string :status, null: false, default: 'Open'
8
9
 
9
10
  t.timestamps
10
11
  end
@@ -0,0 +1,14 @@
1
+ class CreateEcomCoreAttendanceSheetEntries < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_attendance_sheet_entries do |t|
4
+ t.references :attendance_sheet, null: false, index: { name: 'ase_on_as_indx' }
5
+ t.references :crew, null: false, index: { name: 'ase_on_crew_indx' }
6
+ t.float :total_hours
7
+
8
+ t.timestamps
9
+ end
10
+ add_foreign_key :ecom_core_attendance_sheet_entries, :ecom_core_attendance_sheets,
11
+ column: :attendance_sheet_id
12
+ add_foreign_key :ecom_core_attendance_sheet_entries, :ecom_core_crews, column: :crew_id
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ class RelateCrewTimeWithAttendanceSheetEntry < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :ecom_core_crew_times, :attendance_sheet_entry_id, :integer,
4
+ index: { name: 'ase_on_ct_indx' }
5
+ add_foreign_key :ecom_core_crew_times, :ecom_core_attendance_sheet_entries,
6
+ column: :attendance_sheet_entry_id
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ class RemoveCrewTimeIdFromCrew < ActiveRecord::Migration[6.0]
2
+ def change
3
+ remove_foreign_key :ecom_core_crew_times, :ecom_core_crews, column: :crew_id
4
+ remove_index :ecom_core_crew_times, name: 'ct_on_crew_indx'
5
+ remove_column :ecom_core_crew_times, :crew_id
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  module Ecom
2
2
  module Core
3
- VERSION = '1.1.8'.freeze
3
+ VERSION = '1.1.9'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :attendance_sheet_entry, class: 'Ecom::Core::AttendanceSheetEntry' do
3
+ association :attendance_sheet
4
+ association :crew
5
+ total_hours { FFaker::Random.rand(0..8) }
6
+ end
7
+ end
@@ -2,7 +2,8 @@ FactoryBot.define do
2
2
  factory :attendance_sheet, class: 'Ecom::Core::AttendanceSheet' do
3
3
  date { Date.today }
4
4
  opened_at { Time.now }
5
- closed_at { Time.now + 1 }
5
+ closed_at { nil }
6
6
  remark { FFaker::Name.name }
7
+ status { Ecom::Core::AttendanceSheet::OPEN }
7
8
  end
8
9
  end
@@ -4,10 +4,9 @@ FactoryBot.define do
4
4
  checkout_time { Time.now + 2 * 60 * 60 }
5
5
  hours { 2 }
6
6
  converted_hours { 2 }
7
- association :crew
8
7
  remark { FFaker::Name.name }
9
8
  overtime { false }
10
9
  overtime_type { nil }
11
- association :attendance_sheet
10
+ association :attendance_sheet_entry
12
11
  end
13
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecom_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.8
4
+ version: 1.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
@@ -217,6 +217,7 @@ files:
217
217
  - app/models/ecom/core/application_module.rb
218
218
  - app/models/ecom/core/application_record.rb
219
219
  - app/models/ecom/core/attendance_sheet.rb
220
+ - app/models/ecom/core/attendance_sheet_entry.rb
220
221
  - app/models/ecom/core/crew.rb
221
222
  - app/models/ecom/core/crew_time.rb
222
223
  - app/models/ecom/core/crew_type.rb
@@ -298,14 +299,17 @@ files:
298
299
  - db/migrate/20200315160810_create_ecom_core_equipment_valuations.rb
299
300
  - db/migrate/20200316125323_create_ecom_core_equipment_components.rb
300
301
  - db/migrate/20200401040433_create_ecom_core_attendance_sheets.rb
301
- - db/migrate/20200401043014_link_crew_times_with_attendance_sheet.rb
302
302
  - db/migrate/20200401071343_remove_date_column_from_crew_times.rb
303
+ - db/migrate/20200401122539_create_ecom_core_attendance_sheet_entries.rb
304
+ - db/migrate/20200401142959_relate_crew_time_with_attendance_sheet_entry.rb
305
+ - db/migrate/20200401144137_remove_crew_time_id_from_crew.rb
303
306
  - lib/ecom/core.rb
304
307
  - lib/ecom/core/engine.rb
305
308
  - lib/ecom/core/version.rb
306
309
  - lib/ecom_core.rb
307
310
  - lib/tasks/ecom_core_tasks.rake
308
311
  - spec/factories/ecom/core/application_modules.rb
312
+ - spec/factories/ecom/core/attendance_sheet_entries.rb
309
313
  - spec/factories/ecom/core/attendance_sheets.rb
310
314
  - spec/factories/ecom/core/crew_times.rb
311
315
  - spec/factories/ecom/core/crew_types.rb
@@ -1,10 +0,0 @@
1
- class LinkCrewTimesWithAttendanceSheet < ActiveRecord::Migration[6.0]
2
- def up
3
- add_column :ecom_core_crew_times, :attendance_sheet_id, :integer, index: { name: 'ct_on_as_indx' }
4
- add_foreign_key :ecom_core_crew_times, :ecom_core_attendance_sheets, column: :attendance_sheet_id
5
- end
6
-
7
- def down
8
- raise ActiveRecord::IrreversibleMigration
9
- end
10
- end