Files
sx-fc/app/controllers/print_settings_controller.rb
2019-12-03 14:54:53 +06:30

93 lines
3.0 KiB
Ruby
Executable File

class PrintSettingsController < ApplicationController
load_and_authorize_resource except: [:create]
before_action :set_print_setting, only: [:show, :edit, :update, :destroy]
# GET /print_settings
# GET /print_settings.json
def index
@print_settings = PrintSetting.all
end
# GET /print_settings/1
# GET /print_settings/1.json
def show
@lookup = Lookup.shift_sale_items_lookup_value(Shop.current_shop.shop_code)
end
# GET /print_settings/new
def new
@print_setting = PrintSetting.new
@server_mode = ENV["SERVER_MODE"]
end
# GET /print_settings/1/edit
def edit
@lookup = Lookup.shift_sale_items_lookup_value(Shop.current_shop.shop_code)
@server_mode = ENV["SERVER_MODE"]
end
# POST /print_settings
# POST /print_settings.json
def create
@print_setting = PrintSetting.new(print_setting_params)
@print_setting.shop_code = Shop.current_shop.shop_code
respond_to do |format|
if @print_setting.save
format.html { redirect_to @print_setting, notice: 'Print setting was successfully created.' }
format.json { render :show, status: :created, location: @print_setting }
else
format.html { render :new }
format.json { render json: @print_setting.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /print_settings/1
# PATCH/PUT /print_settings/1.json
def update
respond_to do |format|
if @print_setting.update(print_setting_params)
if @print_setting.unique_code == 'CloseCashierPdf'
Lookup.save_shift_sale_items_settings(params[:shift_sale_items],Shop.current_shop.shop_code)
end
format.html { redirect_to @print_setting, notice: 'Print setting was successfully updated.' }
format.json { render :show, status: :ok, location: @print_setting }
else
format.html { render :edit }
format.json { render json: @print_setting.errors, status: :unprocessable_entity }
end
end
end
# DELETE /print_settings/1
# DELETE /print_settings/1.json
def destroy
@print_setting.destroy
flash[:notice] = 'Print setting was successfully destroyed.'
render :json => {:status=> "Success", :url => print_settings_url }.to_json
end
def get_printer_options
printer_name = params[:printer_name]
printer_options = Printer::PrinterWorker.printer_options(printer_name)
options = {
:url => printer_options['device-uri'],
:model => printer_options['printer-info'],
}
render :json => options.to_json
end
private
# Use callbacks to share common setup or constraints between actions.
def set_print_setting
@print_setting = PrintSetting.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def print_setting_params
params.require(:print_setting).permit(:name, :unique_code, :template, :printer_name, :font,:header_font_size, :item_font_size, :api_settings, :page_width, :page_height, :print_copies,:precision,:delimiter,:heading_space)
end
end