193 lines
7.5 KiB
PHP
193 lines
7.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Manage\Cooperations\RelationManagers;
|
|
|
|
use App\Enums\CooperationStatus;
|
|
use App\Enums\RoleEnum;
|
|
use App\Filament\Actions\Cheerful\CreateAction;
|
|
use App\Filament\Actions\Cheerful\DeleteAction;
|
|
use App\Filament\Actions\Cheerful\EditAction;
|
|
use App\Filament\Columns\RowIndexColumn;
|
|
use App\Filament\Support\CheerfulNotification;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Forms\Components\DatePicker;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class TaskAssignmentRelationManager extends RelationManager
|
|
{
|
|
protected static string $relationship = 'taskAssignment';
|
|
|
|
protected static ?string $title = 'Media Order';
|
|
|
|
protected static bool $shouldSkipAuthorization = true;
|
|
|
|
public function isReadOnly(): bool
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public static function canViewForRecord(Model $ownerRecord, string $pageClass): bool
|
|
{
|
|
if (auth()->user()->hasRole(RoleEnum::PERUSAHAAN->value)) {
|
|
return $ownerRecord->cooperationMedia()
|
|
->whereHas('partnerMedia.company', function ($query) {
|
|
$query->where('user_id', auth()->id());
|
|
})
|
|
->accepted()
|
|
->exists();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
...RowIndexColumn::make(),
|
|
|
|
TextColumn::make('start_date')
|
|
->label('Tanggal Mulai')
|
|
->date('l, d F Y'),
|
|
|
|
TextColumn::make('end_date')
|
|
->label('Tanggal Selesai')
|
|
->date('l, d F Y'),
|
|
|
|
TextColumn::make('task_description')
|
|
->label('Deskripsi Tugas')
|
|
->wrap()
|
|
->html(),
|
|
|
|
TextColumn::make('report_amount')
|
|
->label('Jumlah Bukti Tayang'),
|
|
])
|
|
->headerActions([
|
|
CreateAction::make()
|
|
->label('Buat Media Order')
|
|
->modalWidth('md')
|
|
->schema([
|
|
DatePicker::make('start_date')
|
|
->label('Tanggal Mulai')
|
|
->native(false)
|
|
->displayFormat('l, d F Y')
|
|
->required(),
|
|
|
|
DatePicker::make('end_date')
|
|
->label('Tanggal Selesai')
|
|
->native(false)
|
|
->displayFormat('l, d F Y')
|
|
->required()
|
|
->afterOrEqual('start_date'),
|
|
|
|
TextInput::make('report_amount')
|
|
->label('Jumlah Bukti Tayang')
|
|
->numeric()
|
|
->minValue(1)
|
|
->required()
|
|
->autocomplete(false),
|
|
|
|
Textarea::make('task_description')
|
|
->label('Deskripsi Tugas')
|
|
->required()
|
|
->rows(4)
|
|
->placeholder('...')
|
|
->autocomplete(false),
|
|
])
|
|
->visible(function (): bool {
|
|
$user = auth()->user();
|
|
|
|
if (! $user->hasRole(RoleEnum::PERUSAHAAN->value)) {
|
|
return false;
|
|
}
|
|
|
|
$cooperation = $this->getOwnerRecord();
|
|
|
|
$isPartner = $cooperation->cooperationMedia()
|
|
->whereHas('partnerMedia.company', function ($query) use ($user) {
|
|
$query->where('user_id', $user->id);
|
|
})
|
|
->accepted()
|
|
->exists();
|
|
|
|
$hasAcceptedProposal = $cooperation->proposal()->accepted()->exists();
|
|
|
|
return $isPartner && $hasAcceptedProposal && $cooperation->status === CooperationStatus::ASSIGNMENT;
|
|
})
|
|
->successNotification(
|
|
fn () => CheerfulNotification::success(
|
|
CheerfulNotification::getByKey('cooperation.assignment_success'),
|
|
CheerfulNotification::getByKey('cooperation.assignment_set_success')
|
|
)
|
|
),
|
|
])
|
|
->recordActions([
|
|
EditAction::make()
|
|
->modalWidth('md')
|
|
->schema([
|
|
DatePicker::make('start_date')
|
|
->label('Tanggal Mulai')
|
|
->native(false)
|
|
->displayFormat('l, d F Y')
|
|
->required(),
|
|
|
|
DatePicker::make('end_date')
|
|
->label('Tanggal Selesai')
|
|
->native(false)
|
|
->displayFormat('l, d F Y')
|
|
->required()
|
|
->afterOrEqual('start_date'),
|
|
|
|
TextInput::make('report_amount')
|
|
->label('Jumlah Bukti Tayang')
|
|
->numeric()
|
|
->minValue(1)
|
|
->required()
|
|
->autocomplete(false),
|
|
|
|
Textarea::make('task_description')
|
|
->label('Deskripsi Tugas')
|
|
->required()
|
|
->rows(4)
|
|
->placeholder('...')
|
|
->autocomplete(false),
|
|
])
|
|
->successNotification(
|
|
fn () => CheerfulNotification::success(
|
|
CheerfulNotification::getByKey('cooperation.assignment_updated'),
|
|
CheerfulNotification::getByKey('cooperation.assignment_updated_desc')
|
|
)
|
|
),
|
|
|
|
DeleteAction::make()
|
|
->successNotification(
|
|
fn () => CheerfulNotification::success(
|
|
CheerfulNotification::getByKey('cooperation.assignment_deleted'),
|
|
CheerfulNotification::getByKey('cooperation.assignment_deleted_desc')
|
|
)
|
|
),
|
|
])
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make()
|
|
->successNotification(
|
|
fn () => CheerfulNotification::success(
|
|
CheerfulNotification::getByKey('cooperation.assignment_deleted_success'),
|
|
CheerfulNotification::getByKey('cooperation.bulk_assignment_deleted')
|
|
)
|
|
),
|
|
]),
|
|
])
|
|
->emptyStateIcon(Heroicon::OutlinedArchiveBoxXMark)
|
|
->emptyStateHeading(fn () => CheerfulNotification::getByKey('cooperation.assignment_empty_heading'))
|
|
->emptyStateDescription(fn () => CheerfulNotification::getByKey('cooperation.assignment_empty'));
|
|
}
|
|
}
|