ecom_core 1.1.13 → 1.1.18

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: 83f559494c6d48cedb7b001a97bb4b5b2cdaa7258bcee099c8e04d2c7f3c65c7
4
- data.tar.gz: e654ac874380e80a456bb1dcf9c144c629eb46877f05836b683079b3851d2fc8
3
+ metadata.gz: cbaba2b0f521af3d18d5636be2e3be40c6de15aa9f3951b5c3d8b57bdc634e83
4
+ data.tar.gz: 24ab07446617733ce416002684e0565f4bb04e66ad0a30d0b28d1f1cd79cf9a2
5
5
  SHA512:
6
- metadata.gz: dc5caae19f7c33dea9d4c20a084c987857047d1d63b77afaa1a213612eac3e5c76923cc2be464564050a7b5c8e1fb35a82961fd5d6216bd3f05bc7cd09aee5f6
7
- data.tar.gz: 51b882441cf2b6ff81b0028a0e688fe583297ade03b795dd8009f6f20f6a2b7c0c1bb9a5dee7e17cd2d934ae497add907147c6ed6db8b195a4f83c780f9859a8
6
+ metadata.gz: 88dc9269297366e77f415c768da3bb457414b57143f3aef34df98cbbc3923ac7a125f4bec6005f0f46ff071a64dfabb2295c91931b1033ad872f02cfc5100e04
7
+ data.tar.gz: cec52dafb2589e7711300bd0322425be7c670ee83bc440def6f26ee6663f10edf6fd1b4231327e28603e9e6bcea95e09e1635c6ce97dda774f69cdea736f58e7
@@ -2,22 +2,32 @@ module Ecom
2
2
  module Core
3
3
  class AttendanceSheet < ApplicationRecord
4
4
  OPEN = 'Open'.freeze
5
- CLOSED = 'Closed'.freeze
5
+ SUBMITTED = 'Submitted'.freeze
6
+ APPROVED = 'Approved'.freeze
6
7
 
7
8
  validates :date, :opened_at, presence: true, uniqueness: true
8
- validates :status, inclusion: [OPEN, CLOSED]
9
+ validates :status, inclusion: [OPEN, SUBMITTED, APPROVED]
9
10
 
10
11
  has_many :attendance_sheet_entries
11
12
 
12
- scope :open, -> { find_by(status: OPEN) }
13
- scope :current_open, -> { where(status: OPEN, date: Date.today) }
13
+ scope :open, -> { where(status: OPEN) }
14
+ scope :current, -> { where(date: Date.today) }
15
+ scope :current_open, -> { open.current }
16
+
17
+ def self.open_for_date(date)
18
+ AttendanceSheet.find_by(status: OPEN, date: date)
19
+ end
20
+
21
+ def self.open_exists?
22
+ AttendanceSheet.open.exists?
23
+ end
14
24
 
15
25
  def self.exists_for_today?
16
- AttendanceSheet.where(date: Date.today).exists?
26
+ AttendanceSheet.current.exists?
17
27
  end
18
28
 
19
29
  def self.open_exists_for_today?
20
- where(status: OPEN, date: Date.today).exists?
30
+ AttendanceSheet.current_open.exists?
21
31
  end
22
32
 
23
33
  # Attendance sheet should be created using the
@@ -28,29 +38,32 @@ module Ecom
28
38
  def self.create_current
29
39
  raise 'Attendance sheet already created for the day.' if AttendanceSheet.exists_for_today?
30
40
 
41
+ raise 'There is an open attendance sheet which needs to be submitted before creating a new one.' if AttendanceSheet.open_exists?
42
+
31
43
  AttendanceSheet.create(date: Date.today, opened_at: Time.now, status: OPEN)
32
44
  end
33
45
 
34
- def self.close_current
46
+ def self.submit_current
35
47
  sheet = AttendanceSheet.find_by(date: Date.today, status: OPEN)
