-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #689 from portabilis/portabilis-patch-2019-12-15
Portabilis patch 15/12/2019
- Loading branch information
Showing
40 changed files
with
1,160 additions
and
193 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
app/Http/Controllers/UpdateRegistrationStatusController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Http\Requests\UpdateRegistrationStatusRequest; | ||
use App\Models\LegacyRegistration; | ||
use App\Models\LegacyTransferType; | ||
use App\Process; | ||
use App\Services\RegistrationService; | ||
use App_Model_MatriculaSituacao; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\View\View; | ||
|
||
class UpdateRegistrationStatusController extends Controller | ||
{ | ||
/** | ||
* @param Request $request | ||
* @return View | ||
*/ | ||
public function index(Request $request) | ||
{ | ||
$this->breadcrumb('Atualização da situação de matrículas em lote', [ | ||
url('intranet/educar_configuracoes_index.php') => 'Configurações', | ||
]); | ||
|
||
$this->menu(Process::UPDATE_REGISTRATION_STATUS); | ||
|
||
return view('registration.update-registration-status.index', ['user' => $request->user()]); | ||
} | ||
|
||
/** | ||
* Atualiza a situação das matrículas de acordo com o filtro | ||
* | ||
* @param UpdateRegistrationStatusRequest $request | ||
* @param RegistrationService $registrationService | ||
* @return \Illuminate\Http\RedirectResponse | ||
*/ | ||
public function updateStatus(UpdateRegistrationStatusRequest $request, RegistrationService $registrationService) | ||
{ | ||
$query = LegacyRegistration::active(); | ||
|
||
if ($request->get('ano')) { | ||
$query->where('ano', $request->get('ano')); | ||
} | ||
|
||
if ($request->get('ref_cod_escola')) { | ||
$query->where('ref_ref_cod_escola', $request->get('ref_cod_escola')); | ||
} | ||
|
||
if ($request->get('ref_cod_curso')) { | ||
$query->where('ref_cod_curso', $request->get('ref_cod_curso')); | ||
} | ||
|
||
if ($request->get('ref_cod_turma')) { | ||
$schoolClassId = $request->get('ref_cod_turma'); | ||
$query->whereHas('enrollments', function ($enrollmentQuery) use ($schoolClassId) { | ||
$enrollmentQuery->where('ref_cod_turma', $schoolClassId); | ||
}); | ||
} | ||
|
||
if ($request->get('ref_cod_serie')) { | ||
$query->where('ref_ref_cod_serie', $request->get('ref_cod_serie')); | ||
} | ||
|
||
$query->where('aprovado', $request->get('situacao')); | ||
|
||
$registrations = $query->get(); | ||
|
||
DB::beginTransaction(); | ||
|
||
foreach ($registrations as $registration) { | ||
$registrationService->updateStatus( | ||
$registration, | ||
$request->only([ | ||
'nova_situacao', | ||
'transferencia_data', | ||
'transferencia_tipo', | ||
'transferencia_observacoes', | ||
]) | ||
); | ||
} | ||
|
||
DB::commit(); | ||
|
||
return redirect()->route('update-registration-status.index')->with('success', count($registrations) . ' matrículas atualizadas com sucesso.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use App_Model_MatriculaSituacao; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class UpdateRegistrationStatusRequest extends FormRequest | ||
{ | ||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
$rules = $this->getTransferValidations(); | ||
return array_merge($rules, [ | ||
'ano' => [ | ||
'required', | ||
'date_format:Y', | ||
], | ||
'ref_cod_instituicao' => 'required', | ||
'situacao' => 'required', | ||
'nova_situacao' => 'required', | ||
]); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function messages() | ||
{ | ||
return [ | ||
'ano.required' => 'O ano é obrigatório.', | ||
'ano.date_format' => 'O campo Ano deve ser um ano válido.', | ||
'ref_cod_instituicao.required' => 'A instituição é obrigatória.', | ||
'situacao.required' => 'A situação é obrigatória.', | ||
'nova_situacao.required' => 'A nova situação é obrigatória.', | ||
'transferencia_tipo.required' => 'O motivo da transferência é obrigatório.', | ||
'transferencia_data.required' => 'A data da transferência é obrigatória.', | ||
]; | ||
} | ||
|
||
private function getTransferValidations() | ||
{ | ||
if ($this->nova_situacao == App_Model_MatriculaSituacao::TRANSFERIDO) { | ||
return [ | ||
'transferencia_tipo' => 'required', | ||
'transferencia_data' => 'required', | ||
]; | ||
} | ||
|
||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.