base commit
This commit is contained in:
41
app/Filament/Support/ExportExcelAction.php
Normal file
41
app/Filament/Support/ExportExcelAction.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkAction;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
class ExportExcelAction
|
||||
{
|
||||
/**
|
||||
* @param class-string $exportClass
|
||||
*/
|
||||
public static function make(string $name, string $exportClass, string $filename): Action
|
||||
{
|
||||
return Action::make($name)
|
||||
->label('Export')
|
||||
->icon('heroicon-o-arrow-down-tray')
|
||||
->action(fn (): BinaryFileResponse => Excel::download(new $exportClass, $filename));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string $exportClass
|
||||
*/
|
||||
public static function bulk(string $name, string $exportClass, string $filename): BulkAction
|
||||
{
|
||||
return BulkAction::make($name)
|
||||
->label('Export Selected')
|
||||
->icon('heroicon-o-arrow-down-tray')
|
||||
->action(function (Collection $records) use ($exportClass, $filename): BinaryFileResponse {
|
||||
$ids = $records->pluck('id')->all();
|
||||
|
||||
return Excel::download(new $exportClass($ids), $filename);
|
||||
})
|
||||
->deselectRecordsAfterCompletion();
|
||||
}
|
||||
}
|
||||
55
app/Filament/Support/ExportPdfAction.php
Normal file
55
app/Filament/Support/ExportPdfAction.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use App\Models\Employee;
|
||||
use App\Services\Export\PdfExportService;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkAction;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class ExportPdfAction
|
||||
{
|
||||
public static function employeeProfile(): Action
|
||||
{
|
||||
return Action::make('exportPdf')
|
||||
->label('Export PDF')
|
||||
->icon('heroicon-o-document-arrow-down')
|
||||
->action(fn (Employee $record, PdfExportService $pdf) => $pdf->employeeProfile($record));
|
||||
}
|
||||
|
||||
public static function employeeLeaveSummary(): Action
|
||||
{
|
||||
return Action::make('exportLeavePdf')
|
||||
->label('Leave Summary PDF')
|
||||
->icon('heroicon-o-document-text')
|
||||
->action(fn (Employee $record, PdfExportService $pdf) => $pdf->leaveSummary($record));
|
||||
}
|
||||
|
||||
public static function employeeList(): Action
|
||||
{
|
||||
return Action::make('exportPdf')
|
||||
->label('Export PDF')
|
||||
->icon('heroicon-o-document-arrow-down')
|
||||
->action(fn (PdfExportService $pdf) => $pdf->employeeList(
|
||||
Employee::query()->with(['department', 'position', 'shift'])->orderBy('full_name')->get()
|
||||
));
|
||||
}
|
||||
|
||||
public static function employeeListBulk(): BulkAction
|
||||
{
|
||||
return BulkAction::make('exportPdf')
|
||||
->label('Export PDF')
|
||||
->icon('heroicon-o-document-arrow-down')
|
||||
->action(fn (Collection $records, PdfExportService $pdf) => $pdf->employeeList(
|
||||
Employee::query()
|
||||
->with(['department', 'position', 'shift'])
|
||||
->whereIn('id', $records->pluck('id'))
|
||||
->orderBy('full_name')
|
||||
->get()
|
||||
))
|
||||
->deselectRecordsAfterCompletion();
|
||||
}
|
||||
}
|
||||
74
app/Filament/Support/HrForm.php
Normal file
74
app/Filament/Support/HrForm.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use App\Services\Leave\LeaveDaysCalculator;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Components\Utilities\Set;
|
||||
|
||||
class HrForm
|
||||
{
|
||||
public static function fileUpload(string $name): FileUpload
|
||||
{
|
||||
return FileUpload::make($name)
|
||||
->disk(config('hr.file_uploads.disk'))
|
||||
->directory(config('hr.file_uploads.directory'))
|
||||
->visibility('private');
|
||||
}
|
||||
|
||||
public static function employeeSelect(): Select
|
||||
{
|
||||
return Select::make('employee_id')
|
||||
->relationship('employee', 'full_name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required();
|
||||
}
|
||||
|
||||
public static function leaveDaysDisplay(): TextInput
|
||||
{
|
||||
return TextInput::make('days')
|
||||
->label('Days')
|
||||
->numeric()
|
||||
->disabled()
|
||||
->dehydrated(false)
|
||||
->afterStateHydrated(function (TextInput $component, $state, Set $set, Get $get): void {
|
||||
self::syncLeaveDays($set, $get);
|
||||
});
|
||||
}
|
||||
|
||||
public static function leaveDatePicker(string $name, string $label): DatePicker
|
||||
{
|
||||
return DatePicker::make($name)
|
||||
->label($label)
|
||||
->required()
|
||||
->live()
|
||||
->afterStateUpdated(fn (Set $set, Get $get) => self::syncLeaveDays($set, $get));
|
||||
}
|
||||
|
||||
public static function syncLeaveDays(Set $set, Get $get): void
|
||||
{
|
||||
$startDate = $get('start_date');
|
||||
$endDate = $get('end_date');
|
||||
|
||||
if (! $startDate || ! $endDate) {
|
||||
$set('days', null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$days = app(LeaveDaysCalculator::class)->between(
|
||||
Carbon::parse($startDate),
|
||||
Carbon::parse($endDate),
|
||||
);
|
||||
|
||||
$set('days', $days);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user