This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\Estabelecimento;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SalaRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
|
||||
case 'POST':
|
||||
case 'PUT': {
|
||||
|
||||
return $this->getPostPutRules();
|
||||
}
|
||||
default: {
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostPutRules()
|
||||
{
|
||||
return [
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,30',
|
||||
Rule::unique('\App\Models\Cadastro\Estabelecimento\Sala', 'nome')
|
||||
->where(function ($query) {
|
||||
|
||||
return $query
|
||||
->where('centro_custo_id', $this->centro_custo_id)
|
||||
->whereNull('deleted_at');
|
||||
})
|
||||
->ignore($this->sala)
|
||||
],
|
||||
'centro_custo_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'nome.unique' => 'O nome da Sala já foi inserido anteriormente.'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\Estabelecimento;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SetorRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch($this->method()) {
|
||||
case 'POST':
|
||||
return $this->getPostRules();
|
||||
case 'PUT':
|
||||
return $this->getPutRules();
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostRules()
|
||||
{
|
||||
return [
|
||||
'tipo_id' => ['required'],
|
||||
'servico_id' => ['required', 'integer'],
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,180',
|
||||
Rule::unique('\App\Models\Cadastro\Estabelecimento\Setor')->where(function ($query) {
|
||||
return $query
|
||||
->where('servico_id', $this->servico_id)
|
||||
->whereNull('deleted_at');
|
||||
}),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
return [
|
||||
'tipo_id' => ['required'],
|
||||
'servico_id' => ['required', 'integer'],
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,180',
|
||||
Rule::unique('\App\Models\Cadastro\Estabelecimento\Setor')->where(function ($query) {
|
||||
return $query
|
||||
->where('servico_id', $this->servico_id)
|
||||
->whereNull('deleted_at');
|
||||
})->ignore($this->setor),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'nome.unique' => 'Um Setor com o mesmo Serviço e Nome já foi inserido anteriormente.'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\Estabelecimento;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
use App\Rules\CnsTermoValido;
|
||||
|
||||
class UnidadeExternaRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$regex = '/[^a-zA-Z0-9áéíóúâêîôûãõäëïöüÁÉÍÓÚÂÊÎÔÛÃÕÄËÏÖÜ\'()\/,\s-]/';
|
||||
|
||||
return [
|
||||
'nome_fantasia' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,255',
|
||||
'not_regex:' . $regex,
|
||||
new CnsTermoValido(['attribute' => 'Nome Fantasia'])
|
||||
],
|
||||
'municipio_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
'exists:\App\Models\Intranet\Municipio,id'
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,348 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\Estabelecimento;
|
||||
|
||||
use App\Rules\CnsTermoValido;
|
||||
use App\Rules\Cnpj;
|
||||
use App\Http\Requests\FormRequest;
|
||||
use App\Utils\ImportacaoCns;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UnidadeRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
|
||||
case 'POST': {
|
||||
|
||||
return $this->getPostRules();
|
||||
}
|
||||
case 'PUT': {
|
||||
|
||||
return $this->getPutRules();
|
||||
}
|
||||
default: {
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostRules()
|
||||
{
|
||||
return [
|
||||
'nome_fantasia' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,255',
|
||||
'unique:\App\Models\Cadastro\Estabelecimento\Unidade,nome_fantasia,NULL,id,deleted_at,NULL'
|
||||
],
|
||||
'razao_social' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,255',
|
||||
],
|
||||
'cnpj' => [
|
||||
'nullable',
|
||||
'digits:14',
|
||||
new Cnpj(['attribute' => 'CNPJ']),
|
||||
],
|
||||
'tipo_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'esfera_administrativa_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'natureza_juridica_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'pertence_sus' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'unidade_referencia' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'unidade_prestadora' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'gestor_id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'cnes' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'between:7,7',
|
||||
],
|
||||
'email' => [
|
||||
'nullable',
|
||||
'email:rfc,dns',
|
||||
'max:180'
|
||||
],
|
||||
'site' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:180'
|
||||
],
|
||||
'infraestruturas' => [
|
||||
'required',
|
||||
'array'
|
||||
],
|
||||
'infraestruturas.*.infraestrutura_id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'infraestruturas.*.principal' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'infraestruturas.*.nome' => [
|
||||
'nullable',
|
||||
'required_if:infraestruturas.*.principal,0',
|
||||
'string',
|
||||
'between:3,255',
|
||||
],
|
||||
'infraestruturas.*.telefone' => [
|
||||
'required',
|
||||
'digits_between:10,11'
|
||||
],
|
||||
'infraestruturas.*.endereco' => [
|
||||
'required',
|
||||
'array'
|
||||
],
|
||||
'infraestruturas.*.endereco.logradouro_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'infraestruturas.*.endereco.numero' => [
|
||||
'nullable',
|
||||
'digits_between:1,6',
|
||||
],
|
||||
'infraestruturas.*.endereco.complemento' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'not_regex:' . ImportacaoCns::regexValidacao(),
|
||||
new CnsTermoValido(['attribute' => 'Complemento'])
|
||||
],
|
||||
'infraestruturas.*.endereco.zona_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
],
|
||||
'infraestruturas.*.centros_custo' => [
|
||||
'array'
|
||||
],
|
||||
'infraestruturas.*.centros_custo.*.setor_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'infraestruturas.*.centros_custo.*.salas' => [
|
||||
'array'
|
||||
],
|
||||
'infraestruturas.*.centros_custo.*.salas.*.nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,30',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
$custom = [];
|
||||
|
||||
if (is_array($this->infraestruturas)) {
|
||||
|
||||
foreach ($this->infraestruturas as $i => $infraestrutura) {
|
||||
|
||||
if (isset($infraestrutura['centros_custo'])) {
|
||||
|
||||
foreach ($infraestrutura['centros_custo'] as $j => $centroCusto) {
|
||||
|
||||
$custom["infraestruturas.{$i}.centros_custo.{$j}.setor_id"] = [
|
||||
'required',
|
||||
'integer',
|
||||
Rule::unique('\App\Models\Cadastro\Estabelecimento\CentroCusto', 'setor_id')
|
||||
->where(function ($query) use ($infraestrutura) {
|
||||
|
||||
return $query
|
||||
->where('infraestrutura_id', $infraestrutura['id'] ?? null)
|
||||
->whereNull('deleted_at');
|
||||
})
|
||||
->ignore($centroCusto['id'] ?? null)
|
||||
];
|
||||
|
||||
if (isset($centroCusto['salas'])) {
|
||||
|
||||
foreach ($centroCusto['salas'] as $k => $sala) {
|
||||
|
||||
$custom["infraestruturas.{$i}.centros_custo.{$j}.salas.{$k}.nome"] = [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,30',
|
||||
Rule::unique('\App\Models\Cadastro\Estabelecimento\Sala', 'nome')
|
||||
->where(function ($query) use ($centroCusto) {
|
||||
|
||||
return $query
|
||||
->where('centro_custo_id', $centroCusto['id'] ?? null)
|
||||
->whereNull('deleted_at');
|
||||
})
|
||||
->ignore($sala['id'] ?? null)
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge([
|
||||
'nome_fantasia' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,255',
|
||||
"unique:\App\Models\Cadastro\Estabelecimento\Unidade,nome_fantasia,{$this->unidade},id,deleted_at,NULL"
|
||||
],
|
||||
'razao_social' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,255',
|
||||
],
|
||||
'cnpj' => [
|
||||
'nullable',
|
||||
'digits:14',
|
||||
new Cnpj(['attribute' => 'CNPJ']),
|
||||
],
|
||||
'tipo_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'esfera_administrativa_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'natureza_juridica_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'pertence_sus' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'unidade_referencia' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'unidade_prestadora' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'gestor_id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'cnes' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'between:7,7',
|
||||
],
|
||||
'email' => [
|
||||
'nullable',
|
||||
'email:rfc,dns',
|
||||
'max:180'
|
||||
],
|
||||
'site' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:180'
|
||||
],
|
||||
'infraestruturas' => [
|
||||
'required',
|
||||
'array'
|
||||
],
|
||||
'infraestruturas.*.id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'infraestruturas.*.principal' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'infraestruturas.*.nome' => [
|
||||
'nullable',
|
||||
'required_if:infraestruturas.*.principal,0',
|
||||
'string',
|
||||
'between:3,255',
|
||||
],
|
||||
'infraestruturas.*.telefone' => [
|
||||
'required',
|
||||
'digits_between:10,11'
|
||||
],
|
||||
'infraestruturas.*.endereco' => [
|
||||
'required',
|
||||
'array'
|
||||
],
|
||||
'infraestruturas.*.endereco.logradouro_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'infraestruturas.*.endereco.numero' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
'max:999999',
|
||||
],
|
||||
'infraestruturas.*.endereco.complemento' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'not_regex:' . ImportacaoCns::regexValidacao(),
|
||||
new CnsTermoValido(['attribute' => 'Complemento'])
|
||||
],
|
||||
'infraestruturas.*.endereco.zona_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
],
|
||||
'infraestruturas.*.centros_custo' => [
|
||||
'array'
|
||||
],
|
||||
'infraestruturas.*.centros_custo.*.id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'infraestruturas.*.centros_custo.*.salas' => [
|
||||
'array'
|
||||
],
|
||||
'infraestruturas.*.centros_custo.*.salas.*.id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
]
|
||||
], $custom);
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'nome_fantasia.unique' => 'Já existe uma unidade com o Nome fantasia informado.',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user