<?php
require_once(__DIR__.'/../../includes/sysinit.php');
require_once(SABLE_WORKING_PATH.'client/client_func.php');
//**********************************************************************************
$_SESSION['listParams']['searchVisible']	= 1;
$_SESSION['listParams']['allowExport']		= 1;

if (isset($_POST))
{
	$_SESSION['listParams']['searchField'][0]['title'] = 'client_full_name';
	$_SESSION['listParams']['searchField'][0][0] = 'client_name';
	$_SESSION['listParams']['searchField'][0][1] = 'client_surname';
	$_SESSION['listParams']['searchField'][1] = 'client_cell';
	$_SESSION['listParams']['searchField'][2] = 'client_phone';
	$_SESSION['listParams']['searchField'][3] = 'client_email';
	$_SESSION['listParams']['searchField'][4] = 'txn_amount';
}

if (sizeof($_SESSION['caller']['args']) > 2)
{
	$_SESSION['caller']['args'][1] = $_SESSION['caller']['args'][2];
	unset($_SESSION['caller']['args'][2]);
	
	$_SESSION['module']['back'] = 1;
	$_SESSION['module']['backlink'] = SableSystem::getCallPageLink('/report/finance/');
}

if (isset($data))
{
	$_SESSION['listParams']['listSql'] = $data['sql'];
}
else
{
	$sql = "select txn_amount, client.client_id, 
			concat(client_name, ' ', client_surname) as client_full_name,
			client_cell, client_phone, client_email 
			from client 
			left join finance on finance.client_id = client.client_id ";
	$_SESSION['listParams']['listSql'] = $sql;
}

//$_SESSION['listParams']['listSql'] = empty($data['sql']) ? $sql : $data['sql'];

$_SESSION['listParams']['module']					= "client";
$_SESSION['listParams']['page']						= 0;
$_SESSION['listParams']['offset']					= 50; //the number of records to display per page
$_SESSION['listParams']['parentId']					= ""; //
$_SESSION['listParams']['moduleFolder']				= "client";
$_SESSION['listParams']['moduleFolderDesc']			= "Client";
$_SESSION['listParams']['modulePage']				= "finance/client_table.php";
$_SESSION['listParams']['moduleIdField']			= "client_id";
$_SESSION['listParams']['moduleDescField']			= "client_full_name";
$_SESSION['listParams']['orderField']				= 0;
$_SESSION['listParams']['orderDirection']			= 0;
//$_SESSION['listParams']['groupField']				= 'client.client_id';

$_SESSION['listParams']['listHeadings'][0] = "Name";
$_SESSION['listParams']['listHeadings'][1] = "Cell No.";
$_SESSION['listParams']['listHeadings'][2] = "Phone No.";
$_SESSION['listParams']['listHeadings'][3] = "Email";
$_SESSION['listParams']['listHeadings'][4] = "Amount";
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_USER){$_SESSION['listParams']['listHeadings'][5] = "";} //View

$_SESSION['listParams']['listHeadingWidth'][0] = "25%";
$_SESSION['listParams']['listHeadingWidth'][1] = "15%";
$_SESSION['listParams']['listHeadingWidth'][2] = "15%";
$_SESSION['listParams']['listHeadingWidth'][3] = "20%";
$_SESSION['listParams']['listHeadingWidth'][4] = "10%";
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_USER){$_SESSION['listParams']['listHeadingWidth'][5] = "2%";} //View


$_SESSION['listParams']['listFields'][0]['field']			= "client_full_name";
$_SESSION['listParams']['listFields'][1]['field']			= "client_cell";
$_SESSION['listParams']['listFields'][2]['field']			= "client_phone";
$_SESSION['listParams']['listFields'][3]['field']			= "client_email";
$_SESSION['listParams']['listFields'][3]['emailLink']		= "1";
$_SESSION['listParams']['listFields'][4]['field']			= "txn_amount";
$_SESSION['listParams']['listFields'][4]['currency']		= "1";
if ($_SESSION['user']['access_level'] >= SABLE_ACCESS_USER) 
{
	$_SESSION['listParams']['listFields'][5]['field'] = "<i class='fa fa-2x ".SABLE_DATALIST_VIEW."' title='View --!--'></i>";
	$_SESSION['listParams']['listFields'][5]['onClick'] = " onClick='viewClient(\"--#--\")' ";
}

SableGeneralFunctions::callDataList();