Skip to content

Commit

Permalink
Merge pull request #930 from portabilis/portabilis-patch-2023-12-26
Browse files Browse the repository at this point in the history
Portabilis patch 26/12/2023
  • Loading branch information
edersoares authored Dec 26, 2023
2 parents 606e8ea + 1ef70bd commit 18fe2da
Show file tree
Hide file tree
Showing 25 changed files with 951 additions and 29 deletions.
24 changes: 24 additions & 0 deletions app/Events/RegistrationCopyEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Events;

use App\Models\LegacyRegistration;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class RegistrationCopyEvent
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct(public LegacyRegistration $newRegistration, public LegacyRegistration $oldRegistration)
{
}
}
38 changes: 38 additions & 0 deletions app/Http/Controllers/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Jobs\DatabaseToCsvExporter;
use App\Models\Exporter\Employee;
use App\Models\Exporter\Enrollment;
use App\Models\Exporter\Export;
use App\Models\Exporter\SocialAssistance;
Expand Down Expand Up @@ -117,6 +118,10 @@ protected function filter(Request $request)
$data = $this->filterStages($request, $data);
}

if ($model === Employee::class) {
$data = $this->filterEmployees($request, $data);
}

return $data;
}

Expand Down Expand Up @@ -205,6 +210,39 @@ public function filterTeachers(Request $request, $data)
return $data;
}

/**
* @param array $data
* @return array
*/
public function filterEmployees(Request $request, $data)
{
$data['filename'] = 'servidores.csv';

if ($year = $request->input('ano')) {
$data['filters'][] = [
'column' => 'exporter_employee.year_id',
'operator' => '@>',
'value' => (int) $year,
];
}

if ($request->input('ref_cod_escola')) {
$data['filters'][] = [
'column' => 'exporter_employee.school_id',
'operator' => '@>',
'value' => $request->input('ref_cod_escola'),
];
} elseif ($request->user()->isSchooling()) {
$data['filters'][] = [
'column' => 'exporter_employee.school_id',
'operator' => '@>',
'value' => $request->user()->schools->pluck('cod_escola'),
];
}

return $data;
}

/**
* @param array $data
* @return array
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class FileController extends Controller
{

public function show(File $file)
{
$url = (new UrlPresigner())->getPresignedUrl(
Expand Down
36 changes: 36 additions & 0 deletions app/Listeners/RegistrationCopyListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Listeners;

use App\Events\RegistrationCopyEvent;
use App\Exceptions\Transfer\MissingDescriptiveOpinionType;
use App\Exceptions\Transfer\StagesAreNotSame;
use App\Services\RegistrationDataService;
use App\Services\TransferRegistrationDataService;

class RegistrationCopyListener
{
/**
* @var TransferRegistrationDataService
*/
protected $service;

public function __construct(RegistrationDataService $service)
{
$this->service = $service;
}

/**
* Handle the event.
*
* @param object $event
* @return void
*
* @throws MissingDescriptiveOpinionType
* @throws StagesAreNotSame
*/
public function handle(RegistrationCopyEvent $event)
{
$this->service->copy($event->newRegistration, $event->oldRegistration);
}
}
72 changes: 72 additions & 0 deletions app/Models/Exporter/Builders/EmployeeEloquentBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace App\Models\Exporter\Builders;

use App\Support\Database\JoinableBuilder;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Query\JoinClause;

class EmployeeEloquentBuilder extends Builder
{
use JoinableBuilder;

/**
* @param array $columns
* @return TeacherEloquentBuilder
*/
public function person($columns)
{
$this->addSelect(
$this->joinColumns('person', $columns)
);

return $this->join('exporter_person as person', function (JoinClause $join) {
$join->on('exporter_employee.id', '=', 'person.id');
});
}

/**
* @return TeacherEloquentBuilder
*/
public function disabilities()
{
$this->addSelect(
$this->joinColumns('disabilities', ['disabilities'])
);

return $this->leftJoin('exporter_disabilities as disabilities', function (JoinClause $join) {
$join->on('exporter_employee.id', '=', 'disabilities.person_id');
});
}

/**
* @return TeacherEloquentBuilder
*/
public function phones()
{
$this->addSelect(
$this->joinColumns('phones', ['phones'])
);

return $this->leftJoin('exporter_phones as phones', function (JoinClause $join) {
$join->on('exporter_employee.id', '=', 'phones.person_id');
});
}

/**
* @param array $columns
* @return TeacherEloquentBuilder
*/
public function place($columns)
{
$this->addSelect(
$this->joinColumns('place', $columns)
);

return $this->leftJoin('person_has_place', function (JoinClause $join) {
$join->on('exporter_employee.id', '=', 'person_has_place.person_id');
})->leftJoin('addresses as place', function (JoinClause $join) {
$join->on('person_has_place.place_id', '=', 'place.id');
});
}
}
120 changes: 120 additions & 0 deletions app/Models/Exporter/Employee.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

