add wizardform
This commit is contained in:
parent
d9f69b7f68
commit
52b903ad10
|
@ -0,0 +1,220 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\Listform;
|
||||
use App\Models\Mahasiswa;
|
||||
use Filament\Forms\Components\Wizard;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class WizardForm extends Page
|
||||
{
|
||||
use InteractsWithForms;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
protected static string $view = 'filament.pages.wizard-form';
|
||||
protected static ?string $title = 'Form Pendaftaran KIP-K';
|
||||
|
||||
// Data Mahasiswa
|
||||
public $noreg_kipk;
|
||||
public $nama;
|
||||
public $nim;
|
||||
public $jurusan;
|
||||
public $prodi;
|
||||
public $angkatan;
|
||||
public $semester;
|
||||
public $jalur_masuk;
|
||||
public $ponsel;
|
||||
public $alamat;
|
||||
|
||||
// Data Parameter
|
||||
public $kepemilikan_kip;
|
||||
public $tingkatan_desil;
|
||||
public $berkas_sktm;
|
||||
public $berkas_ppke;
|
||||
public $berkas_pmk;
|
||||
public $berkas_pkh;
|
||||
public $berkas_kks;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->form->fill();
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Wizard::make([
|
||||
Wizard\Step::make('Biodata Mahasiswa')
|
||||
->schema([
|
||||
TextInput::make('noreg_kipk')
|
||||
->label('No. Registrasi KIP-K')
|
||||
->required(),
|
||||
TextInput::make('nama')
|
||||
->label('Nama Lengkap')
|
||||
->required(),
|
||||
TextInput::make('nim')
|
||||
->label('NIM')
|
||||
->required(),
|
||||
TextInput::make('jurusan')
|
||||
->label('Jurusan')
|
||||
->required(),
|
||||
TextInput::make('prodi')
|
||||
->label('Program Studi')
|
||||
->required(),
|
||||
TextInput::make('angkatan')
|
||||
->label('Angkatan')
|
||||
->required(),
|
||||
TextInput::make('semester')
|
||||
->label('Semester')
|
||||
->required(),
|
||||
TextInput::make('jalur_masuk')
|
||||
->label('Jalur Masuk')
|
||||
->required(),
|
||||
TextInput::make('ponsel')
|
||||
->label('No. Handphone')
|
||||
->tel()
|
||||
->required(),
|
||||
TextInput::make('alamat')
|
||||
->label('Alamat')
|
||||
->required(),
|
||||
]),
|
||||
|
||||
Wizard\Step::make('Parameter Penilaian')
|
||||
->schema([
|
||||
Select::make('kepemilikan_kip')
|
||||
->label('Kepemilikan KIP')
|
||||
->options([
|
||||
'Memiliki KIP' => 'Memiliki KIP',
|
||||
'Tidak Memiliki KIP' => 'Tidak Memiliki KIP',
|
||||
])
|
||||
->required(),
|
||||
|
||||
Select::make('tingkatan_desil')
|
||||
->label('Tingkatan Desil')
|
||||
->options([
|
||||
'Desil 1' => 'Desil 1',
|
||||
'Desil 2' => 'Desil 2',
|
||||
'Desil 3' => 'Desil 3',
|
||||
'Desil 4' => 'Desil 4',
|
||||
'Desil 5' => 'Desil 5',
|
||||
])
|
||||
->required(),
|
||||
|
||||
FileUpload::make('berkas_sktm')
|
||||
->label('Upload SKTM')
|
||||
->helperText('Surat Keterangan Tidak Mampu dari Kelurahan/Desa')
|
||||
->directory('berkas-sktm')
|
||||
->preserveFilenames()
|
||||
->required()
|
||||
->acceptedFileTypes(['application/pdf']),
|
||||
|
||||
FileUpload::make('berkas_ppke')
|
||||
->label('Upload PPKE')
|
||||
->helperText('Pernyataan Penghasilan Keluarga')
|
||||
->directory('berkas-ppke')
|
||||
->preserveFilenames()
|
||||
->acceptedFileTypes(['application/pdf']),
|
||||
|
||||
FileUpload::make('berkas_pmk')
|
||||
->label('Upload PMK')
|
||||
->helperText('Pernyataan Mahasiswa Kurang Mampu')
|
||||
->directory('berkas-pmk')
|
||||
->preserveFilenames()
|
||||
->acceptedFileTypes(['application/pdf']),
|
||||
|
||||
FileUpload::make('berkas_pkh')
|
||||
->label('Upload PKH')
|
||||
->helperText('Kartu Program Keluarga Harapan')
|
||||
->directory('berkas-pkh')
|
||||
->preserveFilenames()
|
||||
->acceptedFileTypes(['application/pdf']),
|
||||
|
||||
FileUpload::make('berkas_kks')
|
||||
->label('Upload KKS')
|
||||
->helperText('Kartu Keluarga Sejahtera')
|
||||
->directory('berkas-kks')
|
||||
->preserveFilenames()
|
||||
->acceptedFileTypes(['application/pdf']),
|
||||
]),
|
||||
])
|
||||
->submitAction(
|
||||
\Filament\Forms\Components\Actions\Action::make('submit')
|
||||
->label('Submit')
|
||||
->submit('submit')
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getFormActions(): array
|
||||
{
|
||||
return [
|
||||
\Filament\Forms\Components\Actions\Action::make('submit')
|
||||
->label('Submit')
|
||||
->action('submit')
|
||||
->submit()
|
||||
];
|
||||
}
|
||||
|
||||
public function submit()
|
||||
{
|
||||
// Validasi form
|
||||
$data = $this->form->getState();
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
// Simpan data mahasiswa
|
||||
$mahasiswa = Mahasiswa::create([
|
||||
'noreg_kipk' => $data['noreg_kipk'],
|
||||
'nama' => $data['nama'],
|
||||
'nim' => $data['nim'],
|
||||
'jurusan' => $data['jurusan'],
|
||||
'prodi' => $data['prodi'],
|
||||
'angkatan' => $data['angkatan'],
|
||||
'semester' => $data['semester'],
|
||||
'jalur_masuk' => $data['jalur_masuk'],
|
||||
'ponsel' => $data['ponsel'],
|
||||
'alamat' => $data['alamat'],
|
||||
]);
|
||||
|
||||
// Simpan data listform
|
||||
Listform::create([
|
||||
'mahasiswa_id' => $mahasiswa->id,
|
||||
'kepemilikan_kip' => $data['kepemilikan_kip'],
|
||||
'tingkatan_desil' => $data['tingkatan_desil'],
|
||||
'berkas_sktm' => $data['berkas_sktm'],
|
||||
'berkas_ppke' => $data['berkas_ppke'],
|
||||
'berkas_pmk' => $data['berkas_pmk'],
|
||||
'berkas_pkh' => $data['berkas_pkh'],
|
||||
'berkas_kks' => $data['berkas_kks'],
|
||||
'status' => 'submitted',
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('Berhasil')
|
||||
->body('Data berhasil disimpan')
|
||||
->send();
|
||||
|
||||
$this->form->fill(); // Reset form
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('Error')
|
||||
->body('Terjadi kesalahan: ' . $e->getMessage())
|
||||
->send();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
<x-filament::page>
|
||||
{{ $this->form }}
|
||||
</x-filament::page>
|
|
@ -7,6 +7,7 @@
|
|||
use App\Models\Formulir;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
|
@ -15,6 +16,7 @@
|
|||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Actions\Action;
|
||||
|
||||
class FormulirResource extends Resource
|
||||
{
|
||||
|
@ -35,7 +37,12 @@ public static function form(Form $form): Form
|
|||
->label('Tanggal')
|
||||
->required(),
|
||||
TextInput::make('kuota'),
|
||||
TextInput::make('status')
|
||||
Select::make('status')
|
||||
->options([
|
||||
'dibuka' => 'Dibuka',
|
||||
'ditutup' => 'Ditutup'
|
||||
])
|
||||
->default('dibuka')
|
||||
->required(),
|
||||
]);
|
||||
}
|
||||
|
@ -48,12 +55,27 @@ public static function table(Table $table): Table
|
|||
TextColumn::make('tgl_pembuatan')
|
||||
->label('Tanggal'),
|
||||
TextColumn::make('kuota'),
|
||||
TextColumn::make('status'),
|
||||
TextColumn::make('status')
|
||||
->badge()
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'dibuka' => 'success',
|
||||
'ditutup' => 'danger',
|
||||
default => 'gray',
|
||||
}),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Action::make('toggleStatus')
|
||||
->label(fn (Formulir $record): string => $record->status === 'dibuka' ? 'Tutup' : 'Buka')
|
||||
->icon(fn (Formulir $record): string => $record->status === 'dibuka' ? 'heroicon-o-x-circle' : 'heroicon-o-check-circle')
|
||||
->color(fn (Formulir $record): string => $record->status === 'dibuka' ? 'danger' : 'success')
|
||||
->action(function (Formulir $record): void {
|
||||
$record->update([
|
||||
'status' => $record->status === 'dibuka' ? 'ditutup' : 'dibuka'
|
||||
]);
|
||||
}),
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\HasilResource\Pages;
|
||||
use App\Filament\Resources\HasilResource\RelationManagers;
|
||||
use App\Models\Hasil;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
|
||||
class HasilResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Hasil::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
protected static ?string $navigationGroup = 'Penilaian';
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Select::make('mahasiswa_id')
|
||||
->label('Mahasiswa')
|
||||
->relationship('mahasiswa', 'nama')
|
||||
->searchable()
|
||||
->required(),
|
||||
|
||||
TextInput::make('total_bobot')
|
||||
->label('Total Bobot')
|
||||
->numeric()
|
||||
->readOnly(),
|
||||
|
||||
Select::make('status')
|
||||
->label('Status')
|
||||
->options([
|
||||
'Layak' => 'Layak',
|
||||
'Dipertimbangkan' => 'Dipertimbangkan',
|
||||
'Tidak Layak' => 'Tidak Layak',
|
||||
])
|
||||
->required(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('mahasiswa.nama')
|
||||
->label('Nama Mahasiswa')
|
||||
->sortable()
|
||||
->searchable(),
|
||||
|
||||
TextColumn::make('total_bobot')
|
||||
->label('Total Bobot')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('status')
|
||||
->label('Status')
|
||||
->badge()
|
||||
->color(fn ($record) => match ($record->status) {
|
||||
'Layak' => 'success',
|
||||
'Dipertimbangkan' => 'warning',
|
||||
'Tidak Layak' => 'danger',
|
||||
}),
|
||||
|
||||
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListHasils::route('/'),
|
||||
'create' => Pages\CreateHasil::route('/create'),
|
||||
'edit' => Pages\EditHasil::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\HasilResource\Pages;
|
||||
|
||||
use App\Filament\Resources\HasilResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateHasil extends CreateRecord
|
||||
{
|
||||
protected static string $resource = HasilResource::class;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\HasilResource\Pages;
|
||||
|
||||
use App\Filament\Resources\HasilResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditHasil extends EditRecord
|
||||
{
|
||||
protected static string $resource = HasilResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\HasilResource\Pages;
|
||||
|
||||
use App\Filament\Resources\HasilResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListHasils extends ListRecords
|
||||
{
|
||||
protected static string $resource = HasilResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
|
@ -2,13 +2,17 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class formulir extends Model
|
||||
class Formulir extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'tgl_pembuatan' => 'date',
|
||||
'status' => 'string'
|
||||
];
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class hasil extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['mahasiswa_id', 'total_bobot', 'status'];
|
||||
|
||||
public function mahasiswa()
|
||||
{
|
||||
return $this->belongsTo(mahasiswa::class);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('hasils', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('mahasiswa_id')->constrained('mahasiswas')->onDelete('cascade'); // Relasi ke tabel mahasiswa
|
||||
$table->decimal('total_bobot', 5, 2); // Skor akhir hasil perhitungan SMARTER
|
||||
$table->enum('status', ['Layak','Dipertimbangkan', 'Tidak Layak'])->default('Tidak Layak'); // Status keputusan
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('hasils');
|
||||
}
|
||||
};
|
|
@ -14,9 +14,9 @@ public function up(): void
|
|||
Schema::create('formulirs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('nama');
|
||||
$table->datetime('tgl_pembuatan');
|
||||
$table->string('kuota');
|
||||
$table->string('status');
|
||||
$table->date('tgl_pembuatan');
|
||||
$table->string('kuota')->nullable();
|
||||
$table->enum('status', ['dibuka', 'ditutup'])->default('dibuka');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
@ -28,4 +28,4 @@ public function down(): void
|
|||
{
|
||||
Schema::dropIfExists('formulirs');
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
<x-filament-panels::page>
|
||||
<form wire:submit.prevent="submit">
|
||||
{{ $this->form }}
|
||||
</form>
|
||||
</x-filament-panels::page>
|
Loading…
Reference in New Issue