ecom_core 1.2.19 → 1.2.24

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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/ecom/core/attendance_sheet.rb +18 -2
  3. data/app/models/ecom/core/company.rb +23 -0
  4. data/app/models/ecom/core/crew.rb +1 -0
  5. data/app/models/ecom/core/overtime_sheet.rb +16 -0
  6. data/app/models/ecom/core/payment.rb +2 -0
  7. data/app/models/ecom/core/payroll.rb +10 -0
  8. data/app/uploaders/ecom/core/photo_uploader.rb +15 -0
  9. data/db/migrate/20190101085530_create_ecom_core_companies.rb +1 -1
  10. data/db/migrate/20191225100054_create_ecom_core_crews.rb +1 -0
  11. data/db/migrate/20191225140433_create_ecom_core_attendance_sheets.rb +3 -2
  12. data/db/migrate/20200410090701_create_ecom_core_overtime_sheets.rb +3 -2
  13. data/lib/ecom/core/version.rb +1 -1
  14. data/lib/ecom_core.rb +2 -0
  15. data/spec/factories/ecom/core/application_modules.rb +3 -1
  16. data/spec/factories/ecom/core/attendance_sheets.rb +3 -2
  17. data/spec/factories/ecom/core/companies.rb +9 -1
  18. data/spec/factories/ecom/core/crews.rb +1 -0
  19. data/spec/factories/ecom/core/currencies.rb +6 -2
  20. data/spec/factories/ecom/core/equipment.rb +3 -1
  21. data/spec/factories/ecom/core/equipment_categories.rb +3 -1
  22. data/spec/factories/ecom/core/equipment_locations.rb +3 -1
  23. data/spec/factories/ecom/core/lookups.rb +3 -1
  24. data/spec/factories/ecom/core/overtime_sheets.rb +3 -2
  25. data/spec/factories/ecom/core/overtime_types.rb +3 -1
  26. data/spec/factories/ecom/core/product_groups.rb +3 -1
  27. data/spec/factories/ecom/core/product_types.rb +3 -1
  28. data/spec/factories/ecom/core/resource_types.rb +3 -1
  29. data/spec/factories/ecom/core/stakeholder_types.rb +3 -1
  30. data/spec/factories/ecom/core/stakeholders.rb +3 -1
  31. metadata +51 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dec564e431b435c4775432757843f7d46c2c98d0c3858bb783e8325b630ba84f
4
- data.tar.gz: 6831882fb350c6d92d1324a7f6d3fcf6a95ec334af3b551b11b6e24c93c29c75
3
+ metadata.gz: df898073d93a47b62e3478402f39348fb1ebce76fcb15247cbaae48b1f20da8b
4
+ data.tar.gz: 9b0e8f96058c4fcb320e42f4559c7f6ad951414935f8ad369e0d1b3f6cdd4f80
5
5
  SHA512:
6
- metadata.gz: a9043260a84f6ad95cb2e3ba02329f50bb60a98159b143e58db19c5273bacc1d15d6df538ee460ded92e519071741ac32e6003ec29ae659548109d806ea50d36
7
- data.tar.gz: 0e280d833e3b19ce2c87ec29f3d7880e20d015e712c289c027785c885bb8b3b601e8347ecf1290ac26bd14c5b7ccc8cae7fbbc2ecb911b3ef0f2cd97d03f87ba
6
+ metadata.gz: 79e71c70e77d0dfdb3b13141f2be198fe8ab989293af0b7cb82b1bcb661d1a8b9f1b6604a50074c7a8c8d992e9db618720c4520702237b8b280215c4209b57c0
7
+ data.tar.gz: 5d881608dee92bd62f78e777d2b4eadeadcf80faa89852c9d1af820ff900fd373b812a4763a80949d6eec6a5bbeb17ac256404f2b7a729b6dfef63431f9a3761
@@ -61,7 +61,7 @@ module Ecom
61
61
 
62
62
  raise 'There is no open attendance sheet to submit.' if sheet.nil?
63
63
 
64
- sheet.closed_at = Time.now
64
+ sheet.submitted_at = DateTime.now
65
65
  sheet.status = StatusConstants::SUBMITTED
66
66
  sheet.save
67
67
  sheet
@@ -75,11 +75,27 @@ module Ecom
75
75
  sheet = AttendanceSheet.open_for_date(date, project_id)
76
76
  raise 'There is no open attendance sheet to submit for the selected day.' unless sheet
77
77
 
78
- sheet.closed_at = Time.now
78
+ sheet.submitted_at = DateTime.now
79
79
  sheet.status = StatusConstants::SUBMITTED
80
80
  sheet.save
81
81
  sheet
82
82
  end
