From aa48ce7890fe9e19b56ecf0653c8bf75aef8c7a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cmit=20Tun=C3=A7?= Date: Mon, 1 Jun 2026 08:02:36 +0300 Subject: [PATCH] feat: add internship date fields and business day calculation to career applications --- .../Schemas/CareerApplicationForm.php | 46 +++++++++++++++++++ app/Http/Controllers/CareerController.php | 27 ++++++++++- app/Models/CareerApplication.php | 3 ++ ...hip_dates_to_career_applications_table.php | 30 ++++++++++++ .../front/career/intern_dashboard.blade.php | 21 +++++++++ 5 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2026_06_01_045933_add_internship_dates_to_career_applications_table.php diff --git a/app/Filament/Admin/Resources/CareerApplications/Schemas/CareerApplicationForm.php b/app/Filament/Admin/Resources/CareerApplications/Schemas/CareerApplicationForm.php index bc8be02..81bdc1c 100644 --- a/app/Filament/Admin/Resources/CareerApplications/Schemas/CareerApplicationForm.php +++ b/app/Filament/Admin/Resources/CareerApplications/Schemas/CareerApplicationForm.php @@ -6,6 +6,7 @@ use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\Select; use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; +use Filament\Forms\Components\DatePicker; use Filament\Schemas\Components\Section; use Filament\Schemas\Schema; use Illuminate\Support\Facades\Hash; @@ -94,8 +95,53 @@ class CareerApplicationForm ->directory('signed_interns') ->downloadable() ->nullable(), + + DatePicker::make('internship_start_date') + ->label('Staj Başlangıç Tarihi') + ->live() + ->afterStateUpdated(fn ($state, $get, Set $set) => self::calculateTotalDays($state, $get('internship_end_date'), $set)) + ->nullable(), + + DatePicker::make('internship_end_date') + ->label('Staj Bitiş Tarihi') + ->live() + ->afterStateUpdated(fn ($state, $get, Set $set) => self::calculateTotalDays($get('internship_start_date'), $state, $set)) + ->nullable(), + + TextInput::make('internship_total_days') + ->label('Toplam Staj Süresi (İş Günü)') + ->numeric() + ->disabled() + ->dehydrated() + ->nullable(), ]) ->columnSpanFull(), ]); } + + public static function calculateTotalDays($start, $end, Set $set): void + { + if (!$start || !$end) { + $set('internship_total_days', null); + return; + } + + $startDate = \Carbon\Carbon::parse($start); + $endDate = \Carbon\Carbon::parse($end); + + if ($startDate->gt($endDate)) { + $set('internship_total_days', 0); + return; + } + + $days = 0; + while ($startDate->lte($endDate)) { + if (!$startDate->isWeekend()) { + $days++; + } + $startDate->addDay(); + } + + $set('internship_total_days', $days); + } } diff --git a/app/Http/Controllers/CareerController.php b/app/Http/Controllers/CareerController.php index 69cd9fd..e6dd819 100644 --- a/app/Http/Controllers/CareerController.php +++ b/app/Http/Controllers/CareerController.php @@ -136,11 +136,18 @@ class CareerController extends Controller $request->validate([ 'internship_form' => 'required|file|mimes:pdf,docx,jpg,png,jpeg|max:51200', + 'internship_start_date' => 'required|date', + 'internship_end_date' => 'required|date|after_or_equal:internship_start_date', ], [ 'internship_form.required' => 'Lütfen bir dosya seçin.', 'internship_form.file' => 'Yüklenen öğe geçerli bir dosya olmalıdır.', 'internship_form.mimes' => 'Yalnızca PDF, DOCX, JPG ve PNG formatındaki dosyalar kabul edilir.', 'internship_form.max' => 'Dosya boyutu en fazla 50MB olabilir.', + 'internship_start_date.required' => 'Lütfen staj başlangıç tarihini girin.', + 'internship_start_date.date' => 'Geçerli bir başlangıç tarihi girin.', + 'internship_end_date.required' => 'Lütfen staj bitiş tarihini girin.', + 'internship_end_date.date' => 'Geçerli bir bitiş tarihi girin.', + 'internship_end_date.after_or_equal' => 'Bitiş tarihi, başlangıç tarihinden önce olamaz.', ]); $intern = CareerApplication::findOrFail(session('intern_id')); @@ -152,11 +159,27 @@ class CareerController extends Controller } $path = $request->file('internship_form')->store('to_be_signed_interns', 'public'); + + // Calculate business days (excluding weekends) + $startDate = \Carbon\Carbon::parse($request->internship_start_date); + $endDate = \Carbon\Carbon::parse($request->internship_end_date); + $days = 0; + $tempDate = $startDate->copy(); + while ($tempDate->lte($endDate)) { + if (!$tempDate->isWeekend()) { + $days++; + } + $tempDate->addDay(); + } + $intern->update([ - 'to_be_signed_internship_form_path' => $path + 'to_be_signed_internship_form_path' => $path, + 'internship_start_date' => $request->internship_start_date, + 'internship_end_date' => $request->internship_end_date, + 'internship_total_days' => $days, ]); - return redirect()->back()->with('success', 'İmzalanacak staj formunuz başarıyla yüklendi.'); + return redirect()->back()->with('success', 'İmzalanacak staj formunuz ve staj tarihleri başarıyla kaydedildi.'); } return redirect()->back()->with('error', 'Dosya yüklenirken bir hata oluştu.'); diff --git a/app/Models/CareerApplication.php b/app/Models/CareerApplication.php index b8630c6..89c06a0 100644 --- a/app/Models/CareerApplication.php +++ b/app/Models/CareerApplication.php @@ -25,6 +25,9 @@ class CareerApplication extends Model 'password', 'signed_internship_form_path', 'to_be_signed_internship_form_path', + 'internship_start_date', + 'internship_end_date', + 'internship_total_days', ]; /** diff --git a/database/migrations/2026_06_01_045933_add_internship_dates_to_career_applications_table.php b/database/migrations/2026_06_01_045933_add_internship_dates_to_career_applications_table.php new file mode 100644 index 0000000..6cf7653 --- /dev/null +++ b/database/migrations/2026_06_01_045933_add_internship_dates_to_career_applications_table.php @@ -0,0 +1,30 @@ +date('internship_start_date')->nullable()->after('to_be_signed_internship_form_path'); + $table->date('internship_end_date')->nullable()->after('internship_start_date'); + $table->integer('internship_total_days')->nullable()->after('internship_end_date'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('career_applications', function (Blueprint $table) { + $table->dropColumn(['internship_start_date', 'internship_end_date', 'internship_total_days']); + }); + } +}; diff --git a/resources/views/front/career/intern_dashboard.blade.php b/resources/views/front/career/intern_dashboard.blade.php index 4f92f96..7078ef3 100644 --- a/resources/views/front/career/intern_dashboard.blade.php +++ b/resources/views/front/career/intern_dashboard.blade.php @@ -86,6 +86,27 @@ @else Beklemede @endif + + @if($intern->internship_start_date) +
+ Staj Başlangıç Tarihi + {{ \Carbon\Carbon::parse($intern->internship_start_date)->format('d.m.Y') }} +
+ @endif + + @if($intern->internship_end_date) +
+ Staj Bitiş Tarihi + {{ \Carbon\Carbon::parse($intern->internship_end_date)->format('d.m.Y') }} +
+ @endif + + @if($intern->internship_total_days) +
+ Toplam Süre + {{ $intern->internship_total_days }} İş Günü (Haftada 5 Gün) +
+ @endif