148 lines
5.8 KiB
PHP
148 lines
5.8 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Admin\Resources\CareerApplications\Schemas;
|
||
|
||
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;
|
||
use Filament\Actions\Action;
|
||
use Filament\Schemas\Components\Utilities\Set;
|
||
use Illuminate\Support\Str;
|
||
|
||
class CareerApplicationForm
|
||
{
|
||
public static function configure(Schema $schema): Schema
|
||
{
|
||
return $schema
|
||
->components([
|
||
TextInput::make('name')
|
||
->label(__('career.name'))
|
||
->required()
|
||
->disabled(),
|
||
|
||
TextInput::make('email')
|
||
->label(__('career.email'))
|
||
->email()
|
||
->required()
|
||
->disabled(),
|
||
|
||
TextInput::make('phone')
|
||
->label(__('career.phone'))
|
||
->disabled(),
|
||
|
||
FileUpload::make('cv_path')
|
||
->label(__('career.cv'))
|
||
->disk('public')
|
||
->directory('cvs')
|
||
->required()
|
||
->disabled()
|
||
->downloadable(),
|
||
|
||
Textarea::make('message')
|
||
->label(__('career.message'))
|
||
->disabled()
|
||
->columnSpanFull(),
|
||
|
||
Select::make('status')
|
||
->label(__('career.status'))
|
||
->options([
|
||
'pending' => __('career.pending'),
|
||
'reviewed' => __('career.reviewed'),
|
||
'rejected' => __('career.rejected'),
|
||
'accepted' => __('career.accepted'),
|
||
'waiting_document' => __('career.waiting_document'),
|
||
])
|
||
->required(),
|
||
|
||
Section::make('Stajyer Giriş Bilgileri & Belgeleri')
|
||
->description('Stajyerin sisteme giriş yapabilmesi için kullanıcı adı, şifre belirleyin ve imzalı staj formunu yükleyin.')
|
||
->collapsible()
|
||
->schema([
|
||
TextInput::make('username')
|
||
->label('Kullanıcı Adı')
|
||
->unique(ignoreRecord: true)
|
||
->nullable(),
|
||
|
||
TextInput::make('password')
|
||
->label('Şifre')
|
||
->password()
|
||
->revealable()
|
||
->dehydrateStateUsing(fn ($state) => filled($state) ? Hash::make($state) : null)
|
||
->dehydrated(fn ($state) => filled($state))
|
||
->placeholder('Şifreyi değiştirmek istemiyorsanız boş bırakın')
|
||
->nullable()
|
||
->suffixAction(
|
||
Action::make('generatePassword')
|
||
->icon('heroicon-m-arrow-path')
|
||
->action(fn (Set $set) => $set('password', Str::random(12)))
|
||
),
|
||
|
||
FileUpload::make('to_be_signed_internship_form_path')
|
||
->label('İmzalanacak Staj Formu (Stajyerden)')
|
||
->disk('public')
|
||
->directory('to_be_signed_interns')
|
||
->downloadable()
|
||
->nullable(),
|
||
|
||
FileUpload::make('signed_internship_form_path')
|
||
->label('İmzalı Staj Formu')
|
||
->disk('public')
|
||
->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);
|
||
}
|
||
}
|