45 lines
2.6 KiB
PHP
45 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\SupplierImprovementWorkflow;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class SupplierImprovementController extends Controller
|
|
{
|
|
public function store(Request $request, int $evaluation, SupplierImprovementWorkflow $workflow): RedirectResponse
|
|
{
|
|
return $this->execute($request, $evaluation, null, 'create', $workflow);
|
|
}
|
|
|
|
public function update(Request $request, int $evaluation, int $measure, string $command, SupplierImprovementWorkflow $workflow): RedirectResponse
|
|
{
|
|
return $this->execute($request, $evaluation, $measure, $command, $workflow);
|
|
}
|
|
|
|
private function execute(Request $request, int $evaluation, ?int $measure, string $command, SupplierImprovementWorkflow $workflow): RedirectResponse
|
|
{
|
|
abort_unless(Schema::hasTable('supplier_improvements'), 503, 'A instalação das medidas de melhoria ainda não está concluída.');
|
|
$rules = ['tenant_id' => 'prohibited', 'supplier_evaluation_id' => 'prohibited', 'created_by' => 'prohibited', 'status' => 'prohibited', 'contributors' => 'prohibited', 'reviewed_by' => 'prohibited', 'reviewed_at' => 'prohibited'];
|
|
if ($command === 'create' || $command === 'plan') {
|
|
$rules += ['title' => 'required|string|min:3|max:200', 'description' => 'required|string|min:10|max:10000', 'responsible_id' => 'required|integer|min:1', 'due_on' => 'required|date_format:Y-m-d', 'result' => 'prohibited', 'evidence' => 'prohibited'];
|
|
} else {
|
|
$rules += ['title' => 'prohibited', 'description' => 'prohibited', 'responsible_id' => 'prohibited', 'due_on' => 'prohibited'];
|
|
}
|
|
$rules += $command === 'create' ? ['operation_key' => 'required|uuid', 'version' => 'prohibited', 'reason' => 'prohibited'] : ['operation_key' => 'prohibited', 'version' => 'required|integer|min:1'];
|
|
if (in_array($command, ['progress', 'submit'], true)) {
|
|
$rules += ['result' => 'nullable|string|max:10000', 'evidence' => 'nullable|string|max:10000', 'reason' => 'prohibited'];
|
|
} elseif ($command !== 'create') {
|
|
$rules += ['reason' => 'required|string|min:10|max:4000'];
|
|
if ($command !== 'plan') {
|
|
$rules += ['result' => 'prohibited', 'evidence' => 'prohibited'];
|
|
}
|
|
}
|
|
$workflow->execute($request->user(), $evaluation, $measure, $command, $request->validate($rules));
|
|
|
|
return to_route('supplier-evaluations.show', $evaluation)->with('supplier_evaluation_notice', 'Medida de melhoria e histórico actualizados.');
|
|
}
|
|
}
|