- Added comprehensive parameter and return type hinting to closures across various Filament resources, actions, and relation managers to improve type safety and static analysis. - Fixed logic in ReportRelationManager where report count was incorrectly compared, preventing the 'Buat Laporan' button from showing correctly. - Corrected namespaces for RepeatableEntry and TextEntry in ViewCooperation (changed from Filament\Schemas to Filament\Infolists). - Fixed component rendering in JournalistResource form by ensuring sections are correctly returned in the mapping. - Added @var docblocks to resolve lint errors related to auth()->user() and verified query builder return types. - Standardized file retrieval logic in PartnerResource and improved overall code reliability."
113 lines
5.0 KiB
PHP
113 lines
5.0 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 (): string => 'cooperations/proposal-attachment/'.now()->toDateString())
|
|
->required(),
|
|
])
|
|
->action(function (\App\Models\Cooperation $record, array $data): void {
|
|
$cooperationMedia = $record->cooperationMedia()
|
|
->whereHas('partnerMedia', function (\Illuminate\Database\Eloquent\Builder $query): void {
|
|
$query->whereHas('company', function (\Illuminate\Database\Eloquent\Builder $subQuery): void {
|
|
$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 (\App\Models\Cooperation $record): bool {
|
|
if (! auth()->user()->hasRole('Perusahaan')) {
|
|
return false;
|
|
}
|
|
|
|
$cooperationMedia = $record->cooperationMedia()
|
|
->whereHas('partnerMedia', function (\Illuminate\Database\Eloquent\Builder $query): void {
|
|
$query->whereHas('company', function (\Illuminate\Database\Eloquent\Builder $subQuery): void {
|
|
$subQuery->where('user_id', auth()->id());
|
|
});
|
|
})
|
|
->first();
|
|
|
|
return $cooperationMedia
|
|
&& $cooperationMedia->status === ApprovalStatus::ACCEPTED
|
|
&& $record->initial_submission_date->toDateString() === now()->toDateString()
|
|
&& ! $record->proposals()
|
|
->where('partner_media_id', $cooperationMedia->partner_media_id)
|
|
->where(fn (\Illuminate\Database\Eloquent\Builder $q): \Illuminate\Database\Eloquent\Builder => $q->accepted()->orWhere(fn (\Illuminate\Database\Eloquent\Builder $q): \Illuminate\Database\Eloquent\Builder => $q->pending()))
|
|
->exists();
|
|
})
|
|
->modalWidth(Width::Large);
|
|
}
|
|
}
|