36
48
 
37
- raise 'There is no attendance sheet to close.' if sheet.nil?
49
+ raise 'There is no open attendance sheet to submit.' if sheet.nil?
38
50
 
39
51
  sheet.closed_at = Time.now
40
- sheet.status = CLOSED
52
+ sheet.status = SUBMITTED
41
53
  sheet.save
42
54
  sheet
43
55
  end
44
56
 
45
57
  # This method should be used by privileged users
46
- # to close the attendance sheet after the date has
58
+ # to submit the attendance sheet after the date has
47
59
  # passed. Normally, timekeepers need to open and close
48
60
  # an attendance sheet of a date on the specific date.
49
- def self.close
50
- raise 'There is no attendance sheet to close.' unless AttendanceSheet.open_exists_for_today?
61
+ def self.submit(date)
62
+ sheet = AttendanceSheet.open_for_date(date)
63
+ raise 'There is no open attendance sheet to submit for the selected day.' unless sheet
51
64
 
52
- sheet = AttendanceSheet.open
53
65
  sheet.closed_at = Time.now
66
+ sheet.status = SUBMITTED
54
67
  sheet.save
55
68
  sheet
56
69
  end
@@ -0,0 +1,21 @@
1
+ module Ecom
2
+ module Core
3
+ class CrewOvertime < ApplicationRecord
4
+ belongs_to :overtime_type
5
+ belongs_to :overtime_sheet_entry
6
+ belongs_to :revision_to, class_name: 'Ecom::Core::CrewOvertime', optional: true
7
+ belongs_to :created_by, class_name: 'Ecom::Core::User'
8
+
9
+ has_one :revision, class_name: 'Ecom::Core::CrewOvertime', foreign_key: :revision_to_id
10
+
11
+ validates :hours, :converted_hours, presence: true
12
+
13
+ before_save :calculate_converted_hours
14
+
15
+ def calculate_converted_hours
16
+ rate = OvertimeType.find(overtime_type_id).rate
17
+ self.converted_hours = hours * rate
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,42 @@
1
+ module Ecom
2
+ module Core
3
+ class OvertimeSheet < ApplicationRecord
4
+ OPEN = 'Open'.freeze
5
+ SUBMITTED = 'Submitted'.freeze
6
+ APPROVED = 'Approved'.freeze
7
+
8
+ validates :date, :opened_at, presence: true, uniqueness: true
9
+ validates :status, inclusion: [OPEN, SUBMITTED, APPROVED]
10
+
11
+ has_many :overtime_sheet_entries
12
+
13
+ scope :open, -> { where(status: OPEN) }
14
+ scope :for_date, ->(date) { where(date: date) }
15
+
16
+ def self.open_exists?
17
+ OvertimeSheet.open.exists?
18
+ end
19
+
20
+ def self.open_for_date_exists?(date)
21
+ OvertimeSheet.open.for_date(date).exists?
22
+ end
23
+
24
+ # Overtime sheet should be created using the
25
+ # method below only. This is because we need to
26
+ # check if there is an open overtime already,
27
+ # and also that we have only one open overtime
28
+ # sheet at a time.
29
+ def self.create_new(date)
30
+ if OvertimeSheet.open_for_date_exists?(date)
31
+ raise 'There is already an open overtime sheet for the selected date.'
32
+ end
33
+
34
+ if OvertimeSheet.open_exists?
35
+ raise 'There is already an open overtime sheet. It has to be submitted before creating a new one.'
36
+ end
37
+
38
+ OvertimeSheet.create(date: date, opened_at: Time.now, status: OPEN)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,9 @@
1
+ module Ecom
2
+ module Core
3
+ class OvertimeSheetEntry < ApplicationRecord
4
+ belongs_to :overtime_sheet
5
+ belongs_to :crew
6
+ has_many :crew_overtimes
7
+ end
8
+ end
9
+ end
@@ -6,7 +6,7 @@ module Ecom
6
6
  has_and_belongs_to_many :user_roles, join_table: 'ecom_core_users_user_roles'
