pos_configs_controller.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. class PosConfigsController < ApplicationController
  2. ##--- Breadcrum_rails
  3. add_breadcrumb I18n.t("breadcrumbs." + controller_name), :pos_configs_path
  4. before_action :set_pos_config, only: [:update, :destroy]
  5. # GET /pos_configs
  6. # GET /pos_configs.json
  7. def index
  8. @pos_config = PosConfig.first.blank? ? PosConfig.new : PosConfig.first
  9. end
  10. # POST /pos_configs
  11. # POST /pos_configs.json
  12. def create
  13. @pos_config = PosConfig.new(pos_config_params)
  14. @pos_config.skip_haggle_percent = true if params[:pos_config][:enable_haggle] == "false"
  15. respond_to do |format|
  16. if @pos_config.save
  17. format.html { redirect_to root_path, notice: 'Configuración de parámetros generales guardada correctamente.' }
  18. format.json { render :show, status: :created, location: @pos_config }
  19. else
  20. format.html { render action: "index" }
  21. format.json { render json: @pos_config.errors, status: :unprocessable_entity }
  22. end
  23. end
  24. end
  25. # PATCH/PUT /pos_configs/1
  26. # PATCH/PUT /pos_configs/1.json
  27. def update
  28. @pos_config.skip_haggle_percent = true if params[:pos_config][:enable_haggle] == "false"
  29. respond_to do |format|
  30. @pos_config.audit_comment = "Se actualizaron los parámetros generales"
  31. if @pos_config.update(pos_config_params)
  32. format.html { redirect_to root_path, notice: 'Configuración de parámetros generales guardada correctamente.' }
  33. format.json { render :show, status: :ok, location: @pos_config }
  34. else
  35. format.html { render action: "index" }
  36. format.json { render json: @pos_config.errors, status: :unprocessable_entity }
  37. end
  38. end
  39. end
  40. private
  41. # Use callbacks to share common setup or constraints between actions.
  42. def set_pos_config
  43. @pos_config = PosConfig.first
  44. end
  45. # Never trust parameters from the scary internet, only allow the white list through.
  46. def pos_config_params
  47. params[:pos_config]
  48. params.require(:pos_config).permit(:cancel_partial_payment, :refund_sale, :days_cancel_sale, :days_cancel_purchase, :tax_percent, :time_zone, :gain_margin, :ticket_description, :reserve_sale_percent, :days_cancel_reserved, :commission_percent, :ticket_footer, :ticket_img, :ticket_img_cache, :haggle_in_sale_percent, :enable_haggle)
  49. end
  50. end