83
+
84
+ def submit
85
+ raise 'Attendance sheet is not open and cannot be submitted' if status != StatusConstants::OPEN
86
+
87
+ self.submitted_at = DateTime.now
88
+ self.status = StatusConstants::SUBMITTED
89
+ save
90
+ end
91
+
92
+ def approve
93
+ raise 'Attendance sheet is not submitted and cannot be approved' unless status == StatusConstants::SUBMITTED
94
+
95
+ self.status = StatusConstants::APPROVED
96
+ self.approved_at = DateTime.now
97
+ save
98
+ end
83
99
  end
84
100
  end
85
101
  end
@@ -1,10 +1,33 @@
1
1
  module Ecom
2
2
  module Core
3
3
  class Company < ApplicationRecord
4
+ # The settings attribute is a json string containing setting key value
5
+ # pairs. The valid settings are:
6
+ # payroll_periods => a list of payroll period values. Each
7
+ # payroll period has the following entries:
8
+ # order: A numeric value indicating the order of the period.
9
+ # date: A numeric value indicating the date of each month which
10
+ # upto which timesheet data is used for payroll calculation
11
+ # for the specific period.
12
+ # comparison: One of [:exact, :days_before_month_end]. :exact will
13
+ # force calculations to be made upto the exact mentioned date
14
+ # value, whereas :days_before_month_end is often used for last
15
+ # period payroll calculation and we want to specify on which date
16
+ # before the end of the month we have to limit timesheet data to
17
+ # calculate payroll. E.g. 3 days before month end would be 27th
18
+ # for september and 28th for october.
19
+ #
20
+ # period_count - the total number of periods per month for payroll.
21
+ # this value should align with the defined payroll periods.
22
+ #
4
23
  has_many :projects
5
24
 
6
25
  validates :code, :name, :address, :telephone, presence: true
7
26
  validates :code, :name, uniqueness: true
27
+
28
+ def valid_settings?
29
+ settings['payroll_periods'].count == settings['period_count']
30
+ end
8
31
  end
9
32
  end
10
33
  end
@@ -1,6 +1,7 @@
1
1
  module Ecom
2
2
  module Core
3
3
  class Crew < ApplicationRecord
4
+ mount_base64_uploader :photo, PhotoUploader
4
5
  PERMANENT = 'Permanent'.freeze
5
6
  SUPERVISOR = 'Supervisor'.freeze
6
7
  TEMPORARY = 'Temporary'.freeze
@@ -44,6 +44,22 @@ module Ecom
44
44
 
45
45
  OvertimeSheet.create(date: date, opened_at: Time.now, status: StatusConstants::OPEN, project_id: project_id)
46
46
  end
47
+
48
+ def submit
49
+ raise 'Overtime sheet is not open and cannot be submitted' if status != StatusConstants::OPEN
50
+
51
+ self.submitted_at = DateTime.now
52
+ self.status = StatusConstants::SUBMITTED
53
+ save
54
+ end
55
+
56
+ def approve
57
+ raise 'Overtime sheet is not submitted and cannot be approved' unless status == StatusConstants::SUBMITTED
58
+
59
+ self.status = StatusConstants::APPROVED
60
+ self.approved_at = DateTime.now
61
+ save
62
+ end
47
63
  end
48
64
  end
49
65
  end
@@ -7,6 +7,8 @@ module Ecom
7
7
 
8
8
  before_validation :set_payment_order
9
9
 
10
+ scope :by_status, ->(status) { where(approved: status) }
11
+
10
12
  def set_payment_order
11
13
  unless payroll
12
14
  self.payment_order = 1
@@ -9,6 +9,16 @@ module Ecom
9
9
  scope :by_project, ->(id) { where(project_id: id) }
10
10
  scope :by_month, ->(month) { where(month: month) }
11
11
  scope :by_year, ->(year) { where(year: year) }
12
+
13
+ def create_next
14
+ m = month + 1
15
+ y = year
16
+ if m > 12
17
+ m = 1
18
+ y += 1
19
+ end
20
+ Payroll.create(month: m, year: y, project_id: project_id)
21
+ end
12
22
  end
13
23
  end
14
24
  end
@@ -0,0 +1,15 @@
1
+ module Ecom
2
+ module Core
3
+ class PhotoUploader < CarrierWave::Uploader::Base
4
+ storage :file
5
+
6
+ def store_dir
7
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
8
+ end
9
+
10
+ def extension_whitelist
11
+ %w[jpg jpeg gif png]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -6,7 +6,7 @@ class CreateEcomCoreCompanies < ActiveRecord::Migration[6.0]
6
6
  t.string :address, null: false
7
7
  t.string :telephone, null: false
8
8
  t.string :email
9
- t.json :settings
9
+ t.jsonb :settings, default: {}
10
10
 
11
11
  t.timestamps
12
12
  end
@@ -12,6 +12,7 @@ class CreateEcomCoreCrews < ActiveRecord::Migration[6.0]
12
12
  t.string :wage_in_words, null: false
