Linked Workers to the Employer Details show view
This commit is contained in:
parent
85dd95b5e1
commit
3f9358997b
|
@ -8,7 +8,7 @@ class EmployersController < ApplicationController
|
|||
|
||||
# GET /employers/:id
|
||||
def show
|
||||
@employer = Employer.includes(:employer_records, :participants).find(params[:id])
|
||||
@employer = Employer.includes(:employer_records, :direct_participants).find(params[:id])
|
||||
@employer_records = @employer.employer_records.includes(:participant)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
class Employer < ApplicationRecord
|
||||
has_many :participants
|
||||
has_many :workers, through: :participants
|
||||
has_many :employer_records
|
||||
has_many :participants, through: :employer_records
|
||||
# Direct association with participants
|
||||
has_many :direct_participants, class_name: 'Participant'
|
||||
|
||||
# Association with Vendor if needed
|
||||
# Association through EmployerRecord
|
||||
has_many :employer_records
|
||||
has_many :indirect_participants, through: :employer_records, source: :participant
|
||||
|
||||
def full_name
|
||||
"#{first_name} #{last_name}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Association with Workers through direct_participants
|
||||
has_many :workers, through: :direct_participants
|
||||
|
||||
# Other methods...
|
||||
end
|
||||
|
|
|
@ -54,15 +54,14 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container mt-5">
|
||||
<!-- Employer Details ... -->
|
||||
|
||||
<!-- Linked Participants Section -->
|
||||
<div class="row mt-4">
|
||||
<div class="col-md-12">
|
||||
<h2 class="mt-4">Linked Participants</h2>
|
||||
<% if @employer.employer_records.any? %>
|
||||
<table class="table table-striped">
|
||||
<div class="container mt-5">
|
||||
<div class="row">
|
||||
<!-- Linked Participants Section -->
|
||||
<div class="col-md-6">
|
||||
<h2 class="mt-4">Linked Participants</h2>
|
||||
<% if @employer.employer_records.any? %>
|
||||
<table class="table table-striped">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Participant Name</th>
|
||||
|
@ -72,29 +71,69 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @employer.employer_records.each do |employer_record| %>
|
||||
<tr>
|
||||
<% participant = employer_record.participant %>
|
||||
<td><%= "#{participant.first_name} #{participant.last_name}" %></td>
|
||||
<td><%= employer_record.start_date.strftime('%B %d, %Y') if employer_record.start_date %></td>
|
||||
<td><%= employer_record.end_date.strftime('%B %d, %Y') if employer_record.end_date %></td>
|
||||
<td>
|
||||
<%= link_to participant_path(participant), class: 'btn btn-sm btn-secondary' do %>
|
||||
<i class="bi bi-eye"></i> <!-- Eyeball icon for 'Show' -->
|
||||
<% end %>
|
||||
<%= link_to edit_employer_record_path(employer_record), class: 'btn btn-sm btn-info' do %>
|
||||
<i class="bi bi-pencil-fill" style="color: white;"></i> <!-- Pencil icon for 'Edit' with white color -->
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% @employer.employer_records.each do |employer_record| %>
|
||||
<tr>
|
||||
<% participant = employer_record.participant %>
|
||||
<td><%= "#{participant.first_name} #{participant.last_name}" %></td>
|
||||
<td><%= employer_record.start_date.strftime('%B %d, %Y') if employer_record.start_date %></td>
|
||||
<td><%= employer_record.end_date.strftime('%B %d, %Y') if employer_record.end_date %></td>
|
||||
<td>
|
||||
<%= link_to participant_path(participant), class: 'btn btn-sm btn-secondary' do %>
|
||||
<i class="bi bi-eye"></i> <!-- Eyeball icon for 'Show' -->
|
||||
<% end %>
|
||||
<%= link_to edit_employer_record_path(employer_record), class: 'btn btn-sm btn-info' do %>
|
||||
<i class="bi bi-pencil-fill" style="color: white;"></i> <!-- Pencil icon for 'Edit' with white color -->
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p>No linked participants.</p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<h2 class="mt-4">Linked Workers</h2>
|
||||
<% if @employer.workers.any? %>
|
||||
<table class="table table-striped">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Worker Name</th>
|
||||
<th>Start Date</th>
|
||||
<th>End Date</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @employer.workers.each do |worker| %>
|
||||
<% worker.employments.joins(:participant).where(participants: { employer_id: @employer.id }).each do |employment| %>
|
||||
<tr>
|
||||
<td><%= worker.full_name %></td>
|
||||
<td><%= employment.start_date.strftime('%B %d, %Y') if employment.start_date %></td>
|
||||
<td><%= employment.end_date.strftime('%B %d, %Y') if employment.end_date %></td>
|
||||
<td>
|
||||
<%= link_to worker_path(worker), class: 'btn btn-sm btn-secondary' do %>
|
||||
<i class="bi bi-eye"></i> <!-- Eyeball icon for 'Show' -->
|
||||
<% end %>
|
||||
<%= link_to edit_employment_path(employment), class: 'btn btn-sm btn-info' do %>
|
||||
<i class="bi bi-pencil-fill" style="color: white;"></i> <!-- Pencil icon for 'Edit' with white color -->
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p>No linked workers.</p>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue