This commit is contained in:
51
api/app/Services/Sigtap/OcupacaoService.php
Normal file
51
api/app/Services/Sigtap/OcupacaoService.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Sigtap;
|
||||
|
||||
use App\Services\Service;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Enums\Sigtap\OcupacaoInativa;
|
||||
|
||||
class OcupacaoService extends Service
|
||||
{
|
||||
public static function autocomplete()
|
||||
{
|
||||
$excludedValues = [
|
||||
OcupacaoInativa::PROFISSIONAL_EDUCACAO_FISICA_SAUDE,
|
||||
];
|
||||
|
||||
$ocupacoes = DB::table('sigtap.ocupacao')
|
||||
->whereNotIn('sigtap.ocupacao.codigo', $excludedValues);
|
||||
|
||||
if (request()->query('procedimento_id')) {
|
||||
|
||||
$procedimentoRequerCbo = DB::table('sigtap.ocupacao')
|
||||
->whereExists(function ($query) {
|
||||
$query->select(DB::raw(1))
|
||||
->from('sigtap.procedimento_ocupacao')
|
||||
->whereColumn('procedimento_ocupacao.ocupacao_id', 'ocupacao.id')
|
||||
->where('procedimento_ocupacao.procedimento_id', request()->query('procedimento_id'));
|
||||
})->exists();
|
||||
|
||||
if ($procedimentoRequerCbo) {
|
||||
$ocupacoes->whereExists(function($query) {
|
||||
$query->select(DB::raw(1))
|
||||
->from('sigtap.procedimento_ocupacao')
|
||||
->whereColumn('procedimento_ocupacao.ocupacao_id', 'ocupacao.id')
|
||||
->where('procedimento_ocupacao.procedimento_id', request()->query('procedimento_id'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (request()->query('usuario_id')) {
|
||||
$ocupacoes->whereExists(function($query) {
|
||||
$query->select(DB::raw(1))
|
||||
->from('cadastro_lotacao')
|
||||
->whereColumn('cadastro_lotacao.ocupacao_id', 'ocupacao.id')
|
||||
->where('cadastro_lotacao.usuario_id', request()->query('usuario_id'));
|
||||
});
|
||||
}
|
||||
|
||||
return $ocupacoes;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user