ecom_core 1.2.7 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8604bb41df95be804fb66c2ac48f3e1b55b8f776de07f2dee665c4704350858
4
- data.tar.gz: 30decab7dc7997c9c4a22bc2a90548c0b72a67b6648e894b6f1234c785739166
3
+ metadata.gz: 7ec4b0205003456f436aa5ec2ffc99f73d9f9dae97b5038f95b598fa259b6c66
4
+ data.tar.gz: 818efd4bff74c94646dd9fc96f99ee60f2e932e42183fbbdf240e277d9beacac
5
5
  SHA512:
6
- metadata.gz: ac72d68e86a4ff54ee5bf33d3068cf57eb44ab5038873481be623cf1eb1c461c8c65749385536e973a9909c8269e5e06a1125562ff7c14a8c9dba322257fe500
7
- data.tar.gz: 44c1ff6ddcbb054bd262ef9a0a75ab2fb6f42d4558a74afe7866c0ee451b45c577003f8c988a60e4a3e8341212451864cb4f633ffa4a6bf5d95bce1615ac7065
6
+ metadata.gz: 98e9f053543924c0b852c263d6185f5e09e8e7d5557a17835fc7e99b3d3b5f33eb26e2f4f1a4b01bad8195da0d950db9e924bb9ad4899e258c8a9393dac4fd73
7
+ data.tar.gz: ab3f72029a9386058701711220ac5884eb093385c292596d6cd4c0f34d31d71e5431b06e93df294e7e97de53db68afea0896032c0fd10ba8632d194b98532ea3
@@ -0,0 +1,11 @@
1
+ module Ecom
2
+ module Core
3
+ class StatusConstants
4
+ OPEN = 'Open'.freeze
5
+ SUBMITTED = 'Submitted'.freeze
6
+ APPROVED = 'Approved'.freeze
7
+
8
+ STATUSES = [OPEN, SUBMITTED, APPROVED].freeze
9
+ end
10
+ end
11
+ end
@@ -1,37 +1,43 @@
1
1
  module Ecom
2
2
  module Core
3
3
  class AttendanceSheet < ApplicationRecord
4
- OPEN = 'Open'.freeze
5
- SUBMITTED = 'Submitted'.freeze
6
- APPROVED = 'Approved'.freeze
7
-
8
- validates :date, presence: true, uniqueness: true
9
- validates :status, inclusion: [OPEN, SUBMITTED, APPROVED]
4
+ validates :date, presence: true, uniqueness: { scope: :project_id }
5
+ validates :status, inclusion: StatusConstants::STATUSES
10
6
 
11
7
  belongs_to :project
12
8
 
13
9
  has_many :attendance_sheet_entries
14
10
  has_many :crew_times, through: :attendance_sheet_entries
15
11
 
16
- scope :open, ->(id) { where(status: OPEN, project_id: id) }
17
- scope :submitted, ->(id) { where(status: SUBMITTED, project_id: id) }
18
- scope :current, ->(id) { where(date: Date.today, project_id: id) }
19
- scope :current_open, ->(id) { where(date: Date.today, project_id: id, status: OPEN) }
12
+ scope :by_project, ->(id) { where(project_id: id) }
13
+ scope :by_date, ->(date) { where(date: date) }
14
+ scope :by_status, ->(status) { where(status: status) }
15
+ scope :by_date_between, ->(from, to) { where('date BETWEEN ? AND ?', from, to) }
20
16
 
21
17
  def self.open_for_date(date, project_id)
22
- AttendanceSheet.find_by(status: OPEN, date: date, project_id: project_id)
18
+ AttendanceSheet.find_by(status: StatusConstants::OPEN, date: date, project_id: project_id)
23
19
  end
24
20
 
25
21
  def self.open_exists?(project_id)
26
- AttendanceSheet.open(project_id).exists?
22
+ AttendanceSheet
23
+ .by_project(project_id)
24
+ .by_status(StatusConstants::OPEN)
25
+ .exists?
27
26
  end
28
27
 
29
28
  def self.exists_for_today?(project_id)
30
- AttendanceSheet.current(project_id).exists?
29
+ AttendanceSheet
30
+ .by_project(project_id)
31
+ .by_date(Date.today)
32
+ .exists?
31
33
  end
32
34
 
33
35
  def self.open_exists_for_today?(project_id)
34
- AttendanceSheet.current_open(project_id).exists?
36
+ AttendanceSheet
37
+ .by_project(project_id)
38
+ .by_date(Date.today)
39
+ .by_status(StatusConstants::OPEN)
40
+ .exists?
35
41
  end
