CRUDcommissioner
This commit is contained in:
@@ -15,6 +15,7 @@ class CommissionersController < ApplicationController
|
|||||||
# GET /commissioners/new
|
# GET /commissioners/new
|
||||||
def new
|
def new
|
||||||
@commissioner = Commissioner.new
|
@commissioner = Commissioner.new
|
||||||
|
@employee = Employee.all.order('name asc')
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /commissioners/1/edit
|
# GET /commissioners/1/edit
|
||||||
@@ -25,7 +26,7 @@ class CommissionersController < ApplicationController
|
|||||||
# POST /commissioners.json
|
# POST /commissioners.json
|
||||||
def create
|
def create
|
||||||
@commissioner = Commissioner.new(commissioner_params)
|
@commissioner = Commissioner.new(commissioner_params)
|
||||||
|
@commissioner.created_by = current_user.id
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @commissioner.save
|
if @commissioner.save
|
||||||
format.html { redirect_to @commissioner, notice: 'Commissioner was successfully created.' }
|
format.html { redirect_to @commissioner, notice: 'Commissioner was successfully created.' }
|
||||||
@@ -69,6 +70,6 @@ class CommissionersController < ApplicationController
|
|||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
def commissioner_params
|
def commissioner_params
|
||||||
params.fetch(:commissioner, {})
|
params.require(:commissioner).permit(:name,:emp_id,:created_by,:commission_type, :is_active)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
class Commissioner < ApplicationRecord
|
class Commissioner < ApplicationRecord
|
||||||
|
has_many :employees
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class Employee < ApplicationRecord
|
class Employee < ApplicationRecord
|
||||||
has_secure_password
|
has_secure_password
|
||||||
|
belongs_to :commissioner
|
||||||
has_many :shit_sales
|
has_many :shit_sales
|
||||||
validates_presence_of :name, :role
|
validates_presence_of :name, :role
|
||||||
validates_presence_of :password, :on => [:create]
|
validates_presence_of :password, :on => [:create]
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
<%= f.error_notification %>
|
<%= f.error_notification %>
|
||||||
|
|
||||||
<div class="form-inputs">
|
<div class="form-inputs">
|
||||||
|
<%= f.input :name %>
|
||||||
|
<%= f.collection_select :emp_id, Employee.all.order('name asc'), :emp_id, :name, {prompt: "Select an Employee"}, {class: "form-control"} %>
|
||||||
|
<%= f.input :commission_type %>
|
||||||
|
<label><%= f.check_box :is_active %> Active </label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
<h1>Editing Commissioner</h1>
|
<div class="span12">
|
||||||
|
<div class="page-header">
|
||||||
<%= render 'form', commissioner: @commissioner %>
|
<ul class="breadcrumb">
|
||||||
|
<li><a href="<%= root_path %>">Home</a></li>
|
||||||
<%= link_to 'Show', @commissioner %> |
|
<li><a href="<%= commissioners_path %>">Commissioners</a></li>
|
||||||
<%= link_to 'Back', commissioners_path %>
|
<li>Edit</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<%= render 'form', commissioner: @commissioner %>
|
||||||
|
</div>
|
||||||
@@ -1,25 +1,46 @@
|
|||||||
<p id="notice"><%= notice %></p>
|
<div class="page-header">
|
||||||
|
<ul class="breadcrumb">
|
||||||
|
<li><a href="<%= %>">Home</a></li>
|
||||||
|
<li>Commissioner</li>
|
||||||
|
<span style="float: right">
|
||||||
|
<%= link_to t('.new', :default => t("helpers.links.new")),new_commissioner_path,:class => 'btn btn-primary btn-sm' %>
|
||||||
|
</span>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h1>Commissioners</h1>
|
<br>
|
||||||
|
<div class="card">
|
||||||
<table>
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Employee Name</th>
|
||||||
|
<th>Commission type</th>
|
||||||
|
<th>Active</th>
|
||||||
|
<th>Created By</th>
|
||||||
<th colspan="3"></th>
|
<th colspan="3"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @commissioners.each do |commissioner| %>
|
<% @commissioners.each do |commissioner| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= link_to 'Show', commissioner %></td>
|
<td><%= commissioner.name %></td>
|
||||||
|
<td>
|
||||||
|
<% if Employee.exists? %>
|
||||||
|
<% employee = Employee.where('emp_id=?',commissioner.emp_id) %>
|
||||||
|
<%= employee[0].name %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td><%= commissioner.commission_type %></td>
|
||||||
|
<td><%= commissioner.is_active %></td>
|
||||||
|
<td><%= current_user.name %></td>
|
||||||
|
<td><%= link_to 'Show', commissioner_path(commissioner) %></td>
|
||||||
<td><%= link_to 'Edit', edit_commissioner_path(commissioner) %></td>
|
<td><%= link_to 'Edit', edit_commissioner_path(commissioner) %></td>
|
||||||
<td><%= link_to 'Destroy', commissioner, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
<td><%= link_to 'Destroy', commissioner_path(commissioner), method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
<br>
|
|
||||||
|
|
||||||
<%= link_to 'New Commissioner', new_commissioner_path %>
|
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
<h1>New Commissioner</h1>
|
<div class="span12">
|
||||||
|
<div class="page-header">
|
||||||
<%= render 'form', commissioner: @commissioner %>
|
<ul class="breadcrumb">
|
||||||
|
<li><a href="<%= root_path %>">Home</a></li>
|
||||||
<%= link_to 'Back', commissioners_path %>
|
<li><a href="<%= commissioners_path %>">Commissioners</a></li>
|
||||||
|
<li>New</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<%= render 'form', commissioner: @commissioner %>
|
||||||
|
</div>
|
||||||
@@ -1,4 +1,39 @@
|
|||||||
<p id="notice"><%= notice %></p>
|
<div class="page-header">
|
||||||
|
<ul class="breadcrumb">
|
||||||
|
<li><a href="<%= root_path %>">Home</a></li>
|
||||||
|
<li><a href="<%= commissioners_path %>">Commissioners</a></li>
|
||||||
|
|
||||||
<%= link_to 'Edit', edit_commissioner_path(@commissioner) %> |
|
<span style="float: right">
|
||||||
<%= link_to 'Back', commissioners_path %>
|
</span>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-block">
|
||||||
|
<h4 class="card-title">Commissioner</h4>
|
||||||
|
<table class="table">
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
|
||||||
|
<tr><td style="width:20%">Name</td><td><%= @commissioner.name %></td></tr>
|
||||||
|
<tr><td style="width:20%">Employee Name</td>
|
||||||
|
<td>
|
||||||
|
<% if Employee.exists? %>
|
||||||
|
<% employee = Employee.where('emp_id=?',@commissioner.emp_id) %>
|
||||||
|
<%= employee[0].name %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</td></tr>
|
||||||
|
<tr><td style="width:20%">Commission Type</td><td><%= @commissioner.commission_type %></td></tr>
|
||||||
|
<tr><td style="width:20%">Active</td><td><%= @commissioner.is_active %></td></tr>
|
||||||
|
<tr><td style="width:20%">Created By</td><td><%= current_user.name %></td></tr>
|
||||||
|
|
||||||
|
|
||||||
|
<tr><td style="width:20%"><%= link_to 'Edit', edit_commissioner_path(@commissioner) %></td><td><%= link_to 'Destroy', commissioner_path(@commissioner), method: :delete, data: { confirm: 'Are you sure?' } %></td></tr>
|
||||||
|
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
<li><%= link_to "Print Setting", print_settings_path, :tabindex =>"-1" %></li>
|
<li><%= link_to "Print Setting", print_settings_path, :tabindex =>"-1" %></li>
|
||||||
<hr class="hr_advance" />
|
<hr class="hr_advance" />
|
||||||
<li><%= link_to "Employees", settings_employees_path, :tabindex =>"-1" %></li>
|
<li><%= link_to "Employees", settings_employees_path, :tabindex =>"-1" %></li>
|
||||||
|
<li><%= link_to "Commissioners", commissioners_path, :tabindex =>"-1" %></li>
|
||||||
<hr class="hr_advance" />
|
<hr class="hr_advance" />
|
||||||
<li><%= link_to "Accounts", settings_accounts_path, :tabindex =>"-1" %></li>
|
<li><%= link_to "Accounts", settings_accounts_path, :tabindex =>"-1" %></li>
|
||||||
<hr class="hr_advance" />
|
<hr class="hr_advance" />
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ require 'sidekiq/web'
|
|||||||
|
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
|
|
||||||
resources :commissioners
|
|
||||||
root 'home#index'
|
root 'home#index'
|
||||||
mount Sidekiq::Web => '/kiq'
|
mount Sidekiq::Web => '/kiq'
|
||||||
|
|
||||||
@@ -323,6 +323,6 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
#----------- Print Setup --------#
|
#----------- Print Setup --------#
|
||||||
resources :print_settings
|
resources :print_settings
|
||||||
|
resources :commissioners
|
||||||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user