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();
|
$filePath = collect($data['proposal_template'])->first();
|
||||||
dd($filePath);
|
|
||||||
|
|
||||||
$fullPath = Storage::disk(config('filesystems.default'))->path($filePath);
|
$fullPath = Storage::disk(config('filesystems.default'))->path($filePath);
|
||||||
|
|
||||||
|
|||||||
@ -10,14 +10,16 @@
|
|||||||
use Filament\Actions\ViewAction;
|
use Filament\Actions\ViewAction;
|
||||||
use Filament\Forms\Components\Textarea;
|
use Filament\Forms\Components\Textarea;
|
||||||
use Filament\Infolists\Components\TextEntry;
|
use Filament\Infolists\Components\TextEntry;
|
||||||
use Filament\Infolists\Infolist;
|
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Resources\RelationManagers\RelationManager;
|
use Filament\Resources\RelationManagers\RelationManager;
|
||||||
|
use Filament\Schemas\Components\Grid;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
use Filament\Support\Enums\Width;
|
use Filament\Support\Enums\Width;
|
||||||
use Filament\Support\Icons\Heroicon;
|
use Filament\Support\Icons\Heroicon;
|
||||||
use Filament\Tables\Columns\TextColumn;
|
use Filament\Tables\Columns\TextColumn;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Joaopaulolndev\FilamentPdfViewer\Infolists\Components\PdfViewerEntry;
|
||||||
|
|
||||||
class CooperationProposalRelationManager extends RelationManager
|
class CooperationProposalRelationManager extends RelationManager
|
||||||
{
|
{
|
||||||
@ -121,19 +123,54 @@ public function table(Table $table): Table
|
|||||||
BulkActionGroup::make([
|
BulkActionGroup::make([
|
||||||
DeleteBulkAction::make(),
|
DeleteBulkAction::make(),
|
||||||
]),
|
]),
|
||||||
])
|
]);
|
||||||
->recordAction(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function infolist(Infolist $infolist): Infolist
|
public function infolist(Schema $infolist): Schema
|
||||||
// {
|
{
|
||||||
// return $infolist
|
return $infolist
|
||||||
// ->schema([
|
->components([
|
||||||
// TextEntry::make('e_catalog')
|
Grid::make(2)
|
||||||
// ->label('File Proposal')
|
->schema([
|
||||||
// ->url(fn($record) => $record->e_catalog)
|
TextEntry::make('partnerMedia.name')
|
||||||
// ->openUrlInNewTab()
|
->label('Media')
|
||||||
// ->columnSpanFull(),
|
->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\Columns\TextColumn;
|
||||||
use Filament\Tables\Filters\TrashedFilter;
|
use Filament\Tables\Filters\TrashedFilter;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
class CooperationsTable
|
class CooperationsTable
|
||||||
{
|
{
|
||||||
@ -265,13 +266,29 @@ public static function configure(Table $table): Table
|
|||||||
->first();
|
->first();
|
||||||
|
|
||||||
if ($cooperationMedia) {
|
if ($cooperationMedia) {
|
||||||
$record->proposals()->create([
|
$proposal = $record->proposals()->create([
|
||||||
'partner_media_id' => $cooperationMedia->partner_media_id,
|
'partner_media_id' => $cooperationMedia->partner_media_id,
|
||||||
'description' => $data['description'],
|
'description' => $data['description'],
|
||||||
'e_catalog' => $data['e_catalog'],
|
'e_catalog' => $data['e_catalog'],
|
||||||
'status' => ApprovalStatus::PENDING->value,
|
'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()
|
Notification::make()
|
||||||
->title('Proposal kerja sama berhasil dikirim')
|
->title('Proposal kerja sama berhasil dikirim')
|
||||||
->success()
|
->success()
|
||||||
|
|||||||
@ -7,10 +7,12 @@
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
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'];
|
protected $guarded = ['id'];
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user