feat: add detail transactions registration
This commit is contained in:
parent
fc41a62b2e
commit
4b3ffb10ff
@ -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.');
|
||||
}
|
||||
}
|
||||
|
||||
@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,11 +56,13 @@
|
||||
<td>{{ $data->user->name }}</td>
|
||||
<td>{{ $data->created_at }}</td>
|
||||
<td>
|
||||
<a href="{{ route('transaction.index', $data->id) }}" class="btn btn-sm btn-info">
|
||||
<i class="fas fa-money-bill"></i> Transaksi
|
||||
</a>
|
||||
<a href="{{ route('patient-registration.edit', $data->id) }}"
|
||||
class="btn btn-sm btn-warning">
|
||||
<i class="fas fa-pencil-alt"></i> Edit
|
||||
</a>
|
||||
|
||||
<button type="button" class="btn btn-sm btn-danger delete-btn"
|
||||
data-url="{{ route('patient-registration.destroy', $data->id) }}">
|
||||
<i class="fas fa-trash"></i> Hapus
|
||||
|
||||
345
resources/views/registration/transaction/index.blade.php
Normal file
345
resources/views/registration/transaction/index.blade.php
Normal file
@ -0,0 +1,345 @@
|
||||
@push('styles')
|
||||
<!-- DataTables -->
|
||||
<link rel="stylesheet" href="{{ asset('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css') }}">
|
||||
<link rel="stylesheet" href="{{ asset('plugins/datatables-responsive/css/responsive.bootstrap4.min.css') }}">
|
||||
<link rel="stylesheet" href="{{ asset('plugins/datatables-buttons/css/buttons.bootstrap4.min.css') }}">
|
||||
@endpush
|
||||
|
||||
@extends('layouts.app')
|
||||
@section('content-header')
|
||||
<div class="content-header">
|
||||
<div class="container-fluid">
|
||||
<div class="row mb-2">
|
||||
<div class="col-sm-6">
|
||||
<h1 class="m-0">Detail Transaksi Registrasi</h1>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<ol class="breadcrumb float-sm-right">
|
||||
<li class="breadcrumb-item"><a href="#">Home</a></li>
|
||||
<li class="breadcrumb-item active">Detail Transaksi</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@section('main-content')
|
||||
<div id="transaction_data">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card card-primary">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">Data Registrasi Pasien</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<!-- Left Column -->
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label>Tanggal Registrasi:</label>
|
||||
<p>{{ $registration->registration_date }}</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Pasien:</label>
|
||||
<p>{{ $registration->patient->first_name }} {{ $registration->patient->last_name }}</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Asuransi:</label>
|
||||
<p>{{ $registration->insurance->name }}</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>No. Asuransi:</label>
|
||||
<p>{{ $registration->insurance_number }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Middle Column -->
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label>Ruangan Layanan:</label>
|
||||
<p>{{ $registration->service_room->name }}</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Nama Penanggung Jawab:</label>
|
||||
<p>{{ $registration->responsible_person_name }}</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>No. HP Penanggung Jawab:</label>
|
||||
<p>{{ $registration->responsible_person_phone }}</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Email Penanggung Jawab:</label>
|
||||
<p>{{ $registration->responsible_email }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Right Column -->
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label>Hubungan dengan Pasien:</label>
|
||||
<p>{{ $registration->responsible_person_relationship }}</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Alamat Penanggung Jawab:</label>
|
||||
<p>{{ $registration->responsible_person_address }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<button class="btn btn-info" data-toggle="modal" data-target="#addTransactionModal">
|
||||
<i class="fas fa-plus"></i>
|
||||
Tambah Tindakan
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<table id="tableData" class="table table-bordered table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>No</th>
|
||||
<th>Tindakan</th>
|
||||
<th>Jumlah</th>
|
||||
<th>Fee Tindakan</th>
|
||||
<th>Total</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($transactions as $index => $data)
|
||||
<tr>
|
||||
<td>{{ $index + 1 }}</td>
|
||||
<td>{{ $data->treatment->name }}</td>
|
||||
<td>{{ $data->amount }}</td>
|
||||
<td>{{ number_format($data->treatment->fee, 0, ',', '.') }}</td>
|
||||
<td>{{ number_format($data->treatment->fee * $data->amount) }}</td>
|
||||
<td>
|
||||
<a href="#" class="btn btn-sm btn-warning edit-btn"
|
||||
data-url="{{ route('transaction.update', $data->id) }}"
|
||||
data-name="{{ $data->treatment_id }}" data-amount="{{ $data->amount }}"
|
||||
data-toggle="modal" data-target="#editTransactionModal">
|
||||
<i class="fas fa-pencil-alt"></i> Edit
|
||||
</a>
|
||||
<button type="button" class="btn btn-sm btn-danger delete-btn"
|
||||
data-url="{{ route('transaction.destroy', $data->id) }}"
|
||||
data-toggle="modal" data-target="#deleteTransactionModal">
|
||||
<i class="fas fa-trash"></i> Hapus
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-flex justify-content-end mt-3">
|
||||
<h5 class="font-weight-bold">
|
||||
Total Tindakan:
|
||||
{{ number_format(
|
||||
$transactions->sum(function ($transaction) {
|
||||
return $transaction->treatment->fee * $transaction->amount;
|
||||
}),
|
||||
0,
|
||||
',',
|
||||
'.',
|
||||
) }}
|
||||
</h5>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.card-body -->
|
||||
</div>
|
||||
|
||||
<!-- Modal Tambah Jenis Tindakan -->
|
||||
<div class="modal fade" id="addTransactionModal" tabindex="-1" aria-labelledby="addTransactionModalLabel"
|
||||
aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<form id="addTransactionForm" method="POST"
|
||||
action="{{ route('transaction.store', $registration->id) }}">
|
||||
@csrf
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="addTransactionModalLabel">Tambah Jenis Tindakan</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label for="TransactionName" class="form-label">Nama Jenis Tindakan</label>
|
||||
<select class="form-control" id="TransactionName" name="treatment_id" required>
|
||||
<option value="">-- Pilih Jenis Tindakan --</option>
|
||||
@foreach ($treatments as $treatment)
|
||||
<option value="{{ $treatment->id }}">{{ $treatment->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="TransactionAmount" class="form-label">Jumlah Tindakan</label>
|
||||
<input type="number" class="form-control" id="TransactionAmount" name="amount"
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
|
||||
<button type="submit" class="btn btn-primary">Simpan</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal Edit Jenis Tindakan -->
|
||||
<div class="modal fade" id="editTransactionModal" tabindex="-1"
|
||||
aria-labelledby="editTransactionModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<form id="editTransactionForm" method="POST">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="editTransactionModalLabel">Edit Jenis Tindakan</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label for="editTransactionName" class="form-label">Nama Jenis Tindakan</label>
|
||||
<select class="form-control" id="editTransactionName" name="treatment_id"
|
||||
required>
|
||||
<option value="">-- Pilih Jenis Tindakan --</option>
|
||||
@foreach ($treatments as $treatment)
|
||||
<option value="{{ $treatment->id }}">{{ $treatment->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="editTransactionAmount" class="form-label">Jumlah Tindakan</label>
|
||||
<input type="number" class="form-control" id="editTransactionAmount"
|
||||
name="amount" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
|
||||
<button type="submit" class="btn btn-primary">Update</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal Konfirmasi Hapus -->
|
||||
<div class="modal fade" id="deleteTransactionModal" tabindex="-1"
|
||||
aria-labelledby="deleteTransactionModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="deleteTransactionModalLabel">Hapus Jenis Tindakan</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
Apakah Anda yakin ingin menghapus jenis Tindakan ini?
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
|
||||
<form id="deleteForm" action="" method="POST">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="btn btn-danger">Hapus</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row mb-2">
|
||||
<div class="col-12">
|
||||
<button class="btn btn-primary">
|
||||
<i class="fas fa-envelope"></i> Kirim Tagihan
|
||||
</button>
|
||||
<a href="{{ route('patient-registration.index') }}" class="btn btn-secondary">Kembali</a>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
@if (session('success'))
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
Toast.fire({
|
||||
icon: 'success',
|
||||
title: "{{ session('success') }}",
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endif
|
||||
@if (session('error'))
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
Toast.fire({
|
||||
icon: 'error',
|
||||
title: "{{ session('error') }}",
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endif
|
||||
|
||||
<script src="{{ asset('plugins/datatables/jquery.dataTables.min.js') }}"></script>
|
||||
<script src="{{ asset('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js') }}"></script>
|
||||
<script src="{{ asset('plugins/datatables-responsive/js/dataTables.responsive.min.js') }}"></script>
|
||||
<script src="{{ asset('plugins/datatables-responsive/js/responsive.bootstrap4.min.js') }}"></script>
|
||||
|
||||
<script>
|
||||
$(function() {
|
||||
$("#tableData").DataTable({
|
||||
"paging": false,
|
||||
"lengthChange": false,
|
||||
"searching": false,
|
||||
"ordering": true,
|
||||
"info": false,
|
||||
"autoWidth": false,
|
||||
"responsive": true,
|
||||
});
|
||||
|
||||
// Edit Document Type
|
||||
const editButtons = document.querySelectorAll('.edit-btn');
|
||||
const editModal = document.getElementById('editTransactionModal');
|
||||
const editForm = document.getElementById('editTransactionForm');
|
||||
|
||||
editButtons.forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
const url = this.getAttribute('data-url');
|
||||
const name = this.getAttribute('data-name');
|
||||
const amount = this.getAttribute('data-amount');
|
||||
|
||||
editForm.setAttribute('action', url);
|
||||
document.getElementById('editTransactionName').value = name;
|
||||
document.getElementById('editTransactionAmount').value = amount;
|
||||
|
||||
$(editModal).modal('show'); // Use jQuery to show the modal
|
||||
});
|
||||
});
|
||||
|
||||
// Delete Document Type
|
||||
const deleteButtons = document.querySelectorAll('.delete-btn');
|
||||
const deleteModal = document.getElementById('deleteTransactionModal');
|
||||
const deleteForm = document.getElementById('deleteForm');
|
||||
|
||||
deleteButtons.forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
const url = this.getAttribute('data-url');
|
||||
deleteForm.setAttribute('action', url);
|
||||
$(deleteModal).modal('show'); // Use jQuery to show the modal
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
@ -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');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user