
<?php 

include_once 'sesi.php';
$nama_app = " | Kasir Kita";

// Excel Export for Kasir
if (isset($_GET['export']) && $_GET['export'] == 'excel') {
    global $koneksi;
    header("Content-Type: application/vnd-ms-excel");
    header("Content-Disposition: attachment; filename=Laporan_Penjualan_Kasir_" . date('Ymd') . ".xls");
    
    $kasir_nama = mysqli_real_escape_string($koneksi, $_SESSION['namakaskit']);
    $where = ["kasir='$kasir_nama'"];
    
    if (isset($_GET['start_date']) && $_GET['start_date'] != '') {
        $start = mysqli_real_escape_string($koneksi, $_GET['start_date']);
        $where[] = "tanggal >= '$start'";
    }
    if (isset($_GET['end_date']) && $_GET['end_date'] != '') {
        $end = mysqli_real_escape_string($koneksi, $_GET['end_date']);
        $where[] = "tanggal <= '$end'";
    }
    $where_clause = ' WHERE ' . implode(' AND ', $where);
    
    $q = mysqli_query($koneksi, "SELECT * FROM laporan_penjualan$where_clause ORDER BY id DESC");
    
    echo '<table border="1">';
    echo '<tr>
        <th>No</th>
        <th>Kode Barang</th>
        <th>Nama Barang</th>
        <th>Kategori</th>
        <th>Jumlah Beli</th>
        <th>Total</th>
        <th>Tanggal</th>
        <th>Jam</th>
        <th>Kasir</th>
    </tr>';
    $no = 1;
    $grand_total = 0;
    while ($row = mysqli_fetch_array($q)) {
        echo '<tr>';
        echo '<td>' . $no++ . '</td>';
        echo '<td>' . $row['kdbarang'] . '</td>';
        echo '<td>' . $row['nm_barang'] . '</td>';
        echo '<td>' . $row['kategori'] . '</td>';
        echo '<td>' . $row['jumlah_beli'] . '</td>';
        echo '<td>' . $row['total'] . '</td>';
        echo '<td>' . $row['tanggal'] . '</td>';
        echo '<td>' . $row['jam'] . '</td>';
        echo '<td>' . $row['kasir'] . '</td>';
        echo '</tr>';
        $grand_total += $row['total'];
    }
    echo '<tr>
        <td colspan="5"><strong>Grand Total</strong></td>
        <td><strong>' . $grand_total . '</strong></td>
        <td colspan="3"></td>
    </tr>';
    echo '</table>';
    exit;
}

$modul = (isset($_GET['m']))?$_GET['m']:"awal";

switch ($modul) {
	
	case 'title': default: $judul="Beranda Logistik $nama_app"; include "title.php"; break;
	
	case 'barang': $judul="Menu Barang $nama_app"; include 'modul/barang/index.php'; break;
	case 'rak': $judul="Menu Rak $nama_app"; include 'modul/rak/index.php'; break;
	case 'supplier': $judul="Menu Supplier $nama_app"; include 'modul/supplier/index.php'; break; 			
	
	
}


 ?>

