feat: tambah role editor, workflow post, leaderboard, rekap kehadiran, kategori kas dengan type, seeder lengkap
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\CashCategories\Schemas;
|
||||
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
@@ -11,6 +12,9 @@ class CashCategoryForm
|
||||
{
|
||||
return $schema->components([
|
||||
TextInput::make('name')->label('Nama')->required(),
|
||||
Select::make('type')->label('Tipe')
|
||||
->options(['pemasukan' => 'Pemasukan', 'pengeluaran' => 'Pengeluaran'])
|
||||
->required(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@ class CashCategoriesTable
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')->label('Nama')->searchable(),
|
||||
TextColumn::make('type')->label('Tipe')
|
||||
->badge()
|
||||
->color(fn ($state) => $state === 'pemasukan' ? 'success' : 'danger')
|
||||
->formatStateUsing(fn ($state) => ucfirst($state)),
|
||||
TextColumn::make('records_count')->counts('records')->label('Transaksi'),
|
||||
])
|
||||
->recordActions([EditAction::make()])
|
||||
|
||||
@@ -16,7 +16,11 @@ class CashRecordForm
|
||||
{
|
||||
return $schema->components([
|
||||
Select::make('category_id')->label('Kategori')
|
||||
->options(CashCategory::pluck('name', 'id'))
|
||||
->options(
|
||||
CashCategory::all()->mapWithKeys(fn ($c) => [
|
||||
$c->id => $c->name . ' (' . ucfirst($c->type) . ')'
|
||||
])
|
||||
)
|
||||
->required(),
|
||||
TextInput::make('amount')->label('Jumlah (Rp)')->numeric()->required()
|
||||
->helperText('< Rp500.000: langsung | Rp500.000–2.000.000: perlu approval ketua | > Rp2.000.000: perlu voting')
|
||||
|
||||
@@ -58,6 +58,11 @@ class CashRecordsTable
|
||||
->filters([
|
||||
SelectFilter::make('category_id')->label('Kategori')
|
||||
->options(CashCategory::pluck('name', 'id')),
|
||||
SelectFilter::make('type')->label('Tipe')
|
||||
->options(['pemasukan' => 'Pemasukan', 'pengeluaran' => 'Pengeluaran'])
|
||||
->query(fn ($query, $state) => $state['value']
|
||||
? $query->whereHas('category', fn ($q) => $q->where('type', $state['value']))
|
||||
: $query),
|
||||
])
|
||||
->recordActions([
|
||||
// Ketua: approve transaksi 500rb–2jt
|
||||
|
||||
@@ -23,7 +23,7 @@ class PostResource extends Resource
|
||||
// Label dinamis sesuai role
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return auth()->user()?->can('ViewAny:Post') && auth()->user()?->can('Update:Post')
|
||||
return auth()->user()?->can('Publish:Post')
|
||||
? 'Artikel'
|
||||
: 'Artikel Saya';
|
||||
}
|
||||
@@ -32,7 +32,7 @@ class PostResource extends Resource
|
||||
{
|
||||
$query = parent::getEloquentQuery();
|
||||
|
||||
if (auth()->user()?->can('Update:Post')) {
|
||||
if (auth()->user()?->can('Publish:Post')) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class PostForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
$isAdmin = auth()->user()?->can('Update:Post');
|
||||
$canReview = auth()->user()?->can('Publish:Post');
|
||||
|
||||
return $schema->components([
|
||||
TextInput::make('title')->label('Judul')->required()
|
||||
@@ -28,7 +28,7 @@ class PostForm
|
||||
])
|
||||
->default('umum')->required(),
|
||||
DateTimePicker::make('published_at')->label('Tanggal Publikasi')
|
||||
->visible($isAdmin)
|
||||
->visible($canReview)
|
||||
->helperText('Kosongkan untuk menyimpan sebagai draft'),
|
||||
RichEditor::make('content')->label('Konten')->required()->columnSpanFull(),
|
||||
]);
|
||||
|
||||
@@ -7,6 +7,7 @@ use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
@@ -16,7 +17,8 @@ class PostsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
$isAdmin = auth()->user()?->can('Update:Post');
|
||||
$canReview = auth()->user()?->can('Publish:Post');
|
||||
$canPublish = auth()->user()?->can('Publish:Post');
|
||||
|
||||
return $table
|
||||
->columns([
|
||||
@@ -30,68 +32,74 @@ class PostsTable
|
||||
TextColumn::make('status')->badge()
|
||||
->color(fn ($state) => match ($state) {
|
||||
'published' => 'success',
|
||||
'approved' => 'info',
|
||||
'pending' => 'warning',
|
||||
'rejected' => 'danger',
|
||||
default => 'gray',
|
||||
})
|
||||
->formatStateUsing(fn ($state) => match ($state) {
|
||||
'draft' => 'Draft',
|
||||
'pending' => 'Menunggu',
|
||||
'approved' => 'Disetujui',
|
||||
'published' => 'Diterbitkan',
|
||||
'rejected' => 'Ditolak',
|
||||
default => $state,
|
||||
}),
|
||||
TextColumn::make('author.name')->label('Penulis')->visible($isAdmin),
|
||||
TextColumn::make('rejection_reason')->label('Alasan Penolakan')
|
||||
->limit(40)->default('-')
|
||||
->visible(fn ($record) => $record?->status === 'rejected'),
|
||||
TextColumn::make('author.name')->label('Penulis')->visible($canReview),
|
||||
TextColumn::make('published_at')->label('Dipublikasi')
|
||||
->dateTime('d M Y')->default('-')->sortable(),
|
||||
->dateTime('d M Y')->placeholder('-')->sortable(),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('status')->options([
|
||||
'draft' => 'Draft',
|
||||
'pending' => 'Menunggu',
|
||||
'approved' => 'Disetujui',
|
||||
'published' => 'Diterbitkan',
|
||||
'rejected' => 'Ditolak',
|
||||
]),
|
||||
])
|
||||
->recordActions([
|
||||
// Untuk anggota/pengurus/bendahara: ajukan artikel
|
||||
// Member: ajukan artikel
|
||||
Action::make('submit')
|
||||
->label('Ajukan')
|
||||
->icon('heroicon-o-paper-airplane')
|
||||
->color('info')
|
||||
->requiresConfirmation()
|
||||
->visible(fn ($record) => ! $isAdmin && in_array($record->status, ['draft', 'rejected']))
|
||||
->visible(fn ($record) => ! $canReview && in_array($record->status, ['draft', 'rejected']))
|
||||
->action(function ($record): void {
|
||||
$record->update(['status' => 'pending', 'rejection_reason' => null]);
|
||||
NotificationService::toRole('ketua', 'Artikel Menunggu Persetujuan',
|
||||
NotificationService::toRole('editor', 'Artikel Menunggu Persetujuan',
|
||||
"\"{$record->title}\" oleh {$record->author->name} menunggu persetujuan.", 'warning',
|
||||
route('filament.admin.resources.posts.edit', $record));
|
||||
}),
|
||||
|
||||
// Untuk admin: approve
|
||||
Action::make('publish')
|
||||
->label('Terbitkan')
|
||||
// Editor: approve
|
||||
Action::make('approve')
|
||||
->label('Setujui')
|
||||
->icon('heroicon-o-check-circle')
|
||||
->color('success')
|
||||
->requiresConfirmation()
|
||||
->visible(fn ($record) => $isAdmin && $record->status === 'pending')
|
||||
->visible(fn ($record) => $canReview && $record->status === 'pending')
|
||||
->action(fn ($record) => tap($record->update([
|
||||
'status' => 'published',
|
||||
'published_at' => now(),
|
||||
'reviewed_by' => auth()->id(),
|
||||
'status' => 'approved',
|
||||
'approved_by' => auth()->id(),
|
||||
'approved_at' => now(),
|
||||
'reviewed_by' => auth()->id(),
|
||||
]), fn () => NotificationService::send(
|
||||
$record->author, 'Artikel Diterbitkan',
|
||||
"Artikel \"{$record->title}\" Anda telah diterbitkan.", 'success',
|
||||
$record->author, 'Artikel Disetujui',
|
||||
"Artikel \"{$record->title}\" Anda telah disetujui dan akan segera diterbitkan.", 'success',
|
||||
route('filament.admin.resources.posts.edit', $record)
|
||||
))),
|
||||
|
||||
// Untuk admin: tolak
|
||||
// Editor: tolak
|
||||
Action::make('reject')
|
||||
->label('Tolak')
|
||||
->icon('heroicon-o-x-circle')
|
||||
->color('danger')
|
||||
->visible(fn ($record) => $isAdmin && $record->status === 'pending')
|
||||
->form([
|
||||
Textarea::make('rejection_reason')->label('Alasan Penolakan')->required(),
|
||||
])
|
||||
->visible(fn ($record) => $canReview && $record->status === 'pending')
|
||||
->form([Textarea::make('rejection_reason')->label('Alasan Penolakan')->required()])
|
||||
->action(fn ($record, array $data) => tap($record->update([
|
||||
'status' => 'rejected',
|
||||
'status' => 'draft',
|
||||
'reviewed_by' => auth()->id(),
|
||||
'rejection_reason' => $data['rejection_reason'],
|
||||
]), fn () => NotificationService::send(
|
||||
@@ -100,8 +108,35 @@ class PostsTable
|
||||
route('filament.admin.resources.posts.edit', $record)
|
||||
))),
|
||||
|
||||
// Editor: publish (approved → published)
|
||||
Action::make('publish')
|
||||
->label('Terbitkan')
|
||||
->icon('heroicon-o-globe-alt')
|
||||
->color('success')
|
||||
->visible(fn ($record) => $canPublish && $record->status === 'approved')
|
||||
->form([
|
||||
DateTimePicker::make('published_at')->label('Tanggal Publikasi')
|
||||
->default(now())->required(),
|
||||
])
|
||||
->action(fn ($record, array $data) => $record->update([
|
||||
'status' => 'published',
|
||||
'published_at' => $data['published_at'],
|
||||
])),
|
||||
|
||||
// Editor: unpublish
|
||||
Action::make('unpublish')
|
||||
->label('Batalkan Publikasi')
|
||||
->icon('heroicon-o-eye-slash')
|
||||
->color('warning')
|
||||
->requiresConfirmation()
|
||||
->visible(fn ($record) => $canPublish && $record->status === 'published')
|
||||
->action(fn ($record) => $record->update([
|
||||
'status' => 'approved',
|
||||
'published_at' => null,
|
||||
])),
|
||||
|
||||
EditAction::make()
|
||||
->visible(fn ($record) => $isAdmin || in_array($record->status, ['draft', 'rejected'])),
|
||||
->visible(fn ($record) => $canReview || in_array($record->status, ['draft', 'rejected'])),
|
||||
])
|
||||
->toolbarActions([BulkActionGroup::make([DeleteBulkAction::make()])]);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Users\RelationManagers;
|
||||
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class AttendanceRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'activities';
|
||||
protected static ?string $title = 'Rekap Kehadiran';
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('title')->label('Kegiatan'),
|
||||
TextColumn::make('start_date')->label('Tanggal')->date('d M Y')->sortable(),
|
||||
TextColumn::make('pivot.status')->label('Status')
|
||||
->badge()
|
||||
->color(fn ($state) => match ($state) {
|
||||
'hadir' => 'success',
|
||||
'izin' => 'warning',
|
||||
'alpha' => 'danger',
|
||||
default => 'gray',
|
||||
})
|
||||
->formatStateUsing(fn ($state) => ucfirst($state ?? '-')),
|
||||
TextColumn::make('pivot.notes')->label('Catatan')->placeholder('-'),
|
||||
])
|
||||
->defaultSort('activities.start_date', 'desc')
|
||||
->paginated([10, 25]);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\Filament\Resources\Users;
|
||||
use App\Filament\Resources\Users\Pages\CreateUser;
|
||||
use App\Filament\Resources\Users\Pages\EditUser;
|
||||
use App\Filament\Resources\Users\Pages\ListUsers;
|
||||
use App\Filament\Resources\Users\RelationManagers\AttendanceRelationManager;
|
||||
use App\Filament\Resources\Users\Schemas\UserForm;
|
||||
use App\Filament\Resources\Users\Tables\UsersTable;
|
||||
use App\Models\User;
|
||||
@@ -30,6 +31,13 @@ class UserResource extends Resource
|
||||
return UsersTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
AttendanceRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -21,7 +21,7 @@ class CashStatsWidget extends StatsOverviewWidget
|
||||
$saldo = fn ($query) => $query
|
||||
->whereNotNull('verified_at')
|
||||
->join('cash_categories', 'cash_records.category_id', '=', 'cash_categories.id')
|
||||
->selectRaw("SUM(CASE WHEN cash_categories.name = 'pemasukan' THEN amount ELSE -amount END) as saldo")
|
||||
->selectRaw("SUM(CASE WHEN cash_categories.type = 'pemasukan' THEN amount ELSE -amount END) as saldo")
|
||||
->value('saldo') ?? 0;
|
||||
|
||||
$bulanIni = now()->startOfMonth();
|
||||
@@ -30,12 +30,12 @@ class CashStatsWidget extends StatsOverviewWidget
|
||||
$totalSaldo = $saldo(CashRecord::query());
|
||||
$pemasukanBulanIni = CashRecord::whereNotNull('verified_at')
|
||||
->join('cash_categories', 'cash_records.category_id', '=', 'cash_categories.id')
|
||||
->where('cash_categories.name', 'pemasukan')
|
||||
->where('cash_categories.type', 'pemasukan')
|
||||
->whereMonth('date', $bulanIni->month)->whereYear('date', $bulanIni->year)
|
||||
->sum('amount');
|
||||
$pengeluaranBulanIni = CashRecord::whereNotNull('verified_at')
|
||||
->join('cash_categories', 'cash_records.category_id', '=', 'cash_categories.id')
|
||||
->where('cash_categories.name', 'pengeluaran')
|
||||
->where('cash_categories.type', 'pengeluaran')
|
||||
->whereMonth('date', $bulanIni->month)->whereYear('date', $bulanIni->year)
|
||||
->sum('amount');
|
||||
$saldoBulanLalu = $saldo(CashRecord::query()->where('date', '<', $bulanIni));
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\MemberPoint;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Widgets\TableWidget;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class LeaderboardWidget extends TableWidget
|
||||
{
|
||||
protected static ?string $heading = 'Leaderboard Poin Anggota';
|
||||
protected int | string | array $columnSpan = 'full';
|
||||
protected static ?int $sort = 3;
|
||||
|
||||
public function getTableRecordKey(\Illuminate\Database\Eloquent\Model|array $record): string
|
||||
{
|
||||
return (string) (is_array($record) ? $record['user_id'] : $record->user_id);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->query(
|
||||
MemberPoint::query()
|
||||
->selectRaw('user_id, SUM(points) as total_points')
|
||||
->groupBy('user_id')
|
||||
->orderByDesc('total_points')
|
||||
->limit(10)
|
||||
->with('user')
|
||||
)
|
||||
->columns([
|
||||
TextColumn::make('user.name')->label('Anggota'),
|
||||
TextColumn::make('total_points')->label('Total Poin')
|
||||
->badge()->color('success'),
|
||||
])
|
||||
->paginated(false);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ class StatsOverview extends StatsOverviewWidget
|
||||
{
|
||||
$totalKas = CashRecord::whereNotNull('verified_at')
|
||||
->join('cash_categories', 'cash_records.category_id', '=', 'cash_categories.id')
|
||||
->selectRaw("SUM(CASE WHEN cash_categories.name = 'pemasukan' THEN amount ELSE -amount END) as saldo")
|
||||
->selectRaw("SUM(CASE WHEN cash_categories.type = 'pemasukan' THEN amount ELSE -amount END) as saldo")
|
||||
->value('saldo') ?? 0;
|
||||
|
||||
return [
|
||||
|
||||
@@ -51,6 +51,13 @@ class PublicController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function blogDetail(Post $post)
|
||||
{
|
||||
abort_if($post->status !== 'published' || ! $post->published_at, 404);
|
||||
|
||||
return view('public.blog-detail', compact('post'));
|
||||
}
|
||||
|
||||
public function kontak()
|
||||
{
|
||||
return view('public.kontak');
|
||||
|
||||
@@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class CashCategory extends Model
|
||||
{
|
||||
protected $fillable = ['name'];
|
||||
protected $fillable = ['name', 'type'];
|
||||
|
||||
public function records(): HasMany
|
||||
{
|
||||
|
||||
+7
-2
@@ -8,9 +8,9 @@ use Illuminate\Support\Str;
|
||||
|
||||
class Post extends Model
|
||||
{
|
||||
protected $fillable = ['title', 'slug', 'category', 'content', 'author_id', 'published_at', 'status', 'reviewed_by', 'rejection_reason'];
|
||||
protected $fillable = ['title', 'slug', 'category', 'content', 'author_id', 'published_at', 'status', 'reviewed_by', 'rejection_reason', 'approved_by', 'approved_at'];
|
||||
|
||||
protected $casts = ['published_at' => 'datetime'];
|
||||
protected $casts = ['published_at' => 'datetime', 'approved_at' => 'datetime'];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
@@ -30,6 +30,11 @@ class Post extends Model
|
||||
return $this->belongsTo(User::class, 'reviewed_by');
|
||||
}
|
||||
|
||||
public function approver(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'approved_by');
|
||||
}
|
||||
|
||||
public function scopePublished($query)
|
||||
{
|
||||
return $query->where('status', 'published')
|
||||
|
||||
@@ -9,14 +9,18 @@ class PostObserver
|
||||
{
|
||||
public function updated(Post $post): void
|
||||
{
|
||||
if ($post->wasChanged('status') && $post->status === 'published') {
|
||||
MemberPoint::create([
|
||||
'user_id' => $post->author_id,
|
||||
'points' => 5,
|
||||
'reason' => "Artikel dipublikasi: {$post->title}",
|
||||
'source_type' => 'post',
|
||||
'source_id' => $post->id,
|
||||
]);
|
||||
if ($post->wasChanged('status') && $post->status === 'approved') {
|
||||
MemberPoint::firstOrCreate(
|
||||
[
|
||||
'user_id' => $post->author_id,
|
||||
'source_type' => Post::class,
|
||||
'source_id' => $post->id,
|
||||
],
|
||||
[
|
||||
'points' => 5,
|
||||
'reason' => "Artikel disetujui: {$post->title}",
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,11 @@ class UserObserver
|
||||
|
||||
public function created(User $user): void
|
||||
{
|
||||
// Auto-assign role anggota jika belum punya role
|
||||
if ($user->roles->isEmpty()) {
|
||||
$user->assignRole('anggota');
|
||||
}
|
||||
|
||||
ActivityLog::create([
|
||||
'user_id' => Auth::id(),
|
||||
'action' => 'created',
|
||||
|
||||
@@ -27,8 +27,11 @@ class AdminPanelProvider extends PanelProvider
|
||||
{
|
||||
return $panel
|
||||
->default()
|
||||
->brandLogo(asset('images/logo.png'))
|
||||
->brandLogoHeight('2rem')
|
||||
->id('admin')
|
||||
->path('dashboard')
|
||||
->viteTheme('resources/css/filament/admin/theme.css')
|
||||
->login()
|
||||
->colors([
|
||||
'primary' => Color::Amber,
|
||||
@@ -59,6 +62,7 @@ class AdminPanelProvider extends PanelProvider
|
||||
AccountWidget::class,
|
||||
\App\Filament\Widgets\StatsOverview::class,
|
||||
\App\Filament\Widgets\ActivityLogWidget::class,
|
||||
\App\Filament\Widgets\LeaderboardWidget::class,
|
||||
])
|
||||
->middleware([
|
||||
EncryptCookies::class,
|
||||
|
||||
Reference in New Issue
Block a user