- Refactor custom Filament actions into resource-specific subfolders (Cooperation, Proposal, Report).
- Standardize all action identifiers to snake_case for consistency.
- Move action identifiers directly into ::make('name') calls.
- Remove getDefaultName() from custom action classes to favor explicit naming.
- Update relation managers and resources to use the new namespaced action classes.
- Standardize closure syntax (fn) and string formatting across schemas and actions.
112 lines
4.5 KiB
PHP
112 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Manage\Cooperations\Actions\Cooperation;
|
|
|
|
use App\Enums\ApprovalStatus;
|
|
use Asmit\FilamentUpload\Forms\Components\AdvancedFileUpload;
|
|
use Filament\Actions\Action;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Support\Enums\Width;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class SendProposalAction extends Action
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->label('Ajukan Proposal')
|
|
->icon(Heroicon::DocumentText)
|
|
->color('info')
|
|
->schema([
|
|
TextInput::make('e_catalog')
|
|
->label('E-Catalog')
|
|
->placeholder('https://katalog.inaproc.id/purwakarta-kita-media-karya')
|
|
->autocomplete(false)
|
|
->autofocus()
|
|
->nullable()
|
|
->url(),
|
|
|
|
Textarea::make('description')
|
|
->label('Deskripsi')
|
|
->autocomplete(false)
|
|
->required()
|
|
->rows(4)
|
|
->placeholder('...'),
|
|
|
|
AdvancedFileUpload::make('proposal_attachment')
|
|
->label('Lampiran')
|
|
->disk(config('filesystems.default'))
|
|
->acceptedFileTypes(['application/pdf'])
|
|
->maxSize(1024 * 10)
|
|
->directory(fn () => 'cooperations/proposal-attachment/'.now()->toDateString())
|
|
->required(),
|
|
])
|
|
->action(function ($record, array $data) {
|
|
$cooperationMedia = $record->cooperationMedia()
|
|
->whereHas('partnerMedia', function ($query) {
|
|
$query->whereHas('company', function ($subQuery) {
|
|
$subQuery->where('user_id', auth()->id());
|
|
});
|
|
})
|
|
->first();
|
|
|
|
if ($cooperationMedia) {
|
|
$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()
|
|
->send();
|
|
}
|
|
})
|
|
->modalHeading('Proposal Kerja Sama')
|
|
->modalSubmitActionLabel('Kirim Proposal')
|
|
->visible(function ($record) {
|
|
if (! auth()->user()->hasRole('Perusahaan')) {
|
|
return false;
|
|
}
|
|
|
|
$cooperationMedia = $record->cooperationMedia()
|
|
->whereHas('partnerMedia', function ($query) {
|
|
$query->whereHas('company', function ($subQuery) {
|
|
$subQuery->where('user_id', auth()->id());
|
|
});
|
|
})
|
|
->first();
|
|
|
|
return $cooperationMedia
|
|
&& $cooperationMedia->status === ApprovalStatus::ACCEPTED
|
|
&& ! $record->proposals()
|
|
->where('partner_media_id', $cooperationMedia->partner_media_id)
|
|
->where(fn ($q) => $q->accepted()->orWhere(fn ($q) => $q->pending()))
|
|
->exists();
|
|
})
|
|
->modalWidth(Width::Large);
|
|
}
|
|
}
|