diff --git a/app/Filament/Resources/TrTransaksiResource/Pages/ViewTrTransaksi.php b/app/Filament/Resources/TrTransaksiResource/Pages/ViewTrTransaksi.php
index 42477d3..812452b 100644
--- a/app/Filament/Resources/TrTransaksiResource/Pages/ViewTrTransaksi.php
+++ b/app/Filament/Resources/TrTransaksiResource/Pages/ViewTrTransaksi.php
@@ -5,6 +5,7 @@ namespace App\Filament\Resources\TrTransaksiResource\Pages;
use App\Filament\Resources\TrTransaksiResource;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;
+use Torgodly\Html2Media\Actions\Html2MediaAction;
class ViewTrTransaksi extends ViewRecord
{
@@ -26,6 +27,23 @@ class ViewTrTransaksi extends ViewRecord
})->visible(function ($record) {
return $record->status == 'pending';
}),
+ Html2MediaAction::make('print')
+ ->scale(2)
+ ->print() // Enable print option
+ ->preview()
+ ->filename(function ($record) {
+ return 'invoice-' . $record->id_transaksi . '.pdf';
+ })
+ ->content(function ($record) {
+ return view('components.pdf.invoice-detail', ['record' => $record]);
+ })
+ ->savePdf() // Enable save as PDF option
+ ->requiresConfirmation() // Show confirmation modal
+ ->pagebreak('section', ['css', 'legacy'])
+ ->orientation('portrait') // Portrait orientation
+ ->format('a4', 'mm') // A4 format with mm units
+ ->enableLinks() // Enable links in PDF
+ ->margin([25, 50, 0, 50]) //
];
}
}
diff --git a/app/Filament/Widgets/StatsOverview.php b/app/Filament/Widgets/StatsOverview.php
index e2937a0..51c4467 100644
--- a/app/Filament/Widgets/StatsOverview.php
+++ b/app/Filament/Widgets/StatsOverview.php
@@ -15,17 +15,21 @@ class StatsOverview extends BaseWidget
protected function getStats(): array
{
return [
- Stat::make('Total Pasien', TrRegistrasi::count())
- ->description(new HtmlString('Lihat Semua Pasien')),
+ // total pasien hari ini, deskripsi jumlah keseluruhan pasien dengan link ke halaman pasien
+ Stat::make('Total Pasien Hari Ini', TrRegistrasi::whereDate('tgl_registrasi', now()->toDateString())->count())
+ ->description(new HtmlString(
+ 'Jumlah keseluruhan ' . TrRegistrasi::count() . ' pasien'
+ . '
Lihat Semua Pasien'
+ )),
+
+ // total tagihan, deskripsi jumlah keseluruhan tagihan dengan link ke halaman tagihan
+ Stat::make('Total Pendapatan Hari Ini', 'Rp ' . number_format(TrTransaksi::whereDate('created_at', now()->toDateString())->where('status', 'paid')->sum('total_harga'), 0, ',', '.'))
+ ->description(new HtmlString(
+ 'Jumlah keseluruhan Rp.' . number_format(TrTransaksi::where('status', 'paid')->sum('total_harga'), 0, ',', '.') . ' tagihan'
+ . '
Lihat Semua Tagihan'
+ )),
- // section 2
- //
- Stat::make('Total Tagihan', 'Rp ' . number_format(TrTransaksi::sum('total_harga'), 0, ',', '.'))
- ->description(new HtmlString('Lihat Semua Tagihan')),
- // Registrasi yang belum ada transaksi
- Stat::make('Total Pasien Belum Ada Transaksi', TrRegistrasi::whereDoesntHave('transaksi')->count())
- ->description(new HtmlString('Lihat Semua Pasien Belum Ada Transaksi')),
];
}
diff --git a/composer.json b/composer.json
index f919cab..90418c4 100644
--- a/composer.json
+++ b/composer.json
@@ -9,7 +9,8 @@
"php": "^8.2",
"filament/filament": "^3.3",
"laravel/framework": "^11.31",
- "laravel/tinker": "^2.9"
+ "laravel/tinker": "^2.9",
+ "torgodly/html2media": "^1.1"
},
"require-dev": {
"fakerphp/faker": "^1.23",
diff --git a/composer.lock b/composer.lock
index 29a2092..63a92f3 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "b10697b45fe4a086f6982a8e9998fea8",
+ "content-hash": "53b21f71a3004eddc3866a7af901cea9",
"packages": [
{
"name": "anourvalar/eloquent-serialize",
@@ -7241,6 +7241,65 @@
},
"time": "2024-12-21T16:25:41+00:00"
},
+ {
+ "name": "torgodly/html2media",
+ "version": "1.1.4",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/torgodly/Html2Media.git",
+ "reference": "58c31b08fc46fa2dbf307e7bf88d833c4d933c05"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/torgodly/Html2Media/zipball/58c31b08fc46fa2dbf307e7bf88d833c4d933c05",
+ "reference": "58c31b08fc46fa2dbf307e7bf88d833c4d933c05",
+ "shasum": ""
+ },
+ "require": {
+ "filament/filament": "^3.0",
+ "php": "^8.1"
+ },
+ "type": "library",
+ "extra": {
+ "laravel": {
+ "providers": [
+ "Torgodly\\Html2Media\\Html2MediaServiceProvider"
+ ]
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Torgodly\\Html2Media\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Abdullah Alhaj",
+ "email": "torgodly@gmail.com"
+ }
+ ],
+ "description": "Html2Media is a versatile Laravel package that allows users to convert HTML content into high-quality PDFs with options for either downloading or triggering a print dialog. Ideal for generating documents, invoices, and reports, this package includes configurable settings for file name, page orientation, format, margins, and scale. Html2Media also provides seamless integration with Filament actions, enabling dynamic content rendering in modals and customizable output previews. Whether you need to save a PDF or send it directly to the printer, Html2Media simplifies the process with robust, flexible features.",
+ "keywords": [
+ "documents",
+ "filament",
+ "html-to-pdf",
+ "invoice",
+ "laravel",
+ "pdf",
+ "pdf-generation",
+ "printing",
+ "reporting"
+ ],
+ "support": {
+ "issues": "https://github.com/torgodly/Html2Media/issues",
+ "source": "https://github.com/torgodly/Html2Media/tree/1.1.4"
+ },
+ "time": "2025-03-15T22:59:43+00:00"
+ },
{
"name": "vlucas/phpdotenv",
"version": "v5.6.1",
diff --git a/public/js/html2media/html2pdf-script.js b/public/js/html2media/html2pdf-script.js
new file mode 100644
index 0000000..956d285
--- /dev/null
+++ b/public/js/html2media/html2pdf-script.js
@@ -0,0 +1,97 @@
+document.addEventListener('DOMContentLoaded', function () {
+ Livewire.on('triggerPrint', function (options = {}) {
+ console.log('triggerPrint', options);
+
+ performAction(options);
+ });
+});
+
+function performAction({ action = 'print', element, ...customOptions } = {}) {
+ const printElement = document.getElementById(`print-smart-content-${element}`);
+
+ // Default options for html2pdf
+ const defaultOptions = {
+ filename: 'document.pdf',
+ pagebreak: {
+ mode: ['css', 'legacy'],
+ after: 'section'
+ },
+ jsPDF: {
+ unit: 'mm',
+ format: 'a4',
+ orientation: 'portrait'
+ },
+ html2canvas: {
+ scale: 2,
+ useCORS: true,
+ logging: true
+ },
+ margin: 0
+ };
+
+ // Merge custom options with defaults
+ const options = {
+ ...defaultOptions,
+ ...customOptions,
+ pagebreak: {
+ ...defaultOptions.pagebreak,
+ ...(customOptions.pagebreak || {})
+ },
+ jsPDF: {
+ ...defaultOptions.jsPDF,
+ ...(customOptions.jsPDF || {})
+ },
+ html2canvas: {
+ ...defaultOptions.html2canvas,
+ ...(customOptions.html2canvas || {})
+ }
+ };
+
+ if (printElement) {
+ switch (action) {
+ case 'savePdf':
+ // Save as PDF
+ html2pdf()
+ .from(printElement)
+ .set(options)
+ .save();
+ break;
+ case 'print':
+ // Print action
+ html2pdf()
+ .from(printElement)
+ .set(options)
+ .toPdf()
+ .get('pdf')
+ .then(function (pdf) {
+ const blob = pdf.output('blob');
+ const url = URL.createObjectURL(blob);
+ const iframe = document.getElementById(`print-smart-iframe-${element}`);
+ iframe.src = url;
+
+ iframe.onload = function () {
+ iframe.contentWindow.focus();
+ iframe.contentWindow.print();
+ iframe.contentWindow.onafterprint = function () {
+ URL.revokeObjectURL(url);
+ };
+ };
+ });
+ break;
+ default:
+ console.error('Unsupported action:', action);
+ }
+ } else {
+ console.error(`Element with ID "print-smart-content-${element}" not found.`);
+ }
+}
+
+function replaceSpacesInTextNodes(element) {
+ element.childNodes.forEach(node => {
+ if (node.nodeType === Node.TEXT_NODE && node.textContent.trim() !== '') {
+ node.textContent = node.textContent.replace(/\s/g, "\u00a0");
+ } else if (node.nodeType === Node.ELEMENT_NODE) {
+ replaceSpacesInTextNodes(node);
+ }
+ });
+}
diff --git a/resources/views/components/pdf/invoice-detail.blade.php b/resources/views/components/pdf/invoice-detail.blade.php
new file mode 100644
index 0000000..d4f8bba
--- /dev/null
+++ b/resources/views/components/pdf/invoice-detail.blade.php
@@ -0,0 +1,90 @@
+
Laporan Transaksi Pasien
+Nama: {{ $record->pasien->nama }}
+Tanggal Lahir: {{ \Carbon\Carbon::parse($record->pasien->tgl_lahir)->format('d-m-Y') }}
+Jenis Kelamin: {{ ucfirst($record->pasien->jenis_kelamin) }}
+No Kartu Asuransi: {{ $record->registrasi->nomor_kartu_asuransi }}
+Asuransi: {{ $record->registrasi->asuransi->nama_asuransi }}
+Tanggal Registrasi: {{ \Carbon\Carbon::parse($record->registrasi->tgl_registrasi)->format('d-m-Y') }}
+Ruang Pelayanan: {{ $record->registrasi->ruangPelayanan->nama_ruang_pelayanan }}
+| No | +Nama Tindakan | +Tarif | +
|---|---|---|
| {{ $index + 1 }} | +{{ $tindakan->nama_tindakan }} | +Rp {{ number_format($tindakan->tarif_tindakan, 0, ',', '.') }} | +
Grand Total: Rp {{ number_format($grandTotal, 0, ',', '.') }}
+