215 lines
6.8 KiB
PHP
215 lines
6.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\ServiceRoom;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Validation\Rule;
|
|
use Inertia\Inertia;
|
|
|
|
class ServiceRoomController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
$rooms = ServiceRoom::orderBy('created_at', 'desc')
|
|
->select([
|
|
'id',
|
|
'code',
|
|
'name',
|
|
'type',
|
|
'class',
|
|
'floor',
|
|
'building',
|
|
'capacity',
|
|
'price_per_day',
|
|
'is_available',
|
|
'is_active',
|
|
'created_at'
|
|
])
|
|
->paginate(10)
|
|
->through(function ($room) {
|
|
return [
|
|
'id' => $room->id,
|
|
'code' => $room->code,
|
|
'name' => $room->name,
|
|
'type' => $room->type_name,
|
|
'class' => $room->class_name,
|
|
'location' => implode(', ', array_filter([
|
|
$room->floor ? 'Lt. '.$room->floor : null,
|
|
$room->building,
|
|
$room->wing
|
|
])),
|
|
'capacity' => $room->capacity,
|
|
'price' => $room->price_per_day ? 'Rp. '.number_format($room->price_per_day, 2) : '-',
|
|
'status' => $room->is_available ? 'Tersedia' : 'Terpakai',
|
|
'is_active' => $room->is_active,
|
|
'created_at' => $room->created_at->format('d/m/Y H:i')
|
|
];
|
|
});
|
|
|
|
return Inertia::render('servicerooms/index', [
|
|
'rooms' => $rooms,
|
|
'status' => session('status')
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
return Inertia::render('servicerooms/form', [
|
|
'mode' => 'create',
|
|
'roomTypes' => ServiceRoom::getRoomTypes(),
|
|
'roomClasses' => ServiceRoom::getRoomClasses()
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$validated = $request->validate([
|
|
'code' => 'required|string|max:20|unique:m_service_room,code',
|
|
'name' => 'required|string|max:100',
|
|
'type' => [
|
|
'required',
|
|
Rule::in([
|
|
'Rawat Jalan',
|
|
'Rawat Inap',
|
|
'UGD',
|
|
'ICU',
|
|
'Bedah',
|
|
'Persalinan',
|
|
'Radiologi',
|
|
'Laboratorium',
|
|
'Farmasi',
|
|
'Lainnya'
|
|
])
|
|
],
|
|
'class' => [
|
|
'required',
|
|
Rule::in(['vip', 'class_1', 'class_2', 'class_3', 'standard', 'non_class'])
|
|
],
|
|
'floor' => 'nullable|string|max:10',
|
|
'building' => 'nullable|string|max:50',
|
|
'wing' => 'nullable|string|max:50',
|
|
'capacity' => 'required|integer|min:1',
|
|
'price_per_day' => 'nullable|numeric|min:0',
|
|
'facilities' => 'nullable|string',
|
|
'is_available' => 'required|boolean',
|
|
'is_active' => 'required|boolean'
|
|
]);
|
|
|
|
DB::transaction(function () use ($validated) {
|
|
ServiceRoom::create($validated);
|
|
});
|
|
|
|
return redirect()->route('room-services.index')
|
|
->with('status', 'Ruangan berhasil ditambahkan');
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(ServiceRoom $serviceRoom)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(ServiceRoom $serviceRoom)
|
|
{
|
|
return Inertia::render('servicerooms/form', [
|
|
'mode' => 'edit',
|
|
'room' => [
|
|
'id' => $serviceRoom->id,
|
|
'code' => $serviceRoom->code,
|
|
'name' => $serviceRoom->name,
|
|
'type' => $serviceRoom->type,
|
|
'class' => $serviceRoom->class,
|
|
'floor' => $serviceRoom->floor,
|
|
'building' => $serviceRoom->building,
|
|
'wing' => $serviceRoom->wing,
|
|
'capacity' => $serviceRoom->capacity,
|
|
'price_per_day' => $serviceRoom->price_per_day,
|
|
'facilities' => $serviceRoom->facilities,
|
|
'is_available' => $serviceRoom->is_available,
|
|
'is_active' => $serviceRoom->is_active
|
|
],
|
|
'roomTypes' => ServiceRoom::getRoomTypes(),
|
|
'roomClasses' => ServiceRoom::getRoomClasses()
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, ServiceRoom $serviceRoom)
|
|
{
|
|
$validated = $request->validate([
|
|
'code' => [
|
|
'required',
|
|
'string',
|
|
'max:20',
|
|
Rule::unique('m_service_room', 'code')->ignore($serviceRoom->id)
|
|
],
|
|
'name' => 'required|string|max:100',
|
|
'type' => [
|
|
'required',
|
|
Rule::in([
|
|
'Rawat Jalan',
|
|
'Rawat Inap',
|
|
'UGD',
|
|
'ICU',
|
|
'Bedah',
|
|
'Persalinan',
|
|
'Radiologi',
|
|
'Laboratorium',
|
|
'Farmasi',
|
|
'Lainnya'
|
|
])
|
|
],
|
|
'class' => [
|
|
'required',
|
|
Rule::in(['vip', 'class_1', 'class_2', 'class_3', 'standard', 'non_class'])
|
|
],
|
|
'floor' => 'nullable|string|max:10',
|
|
'building' => 'nullable|string|max:50',
|
|
'wing' => 'nullable|string|max:50',
|
|
'capacity' => 'required|integer|min:1',
|
|
'price_per_day' => 'nullable|numeric|min:0',
|
|
'facilities' => 'nullable|string',
|
|
'is_available' => 'required|boolean',
|
|
'is_active' => 'required|boolean'
|
|
]);
|
|
|
|
DB::transaction(function () use ($validated, $serviceRoom) {
|
|
$serviceRoom->update($validated);
|
|
});
|
|
|
|
return redirect()->route('room-services.index')
|
|
->with('status', 'Data ruangan berhasil diperbarui');
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(ServiceRoom $serviceRoom)
|
|
{
|
|
DB::transaction(function () use ($serviceRoom) {
|
|
$serviceRoom->delete();
|
|
});
|
|
|
|
return redirect()->route('room-services.index')
|
|
->with('status', 'Ruangan berhasil dihapus');
|
|
}
|
|
}
|