|
|
@@ -4,9 +4,9 @@ class CashRegistersController < ApplicationController
|
|
|
|
|
|
##--- Breadcrum_rails
|
|
|
add_breadcrumb I18n.t("breadcrumbs." + controller_name), :cash_registers_path
|
|
|
- add_breadcrumb "Nueva Caja registradora " , :new_cash_register_path, only: :new
|
|
|
- add_breadcrumb "Detalle de la Caja registradora " , :cash_register_path, only: :show
|
|
|
- add_breadcrumb "Editar Caja registradora " , :edit_cash_register_path, only: :edit
|
|
|
+ add_breadcrumb "Nueva Caja registradora ", :new_cash_register_path, only: :new
|
|
|
+ add_breadcrumb "Detalle de la Caja registradora ", :cash_register_path, only: :show
|
|
|
+ add_breadcrumb "Editar Caja registradora ", :edit_cash_register_path, only: :edit
|
|
|
|
|
|
before_action :set_cash_register, only: [:show, :edit, :update, :destroy]
|
|
|
|
|
|
@@ -15,7 +15,7 @@ class CashRegistersController < ApplicationController
|
|
|
# GET /cash_registers
|
|
|
# GET /cash_registers.json
|
|
|
def index
|
|
|
- if current_user.usertype == 'A'
|
|
|
+ if current_user.usertype == "A" || current_user.usertype == "SS"
|
|
|
@cash_registers = CashRegister.vigentes.includes(:pointsale)
|
|
|
else
|
|
|
@cash_registers = CashRegister.includes(:pointsale).where(:pointsale_id => current_user.pointsale_id ).vigentes
|
|
|
@@ -24,8 +24,7 @@ class CashRegistersController < ApplicationController
|
|
|
|
|
|
# GET /cash_registers/1
|
|
|
# GET /cash_registers/1.json
|
|
|
- def show
|
|
|
- end
|
|
|
+ def show; end
|
|
|
|
|
|
# GET /cash_registers/new
|
|
|
def new
|
|
|
@@ -33,8 +32,7 @@ class CashRegistersController < ApplicationController
|
|
|
end
|
|
|
|
|
|
# GET /cash_registers/1/edit
|
|
|
- def edit
|
|
|
- end
|
|
|
+ def edit; end
|
|
|
|
|
|
# POST /cash_registers
|
|
|
# POST /cash_registers.json
|
|
|
@@ -43,10 +41,11 @@ class CashRegistersController < ApplicationController
|
|
|
@cash_register.pointsale_id = @current_user.pointsale_id
|
|
|
respond_to do |format|
|
|
|
if @cash_register.save
|
|
|
- format.html { redirect_to cash_registers_url, success: "La caja " + @cash_register.name + " fue registrada." }
|
|
|
- format.json { render :show, status: :created, location: @cash_register }
|
|
|
+ format.html { redirect_to cash_registers_url, success: "La caja " + @cash_register.name + " fue registrada." }
|
|
|
+ format.js
|
|
|
else
|
|
|
format.html { render :new }
|
|
|
+ format.js
|
|
|
format.json { render json: @cash_register.errors, status: :unprocessable_entity }
|
|
|
end
|
|
|
end
|
|
|
@@ -56,31 +55,30 @@ class CashRegistersController < ApplicationController
|
|
|
# PATCH/PUT /cash_registers/1.json
|
|
|
def update
|
|
|
respond_to do |format|
|
|
|
- cash_register_opened = OpenCashRegister.where(:cash_register_id => @cash_register.id, :status => 0).any?
|
|
|
-
|
|
|
+ cash_register_opened = OpenCashRegister.where(cash_register_id: @cash_register.id, status: 0).any?
|
|
|
if cash_register_opened == true && params[:cash_register][:status] == 'inactive'
|
|
|
@cash_register.errors.add(:status, "No se puede desactivar una caja abierta.")
|
|
|
format.html { render :edit }
|
|
|
+ format.js
|
|
|
format.json { render json: @cash_register.errors, status: :unprocessable_entity }
|
|
|
else
|
|
|
@cash_register.update(cash_register_params)
|
|
|
- format.html { redirect_to cash_registers_url, success: "La caja " + @cash_register.name + " fue modificada." }
|
|
|
- format.json { render :show, status: :ok, location: @cash_register }
|
|
|
+ format.js
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def update_status
|
|
|
cash_register = CashRegister.find(params[:cash_register_id])
|
|
|
- puts cash_register.active?
|
|
|
- if cash_register.active?
|
|
|
- cash_register.status = 2
|
|
|
- elsif cash_register.inactive?
|
|
|
- cash_register.status = 1
|
|
|
- end
|
|
|
+ cash_register.status =
|
|
|
+ if cash_register.active?
|
|
|
+ 2
|
|
|
+ elsif cash_register.inactive?
|
|
|
+ 1
|
|
|
+ end
|
|
|
respond_to do |format|
|
|
|
- if cash_register.save(:validate => false)
|
|
|
- format.html { redirect_to cash_registers_url, warning: "La caja registradora " + cash_register.name + " fue "+ (cash_register.active? ? "activada" : "desactivada")+"." }
|
|
|
+ if cash_register.save(validate: false)
|
|
|
+ format.html { redirect_to cash_registers_url, warning: "La caja registradora " + cash_register.name + " fue " + (cash_register.active? ? "activada" : "desactivada") + "." }
|
|
|
# format.json { render :show, status: :ok, location: @pointsale }
|
|
|
format.json { head :no_content }
|
|
|
else
|
|
|
@@ -106,7 +104,7 @@ class CashRegistersController < ApplicationController
|
|
|
format.html { redirect_to cash_registers_url, warning: "La caja " + @cash_register.name + " no se puede eliminar por ser la principal." }
|
|
|
format.json { render json: @cash_register.errors, status: :unprocessable_entity }
|
|
|
else
|
|
|
- @cash_register.update_attributes(:status => 0)
|
|
|
+ @cash_register.update_attributes(status: 0)
|
|
|
format.html { redirect_to cash_registers_url, warning: "La caja " + @cash_register.name + " fue eliminada." }
|
|
|
format.json { head :no_content }
|
|
|
end
|
|
|
@@ -120,13 +118,13 @@ class CashRegistersController < ApplicationController
|
|
|
end
|
|
|
|
|
|
private
|
|
|
- # Use callbacks to share common setup or constraints between actions.
|
|
|
- def set_cash_register
|
|
|
- @cash_register = CashRegister.find(params[:id])
|
|
|
- end
|
|
|
+ # Use callbacks to share common setup or constraints between actions.
|
|
|
+ def set_cash_register
|
|
|
+ @cash_register = CashRegister.find(params[:id])
|
|
|
+ end
|
|
|
|
|
|
- # Never trust parameters from the scary internet, only allow the white list through.
|
|
|
- def cash_register_params
|
|
|
- params.require(:cash_register).permit(:name, :description, :pointsale_id, :status)
|
|
|
- end
|
|
|
+ # Never trust parameters from the scary internet, only allow the white list through.
|
|
|
+ def cash_register_params
|
|
|
+ params.require(:cash_register).permit(:name, :description, :pointsale_id, :status)
|
|
|
+ end
|
|
|
end
|