+
+
+
diff --git a/Gemfile b/Gemfile
index 7b2cdca5..06b49df2 100644
--- a/Gemfile
+++ b/Gemfile
@@ -116,3 +116,4 @@ gem 'httparty', '~> 0.15.5'
# # gem 'momentjs-rails', '>= 2.9.0'
# gem 'bootstrap3-datetimepicker-rails'z
gem 'bootstrap-datepicker-rails'
+gem 'select2-rails'
diff --git a/Gemfile.lock b/Gemfile.lock
index 912f79ef..602a5b15 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -196,6 +196,8 @@ GEM
tilt (>= 1.1, < 3)
schema_to_scaffold (0.8.0)
activesupport (>= 3.2.1)
+ select2-rails (4.0.3)
+ thor (~> 0.14)
shoulda-matchers (3.1.1)
activesupport (>= 4.0.0)
sidekiq (5.0.3)
@@ -280,6 +282,7 @@ DEPENDENCIES
rspec-rails (~> 3.5)
sass-rails (~> 5.0)
schema_to_scaffold
+ select2-rails
shoulda-matchers (~> 3.1)
sidekiq
simple_form
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index cd056d1c..e0e5eba8 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -20,6 +20,8 @@
//= require settings/processing_items
//= require jquery-ui
//= require bootstrap-datepicker
+//= require select2
+//= require select2-full
$(document).on('turbolinks:load', function() {
$('.datepicker').datepicker({
diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss
index 1c5ada90..03e049b4 100644
--- a/app/assets/stylesheets/application.scss
+++ b/app/assets/stylesheets/application.scss
@@ -4,7 +4,8 @@
@import "theme";
@import "jquery-ui";
@import "bootstrap-datepicker3";
-
+@import "select2";
+@import "select2-bootstrap";
/* Show it is fixed to the top */
// body {
diff --git a/app/controllers/origami/commissions_controller.rb b/app/controllers/origami/commissions_controller.rb
index a10e59c6..f18bd11e 100644
--- a/app/controllers/origami/commissions_controller.rb
+++ b/app/controllers/origami/commissions_controller.rb
@@ -15,10 +15,12 @@ class Origami::CommissionsController < BaseOrigamiController
# GET /commissions/new
def new
@commission = Commission.new
+ @products = MenuItem.all
end
# GET /commissions/1/edit
def edit
+ @products = MenuItem.all
end
# POST /commissions
diff --git a/app/models/commission.rb b/app/models/commission.rb
index 48f73f87..df11eb24 100644
--- a/app/models/commission.rb
+++ b/app/models/commission.rb
@@ -1,4 +1,4 @@
class Commission < ApplicationRecord
- belongs_to :product, foreign_key: 'product_id'
+ belongs_to :menu_item, foreign_key: 'product_id'
has_many :commissioners
end
diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb
index 8213ae88..c581a7b0 100644
--- a/app/models/menu_item.rb
+++ b/app/models/menu_item.rb
@@ -3,6 +3,8 @@ class MenuItem < ApplicationRecord
belongs_to :menu_category, :optional => true
has_many :menu_item_instances
+ has_many :commissions
+
# belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id", :optional => true
# has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id"
belongs_to :account
diff --git a/app/models/product.rb b/app/models/product.rb
index fed8ee97..5aff41f5 100644
--- a/app/models/product.rb
+++ b/app/models/product.rb
@@ -1,6 +1,5 @@
class Product < ApplicationRecord
validates_presence_of :name
- has_many :commissions
# Product Image Uploader
mount_uploader :image_path, ProductImageUploader
diff --git a/app/views/origami/commissions/_form.html.erb b/app/views/origami/commissions/_form.html.erb
index a5c0d2c0..1f7fee4a 100644
--- a/app/views/origami/commissions/_form.html.erb
+++ b/app/views/origami/commissions/_form.html.erb
@@ -4,11 +4,11 @@
<%= f.label :product_id %>
- <%= f.collection_select :product_id, Product.all.order('name asc'), :id, :name, {prompt: "Select a Product"}, {class: "form-control"} %>
+ <%= f.collection_select :product_id, @products, :id, :name, {prompt: 'Select a Product'}, {class: 'form-control'} %>
<%= f.input :amount %>
- <%= f.input :commission_type, :collection => [:percentage, :net_amount] %>
+ <%= f.input :commission_type, :collection => ['Percentage','Net Amount'], prompt: 'Select Commission Type', class: 'form-control' %>
-
+
<%= link_to 'Back', origami_commissions_path, class: 'btn btn-success' %>
<%= f.button :submit, class: 'btn btn-info' %>
diff --git a/app/views/origami/commissions/index.html.erb b/app/views/origami/commissions/index.html.erb
index e5a83639..da589347 100644
--- a/app/views/origami/commissions/index.html.erb
+++ b/app/views/origami/commissions/index.html.erb
@@ -1,11 +1,11 @@
@@ -23,22 +23,16 @@
<% @commissions.each do |commission| %>
-
- |
- <% if Product.exists? %>
- <% product = Product.find(commission.product_id) %>
- <%= product.name %>
- <% end %>
-
- |
- <%= commission.amount %> |
- <%= commission.commission_type %> |
- <%= commission.is_active %> |
- <%= link_to 'Show', origami_commission_path(commission) %> |
- <%= link_to 'Edit', edit_origami_commission_path(commission) %> |
- <%= link_to 'Destroy', origami_commission_path(commission), method: :delete, data: { confirm: 'Are you sure?' } %> |
-
+
+ | <%= commission.menu_item.name rescue '-' %> |
+ <%= commission.amount rescue '-' %> |
+ <%= commission.commission_type rescue '-' %> |
+ <%= commission.is_active rescue '-' %> |
+ <%= link_to 'Show', origami_commission_path(commission) %> |
+ <%= link_to 'Edit', edit_origami_commission_path(commission) %> |
+ <%= link_to 'Destroy', origami_commission_path(commission), method: :delete, data: {confirm: 'Are you sure?'} %> |
+
<% end %>
-
+
diff --git a/app/views/origami/commissions/show.html.erb b/app/views/origami/commissions/show.html.erb
index da04710e..439e2c45 100644
--- a/app/views/origami/commissions/show.html.erb
+++ b/app/views/origami/commissions/show.html.erb
@@ -16,12 +16,7 @@
| Product Name |
-
- <% if Product.exists? %>
- <% product = Product.find(@commission.product_id) %>
- <%= product.name %>
- <% end %>
- |
+ <%= @commission.menu_item.name rescue '-' %> |
| Amount |