36
42
 
37
43
  # Attendance sheet should be created using the
@@ -46,16 +52,16 @@ module Ecom
46
52
  raise 'There is an open attendance sheet which needs to be submitted before creating a new one.'
47
53
  end
48
54
 
49
- AttendanceSheet.create(date: Date.today, opened_at: Time.now, status: OPEN, project_id: project_id)
55
+ AttendanceSheet.create(date: Date.today, opened_at: Time.now, status: StatusConstants::OPEN, project_id: project_id)
50
56
  end
51
57
 
52
58
  def self.submit_current(project_id)
53
- sheet = AttendanceSheet.find_by(date: Date.today, status: OPEN, project_id: project_id)
59
+ sheet = AttendanceSheet.find_by(date: Date.today, status: StatusConstants::OPEN, project_id: project_id)
54
60
 
55
61
  raise 'There is no open attendance sheet to submit.' if sheet.nil?
56
62
 
57
63
  sheet.closed_at = Time.now
58
- sheet.status = SUBMITTED
64
+ sheet.status = StatusConstants::SUBMITTED
59
65
  sheet.save
60
66
  sheet
61
67
  end
@@ -69,7 +75,7 @@ module Ecom
69
75
  raise 'There is no open attendance sheet to submit for the selected day.' unless sheet
70
76
 
71
77
  sheet.closed_at = Time.now
72
- sheet.status = SUBMITTED
78
+ sheet.status = StatusConstants::SUBMITTED
73
79
  sheet.save
74
80
  sheet
75
81
  end
@@ -10,6 +10,11 @@ module Ecom
10
10
 
11
11
  validates :hours, :raw_hours, presence: true
12
12
 
13
+ scope :by_overtime, lambda { |id|
14
+ joins(:overtime_sheet_entry).where(ecom_core_overtime_sheet_entries: { overtime_sheet_id: id })
15
+ }
16
+ scope :revised, ->(revised) { where(revised: revised) }
17
+
13
18
  before_save :calculate_hours
14
19
 
15
20
  def calculate_hours
@@ -7,8 +7,8 @@ module Ecom
7
7
  BOTH = 'Both'.freeze
8
8
 
9
9
  TIME_RANGE = {
10
- MORNING => {start: Time.zone.parse('5:00 AM'), end: Time.zone.parse('9:00 AM')},
11
- AFTERNOON => {start: Time.zone.parse('10:00 AM'), end: Time.zone.parse('2:00 PM')},
10
+ MORNING => { start: Time.zone.parse('5:00 AM'), end: Time.zone.parse('9:00 AM') },
11
+ AFTERNOON => { start: Time.zone.parse('10:00 AM'), end: Time.zone.parse('2:00 PM') },
12
12
  BOTH => {start: Time.zone.parse('5:00 AM'), end: Time.zone.parse('2:00 PM')}
13
13
  }.freeze
14
14
 
@@ -19,6 +19,11 @@ module Ecom
19
19
 
20
20
  validates :checkin_time, presence: true, if: :checkout_time
21
21
 
22
+ scope :by_attendance, lambda { |id|
23
+ joins(:attendance_sheet_entry).where(ecom_core_attendance_sheet_entries: { attendance_sheet_id: id })
24
+ }
25
+ scope :revised, ->(revised) { where(revised: revised) }
26
+
22
27
  before_save :calculate_hours
23
28
  after_save :calculate_total
24
29
 
@@ -1,20 +1,20 @@
1
1
  module Ecom
2
2
  module Core
3
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]
4
+ validates :date, :opened_at, presence: true, uniqueness: { scope: :project_id }
5
+ validates :status, inclusion: StatusConstants::STATUSES
10
6
 
11
7
  belongs_to :project
12
8
 
13
9
  has_many :overtime_sheet_entries
14
10
  has_many :crew_overtimes, through: :overtime_sheet_entries
15
11
 
16
- scope :open, ->(id) { where(status: OPEN, project_id: id) }
17
- scope :submitted, ->(id) { where(status: SUBMITTED, project_id: id) }
12
+ scope :by_project, ->(id) { where(project_id: id) }
13
+ scope :by_date, ->(date) { where(date: date) }
14
+ scope :by_status, ->(status) { where(status: status) }
15
+ scope :by_date_between, ->(from, to) { where('date BETWEEN ? AND ?', from, to) }
16
+ scope :open, ->(id) { where(status: StatusConstants::OPEN, project_id: id) }
17
+ scope :submitted, ->(id) { where(status: StatusConstants::SUBMITTED, project_id: id) }
18
18
 
