feat: trx detail
This commit is contained in:
parent
da7b37e83c
commit
f1b619c154
@ -9,8 +9,13 @@ use App\Models\MsTindakan;
|
|||||||
use App\Models\TrRegistrasi;
|
use App\Models\TrRegistrasi;
|
||||||
use App\Models\TrTransaksi;
|
use App\Models\TrTransaksi;
|
||||||
use Filament\Forms;
|
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\Form;
|
||||||
|
use Filament\Forms\Get;
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Support\RawJs;
|
||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
use Filament\Tables\Columns\TextColumn;
|
use Filament\Tables\Columns\TextColumn;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
@ -35,18 +40,48 @@ class TrTransaksiResource extends Resource
|
|||||||
->label('Registrasi')
|
->label('Registrasi')
|
||||||
->options(TrRegistrasi::all()->pluck('id_registrasi', 'id_registrasi'))
|
->options(TrRegistrasi::all()->pluck('id_registrasi', 'id_registrasi'))
|
||||||
->searchable()
|
->searchable()
|
||||||
|
->live()
|
||||||
->required(),
|
->required(),
|
||||||
|
|
||||||
Forms\Components\Select::make('id_tindakan')
|
Forms\Components\Select::make('id_tindakan')
|
||||||
->label('Tindakan')
|
->label('Tindakan')
|
||||||
->options(MsTindakan::all()->pluck('nama_tindakan', 'id_tindakan'))
|
->options(MsTindakan::all()->pluck('nama_tindakan', 'id_tindakan'))
|
||||||
->searchable()
|
->searchable()
|
||||||
->multiple()
|
->multiple()
|
||||||
->required(),
|
->required()
|
||||||
|
->live(),
|
||||||
Forms\Components\Select::make('id_pegawai')
|
Forms\Components\Select::make('id_pegawai')
|
||||||
->label('Pegawai')
|
->label('Pegawai')
|
||||||
->options(MsPegawai::all()->pluck('nama_pegawai', 'id_pegawai'))
|
->options(MsPegawai::all()->pluck('nama_pegawai', 'id_pegawai'))
|
||||||
->searchable()
|
->searchable()
|
||||||
->required(),
|
->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
|
return $table
|
||||||
->defaultSort('created_at', 'desc')
|
->defaultSort('created_at', 'desc')
|
||||||
|
->searchable()
|
||||||
->columns([
|
->columns([
|
||||||
TextColumn::make('id_transaksi')->label('ID Transaksi'),
|
TextColumn::make('id_transaksi')->label('ID Transaksi')
|
||||||
|
->searchable(),
|
||||||
TextColumn::make('id_registrasi')->label('Registrasi')
|
TextColumn::make('id_registrasi')->label('Registrasi')
|
||||||
->url(fn($record) => TrRegistrasiResource::getUrl('view', ['record' => $record->id_registrasi]))
|
->url(fn($record) => TrRegistrasiResource::getUrl('view', ['record' => $record->id_registrasi]))
|
||||||
->openUrlInNewTab(),
|
->openUrlInNewTab()
|
||||||
|
->searchable(),
|
||||||
TextColumn::make('id_tindakan')->label('Tindakan')
|
TextColumn::make('id_tindakan')->label('Tindakan')
|
||||||
->wrap(),
|
->wrap()
|
||||||
TextColumn::make('id_pegawai')->label('Pegawai'),
|
->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'),
|
TextColumn::make('created_at')->label('Tanggal Dibuat'),
|
||||||
])
|
])
|
||||||
->filters([
|
->filters([
|
||||||
@ -72,6 +122,18 @@ class TrTransaksiResource extends Resource
|
|||||||
Tables\Actions\ViewAction::make(),
|
Tables\Actions\ViewAction::make(),
|
||||||
// Tables\Actions\EditAction::make(),
|
// Tables\Actions\EditAction::make(),
|
||||||
Tables\Actions\DeleteAction::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([
|
->bulkActions([
|
||||||
Tables\Actions\BulkActionGroup::make([
|
Tables\Actions\BulkActionGroup::make([
|
||||||
|
|||||||
@ -3,10 +3,26 @@
|
|||||||
namespace App\Filament\Resources\TrTransaksiResource\Pages;
|
namespace App\Filament\Resources\TrTransaksiResource\Pages;
|
||||||
|
|
||||||
use App\Filament\Resources\TrTransaksiResource;
|
use App\Filament\Resources\TrTransaksiResource;
|
||||||
|
use App\Models\MsTindakan;
|
||||||
use Filament\Actions;
|
use Filament\Actions;
|
||||||
use Filament\Resources\Pages\CreateRecord;
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
class CreateTrTransaksi extends CreateRecord
|
class CreateTrTransaksi extends CreateRecord
|
||||||
{
|
{
|
||||||
protected static string $resource = TrTransaksiResource::class;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ use Filament\Resources\Pages\ListRecords;
|
|||||||
class ListTrTransaksis extends ListRecords
|
class ListTrTransaksis extends ListRecords
|
||||||
{
|
{
|
||||||
protected static string $resource = TrTransaksiResource::class;
|
protected static string $resource = TrTransaksiResource::class;
|
||||||
|
protected static ?string $title = 'Daftar Transaksi';
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
{
|
{
|
||||||
|
|||||||
@ -9,11 +9,23 @@ use Filament\Resources\Pages\ViewRecord;
|
|||||||
class ViewTrTransaksi extends ViewRecord
|
class ViewTrTransaksi extends ViewRecord
|
||||||
{
|
{
|
||||||
protected static string $resource = TrTransaksiResource::class;
|
protected static string $resource = TrTransaksiResource::class;
|
||||||
|
protected static ?string $title = 'Detail Transaksi';
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
// Actions\EditAction::make(),
|
// 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';
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,4 +39,9 @@ class TrTransaksi extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(MsPegawai::class, 'id_pegawai', 'id_pegawai');
|
return $this->belongsTo(MsPegawai::class, 'id_pegawai', 'id_pegawai');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPasienAttribute()
|
||||||
|
{
|
||||||
|
return $this->registrasi->pasien;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,9 @@ return new class extends Migration
|
|||||||
// id tindakan as array cause has multiple tindakan
|
// id tindakan as array cause has multiple tindakan
|
||||||
$table->json('id_tindakan');
|
$table->json('id_tindakan');
|
||||||
$table->string('id_pegawai');
|
$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->timestamps();
|
||||||
|
|
||||||
$table->foreign('id_registrasi')->references('id_registrasi')->on('tr_registrasi');
|
$table->foreign('id_registrasi')->references('id_registrasi')->on('tr_registrasi');
|
||||||
|
|||||||
@ -37,6 +37,9 @@ class TransaksiSeed extends Seeder
|
|||||||
'id_registrasi' => TrRegistrasi::all()->random()->id_registrasi,
|
'id_registrasi' => TrRegistrasi::all()->random()->id_registrasi,
|
||||||
'id_tindakan' => $id_tindakan[array_rand($id_tindakan)],
|
'id_tindakan' => $id_tindakan[array_rand($id_tindakan)],
|
||||||
'id_pegawai' => MsPegawai::all()->random()->id_pegawai,
|
'id_pegawai' => MsPegawai::all()->random()->id_pegawai,
|
||||||
|
'total_harga' => $faker->randomFloat(2, 50000, 500000),
|
||||||
|
'status' => 'pending',
|
||||||
|
'keterangan' => $faker->sentence,
|
||||||
'created_at' => now(),
|
'created_at' => now(),
|
||||||
'updated_at' => now(),
|
'updated_at' => now(),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -0,0 +1,86 @@
|
|||||||
|
|
||||||
|
<style>
|
||||||
|
#tindakan_summary {
|
||||||
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
|
border-collapse: collapse;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#tindakan_summary td, #customers th {
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#tindakan_summary tr:nth-child(even){background-color: #f2f2f2;}
|
||||||
|
|
||||||
|
#tindakan_summary tr:hover {background-color: #ddd;}
|
||||||
|
|
||||||
|
#tindakan_summary th {
|
||||||
|
padding-top: 12px;
|
||||||
|
padding-bottom: 12px;
|
||||||
|
text-align: left;
|
||||||
|
background-color: #04AA6D;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
{{-- Informasi pasien --}}
|
||||||
|
|
||||||
|
|
||||||
|
{{-- table non border --}}
|
||||||
|
<table style="width: 100%; margin-bottom: 20px;">
|
||||||
|
<tr>
|
||||||
|
<td style="width: 50%;">Nama Pasien</td>
|
||||||
|
<td style="width: 50%;">{{ $registrasi->pasien->nama }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="width: 50%;">NIK</td>
|
||||||
|
<td style="width: 50%;">{{ $registrasi->pasien->nik }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="width: 50%;">Tanggal Lahir</td>
|
||||||
|
<td style="width: 50%;">{{ $registrasi->pasien->tgl_lahir }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="width: 50%;">Jenis Kelamin</td>
|
||||||
|
<td style="width: 50%;">{{ $registrasi->pasien->jenis_kelamin }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="width: 50%;">Alamat</td>
|
||||||
|
<td style="width: 50%;">{{ $registrasi->pasien->alamat }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="width: 50%;">No. HP</td>
|
||||||
|
<td style="width: 50%;">{{ $registrasi->pasien->no_hp }}</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{{-- Informasi tindakan --}}
|
||||||
|
@php
|
||||||
|
$total = 0;
|
||||||
|
@endphp
|
||||||
|
<table id="tindakan_summary">
|
||||||
|
<tr>
|
||||||
|
<td>Nama Tindakan</td>
|
||||||
|
<td>Harga</td>
|
||||||
|
</tr>
|
||||||
|
@foreach ($data as $tindakan)
|
||||||
|
@php
|
||||||
|
$total += $tindakan->tarif_tindakan;
|
||||||
|
@endphp
|
||||||
|
<tr>
|
||||||
|
<td>{{ $tindakan->nama_tindakan }}</td>
|
||||||
|
<td>Rp. {{ number_format($tindakan->tarif_tindakan, 0, ',', '.') }},-</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
{{-- total --}}
|
||||||
|
<tr>
|
||||||
|
<td><strong>Total</strong></td>
|
||||||
|
<td><strong>Rp. {{ number_format($total, 0, ',', '.') }},-</strong></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user