Files
sx-fc/app/controllers/origami/surveys_controller.rb
2018-02-16 12:13:35 +06:30

74 lines
2.3 KiB
Ruby

class Origami::SurveysController < BaseOrigamiController
def new
@survey = Survey.new
@id = params[:id]
if(@id[0,3] == "SAL")
@sale = Sale.find(@id)
@receipt_no = @sale.receipt_no
@grand_total = @sale.grand_total
@booking = Booking.find_by_sale_id(@id)
@dining_facility = DiningFacility.find(@booking.dining_facility_id)
@table_type = @dining_facility.type
else
@dining_facility = DiningFacility.find(@id)
@table_type = @dining_facility.type
@receipt_no = nil
@grand_total = nil
end
end
def create
@dining_facility = DiningFacility.find(params[:table_id])
@url = "/origami/"+@dining_facility.type.downcase+"/"+params[:table_id]
@survey = Survey.new(survey_params)
@survey.foreigner = params["survey"]["foreigner"].to_json
# respond_to do |format|
if @survey.save
redirect_to @url
end
# end
end
def create_survey
if shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0].id)
dining_facility = DiningFacility.find(params[:dining_id])
cashier_zone = CashierTerminalByZone.find_by_zone_id(dining_facility.zone_id)
shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil)
survey = Survey.find_by_receipt_no(params[:receipt_no])
if survey.nil?
survey = Survey.new
survey.dining_name = dining_facility.name
survey.receipt_no = params[:receipt_no]
survey.shift_id = shift_by_terminal.id
survey.created_by = current_user.name
survey.total_customer = params[:total_customer]
survey.total_amount = params[:total_amount]
survey.save!
else
survey.total_customer = params[:total_customer]
survey.save!
end
render :json => {status: true}
else
render :json => { status: false, error_message: 'No Current Open Shift!'}
end
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def survey_params
params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner, :dining_name,:receipt_no,:shift_id,:created_by,:total_customer,:total_amount)
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
end