refactor: streamline Cooperation resource by consolidating partner media queries and enhancing infolist structure for improved maintainability
This commit is contained in:
parent
e5cbbe7e96
commit
ae46b93b32
@ -24,10 +24,8 @@ protected function setUp(): void
|
||||
->color('success')
|
||||
->action(function (Cooperation $record): void {
|
||||
$cooperationMedia = $record->cooperationMedia()
|
||||
->whereHas('partnerMedia', function (Builder $query): void {
|
||||
$query->whereHas('company', function (Builder $subQuery): void {
|
||||
$subQuery->where('user_id', auth()->id());
|
||||
});
|
||||
->whereHas('partnerMedia.company', function (Builder $query): void {
|
||||
$query->where('user_id', auth()->id());
|
||||
})
|
||||
->first();
|
||||
|
||||
@ -40,7 +38,8 @@ protected function setUp(): void
|
||||
)->send();
|
||||
|
||||
// Notify Admins
|
||||
User::superAdmin()
|
||||
User::query()
|
||||
->superAdmin()
|
||||
->get()
|
||||
->each(function ($admin) use ($record, $cooperationMedia): void {
|
||||
$admin->notify(new BroadcastNotification([
|
||||
@ -63,10 +62,8 @@ protected function setUp(): void
|
||||
}
|
||||
|
||||
$cooperationMedia = $record->cooperationMedia()
|
||||
->whereHas('partnerMedia', function (Builder $query): void {
|
||||
$query->whereHas('company', function (Builder $subQuery): void {
|
||||
$subQuery->where('user_id', auth()->id());
|
||||
});
|
||||
->whereHas('partnerMedia.company', function (Builder $query): void {
|
||||
$query->where('user_id', auth()->id());
|
||||
})
|
||||
->first();
|
||||
|
||||
|
||||
@ -22,10 +22,8 @@ protected function setUp(): void
|
||||
->color('danger')
|
||||
->action(function (Cooperation $record): void {
|
||||
$cooperationMedia = $record->cooperationMedia()
|
||||
->whereHas('partnerMedia', function ($query) {
|
||||
$query->whereHas('company', function ($subQuery) {
|
||||
$subQuery->where('user_id', auth()->id());
|
||||
});
|
||||
->whereHas('partnerMedia.company', function ($query) {
|
||||
$query->where('user_id', auth()->id());
|
||||
})
|
||||
->first();
|
||||
|
||||
@ -38,7 +36,8 @@ protected function setUp(): void
|
||||
)->send();
|
||||
|
||||
// Notify Admins
|
||||
User::superAdmin()
|
||||
User::query()
|
||||
->superAdmin()
|
||||
->get()
|
||||
->each(function ($admin) use ($record, $cooperationMedia): void {
|
||||
$admin->notify(new BroadcastNotification([
|
||||
@ -56,10 +55,8 @@ protected function setUp(): void
|
||||
}
|
||||
|
||||
$cooperationMedia = $record->cooperationMedia()
|
||||
->whereHas('partnerMedia', function ($query) {
|
||||
$query->whereHas('company', function ($subQuery) {
|
||||
$subQuery->where('user_id', auth()->id());
|
||||
});
|
||||
->whereHas('partnerMedia.company', function ($query) {
|
||||
$query->where('user_id', auth()->id());
|
||||
})
|
||||
->first();
|
||||
|
||||
|
||||
@ -56,10 +56,8 @@ protected function setUp(): void
|
||||
])
|
||||
->action(function (Cooperation $record, array $data): void {
|
||||
$cooperationMedia = $record->cooperationMedia()
|
||||
->whereHas('partnerMedia', function (Builder $query): void {
|
||||
$query->whereHas('company', function (Builder $subQuery): void {
|
||||
$subQuery->where('user_id', auth()->id());
|
||||
});
|
||||
->whereHas('partnerMedia.company', function (Builder $query): void {
|
||||
$query->where('user_id', auth()->id());
|
||||
})
|
||||
->first();
|
||||
|
||||
@ -99,7 +97,8 @@ protected function setUp(): void
|
||||
)->send();
|
||||
|
||||
// Notify Admin
|
||||
User::superAdmin()
|
||||
User::query()
|
||||
->superAdmin()
|
||||
->get()
|
||||
->each(function ($admin) use ($isRevision, $record, $cooperationMedia): void {
|
||||
$user = auth()->user();
|
||||
@ -131,10 +130,8 @@ protected function setUp(): void
|
||||
}
|
||||
|
||||
$cooperationMedia = $record->cooperationMedia()
|
||||
->whereHas('partnerMedia', function (Builder $query): void {
|
||||
$query->whereHas('company', function (Builder $subQuery): void {
|
||||
$subQuery->where('user_id', auth()->id());
|
||||
});
|
||||
->whereHas('partnerMedia.company', function (Builder $query): void {
|
||||
$query->where('user_id', auth()->id());
|
||||
})
|
||||
->first();
|
||||
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources\Manage\Cooperations;
|
||||
|
||||
use App\Enums\NotifStyle;
|
||||
use App\Enums\RoleEnum;
|
||||
use App\Filament\Resources\Manage\Cooperations\Infolists\CooperationInfolist;
|
||||
use App\Filament\Resources\Manage\Cooperations\Pages\CreateCooperation;
|
||||
use App\Filament\Resources\Manage\Cooperations\Pages\EditCooperation;
|
||||
use App\Filament\Resources\Manage\Cooperations\Pages\ListCooperations;
|
||||
@ -15,20 +15,13 @@
|
||||
use App\Filament\Resources\Manage\Cooperations\RelationManagers\TaskAssignmentRelationManager;
|
||||
use App\Filament\Resources\Manage\Cooperations\Schemas\CooperationForm;
|
||||
use App\Filament\Resources\Manage\Cooperations\Tables\CooperationsTable;
|
||||
use App\Filament\Support\CheerfulNotification;
|
||||
use App\Models\Cooperation;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Infolists\Components\ImageEntry;
|
||||
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\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Joaopaulolndev\FilamentPdfViewer\Infolists\Components\PdfViewerEntry;
|
||||
use UnitEnum;
|
||||
|
||||
class CooperationResource extends Resource
|
||||
@ -48,10 +41,8 @@ class CooperationResource extends Resource
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
return static::getModel()::when(auth()->user()->hasRole(RoleEnum::PERUSAHAAN->value), function (Builder $query): void {
|
||||
$query->whereHas('partnerMedia', function (Builder $partnerMediaQuery): void {
|
||||
$partnerMediaQuery->whereHas('company', function (Builder $companyQuery): void {
|
||||
$companyQuery->where('user_id', auth()->id());
|
||||
});
|
||||
$query->whereHas('partnerMedia.company', function (Builder $subQuery): void {
|
||||
$subQuery->where('user_id', auth()->id());
|
||||
});
|
||||
})
|
||||
->count();
|
||||
@ -69,75 +60,7 @@ public static function table(Table $table): Table
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make(fn () => CheerfulNotification::getByKey('cooperation.info_title'))
|
||||
->description(fn () => CheerfulNotification::getByKey('cooperation.info_desc'))
|
||||
->icon(fn () => CheerfulNotification::getNotifStyle() === NotifStyle::CHEERFUL ? 'heroicon-o-hand-raised' : null)
|
||||
->headerActions([
|
||||
Action::make('status')
|
||||
->label(fn (Cooperation $record): ?string => $record->status->getLabel())
|
||||
->badge()
|
||||
->color(fn (Cooperation $record): string|array|null => $record->status->getColor())
|
||||
->disabled(),
|
||||
])
|
||||
->schema([
|
||||
TextEntry::make('title')
|
||||
->label('Judul Kerja Sama'),
|
||||
|
||||
Grid::make(3)
|
||||
->schema([
|
||||
TextEntry::make('initial_submission_date')
|
||||
->label('Tanggal Pengajuan Awal')
|
||||
->date('l, d F Y'),
|
||||
|
||||
TextEntry::make('final_submission_date')
|
||||
->label('Tanggal Pengajuan Akhir')
|
||||
->date('l, d F Y'),
|
||||
|
||||
TextEntry::make('taskAssignment.start_date')
|
||||
->label('Tanggal Mulai Media Order')
|
||||
->date('l, d F Y')
|
||||
->placeholder('Belum ditentukan'),
|
||||
|
||||
TextEntry::make('taskAssignment.end_date')
|
||||
->label('Tanggal Selesai Media Order')
|
||||
->date('l, d F Y')
|
||||
->placeholder('Belum ditentukan'),
|
||||
|
||||
TextEntry::make('payment_date')
|
||||
->label('Tanggal Pembayaran')
|
||||
->date('l, d F Y')
|
||||
->placeholder('Belum dibayar'),
|
||||
|
||||
TextEntry::make('completed_at')
|
||||
->label('Tanggal Selesai')
|
||||
->date('l, d F Y')
|
||||
->placeholder('Masih berjalan'),
|
||||
]),
|
||||
|
||||
Grid::make(3)
|
||||
->schema([
|
||||
PdfViewerEntry::make('proposal_template')
|
||||
->label('Template Proposal')
|
||||
->getStateUsing(fn (Cooperation $record): ?string => optional($record->getMedia('cooperations')->where('custom_properties.doc_type', 'proposal-template')->sortByDesc('created_at')->first())->getPathRelativeToRoot())
|
||||
->disk(config('filesystems.default'))
|
||||
->columnSpan(2)
|
||||
->visible(fn (Cooperation $record): bool => $record->getMedia('cooperations')->where('custom_properties.doc_type', 'proposal-template')->isNotEmpty()),
|
||||
|
||||
ImageEntry::make('banner')
|
||||
->label('Banner')
|
||||
->getStateUsing(fn (Cooperation $record): ?string => optional($record->getMedia('banner')->sortByDesc('created_at')->first() ?? $record->getMedia('cooperations')->where('custom_properties.doc_type', 'banner')->sortByDesc('created_at')->first())->getPathRelativeToRoot())
|
||||
->disk(config('filesystems.default'))
|
||||
->visible(fn (Cooperation $record): bool => $record->getMedia('banner')->isNotEmpty() || $record->getMedia('cooperations')->where('custom_properties.doc_type', 'banner')->isNotEmpty()),
|
||||
])
|
||||
->visible(fn (Cooperation $record): bool => $record->getMedia('banner')->isNotEmpty() || $record->getMedia('cooperations')->where('custom_properties.doc_type', 'banner')->isNotEmpty() || $record->getMedia('cooperations')->where('custom_properties.doc_type', 'proposal-template')->isNotEmpty()),
|
||||
|
||||
TextEntry::make('description')
|
||||
->label('Deskripsi'),
|
||||
]),
|
||||
])
|
||||
->columns(1);
|
||||
return CooperationInfolist::configure($schema);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
@ -155,12 +78,8 @@ public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->when(auth()->user()->hasRole(RoleEnum::PERUSAHAAN->value), function (Builder $query): void {
|
||||
$query->whereHas('cooperationMedia', function (Builder $subQuery): void {
|
||||
$subQuery->whereHas('partnerMedia', function (Builder $mediaQuery): void {
|
||||
$mediaQuery->whereHas('company', function (Builder $companyQuery): void {
|
||||
$companyQuery->where('user_id', auth()->id());
|
||||
});
|
||||
});
|
||||
$query->whereHas('cooperationMedia.partnerMedia.company', function (Builder $subQuery): void {
|
||||
$subQuery->where('user_id', auth()->id());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Manage\Cooperations\Infolists;
|
||||
|
||||
use App\Enums\NotifStyle;
|
||||
use App\Filament\Support\CheerfulNotification;
|
||||
use App\Models\Cooperation;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Infolists\Components\ImageEntry;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Joaopaulolndev\FilamentPdfViewer\Infolists\Components\PdfViewerEntry;
|
||||
|
||||
class CooperationInfolist
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make(fn () => CheerfulNotification::getByKey('cooperation.info_title'))
|
||||
->description(fn () => CheerfulNotification::getByKey('cooperation.info_desc'))
|
||||
->icon(fn () => CheerfulNotification::getNotifStyle() === NotifStyle::CHEERFUL ? 'heroicon-o-hand-raised' : null)
|
||||
->headerActions([
|
||||
Action::make('status')
|
||||
->label(fn (Cooperation $record): ?string => $record->status->getLabel())
|
||||
->badge()
|
||||
->color(fn (Cooperation $record): string|array|null => $record->status->getColor())
|
||||
->disabled(),
|
||||
])
|
||||
->schema([
|
||||
TextEntry::make('title')
|
||||
->label('Judul Kerja Sama'),
|
||||
|
||||
Grid::make(3)
|
||||
->schema([
|
||||
TextEntry::make('initial_submission_date')
|
||||
->label('Tanggal Pengajuan Awal')
|
||||
->date('l, d F Y'),
|
||||
|
||||
TextEntry::make('final_submission_date')
|
||||
->label('Tanggal Pengajuan Akhir')
|
||||
->date('l, d F Y'),
|
||||
|
||||
TextEntry::make('taskAssignment.start_date')
|
||||
->label('Tanggal Mulai Media Order')
|
||||
->date('l, d F Y')
|
||||
->placeholder('Belum ditentukan'),
|
||||
|
||||
TextEntry::make('taskAssignment.end_date')
|
||||
->label('Tanggal Selesai Media Order')
|
||||
->date('l, d F Y')
|
||||
->placeholder('Belum ditentukan'),
|
||||
|
||||
TextEntry::make('payment_date')
|
||||
->label('Tanggal Pembayaran')
|
||||
->date('l, d F Y')
|
||||
->placeholder('Belum dibayar'),
|
||||
|
||||
TextEntry::make('completed_at')
|
||||
->label('Tanggal Selesai')
|
||||
->date('l, d F Y')
|
||||
->placeholder('Masih berjalan'),
|
||||
]),
|
||||
|
||||
Grid::make(3)
|
||||
->schema([
|
||||
PdfViewerEntry::make('proposal_template')
|
||||
->label('Template Proposal')
|
||||
->getStateUsing(fn (Cooperation $record): ?string => optional($record->getMedia('cooperations')->where('custom_properties.doc_type', 'proposal-template')->sortByDesc('created_at')->first())->getPathRelativeToRoot())
|
||||
->disk(config('filesystems.default'))
|
||||
->columnSpan(2)
|
||||
->visible(fn (Cooperation $record): bool => $record->getMedia('cooperations')->where('custom_properties.doc_type', 'proposal-template')->isNotEmpty()),
|
||||
|
||||
ImageEntry::make('banner')
|
||||
->label('Banner')
|
||||
->getStateUsing(fn (Cooperation $record): ?string => optional($record->getMedia('banner')->sortByDesc('created_at')->first() ?? $record->getMedia('cooperations')->where('custom_properties.doc_type', 'banner')->sortByDesc('created_at')->first())->getPathRelativeToRoot())
|
||||
->disk(config('filesystems.default'))
|
||||
->visible(fn (Cooperation $record): bool => $record->getMedia('banner')->isNotEmpty() || $record->getMedia('cooperations')->where('custom_properties.doc_type', 'banner')->isNotEmpty()),
|
||||
])
|
||||
->visible(fn (Cooperation $record): bool => $record->getMedia('banner')->isNotEmpty() || $record->getMedia('cooperations')->where('custom_properties.doc_type', 'banner')->isNotEmpty() || $record->getMedia('cooperations')->where('custom_properties.doc_type', 'proposal-template')->isNotEmpty()),
|
||||
|
||||
TextEntry::make('description')
|
||||
->label('Deskripsi')
|
||||
->html()
|
||||
->prose(),
|
||||
]),
|
||||
])
|
||||
->columns(1);
|
||||
}
|
||||
}
|
||||
@ -3,9 +3,11 @@
|
||||
namespace App\Filament\Resources\Manage\Cooperations\Pages;
|
||||
|
||||
use App\Enums\RoleEnum;
|
||||
use App\Filament\Exports\CooperationExcelExport;
|
||||
use App\Filament\Resources\Manage\Cooperations\CooperationResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use pxlrbt\FilamentExcel\Actions\ExportAction;
|
||||
|
||||
class ListCooperations extends ListRecords
|
||||
{
|
||||
@ -15,13 +17,17 @@ class ListCooperations extends ListRecords
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
$actions = [];
|
||||
return [
|
||||
CreateAction::make()
|
||||
->label('Tambah')
|
||||
->visible(! auth()->user()->hasRole(RoleEnum::PERUSAHAAN->value)),
|
||||
|
||||
if (! auth()->user()->hasRole(RoleEnum::PERUSAHAAN->value)) {
|
||||
$actions[] = CreateAction::make()
|
||||
->label('Tambah');
|
||||
}
|
||||
|
||||
return $actions;
|
||||
ExportAction::make()
|
||||
->exports([
|
||||
CooperationExcelExport::make(),
|
||||
])
|
||||
->color('success')
|
||||
->icon(null),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,8 +54,6 @@ public function table(Table $table): Table
|
||||
->label('Status')
|
||||
->badge(),
|
||||
])
|
||||
->filters([])
|
||||
->headerActions([])
|
||||
->recordActions([
|
||||
PayAction::make('pay'),
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Filament\Resources\Manage\Cooperations\RelationManagers;
|
||||
|
||||
use App\Enums\ApprovalStatus;
|
||||
use App\Enums\RoleEnum;
|
||||
use App\Filament\Columns\RowIndexColumn;
|
||||
use App\Filament\Support\CheerfulNotification;
|
||||
@ -28,12 +27,10 @@ public static function canViewForRecord(Model $ownerRecord, string $pageClass):
|
||||
}
|
||||
|
||||
return $ownerRecord->cooperationMedia()
|
||||
->whereHas('partnerMedia', function ($query) {
|
||||
$query->whereHas('company', function ($query) {
|
||||
$query->where('user_id', auth()->id());
|
||||
});
|
||||
->whereHas('partnerMedia.company', function ($query) {
|
||||
$query->where('user_id', auth()->id());
|
||||
})
|
||||
->where('status', ApprovalStatus::ACCEPTED)
|
||||
->accepted()
|
||||
->exists();
|
||||
}
|
||||
|
||||
@ -60,9 +57,6 @@ public function table(Table $table): Table
|
||||
->getStateUsing(fn (CooperationPayment $record): ?string => optional($record->cooperationMedia->getMedia('cooperations')->where('custom_properties.doc_type', 'payment-proof')->sortByDesc('created_at')->first())->getPathRelativeToRoot())
|
||||
->disk(config('filesystems.default')),
|
||||
])
|
||||
->filters([])
|
||||
->headerActions([])
|
||||
->recordActions([])
|
||||
->emptyStateIcon(Heroicon::OutlinedCreditCard)
|
||||
->emptyStateHeading(fn () => CheerfulNotification::getByKey('cooperation.payment_empty_heading'))
|
||||
->emptyStateDescription(fn () => CheerfulNotification::getByKey('cooperation.payment_empty'))
|
||||
|
||||
@ -33,12 +33,10 @@ public static function canViewForRecord(Model $ownerRecord, string $pageClass):
|
||||
{
|
||||
if (auth()->user()->hasRole(RoleEnum::PERUSAHAAN->value)) {
|
||||
return $ownerRecord->cooperationMedia()
|
||||
->whereHas('partnerMedia', function ($query) {
|
||||
$query->whereHas('company', function ($query) {
|
||||
$query->where('user_id', auth()->id());
|
||||
});
|
||||
->whereHas('partnerMedia.company', function ($query) {
|
||||
$query->where('user_id', auth()->id());
|
||||
})
|
||||
->where('status', ApprovalStatus::ACCEPTED)
|
||||
->accepted()
|
||||
->exists();
|
||||
}
|
||||
|
||||
@ -92,8 +90,6 @@ public function table(Table $table): Table
|
||||
->label('Alasan Penolakan')
|
||||
->searchable(),
|
||||
])
|
||||
->filters([])
|
||||
->headerActions([])
|
||||
->recordActions([
|
||||
ViewAction::make(),
|
||||
|
||||
|
||||
@ -43,12 +43,10 @@ public static function canViewForRecord(Model $ownerRecord, string $pageClass):
|
||||
{
|
||||
if (auth()->user()->hasRole(RoleEnum::PERUSAHAAN->value)) {
|
||||
return $ownerRecord->cooperationMedia()
|
||||
->whereHas('partnerMedia', function ($query) {
|
||||
$query->whereHas('company', function ($query) {
|
||||
$query->where('user_id', auth()->id());
|
||||
});
|
||||
->whereHas('partnerMedia.company', function ($query) {
|
||||
$query->where('user_id', auth()->id());
|
||||
})
|
||||
->where('status', ApprovalStatus::ACCEPTED)
|
||||
->accepted()
|
||||
->exists();
|
||||
}
|
||||
|
||||
@ -146,7 +144,6 @@ public function table(Table $table): Table
|
||||
->label('Alasan Penolakan')
|
||||
->searchable(),
|
||||
])
|
||||
->filters([])
|
||||
->recordActions([
|
||||
AcceptAction::make('accept'),
|
||||
|
||||
@ -181,7 +178,8 @@ public function table(Table $table): Table
|
||||
)->send();
|
||||
|
||||
// Notify Admins
|
||||
User::superAdmin()
|
||||
User::query()
|
||||
->superAdmin()
|
||||
->get()
|
||||
->each(function ($admin) use ($record): void {
|
||||
$user = auth()->user();
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Filament\Resources\Manage\Cooperations\RelationManagers;
|
||||
|
||||
use App\Enums\ApprovalStatus;
|
||||
use App\Enums\RoleEnum;
|
||||
use App\Filament\Actions\Cheerful\CreateAction;
|
||||
use App\Filament\Actions\Cheerful\DeleteAction;
|
||||
@ -27,12 +26,10 @@ public static function canViewForRecord(Model $ownerRecord, string $pageClass):
|
||||
{
|
||||
if (auth()->user()->hasRole(RoleEnum::PERUSAHAAN->value)) {
|
||||
return $ownerRecord->cooperationMedia()
|
||||
->whereHas('partnerMedia', function ($query) {
|
||||
$query->whereHas('company', function ($query) {
|
||||
$query->where('user_id', auth()->id());
|
||||
});
|
||||
->whereHas('partnerMedia.company', function ($query) {
|
||||
$query->where('user_id', auth()->id());
|
||||
})
|
||||
->where('status', ApprovalStatus::ACCEPTED)
|
||||
->accepted()
|
||||
->exists();
|
||||
}
|
||||
|
||||
@ -60,9 +57,6 @@ public function table(Table $table): Table
|
||||
TextColumn::make('report_amount')
|
||||
->label('Jumlah Bukti Tayang'),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make()
|
||||
->label('Buat Media Order')
|
||||
@ -72,34 +66,38 @@ public function table(Table $table): Table
|
||||
return $cooperation->proposal()->accepted()->exists()
|
||||
&& ! $cooperation->taskAssignment()->exists();
|
||||
})
|
||||
->successNotification(fn () => CheerfulNotification::success(
|
||||
CheerfulNotification::getByKey('cooperation.assignment_success'),
|
||||
CheerfulNotification::getByKey('cooperation.assignment_set_success')
|
||||
)
|
||||
->successNotification(
|
||||
fn () => CheerfulNotification::success(
|
||||
CheerfulNotification::getByKey('cooperation.assignment_success'),
|
||||
CheerfulNotification::getByKey('cooperation.assignment_set_success')
|
||||
)
|
||||
),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make()
|
||||
->successNotification(fn () => CheerfulNotification::success(
|
||||
CheerfulNotification::getByKey('cooperation.assignment_updated'),
|
||||
CheerfulNotification::getByKey('cooperation.assignment_updated_desc')
|
||||
)
|
||||
->successNotification(
|
||||
fn () => CheerfulNotification::success(
|
||||
CheerfulNotification::getByKey('cooperation.assignment_updated'),
|
||||
CheerfulNotification::getByKey('cooperation.assignment_updated_desc')
|
||||
)
|
||||
),
|
||||
|
||||
DeleteAction::make()
|
||||
->successNotification(fn () => CheerfulNotification::success(
|
||||
CheerfulNotification::getByKey('cooperation.assignment_deleted'),
|
||||
CheerfulNotification::getByKey('cooperation.assignment_deleted_desc')
|
||||
)
|
||||
->successNotification(
|
||||
fn () => CheerfulNotification::success(
|
||||
CheerfulNotification::getByKey('cooperation.assignment_deleted'),
|
||||
CheerfulNotification::getByKey('cooperation.assignment_deleted_desc')
|
||||
)
|
||||
),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make()
|
||||
->successNotification(fn () => CheerfulNotification::success(
|
||||
CheerfulNotification::getByKey('cooperation.assignment_success_dihapus'),
|
||||
CheerfulNotification::getByKey('cooperation.bulk_assignment_deleted')
|
||||
)
|
||||
->successNotification(
|
||||
fn () => CheerfulNotification::success(
|
||||
CheerfulNotification::getByKey('cooperation.assignment_success_dihapus'),
|
||||
CheerfulNotification::getByKey('cooperation.bulk_assignment_deleted')
|
||||
)
|
||||
),
|
||||
]),
|
||||
])
|
||||
|
||||
@ -8,9 +8,9 @@
|
||||
use Asmit\FilamentUpload\Forms\Components\AdvancedFileUpload;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Components\Section;
|
||||
@ -40,16 +40,16 @@ public static function configure(Schema $schema): Schema
|
||||
Grid::make(2)
|
||||
->schema([
|
||||
DatePicker::make('initial_submission_date')
|
||||
->label('Tgl Pengajuan Awal')
|
||||
->label('Tanggal Pengajuan Awal')
|
||||
->placeholder(fn (): string => now()->translatedFormat('l, d F Y'))
|
||||
->native(false)
|
||||
->displayFormat('l, d F Y')
|
||||
->required()
|
||||
->minDate(today())
|
||||
->minDate(fn ($context) => $context === 'create' ? today() : null)
|
||||
->reactive(),
|
||||
|
||||
DatePicker::make('final_submission_date')
|
||||
->label('Tgl Pengajuan Akhir')
|
||||
->label('Tanggal Pengajuan Akhir')
|
||||
->placeholder(fn (): string => now()->addDays(7)->translatedFormat('l, d F Y'))
|
||||
->native(false)
|
||||
->displayFormat('l, d F Y')
|
||||
@ -73,18 +73,15 @@ public static function configure(Schema $schema): Schema
|
||||
->label('Pilih Semua')
|
||||
->icon('heroicon-o-check-circle')
|
||||
->action(function (Set $set): void {
|
||||
$allMediaIds = PartnerMedia::verified()->pluck('id')->toArray();
|
||||
$allMediaIds = PartnerMedia::query()->verified()->pluck('id')->toArray();
|
||||
$set('partner_media_ids', $allMediaIds);
|
||||
})
|
||||
),
|
||||
|
||||
Textarea::make('description')
|
||||
RichEditor::make('description')
|
||||
->label('Deskripsi Kerja Sama')
|
||||
->placeholder('Jelaskan detail lingkup kerja sama di sini...')
|
||||
->required()
|
||||
->rows(5)
|
||||
->maxLength(65535)
|
||||
->autocomplete(false),
|
||||
->required(),
|
||||
])
|
||||
->columnSpan(2),
|
||||
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
use App\Filament\Actions\DefaultBulkActions;
|
||||
use App\Filament\Columns\RowIndexColumn;
|
||||
use App\Filament\Columns\TimestampColumns;
|
||||
use App\Filament\Exports\CooperationExcelExport;
|
||||
use App\Filament\Resources\Manage\Cooperations\Actions\Cooperation\AcceptAction;
|
||||
use App\Filament\Resources\Manage\Cooperations\Actions\Cooperation\CompleteCooperationAction;
|
||||
use App\Filament\Resources\Manage\Cooperations\Actions\Cooperation\CreateTaskAssignmentAction;
|
||||
@ -33,7 +32,6 @@
|
||||
use Filament\Tables\Filters\TrashedFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use pxlrbt\FilamentExcel\Actions\Tables\ExportAction;
|
||||
|
||||
class CooperationsTable
|
||||
{
|
||||
@ -58,13 +56,13 @@ public static function configure(Table $table): Table
|
||||
->visible(! auth()->user()->hasRole(RoleEnum::PERUSAHAAN->value)),
|
||||
|
||||
TextColumn::make('initial_submission_date')
|
||||
->label('Tgl Pengajuan Awal')
|
||||
->label('Tanggal Pengajuan Awal')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->date('l, d F Y'),
|
||||
|
||||
TextColumn::make('final_submission_date')
|
||||
->label('Tgl Pengajuan Akhir')
|
||||
->label('Tanggal Pengajuan Akhir')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->date('l, d F Y')
|
||||
@ -101,15 +99,13 @@ public static function configure(Table $table): Table
|
||||
})
|
||||
->visible(! auth()->user()->hasRole(RoleEnum::PERUSAHAAN->value)),
|
||||
|
||||
TextColumn::make('status_tanggapan')
|
||||
TextColumn::make('response_status')
|
||||
->label('Tanggapan')
|
||||
->getStateUsing(function (Cooperation $record): ?ApprovalStatus {
|
||||
if (auth()->user()->hasRole(RoleEnum::PERUSAHAAN->value)) {
|
||||
$cooperationMedia = $record->cooperationMedia()
|
||||
->whereHas('partnerMedia', function (Builder $query): void {
|
||||
$query->whereHas('company', function (Builder $subQuery): void {
|
||||
$subQuery->where('user_id', auth()->id());
|
||||
});
|
||||
->whereHas('partnerMedia.company', function (Builder $query): void {
|
||||
$query->where('user_id', auth()->id());
|
||||
})
|
||||
->first();
|
||||
|
||||
@ -272,15 +268,6 @@ public static function configure(Table $table): Table
|
||||
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->headerActions([
|
||||
ExportAction::make()
|
||||
->exports([
|
||||
CooperationExcelExport::make(),
|
||||
])
|
||||
->color('success')
|
||||
->visible(fn (): bool => auth()->user()->hasRole(RoleEnum::DEVELOPER->value) || auth()->user()->hasRole(RoleEnum::ADMINISTRATOR->value)),
|
||||
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
...DefaultBulkActions::make('Kerja Sama'),
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ApprovalStatus;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
@ -27,6 +29,24 @@ protected function casts(): array
|
||||
];
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
protected function pending(Builder $query): void
|
||||
{
|
||||
$query->where('status', ApprovalStatus::PENDING);
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
protected function accepted(Builder $query): void
|
||||
{
|
||||
$query->where('status', ApprovalStatus::ACCEPTED);
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
protected function rejected(Builder $query): void
|
||||
{
|
||||
$query->where('status', ApprovalStatus::REJECTED);
|
||||
}
|
||||
|
||||
public function partnerMedia(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PartnerMedia::class);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user