Skip to content

Commit

Permalink
Merge pull request #649 from portabilis/portabilis-patch-2019-08-30
Browse files Browse the repository at this point in the history
[2.2] Portabilis patch 30/08/2019
  • Loading branch information
edersoares authored Sep 2, 2019
2 parents 8af6a3a + 98cab6e commit 85de1e3
Show file tree
Hide file tree
Showing 36 changed files with 1,674 additions and 1,607 deletions.
13 changes: 13 additions & 0 deletions app/Http/Controllers/EnrollmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;
use Throwable;
use Illuminate\Support\Facades\DB;

class EnrollmentController extends Controller
{
Expand Down Expand Up @@ -59,6 +60,7 @@ public function enroll(
LegacyRegistration $registration,
LegacySchoolClass $schoolClass
) {
DB::beginTransaction();
$date = Carbon::createFromFormat('d/m/Y', $request->input('enrollment_date'));

if ($request->input('is_relocation') || $request->input('is_cancellation')) {
Expand All @@ -68,20 +70,31 @@ public function enroll(
try {
$enrollmentService->cancelEnrollment($enrollment, $date);
} catch (Throwable $throwable) {
DB::rollback();
return redirect()->back()->with('error', $throwable->getMessage());
}
}

if ($request->input('is_cancellation')) {
DB::commit();
return redirect('/intranet/educar_matricula_det.php?cod_matricula=' . $registration->id)->with('success', 'Enturmação feita com sucesso.');
}

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

if ($request->input('is_relocation') && $previousEnrollment) {
$enrollmentService->markAsRelocated($previousEnrollment);
}

try {
$enrollmentService->enroll($registration, $schoolClass, $date);
} catch (Throwable $throwable) {
DB::rollback();
return redirect()->back()->with('error', $throwable->getMessage());
}

DB::commit();

return redirect('/intranet/educar_matricula_det.php?cod_matricula=' . $registration->id)->with('success', 'Enturmação feita com sucesso.');
}
}
23 changes: 23 additions & 0 deletions app/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,27 @@ public static function roots()
->orderBy('order')
->get();
}

/**
* Retorna os menus disponíveis para o usuário baseado em seu nível de
* permissão.
*
* @param User $user
* @param string $search
*
* @return LaravelCollection
*/
public static function findByUser(User $user, $search)
{
$query = $user->isAdmin() ? static::query() : $user->menu();

return $query->whereNotNull('link')
->where(function ($query) use ($search) {
$query->orWhere('title', 'ilike', "%{$search}%");
$query->orWhere('description', 'ilike', "%{$search}%");
})
->orderBy('title')
->limit(15)
->get();
}
}
10 changes: 2 additions & 8 deletions app/Services/EnrollmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,6 @@ public function enroll(
throw new ExistsActiveEnrollmentSameTimeException($registration);
}

$previousEnrollment = $this->getPreviousEnrollment($registration);

if ($previousEnrollment) {
$this->markAsRelocated($previousEnrollment);
}

$sequenceInSchoolClass = $this->getSequenceSchoolClass($registration, $schoolClass, $date);

/** @var LegacyEnrollment $enrollment */
Expand All @@ -237,7 +231,7 @@ public function enroll(
* @param LegacyEnrollment $enrollment
* @throws Throwable
*/
private function markAsRelocated(LegacyEnrollment $enrollment)
public function markAsRelocated(LegacyEnrollment $enrollment)
{
$enrollment->remanejado = true;
$enrollment->saveOrFail();
Expand All @@ -250,7 +244,7 @@ private function markAsRelocated(LegacyEnrollment $enrollment)
* @param LegacyRegistration $registration
* @return LegacyEnrollment|void
*/
private function getPreviousEnrollment(LegacyRegistration $registration)
public function getPreviousEnrollmentAccordingToRelocationDate(LegacyRegistration $registration)
{
$previousEnrollment = $registration->lastEnrollment;

Expand Down
51 changes: 51 additions & 0 deletions app/Services/PromotionService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Services;

use App\Models\LegacyEnrollment;
use CoreExt_Controller_Request;
use CoreExt_Exception;
use PromocaoApiController;

class PromotionService
{
/**
* @var LegacyEnrollment
*/
private $enrollment;

public function __construct(LegacyEnrollment $enrollment)
{
$this->enrollment = $enrollment;
}

public function fakeRequest()
{
$fakeRequest = new CoreExt_Controller_Request(
[
'data' => [
'oper' => 'post',
'resource' => 'promocao',
'matricula_id' => $this->enrollment->ref_cod_matricula,
'instituicao_id' => $this->enrollment->schoolClass->school->ref_cod_instituicao,
'ano' => $this->enrollment->registration->ano,
'escola' => $this->enrollment->schoolClass->school_id,
'curso' => $this->enrollment->schoolClass->ref_cod_curso,
'serie' => $this->enrollment->schoolClass->ref_ref_cod_serie,
'turma' => $this->enrollment->ref_cod_turma
]
]);

$promocaoApi = new PromocaoApiController();
$promocaoApi->setRequest($fakeRequest);

try {
$promocaoApi->Gerar();
} catch (CoreExt_Exception $exception) {
// Quando o aluno não possuir enturmação na escola que está
// cancelando a matrícula, uma Exception era lançada ao
// instanciar o ServiceBoletim, este catch garante que não irá
// quebrar o processo.
}
}
}
8 changes: 8 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ public function setRememberTokenAttribute($token)
$this->employee->save();
}

/**
* @return int
*/
public function getLevel()
{
return $this->type->level;
}

/**
* @return BelongsTo
*/
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Software livre de gestão escolar",
"type": "project",
"license": "GPL-2.0-or-later",
"version": "2.2.2",
"version": "2.2.3",
"keywords": [
"Portabilis",
"i-Educar"
Expand Down
Loading

0 comments on commit 85de1e3

Please sign in to comment.