19
19
  def self.open_exists?(project_id)
20
20
  OvertimeSheet.open(project_id).exists?
@@ -38,7 +38,7 @@ module Ecom
38
38
  raise 'There is already an open overtime sheet. It has to be submitted before creating a new one.'
39
39
  end
40
40
 
41
- OvertimeSheet.create(date: date, opened_at: Time.now, status: OPEN, project_id: project_id)
41
+ OvertimeSheet.create(date: date, opened_at: Time.now, status: StatusConstants::OPEN, project_id: project_id)
42
42
  end
43
43
  end
44
44
  end
@@ -5,6 +5,10 @@ module Ecom
5
5
 
6
6
  has_many :payments, class_name: 'Ecom::Core::Payment'
7
7
  belongs_to :project
8
+
9
+ scope :by_project, ->(id) { where(project_id: id) }
10
+ scope :by_month, ->(month) { where(month: month) }
11
+ scope :by_year, ->(year) { where(year: year) }
8
12
  end
9
13
  end
10
14
  end
@@ -1,7 +1,7 @@
1
1
  class CreateEcomCoreAttendanceSheets < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  create_table :ecom_core_attendance_sheets do |t|
4
- t.date :date, null: false, unique: true
4
+ t.date :date, null: false
5
5
  t.time :opened_at, null: false
6
6
  t.time :closed_at
7
7
  t.string :remark
@@ -13,5 +13,6 @@ class CreateEcomCoreAttendanceSheets < ActiveRecord::Migration[6.0]
13
13
 
14
14
  t.timestamps
15
15
  end
16
+ add_index :ecom_core_attendance_sheets, %i[date project_id], unique: true
16
17
  end
17
18
  end
@@ -1,9 +1,10 @@
1
1
  class CreateEcomCoreOvertimeSheets < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  create_table :ecom_core_overtime_sheets do |t|
4
- t.date :date, null: false, unique: true
4
+ t.date :date, null: false
5
5
  t.time :opened_at, null: false
6
6
  t.time :submitted_at
7
+ t.string :remark
7
8
  t.string :status, null: false, default: 'Open'
8
9
  t.references :project,
9
10
  null: false,
@@ -12,5 +13,6 @@ class CreateEcomCoreOvertimeSheets < ActiveRecord::Migration[6.0]
12
13
 
13
14
  t.timestamps
14
15
  end
16
+ add_index :ecom_core_overtime_sheets, %i[date project_id], unique: true
15
17
  end
16
18
  end
@@ -1,5 +1,5 @@
1
1
  module Ecom
2
2
  module Core
3
- VERSION = '1.2.7'.freeze
3
+ VERSION = '1.2.9'.freeze
4
4
  end
5
5
  end
@@ -4,7 +4,7 @@ FactoryBot.define do
4
4
  opened_at { Time.now }
5
5
  closed_at { nil }
6
6
  remark { FFaker::Name.name }
7
- status { Ecom::Core::AttendanceSheet::OPEN }
7
+ status { Ecom::Core::StatusConstants::OPEN }
8
8
  association :project
9
9
  end
10
10
  end
@@ -3,7 +3,7 @@ FactoryBot.define do
3
3
  date { Date.today }
4
4
  opened_at { Time.now }
5
5
  submitted_at { Time.now + 1.day }
6
- status { Ecom::Core::OvertimeSheet::OPEN }
6
+ status { Ecom::Core::StatusConstants::OPEN }
7
7
  association :project
8
8
  end
9
9
  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.2.7
4
+ version: 1.2.9
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-05-19 00:00:00.000000000 Z
11
+ date: 2020-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aasm
@@ -178,20 +178,6 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
- - !ruby/object:Gem::Dependency
182
- name: solargraph
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
181
  description: An engine which contains the core of a construction management app as
196
182
  a layer.
197
183
  email:
@@ -203,6 +189,7 @@ files:
203
189
  - MIT-LICENSE
204
190
  - README.md
205
191
  - Rakefile
192
+ - app/constants/ecom/core/status_constants.rb
206
193
  - app/controllers/concerns/ecom/core/lookupable.rb
207
194
  - app/controllers/concerns/ecom/core/resource_typeable.rb
208
195
  - app/controllers/ecom/core/access_controller.rb