<?php

$exct=$_GET['exct'];


// DB table to use
$table = 'crm_customer';


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


$where="`u`.`executive` = ".$exct."";


// indexes
$columns = array(
	array( 'db' => '`u`.`name`', 'dt' => 0, 'field' => 'name' ),
	array( 'db' => '`uds`.`district`',  'dt' => 1, 'field' => 'district' ),
	array( 'db' => '`u`.`cultivatingcrop`',   'dt' => 2, 'field' => 'cultivatingcrop' ),
	array( 'db' => '`u`.`mobile`',     'dt' => 3, 'field' => 'mobile'),
	array( 'db' => '`ud`.`date`',     'dt' => 4,'formatter' => function( $d, $row ) {
				return date( 'd-m-Y', strtotime($d));
				},
				'field' => 'date' ),
	array( 'db' => '`u`.`id`', 'dt' => 5, 'formatter' => function( $d, $row ) {
                return '<a href="viewcustomerhistory1.php?customer='.$d.'">View</a>';},
            'field' => 'id' )

);


// SQL server connection information
$sql_details = array(
	'user' => 'grotec_admin',
	'pass' => 'VPS_epplecube',
	'db'   => 'grotec_admin',
	'host' => 'localhost'
);


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


$joinQuery = "FROM `crm_customer` AS `u` RIGHT JOIN `followup` AS `ud` ON (`u`.`ID` = `ud`.`customer`) LEFT JOIN `districts` AS `uds` ON (`uds`.`ID` = `u`.`district`)";
$extraWhere = $where;
$groupBy = "`ud`.`customer`";
$orderby = "`ud.date` desc";

echo json_encode(
	SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $joinQuery, $extraWhere, $groupBy, null )
);

