Untitled
unknown
plain_text
2 months ago
3.8 kB
8
Indexable
1. buat fungsi diconttroller
public function print($id)
{
// $transaction = Transaction::with(['items.product', 'customer'])->findOrFail($id);
// return view('transactions.print', compact('transaction'));
$transaction = Transaction::with(['items.product', 'customer'])->findOrFail($id);
$pdf = Pdf::loadView('transactions.print', compact('transaction'));
(buat view tamplian yang mau di print tampilkan data)
$content = $pdf->output();
$base64 = base64_encode($content);
return view('transactions.print-rawbt', compact('base64'));
}
2. contoh view yang akan di print
<!DOCTYPE html>
<html>
<head>
<title>Nota Transaksi</title>
<style>
body {
font-family: monospace;
font-size: 12px;
width: 230px; /* 58mm approx */
margin: 0 auto;
}
.center { text-align: center; }
.right { text-align: right; }
.line { border-top: 1px dashed #000; margin: 5px 0; }
table { width: 100%; border-collapse: collapse; }
td { padding: 2px 0; }
</style>
</head>
<body onload="window.print()">
<div class="center">
<h3 style="margin:0;">Karisma Motor CarWash</h3>
{{-- <small>Jl. Contoh No. 123</small><br>
<small>Telp: 08123456789</small> --}}
</div>
<div class="line"></div>
<p><strong>Ref:</strong> {{ $transaction->reference }}<br>
<strong>Tgl:</strong> {{ $transaction->created_at->format('d/m/Y H:i') }}<br>
<strong>Customer:</strong> {{ $transaction->customer->name ?? 'Walk-in' }}</p>
<div class="line"></div>
<table>
@foreach($transaction->items as $item)
<tr>
<td colspan="2">{{ $item->product->name }}</td>
</tr>
<tr>
<td>{{ $item->qty }} x Rp {{ number_format($item->price, 0, ',', '.') }}</td>
<td class="right">Rp {{ number_format($item->subtotal, 0, ',', '.') }}</td>
</tr>
@endforeach
</table>
<div class="line"></div>
<table>
<tr>
<td>Total</td>
<td class="right">Rp {{ number_format($transaction->total, 0, ',', '.') }}</td>
</tr>
<tr>
<td>Diskon</td>
<td class="right">Rp {{ number_format($transaction->discount, 0, ',', '.') }}</td>
</tr>
<tr>
<td>Pajak</td>
<td class="right">Rp {{ number_format($transaction->tax, 0, ',', '.') }}</td>
</tr>
<tr>
<td><strong>Total Akhir</strong></td>
<td class="right"><strong>Rp {{ number_format($transaction->total_after_tax, 0, ',', '.') }}</strong></td>
</tr>
<tr>
<td>Bayar</td>
<td class="right">Rp {{ number_format($transaction->cash, 0, ',', '.') }}</td>
</tr>
<tr>
<td>Kembali</td>
<td class="right">Rp {{ number_format($transaction->change, 0, ',', '.') }}</td>
</tr>
</table>
<div class="line"></div>
<div class="center">
<p>~~ Terima Kasih ~~</p>
{{-- <small>Barang yang sudah dibeli<br>tidak dapat dikembalikan</small> --}}
</div>
</body>
</html>
3 fungsi share ke rawbt
<html>
<head>
<title>Print ke RawBT</title>
<script>
document.addEventListener("DOMContentLoaded", function () {
// otomatis lempar ke RawBT saat halaman dibuka
window.location.href = "rawbt:data:application/pdf;base64,{{ $base64 }}";
});
</script>
</head>
<body>
<p>Struk sedang dikirim ke RawBT...</p>
</body>
</html>
Editor is loading...
Leave a Comment