Promotion Product Add
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -31,6 +31,7 @@ gem 'coffee-rails', '~> 4.2'
|
||||
# See https://github.com/rails/execjs#readme for more supported runtimes
|
||||
# gem 'therubyracer', platforms: :ruby
|
||||
gem 'simple_form'
|
||||
gem 'nested_form'
|
||||
gem 'bootstrap', '~> 4.0.0.alpha3'
|
||||
gem 'tether-rails'
|
||||
gem "font-awesome-rails"
|
||||
|
||||
@@ -119,6 +119,7 @@ GEM
|
||||
multi_json (1.12.1)
|
||||
multi_xml (0.6.0)
|
||||
mysql2 (0.4.6)
|
||||
nested_form (0.3.2)
|
||||
nio4r (2.1.0)
|
||||
nokogiri (1.8.0)
|
||||
mini_portile2 (~> 2.2.0)
|
||||
@@ -264,6 +265,7 @@ DEPENDENCIES
|
||||
kaminari (~> 1.0.1)
|
||||
listen (~> 3.0.5)
|
||||
mysql2 (>= 0.3.18, < 0.5)
|
||||
nested_form
|
||||
pg
|
||||
prawn
|
||||
prawn-table
|
||||
|
||||
77
app/controllers/settings/promotion_products_controller.rb
Normal file
77
app/controllers/settings/promotion_products_controller.rb
Normal file
@@ -0,0 +1,77 @@
|
||||
class Settings::PromotionProductsController < ApplicationController
|
||||
before_action :set_promotion, only: [:show, :edit, :update, :destroy,:new]
|
||||
before_action :set_promotion_product, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /promotion_products
|
||||
# GET /promotion_products.json
|
||||
def index
|
||||
@promotion_products = PromotionProduct.all
|
||||
end
|
||||
|
||||
# GET /promotion_products/1
|
||||
# GET /promotion_products/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /promotion_products/new
|
||||
def new
|
||||
@promotion_product = PromotionProduct.new
|
||||
end
|
||||
|
||||
# GET /promotion_products/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /promotion_products
|
||||
# POST /promotion_products.json
|
||||
def create
|
||||
@promotion_product = PromotionProduct.new(promotion_params)
|
||||
respond_to do |format|
|
||||
if @promotion_product.save
|
||||
format.html { redirect_to edit_settings_promotion_path(@promotion), notice: 'PromotionProduct was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @promotion_product }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @promotion_product.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /promotion_products/1
|
||||
# PATCH/PUT /promotion_products/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @promotion_product.update(promotion_params)
|
||||
format.html { redirect_to edit_settings_promotion_path(@promotion), notice: 'PromotionProduct was successfully updated.' }
|
||||
format.json { render :show, status: :ok, location: @promotion_product }
|
||||
else
|
||||
format.html { render :edit }
|
||||
format.json { render json: @promotion_product.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /promotion_products/1
|
||||
# DELETE /promotion_products/1.json
|
||||
def destroy
|
||||
@promotion_product.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to edit_settings_promotion_path(@promotion) , notice: 'PromotionProduct was successfully destroyed.' }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_promotion
|
||||
@promotion = Promotion.find(params[:promotion_id])
|
||||
end
|
||||
def set_promotion_product
|
||||
@promotion_product = PromotionProduct.find(params[:id])
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def promotion_params
|
||||
params.require(:promotion_product).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)
|
||||
end
|
||||
end
|
||||
@@ -71,6 +71,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)
|
||||
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])
|
||||
end
|
||||
end
|
||||
|
||||
3
app/models/promotion_product.rb
Normal file
3
app/models/promotion_product.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class PromotionProduct < ApplicationRecord
|
||||
belongs_to :promotion
|
||||
end
|
||||
32
app/views/settings/promotion_products/_form.html.erb
Normal file
32
app/views/settings/promotion_products/_form.html.erb
Normal file
@@ -0,0 +1,32 @@
|
||||
<%= simple_form_for([:settings,@promotion,@promotion_product]) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<div class="form-inputs">
|
||||
<div class="div-border">
|
||||
<div class="row">
|
||||
<div class="col-md-12"><%= f.input :item_code %></div>
|
||||
</div>
|
||||
<% if @promotion.promo_type == Promotion::PROMO_TYPE1 %>
|
||||
<div class="row">
|
||||
<div class="col-md-12"><%= f.input :min_qty %></div>
|
||||
</div>
|
||||
<% elsif @promotion.promo_type == Promotion::PROMO_TYPE2 %>
|
||||
<div class="row">
|
||||
<div class="col-md-12"><%= f.input :net_off %></div>
|
||||
</div>
|
||||
<% elsif @promotion.promo_type == Promotion::PROMO_TYPE3 %>
|
||||
<div class="row">
|
||||
<div class="col-md-12"><%= f.input :net_price %></div>
|
||||
</div>
|
||||
<% elsif @promotion.promo_type == Promotion::PROMO_TYPE4 %>
|
||||
<div class="row">
|
||||
<div class="col-md-12"><%= f.input :percentage %></div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<%= f.button :submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -0,0 +1,2 @@
|
||||
json.extract! promotion, :id, :created_at, :updated_at
|
||||
json.url promotion_url(promotion, format: :json)
|
||||
11
app/views/settings/promotion_products/edit.html.erb
Normal file
11
app/views/settings/promotion_products/edit.html.erb
Normal file
@@ -0,0 +1,11 @@
|
||||
<div class="span12">
|
||||
<div class="page-header">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="<%= root_path %>">Home</a></li>
|
||||
<li><a href="<%= edit_settings_promotion_path(@promotion) %>">Promotions</a></li>
|
||||
<li>Promotion Products</li>
|
||||
<li>Edit</li>
|
||||
</ul>
|
||||
</div>
|
||||
<%= render 'form', promotion_products: @promotion_product %>
|
||||
</div>
|
||||
47
app/views/settings/promotion_products/index.html.erb
Normal file
47
app/views/settings/promotion_products/index.html.erb
Normal file
@@ -0,0 +1,47 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
|
||||
<div class="page-header">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="<%= root_path %>">Home</a></li>
|
||||
<li><a href="<%= settings_promotions_path %>">Promotions</a></li>
|
||||
<li>PromotionProducts</li>
|
||||
<span style="float: right">
|
||||
<%= link_to t('.new', :default => t("helpers.links.new")),new_settings_promotion_promotion_product_path,:class => 'btn btn-primary btn-sm' %>
|
||||
</span>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<div class="card">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Promotion Code</th>
|
||||
<th>Item Code</th>
|
||||
<th>Minimum Quantity</th>
|
||||
<th>Net Off</th>
|
||||
<th>Net Price</th>
|
||||
<th>Percentage</th>
|
||||
<th>Created At</th>
|
||||
<th colspan="2"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @promotion_products.each do |pro| %>
|
||||
<tr>
|
||||
<td><%= link_to pro.promotion.promo_code, settings_promotion_promotion_path(pro.promotion) %></td>
|
||||
<td><%= pro.item_code %></td>
|
||||
<td><%= pro.min_qty %></td>
|
||||
<td><%= pro.net_off rescue "-" %></td>
|
||||
<td><%= pro.net_price rescue "-" %></td>
|
||||
<td><%= pro.percentage %></td>
|
||||
<td><%= pro.created_at.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") %></td>
|
||||
<td><%= link_to 'Edit', edit_settings_promotion_promotion_product_path(pro) %></td>
|
||||
<td><%= link_to 'Destroy', settings_promotion_promotion_product_path(pro), method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -0,0 +1 @@
|
||||
json.array! @promotions, partial: 'promotions/promotion', as: :promotion
|
||||
15
app/views/settings/promotion_products/new.html.erb
Normal file
15
app/views/settings/promotion_products/new.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
<div class="span12">
|
||||
<div class="page-header">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="<%= root_path %>">Home</a></li>
|
||||
<li><a href="<%= edit_settings_promotion_path(@promotion) %>">Promotion</a></li>
|
||||
<!-- <li><a href="<%= settings_promotion_promotion_products_path %>">Promotion Products</a></li> -->
|
||||
<li>New</li>
|
||||
</ul>
|
||||
</div>
|
||||
<%= render 'form', promotion_products: @promotion_product %>
|
||||
</div>
|
||||
<script>
|
||||
$("#promotion_promo_code").val(Math.random().toString(36).slice(5) + Math.random().toString(36).slice(5));
|
||||
</script>
|
||||
28
app/views/settings/promotion_products/show.html.erb
Normal file
28
app/views/settings/promotion_products/show.html.erb
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
<div class="span12">
|
||||
<div class="page-header">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="<%= root_path %>">Home</a></li>
|
||||
<li><a href="<%= settings_promotion_path(@promotion) %>">Promotion</a></li>
|
||||
<li>Promotion Products</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-block">
|
||||
<h4 class="card-title">Promotion Product</h4>
|
||||
<table class="table">
|
||||
<tbody>
|
||||
|
||||
<tr><td style="width:20%">Promotion Code</td><td><%= @promotion_product.promo_code %></td></tr>
|
||||
<tr><td style="width:20%">Item Code</td><td><%= @promotion_product.item_code %></td></tr>
|
||||
<tr><td style="width:20%">Min Qty</td><td><%= @promotion_product.min_qty %></td></tr>
|
||||
<tr><td style="width:20%">Net off</td><td><%= @promotion_product.net_off %></td></tr>
|
||||
<tr><td style="width:20%">Net Price</td><td><%= @promotion_product.net_price %></td></tr>
|
||||
<tr><td style="width:20%">Percentage</td><td><%= @promotion_product.percentage %></td></tr>
|
||||
<tr><td style="width:20%"><%= link_to 'Edit', edit_settings_promotion_product_path(@promotion_product) %></td><td><%= link_to 'Destroy', settings_promotion_product_path(@promotion_product), method: :delete, data: { confirm: 'Are you sure?' } %></td></tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
1
app/views/settings/promotion_products/show.json.jbuilder
Normal file
1
app/views/settings/promotion_products/show.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
||||
json.partial! "promotions/promotion", promotion: @promotion
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= simple_form_for([:settings,@promotion]) do |f| %>
|
||||
<%= simple_nested_form_for([:settings,@promotion]) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<div class="form-inputs">
|
||||
@@ -32,13 +32,62 @@
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<%= f.input :promo_type,input_html: { class: "" },
|
||||
collection: %w{Quantity Net_off Net_price Percentage},:class => 'form-control' ,:label => "" %>
|
||||
collection: %w{Quantity Net_off Net_price Percentage},:class => 'form-control' ,:label => "Promotion Type" %>
|
||||
</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 :min_qty %></div>
|
||||
</div>
|
||||
|
||||
<!-- <% if @promotion.id != nil %>
|
||||
<div class="div-border">
|
||||
<div class="col-md-10">
|
||||
<%= link_to 'Promotion Product', new_settings_promotion_promotion_product_path(@promotion),:class => 'btn btn-primary' %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %> -->
|
||||
<br>
|
||||
<table class="table" style="border : 1px solid #555555 !important">
|
||||
<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"><%= f.link_to_add "Add Product", :promotion_products, :class => 'btn btn-primary' %></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 %>
|
||||
<%= f.fields_for :promotion_products, PromotionProduct.new do |pro| %>
|
||||
<tr>
|
||||
<!-- <td></td> -->
|
||||
<td><%= pro.input :item_code , :class => "form-control" %></td>
|
||||
<td><%= pro.input :min_qty , :class => "form-control"%></td>
|
||||
<td><%= pro.input :net_off , :class => "form-control" %></td>
|
||||
<td><%= pro.input :net_price , :class => "form-control" %></td>
|
||||
<td><%= pro.input :percentage , :class => "form-control" %></td>
|
||||
<td><%= pro.link_to_remove "X" %></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,4 +1,28 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<%= link_to 'Edit', edit_promotion_path(@promotion) %> |
|
||||
<%= link_to 'Back', promotions_path %>
|
||||
<div class="span12">
|
||||
<div class="page-header">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="<%= root_path %>">Home</a></li>
|
||||
<li><a href="<%= settings_promotions_path %>">Promotions</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-block">
|
||||
<h4 class="card-title">Promotion</h4>
|
||||
<table class="table">
|
||||
|
||||
<tbody>
|
||||
|
||||
<tr><td style="width:20%">Promotion code</td><td><%= @promotion.promo_code %></td></tr>
|
||||
<tr><td style="width:20%">Promotion Start Date</td><td><%= @promotion.promo_start_date %></td></tr>
|
||||
<tr><td style="width:20%">Promotion End Date</td><td><%= @promotion.promo_end_date %></td></tr>
|
||||
<tr><td style="width:20%">Promotion Start Hour</td><td><%= @promotion.promo_start_hour %></td></tr>
|
||||
<tr><td style="width:20%">Promotion Start Hour</td><td><%= @promotion.promo_end_hour %></td></tr>
|
||||
<tr><td style="width:20%"><%= link_to 'Edit', edit_settings_promotion_path(@promotion) %></td><td><%= link_to 'Destroy', settings_promotion_path(@promotion), method: :delete, data: { confirm: 'Are you sure?' } %></td></tr>
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -268,7 +268,9 @@ Rails.application.routes.draw do
|
||||
end
|
||||
|
||||
#promotion
|
||||
resources :promotions
|
||||
resources :promotions do
|
||||
resources :promotion_products
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user