7
7
 
8
8
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i.freeze
9
- validates :first_name, :last_name, :active, presence: true
9
+ validates :first_name, :last_name, presence: true
10
10
  validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false }
11
11
  validates :password, presence: true, length: { minimum: 6 }, confirmation: true, if: :password
12
12
 
@@ -9,19 +9,16 @@ module Ecom
9
9
  SQL
10
10
  menu = Menu.joins(join_sql).where('UR.id IN (?)', role_ids).distinct
11
11
  menu_list = menu.select { |m| m.parent.nil? }.each_with_object([]) do |item, list|
12
- list << { id: item.id, label: item.label, icon: item.icon, items: [] }
12
+ list << { id: item.id, label: item.label, icon: item.icon, children: [] }
13
13
  end
14
14
 
15
15
  menu_list.each do |ml|
16
- ml[:items] = menu.reject { |m| m.parent.nil? }.each_with_object([]) do |item, list|
16
+ ml[:children] = menu.reject { |m| m.parent.nil? }.each_with_object([]) do |item, list|
17
17
  if item.parent_id == ml[:id]
18
18
  list << { id: item.id, label: item.label, icon: item.icon, route: item.route }
19
19
  end
20
20
  end
21
21
  end
22
-
23
- # Remove id key
24
- menu_list.map { |ml| ml.delete(:id) }
25
22
  menu_list
26
23
  end
27
24
  end
@@ -0,0 +1,12 @@
1
+ class CreateEcomCoreOvertimeSheets < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_overtime_sheets do |t|
4
+ t.date :date, null: false, unique: true
5
+ t.time :opened_at, null: false
6
+ t.time :submitted_at
7
+ t.string :status, null: false, default: 'Open'
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ class CreateEcomCoreOvertimeSheetEntries < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_overtime_sheet_entries do |t|
4
+ t.references :overtime_sheet, null: false, index: { name: 'ose_on_os_indx' }
5
+ t.references :crew, null: false, index: { name: 'ose_on_crew_indx' }
6
+ t.float :total_overtime
7
+
8
+ t.timestamps
9
+ end
10
+ add_foreign_key :ecom_core_overtime_sheet_entries, :ecom_core_overtime_sheets,
11
+ column: :overtime_sheet_id
12
+ add_foreign_key :ecom_core_overtime_sheet_entries, :ecom_core_crews, column: :crew_id
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ class CreateEcomCoreCrewOvertimes < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_crew_overtimes do |t|
4
+ t.float :hours, null: false
5
+ t.float :converted_hours, null: false, default: 0
6
+ t.string :remark
7
+ t.references :overtime_type, null: false, index: { name: 'ot_on_co_indx' }
8
+ t.references :overtime_sheet_entry, null: false, index: { name: 'ose_on_co_indx' }
9
+ t.boolean :revised, null: false, default: false
10
+ t.references :revision_to, null: true
11
+ t.references :created_by, null: false, index: { name: 'cb_on_co_indx' }
12
+
13
+ t.timestamps
14
+ end
15
+ add_foreign_key :ecom_core_crew_overtimes, :ecom_core_overtime_types, column: :overtime_type_id
16
+ add_foreign_key :ecom_core_crew_overtimes, :ecom_core_overtime_sheet_entries,
17
+ column: :overtime_sheet_entry_id
18
+ add_foreign_key :ecom_core_crew_overtimes, :ecom_core_crew_overtimes, column: :revision_to_id
19
+ add_foreign_key :ecom_core_crew_overtimes, :ecom_core_users, column: :created_by_id
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  module Ecom
2
2
  module Core
