Merge branch 'august_spring' of bitbucket.org:code2lab/sxrestaurant
This commit is contained in:
@@ -74,13 +74,18 @@ class Origami::CommissionsController < BaseOrigamiController
|
||||
def select_sale_item
|
||||
# byebug
|
||||
sale_item_id = params[:sale_item_id]
|
||||
@sale_item = SaleItem.find_by_sale_item_id(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}
|
||||
# format.html {render @commissioners}
|
||||
end
|
||||
# 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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Origami::InJutiesController < BaseOrigamiController
|
||||
before_action :set_in_juty, only: [:show, :edit, :update,:edit_in_juty, :update_for_in_juty , :destroy ,:destroy_in_juty]
|
||||
before_action :set_in_juty, only: [:show, :edit, :update, :edit_in_juty, :update_for_in_juty , :destroy ,:destroy_in_juty]
|
||||
|
||||
# GET /in_juties
|
||||
# GET /in_juties.json
|
||||
@@ -9,6 +9,9 @@ class Origami::InJutiesController < BaseOrigamiController
|
||||
|
||||
def index_in_juty
|
||||
@juties_in= InJuty.where("dinning_id=?",params[:table_id])
|
||||
@table = DiningFacility.find(params[:table_id])
|
||||
@in_juty = InJuty.new
|
||||
|
||||
end
|
||||
# GET /in_juties/1
|
||||
# GET /in_juties/1.json
|
||||
@@ -22,9 +25,11 @@ class Origami::InJutiesController < BaseOrigamiController
|
||||
|
||||
# GET /in_juties/1/edit
|
||||
def edit
|
||||
|
||||
end
|
||||
|
||||
def edit_in_juty
|
||||
@in_juty = InJuty.find(params[:id])
|
||||
@table = DiningFacility.find(params[:table_id])
|
||||
end
|
||||
|
||||
@@ -49,12 +54,24 @@ class Origami::InJutiesController < BaseOrigamiController
|
||||
end
|
||||
|
||||
def create_for_in_juty
|
||||
@in_juty = InJuty.new
|
||||
|
||||
@in_juty.dinning_id = in_juty_params[:dinning_id]
|
||||
@in_juty.commissioner_ids = in_juty_params[:commissioner_ids]
|
||||
@in_juty.in_time = in_juty_params[:in_time]
|
||||
@in_juty.out_time = in_juty_params[:out_time]
|
||||
|
||||
|
||||
respond_to do |format|
|
||||
if @in_juty.save
|
||||
format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @in_juty }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @in_juty.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
|
||||
@in_juty.dinning_id = params[:dining_id]
|
||||
@in_juty.commissioner_ids = params[:commissioner_ids]
|
||||
@in_juty.in_time = params[:in_time]
|
||||
@in_juty.out_time = params[:out_time]
|
||||
@in_juty.save
|
||||
end
|
||||
|
||||
# PATCH/PUT /in_juties/1
|
||||
@@ -77,7 +94,7 @@ class Origami::InJutiesController < BaseOrigamiController
|
||||
@in_juty.commissioner_ids = params[:commissioner_ids]
|
||||
@in_juty.in_time = params[:in_time]
|
||||
@in_juty.out_time = params[:out_time]
|
||||
@in_juty.update
|
||||
@in_juty.save
|
||||
end
|
||||
|
||||
# DELETE /in_juties/1
|
||||
@@ -91,9 +108,11 @@ class Origami::InJutiesController < BaseOrigamiController
|
||||
end
|
||||
|
||||
def destroy_in_juty
|
||||
@table_id = params[:table_id]
|
||||
@in_juty.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to origami_in_juties_path, notice: 'In juty was successfully destroyed.' }
|
||||
format.html { redirect_to origami_index_in_juty_path(@table_id), notice: 'In juty was successfully destroyed.' }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,11 +28,11 @@ class Origami::ProductCommissionsController < ApplicationController
|
||||
|
||||
respond_to do |format|
|
||||
if @product_commission.save
|
||||
format.html { redirect_to @product_commission, notice: 'Product commission was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @product_commission }
|
||||
format.html {redirect_to @product_commission, notice: 'Product commission was successfully created.'}
|
||||
format.json {render :show, status: :created, location: @product_commission}
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @product_commission.errors, status: :unprocessable_entity }
|
||||
format.html {render :new}
|
||||
format.json {render json: @product_commission.errors, status: :unprocessable_entity}
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -42,11 +42,11 @@ class Origami::ProductCommissionsController < ApplicationController
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @product_commission.update(product_commission_params)
|
||||
format.html { redirect_to @product_commission, notice: 'Product commission was successfully updated.' }
|
||||
format.json { render :show, status: :ok, location: @product_commission }
|
||||
format.html {redirect_to @product_commission, notice: 'Product commission was successfully updated.'}
|
||||
format.json {render :show, status: :ok, location: @product_commission}
|
||||
else
|
||||
format.html { render :edit }
|
||||
format.json { render json: @product_commission.errors, status: :unprocessable_entity }
|
||||
format.html {render :edit}
|
||||
format.json {render json: @product_commission.errors, status: :unprocessable_entity}
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -56,19 +56,62 @@ class Origami::ProductCommissionsController < ApplicationController
|
||||
def destroy
|
||||
@product_commission.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to product_commissions_url, notice: 'Product commission was successfully destroyed.' }
|
||||
format.json { head :no_content }
|
||||
format.html {redirect_to product_commissions_url, notice: 'Product commission was successfully destroyed.'}
|
||||
format.json {head :no_content}
|
||||
end
|
||||
end
|
||||
|
||||
def set_commissioner_to_sale_item
|
||||
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
|
||||
@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
|
||||
deselect = true
|
||||
else
|
||||
@product_commission.commissioner_id = @commissioner.id
|
||||
deselect = false
|
||||
end
|
||||
else
|
||||
@product_commission = ProductCommission.new
|
||||
@product_commission.product_id = @menu_item.id
|
||||
unless @commission.nil?
|
||||
@product_commission.commission_id = @commission.id
|
||||
if @commission.commission_type == 'Percentage'
|
||||
@product_commission.price = @sale_item.unit_price * (@commission.amount / 100.0)
|
||||
@product_commission.amount = @product_commission.price * @sale_item.qty
|
||||
elsif @commission.commission_type == 'Net Amount'
|
||||
@product_commission.price = @commission.amount
|
||||
@product_commission.amount = @product_commission.price * @sale_item.qty
|
||||
end
|
||||
end
|
||||
@product_commission.commissioner_id = @commissioner.id
|
||||
@product_commission.qty = @sale_item.qty
|
||||
@product_commission.sale_id = @sale_item.sale_id
|
||||
@product_commission.sale_item_id = @sale_item.sale_item_id
|
||||
end
|
||||
if @product_commission.save
|
||||
render json: {status: true, deselect: deselect}
|
||||
else
|
||||
render json: {status: false, deselect: deselect}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_product_commission
|
||||
@product_commission = ProductCommission.find(params[:id])
|
||||
end
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_product_commission
|
||||
@product_commission = ProductCommission.find(params[:id])
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def product_commission_params
|
||||
params.fetch(:product_commission, {})
|
||||
end
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def product_commission_params
|
||||
params.fetch(:product_commission, {})
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user