commission update -> change route under settings
This commit is contained in:
@@ -1,75 +0,0 @@
|
||||
class Origami::CommissionersController < BaseOrigamiController
|
||||
before_action :set_commissioner, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /commissioners
|
||||
# GET /commissioners.json
|
||||
def index
|
||||
@commissioners = Commissioner.all.order("id asc")
|
||||
end
|
||||
|
||||
# GET /commissioners/1
|
||||
# GET /commissioners/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /commissioners/new
|
||||
def new
|
||||
@commissioner = Commissioner.new
|
||||
@employee = Employee.all.order('name asc')
|
||||
end
|
||||
|
||||
# GET /commissioners/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /commissioners
|
||||
# POST /commissioners.json
|
||||
def create
|
||||
@commissioner = Commissioner.new(commissioner_params)
|
||||
@commissioner.created_by = current_user.id
|
||||
respond_to do |format|
|
||||
if @commissioner.save
|
||||
format.html { redirect_to origami_commissioners_path , notice: 'Commissioner was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @commissioner }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @commissioner.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /commissioners/1
|
||||
# PATCH/PUT /commissioners/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @commissioner.update(commissioner_params)
|
||||
format.html { redirect_to origami_commissioner_path(@commissioner) , notice: 'Commissioner was successfully updated.' }
|
||||
format.json { render :show, status: :ok, location: @commissioner }
|
||||
else
|
||||
format.html { render :edit }
|
||||
format.json { render json: @commissioner.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /commissioners/1
|
||||
# DELETE /commissioners/1.json
|
||||
def destroy
|
||||
@commissioner.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to origami_commissioners_path , notice: 'Commissioner was successfully destroyed.' }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_commissioner
|
||||
@commissioner = Commissioner.find(params[:id])
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def commissioner_params
|
||||
params.require(:commissioner).permit(:name,:emp_id,:created_by,:commission_type, :is_active)
|
||||
end
|
||||
end
|
||||
@@ -1,101 +0,0 @@
|
||||
class Origami::CommissionsController < BaseOrigamiController
|
||||
before_action :set_commission, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /commissions
|
||||
# GET /commissions.json
|
||||
def index
|
||||
@commissions = Commission.all
|
||||
end
|
||||
|
||||
# GET /commissions/1
|
||||
# GET /commissions/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /commissions/new
|
||||
def new
|
||||
@commission = Commission.new
|
||||
@products = MenuItem.all
|
||||
end
|
||||
|
||||
# GET /commissions/1/edit
|
||||
def edit
|
||||
@products = MenuItem.all
|
||||
end
|
||||
|
||||
# POST /commissions
|
||||
# POST /commissions.json
|
||||
def create
|
||||
@commission = Commission.new(commission_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @commission.save
|
||||
format.html {redirect_to origami_commissions_path, notice: 'Commission was successfully created.'}
|
||||
format.json {render :show, status: :created, location: @commission}
|
||||
else
|
||||
format.html {render :new}
|
||||
format.json {render json: @commission.errors, status: :unprocessable_entity}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /commissions/1
|
||||
# PATCH/PUT /commissions/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @commission.update(commission_params)
|
||||
format.html {redirect_to origami_commission_path(@commission), notice: 'Commission was successfully updated.'}
|
||||
format.json {render :show, status: :ok, location: @commission}
|
||||
else
|
||||
format.html {render :edit}
|
||||
format.json {render json: @commission.errors, status: :unprocessable_entity}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /commissions/1
|
||||
# DELETE /commissions/1.json
|
||||
def destroy
|
||||
@commission.destroy
|
||||
respond_to do |format|
|
||||
format.html {redirect_to origami_commissions_path, notice: 'Commission was successfully destroyed.'}
|
||||
format.json {head :no_content}
|
||||
end
|
||||
end
|
||||
|
||||
def load_commissioners
|
||||
sale_id = params[:sale_id]
|
||||
@table_id = params[:table_id]
|
||||
@saleobj = Sale.find(sale_id)
|
||||
|
||||
@commissioners = []
|
||||
end
|
||||
|
||||
def select_sale_item
|
||||
# byebug
|
||||
sale_item_id = params[:sale_item_id]
|
||||
@selected_sale_item = SaleItem.find_by_sale_item_id(sale_item_id)
|
||||
@product_commission = ProductCommission.find_by_sale_item_id(@selected_sale_item.id)
|
||||
unless @product_commission.nil?
|
||||
selected_commissioner = @product_commission.commissioner
|
||||
end
|
||||
@commissioners = Commissioner.active.all
|
||||
|
||||
# respond_to do |format|
|
||||
# format.json {render json: {[@commissioners],[@selected_sale_item]}}
|
||||
# # format.html {render @commissioners}
|
||||
# end
|
||||
render json: {commissioner: @commissioners, selected_commissioner: selected_commissioner}
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_commission
|
||||
@commission = Commission.find(params[:id])
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def commission_params
|
||||
params.require(:commission).permit(:product_id, :amount, :commission_type, :is_active)
|
||||
end
|
||||
end
|
||||
@@ -62,15 +62,16 @@ class Origami::ProductCommissionsController < ApplicationController
|
||||
end
|
||||
|
||||
def set_commissioner_to_sale_item
|
||||
# byebug
|
||||
deselect = false
|
||||
sale_item_id = params[:sale_item_id]
|
||||
commissioner_id = params[:commissioner_id]
|
||||
@sale_item = SaleItem.find(sale_item_id)
|
||||
@menu_item = MenuItem.find_by_item_code(@sale_item.product_code)
|
||||
@commission = Commission.where('product_id = ? AND is_active = ?', @menu_item.id, true).take
|
||||
@commission = Commission.where('product_code = ? AND is_active = ?', @menu_item.id, true).take
|
||||
@commissioner = Commissioner.where('id = ? AND is_active = ?', commissioner_id, true).take
|
||||
@product_commission = ProductCommission.where('sale_item_id = ?', @sale_item.id).take
|
||||
# byebug
|
||||
|
||||
if !@product_commission.nil?
|
||||
if @product_commission.commissioner_id == @commissioner.id
|
||||
@product_commission.destroy
|
||||
@@ -81,7 +82,8 @@ class Origami::ProductCommissionsController < ApplicationController
|
||||
end
|
||||
else
|
||||
@product_commission = ProductCommission.new
|
||||
@product_commission.product_id = @menu_item.id
|
||||
@product_commission.product_code = @menu_item.id
|
||||
@product_commission.product_type = 'menu_item' # use for dummy data ToDo::need to change product type
|
||||
unless @commission.nil?
|
||||
@product_commission.commission_id = @commission.id
|
||||
if @commission.commission_type == 'Percentage'
|
||||
|
||||
Reference in New Issue
Block a user