CRUDcommissioner
This commit is contained in:
@@ -15,6 +15,7 @@ class CommissionersController < ApplicationController
|
||||
# GET /commissioners/new
|
||||
def new
|
||||
@commissioner = Commissioner.new
|
||||
@employee = Employee.all.order('name asc')
|
||||
end
|
||||
|
||||
# GET /commissioners/1/edit
|
||||
@@ -25,7 +26,7 @@ class CommissionersController < ApplicationController
|
||||
# POST /commissioners.json
|
||||
def create
|
||||
@commissioner = Commissioner.new(commissioner_params)
|
||||
|
||||
@commissioner.created_by = current_user.id
|
||||
respond_to do |format|
|
||||
if @commissioner.save
|
||||
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.
|
||||
def commissioner_params
|
||||
params.fetch(:commissioner, {})
|
||||
params.require(:commissioner).permit(:name,:emp_id,:created_by,:commission_type, :is_active)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
class Commissioner < ApplicationRecord
|
||||
has_many :employees
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Employee < ApplicationRecord
|
||||
has_secure_password
|
||||
|
||||
belongs_to :commissioner
|
||||
has_many :shit_sales
|
||||
validates_presence_of :name, :role
|
||||
validates_presence_of :password, :on => [:create]
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
<%= f.error_notification %>
|
||||
|
||||
<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 class="form-actions">
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
<h1>Editing Commissioner</h1>
|
||||
|
||||
<%= render 'form', commissioner: @commissioner %>
|
||||
|
||||
<%= link_to 'Show', @commissioner %> |
|
||||
<%= link_to 'Back', commissioners_path %>
|
||||
<div class="span12">
|
||||
<div class="page-header">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="<%= root_path %>">Home</a></li>
|
||||
<li><a href="<%= commissioners_path %>">Commissioners</a></li>
|
||||
<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>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<br>
|
||||
<div class="card">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Employee Name</th>
|
||||
<th>Commission type</th>
|
||||
<th>Active</th>
|
||||
<th>Created By</th>
|
||||
<th colspan="3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tbody>
|
||||
<% @commissioners.each do |commissioner| %>
|
||||
<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 '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>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
<%= link_to 'New Commissioner', new_commissioner_path %>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
<h1>New Commissioner</h1>
|
||||
|
||||
<%= render 'form', commissioner: @commissioner %>
|
||||
|
||||
<%= link_to 'Back', commissioners_path %>
|
||||
<div class="span12">
|
||||
<div class="page-header">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="<%= root_path %>">Home</a></li>
|
||||
<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) %> |
|
||||
<%= link_to 'Back', commissioners_path %>
|
||||
<span style="float: right">
|
||||
</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>
|
||||
<hr class="hr_advance" />
|
||||
<li><%= link_to "Employees", settings_employees_path, :tabindex =>"-1" %></li>
|
||||
<li><%= link_to "Commissioners", commissioners_path, :tabindex =>"-1" %></li>
|
||||
<hr class="hr_advance" />
|
||||
<li><%= link_to "Accounts", settings_accounts_path, :tabindex =>"-1" %></li>
|
||||
<hr class="hr_advance" />
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'sidekiq/web'
|
||||
|
||||
Rails.application.routes.draw do
|
||||
|
||||
resources :commissioners
|
||||
|
||||
root 'home#index'
|
||||
mount Sidekiq::Web => '/kiq'
|
||||
|
||||
@@ -323,6 +323,6 @@ Rails.application.routes.draw do
|
||||
|
||||
#----------- Print Setup --------#
|
||||
resources :print_settings
|
||||
|
||||
resources :commissioners
|
||||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user