diff --git a/app/Filament/Resources/TrTransaksiResource.php b/app/Filament/Resources/TrTransaksiResource.php index ce28b96..67efc71 100644 --- a/app/Filament/Resources/TrTransaksiResource.php +++ b/app/Filament/Resources/TrTransaksiResource.php @@ -9,8 +9,13 @@ use App\Models\MsTindakan; use App\Models\TrRegistrasi; use App\Models\TrTransaksi; use Filament\Forms; +use Filament\Forms\Components\Placeholder; +use Filament\Forms\Components\Section; +use Filament\Forms\Components\TextInput; use Filament\Forms\Form; +use Filament\Forms\Get; use Filament\Resources\Resource; +use Filament\Support\RawJs; use Filament\Tables; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Table; @@ -35,18 +40,48 @@ class TrTransaksiResource extends Resource ->label('Registrasi') ->options(TrRegistrasi::all()->pluck('id_registrasi', 'id_registrasi')) ->searchable() + ->live() ->required(), + Forms\Components\Select::make('id_tindakan') ->label('Tindakan') ->options(MsTindakan::all()->pluck('nama_tindakan', 'id_tindakan')) ->searchable() ->multiple() - ->required(), + ->required() + ->live(), Forms\Components\Select::make('id_pegawai') ->label('Pegawai') ->options(MsPegawai::all()->pluck('nama_pegawai', 'id_pegawai')) ->searchable() ->required(), + + Forms\Components\Select::make('status') + ->label('Status') + ->options([ + 'pending' => 'Pending', + 'paid' => 'Paid', + 'cancelled' => 'Cancelled', + ]) + ->required(), + Section::make('Detail Tindakan') + ->schema([ + Placeholder::make('') + ->content(function (Get $get) { + // get registrasi by id_registrasi + $registrasi = TrRegistrasi::find($get('id_registrasi')); + // get tindakan by id_tindakan + $tindakan = MsTindakan::find($get('id_tindakan')); + return view('components.transactions.invoice-info', ['data' => $tindakan, 'registrasi' => $registrasi]); + }) + ]) + ->visible(function (Get $get) { + // if id_registrasi and id_tindakan is not empty + if ($get('id_registrasi') != "" && count($get('id_tindakan')) > 0) { + return true; + } + return false; + }), // ]); } @@ -55,14 +90,29 @@ class TrTransaksiResource extends Resource { return $table ->defaultSort('created_at', 'desc') + ->searchable() ->columns([ - TextColumn::make('id_transaksi')->label('ID Transaksi'), + TextColumn::make('id_transaksi')->label('ID Transaksi') + ->searchable(), TextColumn::make('id_registrasi')->label('Registrasi') ->url(fn($record) => TrRegistrasiResource::getUrl('view', ['record' => $record->id_registrasi])) - ->openUrlInNewTab(), + ->openUrlInNewTab() + ->searchable(), TextColumn::make('id_tindakan')->label('Tindakan') - ->wrap(), - TextColumn::make('id_pegawai')->label('Pegawai'), + ->wrap() + ->searchable(), + TextColumn::make('total_harga')->label('Total Harga') + ->money('IDR'), + TextColumn::make('status')->label('Status') + ->badge() + ->color(fn($state) => match ($state) { + 'pending' => 'warning', + 'paid' => 'success', + 'cancelled' => 'danger', + }), + TextColumn::make('id_pegawai')->label('Pegawai') + ->url(fn($record) => MsPegawaiResource::getUrl('view', ['record' => $record->id_pegawai])) + ->openUrlInNewTab(), TextColumn::make('created_at')->label('Tanggal Dibuat'), ]) ->filters([ @@ -72,6 +122,18 @@ class TrTransaksiResource extends Resource Tables\Actions\ViewAction::make(), // Tables\Actions\EditAction::make(), Tables\Actions\DeleteAction::make(), + // mark as paid + Tables\Actions\Action::make('markAsPaid') + ->requiresConfirmation() + ->label('Tandai Sebagai Lunas') + ->icon('heroicon-o-check-circle') + ->color('success') + ->action(function ($record) { + $record->status = 'paid'; + $record->save(); + })->visible(function ($record) { + return $record->status == 'pending'; + }), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ diff --git a/app/Filament/Resources/TrTransaksiResource/Pages/CreateTrTransaksi.php b/app/Filament/Resources/TrTransaksiResource/Pages/CreateTrTransaksi.php index a2f0fd9..f645c10 100644 --- a/app/Filament/Resources/TrTransaksiResource/Pages/CreateTrTransaksi.php +++ b/app/Filament/Resources/TrTransaksiResource/Pages/CreateTrTransaksi.php @@ -3,10 +3,26 @@ namespace App\Filament\Resources\TrTransaksiResource\Pages; use App\Filament\Resources\TrTransaksiResource; +use App\Models\MsTindakan; use Filament\Actions; use Filament\Resources\Pages\CreateRecord; class CreateTrTransaksi extends CreateRecord { protected static string $resource = TrTransaksiResource::class; + protected static ?string $title = 'Tambah Transaksi'; + + + // mutate form data before create + protected function mutateFormDataBeforeCreate(array $data): array + { + $data['total_harga'] = 0; + foreach ($data['id_tindakan'] as $tindakan) { + // find tindakan by id + $tindakan = MsTindakan::find($tindakan); + // add total harga to data + $data['total_harga'] += $tindakan->tarif_tindakan; + } + return $data; + } } diff --git a/app/Filament/Resources/TrTransaksiResource/Pages/ListTrTransaksis.php b/app/Filament/Resources/TrTransaksiResource/Pages/ListTrTransaksis.php index cc6eca6..3aeb5b1 100644 --- a/app/Filament/Resources/TrTransaksiResource/Pages/ListTrTransaksis.php +++ b/app/Filament/Resources/TrTransaksiResource/Pages/ListTrTransaksis.php @@ -9,6 +9,7 @@ use Filament\Resources\Pages\ListRecords; class ListTrTransaksis extends ListRecords { protected static string $resource = TrTransaksiResource::class; + protected static ?string $title = 'Daftar Transaksi'; protected function getHeaderActions(): array { diff --git a/app/Filament/Resources/TrTransaksiResource/Pages/ViewTrTransaksi.php b/app/Filament/Resources/TrTransaksiResource/Pages/ViewTrTransaksi.php index c17de3e..42477d3 100644 --- a/app/Filament/Resources/TrTransaksiResource/Pages/ViewTrTransaksi.php +++ b/app/Filament/Resources/TrTransaksiResource/Pages/ViewTrTransaksi.php @@ -9,11 +9,23 @@ use Filament\Resources\Pages\ViewRecord; class ViewTrTransaksi extends ViewRecord { protected static string $resource = TrTransaksiResource::class; + protected static ?string $title = 'Detail Transaksi'; protected function getHeaderActions(): array { return [ // Actions\EditAction::make(), + Actions\Action::make('markAsPaid') + ->requiresConfirmation() + ->label('Tandai Sebagai Lunas') + ->icon('heroicon-o-check-circle') + ->color('success') + ->action(function ($record) { + $record->status = 'paid'; + $record->save(); + })->visible(function ($record) { + return $record->status == 'pending'; + }), ]; } } diff --git a/app/Models/TrTransaksi.php b/app/Models/TrTransaksi.php index 3939bd3..fcdc7bc 100644 --- a/app/Models/TrTransaksi.php +++ b/app/Models/TrTransaksi.php @@ -39,4 +39,9 @@ class TrTransaksi extends Model { return $this->belongsTo(MsPegawai::class, 'id_pegawai', 'id_pegawai'); } + + public function getPasienAttribute() + { + return $this->registrasi->pasien; + } } diff --git a/database/migrations/2025_04_26_072441_tr_transaksi.php b/database/migrations/2025_04_26_072441_tr_transaksi.php index ac64a3d..bc567d1 100644 --- a/database/migrations/2025_04_26_072441_tr_transaksi.php +++ b/database/migrations/2025_04_26_072441_tr_transaksi.php @@ -17,6 +17,9 @@ return new class extends Migration // id tindakan as array cause has multiple tindakan $table->json('id_tindakan'); $table->string('id_pegawai'); + $table->decimal('total_harga', 15, 2); + $table->enum('status', ['pending', 'paid', 'cancelled'])->default('pending'); + $table->string('keterangan')->nullable(); $table->timestamps(); $table->foreign('id_registrasi')->references('id_registrasi')->on('tr_registrasi'); diff --git a/database/seeders/TransaksiSeed.php b/database/seeders/TransaksiSeed.php index fae7990..0768754 100644 --- a/database/seeders/TransaksiSeed.php +++ b/database/seeders/TransaksiSeed.php @@ -37,6 +37,9 @@ class TransaksiSeed extends Seeder 'id_registrasi' => TrRegistrasi::all()->random()->id_registrasi, 'id_tindakan' => $id_tindakan[array_rand($id_tindakan)], 'id_pegawai' => MsPegawai::all()->random()->id_pegawai, + 'total_harga' => $faker->randomFloat(2, 50000, 500000), + 'status' => 'pending', + 'keterangan' => $faker->sentence, 'created_at' => now(), 'updated_at' => now(), ]); diff --git a/resources/views/components/transactions/invoice-info.blade.php b/resources/views/components/transactions/invoice-info.blade.php new file mode 100644 index 0000000..af035e6 --- /dev/null +++ b/resources/views/components/transactions/invoice-info.blade.php @@ -0,0 +1,86 @@ + + + +{{-- Informasi pasien --}} + + +{{-- table non border --}} + + + + + + + + + + + + + + + + + + + + + + + + + +
Nama Pasien{{ $registrasi->pasien->nama }}
NIK{{ $registrasi->pasien->nik }}
Tanggal Lahir{{ $registrasi->pasien->tgl_lahir }}
Jenis Kelamin{{ $registrasi->pasien->jenis_kelamin }}
Alamat{{ $registrasi->pasien->alamat }}
No. HP{{ $registrasi->pasien->no_hp }}
+ +{{-- Informasi tindakan --}} +@php + $total = 0; +@endphp + + + + + + @foreach ($data as $tindakan) + @php + $total += $tindakan->tarif_tindakan; + @endphp + + + + + @endforeach + {{-- total --}} + + + + + +
Nama TindakanHarga
{{ $tindakan->nama_tindakan }}Rp. {{ number_format($tindakan->tarif_tindakan, 0, ',', '.') }},-
TotalRp. {{ number_format($total, 0, ',', '.') }},-
+ + + +