342 lines
15 KiB
PHP
342 lines
15 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Manage\Partners\Infolists;
|
|
|
|
use App\Enums\DecisionAdmin;
|
|
use App\Filament\Support\CheerfulNotification;
|
|
use App\Models\User;
|
|
use Filament\Infolists\Components\RepeatableEntry;
|
|
use Filament\Infolists\Components\TextEntry;
|
|
use Filament\Schemas\Components\Grid;
|
|
use Filament\Schemas\Components\Section;
|
|
use Filament\Schemas\Schema;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Joaopaulolndev\FilamentPdfViewer\Infolists\Components\PdfViewerEntry;
|
|
|
|
class PartnerInfolist
|
|
{
|
|
public static function configure(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->schema([
|
|
Section::make(fn () => CheerfulNotification::getByKey('company.account_title'))
|
|
->description(fn () => CheerfulNotification::getByKey('company.account_desc'))
|
|
->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(fn () => CheerfulNotification::getByKey('company.company_title'))
|
|
->description(fn () => CheerfulNotification::getByKey('company.company_desc'))
|
|
->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.phone_number')
|
|
->label('No. Telepon'),
|
|
|
|
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(),
|
|
|
|
...self::fileEntries('company.director_nik'),
|
|
]),
|
|
|
|
Section::make('Akta Pendirian')
|
|
->schema([
|
|
TextEntry::make('company.deed_incorporation')
|
|
->hiddenLabel(),
|
|
|
|
...self::fileEntries('company.tax_id_number'),
|
|
]),
|
|
|
|
Section::make('SIUP / NIB')
|
|
->schema([
|
|
TextEntry::make('company.trade_license')
|
|
->hiddenLabel(),
|
|
|
|
...self::fileEntries('company.trade_license'),
|
|
]),
|
|
|
|
Section::make('NPWP')
|
|
->schema([
|
|
TextEntry::make('company.tax_id_number')
|
|
->hiddenLabel(),
|
|
|
|
...self::fileEntries('company.tax_id_number'),
|
|
]),
|
|
|
|
Section::make('PKP')
|
|
->schema([
|
|
TextEntry::make('company.taxable_enterprise')
|
|
->hiddenLabel(),
|
|
|
|
...self::fileEntries('company.taxable_enterprise'),
|
|
]),
|
|
|
|
Section::make('SPT Tahunan')
|
|
->schema([
|
|
TextEntry::make('company.annual_tax_return')
|
|
->hiddenLabel(),
|
|
|
|
...self::fileEntries('company.annual_tax_return'),
|
|
]),
|
|
|
|
Section::make('Suket Domisili')
|
|
->schema([
|
|
TextEntry::make('company.domicile_certificate')
|
|
->hiddenLabel(),
|
|
|
|
...self::fileEntries('company.domicile_certificate'),
|
|
]),
|
|
|
|
Section::make('Profil Perusahaan')
|
|
->schema([
|
|
TextEntry::make('company.profile')
|
|
->hiddenLabel(),
|
|
|
|
...self::fileEntries('company.profile'),
|
|
]),
|
|
]),
|
|
]),
|
|
|
|
Section::make(fn () => CheerfulNotification::getByKey('company.media_title'))
|
|
->description(fn () => CheerfulNotification::getByKey('company.media_desc'))
|
|
->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('Organisasi Kewartawanan')
|
|
->schema([
|
|
TextEntry::make('company.partnerMedia.journalism_organization')
|
|
->hiddenLabel(),
|
|
|
|
...self::fileEntries('company.partnerMedia.journalism_organization', 'company.partnerMedia', 'partnerMedia'),
|
|
]),
|
|
|
|
Section::make('Sertifikat Dewan Pers')
|
|
->schema([
|
|
TextEntry::make('company.partnerMedia.press_council_certificate')
|
|
->hiddenLabel(),
|
|
|
|
...self::fileEntries('company.partnerMedia.press_council_certificate', 'company.partnerMedia', 'partnerMedia'),
|
|
]),
|
|
]),
|
|
]),
|
|
|
|
Section::make(fn () => CheerfulNotification::getByKey('company.journalist_title'))
|
|
->description(fn () => CheerfulNotification::getByKey('company.journalist_desc'))
|
|
->schema([
|
|
RepeatableEntry::make('company.partnerMedia.journalists')
|
|
->hiddenLabel()
|
|
->schema([
|
|
Grid::make(3)
|
|
->schema([
|
|
TextEntry::make('name')
|
|
->label('Nama Lengkap'),
|
|
|
|
TextEntry::make('email')
|
|
->label('Alamat Surel'),
|
|
|
|
TextEntry::make('phone_number')
|
|
->label('Nomor Telepon'),
|
|
]),
|
|
Grid::make(2)
|
|
->schema([
|
|
Section::make('Dokumen Pers')
|
|
->schema([
|
|
TextEntry::make('press_card')
|
|
->hiddenLabel(),
|
|
|
|
...self::fileEntries('press_card', null, 'journalists'),
|
|
]),
|
|
|
|
Section::make('Sertifikat UKW')
|
|
->schema([
|
|
TextEntry::make('ukw_certificate')
|
|
->hiddenLabel(),
|
|
|
|
...self::fileEntries('ukw_certificate', null, 'journalists'),
|
|
]),
|
|
]),
|
|
]),
|
|
]),
|
|
])
|
|
->columns(1);
|
|
}
|
|
|
|
private static function fileEntries(
|
|
string $name,
|
|
?string $mediaOwner = 'company',
|
|
string $collection = 'companies'
|
|
): array {
|
|
return [
|
|
PdfViewerEntry::make($name.'_pdf')
|
|
->hiddenLabel()
|
|
->visible(
|
|
fn (Model $record) => self::isPdf($record, $name, $mediaOwner, $collection)
|
|
)
|
|
->getStateUsing(
|
|
fn (Model $record) => self::getFileUrl($record, $name, $mediaOwner, $collection)
|
|
),
|
|
|
|
TextEntry::make($name.'_image')
|
|
->hiddenLabel()
|
|
->html()
|
|
->visible(
|
|
fn (Model $record) => self::isImage($record, $name, $mediaOwner, $collection)
|
|
)
|
|
->getStateUsing(function (Model $record) use ($name, $mediaOwner, $collection) {
|
|
$media = self::getMedia($record, $name, $mediaOwner, $collection);
|
|
$url = $media?->getUrl();
|
|
|
|
if (! $url) {
|
|
return '';
|
|
}
|
|
|
|
$downloadUrl = $url;
|
|
|
|
if ($media && in_array($media->disk, ['s3', 'minio'])) {
|
|
$downloadUrl = $media->getTemporaryUrl(now()->addMinutes(30), '', [
|
|
'ResponseContentDisposition' => 'attachment; filename="'.$media->file_name.'"',
|
|
]);
|
|
}
|
|
|
|
$downloadLink = '<a href="'.$downloadUrl.'" download="dokumen" class="mt-2 flex items-center gap-1 text-sm font-medium text-primary-600 transition hover:text-primary-500">
|
|
<svg class="h-4 w-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
|
<path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5M16.5 12L12 16.5m0 0L7.5 12m4.5 4.5V3" />
|
|
</svg>
|
|
Unduh Dokumen
|
|
</a>';
|
|
|
|
return '<div class="flex flex-col">'.
|
|
'<img src="'.$url.'" alt="Dokumen" style="max-width: 100%; height: auto; border-radius: 0.5rem;" />'.
|
|
$downloadLink.
|
|
'</div>';
|
|
}),
|
|
];
|
|
}
|
|
|
|
private static function getMedia(
|
|
Model $record,
|
|
string $name,
|
|
?string $mediaOwner,
|
|
string $collection
|
|
) {
|
|
$owner = $mediaOwner ? data_get($record, $mediaOwner) : $record;
|
|
|
|
if (! $owner) {
|
|
return null;
|
|
}
|
|
|
|
$docType = str($name)->afterLast('.')->slug('-');
|
|
|
|
return $owner->getMedia($collection)
|
|
->where('custom_properties.doc_type', (string) $docType)
|
|
->sortByDesc('created_at')
|
|
->first();
|
|
}
|
|
|
|
private static function getFileUrl(
|
|
Model $record,
|
|
string $name,
|
|
?string $mediaOwner,
|
|
string $collection
|
|
): ?string {
|
|
return self::getMedia($record, $name, $mediaOwner, $collection)?->getUrl();
|
|
}
|
|
|
|
private static function getMime(
|
|
Model $record,
|
|
string $name,
|
|
?string $mediaOwner,
|
|
string $collection
|
|
): ?string {
|
|
return self::getMedia($record, $name, $mediaOwner, $collection)?->mime_type;
|
|
}
|
|
|
|
private static function isPdf(...$args): bool
|
|
{
|
|
return str_contains(self::getMime(...$args) ?? '', 'pdf');
|
|
}
|
|
|
|
private static function isImage(...$args): bool
|
|
{
|
|
return str_contains(self::getMime(...$args) ?? '', 'image');
|
|
}
|
|
}
|