442 lines
19 KiB
PHP
442 lines
19 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Manage\Partners;
|
|
|
|
use App\Enums\DecisionAdmin;
|
|
use App\Enums\MediaClassification;
|
|
use App\Enums\MediaType;
|
|
use App\Enums\RoleEnum;
|
|
use App\Enums\VerificationStatus;
|
|
use App\Filament\Actions\DefaultBulkActions;
|
|
use App\Filament\Resources\Manage\Partners\Pages\ManagePartners;
|
|
use App\Filament\Resources\Manage\Partners\Pages\ViewPartner;
|
|
use App\Models\User;
|
|
use BackedEnum;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\ViewAction;
|
|
use Filament\Infolists\Components\RepeatableEntry;
|
|
use Filament\Infolists\Components\TextEntry;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas\Components\Grid;
|
|
use Filament\Schemas\Components\Section;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Tables\Filters\TrashedFilter;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\HtmlString;
|
|
use Joaopaulolndev\FilamentPdfViewer\Infolists\Components\PdfViewerEntry;
|
|
use UnitEnum;
|
|
|
|
class PartnerResource extends Resource
|
|
{
|
|
protected static ?string $model = User::class;
|
|
|
|
protected static string|UnitEnum|null $navigationGroup = 'Kelola';
|
|
|
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::BuildingOffice2;
|
|
|
|
protected static ?string $navigationLabel = 'Rekanan';
|
|
|
|
protected static ?int $navigationSort = 1;
|
|
|
|
protected static ?string $recordTitleAttribute = 'name';
|
|
|
|
protected static ?string $slug = 'manage/partners';
|
|
|
|
public static function infolist(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->schema([
|
|
Section::make('Akun')
|
|
->schema([
|
|
Grid::make(3)
|
|
->schema([
|
|
TextEntry::make('name')
|
|
->label('Nama'),
|
|
|
|
TextEntry::make('email')
|
|
->label('Email'),
|
|
|
|
TextEntry::make('username')
|
|
->label('Nama Pengguna'),
|
|
|
|
TextEntry::make('is_active')
|
|
->label('Status')
|
|
->badge(),
|
|
|
|
TextEntry::make('email_verified_at')
|
|
->label('Email Verifikasi')
|
|
->placeholder('Akun Belum Diverifikasi')
|
|
->dateTime('l, d F Y H:i'),
|
|
]),
|
|
]),
|
|
|
|
Section::make('Perusahaan')
|
|
->schema([
|
|
Grid::make(3)
|
|
->schema([
|
|
TextEntry::make('company.name')
|
|
->label('Nama'),
|
|
|
|
TextEntry::make('company.email')
|
|
->label('Email'),
|
|
|
|
TextEntry::make('company.phone_number')
|
|
->label('Nomor Telepon'),
|
|
|
|
TextEntry::make('company.address')
|
|
->label('Alamat'),
|
|
|
|
TextEntry::make('company.director_name')
|
|
->label('Nama Direktur'),
|
|
|
|
TextEntry::make('company.verificationRequest.created_at')
|
|
->label('Tanggal Pengajuan Verifikasi')
|
|
->dateTime('d F Y H:i'),
|
|
|
|
TextEntry::make('company.verificationRequest.latestReview.decision')
|
|
->label('Status Verifikasi')
|
|
->badge(),
|
|
|
|
TextEntry::make('company.verificationRequest.latestReview.created_at')
|
|
->label('Tanggal Verifikasi')
|
|
->dateTime('d F Y H:i')
|
|
->visible(fn (User $record): ?string => $record->company?->verificationRequest?->latestReview),
|
|
|
|
TextEntry::make('company.verificationRequest.latestReview.note')
|
|
->label('Alasan Penolakan')
|
|
->visible(fn (User $record): ?string => $record->company?->verificationRequest?->latestReview?->decision === DecisionAdmin::REJECTED),
|
|
]),
|
|
|
|
Grid::make(3)
|
|
->schema([
|
|
Section::make('NIK Direktur')
|
|
->schema([
|
|
TextEntry::make('company.director_nik')
|
|
->hiddenLabel(),
|
|
|
|
TextEntry::make('company.director_nik_docs')
|
|
->hiddenLabel()
|
|
->html()
|
|
->getStateUsing(function (User $record): string {
|
|
$media = $record->company
|
|
?->getMedia('companies')
|
|
->where('custom_properties.doc_type', 'director-nik')
|
|
->sortByDesc('created_at')
|
|
->first();
|
|
|
|
if (! $media) {
|
|
return '';
|
|
}
|
|
|
|
$url = $media->getUrl();
|
|
$mime = $media->mime_type;
|
|
|
|
if (str_contains($mime, 'image')) {
|
|
return '<img src="'.$url.'" alt="Dokumen NIK Direktur" style="max-width: 100%; height: auto; border-radius: 0.5rem;" />';
|
|
}
|
|
|
|
if (str_contains($mime, 'pdf')) {
|
|
return '<iframe src="'.$url.'" style="width: 100%; height: 500px; border: none;"></iframe>';
|
|
}
|
|
|
|
return '<a href="'.$url.'" target="_blank" class="text-primary-600 hover:text-primary-500 underline">Unduh Dokumen</a>';
|
|
}),
|
|
]),
|
|
|
|
Section::make('Akta Pendirian')
|
|
->schema([
|
|
TextEntry::make('company.deed_incorporation')
|
|
->hiddenLabel(),
|
|
|
|
self::fileEntry('company.deed_incorporation'),
|
|
]),
|
|
|
|
Section::make('SIUP')
|
|
->schema([
|
|
TextEntry::make('company.trade_license')
|
|
->hiddenLabel(),
|
|
|
|
self::fileEntry('company.trade_license'),
|
|
]),
|
|
|
|
Section::make('NPWP')
|
|
->schema([
|
|
TextEntry::make('company.tax_id_number')
|
|
->hiddenLabel(),
|
|
|
|
self::fileEntry('company.tax_id_number'),
|
|
]),
|
|
|
|
Section::make('PKP')
|
|
->schema([
|
|
TextEntry::make('company.taxable_enterprise')
|
|
->hiddenLabel(),
|
|
|
|
self::fileEntry('company.taxable_enterprise'),
|
|
]),
|
|
|
|
Section::make('SPT Tahunan')
|
|
->schema([
|
|
TextEntry::make('company.annual_tax_return')
|
|
->hiddenLabel(),
|
|
|
|
self::fileEntry('company.annual_tax_return'),
|
|
]),
|
|
|
|
Section::make('SK Domisili')
|
|
->schema([
|
|
TextEntry::make('company.domicile_certificate')
|
|
->hiddenLabel(),
|
|
|
|
self::fileEntry('company.domicile_certificate'),
|
|
]),
|
|
|
|
Section::make('Profil Perusahaan')
|
|
->schema([
|
|
TextEntry::make('company.profile')
|
|
->hiddenLabel(),
|
|
|
|
self::fileEntry('company.profile'),
|
|
]),
|
|
]),
|
|
]),
|
|
|
|
Section::make('Media')
|
|
->schema([
|
|
Grid::make(4)
|
|
->schema([
|
|
TextEntry::make('company.partnerMedia.name')
|
|
->label('Nama'),
|
|
|
|
TextEntry::make('company.partnerMedia.link')
|
|
->label('Tautan')
|
|
->url(fn (User $record): ?string => $record->company?->partnerMedia?->link, true),
|
|
|
|
TextEntry::make('company.partnerMedia.type')
|
|
->label('Jenis')
|
|
->badge(),
|
|
|
|
TextEntry::make('company.partnerMedia.classification')
|
|
->label('Klasifikasi')
|
|
->badge(),
|
|
|
|
TextEntry::make('company.partnerMedia.address')
|
|
->label('Alamat')
|
|
->columnSpanFull(),
|
|
]),
|
|
|
|
Grid::make(2)
|
|
->schema([
|
|
Section::make('Sertifikat Organisasi Kewartawanan')
|
|
->schema([
|
|
TextEntry::make('company.partnerMedia.journalism_organization')
|
|
->hiddenLabel(),
|
|
|
|
self::fileEntry('company.partnerMedia.journalism_organization', 'company.partnerMedia', 'partnerMedia'),
|
|
]),
|
|
|
|
Section::make('Sertifikat Dewan Pers')
|
|
->schema([
|
|
TextEntry::make('company.partnerMedia.press_council_certificate')
|
|
->hiddenLabel(),
|
|
|
|
self::fileEntry('company.partnerMedia.press_council_certificate', 'company.partnerMedia', 'partnerMedia'),
|
|
]),
|
|
]),
|
|
]),
|
|
|
|
Section::make('Jurnalis')
|
|
->schema([
|
|
RepeatableEntry::make('company.partnerMedia.journalists')
|
|
->hiddenLabel()
|
|
->schema([
|
|
Grid::make(3)
|
|
->schema([
|
|
TextEntry::make('name')
|
|
->label('Nama'),
|
|
|
|
TextEntry::make('email')
|
|
->label('Email'),
|
|
|
|
TextEntry::make('phone_number')
|
|
->label('No. Telepon'),
|
|
]),
|
|
Grid::make(2)
|
|
->schema([
|
|
Section::make('Kartu Pers')
|
|
->schema([
|
|
TextEntry::make('press_card')
|
|
->hiddenLabel(),
|
|
|
|
self::fileEntry('press_card', null, 'journalists'),
|
|
]),
|
|
|
|
Section::make('Sertifikat UKW')
|
|
->schema([
|
|
TextEntry::make('ukw_certificate')
|
|
->hiddenLabel(),
|
|
|
|
self::fileEntry('ukw_certificate', null, 'journalists'),
|
|
]),
|
|
]),
|
|
]),
|
|
]),
|
|
])
|
|
->columns(1);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('company.name')
|
|
->label('Perusahaan')
|
|
->searchable(query: function ($query, $search) {
|
|
$query->whereHas('company', function ($q) use ($search) {
|
|
$q->where('companies.name', 'like', "%{$search}%")
|
|
->orWhere('companies.director_name', 'like', "%{$search}%");
|
|
});
|
|
})
|
|
->sortable()
|
|
->description(
|
|
fn (User $record) => new HtmlString(
|
|
'Akun: '.$record->name.
|
|
'<br/>Direktur: '.$record->company?->director_name
|
|
)
|
|
),
|
|
|
|
TextColumn::make('company.partnerMedia.name')
|
|
->label('Media')
|
|
->searchable(query: function ($query, $search) {
|
|
$query->whereHas('company.partnerMedia', function ($q) use ($search) {
|
|
$q->where('partner_media.name', 'like', "%{$search}%");
|
|
});
|
|
})
|
|
->sortable(),
|
|
|
|
TextColumn::make('company.journalists.name')
|
|
->label('Jurnalis')
|
|
->searchable(query: function ($query, $search) {
|
|
$query->whereHas('company.journalists', function ($q) use ($search) {
|
|
$q->where('journalists.name', 'like', "%{$search}%");
|
|
});
|
|
})
|
|
->sortable()
|
|
->badge(),
|
|
|
|
TextColumn::make('status')
|
|
->label('Status')
|
|
->badge()
|
|
->getStateUsing(function ($record) {
|
|
return $record->company->verificationRequest
|
|
? $record->company->verificationRequest->status->getLabel()
|
|
: 'Belum Mengajukan';
|
|
})
|
|
->color(function ($record) {
|
|
return $record->company->verificationRequest
|
|
? $record->company->verificationRequest->status->getColor()
|
|
: 'gray';
|
|
}),
|
|
|
|
TextColumn::make('created_at')
|
|
->label('Tgl Daftar')
|
|
->date()
|
|
->sortable()
|
|
->dateTime('l, d F Y H:i:s')
|
|
->wrap(),
|
|
])
|
|
->filters([
|
|
SelectFilter::make('media_type')
|
|
->label('Jenis Media')
|
|
->options(MediaType::class)
|
|
->query(fn (Builder $query, array $data) => $query->when(
|
|
$data['value'],
|
|
fn (Builder $query, $value) => $query->whereHas('company.partnerMedia', fn ($q) => $q->where('type', $value))
|
|
))
|
|
->native(false),
|
|
|
|
SelectFilter::make('media_classification')
|
|
->label('Klasifikasi Media')
|
|
->options(MediaClassification::class)
|
|
->query(fn (Builder $query, array $data) => $query->when(
|
|
$data['value'],
|
|
fn (Builder $query, $value) => $query->whereHas('company.partnerMedia', fn ($q) => $q->where('classification', $value))
|
|
))
|
|
->native(false),
|
|
|
|
SelectFilter::make('verification_status')
|
|
->label('Status Verifikasi')
|
|
->options(VerificationStatus::class)
|
|
->query(fn (Builder $query, array $data) => $query->when(
|
|
$data['value'],
|
|
fn (Builder $query, $value) => $query->whereHas('company.verificationRequest', fn ($q) => $q->where('status', $value))
|
|
))
|
|
->native(false),
|
|
|
|
TrashedFilter::make()
|
|
->native(false)
|
|
->visible(fn () => auth()->user()?->hasRole(RoleEnum::DEVELOPER->value)),
|
|
])
|
|
->recordActions([
|
|
ViewAction::make(),
|
|
])
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
...DefaultBulkActions::make('rekanan'),
|
|
]),
|
|
])
|
|
->emptyStateIcon(Heroicon::BuildingOffice2)
|
|
->emptyStateDescription('Setelah Anda membubat data pertama, maka akan muncul disini.')
|
|
->defaultSort('created_at', 'desc')
|
|
->deferFilters(false)
|
|
->paginated([25, 50, 100, 'all'])
|
|
->deferLoading();
|
|
}
|
|
|
|
public static function getEloquentQuery(): Builder
|
|
{
|
|
return parent::getEloquentQuery()
|
|
->role('Perusahaan')
|
|
->whereHas('company');
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ManagePartners::route('/'),
|
|
'view' => ViewPartner::route('/{record}'),
|
|
];
|
|
}
|
|
|
|
private static function fileEntry(
|
|
string $name,
|
|
?string $mediaOwner = 'company',
|
|
string $collection = 'companies'
|
|
): PdfViewerEntry {
|
|
return PdfViewerEntry::make($name)
|
|
->hiddenLabel()
|
|
->getStateUsing(function (Model $record) use ($name, $mediaOwner, $collection): ?string {
|
|
$owner = data_get($record, $mediaOwner);
|
|
|
|
if (! $owner) {
|
|
return null;
|
|
}
|
|
|
|
$docType = str($name)
|
|
->afterLast('.')
|
|
->slug('-');
|
|
|
|
return $owner->getMedia($collection)
|
|
->where('custom_properties.doc_type', (string) $docType)
|
|
->sortByDesc('created_at')
|
|
->first()
|
|
?->getUrl();
|
|
});
|
|
}
|
|
}
|