Skip to content

Commit

Permalink
Merge pull request #697 from portabilis/portabilis-patch-2019-01-19
Browse files Browse the repository at this point in the history
[2.2] Portabilis patch 19/01/2019
  • Loading branch information
edersoares authored Jan 20, 2020
2 parents c1d34b8 + d43b374 commit 5c65b4e
Show file tree
Hide file tree
Showing 60 changed files with 949 additions and 2,122 deletions.
19 changes: 0 additions & 19 deletions app/City.php

This file was deleted.

17 changes: 0 additions & 17 deletions app/Country.php

This file was deleted.

17 changes: 0 additions & 17 deletions app/District.php

This file was deleted.

3 changes: 3 additions & 0 deletions app/Http/Controllers/EnrollmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ public function enroll(

$previousEnrollment = $enrollmentService->getPreviousEnrollmentAccordingToRelocationDate($registration);

// Se for um remanejamento e a matrícula anterior tiver data de saída antes da data base (ou não houver data base)
// marca a matrícula como "remanejada" e reordena o sequencial da turma de origem
if ($request->input('is_relocation') && $previousEnrollment) {
$enrollmentService->markAsRelocated($previousEnrollment);
$enrollmentService->reorderSchoolClass($previousEnrollment);
}

try {
Expand Down
8 changes: 8 additions & 0 deletions app/Models/LegacyVacancyReservationCandidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,12 @@ public function school()
{
return $this->belongsTo(LegacySchool::class, 'ref_cod_escola');
}

/**
* @return BelongsTo
*/
public function student()
{
return $this->belongsTo(LegacyStudent::class, 'ref_cod_aluno');
}
}
19 changes: 0 additions & 19 deletions app/Neighborhood.php

This file was deleted.

5 changes: 5 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use iEducar\Modules\ErrorTracking\Tracker;
use iEducar\Support\Navigation\Breadcrumb;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Query\Builder;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
Expand Down Expand Up @@ -99,6 +100,10 @@ public function boot()
Schema::defaultStringLength(191);

Paginator::defaultView('vendor.pagination.default');

Builder::macro('whereUnaccent', function ($column, $value) {
$this->whereRaw('unaccent(' . $column . ') ilike unaccent(\'%\' || ? || \'%\')', [$value]);
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Services/Educacenso/HandleFileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function createImportProcess($school)
$import->finished = false;
$import->save();

$school = array_map('utf8_encode', $school);
$school = array_map('utf8_decode', $school);

EducacensoImportJob::dispatch($import, $school, DB::getDefaultConnection());
}
Expand Down
2 changes: 1 addition & 1 deletion app/Services/Educacenso/Version2019/Registro40Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private function createOrUpdateManager(Employee $employee) : void
$manager->role_id = $this->model->cargo;
$manager->access_criteria_id = $this->model->criterioAcesso ?: null;
$manager->access_criteria_description = $this->model->especificacaoCriterioAcesso;
$manager->link_type_id = $this->model->tipoVinculo ?: null;
$manager->link_type_id = (int)$this->model->tipoVinculo ?: null;
if (!$this->existsChiefSchoolManager($school)) {
$manager->chief = true;
}
Expand Down
62 changes: 58 additions & 4 deletions app/Services/EnrollmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ public function cancelEnrollment(LegacyEnrollment $enrollment, DateTime $date)
$enrollment->data_exclusao = $date;
$enrollment->ativo = 0;

$relocationDate = $enrollment->schoolClass->school->institution->relocation_date;

// Se a matrícula anterior data de saída antes da data base (ou não houver data base)
// reordena o sequencial da turma de origem
if (!$relocationDate || $date < $relocationDate) {
$this->reorderSchoolClass($enrollment);
}

return $enrollment->saveOrFail();
}

Expand Down Expand Up @@ -318,10 +326,8 @@ public function getPreviousEnrollmentAccordingToRelocationDate(LegacyRegistratio

$dateDeparted = $previousEnrollment->date_departed;

$relocationDate = $previousEnrollment->schoolClass->school->institution->relocation_date;

if (!$relocationDate || $relocationDate < $dateDeparted) {
return $previousEnrollment;
if ($this->withoutRelocationDateOrDateIsBefore($previousEnrollment, $dateDeparted)) {
return $previousEnrollment;
}
}

Expand All @@ -341,4 +347,52 @@ public function reorder(LegacyRegistration $registration)

return true;
}

/**
* Reordena os sequenciais da turma baseado em uma matrícula que vai ser remanejada
*
* Altera o sequencial da matrícula anterior para null
* e atualiza todos os sequenciais da turma de origem a partir do sequencial do aluno
* remanejado devem ser atualizados subtraindo 1
*
* @param LegacyEnrollment $enrollment
* @param DateTime $date
*/
public function reorderSchoolClass(LegacyEnrollment $enrollment)
{
if (!$enrollment->sequencial_fechamento) {
return;
}

$schoolClass = $enrollment->schoolClass;
$schoolClass->enrollments()->where('sequencial_fechamento', '>', $enrollment->sequencial_fechamento)
->orderBy('sequencial_fechamento')
->get()
->each(function (LegacyEnrollment $enrollment) {
$enrollment->sequencial_fechamento -= 1;
$enrollment->save();
});

$enrollment->sequencial_fechamento = 9999;
$enrollment->save();
}

/**
* Verifica se a instituição não usa database
* ou se a data informada é antes da database
*
* @param LegacyEnrollment $enrollment
* @param DateTime $date
* @return bool
*/
private function withoutRelocationDateOrDateIsBefore($enrollment, $date)
{
$relocationDate = $enrollment->schoolClass->school->institution->relocation_date;

if (!$relocationDate || $date < $relocationDate) {
return true;
}

return false;
}
}
17 changes: 0 additions & 17 deletions app/State.php

This file was deleted.

Loading

0 comments on commit 5c65b4e

Please sign in to comment.