<?php 
include 'aksi/koneksi.php';
$cabang = $_GET['cabang'];

// Database connection info 
$dbDetails = array( 
    'host' => $servername, 
    'user' => $username, 
    'pass' => $password, 
    'db'   => $db
); 
 
// DB table to use 
// $table = 'members'; 
$table = <<<EOT
 (
    SELECT 
      a.hilangbarang_id, 
      a.hilangbarang_kode,
      a.hilangbarang_deskripsi,
      a.hilangbarang_nama,
      a.hilangbarang_kategori_id, 
      a.hilangbarang_status, 
      a.hilangbarang_harga,
      a.hilangbarang_harga_beli,
      a.hilangbarang_stock,
      a.hilangbarang_terjual,
      a.hilangbarang_tanggal,
      a.hilangbarang_cabang,
      b.kategori_id,
      b.kategori_nama
    FROM hilangbarang a
    LEFT JOIN kategori b ON a.hilangbarang_kategori_id = b.kategori_id
 ) temp
EOT;
 
// Table's primary key 
$primaryKey = 'hilangbarang_id'; 
 
// Array of database columns which should be read and sent back to DataTables. 
// The `db` parameter represents the column name in the database.  
// The `dt` parameter represents the DataTables column identifier. 
$columns = array( 
    array( 'db' => 'hilangbarang_id', 'dt'              => 0 ),
    array( 'db' => 'hilangbarang_kode', 'dt'            => 1 ), 
    array( 'db' => 'hilangbarang_deskripsi', 'dt'            => 2 ),
    array( 'db' => 'hilangbarang_nama', 'dt'            => 3 ), 
    array( 'db' => 'kategori_nama',  'dt'         => 4 ), 
    array( 'db' => 'hilangbarang_harga',      'dt'      => 5 ),
    array( 'db' => 'hilangbarang_harga_beli',      'dt'      => 6 ),
    array( 'db' => 'hilangbarang_stock',      'dt'      => 7 ),
     array( 'db' => 'hilangbarang_terjual',      'dt'      => 8 ),
    array( 'db' => 'hilangbarang_tanggal',      'dt'      => 9 ),
    array( 
        'db'        => 'hilangbarang_status', 
        'dt'        => 10, 
        'formatter' => function( $d, $row ) { 
            // Ternary Operator
            return ($d == 1) ? "<span class='badge badge-success'>Dijual</span>" : 
            ($d == 2 ? "<span class='badge badge-info'>Khusus Servis</span>" : 
            ($d == 3 ? "<span class='badge badge-primary'>Dijual & Untuk Sevis</span>" :  
            "<span class='badge badge-danger'>Tidak Dijual<span>")); 
        } 
    ) 
); 

// Include SQL query processing class 
require 'aksi/ssp.php'; 

// require('ssp.class.php');

// Output data as json format 
echo json_encode( 
    SSP::simple( $_GET, $dbDetails, $table, $primaryKey, $columns, null, "hilangbarang_cabang = $cabang " )
    // SSP::simple( $_GET, $dbDetails, $table, $primaryKey, $columns)

);