diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index 3d19ebd..45fb878 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -2,9 +2,72 @@ namespace App\Http\Controllers; +use App\Models\PatienRegistration; +use App\Models\Transaction; +use App\Models\Treatment; use Illuminate\Http\Request; class TransactionController extends Controller { - // + public function index($id) + { + // Fetch the registration data with related models + $registration = PatienRegistration::with(['patient', 'insurance', 'service_room'])->where('id', $id)->first(); + $transactions = Transaction::with(['treatment']) + ->where('patien_registration_id', $id) + ->get(); + $treatments = Treatment::all(); + + // Pass the data to the view + return view('registration.transaction.index', compact('registration', 'transactions', 'treatments')); + } + + public function store(Request $request, $id) + { + // Validate the request data + $validatedData = $request->validate([ + 'treatment_id' => 'required|exists:treatments,id', + 'amount' => 'required|numeric|min:0', + ]); + + // Create a new transaction + Transaction::create([ + 'patien_registration_id' => $id, + 'treatment_id' => $validatedData['treatment_id'], + 'amount' => $validatedData['amount'], + 'user_id' => auth()->user()->id, + ]); + + // Redirect back with a success message + return redirect()->back()->with('success', 'Transaction created successfully.'); + } + + public function update(Request $request, $transId) + { + // Validate the request data + $validatedData = $request->validate([ + 'treatment_id' => 'required|exists:treatments,id', + 'amount' => 'required|numeric|min:0', + ]); + + // Find the transaction and update it + $transaction = Transaction::findOrFail($transId); + $transaction->update([ + 'treatment_id' => $validatedData['treatment_id'], + 'amount' => $validatedData['amount'], + ]); + + // Redirect back with a success message + return redirect()->back()->with('success', 'Transaction updated successfully.'); + } + + public function destroy($transId) + { + // Find the transaction and delete it + $transaction = Transaction::findOrFail($transId); + $transaction->delete(); + + // Redirect back with a success message + return redirect()->back()->with('success', 'Transaction deleted successfully.'); + } } diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 6c595d4..bdcd447 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -9,4 +9,12 @@ use Illuminate\Database\Eloquent\SoftDeletes; class Transaction extends Model { use HasFactory, SoftDeletes; + + protected $table = "transactions"; + protected $guarded = ["id"]; + + public function treatment() + { + return $this->belongsTo(Treatment::class, 'treatment_id'); + } } diff --git a/resources/views/registration/index.blade.php b/resources/views/registration/index.blade.php index ba91af3..f4cabd9 100644 --- a/resources/views/registration/index.blade.php +++ b/resources/views/registration/index.blade.php @@ -56,11 +56,13 @@ {{ $data->user->name }} {{ $data->created_at }} + +   Transaksi +   Edit - + +
+ + + + + + + + + + + + + @foreach ($transactions as $index => $data) + + + + + + + + + @endforeach + +
NoTindakanJumlahFee TindakanTotalAction
{{ $index + 1 }}{{ $data->treatment->name }}{{ $data->amount }}{{ number_format($data->treatment->fee, 0, ',', '.') }}{{ number_format($data->treatment->fee * $data->amount) }} + +   Edit + + +
+
+
+ Total Tindakan: + {{ number_format( + $transactions->sum(function ($transaction) { + return $transaction->treatment->fee * $transaction->amount; + }), + 0, + ',', + '.', + ) }} +
+
+
+ + + + + + + + + + + + + + + + +
+
+ + Kembali +
+
+@endsection + +@push('scripts') + @if (session('success')) + + @endif + @if (session('error')) + + @endif + + + + + + + +@endpush diff --git a/routes/web.php b/routes/web.php index b739de3..3e61a00 100644 --- a/routes/web.php +++ b/routes/web.php @@ -8,6 +8,7 @@ use App\Http\Controllers\InsuranceController; use App\Http\Controllers\PatienRegistrationController; use App\Http\Controllers\PatientController; use App\Http\Controllers\ServiceRoomController; +use App\Http\Controllers\TransactionController; use App\Http\Controllers\TreatmentController; use Illuminate\Support\Facades\Route; @@ -87,6 +88,13 @@ Route::middleware('auth')->group(function () { Route::put('/registrasi-pasien/{id}', [PatienRegistrationController::class, 'update'])->name('patient-registration.update'); Route::delete('/registrasi-pasien/{id}', [PatienRegistrationController::class, 'destroy'])->name('patient-registration.destroy'); + # Manage Transaksi + Route::get('/registrasi-pasien/{id}/transaksi/', [TransactionController::class, 'index'])->name('transaction.index'); + Route::post('/registrasi-pasien/{id}/transaksi', [TransactionController::class, 'store'])->name('transaction.store'); + + Route::put('/transaksi/{transId}', [TransactionController::class, 'update'])->name('transaction.update'); + Route::delete('/transaksi/{transId}', [TransactionController::class, 'destroy'])->name('transaction.destroy'); + // Profile Page Route::get('/profil-akun', [ProfileController::class, 'edit'])->name('profile.edit'); Route::put('/profil-akun', [ProfileController::class, 'update'])->name('profile.update');