Commit 88a553cf authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei

Merge branch 'Issue#134' into 'master'

Issue#134

See merge request !243
parents c293436c 4b41177c
...@@ -22,10 +22,6 @@ class SchedulesController < ApplicationController ...@@ -22,10 +22,6 @@ class SchedulesController < ApplicationController
# GET /schedules # GET /schedules
# GET /schedules.json # GET /schedules.json
def index def index
if @citizen.nil? and params[:cpf]
@form_error = "O CPF digitado é inválido ou o cidadão não foi cadastrado!"
end
if params[:clear_cpf] if params[:clear_cpf]
session[:cpf] = nil unless session[:cpf].nil? session[:cpf] = nil unless session[:cpf].nil?
end end
...@@ -46,6 +42,14 @@ class SchedulesController < ApplicationController ...@@ -46,6 +42,14 @@ class SchedulesController < ApplicationController
else else
@citizen = Citizen.where(:cpf => params[:cpf]).first @citizen = Citizen.where(:cpf => params[:cpf]).first
if @citizen if @citizen
if !@citizen.nil? and !CityHall.where(city_id: @citizen.city_id).first.active?
return redirect_to :back, alert: "O cidadão pertence a uma cidade inativa!"
end
if @citizen.nil? and params[:cpf]
return redirect_to :back, alert: "O CPF digitado é inválido ou o cidadão não foi cadastrado!"
end
@dependants = Citizen.where(responsible_id: @citizen.id) @dependants = Citizen.where(responsible_id: @citizen.id)
if @currentProfessionalServicePlace.role != "adm_c3sl" if @currentProfessionalServicePlace.role != "adm_c3sl"
if @citizen.city_id != @currentCityHall.city_id if @citizen.city_id != @currentCityHall.city_id
...@@ -66,7 +70,7 @@ class SchedulesController < ApplicationController ...@@ -66,7 +70,7 @@ class SchedulesController < ApplicationController
@chosen = params[:chosen] @chosen = params[:chosen]
@citizen = Citizen.find(@chosen) @citizen = Citizen.find(@chosen)
selected = Citizen.where(cpf: session[:cpf]).first.id selected = Citizen.where(cpf: session[:cpf]).first.id
if @citizen.responsible_id != selected && @citizen.id != selected if @citizen.responsible_id != selected && @citizen.id != selected
return redirect_to root_path, alert: "Selecione o cidadão correspondente ao CPF escolhido." return redirect_to root_path, alert: "Selecione o cidadão correspondente ao CPF escolhido."
end end
session[:chosen] = @chosen session[:chosen] = @chosen
...@@ -110,7 +114,7 @@ class SchedulesController < ApplicationController ...@@ -110,7 +114,7 @@ class SchedulesController < ApplicationController
if @currentProfessionalServicePlace.role == "adm_c3sl" if @currentProfessionalServicePlace.role == "adm_c3sl"
# As adm_c3sl # As adm_c3sl
# Get all active sectors # Get all active sectors
if(@citizen != nil) if @citizen != nil
@city_hall_id = CityHall.active.where(city_id: @citizen.city.id).first.id @city_hall_id = CityHall.active.where(city_id: @citizen.city.id).first.id
@sectors = Sector.active.where(city_hall_id: @city_hall_id) @sectors = Sector.active.where(city_hall_id: @city_hall_id)
else else
......
...@@ -235,6 +235,7 @@ class Citizen < ActiveRecord::Base ...@@ -235,6 +235,7 @@ class Citizen < ActiveRecord::Base
############################## ##############################
validates_presence_of :name, :birth_date validates_presence_of :name, :birth_date
validates_presence_of :rg, :cep, :phone1, :if => :cpf_required? validates_presence_of :rg, :cep, :phone1, :if => :cpf_required?
validates_presence_of :city
validates_with PhonesValidator, fields: [:phone1, :phone2] validates_with PhonesValidator, fields: [:phone1, :phone2]
validates_with EmailValidator validates_with EmailValidator
validates_length_of :name, maximum: 255 validates_length_of :name, maximum: 255
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment