Skip to content

Commit

Permalink
Merge pull request #663 from portabilis/portabilis-patch-2019-09-27
Browse files Browse the repository at this point in the history
[2.2] Portabilis patch 27/09/2019
  • Loading branch information
edersoares authored Sep 30, 2019
2 parents 713fb03 + 424dcbc commit fa8af87
Show file tree
Hide file tree
Showing 178 changed files with 1,415 additions and 3,762 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Exceptions\Enrollment;

use App\Models\LegacyRegistration;
use DateTime;
use RuntimeException;

class PreviousEnrollCancellationDateException extends RuntimeException
{
/**
* A data de cancelamento da enturmação é anterior a data de
* matrícula.
*
* @param LegacyRegistration $registration
* @param DateTime $cancellationDate
*/
public function __construct(LegacyRegistration $registration, DateTime $cancellationDate)
{
$message = 'A data de saída %s deve ser maior que a data de matrícula %s.';

$message = sprintf(
$message, $cancellationDate->format('d/m/Y'), (new DateTime($registration->data_matricula))->format('d/m/Y')
);

parent::__construct($message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Exceptions\Enrollment;

use App\Models\LegacyRegistration;
use DateTime;
use RuntimeException;

class PreviousEnrollRegistrationDateException extends RuntimeException
{
/**
* A data de enturmação é anterior a data de matrícula.
*
* @param DateTime $date
* @param LegacyRegistration $registration
*/
public function __construct(DateTime $date, LegacyRegistration $registration)
{
$message = 'A data de enturmação %s é anterior a data da matrícula %s.';

$message = sprintf(
$message, $date->format('d/m/Y'), (new DateTime($registration->data_matricula))->format('d/m/Y')
);

parent::__construct($message);
}
}
2 changes: 1 addition & 1 deletion app/Models/LegacyCourse.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LegacyCourse extends Model
*/
protected $fillable = [
'ref_usuario_cad', 'ref_cod_tipo_regime', 'ref_cod_nivel_ensino', 'ref_cod_tipo_ensino', 'nm_curso',
'sgl_curso', 'qtd_etapas', 'carga_horaria', 'data_cadastro', 'ref_cod_instituicao',
'sgl_curso', 'qtd_etapas', 'carga_horaria', 'data_cadastro', 'ref_cod_instituicao', 'hora_falta',
];

/**
Expand Down
11 changes: 10 additions & 1 deletion app/Models/LegacyDisciplineExemption.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
* Class LegacyDisciplineExemption
* @property LegacyRegistration $registration
* @property integer cod_dispensa
*/
class LegacyDisciplineExemption extends Model
{
Expand Down Expand Up @@ -75,9 +77,16 @@ public function type()
return $this->belongsTo(LegacyExemptionType::class, 'ref_cod_tipo_dispensa');
}

/**
* @return HasMany
*/
public function stages()
{
return $this->hasMany(LegacyExemptionStage::class, 'ref_cod_dispensa', 'cod_dispensa');
}

/**
* @param Builder $query
*
* @return Builder
*/
public function scopeActive($query)
Expand Down
2 changes: 1 addition & 1 deletion app/Models/LegacyEvaluationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class LegacyEvaluationRule extends Model
* @var array
*/
protected $fillable = [
'instituicao_id', 'nome', 'formula_media_id', 'tipo_nota', 'tipo_progressao', 'tipo_presenca',
'instituicao_id', 'nome', 'formula_media_id', 'formula_recuperacao_id', 'tipo_nota', 'tipo_progressao', 'tipo_presenca',
];

/**
Expand Down
45 changes: 45 additions & 0 deletions app/Models/LegacyExemptionStage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
* Class LegacyDisciplineExemption
* @property LegacyRegistration $registration
*/
class LegacyExemptionStage extends Model
{
/**
* @var string
*/
protected $table = 'pmieducar.dispensa_etapa';

/**
* @var string
*/
protected $primaryKey = 'ref_cod_dispensa';

/**
* @var array
*/
protected $fillable = [
'ref_cod_dispensa',
'etapa',
'ref_cod_disciplina',
];

/**
* @var bool
*/
public $timestamps = false;

/**
* @return BelongsTo
*/
public function exemption()
{
return $this->belongsTo(LegacyDisciplineExemption::class, 'ref_cod_dispensa', 'cod_dispensa');
}
}
8 changes: 8 additions & 0 deletions app/Models/LegacyInstitution.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,12 @@ public function getIdAttribute()
{
return $this->cod_instituicao;
}

/**
* @return bool
*/
public function getAllowRegistrationOutAcademicYearAttribute()
{
return boolval($this->permitir_matricula_fora_periodo_letivo);
}
}
8 changes: 8 additions & 0 deletions app/Models/LegacyRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,12 @@ public function lastEnrollment()

return $hasOne;
}

/**
* @return HasMany
*/
public function exemptions()
{
return $this->hasMany(LegacyDisciplineExemption::class, 'ref_cod_matricula', 'cod_matricula');
}
}
20 changes: 18 additions & 2 deletions app/Services/EnrollmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
use App\Exceptions\Enrollment\ExistsActiveEnrollmentException;
use App\Exceptions\Enrollment\ExistsActiveEnrollmentSameTimeException;
use App\Exceptions\Enrollment\NoVacancyException;
use App\Exceptions\Enrollment\PreviousEnrollCancellationDateException;
use App\Exceptions\Enrollment\PreviousEnrollDateException;
use App\Exceptions\Enrollment\PreviousCancellationDateException;
use App\Exceptions\Enrollment\PreviousEnrollRegistrationDateException;
use App\Models\LegacyRegistration;
use App\Models\LegacySchoolClass;
use App\Models\LegacyEnrollment;
Expand Down Expand Up @@ -139,8 +141,12 @@ public function findAll(array $ids)
*/
public function cancelEnrollment(LegacyEnrollment $enrollment, DateTime $date)
{
$schoolClass = $enrollment->schoolClass;

if ($date->format('Y-m-d') < $enrollment->schoolClass->begin_academic_year->format('Y-m-d')) {
throw new CancellationDateBeforeAcademicYearException($enrollment->schoolClass, $date);
if (!$schoolClass->school->institution->allowRegistrationOutAcademicYear) {
throw new CancellationDateBeforeAcademicYearException($enrollment->schoolClass, $date);
}
}

if ($date->format('Y-m-d') > $enrollment->schoolClass->end_academic_year->format('Y-m-d')) {
Expand All @@ -151,6 +157,10 @@ public function cancelEnrollment(LegacyEnrollment $enrollment, DateTime $date)
throw new PreviousCancellationDateException($enrollment, $date);
}

if ($date < $enrollment->registration->data_matricula) {
throw new PreviousEnrollCancellationDateException($enrollment->registration, $date);
}

$enrollment->ref_usuario_exc = $this->user->getKey();
$enrollment->data_exclusao = $date;
$enrollment->ativo = 0;
Expand Down Expand Up @@ -180,7 +190,9 @@ public function enroll(
}

if ($date->format('Y-m-d') < $schoolClass->begin_academic_year->format('Y-m-d')) {
throw new EnrollDateBeforeAcademicYearException($schoolClass, $date);
if (!$schoolClass->school->institution->allowRegistrationOutAcademicYear) {
throw new EnrollDateBeforeAcademicYearException($schoolClass, $date);
}
}

if ($date->format('Y-m-d') > $schoolClass->end_academic_year->format('Y-m-d')) {
Expand All @@ -204,6 +216,10 @@ public function enroll(
throw new PreviousEnrollDateException($date, $registration->lastEnrollment);
}

if ($registration->data_matricula > $date) {
throw new PreviousEnrollRegistrationDateException($date, $registration);
}

$isMandatoryCensoFields = $schoolClass->school->institution->isMandatoryCensoFields();

if ($isMandatoryCensoFields && !$this->getAvailableTimeService()->isAvailable($registration->ref_cod_aluno, $schoolClass->id)) {
Expand Down
30 changes: 30 additions & 0 deletions app/Support/Database/IncrementSequence.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Support\Database;

use Illuminate\Support\Facades\DB;

trait IncrementSequence
{
/**
* @param string $table
* @param string $column
*
* @return void
*/
public function incrementSequence($table, $column = 'id')
{
if (class_exists($table)) {
$class = new $table;

$table = $class->getTable();
$column = $class->getKeyName();
}

DB::unprepared(
"
SELECT setval(pg_get_serial_sequence('{$table}', '{$column}'), coalesce(max({$column}), 1)) FROM {$table};
"
);
}
}
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.6",
"version": "2.2.7",
"keywords": [
"Portabilis",
"i-Educar"
Expand Down
36 changes: 18 additions & 18 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fa8af87

Please sign in to comment.