<?php
session_start();
require_once '../../config.php';
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
	require_once '../../system/helpers/ssp.class.php';
	$table = 'history_balance';
	$primaryKey = 'id';
	$aksi = 'aksi';
	
	$columns = array(
		array( 'db' => 'tanggal', 'dt' => 0, 'formatter' => function($i) {
			return "<center>".format_date('id',$i)."</center>";
		}),
		array( 'db' => 'aksi', 'dt' => 1, 'formatter' => function($i) {
		    if ($i == "+") {
                $label = "success";
                $icon = "Saldo Bertambah";
            } else {
                $label = "danger";
                $icon = "Saldo Berkurang";
            }
			return "<center><span class=\"badge badge-glow badge-pill badge-".$label."\">".$icon."</span></center>";
		    
		}),
		array( 'db' => 'nominal', 'dt' => 2, 'formatter' => function($i, $aksi) {
		    $aksi = array('db' => 'aksi');
			return "<center><span class=\"badge badge-glow badge-pill badge-primary\">Rp ".number_format($i,0,',','.')."</span></center>";
		})
		
		
	);
	$sql_details = array(
		'user' => $_CONFIG['db']['username'],
		'pass' => $_CONFIG['db']['password'],
		'db'   => $_CONFIG['db']['name'],
		'host' => $_CONFIG['db']['host']
	);
	$joinQuery = null;
	$extraWhere = "user = '$session' ORDER BY id DESC";
	$groupBy = '';
	$having = '';
	print(json_encode(
		SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $joinQuery, $extraWhere, $groupBy, $having )
	));
} else {
	exit("No direct script access allowed!");
}