diff --git a/app/controllers/settings/promotions_controller.rb b/app/controllers/settings/promotions_controller.rb
index 94f095ec..ef972df9 100644
--- a/app/controllers/settings/promotions_controller.rb
+++ b/app/controllers/settings/promotions_controller.rb
@@ -4,7 +4,7 @@ class Settings::PromotionsController < ApplicationController
# GET /promotions
# GET /promotions.json
def index
- @promotions = Promotion.all
+ @promotions = Promotion.all.order("created_at asc")
end
# GET /promotions/1
@@ -85,6 +85,6 @@ class Settings::PromotionsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def promotion_params
params.require(:promotion).permit(:promo_code, :promo_start_date, :promo_end_date, :promo_start_hour,:promo_end_hour ,:promo_day, :promo_type,:original_product ,:min_qty ,:created_by,
- :promotion_products_attributes => [:item_code, :min_qty, :net_off, :net_price, :percentage, :_destroy])
+ :promotion_products_attributes => [:id,:item_code, :min_qty, :net_off, :net_price, :percentage, :_destroy])
end
end
diff --git a/app/models/promotion.rb b/app/models/promotion.rb
index ed727038..87b90613 100644
--- a/app/models/promotion.rb
+++ b/app/models/promotion.rb
@@ -3,7 +3,7 @@ class Promotion < ApplicationRecord
has_many :promotion_products
- accepts_nested_attributes_for :promotion_products , :allow_destroy => true
+ accepts_nested_attributes_for :promotion_products , :allow_destroy => true , update_only: true
PROMO_TYPE1 = "Quantity"
PROMO_TYPE2 = "Net_off" # 3000 => - 500 => 2500 [total]
@@ -204,6 +204,6 @@ class Promotion < ApplicationRecord
end
def self.calculate_discount(total, discount)
- self (total.to_i * discount.to_i) / 100
+ return (total.to_i * discount.to_i) / 100
end
end
diff --git a/app/models/promotion_product.rb b/app/models/promotion_product.rb
index c853ebdc..e97445ea 100644
--- a/app/models/promotion_product.rb
+++ b/app/models/promotion_product.rb
@@ -1,3 +1,4 @@
class PromotionProduct < ApplicationRecord
+ validates_presence_of :item_code
belongs_to :promotion
end
diff --git a/app/views/settings/promotions/_form.html.erb b/app/views/settings/promotions/_form.html.erb
index c3953f32..1e4a3f86 100644
--- a/app/views/settings/promotions/_form.html.erb
+++ b/app/views/settings/promotions/_form.html.erb
@@ -10,18 +10,18 @@
- Promo Start Date
+ * Promo Start Date
<%= f.date_field :promo_start_date, :placeholder => "From Date" , :class => "form-control"%>
- Promo End Date
+ * Promo End Date
<%= f.date_field :promo_end_date ,:placeholder => "To Date" , :class => "form-control"%>
-
+
<% if !@promotion.promo_start_hour.nil?%>
<%= f.input :promo_start_hour, as: :string, input_html: { :value => @promotion.promo_start_hour.utc.strftime('%H:%M') } %>
<% else %>
@@ -31,7 +31,7 @@
<%= text_field_tag :promo_start_hour , nil, :placeholder => "From Time", :id => "fromtime", :class => 'form-control' %> -->
-
+
<% if !@promotion.promo_end_hour.nil?%>
<%= f.input :promo_end_hour, as: :string, input_html: {:value => @promotion.promo_end_hour.utc.strftime('%H:%M') } %>
<% else %>
@@ -49,60 +49,38 @@
-
<%= f.input :original_product,collection: MenuItem.order("name desc"),input_html: { selected: 2 } %>
+
<%= f.input :original_product,collection: MenuItem.order("name desc").pluck(:name,:item_code),input_html: { selected: 2 } %>
<%= f.input :min_qty %>
-
-
-
-
-
- | Item Code |
- Min Qty |
- Net off |
- Net Price |
- Percentage |
- |
-
-
-
-
-
- <%= f.fields_for :promotion_products do |pro| %>
-
-
-
-
- | <%= pro.input :item_code, label: false%> |
- <%= pro.input :min_qty , label: false%> |
- <%= pro.input :net_off , label: false %> |
- <%= pro.input :net_price , label: false %> |
- <%= pro.input :percentage , label: false %> |
- <%= pro.link_to_remove "X" %> |
- |
-
-
-
- <% end %>
- <%= f.link_to_add "Add Product", :promotion_products, :class => 'btn btn-primary' %>
-
+
+
+
Item Code
+
Min Qty
+
Net off
+
Net Price
+
Percentage
+
+
+
+ <%= f.fields_for :promotion_products do |pro| %>
+
+
<%= pro.input :item_code, label: false,collection: MenuItem.order("name desc").pluck(:name,:item_code)%>
+
<%= pro.input :min_qty , label: false%>
+
<%= pro.input :net_off , label: false %>
+
<%= pro.input :net_price , label: false %>
+
<%= pro.input :percentage , label: false %>
+
<%= pro.link_to_remove "X" %>
+
+ <% end %>
+
+
<%= f.link_to_add "Add Product", :promotion_products, :class => 'btn btn-primary' %>
+
+
+
<%= f.button :submit %>
diff --git a/app/views/settings/promotions/index.html.erb b/app/views/settings/promotions/index.html.erb
index 7914c6af..b0cfd599 100644
--- a/app/views/settings/promotions/index.html.erb
+++ b/app/views/settings/promotions/index.html.erb
@@ -39,9 +39,7 @@
<%= pro.promo_end_hour.utc.strftime("%I:%M %P") rescue "-" %> |
<%= pro.promo_day %> |
- <% if MenuItem.exists?(pro.original_product) %>
- <%= MenuItem.find(pro.original_product).name %>
- <% end %>
+ <%= MenuItem.find_by_item_code(pro.original_product).name rescue "-"%>
|
<% if Employee.exists?(pro.created_by) %>
<%= Employee.find(pro.created_by).name %> |