3
- VERSION = '1.1.13'.freeze
3
+ VERSION = '1.1.18'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,12 @@
1
+ FactoryBot.define do
2
+ factory :crew_overtime, class: 'Ecom::Core::CrewOvertime' do
3
+ hours { 2 }
4
+ converted_hours { 2 }
5
+ remark { FFaker::Name.name }
6
+ association :overtime_type
7
+ association :overtime_sheet_entry
8
+ revised { false }
9
+ revision_to { nil }
10
+ association :created_by, factory: :user
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :overtime_sheet_entry, class: 'Ecom::Core::OvertimeSheetEntry' do
3
+ association :overtime_sheet
4
+ association :crew
5
+ total_overtime { FFaker::Random.rand(0..8) }
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :overtime_sheet, class: 'Ecom::Core::OvertimeSheet' do
3
+ date { Date.today }
4
+ opened_at { Time.now }
5
+ submitted_at { Time.now + 1.day }
6
+ status { Ecom::Core::OvertimeSheet::OPEN }
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecom_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.13
4
+ version: 1.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-04 00:00:00.000000000 Z
11
+ date: 2020-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aasm
@@ -219,6 +219,7 @@ files:
219
219
  - app/models/ecom/core/attendance_sheet.rb
220
220
  - app/models/ecom/core/attendance_sheet_entry.rb
221
221
  - app/models/ecom/core/crew.rb
222
+ - app/models/ecom/core/crew_overtime.rb
222
223
  - app/models/ecom/core/crew_time.rb
223
224
  - app/models/ecom/core/crew_type.rb
224
225
  - app/models/ecom/core/currency.rb
@@ -234,6 +235,8 @@ files:
234
235
  - app/models/ecom/core/lookup.rb
235
236
  - app/models/ecom/core/material_type.rb
236
237
  - app/models/ecom/core/menu.rb
238
+ - app/models/ecom/core/overtime_sheet.rb
239
+ - app/models/ecom/core/overtime_sheet_entry.rb
237
240
  - app/models/ecom/core/overtime_type.rb
238
241
  - app/models/ecom/core/payment.rb
239
242
  - app/models/ecom/core/payment_detail.rb
@@ -303,6 +306,9 @@ files:
303
306
  - db/migrate/20200401122539_create_ecom_core_attendance_sheet_entries.rb
304
307
  - db/migrate/20200401142959_relate_crew_time_with_attendance_sheet_entry.rb
305
308
  - db/migrate/20200401144137_remove_crew_time_id_from_crew.rb
309
+ - db/migrate/20200410090701_create_ecom_core_overtime_sheets.rb
310
+ - db/migrate/20200410100035_create_ecom_core_overtime_sheet_entries.rb
311
+ - db/migrate/20200410111827_create_ecom_core_crew_overtimes.rb
306
312
  - lib/ecom/core.rb
307
313
  - lib/ecom/core/engine.rb
308
314
  - lib/ecom/core/version.rb
@@ -311,6 +317,7 @@ files:
311
317
  - spec/factories/ecom/core/application_modules.rb
312
318
  - spec/factories/ecom/core/attendance_sheet_entries.rb
313
319
  - spec/factories/ecom/core/attendance_sheets.rb
320
+ - spec/factories/ecom/core/crew_overtimes.rb
314
321
  - spec/factories/ecom/core/crew_times.rb
315
322
  - spec/factories/ecom/core/crew_types.rb
316
323
  - spec/factories/ecom/core/crews.rb
@@ -327,6 +334,8 @@ files:
327
334
  - spec/factories/ecom/core/lookups.rb
328
335
  - spec/factories/ecom/core/material_types.rb
329
336
  - spec/factories/ecom/core/menus.rb
337
+ - spec/factories/ecom/core/overtime_sheet_entries.rb
338
+ - spec/factories/ecom/core/overtime_sheets.rb
330
339
  - spec/factories/ecom/core/overtime_types.rb
331
340
  - spec/factories/ecom/core/payment_details.rb
332
341
  - spec/factories/ecom/core/payments.rb