<?php

$exct=$_GET['exct'];
$date=$_GET['date'];
$nmrw=$_GET['nmrw'];

$date=date('Y-m-d',strtotime($date));

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


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

if($nmrw>0)
{
$where="`u`.`date`='$date' and `u`.`status`=''";
}
else
{
$where="`u`.`executive` = ".$exct." and `u`.`date`='$date' and `u`.`status`=''";
}

// indexes
$columns = array(
	array( 'db' => '`ud`.`name`', 'dt' => 0, 'field' => 'name' ),
	array( 'db' => '`dts`.`district`', 'dt' => 1, 'field' => 'district' ),
	array( 'db' => '`ud`.`cultivatingcrop`', 'dt' => 2, 'field' => 'cultivatingcrop' ),
	array( 'db' => '`ud`.`mobile`', 'dt' => 3, 'field' => 'mobile'),
	array( 'db' => '`u`.`time`', 'dt' => 4, 'field' => 'time'),
	array( 'db' => '`u`.`lastremarks`', 'dt' => 5, 'field' => 'lastremarks'),
	array( 'db' => '`u`.`remarks`', 'dt' => 6, 'field' => 'remarks'),
	array( 'db' => '`uds`.`ename`', 'dt' => 7, 'field' => 'ename'),
	array( 'db' => '`u`.`id`', 'dt' => 8, 'formatter' => function( $d, $row ) {
                return '<a href="status.php?id='.$d.'">Update</a> &nbsp; <a href="salesorder1.php?id='.$d.'">Order</a> &nbsp; <a href="close.php?id='.$d.'">Close</a>';},
            'field' => 'id' )
);


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


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


$joinQuery = "FROM `followup` AS `u` LEFT JOIN (SELECT ID, name as ename from `employee`) AS `uds` ON (`uds`.`ID` = `u`.`executive`) RIGHT JOIN `crm_customer` AS `ud` ON (`ud`.`ID` = `u`.`customer`) LEFT JOIN `districts` AS `dts` ON (`dts`.`ID` = `ud`.`district`)";
$extraWhere = $where;


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

