connect_error) { die("Koneksi gagal: " . $conn->connect_error); } // Ambil data untuk laporan $sql = "SELECT r.id_report, r.tanggal, b.nama_barang, jb.nama_jenis, r.jumlah, r.harga FROM report r JOIN barang b ON r.id_barang = b.id_barang JOIN jenis_barang jb ON b.id_jenis = jb.id_jenis ORDER BY r.tanggal DESC"; $result = $conn->query($sql); // Set header for Excel file header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename="laporan_barang_' . date('Y-m-d') . '.xls"'); header('Pragma: no-cache'); header('Expires: 0'); // Output tabel HTML yang akan dibaca sebagai Excel echo ' Laporan Barang

Laporan Barang - Ayula Store

Tanggal Export: ' . date('d/m/Y H:i:s') . '

'; $no = 1; $grand_total = 0; if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $total = $row['jumlah'] * $row['harga']; $grand_total += $total; echo ''; } echo ''; } else { echo ''; } echo '
No ID Laporan Tanggal Nama Barang Jenis Jumlah Harga (Rp) Total (Rp)
' . $no++ . ' ' . $row['id_report'] . ' ' . date('d/m/Y H:i', strtotime($row['tanggal'])) . ' ' . $row['nama_barang'] . ' ' . $row['nama_jenis'] . ' ' . $row['jumlah'] . ' ' . number_format($row['harga'], 0, ',', '.') . ' ' . number_format($total, 0, ',', '.') . '
Grand Total ' . number_format($grand_total, 0, ',', '.') . '
Tidak ada data laporan
'; // Close database connection $conn->close(); ?>