feat: Enhance cooperation proposal management with media handling and improved infolist display
- 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.
This commit is contained in:
parent
2d362b54dc
commit
2b49688f8f
@ -39,7 +39,6 @@ protected function afterCreate(): void
|
||||
}
|
||||
|
||||
$filePath = collect($data['proposal_template'])->first();
|
||||
dd($filePath);
|
||||
|
||||
$fullPath = Storage::disk(config('filesystems.default'))->path($filePath);
|
||||
|
||||
|
||||
@ -10,14 +10,16 @@
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Infolists\Infolist;
|
||||
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
|
||||
{
|
||||
@ -121,19 +123,54 @@ public function table(Table $table): Table
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->recordAction(null);
|
||||
]);
|
||||
}
|
||||
|
||||
// public function infolist(Infolist $infolist): Infolist
|
||||
// {
|
||||
// return $infolist
|
||||
// ->schema([
|
||||
// TextEntry::make('e_catalog')
|
||||
// ->label('File Proposal')
|
||||
// ->url(fn($record) => $record->e_catalog)
|
||||
// ->openUrlInNewTab()
|
||||
// ->columnSpanFull(),
|
||||
// ]);
|
||||
// }
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\TrashedFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class CooperationsTable
|
||||
{
|
||||
@ -265,13 +266,29 @@ public static function configure(Table $table): Table
|
||||
->first();
|
||||
|
||||
if ($cooperationMedia) {
|
||||
$record->proposals()->create([
|
||||
$proposal = $record->proposals()->create([
|
||||
'partner_media_id' => $cooperationMedia->partner_media_id,
|
||||
'description' => $data['description'],
|
||||
'e_catalog' => $data['e_catalog'],
|
||||
'status' => ApprovalStatus::PENDING->value,
|
||||
]);
|
||||
|
||||
if (! empty($data['proposal_attachment'])) {
|
||||
$filePath = collect($data['proposal_attachment'])->first();
|
||||
$fullPath = Storage::disk(config('filesystems.default'))->path($filePath);
|
||||
|
||||
if (file_exists($fullPath)) {
|
||||
$proposal->addMediaFromDisk($filePath, config('filesystems.default'))
|
||||
->preservingOriginal()
|
||||
->withCustomProperties([
|
||||
'feature' => 'cooperations',
|
||||
'date' => now()->toDateString(),
|
||||
'doc_type' => 'proposal-attachment',
|
||||
])
|
||||
->toMediaCollection('cooperations');
|
||||
}
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->title('Proposal kerja sama berhasil dikirim')
|
||||
->success()
|
||||
|
||||
@ -7,10 +7,12 @@
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
|
||||
class CooperationProposal extends Model
|
||||
class CooperationProposal extends Model implements HasMedia
|
||||
{
|
||||
use HasFactory;
|
||||
use HasFactory, InteractsWithMedia;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user