13
13
  t.date :employment_date
14
14
  t.boolean :sub_contracted, null: false, default: false
15
+ t.string :photo
15
16
  t.string :guarantor_name
16
17
  t.string :guarantor_phone
17
18
  t.boolean :active, null: false, default: true
@@ -2,8 +2,9 @@ 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
5
- t.time :opened_at, null: false
6
- t.time :closed_at
5
+ t.datetime :opened_at, null: false
6
+ t.datetime :submitted_at
7
+ t.datetime :approved_at
7
8
  t.string :remark
8
9
  t.string :status, null: false, default: 'Open'
9
10
  t.references :project,
@@ -2,8 +2,9 @@ class CreateEcomCoreOvertimeSheets < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  create_table :ecom_core_overtime_sheets do |t|
4
4
  t.date :date, null: false
5
- t.time :opened_at, null: false
6
- t.time :submitted_at
5
+ t.datetime :opened_at, null: false
6
+ t.datetime :submitted_at
7
+ t.datetime :approved_at
7
8
  t.string :remark
8
9
  t.string :status, null: false, default: 'Open'
9
10
  t.references :project,
@@ -1,5 +1,5 @@
1
1
  module Ecom
2
2
  module Core
3
- VERSION = '1.2.19'.freeze
3
+ VERSION = '1.2.24'.freeze
4
4
  end
5
5
  end
@@ -3,3 +3,5 @@ require 'ecom/core/engine'
3
3
  require 'ancestry'
4
4
  require 'aasm'
5
5
  require 'active_model_serializers'
6
+ require 'carrierwave'
7
+ require 'carrierwave/base64'
@@ -3,6 +3,8 @@ FactoryBot.define do
3
3
  sequence :code do |n|
4
4
  "AMCode#{n}"
5
5
  end
6
- name { FFaker::Name.name }
6
+ sequence :name do |n|
7
+ "AMName#{n}"
8
+ end
7
9
  end
8
10
  end
@@ -1,8 +1,9 @@
1
1
  FactoryBot.define do
2
2
  factory :attendance_sheet, class: Ecom::Core::AttendanceSheet do
3
3
  date { Date.today }
4
- opened_at { Time.now }
5
- closed_at { nil }
4
+ opened_at { DateTime.now }
5
+ submitted_at { nil }
6
+ approved_at { nil }
6
7
  remark { FFaker::Name.name }
7
8
  status { Ecom::Core::StatusConstants::OPEN }
8
9
  association :project
@@ -3,9 +3,17 @@ FactoryBot.define do
3
3
  sequence :code do |n|
4
4
  "CCode#{n}"
5
5
  end
6
- name { FFaker::Name.name }
6
+ sequence :name do |n|
7
+ "CName#{n}"
8
+ end
7
9
  address { FFaker::Address.street_address }
8
10
  telephone { FFaker::PhoneNumber.phone_number }
9
11
  email { FFaker::Internet.email }
12
+ settings do
13
+ {
14
+ payroll_periods: [{ order: 1, date: 25, comparison: :exact }],
15
+ period_count: 1
16
+ }
17
+ end
10
18
  end
11
19
  end
@@ -10,6 +10,7 @@ FactoryBot.define do
10
10
  wage_in_words { FFaker::Name.name }
11
11
  employment_date { Date.today - 1 }
12
12
  sub_contracted { false }
13
+ photo { FFaker::Name.name }
13
14
  guarantor_name { FFaker::Name.name }
14
15
  guarantor_phone { FFaker::Name.name }
15
16
  active { true }
@@ -1,6 +1,10 @@
1
1
  FactoryBot.define do
2
2
  factory :currency, class: Ecom::Core::Currency do
3
- code { FFaker::Currency.code }
4
- name { FFaker::Currency.name }
3
+ sequence :code do |n|
4
+ "CCode#{n}"
5
+ end
6
+ sequence :name do |n|
7
+ "CName#{n}"
8
+ end
5
9
  end
6
10
  end
@@ -1,6 +1,8 @@
1
1
  FactoryBot.define do
2
2
  factory :equipment, class: Ecom::Core::Equipment do
3
- name { FFaker::Name.name }
3
+ sequence :name do |n|
4
+ "EQName#{n}"
5
+ end
4
6
  description { FFaker::Name.name }
5
7
  minimum_acquisition_time { 10 }
6
8
  brands { ['Brand I', 'Brand II', 'Brand III'] }
@@ -1,6 +1,8 @@
1
1
  FactoryBot.define do
2
2
  factory :equipment_category, class: Ecom::Core::EquipmentCategory do
3
- name { FFaker::Name.name }
3
+ sequence :name do |n|
4
+ "ECName#{n}"
5
+ end
4
6
  description { FFaker::Name.name }
5
7
  association :equipment_type
6
8
  end
@@ -1,6 +1,8 @@
1
1
  FactoryBot.define do
2
2
  factory :equipment_location, class: Ecom::Core::EquipmentLocation do
3
- name { FFaker::Name.name }
3
+ sequence :name do |n|
4
+ "ELName#{n}"
5
+ end
4
6
  description { FFaker::Name.name }
5
7
  address { FFaker::Name.name }
6
8
  association :location_type
@@ -1,6 +1,8 @@
1
1
  FactoryBot.define do
2
2
  factory :lookup, class: Ecom::Core::Lookup do
3
- name { FFaker::Name.name }
3
+ sequence :name do |n|
4
+ "LName#{n}"
5
+ end
4
6
  type { 'Ecom::Core::Lookup' }
5
7
  end
6
8
  end
@@ -1,8 +1,9 @@
1
1
  FactoryBot.define do
2
2
  factory :overtime_sheet, class: Ecom::Core::OvertimeSheet do
3
3
  date { Date.today }
4
- opened_at { Time.now }
5
- submitted_at { Time.now + 1.day }
4
+ opened_at { DateTime.now }
5
+ submitted_at { nil }
6
+ approved_at { nil }
6
7
  status { Ecom::Core::StatusConstants::OPEN }
7
8
  association :project
8
9
  end
@@ -1,6 +1,8 @@
1
1
  FactoryBot.define do
2
2
  factory :overtime_type, class: Ecom::Core::OvertimeType do
3
- name { FFaker::Name.name }
3
+ sequence :name do |n|
4
+ "OTName#{n}"
5
+ end
4
6
  from { '07:00 AM' }
5
7
  to { '08:00 AM' }
6
8
  rate { 1.5 }
@@ -1,6 +1,8 @@
1
1
  FactoryBot.define do
2
2
  factory :product_group, class: Ecom::Core::ProductGroup do
3
- name { FFaker::Name.name }
3
+ sequence :name do |n|
4
+ "PGName#{n}"
5
+ end
4
6
  association :project
5
7
  end
6
8
  end
@@ -1,6 +1,8 @@
1
1
  FactoryBot.define do
2
2
  factory :product_type, class: Ecom::Core::ProductType do
3
- name { FFaker::Name.name }
3
+ sequence :name do |n|
4
+ "PTname#{n}"
5
+ end
4
6
  association :work_product_template
5
7
  dimension { [{ name: 'length', label: 'length' }, { name: 'width', label: 'width' }] }
6
8
  end
@@ -3,7 +3,9 @@ FactoryBot.define do
3
3
  sequence :code do |n|
4
4
  "RTCode#{n}"
5
5
  end
6
- name { FFaker::Name.name }
6
+ sequence :name do |n|
7
+ "RTName#{n}"
8
+ end
7
9
  base_unit { FFaker::Name.name }
8
10
  type { 'Ecom::Core::CrewType' }
9
11
  end
@@ -1,5 +1,7 @@
1
1
  FactoryBot.define do
2
2
  factory :stakeholder_type, class: Ecom::Core::StakeholderType do
3
- name { FFaker::Name.name }
3
+ sequence :name do |n|
4
+ "STName#{n}"
5
+ end
4
6
  end
5
7
  end
@@ -1,6 +1,8 @@
1
1
  FactoryBot.define do
2
2
  factory :stakeholder, class: Ecom::Core::Stakeholder do
3
- name { FFaker::Name.unique.name }
3
+ sequence :name do |n|
4
+ "Stakeholder #{n}"
5
+ end
4
6
  type_of_business { FFaker::Name.name }
5
7
  address { FFaker::Name.name }
6
8
  license_no { FFaker::Name.name }
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.19
4
+ version: 1.2.24
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-07-21 00:00:00.000000000 Z
11
+ date: 2020-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aasm
@@ -38,6 +38,26 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.10.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: after_commit_everywhere
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 0.1.5
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '0.1'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.1.5
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: ancestry
43
63
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +86,34 @@ dependencies:
66
86
  - - ">="
67
87
  - !ruby/object:Gem::Version
68
88
  version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: carrierwave
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: carrierwave-base64
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
69
117
  - !ruby/object:Gem::Dependency
70
118
  name: jwt
71
119
  requirement: !ruby/object:Gem::Requirement
@@ -258,6 +306,7 @@ files:
258
306
  - app/serializers/ecom/core/user_serializer.rb
259
307
  - app/services/ecom/core/menu_service.rb
260
308
  - app/services/ecom/core/token_auth_service.rb
309
+ - app/uploaders/ecom/core/photo_uploader.rb
261
310
  - app/validators/ecom/core/date_range_validator.rb
262
311
  - config/database.ci.yml
263
312
  - config/routes.rb