You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.6 KiB
48 lines
1.6 KiB
<?php |
|
|
|
namespace app\Actions; |
|
|
|
use app\Models\SupervisorModel; |
|
use app\Repositories\AtendimentoRepository; |
|
use app\Repositories\EventosUsuarioRepository; |
|
use app\Repositories\SupervisorRepository; |
|
use Exception; |
|
|
|
class EntrarPausaAction |
|
{ |
|
private SupervisorRepository $supervisorRepository; |
|
private EventosUsuarioRepository $eventosUsuarioRepository; |
|
private AtendimentoRepository $atendimentoRepository; |
|
|
|
function __construct() |
|
{ |
|
$this->supervisorRepository = new SupervisorRepository; |
|
$this->eventosUsuarioRepository = new EventosUsuarioRepository; |
|
$this->atendimentoRepository = new AtendimentoRepository; |
|
} |
|
function __invoke(SupervisorModel $agent, $pause): string |
|
{ |
|
$atendimentosAbertos = $this->atendimentoRepository->getAtendimentoAbertoByAgente($agent->matricula); |
|
$statusAgente = !empty($atendimentosAbertos) ? CONF_AGENT_STATUS_INDISPONIVEL : CONF_AGENT_STATUS_PAUSA; |
|
if (!$this->supervisorRepository->update( |
|
[ |
|
'matricula' => $agent->matricula, |
|
'status' => $statusAgente, |
|
'motivo_pausa' => $pause->motivo |
|
] |
|
)) { |
|
throw new Exception('Não foi possível atualizar o status do agente!'); |
|
} |
|
|
|
|
|
if (!$this->eventosUsuarioRepository->update([ |
|
'id_usuario' => $agent->id_usuario, |
|
'id_motivo_pausa' => $pause->id, |
|
'entrada_pausa' => 'now()', |
|
'saida_pausa' => 'now()' |
|
])) { |
|
throw new Exception('Não foi possível atualizar informações complementares do agente!'); |
|
} |
|
return $statusAgente; |
|
} |
|
} |