Merge branch 'feature/108-Moznost-evidovat-platene-zamestnanie-ako-prax' into develop

This commit is contained in:
2025-11-29 16:48:18 +01:00
26 changed files with 243 additions and 145 deletions

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Enums;
enum InternshipStatus: string
{
case SUBMITTED = 'SUBMITTED';
case CONFIRMED_BY_COMPANY = 'CONFIRMED_BY_COMPANY';
case CONFIRMED_BY_ADMIN = 'CONFIRMED_BY_ADMIN';
case DENIED_BY_COMPANY = 'DENIED_BY_COMPANY';
case DENIED_BY_ADMIN = 'DENIED_BY_ADMIN';
case DEFENDED = 'DEFENDED';
case NOT_DEFENDED = 'NOT_DEFENDED';
public static function all(): array
{
return array_map(fn($case) => $case->value, self::cases());
}
}

View File

@@ -5,7 +5,7 @@ namespace App\Http\Controllers;
use App\Models\Company; use App\Models\Company;
use App\Models\User; use App\Models\User;
use App\Models\Internship; use App\Models\Internship;
use App\Models\InternshipStatus; use App\Models\InternshipStatusData;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@@ -186,7 +186,7 @@ class CompanyController extends Controller
// mazanie statusov // mazanie statusov
$internships->each(function ($internship) { $internships->each(function ($internship) {
InternshipStatus::whereInternshipId($internship->id)->delete(); InternshipStatusData::whereInternshipId($internship->id)->delete();
}); });
// mazanie praxov // mazanie praxov

View File

