unduh excel & pdf laporan transaksi
This commit is contained in:
parent
2c9b99b40a
commit
83b76cd7af
33
app/Exports/TransaksiExport.php
Normal file
33
app/Exports/TransaksiExport.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Transaksi;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
class TransaksiExport implements FromCollection, WithStyles, ShouldAutoSize
|
||||
{
|
||||
protected $header;
|
||||
protected $data;
|
||||
|
||||
public function __construct(array $header, array $data)
|
||||
{
|
||||
$this->header = $header;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function collection()
|
||||
{
|
||||
return collect([$this->header])->merge($this->data);
|
||||
}
|
||||
|
||||
public function styles(Worksheet $sheet)
|
||||
{
|
||||
return [
|
||||
1 => ['font' => ['bold' => true]],
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -8,11 +8,10 @@ use App\Models\Pasien;
|
||||
use App\Models\Registrasi;
|
||||
use App\Models\RuangPelayanan;
|
||||
use App\Models\Tindakan;
|
||||
use Barryvdh\DomPDF\Facade\Pdf as FacadePdf;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use PDF;
|
||||
|
||||
class RegistrasiController extends Controller
|
||||
{
|
||||
@ -97,7 +96,7 @@ class RegistrasiController extends Controller
|
||||
{
|
||||
$registrasi = Registrasi::with(['pasien', 'asuransi', 'pegawai', 'ruangPelayanan'])->orderByDesc('id')->get();
|
||||
|
||||
$pdf = FacadePdf::loadview('module.registrasi.registrasi_pdf', ['registrasi' => $registrasi]);
|
||||
$pdf = Pdf::loadview('module.registrasi.registrasi_pdf', ['registrasi' => $registrasi]);
|
||||
$pdf->setPaper('A4');
|
||||
|
||||
return $pdf->stream('Data Regitrasi Pasien '.now().'.pdf');
|
||||
|
||||
@ -2,12 +2,15 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Exports\TransaksiExport;
|
||||
use App\Models\Asuransi;
|
||||
use App\Models\AsuransiTindakan;
|
||||
use App\Models\Registrasi;
|
||||
use App\Models\Tindakan;
|
||||
use App\Models\Transaksi;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class TransaksiController extends Controller
|
||||
{
|
||||
@ -49,4 +52,54 @@ class TransaksiController extends Controller
|
||||
|
||||
return redirect()->back()->with('message', 'Transaksi berhasil');
|
||||
}
|
||||
|
||||
public function laporan()
|
||||
{
|
||||
$transaksi = Transaksi::with(['registrasi', 'tindakan'])->orderByDesc('id')->get();
|
||||
|
||||
return view('module.transaksi.laporan', compact('transaksi'));
|
||||
}
|
||||
|
||||
public function excelExport()
|
||||
{
|
||||
$transaksi = Transaksi::with(['registrasi', 'tindakan'])->orderByDesc('id')->get();
|
||||
|
||||
$data = [];
|
||||
$no = 1;
|
||||
foreach ($transaksi as $trs) {
|
||||
$data[] = [
|
||||
'No' => $no++,
|
||||
'Tanggal' => date('d/m/Y', strtotime($trs->created_at)),
|
||||
'Nama Pasien' => $trs->registrasi->pasien->nama,
|
||||
'Nama Tindakan' => $trs->tindakan->nama,
|
||||
'Jumlah' => $trs->jml_tindakan,
|
||||
'Subtotal' => $trs->subtotal,
|
||||
'Potongan' => $trs->potongan,
|
||||
'Total' => $trs->total,
|
||||
];
|
||||
}
|
||||
|
||||
$header = [
|
||||
'No',
|
||||
'Tanggal',
|
||||
'Nama Pasien',
|
||||
'Nama Tindakan',
|
||||
'Jumlah',
|
||||
'Subtotal',
|
||||
'Potongan',
|
||||
'Total',
|
||||
];
|
||||
|
||||
return Excel::download(new TransaksiExport($header, $data), 'Data Transaksi Pasien '.now().'.xlsx');
|
||||
}
|
||||
|
||||
public function generatePdf()
|
||||
{
|
||||
$transaksi = Transaksi::with(['registrasi', 'tindakan'])->orderByDesc('id')->get();
|
||||
|
||||
$pdf = Pdf::loadview('module.transaksi.laporan_pdf', ['transaksi' => $transaksi]);
|
||||
$pdf->setPaper('A4');
|
||||
|
||||
return $pdf->stream('Data Transaksi Pasien '.now().'.pdf');
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,6 +89,15 @@
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a href="{{ route('transaksi.laporan') }}" class="nav-link {{ request()->is('/transaksi/laporan') ? 'active' : '' }}">
|
||||
<i class="nav-icon fas fa-tree"></i>
|
||||
<p>
|
||||
Laporan
|
||||
</p>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
{{-- For Access Superadmin --}}
|
||||
{{-- <li class="nav-item">
|
||||
<a href="#" class="nav-link">
|
||||
|
||||
66
resources/views/module/transaksi/laporan.blade.php
Normal file
66
resources/views/module/transaksi/laporan.blade.php
Normal file
@ -0,0 +1,66 @@
|
||||
@extends('layout.main')
|
||||
@section('content')
|
||||
<section class="content">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<a href="{{ route('transaksi.excel.export') }}" class="btn btn-success"><i class="fas fa-file-excel"></i>Unduh Excel</a>
|
||||
<a href="{{ route('transaksi.generate_pdf') }}" class="btn btn-danger"><i class="fas fa-file-pdf"></i>Unduh PDF</a>
|
||||
</div>
|
||||
<!-- /.card-header -->
|
||||
<div class="card-body">
|
||||
<table id="transaksi_tb" class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>No</th>
|
||||
<th>Tanggal</th>
|
||||
<th>Nama Pasien</th>
|
||||
<th>Nama Tindakan</th>
|
||||
<th>Jumlah</th>
|
||||
<th>Subtotal</th>
|
||||
<th>Potongan</th>
|
||||
<th>Total</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
$no = 1;
|
||||
@endphp
|
||||
@foreach ($transaksi as $data)
|
||||
<tr>
|
||||
<td>{{ $no++ }}</td>
|
||||
<td>{{ date('d/m/Y', strtotime($data->created_at)) }}</td>
|
||||
<td>{{ $data->registrasi->pasien->nama }}</td>
|
||||
<td>{{ $data->tindakan->nama }}</td>
|
||||
<td>{{ $data->jml_tindakan }}</td>
|
||||
<td>{{ $data->subtotal }}</td>
|
||||
<td>{{ $data->potongan }}</td>
|
||||
<td>{{ $data->total }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- /.card-body -->
|
||||
</div>
|
||||
<!-- /.card -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@push('script')
|
||||
<script>
|
||||
$(function () {
|
||||
$("#transaksi_tb").DataTable({
|
||||
"responsive": true,
|
||||
"lengthChange": false,
|
||||
"autoWidth": false,
|
||||
"ordering": false,
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
@endsection
|
||||
105
resources/views/module/transaksi/laporan_pdf.blade.php
Normal file
105
resources/views/module/transaksi/laporan_pdf.blade.php
Normal file
@ -0,0 +1,105 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Data Transaksi Pasien</title>
|
||||
<style>
|
||||
/* Gaya tabel */
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Gaya sel header */
|
||||
th {
|
||||
border-bottom: 1px solid black;
|
||||
text-align: left;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
/* Gaya sel data */
|
||||
td {
|
||||
border-bottom: 1px solid black;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
/* Gaya untuk border dalam horizontal */
|
||||
tr:nth-child(even) td {
|
||||
border-top: 1px solid black;
|
||||
}
|
||||
|
||||
thead{
|
||||
background-color: silver;
|
||||
}
|
||||
|
||||
/* Gaya untuk judul tabel */
|
||||
.table-title {
|
||||
text-align: center;
|
||||
font-size: 24px;
|
||||
/* font-weight: bold; */
|
||||
/* padding: 10px; */
|
||||
}
|
||||
|
||||
/* posisi text laporan yg dibawah kanan tengah */
|
||||
.center-right {
|
||||
text-align: right;
|
||||
padding-left: 60%;
|
||||
}
|
||||
.text-center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo-container {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
width: 90%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p class="table-title">DATA TRANSAKSI PASIEN</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>No</th>
|
||||
<th>Tanggal</th>
|
||||
<th>Nama Pasien</th>
|
||||
<th>Nama Tindakan</th>
|
||||
<th>Jumlah</th>
|
||||
<th>Subtotal</th>
|
||||
<th>Potongan</th>
|
||||
<th>Total</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
$no = 1;
|
||||
@endphp
|
||||
@foreach ($transaksi as $data)
|
||||
<tr>
|
||||
<td>{{ $no++ }}</td>
|
||||
<td>{{ date('d/m/Y', strtotime($data->created_at)) }}</td>
|
||||
<td>{{ $data->registrasi->pasien->nama }}</td>
|
||||
<td>{{ $data->tindakan->nama }}</td>
|
||||
<td>{{ $data->jml_tindakan }}</td>
|
||||
<td>{{ $data->subtotal }}</td>
|
||||
<td>{{ $data->potongan }}</td>
|
||||
<td>{{ $data->total }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="center-right">
|
||||
<div class="text-center">
|
||||
@php
|
||||
$tanggal = \Carbon\Carbon::now();
|
||||
@endphp
|
||||
<p>Jakarta, {{ $tanggal->locale('id')->isoFormat('dddd D MMMM YYYY') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@ -62,4 +62,7 @@ Route::middleware('auth:pegawai')->group(function () {
|
||||
|
||||
Route::get('/tansaksi/tindakan/{registrasi}', [TransaksiController::class, 'tindakanForm'])->name('transaksi.tindakan');
|
||||
Route::post('/transaksi', [TransaksiController::class, 'store'])->name('transaksi.store');
|
||||
Route::get('/transaksi/laporan', [TransaksiController::class, 'laporan'])->name('transaksi.laporan');
|
||||
Route::get('/transaksi/excel/export/', [TransaksiController::class, 'excelExport'])->name('transaksi.excel.export');
|
||||
Route::get('/transaksi/generate_pdf', [TransaksiController::class, 'generatePdf'])->name('transaksi.generate_pdf');
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user