Promotion Product Bug Fix

This commit is contained in:
Phyo
2017-08-24 14:37:11 +06:30
parent 0118a178b2
commit 0670a6a05d
5 changed files with 36 additions and 59 deletions

View File

@@ -4,7 +4,7 @@ class Settings::PromotionsController < ApplicationController
# GET /promotions # GET /promotions
# GET /promotions.json # GET /promotions.json
def index def index
@promotions = Promotion.all @promotions = Promotion.all.order("created_at asc")
end end
# GET /promotions/1 # GET /promotions/1
@@ -85,6 +85,6 @@ class Settings::PromotionsController < 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 promotion_params 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, 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
end end

View File

@@ -3,7 +3,7 @@ class Promotion < ApplicationRecord
has_many :promotion_products 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_TYPE1 = "Quantity"
PROMO_TYPE2 = "Net_off" # 3000 => - 500 => 2500 [total] PROMO_TYPE2 = "Net_off" # 3000 => - 500 => 2500 [total]
@@ -204,6 +204,6 @@ class Promotion < ApplicationRecord
end end
def self.calculate_discount(total, discount) def self.calculate_discount(total, discount)
self (total.to_i * discount.to_i) / 100 return (total.to_i * discount.to_i) / 100
end end
end end

View File

@@ -1,3 +1,4 @@
class PromotionProduct < ApplicationRecord class PromotionProduct < ApplicationRecord
validates_presence_of :item_code
belongs_to :promotion belongs_to :promotion
end end

View File