@@ -4,7 +4,7 @@ namespace App\Http\Controllers;
use App\Models\Company; use App\Models\Company;
use App\Models\Internship; use App\Models\Internship;
use App\Models\InternshipStatus; use App\Models\InternshipStatusData;
use App\Models\User; use App\Models\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Mpdf\Mpdf; use Mpdf\Mpdf;
@@ -61,7 +61,7 @@ class InternshipController extends Controller
return response()->json($internship); return response()->json($internship);
} }
public function get_default_agreement(Request $request, int $id) public function get_default_proof(Request $request, int $id)
{ {
$user = auth()->user(); $user = auth()->user();
$internship = Internship::find($id); $internship = Internship::find($id);
@@ -78,7 +78,7 @@ class InternshipController extends Controller
$contact = User::find($internship->company->contact); $contact = User::find($internship->company->contact);
$html = view('agreement.default', [ $html = view('proof.default', [
'company' => $internship->company, 'company' => $internship->company,
'companyContact' => $contact, 'companyContact' => $contact,
'internship' => $internship, 'internship' => $internship,
@@ -93,10 +93,10 @@ class InternshipController extends Controller
return response($pdf->Output('', 'S'), 200) return response($pdf->Output('', 'S'), 200)
->header('Content-Type', 'application/pdf') ->header('Content-Type', 'application/pdf')
->header('Content-Disposition', 'attachment; filename="agreement_' . $id . '.pdf"'); ->header('Content-Disposition', 'attachment; filename="proof_' . $id . '.pdf"');
} }
public function get_agreement(int $id) public function get_proof(int $id)
{ {
$user = auth()->user(); $user = auth()->user();
$internship = Internship::find($id); $internship = Internship::find($id);
@@ -107,9 +107,9 @@ class InternshipController extends Controller
], 400); ], 400);
} }
if (!$internship->agreement) { if (!$internship->proof) {
return response()->json([ return response()->json([
'message' => 'No agreement file exists for this internship.' 'message' => 'No proof file exists for this internship.'
], 404); ], 404);
} }
@@ -117,9 +117,9 @@ class InternshipController extends Controller
abort(403, 'Unauthorized'); abort(403, 'Unauthorized');
} }
return response($internship->agreement, 200) return response($internship->proof, 200)
->header('Content-Type', 'application/pdf') ->header('Content-Type', 'application/pdf')
->header('Content-Disposition', 'attachment; filename="agreement_' . $id . '.pdf"'); ->header('Content-Disposition', 'attachment; filename="proof_' . $id . '.pdf"');
} }
public function get_report(int $id) public function get_report(int $id)
@@ -182,10 +182,10 @@ class InternshipController extends Controller
'year_of_study' => $request->year_of_study, 'year_of_study' => $request->year_of_study,
'semester' => $request->semester, 'semester' => $request->semester,
'position_description' => $request->position_description, 'position_description' => $request->position_description,
'agreement' => null 'proof' => null
]); ]);
InternshipStatus::create([ InternshipStatusData::create([
'internship_id' => $Internship->id, 'internship_id' => $Internship->id,
'status' => 'SUBMITTED', 'status' => 'SUBMITTED',
'changed' => now(), 'changed' => now(),
@@ -250,13 +250,13 @@ class InternshipController extends Controller
} }
$request->validate([ $request->validate([
'agreement' => ['nullable', 'file', 'mimes:pdf', 'max:10240'], 'proof' => ['nullable', 'file', 'mimes:pdf', 'max:10240'],
'report' => ['nullable', 'file', 'mimes:pdf', 'max:10240'], 'report' => ['nullable', 'file', 'mimes:pdf', 'max:10240'],
'report_confirmed' => ['required', 'boolean'], 'report_confirmed' => ['required', 'boolean'],
]); ]);
if ($request->hasFile('agreement')) { if ($request->hasFile('proof')) {
$internship->agreement = file_get_contents($request->file('agreement')->getRealPath()); $internship->proof = file_get_contents($request->file('proof')->getRealPath());
} }
if ($request->hasFile('report')) { if ($request->hasFile('report')) {
@@ -264,9 +264,9 @@ class InternshipController extends Controller
} }
if ($user->role === 'EMPLOYER') { if ($user->role === 'EMPLOYER') {
if ($request->report_confirmed && (!$internship->agreement || !$internship->report)) { if ($request->report_confirmed && (!$internship->proof || !$internship->report)) {
return response()->json([ return response()->json([
'message' => 'Report cannot be confirmed without an agreement and report.' 'message' => 'Report cannot be confirmed without an proof and report.'
], 400); ], 400);
} }

View File

@@ -2,19 +2,19 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Enums\InternshipStatus;
use App\Mail\InternshipStatusUpdated; use App\Mail\InternshipStatusUpdated;
use App\Models\Internship; use App\Models\Internship;
use App\Models\InternshipStatus; use App\Models\InternshipStatusData;
use App\Models\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Mail; use Mail;
class InternshipStatusController extends Controller class InternshipStatusDataController extends Controller
{ {
public function get(int $id) public function get(int $id)
{ {
$user = auth()->user(); $user = auth()->user();
$internship_statuses = InternshipStatus::whereInternshipId($id)->orderByDesc('changed')->get(); $internship_statuses = InternshipStatusData::whereInternshipId($id)->orderByDesc('changed')->get();
if (!$internship_statuses) { if (!$internship_statuses) {
return response()->json([ return response()->json([
@@ -45,9 +45,7 @@ class InternshipStatusController extends Controller
abort(403, 'Unauthorized'); abort(403, 'Unauthorized');
} }
$currentStatus = $internship->status; $nextPossibleStatuses = $internship->nextStates($user->role);
$nextPossibleStatuses = $this->possibleNewStatuses($currentStatus->status, $user->role, $internship->report_confirmed);
return response()->json($nextPossibleStatuses); return response()->json($nextPossibleStatuses);
} }
@@ -78,7 +76,7 @@ class InternshipStatusController extends Controller
/** /**
* Display the specified resource. * Display the specified resource.
*/ */
public function show(InternshipStatus $internshipStatus) public function show(InternshipStatusData $internshipStatus)
{ {
// //
} }
@@ -86,7 +84,7 @@ class InternshipStatusController extends Controller
/** /**
* Show the form for editing the specified resource. * Show the form for editing the specified resource.
*/ */
public function edit(InternshipStatus $internshipStatus) public function edit(InternshipStatusData $internshipStatus)
{ {
// //
} }
@@ -110,14 +108,14 @@ class InternshipStatusController extends Controller
} }
$internshipStatus = $internship->status; $internshipStatus = $internship->status;
$newStatusValidator = 'in:' . implode(',', $this->possibleNewStatuses($internshipStatus->status, $user->role, $internship->report_confirmed)); $newStatusValidator = 'in:' . implode(',', $internship->nextStates($user->role));
$request->validate([ $request->validate([
'status' => ['required', 'string', 'uppercase', $newStatusValidator], 'status' => ['required', 'string', 'uppercase', $newStatusValidator],
'note' => ['required', 'string', 'min:1'] 'note' => ['required', 'string', 'min:1']
]); ]);
InternshipStatus::create([ $newStatus = InternshipStatusData::make([
'internship_id' => $id, 'internship_id' => $id,
'status' => $request->status, 'status' => $request->status,
'note' => $request->note, 'note' => $request->note,
@@ -125,47 +123,26 @@ class InternshipStatusController extends Controller
'modified_by' => $user->id 'modified_by' => $user->id
]); ]);
Mail::to($internship->student)->sendNow(new InternshipStatusUpdated($internship, $user->name, $internship->student->name, $internship->company->name, $internshipStatus->status, $request->status, $request->note)); Mail::to($internship->student)
->sendNow(new InternshipStatusUpdated(
$internship,
$user->name,
$internship->student->name,
$internship->company->name,
$internshipStatus->status,
$request->enum('status', InternshipStatus::class),
$request->note
));
$newStatus->save();
return response()->noContent(); return response()->noContent();
} }
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
*/ */
public function destroy(InternshipStatus $internshipStatus) public function destroy(InternshipStatusData $internshipStatus)
{ {
// //
} }
private function possibleNewStatuses(string $current_status, string $userRole, bool $report_confirmed)
{
if ($userRole === "STUDENT")
return [];
switch ($current_status) {
case 'SUBMITTED':
return ['CONFIRMED', 'DENIED'];
case 'CONFIRMED':
if ($userRole === 'EMPLOYER') {
return ['DENIED'];
}
if ($report_confirmed) {
return ['SUBMITTED', 'DENIED', 'DEFENDED', 'NOT_DEFENDED'];
}
return ['SUBMITTED', 'DENIED'];
case 'DENIED':
if ($userRole === 'EMPLOYER') {
return ['CONFIRMED'];
}
return ['SUBMITTED', 'CONFIRMED'];
case 'DEFENDED':
case 'NOT_DEFENDED':
return [];
default:
throw new \InvalidArgumentException('Unknown status');
}
}
} }

View File

@@ -5,7 +5,7 @@ namespace App\Http\Controllers;
use App\Models\Internship; use App\Models\Internship;
use App\Models\StudentData; use App\Models\StudentData;
use App\Models\User; use App\Models\User;
use App\Models\InternshipStatus; use App\Models\InternshipStatusData;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@@ -208,7 +208,7 @@ class StudentDataController extends Controller
// mazanie statusov // mazanie statusov
$internships->each(function ($internship) { $internships->each(function ($internship) {
InternshipStatus::whereInternshipId($internship->id)->delete(); InternshipStatusData::whereInternshipId($internship->id)->delete();
}); });
// mazanie praxov // mazanie praxov

View File

@@ -2,6 +2,7 @@
namespace App\Mail; namespace App\Mail;
use App\Enums\InternshipStatus;
use App\Models\Internship; use App\Models\Internship;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable; use Illuminate\Mail\Mailable;
@@ -17,14 +18,14 @@ class InternshipStatusUpdated extends Mailable
private string $changedByName; private string $changedByName;
private string $studentName; private string $studentName;
private string $companyName; private string $companyName;
private string $oldStatus; private InternshipStatus $oldStatus;
private string $newStatus; private InternshipStatus $newStatus;
private string $note; private string $note;
/** /**
* Create a new message instance. * Create a new message instance.
*/ */
public function __construct(Internship $internship, string $changedByName, string $studentName, string $companyName, string $oldStatus, string $newStatus, string $note) public function __construct(Internship $internship, string $changedByName, string $studentName, string $companyName, InternshipStatus $oldStatus, InternshipStatus $newStatus, string $note)
{ {
$this->internship = $internship; $this->internship = $internship;
$this->changedByName = $changedByName; $this->changedByName = $changedByName;
@@ -57,8 +58,8 @@ class InternshipStatusUpdated extends Mailable
"changedByName" => $this->changedByName, "changedByName" => $this->changedByName,
"studentName" => $this->studentName, "studentName" => $this->studentName,
"companyName" => $this->companyName, "companyName" => $this->companyName,
"oldStatus" => $this->prettyStatus($this->oldStatus), "oldStatus" => $this->prettyStatus($this->oldStatus->value),
"newStatus" => $this->prettyStatus($this->newStatus), "newStatus" => $this->prettyStatus($this->newStatus->value),
"note" => $this->note, "note" => $this->note,
] ]
); );
@@ -78,8 +79,10 @@ class InternshipStatusUpdated extends Mailable
{ {
return match ($status) { return match ($status) {
'SUBMITTED' => 'Zadané', 'SUBMITTED' => 'Zadané',
'CONFIRMED' => 'Potvrdená', 'CONFIRMED_BY_COMPANY' => 'Potvrdená firmou',
'DENIED' => 'Zamietnutá', 'CONFIRMED_BY_ADMIN' => 'Potvrdená garantom',
'DENIED_BY_COMPANY' => 'Zamietnutá firmou',
'DENIED_BY_ADMIN' => 'Zamietnutá garantom',
'DEFENDED' => 'Obhájená', 'DEFENDED' => 'Obhájená',
'NOT_DEFENDED' => 'Neobhájená', 'NOT_DEFENDED' => 'Neobhájená',
default => throw new \Exception("Invalid status: $status") default => throw new \Exception("Invalid status: $status")

View File

@@ -2,6 +2,7 @@
namespace App\Models; namespace App\Models;
use App\Enums\InternshipStatus;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
@@ -24,7 +25,7 @@ class Internship extends Model
'year_of_study', 'year_of_study',
'semester', 'semester',
'position_description', 'position_description',
'agreement', 'proof',
'report', 'report',
'report_confirmed', 'report_confirmed',
]; ];
@@ -63,7 +64,59 @@ class Internship extends Model
public function status() public function status()
{ {
return $this->hasOne(InternshipStatus::class, 'internship_id')->latestOfMany(); return $this->hasOne(InternshipStatusData::class, 'internship_id')->latestOfMany();
}
public function nextStates(string $userRole)
{
$current_status = $this->status->status;
$report_confirmed = $this->report_confirmed;
// študent nemôže meniť stav
if ($userRole === 'STUDENT')
return [];
/*
nasledujúci platný stav je určený podľa:
- aktuálneho stavu
- roly používateľa, ktorý ide meniť stav
- či bol výkaz potvrdený firmou
*/
return match (true) {
// prax bola iba vytvorená a ide ju meniť admin alebo firma
$current_status === InternshipStatus::SUBMITTED
=> ['CONFIRMED_BY_COMPANY', 'DENIED_BY_COMPANY'],
// prax bola potvrdená firmou a ide ju meniť admin
$current_status === InternshipStatus::CONFIRMED_BY_COMPANY && $userRole === "ADMIN"
=> ['CONFIRMED_BY_ADMIN', 'DENIED_BY_ADMIN'],
// prax bola potvrdená firmou a ide ju meniť firma
$current_status === InternshipStatus::CONFIRMED_BY_COMPANY && $userRole === "EMPLOYER"
=> ['DENIED_BY_COMPANY'],
// prax bola zamietnutá firmou a ide ju meniť admin
$current_status === InternshipStatus::DENIED_BY_COMPANY && $userRole === "ADMIN"
=> ['CONFIRMED_BY_COMPANY', 'SUBMITTED'],
// prax bola potvrdená garantom, ide ju meniť admin a výkaz bol potvrdený firmou
$current_status === InternshipStatus::CONFIRMED_BY_ADMIN && $userRole === "ADMIN" && $report_confirmed
=> ['DENIED_BY_ADMIN', 'CONFIRMED_BY_COMPANY', 'DENIED_BY_COMPANY', 'DEFENDED', 'NOT_DEFENDED'],
// prax bola potvrdená garantom, ide ju meniť admin a výkaz nebol potvrdený firmou
$current_status === InternshipStatus::CONFIRMED_BY_ADMIN && $userRole === "ADMIN" && !$report_confirmed
=> ['DENIED_BY_ADMIN', 'CONFIRMED_BY_COMPANY', 'DENIED_BY_COMPANY'],
// prax bola obhájená a ide ju meniť admin
$current_status === InternshipStatus::DEFENDED && $userRole === "ADMIN"
=> ['NOT_DEFENDED'],
// prax nebola obhájená a ide ju meniť admin
$current_status === InternshipStatus::NOT_DEFENDED && $userRole === "ADMIN"
=> ['DEFENDED'],
default => []
};
} }
/** /**
@@ -82,7 +135,7 @@ class Internship extends Model
'year_of_study' => $this->year_of_study, 'year_of_study' => $this->year_of_study,
'semester' => $this->semester, 'semester' => $this->semester,
'position_description' => $this->position_description, 'position_description' => $this->position_description,
'agreement' => $this->agreement !== null, 'proof' => $this->proof !== null,
'report' => $this->report !== null, 'report' => $this->report !== null,
'report_confirmed' => $this->report_confirmed, 'report_confirmed' => $this->report_confirmed,
'status' => $this->status, 'status' => $this->status,

View File

@@ -5,7 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class InternshipStatus extends Model class InternshipStatusData extends Model
{ {
/** @use HasFactory<\Database\Factories\InternshipStatusFactory> */ /** @use HasFactory<\Database\Factories\InternshipStatusFactory> */
use HasFactory; use HasFactory;
@@ -33,6 +33,20 @@ class InternshipStatus extends Model
'updated_at', 'updated_at',
]; ];
protected $table = 'internship_statuses';
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'status' => '\App\Enums\InternshipStatus',
];
}
public function modifiedBy() public function modifiedBy()
{ {
return $this->belongsTo(User::class, 'modified_by'); return $this->belongsTo(User::class, 'modified_by');
@@ -43,7 +57,7 @@ class InternshipStatus extends Model
return [ return [
'id' => $this->id, 'id' => $this->id,
'internship_id' => $this->internship_id, 'internship_id' => $this->internship_id,
'status' => $this->status, 'status' => $this->status->value,
'changed' => $this->changed, 'changed' => $this->changed,
'note' => $this->note, 'note' => $this->note,
'modified_by' => $this->modifiedBy, 'modified_by' => $this->modifiedBy,

View File

@@ -12,7 +12,7 @@
"php": "^8.2", "php": "^8.2",
"laravel/framework": "^12.0", "laravel/framework": "^12.0",
"laravel/sanctum": "^4.0", "laravel/sanctum": "^4.0",
"laravel/tinker": "^2.10.1", "laravel/tinker": "^2.10",
"mpdf/mpdf": "^8.2" "mpdf/mpdf": "^8.2"
}, },
"require-dev": { "require-dev": {

14
backend/composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "9911f9a2eb5e48d459c109368a23930b", "content-hash": "3b2e99453e86a7f518baa13eca7aa622",
"packages": [ "packages": [
{ {
"name": "brick/math", "name": "brick/math",
@@ -1458,16 +1458,16 @@
}, },
{ {
"name": "laravel/tinker", "name": "laravel/tinker",
"version": "v2.10.1", "version": "v2.10.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/tinker.git", "url": "https://github.com/laravel/tinker.git",
"reference": "22177cc71807d38f2810c6204d8f7183d88a57d3" "reference": "3bcb5f62d6f837e0f093a601e26badafb127bd4c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/tinker/zipball/22177cc71807d38f2810c6204d8f7183d88a57d3", "url": "https://api.github.com/repos/laravel/tinker/zipball/3bcb5f62d6f837e0f093a601e26badafb127bd4c",
"reference": "22177cc71807d38f2810c6204d8f7183d88a57d3", "reference": "3bcb5f62d6f837e0f093a601e26badafb127bd4c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -1518,9 +1518,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/laravel/tinker/issues", "issues": "https://github.com/laravel/tinker/issues",
"source": "https://github.com/laravel/tinker/tree/v2.10.1" "source": "https://github.com/laravel/tinker/tree/v2.10.2"
}, },
"time": "2025-01-27T14:24:01+00:00" "time": "2025-11-20T16:29:12+00:00"
}, },
{ {
"name": "league/commonmark", "name": "league/commonmark",

View File

@@ -27,7 +27,7 @@ class InternshipFactory extends Factory
'year_of_study' => fake()->randomElement([1, 2, 3, 4, 5]), 'year_of_study' => fake()->randomElement([1, 2, 3, 4, 5]),
'semester' => fake()->randomElement(["WINTER", "SUMMER"]), 'semester' => fake()->randomElement(["WINTER", "SUMMER"]),
'position_description' => fake()->jobTitle(), 'position_description' => fake()->jobTitle(),
'agreement' => null, 'proof' => null,
'report' => null, 'report' => null,
'report_confirmed' => false, 'report_confirmed' => false,
]; ];

View File

@@ -2,12 +2,13 @@
namespace Database\Factories; namespace Database\Factories;
use App\Enums\InternshipStatus;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
/** /**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\InternshipStatus> * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\InternshipStatusData>
*/ */
class InternshipStatusFactory extends Factory class InternshipStatusDataFactory extends Factory
{ {
/** /**
* Define the model's default state. * Define the model's default state.
@@ -18,7 +19,7 @@ class InternshipStatusFactory extends Factory
{ {
return [ return [
'internship_id' => 0, 'internship_id' => 0,
'status' => fake()->randomElement(["SUBMITTED", "CONFIRMED", "DENIED", "DEFENDED", "NOT_DEFENDED"]), 'status' => fake()->randomElement(InternshipStatus::all()),
'changed' => fake()->dateTime(), 'changed' => fake()->dateTime(),
'note' => null, 'note' => null,
'modified_by' => 0, 'modified_by' => 0,

View File

@@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration {
{
/** /**
* Run the migrations. * Run the migrations.
*/ */
@@ -20,7 +19,7 @@ return new class extends Migration
$table->unsignedSmallInteger("year_of_study")->nullable(false); $table->unsignedSmallInteger("year_of_study")->nullable(false);
$table->enum("semester", ["WINTER", "SUMMER"])->nullable(false); $table->enum("semester", ["WINTER", "SUMMER"])->nullable(false);
$table->string("position_description")->nullable(false); $table->string("position_description")->nullable(false);
$table->binary("agreement")->nullable(true); $table->binary("proof")->nullable(true);
$table->binary("report")->nullable(true); $table->binary("report")->nullable(true);
$table->boolean("report_confirmed")->nullable(false)->default(false); $table->boolean("report_confirmed")->nullable(false)->default(false);
$table->timestamps(); $table->timestamps();

View File

@@ -1,11 +1,11 @@
<?php <?php
use App\Enums\InternshipStatus;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration {
{
/** /**
* Run the migrations. * Run the migrations.
*/ */
@@ -14,7 +14,7 @@ return new class extends Migration
Schema::create('internship_statuses', function (Blueprint $table) { Schema::create('internship_statuses', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId("internship_id")->nullable(false)->constrained("internships")->onDelete("cascade"); $table->foreignId("internship_id")->nullable(false)->constrained("internships")->onDelete("cascade");
$table->enum("status", ["SUBMITTED", "CONFIRMED", "DENIED", "DEFENDED", "NOT_DEFENDED"])->nullable(false)->default("SUBMITTED"); $table->enum("status", InternshipStatus::all())->nullable(false)->default(InternshipStatus::SUBMITTED);
$table->dateTimeTz("changed")->nullable(false); $table->dateTimeTz("changed")->nullable(false);
$table->string("note")->nullable(true)->default(null); $table->string("note")->nullable(true)->default(null);
$table->foreignId("modified_by")->nullable(false)->constrained("users")->onDelete("cascade"); $table->foreignId("modified_by")->nullable(false)->constrained("users")->onDelete("cascade");

View File

@@ -4,7 +4,7 @@ namespace Database\Seeders;
use App\Models\Company; use App\Models\Company;
use App\Models\Internship; use App\Models\Internship;
use App\Models\InternshipStatus; use App\Models\InternshipStatusData;
use App\Models\StudentData; use App\Models\StudentData;
use App\Models\User; use App\Models\User;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents; // use Illuminate\Database\Console\Seeds\WithoutModelEvents;
@@ -57,7 +57,7 @@ class DatabaseSeeder extends Seeder
'company_id' => Company::inRandomOrder()->value('id'), 'company_id' => Company::inRandomOrder()->value('id'),
]); ]);
InternshipStatus::factory()->create([ InternshipStatusData::factory()->create([
'internship_id' => $internship->id, 'internship_id' => $internship->id,
'status' => "SUBMITTED", 'status' => "SUBMITTED",
'note' => 'made by seeder', 'note' => 'made by seeder',

View File

@@ -4,7 +4,7 @@ use App\Http\Controllers\Auth\RegisteredUserController;
use App\Http\Controllers\CompanyController; use App\Http\Controllers\CompanyController;
use App\Http\Controllers\InternshipController; use App\Http\Controllers\InternshipController;
use App\Http\Controllers\StudentDataController; use App\Http\Controllers\StudentDataController;
use App\Http\Controllers\InternshipStatusController; use App\Http\Controllers\InternshipStatusDataController;
use App\Models\Company; use App\Models\Company;
use App\Models\StudentData; use App\Models\StudentData;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@@ -46,11 +46,11 @@ Route::prefix('/internships')->group(function () {
//Route::middleware("auth:sanctum")->group(function () { //Route::middleware("auth:sanctum")->group(function () {
Route::prefix('/{id}')->group(function () { Route::prefix('/{id}')->group(function () {
Route::get("/", [InternshipController::class, 'get'])->name("api.internships.get"); Route::get("/", [InternshipController::class, 'get'])->name("api.internships.get");
Route::put("/status", [InternshipStatusController::class, 'update'])->name("api.internships.status.update"); Route::put("/status", [InternshipStatusDataController::class, 'update'])->name("api.internships.status.update");
Route::get("/statuses", [InternshipStatusController::class, 'get'])->name("api.internships.get"); Route::get("/statuses", [InternshipStatusDataController::class, 'get'])->name("api.internships.get");
Route::get("/next-statuses", [InternshipStatusController::class, 'get_next_states'])->name("api.internships.status.next.get"); Route::get("/next-statuses", [InternshipStatusDataController::class, 'get_next_states'])->name("api.internships.status.next.get");
Route::get("/default-agreement", [InternshipController::class, 'get_default_agreement'])->name("api.internships.agreement.default.get"); Route::get("/default-proof", [InternshipController::class, 'get_default_proof'])->name("api.internships.proof.default.get");
Route::get("/agreement", [InternshipController::class, 'get_agreement'])->name("api.internships.agreement.get"); Route::get("/proof", [InternshipController::class, 'get_proof'])->name("api.internships.proof.get");
Route::get("/report", [InternshipController::class, 'get_report'])->name("api.internships.report.get"); Route::get("/report", [InternshipController::class, 'get_report'])->name("api.internships.report.get");
Route::post("/documents", [InternshipController::class, 'update_documents'])->name("api.internships.documents.set"); Route::post("/documents", [InternshipController::class, 'update_documents'])->name("api.internships.documents.set");
Route::post("/basic", [InternshipController::class, 'update_basic'])->name("api.internships.update.basic"); Route::post("/basic", [InternshipController::class, 'update_basic'])->name("api.internships.update.basic");

View File

@@ -2,7 +2,8 @@
import { FetchError } from 'ofetch'; import { FetchError } from 'ofetch';
const props = defineProps<{ const props = defineProps<{
internship_id: number internship_id: number,
block?: boolean,
}>(); }>();
const client = useSanctumClient(); const client = useSanctumClient();
@@ -13,8 +14,8 @@ async function requestDownload() {
loading.value = true; loading.value = true;
try { try {
const agreement = await client<Blob>(`/api/internships/${props.internship_id}/default-agreement`); const proof = await client<Blob>(`/api/internships/${props.internship_id}/default-proof`);
triggerDownload(agreement, `default-agreement-${props.internship_id}`); triggerDownload(proof, `default-proof-${props.internship_id}`);
} catch (e) { } catch (e) {
if (e instanceof FetchError) { if (e instanceof FetchError) {
alert(`Nepodarilo sa vygenerovať zmluvu: ${e.statusMessage}`); alert(`Nepodarilo sa vygenerovať zmluvu: ${e.statusMessage}`);
@@ -27,8 +28,8 @@ async function requestDownload() {
<template> <template>
<div> <div>
<v-btn prepend-icon="mdi-download" color="blue" class="mr-2 mt-2" block :disabled="loading" <v-btn prepend-icon="mdi-download" color="blue" class="mr-2 mt-2 mb-2" :disabled="loading"
@click="requestDownload"> :block="block ?? undefined" @click="requestDownload">
<span v-show="!loading">Stiahnuť originálnu zmluvu</span> <span v-show="!loading">Stiahnuť originálnu zmluvu</span>
<span v-show="loading">Prosím čakajte...</span> <span v-show="loading">Prosím čakajte...</span>
</v-btn> </v-btn>

View File

@@ -18,7 +18,7 @@ const rules = {
const loading = ref(false); const loading = ref(false);
const error = ref<string | null>(null); const error = ref<string | null>(null);
const agreement = ref<File | null>(null); const proof = ref<File | null>(null);
const report = ref<File | null>(null); const report = ref<File | null>(null);
const report_confirmed = ref(props.internship.report_confirmed); const report_confirmed = ref(props.internship.report_confirmed);
@@ -35,9 +35,9 @@ function triggerDownload(file: Blob, file_name: string) {
window.URL.revokeObjectURL(url); window.URL.revokeObjectURL(url);
} }
async function downloadAgreement() { async function downloadProof() {
const agreement: Blob = await client(`/api/internships/${props.internship.id}/agreement`); const proof: Blob = await client(`/api/internships/${props.internship.id}/proof`);
triggerDownload(agreement, `agreement-${props.internship.id}`); triggerDownload(proof, `proof-${props.internship.id}`);
} }
async function downloadReport() { async function downloadReport() {
@@ -51,8 +51,8 @@ async function onSubmit() {
const formData = new FormData(); const formData = new FormData();
formData.append('report_confirmed', report_confirmed.value ? '1' : '0'); formData.append('report_confirmed', report_confirmed.value ? '1' : '0');
if (agreement.value) { if (proof.value) {
formData.append('agreement', agreement.value); formData.append('proof', proof.value);
} }
if (report.value) { if (report.value) {
formData.append('report', report.value); formData.append('report', report.value);
@@ -64,7 +64,7 @@ async function onSubmit() {
body: formData body: formData
}); });
agreement.value = null; proof.value = null;
report.value = null; report.value = null;
emit('successfulSubmit'); emit('successfulSubmit');
} catch (e) { } catch (e) {
@@ -87,19 +87,22 @@ async function onSubmit() {
<v-form @submit.prevent="onSubmit" :disabled="loading"> <v-form @submit.prevent="onSubmit" :disabled="loading">
<div> <div>
<h4 class="mb-2">Podpísaná zmluva / dohoda</h4> <h4 class="mb-2">Dokument o vykonaní praxe</h4>
<WarningAlert v-if="props.internship.agreement" title="Existujúci dokument" <p>Zmluva/dohoda o brigádnickej praxi alebo 3 faktúry v pre živnostníkov.</p>
text="V systéme je už nahratá zmluva/dohoda. Ak chcete nahradiť existujúcu verziu, vyberte súbor, alebo v opačnom prípade nechajte toto pole nevyplnené."> <InternshipAgreementDownloader :internship_id="internship.id" />
<WarningAlert v-if="props.internship.proof" title="Existujúci dokument"
text="V systéme je už nahratý dokument. Ak chcete nahradiť existujúcu verziu, vyberte súbor, alebo v opačnom prípade nechajte toto pole nevyplnené.">
<br /> <br />
<v-btn prepend-icon="mdi-download" color="blue" class="mr-2 mt-2" @click="downloadAgreement"> <v-btn prepend-icon="mdi-download" color="blue" class="mr-2 mt-2" @click="downloadProof">
Stiahnuť Stiahnuť
</v-btn> </v-btn>
</WarningAlert> </WarningAlert>
<v-file-input v-model="agreement" :rules="[rules.isPdf, rules.maxSize]" accept=".pdf,application/pdf" <v-file-input v-model="proof" :rules="[rules.isPdf, rules.maxSize]" accept=".pdf,application/pdf"
prepend-icon="mdi-handshake" label="Nahrať PDF zmluvu" variant="outlined" show-size clearable prepend-icon="mdi-handshake" label="Nahrať PDF dokument" variant="outlined" show-size clearable
hint="Povolené: PDF, max 10 MB" persistent-hint /> hint="Povolené: PDF, max 10 MB" persistent-hint />
</div> </div>
@@ -108,6 +111,12 @@ async function onSubmit() {
<div> <div>
<h4 class="mb-2">Výkaz</h4> <h4 class="mb-2">Výkaz</h4>
<p>Dokument o hodnotení praxe.</p>
<v-btn prepend-icon="mdi-download" color="blue" class="mr-2 mt-2 mb-2" target="_blank"
href="https://www.fpvai.ukf.sk/images/Organizacia_studia/odborna_prax/aplikovana_informatika/Priloha_Vykaz_o_vykonanej_odbornej_praxi-AI.docx">
<span>Stiahnuť šablónu na výkaz</span>
</v-btn>
<WarningAlert v-if="props.internship.report" title="Existujúci dokument" <WarningAlert v-if="props.internship.report" title="Existujúci dokument"
text="V systéme je už nahratý výkaz. Ak chcete nahradiť existujúcu verziu, vyberte súbor, alebo v opačnom prípade nechajte toto pole nevyplnené."> text="V systéme je už nahratý výkaz. Ak chcete nahradiť existujúcu verziu, vyberte súbor, alebo v opačnom prípade nechajte toto pole nevyplnené.">
@@ -123,14 +132,14 @@ async function onSubmit() {
hint="Povolené: PDF, max 10 MB" persistent-hint /> hint="Povolené: PDF, max 10 MB" persistent-hint />
<v-checkbox v-if="user?.role === Role.EMPLOYER" <v-checkbox v-if="user?.role === Role.EMPLOYER"
:disabled="!props.internship.agreement || !props.internship.report" v-model="report_confirmed" :disabled="!props.internship.proof || !props.internship.report" v-model="report_confirmed"
label="Výkaz je správny"></v-checkbox> label="Výkaz je správny"></v-checkbox>
</div> </div>
<br /> <br />
<v-btn type="submit" color="success" size="large" block <v-btn type="submit" color="success" size="large" block
:disabled="!agreement && !report && (!props.internship.agreement || !props.internship.report)"> :disabled="!proof && !report && (!props.internship.proof || !props.internship.report)">
Uloziť Uloziť
</v-btn> </v-btn>
</v-form> </v-form>

View File

@@ -8,8 +8,8 @@ const props = defineProps<{
const client = useSanctumClient(); const client = useSanctumClient();
async function downloadAgreement() { async function downloadAgreement() {
const agreement: Blob = await client(`/api/internships/${props.internship.id}/agreement`); const proof: Blob = await client(`/api/internships/${props.internship.id}/proof`);
triggerDownload(agreement, `agreement-${props.internship.id}`); triggerDownload(proof, `proof-${props.internship.id}`);
} }
async function downloadReport() { async function downloadReport() {
@@ -21,18 +21,19 @@ async function downloadReport() {
<template> <template>
<div> <div>
<v-row class="d-flex"> <v-row class="d-flex">
<!-- Podpísaná zmluva --> <!-- Podpísaný dokument k praxe -->
<v-col cols="12" md="6"> <v-col cols="12" md="6">
<v-card variant="outlined" class="h-100"> <v-card variant="outlined" class="h-100">
<v-card-title class="d-flex align-center ga-2"> <v-card-title class="d-flex align-center ga-2">
<v-icon icon="mdi mdi-file-document-outline" /> <v-icon icon="mdi mdi-file-document-outline" />
Podpísaná zmluva / dohoda Dokument o vykonaní praxe
</v-card-title> </v-card-title>
<v-card-text>
<InternshipAgreementDownloader :internship_id="internship.id" />
<WarningAlert v-if="!props.internship.agreement" title="Neodovzdané" <v-card-text>
text="Zmluva zatiaľ nebola nahratá." /> <InternshipAgreementDownloader :internship_id="internship.id" block />
<WarningAlert v-if="!props.internship.proof" title="Neodovzdané"
text="Dokument zatiaľ nebol nahratý." />
<div v-else> <div v-else>
<SuccessAlert title="Odovzdané" text="Zmluva bola nahratá." /> <SuccessAlert title="Odovzdané" text="Zmluva bola nahratá." />
@@ -53,8 +54,14 @@ async function downloadReport() {
<v-icon icon="mdi-file-clock-outline" /> <v-icon icon="mdi-file-clock-outline" />
Výkaz Výkaz
</v-card-title> </v-card-title>
<v-card-text> <v-card-text>
<InfoAlert v-if="!props.internship.report" title="Neodovzdané" <v-btn prepend-icon="mdi-download" color="blue" class="mr-2 mt-2" block target="_blank"
href="https://www.fpvai.ukf.sk/images/Organizacia_studia/odborna_prax/aplikovana_informatika/Priloha_Vykaz_o_vykonanej_odbornej_praxi-AI.docx">
<span>Stiahnuť šablónu na výkaz</span>
</v-btn>
<WarningAlert v-if="!props.internship.report" title="Neodovzdané"
text="Výkaz zatiaľ nebol nahratý." /> text="Výkaz zatiaľ nebol nahratý." />
<div v-else> <div v-else>

View File

@@ -68,10 +68,11 @@ async function submit() {
<ErrorAlert v-if="save_error" :error="`Nepodarilo uložiť: ${save_error}`" /> <ErrorAlert v-if="save_error" :error="`Nepodarilo uložiť: ${save_error}`" />
<!-- Chybová hláška --> <!-- Chybová hláška -->
<ErrorAlert v-if="load_error" :error="`Nepodarilo sa načítať stavy: ${save_error}`" /> <ErrorAlert v-if="load_error" :error="`Nepodarilo sa načítať stavy: ${load_error}`" />
<!-- Chybová hláška --> <!-- Chybová hláška -->
<ErrorAlert v-else-if="data?.length === 0" :error="`Nepodarilo sa načítať stavy: ${save_error}`" /> <WarningAlert v-else-if="data?.length === 0" title="Blokované"
text="Stav praxe už nie je možné meniť, pretože bola (ne)obhájená alebo zamietnutá. V prípade, že ste prax zamietli omylom, alebo ak máte technické problémy, prosíme kontaktovať garanta praxe." />
<v-form v-else v-model="isValid" @submit.prevent="submit" :disabled="loading"> <v-form v-else v-model="isValid" @submit.prevent="submit" :disabled="loading">
<v-select v-model="new_state" label="Stav" :items="data" item-value="value"></v-select> <v-select v-model="new_state" label="Stav" :items="data" item-value="value"></v-select>

View File

@@ -99,7 +99,8 @@ async function handleUpdateOfBasicInfo(internship: NewInternship) {
<div> <div>
<h2>Nahratie dokumentov</h2> <h2>Nahratie dokumentov</h2>
<ErrorAlert v-if="data?.status.status !== InternshipStatus.CONFIRMED" title="Blokované" <ErrorAlert v-if="data?.status.status !== InternshipStatus.CONFIRMED_BY_COMPANY"
title="Blokované"
error='Vaša prax nie je v stave "Schválená" a teda nemôžete nahrať dokumenty.' /> error='Vaša prax nie je v stave "Schválená" a teda nemôžete nahrať dokumenty.' />
<InternshipDocumentEditor v-else :internship="data!" @successful-submit="refresh" /> <InternshipDocumentEditor v-else :internship="data!" @successful-submit="refresh" />

View File

@@ -92,7 +92,8 @@ async function handleUpdateOfBasicInfo(internship: NewInternship) {
<div> <div>
<h2>Nahratie dokumentov</h2> <h2>Nahratie dokumentov</h2>
<ErrorAlert v-if="data?.status.status !== InternshipStatus.CONFIRMED" title="Blokované" <ErrorAlert v-if="data?.status.status !== InternshipStatus.CONFIRMED_BY_COMPANY"
title="Blokované"
error='Vaša prax nie je v stave "Schválená" a teda nemôžete nahrať dokumenty.' /> error='Vaša prax nie je v stave "Schválená" a teda nemôžete nahrať dokumenty.' />
<InternshipDocumentEditor v-else :internship="data!" @successful-submit="refresh" /> <InternshipDocumentEditor v-else :internship="data!" @successful-submit="refresh" />

View File

@@ -14,20 +14,29 @@ export interface NewInternshipStatusData {
export enum InternshipStatus { export enum InternshipStatus {
SUBMITTED = 'SUBMITTED', SUBMITTED = 'SUBMITTED',
CONFIRMED = 'CONFIRMED',
DENIED = 'DENIED', CONFIRMED_BY_COMPANY = 'CONFIRMED_BY_COMPANY',
CONFIRMED_BY_ADMIN = 'CONFIRMED_BY_ADMIN',
DENIED_BY_COMPANY = 'DENIED_BY_COMPANY',
DENIED_BY_ADMIN = 'DENIED_BY_ADMIN',
DEFENDED = 'DEFENDED', DEFENDED = 'DEFENDED',
NOT_DEFENDED = 'NOT_DEFENDED' NOT_DEFENDED = 'NOT_DEFENDED',
}; }
export function prettyInternshipStatus(status: InternshipStatus) { export function prettyInternshipStatus(status: InternshipStatus) {
switch (status) { switch (status) {
case InternshipStatus.SUBMITTED: case InternshipStatus.SUBMITTED:
return "Zadané"; return "Zadané";
case InternshipStatus.CONFIRMED: case InternshipStatus.CONFIRMED_BY_COMPANY:
return "Potvrdené"; return "Potvrdené firmou";
case InternshipStatus.DENIED: case InternshipStatus.CONFIRMED_BY_ADMIN:
return "Zamietnuté"; return "Potvrdené garantom";
case InternshipStatus.DENIED_BY_COMPANY:
return "Zamietnuté firmou";
case InternshipStatus.DENIED_BY_ADMIN:
return "Zamietnuté garantom";
case InternshipStatus.DEFENDED: case InternshipStatus.DEFENDED:
return "Obhájené"; return "Obhájené";
case InternshipStatus.NOT_DEFENDED: case InternshipStatus.NOT_DEFENDED:

View File

@@ -11,7 +11,7 @@ export interface Internship {
year_of_study: number; year_of_study: number;
semester: string; semester: string;
position_description: string; position_description: string;
agreement: boolean; proof: boolean;
report: boolean; report: boolean;
report_confirmed: boolean; report_confirmed: boolean;
status: InternshipStatusData; status: InternshipStatusData;

View File

@@ -14,7 +14,7 @@ describe('Admin Student Document Downloads', () => {
cy.url().should('include', '/dashboard/admin/internships') cy.url().should('include', '/dashboard/admin/internships')
}) })
it('should be able to generate and download the default agreement', () => { it('should be able to generate and download the default proof', () => {
cy.get('table').within(() => { cy.get('table').within(() => {
cy.get('tbody tr') cy.get('tbody tr')
.then(rows => { .then(rows => {