namespace App\Models\Exporter;

use App\Models\Exporter\Builders\EmployeeEloquentBuilder;
use App\Models\Exporter\Builders\TeacherEloquentBuilder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;

class Employee extends Model
{
/**
* @var string
*/
protected $table = 'exporter_employee';

/**
* @var Collection
*/
protected $alias;

/**
* @param Builder $query
* @return TeacherEloquentBuilder
*/
public function newEloquentBuilder($query)
{
return new EmployeeEloquentBuilder($query);
}

/**
* @return array
*/
public function getExportedColumnsByGroup()
{
return [
'Códigos' => [
'id' => 'ID Pessoa',
'school_id' => 'ID Escola',
],
'Servidor' => [
'name' => 'Nome',
'social_name' => 'Nome social e/ou afetivo',
'cpf' => 'CPF',
'rg' => 'RG',
'rg_issue_date' => 'RG (Data Emissão)',
'rg_state_abbreviation' => 'RG (Estado)',
'date_of_birth' => 'Data de nascimento',
'email' => 'E-mail',
'sus' => 'Número SUS',
'nis' => 'NIS (PIS/PASEP)',
'occupation' => 'Ocupação',
'organization' => 'Empresa',
'monthly_income' => 'Renda Mensal',
'gender' => 'Gênero',
'race' => 'Raça',
],
'Alocação' => [
'employee_workload' => 'Carga horária do servidor',
'year' => 'Ano',
'school' => 'Escola',
'period' => 'Período',
'role' => 'Função',
'link' => 'Vínculo',
'allocated_workload' => 'Carga horária alocada',
],
'Informações' => [
'phones.phones' => 'Telefones',
'disabilities.disabilities' => 'Deficiências',
'schooling_degree' => 'Escolaridade',
'high_school_type' => 'Tipo de ensino médio cursado',
'employee_postgraduates_complete' => 'Pós-Graduações concluídas',
'continuing_education_course' => 'Outros cursos de formação continuada',
'employee_graduation_complete' => 'Curso(s) superior(es) concluído(s)',
],
'Endereço' => [
'place.address' => 'Logradouro',
'place.number' => 'Número',
'place.complement' => 'Complemento',
'place.neighborhood' => 'Bairro',
'place.postal_code' => 'CEP',
'place.latitude' => 'Latitude',
'place.longitude' => 'Longitude',
'place.city' => 'Cidade',
'place.state_abbreviation' => 'Sigla do Estado',
'place.state' => 'Estado',
'place.country' => 'País',
],
];
}

/**
* @return string
*/
public function getLabel()
{
return 'Servidores';
}

public function getDescription()
{
return 'Os dados exportados serão contabilizados por quantidade de servidores(as) alocados(as) no ano filtrado, agrupando as informações das alocações nas escolas.';
}

/**
* @param string $column
* @return string
*/
public function alias($column)
{
if (empty($this->alias)) {
$this->alias = collect($this->getExportedColumnsByGroup())->flatMap(function ($item) {
return $item;
});
}

return $this->alias->get($column, $column);
}
}
1 change: 1 addition & 0 deletions app/Models/Exporter/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function getAllowedExports()
3 => new Teacher(),
4 => new SocialAssistance(),
5 => new Stage(),
6 => new Employee(),
];
}

Expand Down
2 changes: 1 addition & 1 deletion app/Models/LegacyEvaluationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function isGeneralAbsence(): bool

public function hasOpinion(): bool
{
return in_array($this->registration->grade->evaluationRule?->parecer_descritivo, [0, 1], true);
return $this->parecer_descritivo !== 0;
}

public function isGeneralScore(): bool
Expand Down
5 changes: 5 additions & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Providers;

use App\Events\RegistrationCopyEvent;
use App\Events\RegistrationEvent;
use App\Events\ReportIssued;
use App\Events\TransferEvent;
Expand All @@ -15,6 +16,7 @@
use App\Listeners\LoginLegacySession;
use App\Listeners\MessageSendingListener;
use App\Listeners\NotificationWhenResetPassword;
use App\Listeners\RegistrationCopyListener;
use App\Listeners\ReportIssuedListener;
use App\Listeners\TransferNotificationListener;
use App\Models\LegacyRegistrationDisciplinaryOccurrenceType;
Expand Down Expand Up @@ -54,6 +56,9 @@ class EventServiceProvider extends ServiceProvider
CopyTransferDataListener::class,
AcceptTransferRequestListener::class,
],
RegistrationCopyEvent::class => [
RegistrationCopyListener::class,
],
TransferEvent::class => [
TransferNotificationListener::class,
],
Expand Down
Loading

0 comments on commit 18fe2da

Please sign in to comment.