@@ -10,18 +10,18 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<span>Promo Start Date</span> <span>* Promo Start Date</span>
<%= f.date_field :promo_start_date, :placeholder => "From Date" , :class => "form-control"%> <%= f.date_field :promo_start_date, :placeholder => "From Date" , :class => "form-control"%>
<br> <br>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<span>Promo End Date</span> <span>* Promo End Date</span>
<%= f.date_field :promo_end_date ,:placeholder => "To Date" , :class => "form-control"%> <%= f.date_field :promo_end_date ,:placeholder => "To Date" , :class => "form-control"%>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<!-- <%= f.input :promo_start_hour %> --> <!-- <span>* Promo Start Hour</span> -->
<% if !@promotion.promo_start_hour.nil?%> <% if !@promotion.promo_start_hour.nil?%>
<%= f.input :promo_start_hour, as: :string, input_html: { :value => @promotion.promo_start_hour.utc.strftime('%H:%M') } %> <%= f.input :promo_start_hour, as: :string, input_html: { :value => @promotion.promo_start_hour.utc.strftime('%H:%M') } %>
<% else %> <% else %>
@@ -31,7 +31,7 @@
<%= text_field_tag :promo_start_hour , nil, :placeholder => "From Time", :id => "fromtime", :class => 'form-control' %> --> <%= text_field_tag :promo_start_hour , nil, :placeholder => "From Time", :id => "fromtime", :class => 'form-control' %> -->
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<!-- <%= f.input :promo_end_hour %> --> <!-- <span>* Promo End Hour</span> -->
<% if !@promotion.promo_end_hour.nil?%> <% if !@promotion.promo_end_hour.nil?%>
<%= f.input :promo_end_hour, as: :string, input_html: {:value => @promotion.promo_end_hour.utc.strftime('%H:%M') } %> <%= f.input :promo_end_hour, as: :string, input_html: {:value => @promotion.promo_end_hour.utc.strftime('%H:%M') } %>
<% else %> <% else %>
@@ -49,60 +49,38 @@
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-6"><%= f.input :original_product,collection: MenuItem.order("name desc"),input_html: { selected: 2 } %></div> <div class="col-md-6"><%= f.input :original_product,collection: MenuItem.order("name desc").pluck(:name,:item_code),input_html: { selected: 2 } %></div>
<div class="col-md-6"><%= f.input :min_qty %></div> <div class="col-md-6"><%= f.input :min_qty %></div>
</div> </div>
<br> <br>
<br> <div class="" style="border: 1px solid #cccccc;padding:1%">
<table class="table" style="border : 1px solid #555555 !important;margin:0px"> <div class="row">
<tbody> <div class="col-md-2" style="text-align:center">Item Code</div>
<tr> <div class="col-md-2" style="text-align:center">Min Qty</div>
<!-- <td>Promotion Code</td> --> <div class="col-md-2" style="text-align:center">Net off</div>
<td>Item Code</td> <div class="col-md-2" style="text-align:center">Net Price</div>
<td>Min Qty</td> <div class="col-md-2" style="text-align:center">Percentage</div>
<td>Net off</td> <div class="col-md-2" style="text-align:center"></div>
<td>Net Price</td> </div>
<td>Percentage</td> <div class="row"></div >
<td colspan="2"></td>
</tr>
<!-- <% @promotion.promotion_products.each do |pp| %>
<tr>
<!-- <td><%= pp.promotion_id %></td>
<td><%= pp.item_code %></td>
<td><%= pp.min_qty %></td>
<td><%= pp.net_off %></td>
<td><%= pp.net_price %></td>
<td><%= pp.percentage %></td>
<td><%= link_to 'Edit', edit_settings_promotion_promotion_product_path(@promotion,pp) %></td>
<td><%= link_to 'Destroy', settings_promotion_promotion_product_path(@promotion,pp), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %> -->
</tbody>
</table>
<%= f.fields_for :promotion_products do |pro| %> <%= f.fields_for :promotion_products do |pro| %>
<table class="table" style="margin:0px"> <div class="row">
<tbody> <div class="col-md-2"><%= pro.input :item_code, label: false,collection: MenuItem.order("name desc").pluck(:name,:item_code)%></div>
<tr> <div class="col-md-2"><%= pro.input :min_qty , label: false%></div>
<!-- <td></td> --> <div class="col-md-2"><%= pro.input :net_off , label: false %></div>
<td><%= pro.input :item_code, label: false%></td> <div class="col-md-2"><%= pro.input :net_price , label: false %></div>
<td><%= pro.input :min_qty , label: false%></td> <div class="col-md-2"><%= pro.input :percentage , label: false %></div>
<td><%= pro.input :net_off , label: false %></td> <div class="col-md-2" style="text-align:right"><%= pro.link_to_remove "X" %></div>
<td><%= pro.input :net_price , label: false %></td> </div>
<td><%= pro.input :percentage , label: false %></td>
<td><%= pro.link_to_remove "X" %></td>
<td></td>
</tr>
</tbody>
</table>
<% end %> <% end %>
<%= f.link_to_add "Add Product", :promotion_products, :class => 'btn btn-primary' %> <div class="row">
<div class="col-md-12" style="text-align:right;"><%= f.link_to_add "Add Product", :promotion_products, :class => 'btn btn-primary' %></div>
</div>
</div>
</div> </div>
</div> </div>
<br>
<div class="form-actions"> <div class="form-actions">
<%= f.button :submit %> <%= f.button :submit %>
</div> </div>

View File

@@ -39,9 +39,7 @@
<td><%= pro.promo_end_hour.utc.strftime("%I:%M %P") rescue "-" %></td> <td><%= pro.promo_end_hour.utc.strftime("%I:%M %P") rescue "-" %></td>
<td><%= pro.promo_day %></td> <td><%= pro.promo_day %></td>
<td> <td>
<% if MenuItem.exists?(pro.original_product) %> <%= MenuItem.find_by_item_code(pro.original_product).name rescue "-"%>
<%= MenuItem.find(pro.original_product).name %>
<% end %>
</td> </td>
<% if Employee.exists?(pro.created_by) %> <% if Employee.exists?(pro.created_by) %>
<td><%= Employee.find(pro.created_by).name %></td> <td><%= Employee.find(pro.created_by).name %></td>