- Removed debug statement from CreateCooperation.php. - Updated CooperationProposalRelationManager to include a detailed infolist schema with media and status information. - Improved proposal creation logic in CooperationsTable to handle proposal attachments and store them in the media library. - Implemented media handling in CooperationProposal model for better integration with file uploads.
177 lines
6.7 KiB
PHP
177 lines
6.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Manage\Cooperations\RelationManagers;
|
|
|
|
use App\Enums\ApprovalStatus;
|
|
use App\Models\CooperationProposal;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Actions\ViewAction;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Infolists\Components\TextEntry;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
|
use Filament\Schemas\Components\Grid;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Support\Enums\Width;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Joaopaulolndev\FilamentPdfViewer\Infolists\Components\PdfViewerEntry;
|
|
|
|
class CooperationProposalRelationManager extends RelationManager
|
|
{
|
|
protected static string $relationship = 'proposals';
|
|
|
|
protected static ?string $title = 'Proposal';
|
|
|
|
public static function getBadge(Model $ownerRecord, string $pageClass): ?string
|
|
{
|
|
return $ownerRecord->proposals()->count();
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->recordTitleAttribute('description')
|
|
->columns([
|
|
TextColumn::make('partnerMedia.name')
|
|
->label('Media')
|
|
->searchable()
|
|
->visible(! auth()->user()->hasRole('Perusahaan')),
|
|
|
|
TextColumn::make('e_catalog')
|
|
->label('E-Catalog')
|
|
->url(fn ($record) => $record->e_catalog)
|
|
->openUrlInNewTab()
|
|
->color('primary'),
|
|
|
|
TextColumn::make('description')
|
|
->label('Deskripsi'),
|
|
|
|
TextColumn::make('status')
|
|
->label('Status')
|
|
->badge(),
|
|
|
|
TextColumn::make('submitted_at')
|
|
->label('Diajukan')
|
|
->dateTime('l, d F Y H:i:s')
|
|
->sortable(),
|
|
|
|
TextColumn::make('responded_at')
|
|
->label('Ditanggapi')
|
|
->dateTime('l, d F Y H:i:s')
|
|
->sortable(),
|
|
|
|
TextColumn::make('rejectionReasons.reason')
|
|
->label('Alasan Penolakan')
|
|
->searchable(),
|
|
])
|
|
->filters([])
|
|
->headerActions([])
|
|
->recordActions([
|
|
ViewAction::make(),
|
|
|
|
Action::make('accept')
|
|
->label('Terima')
|
|
->icon(Heroicon::OutlinedCheck)
|
|
->color('success')
|
|
->action(function (CooperationProposal $record) {
|
|
$record->update([
|
|
'status' => ApprovalStatus::ACCEPTED,
|
|
'responded_at' => now(),
|
|
]);
|
|
|
|
Notification::make()
|
|
->title('Proposal Diterima')
|
|
->body("Proposal dari {$record->partnerMedia->name} telah diterima.")
|
|
->success()
|
|
->send();
|
|
})
|
|
->visible(fn (CooperationProposal $record) => ! auth()->user()->hasRole('Perusahaan') && $record->status === ApprovalStatus::PENDING),
|
|
|
|
Action::make('reject')
|
|
->label('Tolak')
|
|
->icon(Heroicon::XMark)
|
|
->color('danger')
|
|
->schema([
|
|
Textarea::make('reason')
|
|
->label('Alasan Penolakan')
|
|
->placeholder('...')
|
|
->required(),
|
|
])
|
|
->action(function (CooperationProposal $record, array $data) {
|
|
$record->update([
|
|
'status' => ApprovalStatus::REJECTED,
|
|
'responded_at' => now(),
|
|
]);
|
|
|
|
$record->rejectionReasons()->create(['reason' => $data['reason']]);
|
|
|
|
Notification::make()
|
|
->title('Proposal Ditolak')
|
|
->body("Proposal dari {$record->partnerMedia->name} telah ditolak.")
|
|
->warning()
|
|
->send();
|
|
})
|
|
->visible(fn (CooperationProposal $record) => ! auth()->user()->hasRole('Perusahaan') && $record->status === ApprovalStatus::PENDING)
|
|
->modalWidth(Width::Large),
|
|
])
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public function infolist(Schema $infolist): Schema
|
|
{
|
|
return $infolist
|
|
->components([
|
|
Grid::make(2)
|
|
->schema([
|
|
TextEntry::make('partnerMedia.name')
|
|
->label('Media')
|
|
->visible(! auth()->user()->hasRole('Perusahaan')),
|
|
|
|
TextEntry::make('status')
|
|
->label('Status')
|
|
->badge(),
|
|
|
|
TextEntry::make('submitted_at')
|
|
->label('Diajukan')
|
|
->dateTime('l, d F Y H:i:s'),
|
|
|
|
TextEntry::make('responded_at')
|
|
->label('Ditanggapi')
|
|
->dateTime('l, d F Y H:i:s'),
|
|
]),
|
|
|
|
TextEntry::make('e_catalog')
|
|
->label('E-Catalog')
|
|
->url(fn ($record) => $record->e_catalog)
|
|
->openUrlInNewTab()
|
|
->color('primary')
|
|
->visible(fn ($record) => $record->e_catalog),
|
|
|
|
TextEntry::make('description')
|
|
->label('Deskripsi')
|
|
->columnSpanFull(),
|
|
|
|
PdfViewerEntry::make('proposal_attachment')
|
|
->label('Lampiran Proposal')
|
|
->getStateUsing(fn ($record) => optional($record->getMedia('cooperations')->where('custom_properties.doc_type', 'proposal-attachment')->sortByDesc('created_at')->first())->getPathRelativeToRoot())
|
|
->disk(config('filesystems.default')),
|
|
|
|
TextEntry::make('rejectionReasons.reason')
|
|
->label('Alasan Penolakan')
|
|
->listWithLineBreaks()
|
|
->visible(fn ($record) => $record->status === ApprovalStatus::REJECTED && $record->rejectionReasons->isNotEmpty())
|
|
->columnSpanFull(),
|
|
])
|
|
->columns(1);
|
|
}
|
|
}
|