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
|
||||
# Direct association with participants
|
||||
has_many :direct_participants, class_name: 'Participant'
|
||||
|
||||
# Association through EmployerRecord
|
||||
has_many :employer_records
|
||||
has_many :participants, through: :employer_records
|
||||
has_many :indirect_participants, through: :employer_records, source: :participant
|
||||
|
||||
# Association with Vendor if needed
|
||||
# Association with Workers through direct_participants
|
||||
has_many :workers, through: :direct_participants
|
||||
|
||||
def full_name
|
||||
"#{first_name} #{last_name}"
|
||||
# Other methods...
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -54,12 +54,11 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container mt-5">
|
||||
<!-- Employer Details ... -->
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row">
|
||||
<!-- Linked Participants Section -->
|
||||
<div class="row mt-4">
|
||||
<div class="col-md-12">
|
||||
<div class="col-md-6">
|
||||
<h2 class="mt-4">Linked Participants</h2>
|
||||
<% if @employer.employer_records.any? %>
|
||||
<table class="table table-striped">
|
||||
|
@ -94,7 +93,47 @@
|
|||
<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