Class: NextSgad::Department
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ApplicationRecord
- NextSgad::Department
- Defined in:
- app/models/next_sgad/department.rb
Constant Summary collapse
- INITIAL_LETTER =
"D"
Class Method Summary collapse
-
.employees_assessments_by_dep(employees_assessments) ⇒ Object
return a hash like => [EmployeeAssessmentObject] groups employee by hash.
-
.employees_by_dep ⇒ Object
return a hash like => [EmployeeObject] groups employee by hash.
-
.map_for_filter ⇒ Object
creates filter data.
-
.map_for_select ⇒ Object
creates filter data.
Instance Method Summary collapse
Methods inherited from ApplicationRecord
#create_number, #create_number!
Class Method Details
.employees_assessments_by_dep(employees_assessments) ⇒ Object
return a hash like => [EmployeeAssessmentObject] groups employee by hash
52 53 54 55 56 |
# File 'app/models/next_sgad/department.rb', line 52 def self.employees_assessments_by_dep(employees_assessments) pos_ind_by_emp = NextSgad::Position.all.index_by(&:efective_id) emp_by_dep_id = all.index_by(&:id) employees_assessments.group_by {|e| emp_by_dep_id[pos_ind_by_emp[e.employee_id]&.department_id]} end |
.employees_by_dep ⇒ Object
return a hash like => [EmployeeObject] groups employee by hash
38 39 40 41 42 |
# File 'app/models/next_sgad/department.rb', line 38 def self.employees_by_dep pos_ind_by_emp = NextSgad::Position.all.index_by(&:efective_id) emp_by_dep_id = all.index_by(&:id) NextSgad::Employee.all.group_by {|e| emp_by_dep_id[pos_ind_by_emp[e.id]&.department_id]} end |
.map_for_filter ⇒ Object
creates filter data
32 33 34 |
# File 'app/models/next_sgad/department.rb', line 32 def self.map_for_filter [[I18n.t(:everything), :all]] + all.map {|f| [f.name_and_number, f.id]} end |
.map_for_select ⇒ Object
creates filter data
27 28 29 |
# File 'app/models/next_sgad/department.rb', line 27 def self.map_for_select all.map {|f| [f.name_and_number, f.id]} end |
Instance Method Details
#all_employees_of_dep ⇒ Object
44 45 46 47 |
# File 'app/models/next_sgad/department.rb', line 44 def all_employees_of_dep positions = NextSgad::Position.where(department_id: self.id).map(&:efective_id)#all.index_by(&:efective_id) NextSgad::Employee.all.where(id: positions) #all.group_by {|e| emp_by_dep_id[pos_ind_by_emp[e.id]&.department_id]} end |
#name_and_number ⇒ Object
22 23 24 |
# File 'app/models/next_sgad/department.rb', line 22 def name_and_number "#{number} - #{name}" end |
#parent_department ⇒ Object
16 17 18 19 20 |
# File 'app/models/next_sgad/department.rb', line 16 def parent_department if department_id.present? && NextSgad::Department.find_by(id: department_id).nil? errors.add(:department_id, :no_department_found_with_this_number.ts) end end |