Commit e041b90a09a111bda06ed19d5123d7d6450e37d9
1 parent
f757e224
Exists in
2.9
and in
2 other branches
Cadastra funcionário ao identificar que o mesmo não existe na edição de funcionário.
Showing
1 changed file
with
62 additions
and
0 deletions
Show diff stats
ieducar/intranet/educar_usuario_cad.php
1 | 1 | <?php |
2 | 2 | |
3 | +use App\Models\Employee; | |
3 | 4 | use App\Models\LegacyEmployee; |
4 | 5 | use App\Services\ChangeUserPasswordService; |
5 | 6 | use App\Services\ValidateUserPasswordService; |
... | ... | @@ -22,6 +23,7 @@ return new class extends clsCadastro { |
22 | 23 | public $data_expiracao; |
23 | 24 | public $escola; |
24 | 25 | public $force_reset_password; |
26 | + public $tempo_expira_senha; | |
25 | 27 | |
26 | 28 | public function Inicializar() |
27 | 29 | { |
... | ... | @@ -278,6 +280,25 @@ return new class extends clsCadastro { |
278 | 280 | return false; |
279 | 281 | } |
280 | 282 | |
283 | + // Em caso de unificação de pessoas o usuário perde os dados da tabela de funcionário. | |
284 | + // Neste caso verificamos se existe e caso não exista, é realizado um novo cadastro de funcionário para o usuário | |
285 | + /** @var Employee|null $legacyEmployee */ | |
286 | + $legacyEmployee = LegacyEmployee::query()->find($this->ref_pessoa); | |
287 | + | |
288 | + if ($legacyEmployee === null && empty($this->_senha)) { | |
289 | + $this->mensagem = 'Erro ao cadastrar funcionário, favor informe uma senha.<br>'; | |
290 | + return false; | |
291 | + } | |
292 | + | |
293 | + if ($legacyEmployee === null) { | |
294 | + $legacyEmployee = $this->cadastraNovoFuncionario(); | |
295 | + | |
296 | + if ($legacyEmployee === null) { | |
297 | + $this->mensagem = 'Erro ao cadastrar funcionário, favor entrar em contato com o suporte.<br>'; | |
298 | + return false; | |
299 | + } | |
300 | + } | |
301 | + | |
281 | 302 | // Ao editar não é necessário trocar a senha, então apenas quando algo |
282 | 303 | // for informado é que a mesma será alterada. |
283 | 304 | if ($this->_senha) { |
... | ... | @@ -350,6 +371,47 @@ return new class extends clsCadastro { |
350 | 371 | return false; |
351 | 372 | } |
352 | 373 | |
374 | + /** | |
375 | + * @param string $dataReativaConta | |
376 | + * @return Employee|null | |
377 | + */ | |
378 | + private function cadastraNovoFuncionario() | |
379 | + { | |
380 | + $objFuncionario = new clsPortalFuncionario( | |
381 | + $this->ref_pessoa, | |
382 | + $this->matricula, | |
383 | + $this->_senha, | |
384 | + $this->ativo, | |
385 | + null, | |
386 | + null, | |
387 | + null, | |
388 | + null, | |
389 | + null, | |
390 | + null, | |
391 | + null, | |
392 | + null, | |
393 | + null, | |
394 | + null, | |
395 | + $this->ref_cod_funcionario_vinculo, | |
396 | + $this->tempo_expira_senha, | |
397 | + Portabilis_Date_Utils::brToPgSQL($this->data_expiracao), | |
398 | + null, | |
399 | + 'NOW()', | |
400 | + $this->pessoa_logada, | |
401 | + 0, | |
402 | + 0, | |
403 | + null, | |
404 | + 0, | |
405 | + null, | |
406 | + $this->email, | |
407 | + $this->matricula_interna | |
408 | + ); | |
409 | + | |
410 | + $objFuncionario->cadastra(); | |
411 | + | |
412 | + return Employee::query()->find($this->ref_pessoa); | |
413 | + } | |
414 | + | |
353 | 415 | public function Excluir() |
354 | 416 | { |
355 | 417 | /** @var User $user */ | ... | ... |
-
mentioned in commit 3edf0d2770ddbd43923955627758961ab52e4c57