178 lines
7.2 KiB
PHP
178 lines
7.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Manage\Cooperations\Tables;
|
|
|
|
use App\Enums\ApprovalStatus;
|
|
use App\Filament\Actions\Cheerful\DeleteAction;
|
|
use App\Filament\Actions\Cheerful\EditAction;
|
|
use App\Filament\Actions\DefaultBulkActions;
|
|
use App\Filament\Columns\TimestampColumns;
|
|
use App\Filament\Resources\Manage\Cooperations\Actions\Cooperation\AcceptAction;
|
|
use App\Filament\Resources\Manage\Cooperations\Actions\Cooperation\CreateTaskAssignmentAction;
|
|
use App\Filament\Resources\Manage\Cooperations\Actions\Cooperation\RejectAction;
|
|
use App\Filament\Resources\Manage\Cooperations\Actions\Cooperation\SendProposalAction;
|
|
use App\Models\Cooperation;
|
|
use Carbon\CarbonInterface;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\ViewAction;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Filters\TrashedFilter;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
class CooperationsTable
|
|
{
|
|
public static function configure(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('title')
|
|
->label('Judul')
|
|
->searchable()
|
|
->sortable()
|
|
->wrap(),
|
|
|
|
TextColumn::make('partnerMedia.name')
|
|
->label('Media')
|
|
->listWithLineBreaks()
|
|
->limitList(3)
|
|
->expandableLimitedList()
|
|
->badge()
|
|
->visible(! auth()->user()->hasRole('Perusahaan')),
|
|
|
|
TextColumn::make('initial_submission_date')
|
|
->label('Tgl Pengajuan Awal')
|
|
->searchable()
|
|
->sortable()
|
|
->date('l, d F Y'),
|
|
|
|
TextColumn::make('final_submission_date')
|
|
->label('Tgl Pengajuan Akhir')
|
|
->searchable()
|
|
->sortable()
|
|
->date('l, d F Y')
|
|
->description(
|
|
fn (Cooperation $record): string => now()->greaterThan($record->final_submission_date->copy()->endOfDay())
|
|
? 'Waktu Pengajuan Habis'
|
|
: 'Sisa waktu pengajuan: '.now()->diffForHumans(
|
|
$record->final_submission_date->copy()->endOfDay(),
|
|
['syntax' => CarbonInterface::DIFF_ABSOLUTE]
|
|
)
|
|
),
|
|
|
|
TextColumn::make('assignment_deadline')
|
|
->label('Deadline Penugasan')
|
|
->searchable()
|
|
->sortable()
|
|
->date('l, d F Y')
|
|
->placeholder('Belum ditentukan')
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
|
|
TextColumn::make('verification_deadline')
|
|
->label('Deadline Verifikasi')
|
|
->searchable()
|
|
->sortable()
|
|
->date('l, d F Y')
|
|
->placeholder('Belum ditentukan')
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
|
|
TextColumn::make('status')
|
|
->searchable()
|
|
->sortable()
|
|
->badge(),
|
|
|
|
TextColumn::make('media_count')
|
|
->label('Tanggapan Media')
|
|
->html()
|
|
->getStateUsing(function (Cooperation $record): string {
|
|
$record->loadCount([
|
|
'partnerMedia as approved_count' => fn (Builder $query): Builder => $query->wherePivotAccepted(),
|
|
'partnerMedia as rejected_count' => fn (Builder $query): Builder => $query->wherePivotRejected(),
|
|
'partnerMedia as pending_count' => fn (Builder $query): Builder => $query->wherePivotPending(),
|
|
]);
|
|
|
|
$totalCount = $record->partnerMedia()->count();
|
|
|
|
return "Menerima: {$record->approved_count}<br>
|
|
Menolak: {$record->rejected_count}<br>
|
|
Belum Menanggapi: {$record->pending_count}<br>
|
|
Total: {$totalCount}";
|
|
})
|
|
->visible(! auth()->user()->hasRole('Perusahaan')),
|
|
|
|
TextColumn::make('status_tanggapan')
|
|
->label('Tanggapan')
|
|
->getStateUsing(function (Cooperation $record): ?ApprovalStatus {
|
|
if (auth()->user()->hasRole('Perusahaan')) {
|
|
$cooperationMedia = $record->cooperationMedia()
|
|
->whereHas('partnerMedia', function (Builder $query): void {
|
|
$query->whereHas('company', function (Builder $subQuery): void {
|
|
$subQuery->where('user_id', auth()->id());
|
|
});
|
|
})
|
|
->first();
|
|
|
|
return $cooperationMedia?->status;
|
|
}
|
|
|
|
return null;
|
|
})
|
|
->badge()
|
|
->visible(auth()->user()->hasRole('Perusahaan')),
|
|
|
|
TextColumn::make('payment_amount')
|
|
->label('Jumlah Pembayaran')
|
|
->money('IDR')
|
|
->sortable()
|
|
->placeholder('Belum ditentukan')
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
|
|
TextColumn::make('payment_date')
|
|
->label('Tanggal Pembayaran')
|
|
->date('l, d F Y')
|
|
->sortable()
|
|
->placeholder('Belum dibayar')
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
|
|
TextColumn::make('description')
|
|
->label('Deskripsi')
|
|
->searchable()
|
|
->limit(50)
|
|
->wrap()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
|
|
...TimestampColumns::make(),
|
|
])
|
|
->filters([
|
|
TrashedFilter::make()->native(false),
|
|
])
|
|
->recordActions([
|
|
ViewAction::make(),
|
|
|
|
AcceptAction::make('accept'),
|
|
|
|
RejectAction::make('reject'),
|
|
|
|
SendProposalAction::make('sendProposal'),
|
|
|
|
CreateTaskAssignmentAction::make('createTaskAssignment'),
|
|
|
|
EditAction::make()
|
|
->visible(fn (): bool => ! auth()->user()->hasRole('Perusahaan')),
|
|
|
|
DeleteAction::make()
|
|
->visible(fn (): bool => ! auth()->user()->hasRole('Perusahaan')),
|
|
])
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
...DefaultBulkActions::make('Kerja Sama'),
|
|
]),
|
|
])
|
|
->emptyStateIcon(Heroicon::HandRaised)
|
|
->emptyStateDescription('Setelah Anda membuat data pertama, maka akan muncul disini.')
|
|
->defaultSort('created_at', 'desc')
|
|
->deferFilters(false);
|
|
}
|
|
}
|