Bagian 7 dari seri
Dashboard, Laporan, dan Nota Sistem Kasir Laravel
Diterbitkan 15 September 2026
Data dashboard
$todaySales = Sale::where('status', 'paid')->whereDate('sale_date', today())->sum('grand_total');
$todayTransactions = Sale::where('status', 'paid')->whereDate('sale_date', today())->count();
$lowStocks = Product::whereColumn('stock', '<=', 'minimum_stock')->orderBy('stock')->limit(10)->get();
$bestSellers = SaleDetail::query()->select('product_id')->selectRaw('SUM(quantity) AS total_quantity')
->whereHas('sale', fn ($query) => $query->where('status', 'paid'))
->with('product')->groupBy('product_id')->orderByDesc('total_quantity')->limit(10)->get();
Laporan periode
$request->validate([
'start_date' => ['nullable', 'date'],
'end_date' => ['nullable', 'date', 'after_or_equal:start_date'],
]);
$query = Sale::where('status', 'paid')
->when($request->start_date, fn ($q, $date) => $q->whereDate('sale_date', '>=', $date))
->when($request->end_date, fn ($q, $date) => $q->whereDate('sale_date', '<=', $date));
$totalRevenue = (clone $query)->sum('grand_total');
$sales = $query->with(['customer', 'user'])->latest('sale_date')->paginate(25)->withQueryString();
Gunakan query yang sama untuk tampilan dan cetak agar angka laporan konsisten.
Nota cetak
<h1>{{ config('app.name') }}</h1>
<p>Nota: {{ $sale->invoice_number }}<br>Tanggal: {{ $sale->sale_date->format('d/m/Y H:i') }}</p>
<table>
@foreach($sale->details as $detail)
<tr><td>{{ $detail->product->name }} × {{ $detail->quantity }}</td><td>Rp{{ number_format($detail->subtotal, 0, ',', '.') }}</td></tr>
@endforeach
</table>
<p>Total: Rp{{ number_format($sale->grand_total, 0, ',', '.') }}</p>
<p>Bayar: Rp{{ number_format($sale->paid_amount, 0, ',', '.') }}</p>
<p>Kembali: Rp{{ number_format($sale->change_amount, 0, ',', '.') }}</p>
<button class="d-print-none" onclick="window.print()">Cetak</button>
Tambahkan CSS @media print untuk menyembunyikan navigasi dan menyesuaikan lebar nota 58 mm atau 80 mm.




