Promotion CRUD
This commit is contained in:
76
app/controllers/settings/promotions_controller.rb
Normal file
76
app/controllers/settings/promotions_controller.rb
Normal file
@@ -0,0 +1,76 @@
|
||||
class Settings::PromotionsController < ApplicationController
|
||||
before_action :set_promotion, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /promotions
|
||||
# GET /promotions.json
|
||||
def index
|
||||
@promotions = Promotion.all
|
||||
end
|
||||
|
||||
# GET /promotions/1
|
||||
# GET /promotions/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /promotions/new
|
||||
def new
|
||||
@promotion = Promotion.new
|
||||
@promotion.promo_start_date = DateTime.now
|
||||
@promotion.promo_end_date = DateTime.now
|
||||
end
|
||||
|
||||
# GET /promotions/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /promotions
|
||||
# POST /promotions.json
|
||||
def create
|
||||
@promotion = Promotion.new(promotion_params)
|
||||
@promotion.created_by = current_login_employee.id
|
||||
respond_to do |format|
|
||||
if @promotion.save
|
||||
format.html { redirect_to settings_promotions_path, notice: 'Promotion was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @promotion }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @promotion.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /promotions/1
|
||||
# PATCH/PUT /promotions/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @promotion.update(promotion_params)
|
||||
format.html { redirect_to settings_promotions_path, notice: 'Promotion was successfully updated.' }
|
||||
format.json { render :show, status: :ok, location: @promotion }
|
||||
else
|
||||
format.html { render :edit }
|
||||
format.json { render json: @promotion.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /promotions/1
|
||||
# DELETE /promotions/1.json
|
||||
def destroy
|
||||
@promotion.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to settings_promotions_path, notice: 'Promotion 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[:id])
|
||||
end
|
||||
|
||||
# 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)
|
||||
end
|
||||
end
|
||||
2
app/helpers/settings/promotions_helper.rb
Normal file
2
app/helpers/settings/promotions_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module Settings::PromotionsHelper
|
||||
end
|
||||
2
app/models/promotion.rb
Normal file
2
app/models/promotion.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
class Promotion < ApplicationRecord
|
||||
end
|
||||
@@ -28,6 +28,8 @@
|
||||
<li><%= link_to "Employees", settings_employees_path, :tabindex =>"-1" %></li>
|
||||
<hr class="hr_advance" />
|
||||
<li><%= link_to "Accounts", settings_accounts_path, :tabindex =>"-1" %></li>
|
||||
<hr class="hr_advance" />
|
||||
<li><%= link_to "Promotion", settings_promotions_path, :tabindex =>"-1" %></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
|
||||
48
app/views/settings/promotions/_form.html.erb
Normal file
48
app/views/settings/promotions/_form.html.erb
Normal file
@@ -0,0 +1,48 @@
|
||||
<%= simple_form_for([:settings,@promotion]) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<div class="form-inputs">
|
||||
<div class="div-border">
|
||||
<div class="row">
|
||||
<div class="col-md-6"><%= f.input :promo_code %></div>
|
||||
<div class="col-md-6"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<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>
|
||||
<%= 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>
|
||||
<%= 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 %></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12"><%= f.input :promo_day %></div>
|
||||
</div>
|
||||
<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 => "" %>
|
||||
</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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<%= f.button :submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
2
app/views/settings/promotions/_promotion.json.jbuilder
Normal file
2
app/views/settings/promotions/_promotion.json.jbuilder
Normal file
@@ -0,0 +1,2 @@
|
||||
json.extract! promotion, :id, :created_at, :updated_at
|
||||
json.url promotion_url(promotion, format: :json)
|
||||
10
app/views/settings/promotions/edit.html.erb
Normal file
10
app/views/settings/promotions/edit.html.erb
Normal file
@@ -0,0 +1,10 @@
|
||||
<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>
|
||||
<li>Edit</li>
|
||||
</ul>
|
||||
</div>
|
||||
<%= render 'form', promotion: @promotion %>
|
||||
</div>
|
||||
58
app/views/settings/promotions/index.html.erb
Normal file
58
app/views/settings/promotions/index.html.erb
Normal file
@@ -0,0 +1,58 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
|
||||
<div class="page-header">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="<%= root_path %>">Home</a></li>
|
||||
<li>Promotions</li>
|
||||
<span style="float: right">
|
||||
<%= link_to t('.new', :default => t("helpers.links.new")),new_settings_promotion_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>Start Date</th>
|
||||
<th>End Date</th>
|
||||
<th>Start Time</th>
|
||||
<th>End Time</th>
|
||||
<th>Promotion Day</th>
|
||||
<th>Original Product</th>
|
||||
<th>Created By</th>
|
||||
<th>Created At</th>
|
||||
<th colspan="2"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @promotions.each do |pro| %>
|
||||
<tr>
|
||||
<td><%= link_to pro.promo_code, settings_promotion_path(pro) %></td>
|
||||
<td><%= pro.promo_start_date %></td>
|
||||
<td><%= pro.promo_end_date %></td>
|
||||
<td><%= pro.promo_start_hour.strftime("%I:%M %P") rescue "-" %></td>
|
||||
<td><%= pro.promo_end_hour.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 %>
|
||||
</td>
|
||||
<% if Employee.exists?(pro.created_by) %>
|
||||
<td><%= Employee.find(pro.created_by).name %></td>
|
||||
<% else %>
|
||||
<td><%= pro.created_by %></td>
|
||||
<% end %>
|
||||
<td><%= pro.created_at.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") %></td>
|
||||
<td><%= link_to 'Edit', edit_settings_promotion_path(pro) %></td>
|
||||
<td><%= link_to 'Destroy', settings_promotion_path(pro), method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
1
app/views/settings/promotions/index.json.jbuilder
Normal file
1
app/views/settings/promotions/index.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
||||
json.array! @promotions, partial: 'promotions/promotion', as: :promotion
|
||||
17
app/views/settings/promotions/new.html.erb
Normal file
17
app/views/settings/promotions/new.html.erb
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
<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>
|
||||
<li>New</li>
|
||||
</ul>
|
||||
</div>
|
||||
<%= render 'form', promotion: @promotion %>
|
||||
</div>
|
||||
<script>
|
||||
$("#promotion_promo_code").val(Math.random().toString(36).slice(5) + Math.random().toString(36).slice(5));
|
||||
// $( "#fromtime" ).timepicker();
|
||||
// $( "#totime" ).timepicker({ 'scrollDefault': 'now' });
|
||||
$('#scrollDefaultExample').timepicker({ 'scrollDefault': 'now' });
|
||||
</script>
|
||||
4
app/views/settings/promotions/show.html.erb
Normal file
4
app/views/settings/promotions/show.html.erb
Normal file
@@ -0,0 +1,4 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<%= link_to 'Edit', edit_promotion_path(@promotion) %> |
|
||||
<%= link_to 'Back', promotions_path %>
|
||||
1
app/views/settings/promotions/show.json.jbuilder
Normal file
1
app/views/settings/promotions/show.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
||||
json.partial! "promotions/promotion", promotion: @promotion
|
||||
@@ -3,8 +3,8 @@ class CreatePromotion < ActiveRecord::Migration[5.1]
|
||||
create_table :promotions do |t|
|
||||
t.string :promo_code, :limit => 16
|
||||
|
||||
t.datetime :promo_start_date, :null => false
|
||||
t.datetime :promo_end_date, :null => false
|
||||
t.date :promo_start_date, :null => false
|
||||
t.date :promo_end_date, :null => false
|
||||
t.time :promo_start_hour, :null => false
|
||||
t.time :promo_end_hour, :null => false
|
||||
t.string :promo_day, :null => false, :default => "[0,1,2,3,4,5,6]"
|
||||
|
||||
Reference in New Issue
Block a user