Commit a3162b1b0875c76a03403bf363caf6590fde4243
Committed by
GitHub
Exists in
2.9
and in
6 other branches
Merge branch 'master' into issue-7238
Showing
30 changed files
with
706 additions
and
21 deletions
Show diff stats
... | ... | @@ -0,0 +1,45 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Console\Commands; | |
4 | + | |
5 | +use App\Services\Discipline\MoveDisciplineDataService; | |
6 | +use Illuminate\Console\Command; | |
7 | +use Illuminate\Filesystem\Filesystem; | |
8 | +use Illuminate\Support\Facades\DB; | |
9 | +use Maatwebsite\Excel\Facades\Excel; | |
10 | + | |
11 | +class UpdateDisciplinesCommand extends Command | |
12 | +{ | |
13 | + /** | |
14 | + * The name and signature of the console command. | |
15 | + * | |
16 | + * @var string | |
17 | + */ | |
18 | + protected $signature = 'update:disciplines {filename}'; | |
19 | + | |
20 | + /** | |
21 | + * The console command description. | |
22 | + * | |
23 | + * @var string | |
24 | + */ | |
25 | + protected $description = 'Move os dados de um componente curricular para outro'; | |
26 | + | |
27 | + /** | |
28 | + * Execute the console command. | |
29 | + * | |
30 | + * @param Filesystem $filesystem | |
31 | + * | |
32 | + * @return mixed | |
33 | + */ | |
34 | + public function handle(Filesystem $filesystem) | |
35 | + { | |
36 | + $filename = $this->argument('filename'); | |
37 | + | |
38 | + $service = new MoveDisciplineDataService(); | |
39 | + $service->setDefaultCopiers(); | |
40 | + | |
41 | + DB::beginTransaction(); | |
42 | + Excel::import($service, $filename); | |
43 | + DB::commit(); | |
44 | + } | |
45 | +} | ... | ... |
app/Models/Individual.php
... | ... | @@ -251,4 +251,12 @@ class Individual extends Model |
251 | 251 | { |
252 | 252 | return $this->belongsTo(User::class, 'id', 'cod_usuario'); |
253 | 253 | } |
254 | + | |
255 | + /** | |
256 | + * @return HasOne | |
257 | + */ | |
258 | + public function employee() | |
259 | + { | |
260 | + return $this->hasOne(Employee::class, 'cod_servidor', 'id'); | |
261 | + } | |
254 | 262 | } | ... | ... |
app/Models/LegacyDisciplineScore.php
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | namespace App\Models; |
4 | 4 | |
5 | 5 | use Illuminate\Database\Eloquent\Model; |
6 | +use Illuminate\Database\Eloquent\Relations\BelongsTo; | |
6 | 7 | |
7 | 8 | class LegacyDisciplineScore extends Model |
8 | 9 | { |
... | ... | @@ -34,4 +35,12 @@ class LegacyDisciplineScore extends Model |
34 | 35 | * @var bool |
35 | 36 | */ |
36 | 37 | public $timestamps = false; |
38 | + | |
39 | + /** | |
40 | + * @return BelongsTo | |
41 | + */ | |
42 | + public function registrationScore() | |
43 | + { | |
44 | + return $this->belongsTo(LegacyRegistrationScore::class, 'nota_aluno_id'); | |
45 | + } | |
37 | 46 | } | ... | ... |
... | ... | @@ -0,0 +1,45 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Models; | |
4 | + | |
5 | +use Illuminate\Database\Eloquent\Model; | |
6 | +use Illuminate\Database\Eloquent\Relations\BelongsTo; | |
7 | + | |
8 | +class LegacyDisciplineScoreAverage extends Model | |
9 | +{ | |
10 | + /** | |
11 | + * @var string | |
12 | + */ | |
13 | + protected $table = 'modules.nota_componente_curricular_media'; | |
14 | + | |
15 | + /** | |
16 | + * @var string | |
17 | + */ | |
18 | + protected $primaryKey = 'nota_aluno_id'; | |
19 | + | |
20 | + /** | |
21 | + * @var array | |
22 | + */ | |
23 | + protected $fillable = [ | |
24 | + 'nota_aluno_id', | |
25 | + 'componente_curricular_id', | |
26 | + 'media', | |
27 | + 'media_arredondada', | |
28 | + 'etapa', | |
29 | + 'situacao', | |
30 | + 'bloqueada', | |
31 | + ]; | |
32 | + | |
33 | + /** | |
34 | + * @var bool | |
35 | + */ | |
36 | + public $timestamps = false; | |
37 | + | |
38 | + /** | |
39 | + * @return BelongsTo | |
40 | + */ | |
41 | + public function registrationScore() | |
42 | + { | |
43 | + return $this->belongsTo(LegacyRegistrationScore::class, 'nota_aluno_id'); | |
44 | + } | |
45 | +} | ... | ... |
app/Models/LegacyRegistrationScore.php
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | namespace App\Models; |
4 | 4 | |
5 | 5 | use Illuminate\Database\Eloquent\Model; |
6 | +use Illuminate\Database\Eloquent\Relations\BelongsTo; | |
6 | 7 | |
7 | 8 | class LegacyRegistrationScore extends Model |
8 | 9 | { |
... | ... | @@ -27,4 +28,12 @@ class LegacyRegistrationScore extends Model |
27 | 28 | * @var bool |
28 | 29 | */ |
29 | 30 | public $timestamps = false; |
31 | + | |
32 | + /** | |
33 | + * @return BelongsTo | |
34 | + */ | |
35 | + public function registration() | |
36 | + { | |
37 | + return $this->belongsTo(LegacyRegistration::class, 'matricula_id'); | |
38 | + } | |
30 | 39 | } | ... | ... |
app/Models/LegacySchoolClassTeacherDiscipline.php
... | ... | @@ -6,9 +6,10 @@ use Illuminate\Database\Eloquent\Model; |
6 | 6 | |
7 | 7 | class LegacySchoolClassTeacherDiscipline extends Model |
8 | 8 | { |
9 | - | |
10 | 9 | public $incrementing = false; |
10 | + | |
11 | 11 | public $primaryKey = null; |
12 | + | |
12 | 13 | protected $fillable = [ |
13 | 14 | 'professor_turma_id', |
14 | 15 | 'componente_curricular_id', | ... | ... |
... | ... | @@ -0,0 +1,41 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Models; | |
4 | + | |
5 | +use Illuminate\Database\Eloquent\Model; | |
6 | +use Illuminate\Database\Eloquent\Relations\BelongsTo; | |
7 | + | |
8 | +class LegacyScoreExam extends Model | |
9 | +{ | |
10 | + /** | |
11 | + * @var string | |
12 | + */ | |
13 | + protected $table = 'modules.nota_exame'; | |
14 | + | |
15 | + /** | |
16 | + * @var string | |
17 | + */ | |
18 | + protected $primaryKey = 'ref_cod_matricula'; | |
19 | + | |
20 | + /** | |
21 | + * @var array | |
22 | + */ | |
23 | + protected $fillable = [ | |
24 | + 'ref_cod_matricula', | |
25 | + 'ref_cod_componente_curricular', | |
26 | + 'nota_exame' | |
27 | + ]; | |
28 | + | |
29 | + /** | |
30 | + * @var bool | |
31 | + */ | |
32 | + public $timestamps = false; | |
33 | + | |
34 | + /** | |
35 | + * @return BelongsTo | |
36 | + */ | |
37 | + public function registration() | |
38 | + { | |
39 | + return $this->belongsTo(LegacyRegistration::class, 'ref_cod_matricula'); | |
40 | + } | |
41 | +} | ... | ... |
... | ... | @@ -0,0 +1,15 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Models; | |
4 | + | |
5 | +use Illuminate\Database\Eloquent\Model; | |
6 | + | |
7 | +class MigratedDiscipline extends Model | |
8 | +{ | |
9 | + /** | |
10 | + * @var array | |
11 | + */ | |
12 | + protected $fillable = [ | |
13 | + 'old_discipline_id', 'new_discipline_id', 'grade_id', 'year', 'created_by' | |
14 | + ]; | |
15 | +} | ... | ... |
... | ... | @@ -0,0 +1,25 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Services\Discipline; | |
4 | + | |
5 | +use App\Models\LegacyDisciplineAbsence; | |
6 | +use Illuminate\Database\Eloquent\Builder; | |
7 | + | |
8 | +class MoveDataDisciplineAbsence implements MoveDisciplineDataInterface | |
9 | +{ | |
10 | + public function moveData($disciplineFrom, $disciplineTo, $year, $gradeId) | |
11 | + { | |
12 | + LegacyDisciplineAbsence::query() | |
13 | + ->where('componente_curricular_id', $disciplineFrom) | |
14 | + ->whereHas('studentAbsence', function (Builder $registrationScoreQuery) use ($gradeId, $year) { | |
15 | + $registrationScoreQuery->whereHas('registration', function (Builder $registrationQuery) use ($gradeId, $year) { | |
16 | + $registrationQuery->where('ano', $year); | |
17 | + | |
18 | + if ($gradeId) { | |
19 | + $registrationQuery->where('ref_ref_cod_serie', $gradeId); | |
20 | + } | |
21 | + }); | |
22 | + }) | |
23 | + ->update(['componente_curricular_id' => $disciplineTo]); | |
24 | + } | |
25 | +} | ... | ... |
app/Services/Discipline/MoveDataDisciplineDescritiveOpinion.php
0 → 100644
... | ... | @@ -0,0 +1,25 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Services\Discipline; | |
4 | + | |
5 | +use App\Models\LegacyDisciplineDescriptiveOpinion; | |
6 | +use Illuminate\Database\Eloquent\Builder; | |
7 | + | |
8 | +class MoveDataDisciplineDescritiveOpinion implements MoveDisciplineDataInterface | |
9 | +{ | |
10 | + public function moveData($disciplineFrom, $disciplineTo, $year, $gradeId) | |
11 | + { | |
12 | + LegacyDisciplineDescriptiveOpinion::query() | |
13 | + ->where('componente_curricular_id', $disciplineFrom) | |
14 | + ->whereHas('studentDescriptiveOpinion', function (Builder $studentDescriptiveOpinionQuery) use ($gradeId, $year) { | |
15 | + $studentDescriptiveOpinionQuery->whereHas('registration', function (Builder $registrationQuery) use ($gradeId, $year) { | |
16 | + $registrationQuery->where('ano', $year); | |
17 | + | |
18 | + if ($gradeId) { | |
19 | + $registrationQuery->where('ref_ref_cod_serie', $gradeId); | |
20 | + } | |
21 | + }); | |
22 | + }) | |
23 | + ->update(['componente_curricular_id' => $disciplineTo]); | |
24 | + } | |
25 | +} | ... | ... |
... | ... | @@ -0,0 +1,23 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Services\Discipline; | |
4 | + | |
5 | +use App\Models\LegacyDisciplineExemption; | |
6 | +use Illuminate\Database\Eloquent\Builder; | |
7 | + | |
8 | +class MoveDataDisciplineExemption implements MoveDisciplineDataInterface | |
9 | +{ | |
10 | + public function moveData($disciplineFrom, $disciplineTo, $year, $gradeId) | |
11 | + { | |
12 | + LegacyDisciplineExemption::query() | |
13 | + ->where('ref_cod_disciplina', $disciplineFrom) | |
14 | + ->whereHas('registration', function (Builder $registrationQuery) use ($gradeId, $year) { | |
15 | + $registrationQuery->where('ano', $year); | |
16 | + | |
17 | + if ($gradeId) { | |
18 | + $registrationQuery->where('ref_ref_cod_serie', $gradeId); | |
19 | + } | |
20 | + }) | |
21 | + ->update(['ref_cod_disciplina' => $disciplineTo]); | |
22 | + } | |
23 | +} | ... | ... |
... | ... | @@ -0,0 +1,25 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Services\Discipline; | |
4 | + | |
5 | +use App\Models\LegacyDisciplineScore; | |
6 | +use Illuminate\Database\Eloquent\Builder; | |
7 | + | |
8 | +class MoveDataDisciplineScore implements MoveDisciplineDataInterface | |
9 | +{ | |
10 | + public function moveData($disciplineFrom, $disciplineTo, $year, $gradeId) | |
11 | + { | |
12 | + LegacyDisciplineScore::query() | |
13 | + ->where('componente_curricular_id', $disciplineFrom) | |
14 | + ->whereHas('registrationScore', function (Builder $registrationScoreQuery) use ($gradeId, $year) { | |
15 | + $registrationScoreQuery->whereHas('registration', function (Builder $registrationQuery) use ($gradeId, $year) { | |
16 | + $registrationQuery->where('ano', $year); | |
17 | + | |
18 | + if ($gradeId) { | |
19 | + $registrationQuery->where('ref_ref_cod_serie', $gradeId); | |
20 | + } | |
21 | + }); | |
22 | + }) | |
23 | + ->update(['componente_curricular_id' => $disciplineTo]); | |
24 | + } | |
25 | +} | ... | ... |
app/Services/Discipline/MoveDataDisciplineScoreAverage.php
0 → 100644
... | ... | @@ -0,0 +1,25 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Services\Discipline; | |
4 | + | |
5 | +use App\Models\LegacyDisciplineScoreAverage; | |
6 | +use Illuminate\Database\Eloquent\Builder; | |
7 | + | |
8 | +class MoveDataDisciplineScoreAverage implements MoveDisciplineDataInterface | |
9 | +{ | |
10 | + public function moveData($disciplineFrom, $disciplineTo, $year, $gradeId) | |
11 | + { | |
12 | + LegacyDisciplineScoreAverage::query() | |
13 | + ->where('componente_curricular_id', $disciplineFrom) | |
14 | + ->whereHas('registrationScore', function (Builder $registrationScoreQuery) use ($gradeId, $year) { | |
15 | + $registrationScoreQuery->whereHas('registration', function (Builder $registrationQuery) use ($gradeId, $year) { | |
16 | + $registrationQuery->where('ano', $year); | |
17 | + | |
18 | + if ($gradeId) { | |
19 | + $registrationQuery->where('ref_ref_cod_serie', $gradeId); | |
20 | + } | |
21 | + }); | |
22 | + }) | |
23 | + ->update(['componente_curricular_id' => $disciplineTo]); | |
24 | + } | |
25 | +} | ... | ... |
... | ... | @@ -0,0 +1,24 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Services\Discipline; | |
4 | + | |
5 | +use App\Models\LegacyDisciplineScoreAverage; | |
6 | +use App\Models\LegacyScoreExam; | |
7 | +use Illuminate\Database\Eloquent\Builder; | |
8 | + | |
9 | +class MoveDataScoreExam implements MoveDisciplineDataInterface | |
10 | +{ | |
11 | + public function moveData($disciplineFrom, $disciplineTo, $year, $gradeId) | |
12 | + { | |
13 | + LegacyScoreExam::query() | |
14 | + ->where('ref_cod_componente_curricular', $disciplineFrom) | |
15 | + ->whereHas('registration', function (Builder $registrationQuery) use ($gradeId, $year) { | |
16 | + $registrationQuery->where('ano', $year); | |
17 | + | |
18 | + if ($gradeId) { | |
19 | + $registrationQuery->where('ref_ref_cod_serie', $gradeId); | |
20 | + } | |
21 | + }) | |
22 | + ->update(['ref_cod_componente_curricular' => $disciplineTo]); | |
23 | + } | |
24 | +} | ... | ... |
... | ... | @@ -0,0 +1,24 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Services\Discipline; | |
4 | + | |
5 | +use App\Models\LegacySchoolClassTeacherDiscipline; | |
6 | +use Illuminate\Database\Eloquent\Builder; | |
7 | + | |
8 | +class MoveDataTeacherDiscipline implements MoveDisciplineDataInterface | |
9 | +{ | |
10 | + public function moveData($disciplineFrom, $disciplineTo, $year, $gradeId) | |
11 | + { | |
12 | + LegacySchoolClassTeacherDiscipline::query() | |
13 | + ->where('componente_curricular_id', $disciplineFrom) | |
14 | + ->whereHas('schoolClassTeacher', function (Builder $schoolClassTeacherQuery) use ($gradeId, $year) { | |
15 | + $schoolClassTeacherQuery->whereHas('schoolClass', function (Builder $schoolClassQuery) use ($gradeId, $year) { | |
16 | + $schoolClassQuery->where('ano', $year); | |
17 | + | |
18 | + if ($gradeId) { | |
19 | + $schoolClassQuery->where('ref_ref_cod_serie', $gradeId); | |
20 | + } | |
21 | + }); | |
22 | + })->update(['componente_curricular_id' => $disciplineTo]); | |
23 | + } | |
24 | +} | ... | ... |
... | ... | @@ -0,0 +1,71 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Services\Discipline; | |
4 | + | |
5 | +use App\Models\MigratedDiscipline; | |
6 | +use Illuminate\Support\Collection; | |
7 | +use Maatwebsite\Excel\Concerns\ToCollection; | |
8 | + | |
9 | +class MoveDisciplineDataService implements ToCollection | |
10 | +{ | |
11 | + /** | |
12 | + * @var MoveDisciplineDataInterface[] | |
13 | + */ | |
14 | + private $moveDataServices = []; | |
15 | + | |
16 | + /** | |
17 | + * @inheritDoc | |
18 | + */ | |
19 | + public function collection(Collection $rows) | |
20 | + { | |
21 | + foreach ($rows as $row) { | |
22 | + $disciplineFrom = $row[0]; | |
23 | + $disciplineTo = $row[1]; | |
24 | + $gradeId = $row[2]; | |
25 | + $year = $row[3]; | |
26 | + | |
27 | + if (!is_numeric($disciplineTo) || !is_numeric($disciplineFrom)) { | |
28 | + continue; | |
29 | + } | |
30 | + | |
31 | + MigratedDiscipline::create([ | |
32 | + 'old_discipline_id' => $disciplineFrom, | |
33 | + 'new_discipline_id' => $disciplineTo, | |
34 | + 'grade_id' => $gradeId, | |
35 | + 'year' => $year, | |
36 | + ]); | |
37 | + | |
38 | + $this->moveData($disciplineFrom, $disciplineTo, $year, $gradeId); | |
39 | + } | |
40 | + } | |
41 | + | |
42 | + public function moveData($disciplineFrom, $disciplineTo, $year, $gradeId) | |
43 | + { | |
44 | + foreach ($this->moveDataServices as $moveDataService) { | |
45 | + $moveDataService->moveData($disciplineFrom, $disciplineTo, $year, $gradeId); | |
46 | + } | |
47 | + } | |
48 | + | |
49 | + public function setDefaultCopiers() | |
50 | + { | |
51 | + $this->moveDataServices = [ | |
52 | + new MoveDataTeacherDiscipline(), | |
53 | + new MoveDataDisciplineScore(), | |
54 | + new MoveDataDisciplineScoreAverage(), | |
55 | + new MoveDataScoreExam(), | |
56 | + new MoveDataDisciplineDescritiveOpinion(), | |
57 | + new MoveDataDisciplineAbsence(), | |
58 | + new MoveDataDisciplineExemption(), | |
59 | + ]; | |
60 | + } | |
61 | + | |
62 | + /** | |
63 | + * @param MoveDisciplineDataInterface $moveDataServices | |
64 | + * @return MoveDisciplineDataService | |
65 | + */ | |
66 | + public function setMoveDataService(MoveDisciplineDataInterface $moveDataServices): MoveDisciplineDataService | |
67 | + { | |
68 | + $this->moveDataServices[] = $moveDataServices; | |
69 | + return $this; | |
70 | + } | |
71 | +} | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Services; | |
4 | + | |
5 | +use App\Models\LogUnificationOldData; | |
6 | + | |
7 | +class UnificationService | |
8 | +{ | |
9 | + public function storeLogOldData($unificationId, $table, $keys, $oldData) | |
10 | + { | |
11 | + $logData = new LogUnificationOldData(); | |
12 | + $logData->unification_id = $unificationId; | |
13 | + $logData->table = $table; | |
14 | + $logData->keys = json_encode([$keys]); | |
15 | + $logData->old_data = json_encode($oldData); | |
16 | + $logData->save(); | |
17 | + | |
18 | + return $logData; | |
19 | + } | |
20 | +} | ... | ... |
database/migrations/2020_03_12_085826_add_balneario_rincao_to_cities.php
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +<?php | |
2 | + | |
3 | +use Illuminate\Support\Facades\Schema; | |
4 | +use Illuminate\Database\Schema\Blueprint; | |
5 | +use Illuminate\Database\Migrations\Migration; | |
6 | + | |
7 | +class AddBalnearioRincaoToCities extends Migration | |
8 | +{ | |
9 | + /** | |
10 | + * Run the migrations. | |
11 | + * | |
12 | + * @return void | |
13 | + */ | |
14 | + public function up() | |
15 | + { | |
16 | + DB::table('public.cities')->insert( | |
17 | + [ | |
18 | + 'state_id' => DB::table('public.states')->where('abbreviation', 'SC')->first()->id, | |
19 | + 'name' => 'Balneário Rincão', | |
20 | + 'ibge_code' => '4220000', | |
21 | + 'created_at' => DB::raw('now()'), | |
22 | + 'updated_at' => DB::raw('now()') | |
23 | + ] | |
24 | + ); | |
25 | + } | |
26 | + | |
27 | + /** | |
28 | + * Reverse the migrations. | |
29 | + * | |
30 | + * @return void | |
31 | + */ | |
32 | + public function down() | |
33 | + { | |
34 | + DB::table('public.cities') | |
35 | + ->where('ibge_code', '4220000') | |
36 | + ->delete(); | |
37 | + } | |
38 | +} | ... | ... |
database/migrations/2020_03_12_114844_add_balneario_rincao_to_districts.php
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +<?php | |
2 | + | |
3 | +use Illuminate\Support\Facades\Schema; | |
4 | +use Illuminate\Database\Schema\Blueprint; | |
5 | +use Illuminate\Database\Migrations\Migration; | |
6 | + | |
7 | +class AddBalnearioRincaoToDistricts extends Migration | |
8 | +{ | |
9 | + /** | |
10 | + * Run the migrations. | |
11 | + * | |
12 | + * @return void | |
13 | + */ | |
14 | + public function up() | |
15 | + { | |
16 | + DB::table('public.districts')->insert( | |
17 | + [ | |
18 | + 'city_id' => DB::table('public.cities')->where('ibge_code', '4220000')->first()->id, | |
19 | + 'name' => 'Balneário Rincão', | |
20 | + 'ibge_code' => '5', | |
21 | + 'created_at' => DB::raw('now()'), | |
22 | + 'updated_at' => DB::raw('now()') | |
23 | + ] | |
24 | + ); | |
25 | + } | |
26 | + | |
27 | + /** | |
28 | + * Reverse the migrations. | |
29 | + * | |
30 | + * @return void | |
31 | + */ | |
32 | + public function down() | |
33 | + { | |
34 | + DB::table('public.districts') | |
35 | + ->where('city_id', DB::table('public.cities')->where('ibge_code', '4220000')->first()->id) | |
36 | + ->delete(); | |
37 | + } | |
38 | +} | ... | ... |
database/migrations/2020_04_06_090159_create_table_migrated_disciplines.php
0 → 100644
... | ... | @@ -0,0 +1,39 @@ |
1 | +<?php | |
2 | + | |
3 | +use Illuminate\Support\Facades\Schema; | |
4 | +use Illuminate\Database\Schema\Blueprint; | |
5 | +use Illuminate\Database\Migrations\Migration; | |
6 | + | |
7 | +class CreateTableMigratedDisciplines extends Migration | |
8 | +{ | |
9 | + /** | |
10 | + * Run the migrations. | |
11 | + * | |
12 | + * @return void | |
13 | + */ | |
14 | + public function up() | |
15 | + { | |
16 | + Schema::create('public.migrated_disciplines', function (Blueprint $table) { | |
17 | + $table->bigIncrements('id'); | |
18 | + $table->integer('old_discipline_id'); | |
19 | + $table->integer('new_discipline_id'); | |
20 | + $table->integer('grade_id')->nullable(); | |
21 | + $table->integer('year'); | |
22 | + $table->integer('created_by')->nullable(); | |
23 | + $table->timestamps(); | |
24 | + | |
25 | + $table->foreign('old_discipline_id')->references('id')->on('modules.componente_curricular'); | |
26 | + $table->foreign('new_discipline_id')->references('id')->on('modules.componente_curricular'); | |
27 | + }); | |
28 | + } | |
29 | + | |
30 | + /** | |
31 | + * Reverse the migrations. | |
32 | + * | |
33 | + * @return void | |
34 | + */ | |
35 | + public function down() | |
36 | + { | |
37 | + Schema::dropIfExists('public.migrated_disciplines'); | |
38 | + } | |
39 | +} | ... | ... |
ieducar/intranet/educar_historico_escolar_cad.php
ieducar/intranet/educar_historico_escolar_det.php
... | ... | @@ -188,6 +188,10 @@ class indice extends clsDetalhe |
188 | 188 | { |
189 | 189 | $registro["aprovado"] = "Transferido"; |
190 | 190 | } |
191 | + elseif ($registro["aprovado"] == 5) | |
192 | + { | |
193 | + $registro["aprovado"] = "Reclassificado"; | |
194 | + } | |
191 | 195 | elseif ($registro['aprovado'] == 6) { |
192 | 196 | $registro["aprovado"] = "Abandono"; |
193 | 197 | } | ... | ... |
ieducar/intranet/educar_unifica_pessoa.php
1 | 1 | <?php |
2 | 2 | |
3 | +use App\Models\LogUnification; | |
4 | +use iEducar\Modules\Unification\PersonLogUnification; | |
5 | +use Illuminate\Support\Facades\DB; | |
6 | + | |
3 | 7 | require_once 'include/clsBase.inc.php'; |
4 | 8 | require_once 'include/clsCadastro.inc.php'; |
5 | 9 | require_once 'include/clsBanco.inc.php'; |
... | ... | @@ -83,10 +87,15 @@ class indice extends clsCadastro |
83 | 87 | return false; |
84 | 88 | } |
85 | 89 | |
86 | - $unificador = new App_Unificacao_Pessoa($codPessoaPrincipal, $codPessoas, $this->pessoa_logada, new clsBanco(), FALSE); | |
90 | + DB::beginTransaction(); | |
91 | + $unificationId = $this->createLog($codPessoaPrincipal, $codPessoas, $this->pessoa_logada); | |
92 | + $unificador = new App_Unificacao_Pessoa($codPessoaPrincipal, $codPessoas, $this->pessoa_logada, new clsBanco(), $unificationId); | |
93 | + | |
87 | 94 | try { |
88 | 95 | $unificador->unifica(); |
96 | + DB::commit(); | |
89 | 97 | } catch (CoreExt_Exception $exception) { |
98 | + DB::rollBack(); | |
90 | 99 | $this->mensagem = $exception->getMessage(); |
91 | 100 | return FALSE; |
92 | 101 | } |
... | ... | @@ -94,6 +103,18 @@ class indice extends clsCadastro |
94 | 103 | $this->mensagem = "<span>Pessoas unificadas com sucesso.</span>"; |
95 | 104 | return true; |
96 | 105 | } |
106 | + | |
107 | + private function createLog($mainId, $duplicatesId, $createdBy) | |
108 | + { | |
109 | + $log = new LogUnification(); | |
110 | + $log->type = PersonLogUnification::getType(); | |
111 | + $log->main_id = $mainId; | |
112 | + $log->duplicates_id = json_encode($duplicatesId); | |
113 | + $log->created_by = $createdBy; | |
114 | + $log->updated_by = $createdBy; | |
115 | + $log->save(); | |
116 | + return $log->id; | |
117 | + } | |
97 | 118 | } |
98 | 119 | |
99 | 120 | // Instancia objeto de página | ... | ... |
ieducar/lib/App/Unificacao/Base.php
1 | 1 | <?php |
2 | 2 | |
3 | +use App\Services\UnificationService; | |
4 | +use Illuminate\Support\Facades\DB; | |
5 | + | |
3 | 6 | class App_Unificacao_Base |
4 | 7 | { |
5 | 8 | protected $chavesManterPrimeiroVinculo = []; |
... | ... | @@ -10,15 +13,21 @@ class App_Unificacao_Base |
10 | 13 | protected $codigosDuplicados; |
11 | 14 | protected $codPessoaLogada; |
12 | 15 | protected $db; |
13 | - protected $transacao; | |
16 | + protected $unificationId; | |
17 | + | |
18 | + /** | |
19 | + * @var UnificationService | |
20 | + */ | |
21 | + protected $unificationService; | |
14 | 22 | |
15 | - public function __construct($codigoUnificador, $codigosDuplicados, $codPessoaLogada, clsBanco $db, $transacao = true) | |
23 | + public function __construct($codigoUnificador, $codigosDuplicados, $codPessoaLogada, clsBanco $db, $unificationId) | |
16 | 24 | { |
17 | 25 | $this->codigoUnificador = $codigoUnificador; |
18 | 26 | $this->codigosDuplicados = $codigosDuplicados; |
19 | 27 | $this->codPessoaLogada = $codPessoaLogada; |
20 | 28 | $this->db = $db; |
21 | - $this->transacao = $transacao; | |
29 | + $this->unificationId = $unificationId; | |
30 | + $this->unificationService = new UnificationService(); | |
22 | 31 | } |
23 | 32 | |
24 | 33 | public function unifica() |
... | ... | @@ -38,6 +47,9 @@ class App_Unificacao_Base |
38 | 47 | $stringCodigosDuplicados = implode(',', $this->codigosDuplicados); |
39 | 48 | |
40 | 49 | foreach ($this->chavesDeletarDuplicados as $key => $value) { |
50 | + $oldKeys = explode(',', $stringCodigosDuplicados); | |
51 | + $this->storeLogOldDataByKeys($oldKeys, $value['tabela'], $value['coluna']); | |
52 | + | |
41 | 53 | try { |
42 | 54 | $this->db->Consulta( |
43 | 55 | " |
... | ... | @@ -62,6 +74,9 @@ class App_Unificacao_Base |
62 | 74 | $stringCodigosDuplicados = implode(',', $this->codigosDuplicados); |
63 | 75 | |
64 | 76 | foreach ($this->chavesManterTodosVinculos as $key => $value) { |
77 | + $oldKeys = explode(',', $stringCodigosDuplicados); | |
78 | + $this->storeLogOldDataByKeys($oldKeys, $value['tabela'], $value['coluna']); | |
79 | + | |
65 | 80 | $this->db->Consulta( |
66 | 81 | " |
67 | 82 | UPDATE {$value['tabela']} |
... | ... | @@ -79,6 +94,9 @@ class App_Unificacao_Base |
79 | 94 | $chavesConsultarString = implode(',', $chavesConsultar); |
80 | 95 | |
81 | 96 | foreach ($this->chavesManterPrimeiroVinculo as $key => $value) { |
97 | + $oldKeys = explode(',', $chavesConsultarString); | |
98 | + $this->storeLogOldDataByKeys($oldKeys, $value['tabela'], $value['coluna']); | |
99 | + | |
82 | 100 | $this->db->Consulta( |
83 | 101 | " |
84 | 102 | DELETE FROM {$value['tabela']} |
... | ... | @@ -155,4 +173,42 @@ class App_Unificacao_Base |
155 | 173 | throw new CoreExt_Exception('Parâmetro 3 deve ser um inteiro'); |
156 | 174 | } |
157 | 175 | } |
176 | + | |
177 | + /** | |
178 | + * Grava log das tabelas alteradas pela unificação | |
179 | + * | |
180 | + * @param $oldKeys | |
181 | + * @param $table | |
182 | + * @param $columnKey | |
183 | + */ | |
184 | + private function storeLogOldDataByKeys($oldKeys, $table, $columnKey) | |
185 | + { | |
186 | + foreach($oldKeys as $key) { | |
187 | + $data = $this->getOldData($table, $columnKey, $key); | |
188 | + | |
189 | + if ($data->isEmpty()){ | |
190 | + continue; | |
191 | + } | |
192 | + | |
193 | + $this->unificationService->storeLogOldData( | |
194 | + $this->unificationId, | |
195 | + $table, | |
196 | + [$columnKey => $key], | |
197 | + $data | |
198 | + ); | |
199 | + } | |
200 | + } | |
201 | + | |
202 | + /** | |
203 | + * Retorna dados da tabela de acordo com a chave informada | |
204 | + * | |
205 | + * @param $table | |
206 | + * @param $key | |
207 | + * @param $value | |
208 | + * @return \Illuminate\Support\Collection | |
209 | + */ | |
210 | + private function getOldData($table, $key, $value) | |
211 | + { | |
212 | + return DB::table($table)->whereIn($key, [$value])->get(); | |
213 | + } | |
158 | 214 | } | ... | ... |
ieducar/lib/App/Unificacao/Pessoa.php
... | ... | @@ -232,9 +232,9 @@ class App_Unificacao_Pessoa extends App_Unificacao_Base |
232 | 232 | ] |
233 | 233 | ]; |
234 | 234 | |
235 | - public function __construct($codigoUnificador, $codigosDuplicados, $codPessoaLogada, clsBanco $db, bool $transacao = true) | |
235 | + public function __construct($codigoUnificador, $codigosDuplicados, $codPessoaLogada, clsBanco $db, $unificationId) | |
236 | 236 | { |
237 | - parent::__construct($codigoUnificador, $codigosDuplicados, $codPessoaLogada, $db, $transacao); | |
237 | + parent::__construct($codigoUnificador, $codigosDuplicados, $codPessoaLogada, $db, $unificationId); | |
238 | 238 | |
239 | 239 | if (is_dir(base_path('ieducar/intranet/filaunica'))) { |
240 | 240 | $this->chavesManterTodosVinculos[] = [ |
... | ... | @@ -255,7 +255,7 @@ class App_Unificacao_Pessoa extends App_Unificacao_Base |
255 | 255 | public function unifica() |
256 | 256 | { |
257 | 257 | $this->unificaClientes(); |
258 | - $unificadorServidor = new App_Unificacao_Servidor($this->codigoUnificador, $this->codigosDuplicados, $this->codPessoaLogada, $this->db, $this->transacao); | |
258 | + $unificadorServidor = new App_Unificacao_Servidor($this->codigoUnificador, $this->codigosDuplicados, $this->codPessoaLogada, $this->db, $this->unificationId); | |
259 | 259 | $unificadorServidor->unifica(); |
260 | 260 | parent::unifica(); |
261 | 261 | } |
... | ... | @@ -283,7 +283,7 @@ class App_Unificacao_Pessoa extends App_Unificacao_Base |
283 | 283 | if (COUNT($codigoClientes) < 2) { |
284 | 284 | return true; |
285 | 285 | } |
286 | - $unificadorCliente = new App_Unificacao_Cliente(array_shift($codigoClientes), $codigoClientes, $this->codPessoaLogada, $this->db, $this->transacao); | |
286 | + $unificadorCliente = new App_Unificacao_Cliente(array_shift($codigoClientes), $codigoClientes, $this->codPessoaLogada, $this->db, $this->unificationId); | |
287 | 287 | $unificadorCliente->unifica(); |
288 | 288 | } |
289 | 289 | ... | ... |
ieducar/modules/Api/Views/ComponenteCurricularController.php
1 | 1 | <?php |
2 | 2 | |
3 | +use App\Models\MigratedDiscipline; | |
4 | + | |
3 | 5 | require_once 'lib/Portabilis/Controller/ApiCoreController.php'; |
4 | 6 | require_once 'lib/Portabilis/Array/Utils.php'; |
5 | 7 | require_once 'lib/Portabilis/String/Utils.php'; |
... | ... | @@ -88,6 +90,19 @@ class ComponenteCurricularController extends ApiCoreController |
88 | 90 | } |
89 | 91 | } |
90 | 92 | |
93 | + private function getComponentesCurricularesMigrados() | |
94 | + { | |
95 | + $modified = $this->getRequest()->modified; | |
96 | + | |
97 | + $query = MigratedDiscipline::query(); | |
98 | + | |
99 | + if ($modified) { | |
100 | + $query->where('created_at', '>=', $modified); | |
101 | + } | |
102 | + | |
103 | + return array('disciplinas' => $query->get()); | |
104 | + } | |
105 | + | |
91 | 106 | function getComponentesCurricularesPorSerie(){ |
92 | 107 | if($this->canGetComponentesCurriculares()){ |
93 | 108 | |
... | ... | @@ -214,6 +229,8 @@ function getComponentesCurricularesPorSerie(){ |
214 | 229 | $this->appendResponse($this->getComponentesCurricularesPorEscolaSerieAno()); |
215 | 230 | elseif($this->isRequestFor('get', 'componentes-curriculares-for-multiple-search')) |
216 | 231 | $this->appendResponse($this->getComponentesCurricularesForMultipleSearch()); |
232 | + elseif($this->isRequestFor('get', 'componentes-curriculares-migrados')) | |
233 | + $this->appendResponse($this->getComponentesCurricularesMigrados()); | |
217 | 234 | else |
218 | 235 | $this->notImplementedOperationError(); |
219 | 236 | } | ... | ... |
ieducar/modules/Api/Views/ServidorController.php
1 | 1 | <?php |
2 | 2 | use App\Models\LegacyDeficiency; |
3 | +use App\Models\LogUnification; | |
3 | 4 | use iEducar\Modules\Educacenso\Validator\DeficiencyValidator; |
4 | 5 | require_once 'lib/Portabilis/Controller/ApiCoreController.php'; |
5 | 6 | require_once 'lib/Portabilis/Array/Utils.php'; |
... | ... | @@ -94,7 +95,7 @@ class ServidorController extends ApiCoreController |
94 | 95 | } |
95 | 96 | |
96 | 97 | $sql = " |
97 | - SELECT | |
98 | + SELECT | |
98 | 99 | s.cod_servidor as servidor_id, |
99 | 100 | p.nome as nome, |
100 | 101 | s.ativo as ativo, |
... | ... | @@ -148,12 +149,12 @@ class ServidorController extends ApiCoreController |
148 | 149 | string_agg(concat(ptd.componente_curricular_id, ' ', ccae.tipo_nota)::varchar, ',') as disciplinas, |
149 | 150 | greatest(pt.updated_at, date(ccae.updated_at)) as updated_at, |
150 | 151 | null as deleted_at |
151 | - from modules.professor_turma pt | |
152 | - left join modules.professor_turma_disciplina ptd | |
152 | + from modules.professor_turma pt | |
153 | + left join modules.professor_turma_disciplina ptd | |
153 | 154 | on ptd.professor_turma_id = pt.id |
154 | - inner join pmieducar.turma t | |
155 | + inner join pmieducar.turma t | |
155 | 156 | on t.cod_turma = pt.turma_id |
156 | - inner join modules.componente_curricular_ano_escolar ccae | |
157 | + inner join modules.componente_curricular_ano_escolar ccae | |
157 | 158 | on ccae.ano_escolar_id = t.ref_ref_cod_serie |
158 | 159 | and ccae.componente_curricular_id = ptd.componente_curricular_id |
159 | 160 | where true |
... | ... | @@ -174,10 +175,10 @@ class ServidorController extends ApiCoreController |
174 | 175 | null as disciplinas, |
175 | 176 | pt.updated_at, |
176 | 177 | pt.deleted_at |
177 | - from modules.professor_turma_excluidos pt | |
178 | - inner join pmieducar.turma t | |
178 | + from modules.professor_turma_excluidos pt | |
179 | + inner join pmieducar.turma t | |
179 | 180 | on t.cod_turma = pt.turma_id |
180 | - where true | |
181 | + where true | |
181 | 182 | and pt.instituicao_id = $1 |
182 | 183 | and pt.ano = $2 |
183 | 184 | and t.ref_ref_cod_escola in ({$escola}) |
... | ... | @@ -232,6 +233,25 @@ class ServidorController extends ApiCoreController |
232 | 233 | return ['result' => $result[0]]; |
233 | 234 | } |
234 | 235 | |
236 | + protected function getUnificacoes() | |
237 | + { | |
238 | + $modified = $this->getRequest()->modified; | |
239 | + | |
240 | + $unificationsQuery = LogUnification::query(); | |
241 | + | |
242 | + if ($modified) { | |
243 | + $unificationsQuery->where('created_at', '>=', $modified); | |
244 | + } | |
245 | + | |
246 | + $unificationsQuery->whereHas('personMain', function ($individualQuery) { | |
247 | + $individualQuery->whereHas('employee'); | |
248 | + }); | |
249 | + | |
250 | + $unificationsQuery->person(); | |
251 | + | |
252 | + return ['unificacoes' => $unificationsQuery->get(['main_id', 'duplicates_id', 'created_at', 'active'])]; | |
253 | + } | |
254 | + | |
235 | 255 | /** |
236 | 256 | * @return bool |
237 | 257 | */ |
... | ... | @@ -279,6 +299,8 @@ class ServidorController extends ApiCoreController |
279 | 299 | $this->appendResponse($this->validateDeficiencies()); |
280 | 300 | } elseif ($this->isRequestFor('get', 'servidores')) { |
281 | 301 | $this->appendResponse($this->getServidores()); |
302 | + } elseif ($this->isRequestFor('get', 'unificacoes')) { | |
303 | + $this->appendResponse($this->getUnificacoes()); | |
282 | 304 | } else { |
283 | 305 | $this->notImplementedOperationError(); |
284 | 306 | } | ... | ... |
ieducar/modules/HistoricoEscolar/Views/ProcessamentoApiController.php
... | ... | @@ -298,7 +298,7 @@ class ProcessamentoApiController extends Core_Controller_Page_EditController |
298 | 298 | $isValid = $this->validatesPresenceOf($this->getRequest()->situacao, $name, $raiseExceptionOnError); |
299 | 299 | |
300 | 300 | if ($isValid) { |
301 | - $expectedOpers = ['buscar-matricula', 'aprovado', 'reprovado', 'em-andamento', 'transferido']; | |
301 | + $expectedOpers = ['buscar-matricula', 'aprovado', 'reprovado', 'em-andamento', 'transferido', 'reclassificado', 'abandono']; | |
302 | 302 | $isValid = $this->validatesValueInSetOf($this->getRequest()->situacao, $expectedOpers, $name, |
303 | 303 | $raiseExceptionOnError); |
304 | 304 | } |
... | ... | @@ -483,7 +483,9 @@ class ProcessamentoApiController extends Core_Controller_Page_EditController |
483 | 483 | 'aprovado' => App_Model_MatriculaSituacao::APROVADO, |
484 | 484 | 'reprovado' => App_Model_MatriculaSituacao::REPROVADO, |
485 | 485 | 'em-andamento' => App_Model_MatriculaSituacao::EM_ANDAMENTO, |
486 | - 'transferido' => App_Model_MatriculaSituacao::TRANSFERIDO | |
486 | + 'transferido' => App_Model_MatriculaSituacao::TRANSFERIDO, | |
487 | + 'reclassificado' => App_Model_MatriculaSituacao::RECLASSIFICADO, | |
488 | + 'abandono' => App_Model_MatriculaSituacao::ABANDONO | |
487 | 489 | ]; |
488 | 490 | $situacao = $situacoes[$this->getRequest()->situacao]; |
489 | 491 | } |
... | ... | @@ -1004,7 +1006,9 @@ class ProcessamentoApiController extends Core_Controller_Page_EditController |
1004 | 1006 | 'reprovado-faltas' => App_Model_MatriculaSituacao::REPROVADO_POR_FALTAS, |
1005 | 1007 | 'em-andamento' => App_Model_MatriculaSituacao::EM_ANDAMENTO, |
1006 | 1008 | 'aprovado-conselho' => App_Model_MatriculaSituacao::APROVADO_PELO_CONSELHO, |
1007 | - 'aprovado-dependencia' => App_Model_MatriculaSituacao::APROVADO_COM_DEPENDENCIA | |
1009 | + 'aprovado-dependencia' => App_Model_MatriculaSituacao::APROVADO_COM_DEPENDENCIA, | |
1010 | + 'reclassificado' => App_Model_MatriculaSituacao::RECLASSIFICADO, | |
1011 | + 'abandono' => App_Model_MatriculaSituacao::ABANDONO | |
1008 | 1012 | ]; |
1009 | 1013 | |
1010 | 1014 | foreach ($alunos as $aluno) { | ... | ... |
ieducar/modules/HistoricoEscolar/Views/ProcessamentoController.php
... | ... | @@ -117,6 +117,8 @@ class ProcessamentoController extends Portabilis_Controller_Page_ListController |
117 | 117 | <option value='aprovado'>Aprovado</option> |
118 | 118 | <option value='reprovado'>Reprovado</option> |
119 | 119 | <option value='transferido'>Transferido</option> |
120 | + <option value='reclassificado'>Reclassificado</option> | |
121 | + <option value='abandono'>Abandono</option> | |
120 | 122 | </select> |
121 | 123 | </td> |
122 | 124 | </tr> |
... | ... | @@ -181,7 +183,7 @@ class ProcessamentoController extends Portabilis_Controller_Page_ListController |
181 | 183 | </td> |
182 | 184 | <td><input id='faltas-manual' name='faltas-manual' style='display:none;'></input></td> |
183 | 185 | </tr> |
184 | - | |
186 | + | |
185 | 187 | <tr id='tr-area-conhecimento'> |
186 | 188 | <td><label for='area-conhecimento'>Area Conhecimento </label></td> |
187 | 189 | <td> | ... | ... |