<?php
require_once('../config.php');
$user_id = $_SESSION['user_id'];
$emp_id = $_SESSION['emp_id'];
$user_role = $_SESSION['user_role'];


// SQL server connection information
// $sql_details = $search_db;
$sql_details = $search_db;

if(!isset($_GET['isset'])){
    exit();
}



$table = <<<EOT
(
    SELECT 
        *
    FROM taxSlabs
) join_table
EOT;


$whereResult = null;
$whereAll = null;
if (isset($_GET['where_condition']) && !empty($_GET['where_condition'])) {
    $whereAll = $_GET['where_condition'];
}

// Table's primary key
$primaryKey = 'id';

// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array(

    array('db' => 'id', 'dt' => 'id'),
    array(
        'db' => 'year_start', 'dt' => 'year_start',
        'formatter' => function($cell, $row){
            return $row['year_start'] . ' - ' . $row['year_end'];
        }
    ),
    array(
        'db' => 'tax_slab_from', 'dt' => 'tax_slab_from',
        'formatter' => function($cell, $row){
            return '₹'.$row['tax_slab_from'] .' - ₹'. $row['tax_slab_to'];
        }
    ),
    array(
        'db' => 'tax_slab_rate', 'dt' => 'tax_slab_rate',
        'formatter' => function($cell, $row){
            return $row['tax_slab_rate'] .'%';
        }
    ),
    array(
        'db' => 'year_end', 
        'dt' => 'year_end',
        'formatter' => function($cell, $row){
            $returnValue = '
            <a href="tax-slab?edit='.$row['id'].'" class="text-success mr-1" title="Edit"><i class="uil uil-edit"></i></a>
            <a href="javascript:;" onclick="_delete_(\''.$row['id'].'\');" class="text-danger" title="Delete"><i class="uil uil-trash-alt"></i></a>
            ';
            return $returnValue;
        }
    ),
    array('db' => 'tax_slab_to', 'dt' => 'tax_slab_to'),
);


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * If you just want to use the basic configuration for DataTables with PHP
 * server-side, there is no need to edit below this line.
 */
require('ssp.class.php');

echo json_encode(
    // SSP::simple($_GET, $sql_details, $table, $primaryKey, $columns)
    SSP::complex($_GET, $sql_details, $table, $primaryKey, $columns, $whereResult, $whereAll)
);
