public function setup()
{
$query_params = array();
if($this->params["R_officeId"]!=array())
{
$query_params[":R_officeId"] = $this->params["R_officeId"];
}
if($this->params["R_groupId"]!=array())
{
$query_params[":R_groupId"] = $this->params["R_groupId"];
}
if($this->params["R_loanOfficerId"]!=array())
{
$query_params[":R_loanOfficerId"] = $this->params["R_loanOfficerId"];
}
if($this->params["R_genderId"]!=array())
{
$query_params[":R_genderId"] = $this->params["R_genderId"];
}
///////////////////
$this->src('clients')->query("select
concat(repeat('..',
((LENGTH(ounder.`hierarchy`) - LENGTH(REPLACE(ounder.`hierarchy`, '.', '')) - 1))), ounder.`name`) as 'Office/Branch',
c.account_no as 'Client Account No.',
ifnull(mg.display_name, '-') as 'Group',
c.display_name as 'Name',
c.mobile_no as 'Phone',
DATE_FORMAT(c.date_of_birth, '%d %b %Y') as 'Date Of Birth',
ms.display_name as 'Loan Officer',
r.enum_message_property as 'Status',
DATE_FORMAT(c.activation_date, '%d %b %Y') as 'Activation', c.external_id as 'External Id'
from m_office o
join m_office ounder on ounder.hierarchy like concat(o.hierarchy, '%')
and ounder.hierarchy like concat('.', '%')
join m_client c on c.office_id = ounder.id
left join r_enum_value r on r.enum_name = 'status_enum' and r.enum_id = c.status_enum
LEFT JOIN m_group_client mgc ON c.id = mgc.client_id
LEFT JOIN m_group mg ON mgc.group_id = mg.id
LEFT JOIN m_staff ms ON c.staff_id = ms.id
where 1=1
".(($this->params["R_officeId"]!=array())? "AND o.id = (:R_officeId)": "")."
".(($this->params["R_groupId"]!=array())?" AND (ifnull(mgc.group_id, -10) = (:R_groupId) OR (:R_groupId) = '-1')" : "")."
".(($this->params["R_loanOfficerId"]!=array())?" AND (ifnull(c.staff_id, -10) = (:R_loanOfficerId) OR (:R_loanOfficerId) = '-1')":"")."
".(($this->params["R_genderId"]!=array())?" AND (ifnull(c.gender_cv_id, -10) = (:R_genderId) OR (:R_genderId) = '-1')":"")."
order by ounder.hierarchy, c.account_no")->params($query_params)
->pipe($this->dataStore('clients_list'));
}
DataTables::create(array(
"dataStore"=>$this->dataStore('clients_list'),
"columns"=>array(
"Office/Branch"=>array(
"label"=>"Office/Branch"
),
"Group"=>array(
"label"=>"Group",
),
"Name"=>array(
"label"=>"Name",
),
"Phone"=>array(
"label"=>"Phone",
),
"Date Of Birth"=>array(
"label"=>"Date Of Birth",
),
"Loan Officer"=>array(
"label"=>"Loan Officer",
),
"Status"=>array(
"label"=>"Status",
),
"Activation"=>array(
"label"=>"Activation",
),
"External Id"=>array(
"label"=>"External Id",
),
),
"plugins" => ["Buttons"],
"options"=>array(
"colReorder"=>true,
"dom" => 'Blfrtip',
"order" => [],
"buttons" => [
[
"extend" => "colvis",
"text" => 'Show/Hide Column '
],
[
"extend" => 'excelHtml5',
"className" => 'btn btn-primary',
"title" => 'Client List',
"exportOptions" => [
"columns" => ':visible'
]
],
[
"extend" => 'pdfHtml5',
"className" => 'btn btn-primary',
"title" => 'Client List',
"orientation" => "landscape",
"pageSize" => "A4",
"exportOptions" => [
"columns" => ':visible'
]
],
],
//"paging" => true,
"fixedHeader" => true,
"searching"=>true,
),
"serverSide"=>true,
"processing" => true,
//"fastRender" => true,
"themeBase"=>"bs4",
"cssClass"=>array(
"table" => "table table-condensed table-striped table-bordered",
),
"cssStyle"=>array(
"td"=>"padding: 3px; color: #000; font-size:12px",
"th"=>"padding: 5px; color: #000; font-size:14px",
)
));