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.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

View File

@@ -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

View File

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

View File

@@ -10,18 +10,18 @@
</div>
<div class="row">
<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"%>
<br>
</div>
<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"%>
</div>
</div>
<div class="row">
<div class="col-md-6">
<!-- <%= f.input :promo_start_hour %> -->
<!-- <span>* Promo Start Hour</span> -->
<% 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' %> -->
</div>
<div class="col-md-6">
<!-- <%= f.input :promo_end_hour %> -->
<!-- <span>* Promo End Hour</span> -->
<% 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 @@
</div>
</div>
<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>
<br>
<br>
<table class="table" style="border : 1px solid #555555 !important;margin:0px">
<tbody>
<tr>
<!-- <td>Promotion Code</td> -->
<td>Item Code</td>
<td>Min Qty</td>
<td>Net off</td>
<td>Net Price</td>
<td>Percentage</td>
<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>
<div class="" style="border: 1px solid #cccccc;padding:1%">
<div class="row">
<div class="col-md-2" style="text-align:center">Item Code</div>
<div class="col-md-2" style="text-align:center">Min Qty</div>
<div class="col-md-2" style="text-align:center">Net off</div>
<div class="col-md-2" style="text-align:center">Net Price</div>
<div class="col-md-2" style="text-align:center">Percentage</div>
<div class="col-md-2" style="text-align:center"></div>
</div>
<div class="row"></div >
<%= f.fields_for :promotion_products do |pro| %>
<table class="table" style="margin:0px">
<tbody>
<tr>
<!-- <td></td> -->
<td><%= pro.input :item_code, label: false%></td>
<td><%= pro.input :min_qty , label: false%></td>
<td><%= pro.input :net_off , label: false %></td>
<td><%= pro.input :net_price , label: false %></td>
<td><%= pro.input :percentage , label: false %></td>
<td><%= pro.link_to_remove "X" %></td>
<td></td>
</tr>
</tbody>
</table>
<div class="row">
<div class="col-md-2"><%= pro.input :item_code, label: false,collection: MenuItem.order("name desc").pluck(:name,:item_code)%></div>
<div class="col-md-2"><%= pro.input :min_qty , label: false%></div>
<div class="col-md-2"><%= pro.input :net_off , label: false %></div>
<div class="col-md-2"><%= pro.input :net_price , label: false %></div>
<div class="col-md-2"><%= pro.input :percentage , label: false %></div>
<div class="col-md-2" style="text-align:right"><%= pro.link_to_remove "X" %></div>
</div>
<% 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>
<br>
<div class="form-actions">
<%= f.button :submit %>
</div>

View File

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