2472 lines
103 KiB
PHP
Executable File
2472 lines
103 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class EmployeePolicyModel extends Model
|
|
{
|
|
protected $table = 'employee_polices';
|
|
protected $primaryKey = 'id';
|
|
protected $allowedFields = [
|
|
"id",
|
|
"employee_id",
|
|
"client_policy_id",
|
|
"tpa_id",
|
|
"uhid",
|
|
"batch_id",
|
|
"status",
|
|
"emp_policy_created_by",
|
|
"approved_by",
|
|
"pre_existing_alignments",
|
|
"date_of_exit",
|
|
"reason_for_exit",
|
|
"basic_cover_si",
|
|
"date_coverage",
|
|
"policy_end_date",
|
|
"days",
|
|
"premium",
|
|
"rata_premimum",
|
|
"si_enhancement_date",
|
|
"gst",
|
|
"created_by",
|
|
"updated_by",
|
|
"updated_at",
|
|
"rand_string",
|
|
"is_active",
|
|
"claim_status",
|
|
'ecard_sent_status',
|
|
'payable_employee',
|
|
'file_id',
|
|
"age_band",
|
|
"wellness_onboard"
|
|
];
|
|
|
|
// Callbacks
|
|
protected $allowCallbacks = true;
|
|
protected $beforeInsert = ["checkAndADDCreatedByValue", "addRandomNumberBeforeInsert"];
|
|
protected $afterInsert = [];
|
|
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
|
|
protected $afterUpdate = [];
|
|
protected $beforeFind = [];
|
|
protected $afterFind = [];
|
|
protected $beforeDelete = [];
|
|
protected $afterDelete = [];
|
|
|
|
protected function checkAndADDCreatedByValue(array $data)
|
|
{
|
|
// Check if 'updated_by' value is null or empty
|
|
if (empty($data['data']['created_by'])) {
|
|
// Set 'updated_by' value to the current session user ID
|
|
$data['data']['created_by'] = get_session_userid();
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function checkAndUpdateUpdatedByValue(array $data)
|
|
{
|
|
// Check if 'updated_by' value is null or empty
|
|
if (empty($data['data']['updated_by'])) {
|
|
// Set 'updated_by' value to the current session user ID
|
|
$data['data']['updated_by'] = get_session_userid();
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function addRandomNumberBeforeInsert(array $data)
|
|
{
|
|
$random_number = generate_random_alphanumeric();
|
|
$data['data']['rand_string'] = $random_number;
|
|
|
|
return $data;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------------------------------------
|
|
// public function getEmployeePolicy($client_id = 0, $policy_id = 0, $status = [], $branch_id = 0, $emp_code = "", $emp_name = "")
|
|
// {
|
|
// // dd($status);
|
|
|
|
// $result = $this->select([
|
|
// 'employee_polices.*',
|
|
// 'policy_type.policy_type as policy_name',
|
|
// 'im.short_name as insurer_short_name',
|
|
// 'ib.branch_name as insurer_branch_name',
|
|
// 'ib.branch_code as insurer_branch_code',
|
|
// 'tpam.name as tpa_name',
|
|
// 'tpam.short_name as tpa_short_name',
|
|
// 'tpab.branch_code as tpa_branch_code',
|
|
// 'cm.client_name',
|
|
// 'cm.short_name as client_short_name',
|
|
// // 'emp.id as employee_primary_id',
|
|
// 'emp.relationship',
|
|
// 'emp.relationship_code',
|
|
// 'emp.change_event',
|
|
// 'emp.emp_code',
|
|
// 'emp.name',
|
|
// 'emp.email_corporate',
|
|
// 'emp.dob',
|
|
// 'DATE_FORMAT(emp.dob, "%d/%m/%Y") AS formatted_dob',
|
|
// 'emp.gender',
|
|
// 'emp.emp_status',
|
|
// 'emp.is_active as emp_is_active',
|
|
// 'emp.mobile as mobile',
|
|
// 'emp.doj',
|
|
// 'emp.basic_pay',
|
|
// 'emp.band as grade',
|
|
// 'policy_type.policy_type',
|
|
// 'client_branch.branch_name as client_branch_name',
|
|
// 'client_branch.branch_code as client_branch_code',
|
|
// 'cp.policy_no',
|
|
// 'cp.policy_type_id',
|
|
|
|
// // Name audit trail
|
|
// '(SELECT old_value FROM auditing_history WHERE pk = emp.id AND field_name = "name" AND table_name = "employees" ORDER BY id ASC LIMIT 1) AS name_first_old',
|
|
// '(SELECT new_value FROM auditing_history WHERE pk = emp.id AND field_name = "name" AND table_name = "employees" ORDER BY id DESC LIMIT 1) AS name_last_new',
|
|
|
|
// // DOB audit trail
|
|
// '(SELECT old_value FROM auditing_history WHERE pk = emp.id AND field_name = "dob" AND table_name = "employees" ORDER BY id ASC LIMIT 1) AS dob_first_old',
|
|
// '(SELECT new_value FROM auditing_history WHERE pk = emp.id AND field_name = "dob" AND table_name = "employees" ORDER BY id DESC LIMIT 1) AS dob_last_new',
|
|
|
|
// // Gender audit trail
|
|
// '(SELECT old_value FROM auditing_history WHERE pk = emp.id AND field_name = "gender" AND table_name = "employees" ORDER BY id ASC LIMIT 1) AS gender_first_old',
|
|
// '(SELECT new_value FROM auditing_history WHERE pk = emp.id AND field_name = "gender" AND table_name = "employees" ORDER BY id DESC LIMIT 1) AS gender_last_new',
|
|
|
|
// '(CASE
|
|
// WHEN emp.relationship = "Self"
|
|
// THEN (SELECT COUNT(id) FROM employees WHERE emp_code = emp.emp_code AND is_active = 0 AND emp_status != "truncated")
|
|
// ELSE NULL
|
|
// END) AS removed_count',
|
|
|
|
// '(CASE
|
|
// WHEN emp.relationship != "Self" AND emp.created_at != (
|
|
// SELECT created_at
|
|
// FROM employees
|
|
// WHERE emp_code = emp.emp_code AND relationship = "Self" AND is_active = 1
|
|
// LIMIT 1
|
|
// )
|
|
// THEN "Newly Added"
|
|
// ELSE NULL
|
|
// END) AS newly_added',
|
|
|
|
// ])
|
|
// ->join('employees emp', 'employee_polices.employee_id = emp.id')
|
|
// ->join('client_policy cp', 'employee_polices.client_policy_id = cp.id') //cp - client policy
|
|
// ->join('policies pm', 'cp.policy_id = pm.id', 'left') //pm - policy master
|
|
// ->join('policy_type', 'policy_type.id = cp.policy_type_id')
|
|
// ->join('insurers im', 'cp.insurer_id = im.id') //im - insurer master
|
|
// ->join('insurer_branch ib', 'cp.insurer_branch_id = ib.id') //ib - insurer branch
|
|
// ->join('tpa tpam', 'cp.tpa_id = tpam.id', 'left') //tpam - tpa master
|
|
// ->join('tpa_branch tpab', 'cp.tpa_branch_id = tpab.id', 'left') //tpab - tpa branch
|
|
// ->join('clients cm', 'cp.client_id = cm.id') //cm - client master
|
|
// ->join('client_branch', 'emp.client_branch_id = client_branch.id') //cm - client master
|
|
// ->orderBy('emp.emp_code', 'ASC')
|
|
// ->orderBy('employee_polices.employee_id', 'ASC');
|
|
|
|
|
|
// // Conditionally add where clauses
|
|
// if ($client_id != 0 && !empty($client_id)) {
|
|
// $result->where('emp.client_id', $client_id);
|
|
// }
|
|
// if ($branch_id != 0 && !empty($branch_id)) {
|
|
// $result->where('emp.client_branch_id', $branch_id);
|
|
// }
|
|
// if ($policy_id != 0 && !empty($policy_id)) {
|
|
// $result->where('employee_polices.client_policy_id', $policy_id);
|
|
// }
|
|
|
|
// if (is_array($status) && count($status) > 0) {
|
|
|
|
// $result->where('employee_polices.status !=', 'expired');
|
|
|
|
// if (in_array("active", $status)) {
|
|
|
|
// $result->where('employee_polices.tpa_id IS NOT NULL');
|
|
// $result->where('employee_polices.uhid IS NOT NULL');
|
|
// $result->whereIn('employee_polices.status', $status);
|
|
// } elseif (in_array("pending", $status)) {
|
|
|
|
// $result->where('employee_polices.tpa_id IS NULL');
|
|
// $result->where('employee_polices.uhid IS NULL');
|
|
// $result->whereIn('employee_polices.status', array_merge($status, ['active']));
|
|
// } else {
|
|
|
|
// $result->whereIn('employee_polices.status', $status);
|
|
// }
|
|
|
|
// // if($status == 'active'){
|
|
// // $result->where('employee_polices.tpa_id IS NOT NULL');
|
|
// // $result->where('employee_polices.uhid IS NOT NULL');
|
|
// // }else if($status == 'pending'){
|
|
// // $status = 'active';
|
|
// // $result->where('employee_polices.status', $status);
|
|
// // }else{
|
|
// // $result->where('employee_polices.status', $status);
|
|
// // }
|
|
// }
|
|
|
|
// if (!empty($emp_code)) {
|
|
// $result->where('emp.emp_code', $emp_code);
|
|
// }
|
|
// if (!empty($emp_name)) {
|
|
// $result->like('emp.name', $emp_name);
|
|
// }
|
|
|
|
// // Always check these conditions
|
|
// $result->where('employee_polices.is_active', 1)
|
|
// ->where('emp.is_active', 1);
|
|
|
|
// $res = $result->findAll();
|
|
|
|
// // dd($this->db->getLastQuery());
|
|
|
|
// return $res;
|
|
// } // remarks do not remove
|
|
|
|
public function getEmployeePolicy($client_id = 0, $policy_id = 0, $status = [], $branch_id = 0, $emp_code = "", $emp_name = "", $status_type = '', $search = '')
|
|
{
|
|
// dd($status);
|
|
$ecard_download_link = "
|
|
CASE
|
|
WHEN
|
|
LOWER(emp.relationship) = 'self' AND
|
|
employee_polices.tpa_id IS NOT NULL AND employee_polices.tpa_id != '' AND
|
|
employee_polices.uhid IS NOT NULL AND employee_polices.uhid != ''
|
|
THEN
|
|
CASE
|
|
WHEN
|
|
(employee_polices.tpa_id IS NOT NULL AND employee_polices.tpa_id != '')
|
|
AND
|
|
(employee_polices.uhid IS NOT NULL AND employee_polices.uhid != '')
|
|
THEN
|
|
CONCAT('" . base_url('download-e-card/') . "', employee_polices.rand_string, '/1')
|
|
ELSE
|
|
null
|
|
END
|
|
ELSE
|
|
NULL
|
|
END AS ecard_download_link
|
|
";
|
|
|
|
$result = $this->select([
|
|
'employee_polices.*',
|
|
'policy_type.policy_type as policy_name',
|
|
'im.short_name as insurer_short_name',
|
|
'ib.branch_name as insurer_branch_name',
|
|
'ib.branch_code as insurer_branch_code',
|
|
'tpam.name as tpa_name',
|
|
'tpam.short_name as tpa_short_name',
|
|
'tpab.branch_code as tpa_branch_code',
|
|
'cm.client_name',
|
|
'cm.short_name as client_short_name',
|
|
// 'emp.id as employee_primary_id',
|
|
'emp.relationship',
|
|
'emp.relationship_code',
|
|
'emp.change_event',
|
|
'emp.emp_code',
|
|
'emp.name',
|
|
'emp.email_corporate',
|
|
'emp.dob',
|
|
'DATE_FORMAT(emp.dob, "%d/%m/%Y") AS formatted_dob',
|
|
'emp.gender',
|
|
'emp.emp_status',
|
|
'emp.is_active as emp_is_active',
|
|
'emp.mobile as mobile',
|
|
'emp.doj',
|
|
'emp.basic_pay',
|
|
'emp.band as grade',
|
|
'policy_type.policy_type',
|
|
'client_branch.branch_name as client_branch_name',
|
|
'client_branch.branch_code as client_branch_code',
|
|
'cp.policy_no',
|
|
'cp.policy_type_id',
|
|
'cp.is_addon',
|
|
'(
|
|
select id from employees
|
|
where emp_code = emp.emp_code
|
|
and client_id = emp.client_id
|
|
and lower(relationship) = "self"
|
|
and is_active = 1
|
|
limit 1
|
|
) as self_employee_id',
|
|
$ecard_download_link
|
|
])
|
|
->join('employees emp', 'employee_polices.employee_id = emp.id')
|
|
->join('client_policy cp', 'employee_polices.client_policy_id = cp.id') //cp - client policy
|
|
->join('policies pm', 'cp.policy_id = pm.id', 'left') //pm - policy master
|
|
->join('policy_type', 'policy_type.id = cp.policy_type_id')
|
|
->join('insurers im', 'cp.insurer_id = im.id') //im - insurer master
|
|
->join('insurer_branch ib', 'cp.insurer_branch_id = ib.id') //ib - insurer branch
|
|
->join('tpa tpam', 'cp.tpa_id = tpam.id', 'left') //tpam - tpa master
|
|
->join('tpa_branch tpab', 'cp.tpa_branch_id = tpab.id', 'left') //tpab - tpa branch
|
|
->join('clients cm', 'cp.client_id = cm.id') //cm - client master
|
|
->join('client_branch', 'emp.client_branch_id = client_branch.id') //cm - client master
|
|
->orderBy('emp.emp_code', 'ASC')
|
|
->orderBy('employee_polices.employee_id', 'ASC');
|
|
// Conditionally add where clauses
|
|
if (is_string($client_id) && preg_match('/^[a-f0-9]{32}$/i', $client_id)) {
|
|
// MD5 hash → compare using md5()
|
|
$result->where('md5(emp.client_id)', $client_id);
|
|
}else if ($client_id != 0 && !empty($client_id)) {
|
|
$result->where('emp.client_id', $client_id);
|
|
}
|
|
if ($branch_id != 0 && !empty($branch_id)) {
|
|
$result->where('emp.client_branch_id', $branch_id);
|
|
}
|
|
if ($policy_id != 0 && !empty($policy_id)) {
|
|
$result->where('employee_polices.client_policy_id', $policy_id);
|
|
}
|
|
|
|
if (is_array($status) && count($status) > 0) {
|
|
|
|
$result->where('employee_polices.status !=', 'expired');
|
|
|
|
if (in_array("active", $status)) {
|
|
|
|
$result->where('employee_polices.tpa_id IS NOT NULL');
|
|
$result->where('employee_polices.uhid IS NOT NULL');
|
|
$result->whereIn('employee_polices.status', $status);
|
|
} elseif (in_array("pending", $status)) {
|
|
|
|
$result->where('employee_polices.tpa_id IS NULL');
|
|
$result->where('employee_polices.uhid IS NULL');
|
|
$result->whereIn('employee_polices.status', array_merge($status, ['active']));
|
|
} else {
|
|
|
|
$result->whereIn('employee_polices.status', $status);
|
|
}
|
|
|
|
// if($status == 'active'){
|
|
// $result->where('employee_polices.tpa_id IS NOT NULL');
|
|
// $result->where('employee_polices.uhid IS NOT NULL');
|
|
// }else if($status == 'pending'){
|
|
// $status = 'active';
|
|
// $result->where('employee_polices.status', $status);
|
|
// }else{
|
|
// $result->where('employee_polices.status', $status);
|
|
// }
|
|
}
|
|
|
|
if (!empty($emp_code)) {
|
|
$result->where('emp.emp_code', $emp_code);
|
|
}
|
|
if (!empty($emp_name)) {
|
|
$result->like('emp.name', $emp_name);
|
|
}
|
|
|
|
// Always check these conditions
|
|
$result
|
|
->where('employee_polices.is_active', 1)
|
|
->where('emp.is_active', 1);
|
|
|
|
if($status_type == 'inactive'){
|
|
$result->whereIn('employee_polices.status', ['active', 'inactive']);
|
|
}else{
|
|
$result->where('employee_polices.status !=', 'inactive');
|
|
}
|
|
|
|
if (!empty($search)) {
|
|
$this->applyEmployeeGlobalSearch($result, $search);
|
|
}
|
|
|
|
$res = $result->findAll();
|
|
|
|
// dd($this->db->getLastQuery());
|
|
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* Pending-approval dependents (excludes Self) for a client / branch / policy.
|
|
*/
|
|
public function getPendingApprovalDependents($client_id = 0, $policy_id = 0, $branch_id = 0, $search = '')
|
|
{
|
|
$ecard_download_link = "
|
|
CASE
|
|
WHEN
|
|
LOWER(emp.relationship) = 'self' AND
|
|
employee_polices.tpa_id IS NOT NULL AND employee_polices.tpa_id != '' AND
|
|
employee_polices.uhid IS NOT NULL AND employee_polices.uhid != ''
|
|
THEN
|
|
CONCAT('" . base_url('download-e-card/') . "', employee_polices.rand_string, '/1')
|
|
ELSE
|
|
NULL
|
|
END AS ecard_download_link
|
|
";
|
|
|
|
$result = $this->select([
|
|
'employee_polices.*',
|
|
'policy_type.policy_type as policy_name',
|
|
'im.short_name as insurer_short_name',
|
|
'ib.branch_name as insurer_branch_name',
|
|
'ib.branch_code as insurer_branch_code',
|
|
'tpam.name as tpa_name',
|
|
'tpam.short_name as tpa_short_name',
|
|
'tpab.branch_code as tpa_branch_code',
|
|
'cm.client_name',
|
|
'cm.short_name as client_short_name',
|
|
'emp.relationship',
|
|
'emp.relationship_code',
|
|
'emp.change_event',
|
|
'emp.emp_code',
|
|
'emp.name',
|
|
'emp.email_corporate',
|
|
'emp.dob',
|
|
'DATE_FORMAT(emp.dob, "%d/%m/%Y") AS formatted_dob',
|
|
'emp.gender',
|
|
'emp.emp_status',
|
|
'emp.is_active as emp_is_active',
|
|
'emp.mobile as mobile',
|
|
'emp.doj',
|
|
'emp.basic_pay',
|
|
'emp.band as grade',
|
|
'policy_type.policy_type',
|
|
'client_branch.branch_name as client_branch_name',
|
|
'client_branch.branch_code as client_branch_code',
|
|
'cp.policy_no',
|
|
'cp.policy_type_id',
|
|
'cp.is_addon',
|
|
'(
|
|
select id from employees
|
|
where emp_code = emp.emp_code
|
|
and client_id = emp.client_id
|
|
and lower(relationship) = "self"
|
|
and is_active = 1
|
|
limit 1
|
|
) as self_employee_id',
|
|
$ecard_download_link
|
|
])
|
|
->join('employees emp', 'employee_polices.employee_id = emp.id')
|
|
->join('client_policy cp', 'employee_polices.client_policy_id = cp.id')
|
|
->join('policies pm', 'cp.policy_id = pm.id', 'left')
|
|
->join('policy_type', 'policy_type.id = cp.policy_type_id')
|
|
->join('insurers im', 'cp.insurer_id = im.id')
|
|
->join('insurer_branch ib', 'cp.insurer_branch_id = ib.id')
|
|
->join('tpa tpam', 'cp.tpa_id = tpam.id', 'left')
|
|
->join('tpa_branch tpab', 'cp.tpa_branch_id = tpab.id', 'left')
|
|
->join('clients cm', 'cp.client_id = cm.id')
|
|
->join('client_branch', 'emp.client_branch_id = client_branch.id')
|
|
->where('employee_polices.is_active', 1)
|
|
->where('emp.is_active', 1)
|
|
->where('employee_polices.status', 'pending_approval')
|
|
->where('emp.emp_status', 'pending_approval')
|
|
->where("LOWER(emp.relationship) != 'self'", null, false)
|
|
->orderBy('emp.emp_code', 'ASC')
|
|
->orderBy('employee_polices.employee_id', 'ASC');
|
|
|
|
if (is_string($client_id) && preg_match('/^[a-f0-9]{32}$/i', $client_id)) {
|
|
$result->where('md5(emp.client_id)', $client_id);
|
|
} elseif ($client_id != 0 && ! empty($client_id)) {
|
|
$result->where('emp.client_id', $client_id);
|
|
}
|
|
|
|
if ($branch_id != 0 && ! empty($branch_id)) {
|
|
$result->where('emp.client_branch_id', $branch_id);
|
|
}
|
|
|
|
if ($policy_id != 0 && ! empty($policy_id)) {
|
|
$result->where('employee_polices.client_policy_id', $policy_id);
|
|
}
|
|
|
|
if (! empty($search)) {
|
|
$this->applyEmployeeGlobalSearch($result, $search);
|
|
}
|
|
|
|
return $result->findAll();
|
|
}
|
|
|
|
/**
|
|
* Global search across employee + policy fields (OR + LIKE).
|
|
* Searches: emp_code, name, mobile, email, tpa_id, dob, relationship, status.
|
|
*/
|
|
protected function applyEmployeeGlobalSearch($builder, string $search)
|
|
{
|
|
$search = trim($search);
|
|
if ($search === '') {
|
|
return $builder;
|
|
}
|
|
|
|
return $builder->groupStart()
|
|
->like('emp.emp_code', $search)
|
|
->orLike('emp.name', $search)
|
|
->orLike('emp.mobile', $search)
|
|
->orLike('emp.email_corporate', $search)
|
|
->orLike('employee_polices.tpa_id', $search)
|
|
->orLike('emp.dob', $search)
|
|
->orLike("DATE_FORMAT(emp.dob, '%d/%m/%Y')", $search)
|
|
->orLike('emp.relationship', $search)
|
|
->orLike('employee_polices.status', $search)
|
|
->orLike('emp.emp_status', $search)
|
|
->groupEnd();
|
|
}
|
|
|
|
public function getEmployeePolicyForEcard($policy_id = 0)
|
|
{
|
|
$result = $this->select([
|
|
'employee_polices.id',
|
|
'emp.relationship',
|
|
])
|
|
->join('employees emp', 'employee_polices.employee_id = emp.id');
|
|
if ($policy_id !=0 && !empty($policy_id)) {
|
|
$result->where('employee_polices.client_policy_id', $policy_id);
|
|
}
|
|
// Always check these conditions
|
|
$result->where('employee_polices.is_active', 1)
|
|
->where('employee_polices.status', 'active')
|
|
->where('employee_polices.tpa_id is not null')
|
|
->where('employee_polices.ecard_sent_status',0)
|
|
// ->where('emp.relationship','Self');
|
|
->where('emp.email_corporate !=','')
|
|
->where('emp.email_corporate is not null');
|
|
|
|
return $result->findAll();
|
|
// $result->findAll();
|
|
// print_r($this->db->getLastQuery());die();
|
|
}
|
|
|
|
|
|
//for emp onboard do not change
|
|
public function checkExistingEmpPolicy($arr)
|
|
{
|
|
return $this->where('employee_id',$arr['employee_id'])
|
|
->where('client_policy_id',$arr['client_policy_id'])
|
|
->where('status', 'active')
|
|
->where('is_active',1)
|
|
->find();
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------------------------------
|
|
|
|
public function getInceptionEmployeeDataForExportExcel($ref_data, $return_type = 0)
|
|
{
|
|
$client_id = $ref_data['client_id'];
|
|
$client_policy_id = $ref_data['client_policy_id'];
|
|
$client_branch_id = $ref_data['client_branch_id'];
|
|
$insurer_or_tpa = $ref_data['insurer_or_tpa'];
|
|
$event = $ref_data['event_type'];
|
|
|
|
if($insurer_or_tpa == 'tpa'){
|
|
|
|
$id = 'tpa_id';
|
|
|
|
}else if($insurer_or_tpa == 'insurer'){
|
|
|
|
$id = 'uhid';
|
|
}
|
|
|
|
$datas = '';
|
|
if($event === 'inception'){
|
|
|
|
$datas = 'I';
|
|
|
|
}else if($event === 'dependent_addition'){
|
|
|
|
$datas = 'DA';
|
|
|
|
}else if($event === 'addition'){
|
|
|
|
$datas = 'A';
|
|
|
|
}
|
|
|
|
$sql = "
|
|
SELECT
|
|
employees.name AS emp_name,
|
|
employees.emp_code AS emp_code,
|
|
employees.gender AS emp_gender,
|
|
employees.relationship AS emp_relationship,
|
|
employees.relationship_code AS emp_relationship_code,
|
|
:datas: as event_type_data,
|
|
employees.change_event AS change_event,
|
|
|
|
|
|
employees.mobile AS emp_mobile,
|
|
employees.email_corporate AS emp_email_c,
|
|
employees.email_personal AS emp_email_p,
|
|
employees.band AS emp_grade,
|
|
employees.designation AS emp_designation,
|
|
employees.basic_pay AS emp_basic_pay,
|
|
|
|
TIMESTAMPDIFF(YEAR, employees.dob, employee_polices.date_coverage) AS emp_age,
|
|
employees.emp_type as emp_type,
|
|
|
|
|
|
employee_polices.id as primaryKey,
|
|
employee_polices.tpa_id,
|
|
employee_polices.uhid,
|
|
employee_polices.pre_existing_alignments,
|
|
employee_polices.basic_cover_si,
|
|
employee_polices.days as no_of_days,
|
|
employee_polices.premium,
|
|
employee_polices.rata_premimum as pro_rata_premium,
|
|
employee_polices.gst,
|
|
employee_polices.age_band,
|
|
(employee_polices.rata_premimum + employee_polices.gst) AS total,
|
|
|
|
|
|
batch_data.emp_policy_id,
|
|
batch_data.bl AS batch_list_batch_code,
|
|
batch_data.bf AS batch_files_batch_code,
|
|
|
|
DATE_FORMAT(employees.dob, '%d-%b-%Y') AS emp_dob,
|
|
DATE_FORMAT(employees.doj, '%d-%b-%Y') AS emp_doj,
|
|
DATE_FORMAT(employee_polices.policy_end_date, '%d-%b-%Y') AS policy_end_date,
|
|
DATE_FORMAT(employee_polices.date_coverage, '%d-%b-%Y') AS date_of_coverage,
|
|
|
|
|
|
CASE
|
|
WHEN client_branch.sez = 0 THEN 'NON-SEZ'
|
|
WHEN client_branch.sez = 1 THEN 'SEZ'
|
|
END as sez
|
|
|
|
FROM employee_polices
|
|
LEFT JOIN employees ON employees.id = employee_polices.employee_id
|
|
LEFT JOIN client_branch ON client_branch.id = employees.client_branch_id
|
|
LEFT JOIN (
|
|
SELECT
|
|
batch_list.emp_policy_id,
|
|
batch_list.batch_code as bl,
|
|
batch_files.batch_code as bf
|
|
FROM batch_files
|
|
LEFT JOIN batch_list ON batch_files.batch_code = batch_list.batch_code
|
|
WHERE batch_files.event_type = :event:
|
|
AND batch_files.actions = 'export'
|
|
AND batch_files.insurer_or_tpa = :insurer_or_tpa:
|
|
AND batch_files.client_policy_id = :client_policy_id:
|
|
AND batch_files.client_policy_id = :client_id:
|
|
|
|
) as batch_data ON employee_polices.id = batch_data.emp_policy_id
|
|
WHERE employee_polices.client_policy_id = :client_policy_id:
|
|
AND employees.client_branch_id = :client_branch_id:
|
|
AND employee_polices.is_active = 1
|
|
AND employee_polices.status = 'active'
|
|
AND employees.is_active = 1
|
|
AND employees.emp_status = 'active'
|
|
";
|
|
|
|
if($insurer_or_tpa == 'insurer'){
|
|
$sql .= "AND employee_polices.uhid IS NULL";
|
|
}
|
|
|
|
if($insurer_or_tpa == 'tpa'){
|
|
$sql .= "AND employee_polices.tpa_id IS NULL";
|
|
}
|
|
|
|
$binds = ["datas" => $datas,"event" => $event
|
|
,"insurer_or_tpa" => $insurer_or_tpa
|
|
,"client_policy_id" => $client_policy_id
|
|
,"client_branch_id" => $client_branch_id
|
|
,"client_id" => $client_id,"id" => $id];
|
|
|
|
// Get the result set
|
|
$query = $this->db->query($sql,$binds);
|
|
|
|
if($return_type == 1){
|
|
$results = $query->getResultArray();
|
|
}else{
|
|
$results = $query->getResult();
|
|
}
|
|
|
|
// dd($this->db->getLastQuery());
|
|
|
|
return $results;
|
|
}
|
|
|
|
|
|
public function getCorrectionEmployeesDataForExportExcel($ref_data, $return_type = 0)
|
|
{
|
|
|
|
$client_id = $ref_data['client_id'];
|
|
$client_policy_id = $ref_data['client_policy_id'];
|
|
$client_branch_id = $ref_data['client_branch_id'];
|
|
$insurer_or_tpa = $ref_data['insurer_or_tpa'];
|
|
|
|
$endorsement_condition = "{$insurer_or_tpa}" === 'tpa' ? "AND (emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = '')" : "AND (emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = '')";
|
|
|
|
$sql = "
|
|
SELECT DISTINCT
|
|
emp_endorsement.id,
|
|
emp_endorsement.pk,
|
|
emp_endorsement.emp_code,
|
|
emp_endorsement.endorsement_id,
|
|
emp_endorsement.field_name,
|
|
emp_endorsement.remarks,
|
|
emp_endorsement.actions,
|
|
employees.id AS primaryKey,
|
|
employees.name AS emp_name,
|
|
employees.gender AS emp_gender,
|
|
employees.client_id AS emp_client_id,
|
|
employees.emp_type as emp_type,
|
|
employee_polices.uhid,
|
|
employee_polices.tpa_id,
|
|
employees.relationship_code as emp_relationship_code,
|
|
employees.relationship as emp_relationship,
|
|
employees.email_corporate as emp_email_c,
|
|
'C' as event_type_data,
|
|
|
|
employee_polices.date_coverage,
|
|
employee_polices.basic_cover_si,
|
|
|
|
CASE
|
|
WHEN emp_endorsement.field_name = 'dob' THEN
|
|
DATE_FORMAT(emp_endorsement.old_value, '%d-%b-%Y')
|
|
ELSE
|
|
emp_endorsement.old_value
|
|
END AS old_value,
|
|
|
|
CASE
|
|
WHEN emp_endorsement.field_name = 'dob' THEN
|
|
DATE_FORMAT(emp_endorsement.new_value, '%d-%b-%Y')
|
|
ELSE
|
|
emp_endorsement.new_value
|
|
END AS new_value,
|
|
|
|
DATE_FORMAT(employees.dob, '%d-%b-%Y') AS emp_dob,
|
|
DATE_FORMAT(employees.doj, '%d-%b-%Y') AS emp_doj,
|
|
|
|
employees.mobile AS emp_mobile,
|
|
employees.email_corporate AS emp_email_c,
|
|
employees.email_personal AS emp_email_p,
|
|
employees.band AS emp_grade,
|
|
employees.designation AS emp_designation,
|
|
employees.basic_pay AS emp_basic_pay
|
|
FROM
|
|
emp_endorsement
|
|
LEFT JOIN
|
|
employees ON employees.id = emp_endorsement.pk
|
|
LEFT JOIN
|
|
employee_polices ON employees.id = employee_polices.employee_id
|
|
WHERE employees.client_id = :client_id:
|
|
AND employee_polices.client_policy_id = :client_policy_id:
|
|
AND employees.client_branch_id = :client_branch_id:
|
|
AND emp_endorsement.actions = 'c'
|
|
AND emp_endorsement.status != 'truncated'
|
|
AND emp_endorsement.is_active = 1
|
|
AND employee_polices.is_active = 1
|
|
AND employee_polices.status = 'active'
|
|
AND employees.is_active = 1
|
|
AND employees.emp_status = 'active'
|
|
$endorsement_condition";
|
|
|
|
$binds = ["client_policy_id" => $client_policy_id,"client_branch_id" => $client_branch_id,"client_id" => $client_id];
|
|
|
|
// Execute the raw query
|
|
$query = $this->db->query($sql,$binds);
|
|
|
|
// Get the result set
|
|
if($return_type == 1){
|
|
$results = $query->getResultArray();
|
|
}else{
|
|
$results = $query->getResult();
|
|
}
|
|
|
|
// dd($this->db->getLastQuery(), $result);
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
public function getSIEnhancementEmployeesDataForExportExcel($ref_data, $return_type = 0)
|
|
{
|
|
|
|
$client_id = $ref_data['client_id'];
|
|
$client_policy_id = $ref_data['client_policy_id'];
|
|
$client_branch_id = $ref_data['client_branch_id'];
|
|
$insurer_or_tpa = $ref_data['insurer_or_tpa'];
|
|
|
|
// $endorsement_condition = "{$insurer_or_tpa}" === 'tpa' ? "AND (a.endorsement_id IS NOT NULL OR a.endorsement_id != '')" : "AND (a.endorsement_id IS NULL OR a.endorsement_id = '')";
|
|
// $subquery_endorsement_condition = "{$insurer_or_tpa}" === 'tpa' ? "WHERE (endorsement_id IS NOT NULL OR endorsement_id != '')" : "WHERE (endorsement_id IS NULL OR endorsement_id = '')";
|
|
|
|
$endorsement_condition = "{$insurer_or_tpa}" === 'tpa' ? "AND (a.endorsement_id IS NULL OR a.is_tpa_export IS NULL)" : "AND (a.endorsement_id IS NULL OR a.endorsement_id = '')";
|
|
$subquery_endorsement_condition = "{$insurer_or_tpa}" === 'tpa' ? "WHERE (endorsement_id IS NULL OR is_tpa_export IS NULL)" : "WHERE (endorsement_id IS NULL OR endorsement_id = '')";
|
|
|
|
/*
|
|
ROUND(sidata.new_si_premium - sidata.old_si_premium, 2) AS difference_premium,
|
|
ROUND(
|
|
(sidata.new_si_premium - sidata.old_si_premium) *
|
|
(DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365,
|
|
2
|
|
) AS pro_rata_premium,
|
|
ROUND(
|
|
(
|
|
(sidata.new_si_premium - sidata.old_si_premium) *
|
|
(DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365
|
|
) * 0.18,
|
|
2
|
|
) AS gst,
|
|
ROUND(
|
|
(
|
|
(sidata.new_si_premium - sidata.old_si_premium) *
|
|
(DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365
|
|
) +
|
|
ROUND(
|
|
(
|
|
(sidata.new_si_premium - sidata.old_si_premium) *
|
|
(DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365
|
|
) * 0.18,
|
|
2
|
|
),
|
|
2
|
|
) AS total
|
|
*/
|
|
|
|
$query = $this->db->query("
|
|
SELECT
|
|
a.id AS endorsement_primarykey,
|
|
a.group_key,
|
|
employee_polices.id AS primaryKey,
|
|
employees.name AS emp_name,
|
|
employees.emp_code AS emp_code,
|
|
employees.dob AS emp_dob,
|
|
employees.gender AS emp_gender,
|
|
employees.relationship_code AS emp_relationship_code,
|
|
employees.relationship AS emp_relationship,
|
|
employees.emp_type AS emp_type,
|
|
'SI' AS event_type_data,
|
|
employees.doj AS emp_doj,
|
|
employees.mobile AS emp_mobile,
|
|
employees.email_corporate AS emp_email_c,
|
|
employees.email_personal AS emp_email_p,
|
|
employees.band AS emp_grade,
|
|
employees.designation AS emp_designation,
|
|
employees.basic_pay AS emp_basic_pay,
|
|
employee_polices.uhid AS uhid,
|
|
employee_polices.pre_existing_alignments,
|
|
employee_polices.policy_end_date,
|
|
employee_polices.basic_cover_si AS old_basic_cover_si,
|
|
employee_polices.premium AS old_si_premium,
|
|
employee_polices.rata_premimum AS old_rata_premium,
|
|
employee_polices.age_band,
|
|
employee_polices.date_coverage,
|
|
sidata.new_basic_cover_si,
|
|
sidata.new_si_premium,
|
|
sidata.old_si_premium,
|
|
sidata.date_of_coverage,
|
|
DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1 AS no_of_days,
|
|
|
|
ROUND(ABS(sidata.new_si_premium - sidata.old_si_premium), 2) AS difference_premium,
|
|
ROUND(
|
|
ABS(
|
|
(sidata.new_si_premium - sidata.old_si_premium) *
|
|
(DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365
|
|
),
|
|
2
|
|
) AS pro_rata_premium,
|
|
ROUND(
|
|
ABS(
|
|
(
|
|
(sidata.new_si_premium - sidata.old_si_premium) *
|
|
(DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365
|
|
) * 0.18
|
|
),
|
|
2
|
|
) AS gst,
|
|
ROUND(
|
|
ABS(
|
|
(
|
|
(sidata.new_si_premium - sidata.old_si_premium) *
|
|
(DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365
|
|
) +
|
|
(
|
|
(
|
|
(sidata.new_si_premium - sidata.old_si_premium) *
|
|
(DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365
|
|
) * 0.18
|
|
)
|
|
),
|
|
2
|
|
) AS total
|
|
|
|
FROM
|
|
emp_endorsement a
|
|
LEFT JOIN employees ON employees.emp_code = a.emp_code
|
|
LEFT JOIN employee_polices ON employees.id = employee_polices.employee_id
|
|
LEFT JOIN (
|
|
SELECT
|
|
emp_code,
|
|
group_key,
|
|
CAST(MAX(CASE WHEN field_name = 'basic_cover_si' THEN new_value END) AS UNSIGNED) AS new_basic_cover_si,
|
|
CAST(MAX(CASE WHEN field_name = 'premium' THEN new_value END) AS DECIMAL(10,2)) AS new_si_premium,
|
|
CAST(MAX(CASE WHEN field_name = 'premium' THEN old_value END) AS DECIMAL(10,2)) AS old_si_premium,
|
|
MAX(CASE WHEN field_name = 'si_enhancement_date' THEN new_value END) AS date_of_coverage
|
|
FROM emp_endorsement
|
|
$subquery_endorsement_condition
|
|
AND actions = 'si'
|
|
AND status != 'truncated'
|
|
GROUP BY emp_code, group_key
|
|
) AS sidata ON a.emp_code = sidata.emp_code AND a.group_key = sidata.group_key
|
|
WHERE employee_polices.client_policy_id = '{$client_policy_id}'
|
|
AND employees.client_branch_id = '{$client_branch_id}'
|
|
$endorsement_condition
|
|
AND a.actions = 'si'
|
|
AND a.status != 'truncated'
|
|
AND employee_polices.is_active = 1
|
|
AND employee_polices.status = 'active'
|
|
AND employees.is_active = 1
|
|
AND employees.emp_status = 'active'
|
|
group by group_key
|
|
");
|
|
|
|
// Get the result set
|
|
$results = $query->getResult();
|
|
|
|
if ($return_type == 1) {
|
|
$results = $query->getResultArray();
|
|
} else {
|
|
$results = $query->getResult();
|
|
}
|
|
|
|
// dd($this->db->getLastQuery());
|
|
return $results;
|
|
}
|
|
|
|
// DO NOT DELETE this SI ENHANCEMENT QUERY FUNCTION
|
|
|
|
// public function getSIEnhancementEmployeesDataForExportExcel($ref_data, $return_type = 0)
|
|
// {
|
|
|
|
// $client_id = $ref_data['client_id'];
|
|
// $client_policy_id = $ref_data['client_policy_id'];
|
|
// $client_branch_id = $ref_data['client_branch_id'];
|
|
// $insurer_or_tpa = $ref_data['insurer_or_tpa'];
|
|
|
|
// $endorsement_condition = "{$insurer_or_tpa}" === 'tpa' ? "AND (a.endorsement_id IS NOT NULL OR a.endorsement_id != '')" : "AND (a.endorsement_id IS NULL OR a.endorsement_id = '')";
|
|
|
|
|
|
// $query = $this->db->query("
|
|
// SELECT
|
|
// a.id as endorsement_primarykey,
|
|
// a.group_key,
|
|
// employee_polices.id AS primaryKey,
|
|
// employees.name AS emp_name,
|
|
// employees.emp_code AS emp_code,
|
|
// employees.dob AS emp_dob,
|
|
// employees.gender AS emp_gender,
|
|
// employees.relationship_code AS emp_relationship_code,
|
|
// employees.relationship AS emp_relationship,
|
|
// employees.emp_type as emp_type,
|
|
// 'SI' as event_type_data,
|
|
|
|
|
|
// employees.doj AS emp_doj,
|
|
// employees.mobile AS emp_mobile,
|
|
// employees.email_corporate AS emp_email_c,
|
|
// employees.email_personal AS emp_email_p,
|
|
// employees.band AS emp_grade,
|
|
// employees.designation AS emp_designation,
|
|
// employees.basic_pay AS emp_basic_pay,
|
|
|
|
// employee_polices.uhid AS uhid,
|
|
// employee_polices.pre_existing_alignments,
|
|
// employee_polices.policy_end_date,
|
|
// employee_polices.basic_cover_si as old_basic_cover_si,
|
|
// employee_polices.premium as old_si_premium,
|
|
// employee_polices.rata_premimum as old_rata_premium,
|
|
// employee_polices.age_band,
|
|
|
|
// batch_data.emp_policy_id,
|
|
// batch_data.bl AS batch_list_batch_code,
|
|
// batch_data.bf AS batch_files_batch_code,
|
|
|
|
// sidata.new_basic_cover_si,
|
|
// sidata.new_si_premium,
|
|
// sidata.old_si_premium,
|
|
// sidata.date_of_coverage,
|
|
|
|
// DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1 AS no_of_days,
|
|
|
|
// ROUND(sidata.new_si_premium - sidata.old_si_premium, 2) AS difference_premium,
|
|
|
|
// ROUND((sidata.new_si_premium - sidata.old_si_premium) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365, 2) AS pro_rata_premium,
|
|
|
|
// ROUND(((sidata.new_si_premium - sidata.old_si_premium) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS gst,
|
|
|
|
// ROUND(
|
|
// ((sidata.new_si_premium - sidata.old_si_premium) *
|
|
// (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) +
|
|
// ROUND(
|
|
// ((sidata.new_si_premium - sidata.old_si_premium) *
|
|
// (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2
|
|
// ), 2
|
|
// ) AS total
|
|
|
|
// FROM
|
|
// emp_endorsement a
|
|
// LEFT JOIN
|
|
// employees ON employees.emp_code = a.emp_code
|
|
// LEFT JOIN
|
|
// employee_polices ON employees.id = employee_polices.employee_id
|
|
// LEFT JOIN (
|
|
// SELECT
|
|
// aa.emp_code,
|
|
// aa.new_value as 'new_basic_cover_si',
|
|
// bb.new_value as 'new_si_premium',
|
|
// bb.old_value as 'old_si_premium',
|
|
// cc.new_value as 'date_of_coverage'
|
|
// FROM (
|
|
// SELECT
|
|
// a1.emp_code,
|
|
// a1.field_name,
|
|
// a1.new_value,
|
|
// a1.old_value
|
|
// FROM
|
|
// emp_endorsement as a1
|
|
// WHERE
|
|
// a1.field_name = 'basic_cover_si'
|
|
// ) aa
|
|
// LEFT JOIN (
|
|
// SELECT
|
|
// b1.emp_code,
|
|
// b1.field_name,
|
|
// b1.new_value,
|
|
// b1.old_value
|
|
// FROM
|
|
// emp_endorsement as b1
|
|
// WHERE
|
|
// b1.field_name = 'premium'
|
|
// ) bb ON aa.emp_code = bb.emp_code
|
|
// LEFT JOIN (
|
|
// SELECT
|
|
// c1.emp_code,
|
|
// c1.field_name,
|
|
// c1.new_value,
|
|
// c1.old_value
|
|
// FROM
|
|
// emp_endorsement as c1
|
|
// WHERE
|
|
// c1.field_name = 'si_enhancement_date'
|
|
// ) cc ON aa.emp_code = cc.emp_code
|
|
// ) as sidata ON a.emp_code = sidata.emp_code
|
|
// LEFT JOIN (
|
|
// SELECT DISTINCT
|
|
// batch_list.emp_policy_id,
|
|
// batch_list.batch_code AS bl,
|
|
// batch_files.batch_code AS bf
|
|
// FROM
|
|
// batch_files
|
|
// LEFT JOIN
|
|
// batch_list ON batch_files.batch_code = batch_list.batch_code
|
|
// WHERE
|
|
// batch_files.event_type = 'si_enhancement'
|
|
// AND batch_files.actions = 'export'
|
|
// AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}'
|
|
// ) AS batch_data ON employee_polices.id = batch_data.emp_policy_id
|
|
|
|
// WHERE employee_polices.client_policy_id = '{$client_policy_id}'
|
|
// AND employees.client_branch_id = '{$client_branch_id}'
|
|
// $endorsement_condition
|
|
// AND a.actions = 'si'
|
|
// AND a.status != 'truncated'
|
|
// AND employee_polices.is_active = 1
|
|
// AND employee_polices.status = 'active'
|
|
// AND employees.is_active = 1
|
|
// AND employees.emp_status = 'active'
|
|
// group by group_key
|
|
// ");
|
|
|
|
// // Get the result set
|
|
// $results = $query->getResult();
|
|
|
|
// if($return_type == 1){
|
|
// $results = $query->getResultArray();
|
|
// }else{
|
|
// $results = $query->getResult();
|
|
// }
|
|
|
|
// // dd($this->db->getLastQuery());
|
|
// return $results;
|
|
|
|
// }
|
|
|
|
// DO NOT DELETE this DELETION QUERY FUNCTION
|
|
|
|
// public function getDeletionEmployeeDataForExportExcel($ref_data, $return_type = 0)
|
|
// {
|
|
|
|
// $client_id = $ref_data['client_id'];
|
|
// $client_policy_id = $ref_data['client_policy_id'];
|
|
// $client_branch_id = $ref_data['client_branch_id'];
|
|
// $insurer_or_tpa = $ref_data['insurer_or_tpa'];
|
|
|
|
// $get_insurer_id_from_client_policy = $this->db->table('client_policy')
|
|
// ->select('insurer_id')
|
|
// ->where('id', $client_policy_id)
|
|
// ->get()
|
|
// ->getRowArray();
|
|
|
|
// $add_one_day = 0;
|
|
|
|
// if (!empty($get_insurer_id_from_client_policy)) {
|
|
|
|
// $get_the_insurer_add_one_for_delete = $this->db->table('insurers')
|
|
// ->select('deletion_add_day')
|
|
// ->where('id', $get_insurer_id_from_client_policy['insurer_id'])
|
|
// ->get()
|
|
// ->getRowArray();
|
|
|
|
// if (!empty($get_the_insurer_add_one_for_delete) && $get_the_insurer_add_one_for_delete['deletion_add_day'] == 1) {
|
|
// $add_one_day = 1;
|
|
// }
|
|
// }
|
|
|
|
// $status_condition = "{$insurer_or_tpa}" === 'tpa'
|
|
// ? "employee_polices.status = 'inactive' AND employees.emp_status = 'inactive'"
|
|
// : "employee_polices.status = 'active' AND employees.emp_status = 'active'";
|
|
|
|
// $endorsement_condition = "{$insurer_or_tpa}" === 'tpa' ? "AND (a.endorsement_id IS NOT NULL OR a.endorsement_id != '')" : "AND (a.endorsement_id IS NULL OR a.endorsement_id = '')";
|
|
|
|
// $query = $this->db->query("
|
|
// SELECT DISTINCT
|
|
// a.id as endorsement_primarykey,
|
|
// a.group_key,
|
|
// employee_polices.id as primaryKey,
|
|
// employees.name AS emp_name,
|
|
// employees.emp_code AS emp_code,
|
|
// employees.dob AS emp_dob,
|
|
// employees.gender AS emp_gender,
|
|
// employees.relationship AS emp_relationship,
|
|
// employees.relationship_code AS emp_relationship_code,
|
|
// employees.emp_type as emp_type,
|
|
// 'D' as event_type_data,
|
|
// TIMESTAMPDIFF(YEAR, employees.dob, CURDATE()) AS emp_age,
|
|
|
|
// employees.doj AS emp_doj,
|
|
// employees.mobile AS emp_mobile,
|
|
// employees.email_corporate AS emp_email_c,
|
|
// employees.email_personal AS emp_email_p,
|
|
// employees.band AS emp_grade,
|
|
// employees.designation AS emp_designation,
|
|
// employees.basic_pay AS emp_basic_pay,
|
|
|
|
// employee_polices.basic_cover_si,
|
|
// employee_polices.uhid as uhid,
|
|
// employee_polices.policy_end_date,
|
|
// employee_polices.rata_premimum as premium,
|
|
// employee_polices.claim_status,
|
|
|
|
// batch_data.emp_policy_id AS emp_policy_id,
|
|
// batch_data.bl AS batch_list_batch_code,
|
|
// batch_data.bf AS batch_files_batch_code,
|
|
|
|
// deletiondata.empstatus,
|
|
// deletiondata.changeevent,
|
|
// deletiondata.dateofexit,
|
|
// deletiondata.reasonforexit,
|
|
// deletiondata.status,
|
|
|
|
// DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + '$add_one_day' AS no_of_days,
|
|
|
|
|
|
// CASE
|
|
// WHEN employee_polices.claim_status = 0 THEN
|
|
// ROUND((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365, 2)
|
|
// ELSE
|
|
// 0
|
|
// END AS pro_rata_premium,
|
|
|
|
// CASE
|
|
// WHEN employee_polices.claim_status = 0 THEN
|
|
// ROUND(((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365) * 0.18, 2)
|
|
// ELSE
|
|
// 0
|
|
// END AS gst,
|
|
|
|
// CASE
|
|
// WHEN employee_polices.claim_status = 0 THEN
|
|
// ROUND(((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365) +
|
|
// (((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365) * 0.18), 2)
|
|
// ELSE
|
|
// 0
|
|
// END AS total,
|
|
|
|
// CASE
|
|
// WHEN employee_polices.claim_status = 0 THEN
|
|
// 'No claim'
|
|
// ELSE
|
|
// 'Claim'
|
|
// END AS claim_status
|
|
|
|
// FROM
|
|
// emp_endorsement a
|
|
// LEFT JOIN
|
|
// employees ON a.emp_code = employees.emp_code
|
|
// LEFT JOIN
|
|
// employee_polices ON employees.id = employee_polices.employee_id
|
|
|
|
// LEFT JOIN(
|
|
|
|
// select aa.emp_code, aa.new_value as 'empstatus', bb.new_value as 'changeevent', cc.new_value as 'dateofexit', dd.new_value as 'reasonforexit', ee.new_value as 'status' from
|
|
|
|
// ( SELECT a1.emp_code, a1.field_name, a1.new_value from emp_endorsement as a1 where a1.field_name = 'emp_status' and a1.status != 'truncated') aa
|
|
// left join
|
|
// ( SELECT b1.emp_code, b1.field_name, b1.new_value from emp_endorsement as b1 where b1.field_name = 'change_event' and b1.status != 'truncated') bb on aa.emp_code = bb.emp_code
|
|
// left join
|
|
// ( SELECT c1.emp_code, c1.field_name, c1.new_value from emp_endorsement as c1 where c1.field_name = 'date_of_exit' and c1.status != 'truncated') cc on aa.emp_code = cc.emp_code
|
|
// left join
|
|
// ( SELECT d1.emp_code, d1.field_name, d1.new_value from emp_endorsement as d1 where d1.field_name = 'reason_for_exit' and d1.status != 'truncated') dd on aa.emp_code = dd.emp_code
|
|
// left JOIN
|
|
// ( SELECT e1.emp_code, e1.field_name, e1.new_value from emp_endorsement as e1 where e1.field_name = 'status' and e1.status != 'truncated') ee on aa.emp_code = ee.emp_code
|
|
|
|
// ) as deletiondata on a.emp_code = deletiondata.emp_code and a.status != 'truncated'
|
|
|
|
// LEFT JOIN
|
|
// (
|
|
// SELECT
|
|
// batch_list.emp_policy_id,
|
|
// batch_list.batch_code AS bl,
|
|
// batch_files.batch_code AS bf
|
|
// FROM
|
|
// batch_files
|
|
// LEFT JOIN
|
|
// batch_list ON batch_files.batch_code = batch_list.batch_code
|
|
// WHERE
|
|
// batch_files.event_type = 'deletion'
|
|
// AND batch_files.actions = 'export'
|
|
// AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}'
|
|
// ) AS batch_data ON employee_polices.id = batch_data.emp_policy_id
|
|
|
|
// WHERE employee_polices.client_policy_id = {$client_policy_id}
|
|
// AND employees.client_branch_id = {$client_branch_id}
|
|
// $endorsement_condition
|
|
// AND a.actions = 'd'
|
|
// AND a.status != 'truncated'
|
|
// AND employee_polices.is_active = 1
|
|
// AND employees.is_active = 1
|
|
// AND $status_condition
|
|
// group by group_key
|
|
// ");
|
|
|
|
// if($return_type == 1){
|
|
// $result = $query->getResultArray();
|
|
// }else{
|
|
// $result = $query->getResult();
|
|
// }
|
|
|
|
// // dd($this->db->getLastQuery(), $result);
|
|
|
|
// return $result;
|
|
|
|
// }
|
|
|
|
public function getDeletionEmployeeDataForExportExcel($ref_data, $return_type = 0)
|
|
{
|
|
|
|
$client_id = (string) "'".$ref_data['client_id']."'";
|
|
$client_policy_id = (string) "'".$ref_data['client_policy_id']."'";
|
|
$client_branch_id = (string) "'".$ref_data['client_branch_id']."'";
|
|
$insurer_or_tpa = $ref_data['insurer_or_tpa'];
|
|
|
|
$get_insurer_id_from_client_policy = $this->db->table('client_policy')
|
|
->select('insurer_id')
|
|
->where('id', $client_policy_id)
|
|
->get()
|
|
->getRowArray();
|
|
|
|
$add_one_day = 0;
|
|
|
|
if (!empty($get_insurer_id_from_client_policy)) {
|
|
|
|
$get_the_insurer_add_one_for_delete = $this->db->table('insurers')
|
|
->select('deletion_add_day')
|
|
->where('id', $get_insurer_id_from_client_policy['insurer_id'])
|
|
->get()
|
|
->getRowArray();
|
|
|
|
if (!empty($get_the_insurer_add_one_for_delete) && $get_the_insurer_add_one_for_delete['deletion_add_day'] == 1) {
|
|
$add_one_day = 1;
|
|
}
|
|
}
|
|
|
|
$status_condition = "{$insurer_or_tpa}" === 'tpa'
|
|
? "employee_polices.status = 'active' AND employees.emp_status = 'active'"
|
|
: "employee_polices.status = 'active' AND employees.emp_status = 'active'";
|
|
|
|
$endorsement_condition = "{$insurer_or_tpa}" === 'tpa' ? "AND (a.endorsement_id IS NULL OR a.endorsement_id = '')" : "AND (a.endorsement_id IS NULL OR a.endorsement_id = '')";
|
|
|
|
$add_one_day = (int)$add_one_day;
|
|
|
|
$query = $this->db->query("
|
|
SELECT DISTINCT
|
|
a.id as endorsement_primarykey,
|
|
a.group_key,
|
|
employee_polices.id as primaryKey,
|
|
employees.name AS emp_name,
|
|
employees.emp_code AS emp_code,
|
|
employees.gender AS emp_gender,
|
|
employees.relationship AS emp_relationship,
|
|
employees.relationship_code AS emp_relationship_code,
|
|
employees.emp_type as emp_type,
|
|
'D' as event_type_data,
|
|
TIMESTAMPDIFF(YEAR, employees.dob, CURDATE()) AS emp_age,
|
|
|
|
employees.mobile AS emp_mobile,
|
|
employees.email_corporate AS emp_email_c,
|
|
employees.email_personal AS emp_email_p,
|
|
employees.band AS emp_grade,
|
|
employees.designation AS emp_designation,
|
|
employees.basic_pay AS emp_basic_pay,
|
|
|
|
employee_polices.basic_cover_si,
|
|
employee_polices.uhid as uhid,
|
|
employee_polices.rata_premimum,
|
|
ROUND(employee_polices.premium,2) as premium,
|
|
employee_polices.claim_status,
|
|
employee_polices.age_band,
|
|
employee_polices.tpa_id,
|
|
employee_polices.date_coverage,
|
|
|
|
|
|
batch_data.emp_policy_id AS emp_policy_id,
|
|
batch_data.bl AS batch_list_batch_code,
|
|
batch_data.bf AS batch_files_batch_code,
|
|
|
|
deletiondata.empstatus,
|
|
deletiondata.changeevent,
|
|
deletiondata.reasonforexit,
|
|
deletiondata.status,
|
|
CASE
|
|
WHEN deletiondata.claimstatus = 1 THEN 'Yes'
|
|
ELSE 'No'
|
|
END AS claimstatus,
|
|
|
|
DATE_FORMAT(employees.dob, '%d-%b-%Y') AS emp_dob,
|
|
DATE_FORMAT(employees.doj, '%d-%b-%Y') AS emp_doj,
|
|
DATE_FORMAT(employee_polices.policy_end_date, '%d-%b-%Y') AS policy_end_date,
|
|
DATE_FORMAT(deletiondata.dateofexit, '%d-%b-%Y') AS dateofexit,
|
|
|
|
|
|
DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + '$add_one_day' AS no_of_days,
|
|
|
|
CASE
|
|
WHEN deletiondata.claimstatus = 0 OR deletiondata.claimstatus IS NULL THEN
|
|
ROUND((employee_polices.premium * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365, 2)
|
|
ELSE
|
|
0
|
|
END AS pro_rata_premium,
|
|
|
|
CASE
|
|
WHEN deletiondata.claimstatus = 0 OR deletiondata.claimstatus IS NULL THEN
|
|
ROUND(((employee_polices.premium * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365) * 0.18, 2)
|
|
ELSE
|
|
0
|
|
END AS gst,
|
|
|
|
CASE
|
|
WHEN deletiondata.claimstatus = 0 OR deletiondata.claimstatus IS NULL THEN
|
|
ROUND(((employee_polices.premium * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365) +
|
|
(((employee_polices.premium * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365) * 0.18), 2)
|
|
ELSE
|
|
0
|
|
END AS total,
|
|
|
|
CASE
|
|
WHEN deletiondata.claimstatus = 0 OR deletiondata.claimstatus IS NULL THEN
|
|
|
|
'No claim'
|
|
ELSE
|
|
'Claim'
|
|
END AS claim_status
|
|
|
|
FROM
|
|
emp_endorsement a
|
|
LEFT JOIN
|
|
employee_polices ON a.pk = employee_polices.id
|
|
LEFT JOIN
|
|
employees ON employee_polices.employee_id = employees.id
|
|
|
|
LEFT JOIN (
|
|
SELECT
|
|
group_key,
|
|
MAX(CASE WHEN field_name = 'emp_status' THEN new_value END) AS empstatus,
|
|
MAX(CASE WHEN field_name = 'change_event' THEN new_value END) AS changeevent,
|
|
MAX(CASE WHEN field_name = 'date_of_exit' THEN new_value END) AS dateofexit,
|
|
MAX(CASE WHEN field_name = 'reason_for_exit' THEN new_value END) AS reasonforexit,
|
|
MAX(CASE WHEN field_name = 'status' THEN new_value END) AS status,
|
|
MAX(CASE WHEN field_name = 'claim_status' THEN new_value END) AS claimstatus
|
|
FROM
|
|
emp_endorsement
|
|
WHERE
|
|
status != 'truncated'
|
|
GROUP BY
|
|
group_key
|
|
|
|
) AS deletiondata
|
|
ON a.group_key = deletiondata.group_key AND a.status != 'truncated'
|
|
|
|
LEFT JOIN
|
|
(
|
|
SELECT
|
|
batch_list.emp_policy_id,
|
|
batch_list.batch_code AS bl,
|
|
batch_files.batch_code AS bf
|
|
FROM
|
|
batch_files
|
|
LEFT JOIN
|
|
batch_list ON batch_files.batch_code = batch_list.batch_code
|
|
WHERE
|
|
batch_files.event_type = 'deletion'
|
|
AND batch_files.actions = 'export'
|
|
AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}'
|
|
) AS batch_data ON employee_polices.id = batch_data.emp_policy_id
|
|
|
|
WHERE employee_polices.client_policy_id = {$client_policy_id}
|
|
AND employees.client_branch_id = {$client_branch_id}
|
|
$endorsement_condition
|
|
AND a.actions = 'd'
|
|
AND a.status != 'truncated'
|
|
AND employee_polices.is_active = 1
|
|
AND employees.is_active = 1
|
|
AND $status_condition
|
|
group by group_key
|
|
");
|
|
|
|
if($return_type == 1){
|
|
$result = $query->getResultArray();
|
|
}else{
|
|
$result = $query->getResult();
|
|
}
|
|
|
|
// dd($this->db->getLastQuery(), $result);
|
|
// dd($result);
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
public function fetchEmpEndorsementData($fetch_data)
|
|
{
|
|
// dd($fetch_data);
|
|
|
|
$client_policy_id = $fetch_data['client_policy_id'];
|
|
$client_branch_id = $fetch_data['client_branch_id'];
|
|
$client_id = $fetch_data['client_id'];
|
|
$emp_name = $fetch_data['emp_name'];
|
|
$emp_code = $fetch_data['emp_code'];
|
|
|
|
// Your raw SQL query
|
|
$sql = "
|
|
SELECT
|
|
ee.id as emp_endorsement_primarykey,
|
|
ep.id as emp_policy_primarykey,
|
|
e.id as employees_primarykey,
|
|
e.relationship,
|
|
e.emp_code,
|
|
e.name as emp_name,
|
|
ee.file_id,
|
|
ee.group_key,
|
|
(
|
|
SELECT employees.id
|
|
FROM employees
|
|
WHERE client_id = :client_id:
|
|
AND client_branch_id = :client_branch_id:
|
|
AND is_active = 1
|
|
AND emp_status = 'active'
|
|
AND emp_code = :emp_code:
|
|
AND name = :emp_name:
|
|
LIMIT 1
|
|
) AS employees_id,
|
|
|
|
MAX(
|
|
CASE
|
|
WHEN ee.field_name = 'date_of_exit' THEN ee.new_value
|
|
END
|
|
) AS date_of_exit,
|
|
MAX(
|
|
CASE
|
|
WHEN ee.field_name = 'reason_for_exit' THEN ee.new_value
|
|
END
|
|
) AS reason_for_exit,
|
|
MAX(
|
|
CASE
|
|
WHEN ee.field_name = 'status' THEN ee.new_value
|
|
END
|
|
) AS status,
|
|
MAX(
|
|
CASE
|
|
WHEN ee.field_name = 'claim_status' THEN ee.new_value
|
|
END
|
|
) AS claim_status
|
|
FROM
|
|
emp_endorsement AS ee
|
|
JOIN employee_polices AS ep ON ep.id = ee.pk
|
|
JOIN employees AS e ON e.emp_code = ee.emp_code
|
|
WHERE
|
|
ee.emp_code = :emp_code:
|
|
AND ep.client_policy_id = :client_policy_id:
|
|
AND e.client_branch_id = :client_branch_id:
|
|
AND ee.name = :emp_name:
|
|
AND ee.field_name IN ('date_of_exit', 'reason_for_exit', 'status', 'claim_status')
|
|
AND ep.is_active = 1
|
|
AND ep.status = 'active'
|
|
AND e.is_active = 1
|
|
AND e.emp_status = 'active'
|
|
GROUP BY
|
|
ee.group_key
|
|
";
|
|
|
|
$binds = ['client_policy_id' => $client_policy_id,
|
|
'client_branch_id' => $client_branch_id,
|
|
'client_id' => $client_id,
|
|
'emp_name' => $emp_name,
|
|
'emp_code' => $emp_code];
|
|
// dd($sql);
|
|
|
|
// Execute the raw SQL query
|
|
$query = $this->db->query($sql,$binds);
|
|
|
|
// Fetch and return results
|
|
$row = $query->getRowArray();
|
|
|
|
return $row;
|
|
}
|
|
|
|
|
|
//for emp onboard do not change
|
|
|
|
// public function checkExistingEmpPolicy($arr)
|
|
// {
|
|
// return $this->where('employee_id',$arr['employee_id'])
|
|
// ->where('client_policy_id',$arr['client_policy_id'])
|
|
// ->find();
|
|
// }
|
|
|
|
|
|
public function updateSiAndPremium( $client_policy_id, $employee_id,$basic_cover_si,$premium = 0)
|
|
{
|
|
|
|
|
|
$query = "UPDATE employee_polices
|
|
SET employee_polices.basic_cover_si = :basic_cover_si:
|
|
, employee_polices.premium = :premium:
|
|
WHERE employee_polices.employee_id = :employee_id:
|
|
AND employee_polices.client_policy_id = :client_policy_id:";
|
|
$binds = ["client_policy_id"=>$client_policy_id, "employee_id"=>$employee_id,"basic_cover_si"=>$basic_cover_si,"premium"=>$premium];
|
|
$this->query($query,$binds);
|
|
}
|
|
|
|
|
|
public function getEmployeeEndorsementList($client_id, $policy_id, $status, $branch_id)
|
|
{
|
|
$query1 = $this->db->table('emp_endorsement e');
|
|
$query1->select('
|
|
e.id,
|
|
e.pk,
|
|
e.emp_code,
|
|
e.name,
|
|
e.actions,
|
|
e.status,
|
|
e.remarks,
|
|
e.endorsement_id,
|
|
ep.client_policy_id,
|
|
insurers.short_name as insurer_short_name,
|
|
client_policy.policy_no,
|
|
policy_type.policy_type
|
|
');
|
|
$query1->distinct();
|
|
$query1->join('employee_polices ep', 'ep.id = e.pk');
|
|
$query1->join('employees', 'employees.id = ep.employee_id');
|
|
$query1->join('client_policy', 'client_policy.id = ep.client_policy_id');
|
|
$query1->join('client_branch', 'client_branch.id = employees.client_branch_id');
|
|
// $query1->join('policies', 'policies.id = client_policy.policy_id');
|
|
$query1->join('policy_type', 'policy_type.id = client_policy.policy_type_id');
|
|
$query1->join('insurers', 'insurers.id = client_policy.insurer_id');
|
|
$query1->whereIn('e.actions', ['c']);
|
|
$query1->where('ep.client_policy_id', $policy_id);
|
|
$query1->where('employees.client_id', $client_id);
|
|
$query1->where('employees.client_branch_id', $branch_id);
|
|
if($status != 0 && !empty($status)){
|
|
|
|
$query1->where('e.status', $status);
|
|
}
|
|
$query1->orderBy('e.id', 'desc');
|
|
|
|
$results1 = $query1->get()->getResultArray();
|
|
|
|
$query2 = $this->db->table('emp_endorsement e');
|
|
|
|
$query2->select('
|
|
e.id,
|
|
e.pk,
|
|
e.emp_code,
|
|
e.name,
|
|
e.actions,
|
|
e.status,
|
|
e.endorsement_id,
|
|
e.remarks,
|
|
ep.client_policy_id,
|
|
insurers.short_name as insurer_short_name,
|
|
client_policy.policy_no,
|
|
policy_type.policy_type
|
|
');
|
|
$query2->join('employee_polices ep', 'ep.id = e.pk');
|
|
$query2->join('employees', 'employees.id = ep.employee_id');
|
|
$query2->join('client_policy', 'client_policy.id = ep.client_policy_id');
|
|
$query2->join('client_branch', 'client_branch.id = employees.client_branch_id');
|
|
// $query2->join('policies', 'policies.id = client_policy.policy_id');
|
|
$query2->join('policy_type', 'policy_type.id = client_policy.policy_type_id');
|
|
$query2->join('insurers', 'insurers.id = client_policy.insurer_id');
|
|
$query2->whereIn('e.actions', ['si', 'd', 'a']);
|
|
$query2->where('ep.client_policy_id', $policy_id);
|
|
$query2->where('employees.client_id', $client_id);
|
|
$query2->where('employees.client_branch_id', $branch_id);
|
|
if($status != 0 && !empty($status)){
|
|
|
|
$query2->where('e.status', $status);
|
|
}
|
|
$query2->groupBy('e.emp_code, e.name, e.actions');
|
|
$query2->orderBy('e.id', 'desc');
|
|
|
|
$results2 = $query2->get()->getResultArray();
|
|
|
|
$results = array_merge($results1, $results2);
|
|
|
|
// dd($this->db->getLastQuery());
|
|
|
|
return $results;
|
|
|
|
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------
|
|
|
|
|
|
public function getEmployeePolicyForFileList($client_id, $policy_id)
|
|
{
|
|
$result = $this->select(['employee_polices.*','pt.policy_type','im.short_name as insurer_short_name','ib.branch_name as insurer_branch_name','ib.branch_code as insurer_branch_code','tpam.name as tpa_name','tpam.short_name as tpa_short_name','tpab.branch_code as tpa_branch_code','cm.client_name','cm.short_name as client_short_name','emp.relationship','emp.relationship_code','emp.change_event','emp.emp_code','emp.name','emp.email_corporate','emp.dob','emp.gender','emp.emp_status','emp.is_active as emp_is_active','emp.mobile as mobile','cp.policy_type_id'])
|
|
->join('employees emp', 'employee_polices.employee_id = emp.id')
|
|
->join('client_policy cp', 'employee_polices.client_policy_id = cp.id') //cp - client policy
|
|
->join('policy_type pt', 'cp.policy_type_id = pt.id') //pm - policy master
|
|
->join('insurers im', 'cp.insurer_id = im.id') //im - insurar master
|
|
->join('insurer_branch ib', 'cp.insurer_branch_id = ib.id') //ib - insurar branch
|
|
->join('tpa tpam', 'cp.tpa_id = tpam.id') //tpam - tpa master
|
|
->join('tpa_branch tpab', 'cp.tpa_branch_id = tpab.id') //tpab - tpa brach
|
|
->join('clients cm', 'cp.client_id = cm.id') //cm - client master
|
|
->where('emp.client_id',$client_id)
|
|
->where('employee_polices.client_policy_id',$policy_id)
|
|
->where('employee_polices.is_active',1)
|
|
->where('emp.is_active',1);
|
|
|
|
$result->whereIn('employee_polices.status', ['enrolled']);
|
|
$result->whereIn('emp.emp_status', ['enrolled']);
|
|
$result = $result->findAll();
|
|
// print_r($this->db->getLastQuery());
|
|
return ($result);
|
|
}
|
|
|
|
|
|
public function getViewEmpSuccessList($file_id)
|
|
{
|
|
return $this->db->table('employees emp')
|
|
->select(['employee_polices.*','pm.name as policy_name','im.short_name as insurer_short_name','ib.branch_name as insurer_branch_name','ib.branch_code as insurer_branch_code','tpam.name as tpa_name','tpam.short_name as tpa_short_name','tpab.branch_code as tpa_branch_code','cm.client_name','cm.short_name as client_short_name','emp.relationship','emp.relationship_code','emp.change_event','emp.emp_code','emp.name','emp.email_corporate','emp.dob','emp.gender','emp.emp_status','emp.is_active as emp_is_active','emp.mobile as mobile'])
|
|
->join('employee_polices', 'employee_polices.employee_id = emp.id')
|
|
->join('client_policy cp', 'employee_polices.client_policy_id = cp.id') //cp - client policy
|
|
->join('policies pm', 'cp.policy_id = pm.id') //pm - policy master
|
|
->join('insurers im', 'cp.insurer_id = im.id') //im - insurar master
|
|
->join('insurer_branch ib', 'cp.insurer_branch_id = ib.id') //ib - insurar branch
|
|
->join('tpa tpam', 'cp.tpa_id = tpam.id') //tpam - tpa master
|
|
->join('tpa_branch tpab', 'cp.tpa_branch_id = tpab.id') //tpab - tpa brach
|
|
->join('clients cm', 'cp.client_id = cm.id') //cm - client master
|
|
->where('emp.file_id',$file_id)
|
|
->whereIn('employee_polices.status', ['draft', 'enrolled'])
|
|
->get()->getResultArray();
|
|
}
|
|
|
|
public function getECardDataUsingMd5($client_policy_id, $emp_code,$client_id){
|
|
|
|
$result = $this->db->table('employees e')
|
|
->select('e.id,
|
|
e.name, e.mobile,
|
|
e.relationship,
|
|
e.relationship_code,
|
|
e.emp_code,
|
|
e.email_personal,
|
|
e.email_corporate,
|
|
e.gender,
|
|
e.dob,
|
|
e.doj,
|
|
e.band,
|
|
TIMESTAMPDIFF(YEAR, e.dob, CURDATE()) AS emp_age,
|
|
(SELECT name FROM employees WHERE relationship = "Self" and emp_code = ' . $this->db->escape($emp_code) . ' and client_id = '.$client_id.' LIMIT 1) AS self,
|
|
|
|
|
|
ep.tpa_id,
|
|
ep.uhid,
|
|
cp.policy_end_date,
|
|
ep.basic_cover_si,
|
|
|
|
clients.client_name,
|
|
clients.short_name AS client_short_name,
|
|
|
|
cp.policy_start_date,
|
|
cp.policy_no,
|
|
|
|
insurers.name AS insurer_name,
|
|
insurers.short_name AS insurer_short_name,
|
|
insurers.insurer_logo,
|
|
|
|
insurer_branch.branch_name,
|
|
insurer_branch.branch_code,
|
|
insurer_branch.city as insurer_branch_city,
|
|
|
|
tpa.name AS tpa_name,
|
|
tpa.tpa_logo AS tpa_logo,
|
|
tpa.front_card,
|
|
tpa.back_card,
|
|
tpa.network_hospitals,
|
|
tpa.short_name AS tpa_short_name'
|
|
)
|
|
|
|
->join('employee_polices ep', 'ep.employee_id = e.id')
|
|
->join('client_policy cp', 'cp.id = ep.client_policy_id')
|
|
->join('clients', 'clients.id = cp.client_id')
|
|
->join('insurers', 'insurers.id = cp.insurer_id')
|
|
->join('insurer_branch', 'insurer_branch.id = cp.insurer_branch_id')
|
|
->join('tpa', 'tpa.id = cp.tpa_id')
|
|
->where("ep.tpa_id IS NOT NULL AND ep.tpa_id <> ''")
|
|
->where('e.is_active', '1')
|
|
->whereIn('ep.status', ['active', 'expired'])
|
|
->whereIn('e.emp_status', ['active', 'expired'])
|
|
->where('ep.is_active', '1')
|
|
->where('e.emp_code', $emp_code)
|
|
->where('ep.client_policy_id', $client_policy_id)
|
|
->get()
|
|
->getResultArray();
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
public function getECardSingleData($rand_string, $emp_code,$client_id){
|
|
|
|
$result = $this->db->table('employees e')
|
|
->select('e.id,
|
|
e.name, e.mobile,
|
|
e.relationship,
|
|
e.relationship_code,
|
|
e.emp_code,
|
|
e.email_personal,
|
|
e.email_corporate,
|
|
e.gender,
|
|
e.dob,
|
|
e.doj,
|
|
e.band,
|
|
TIMESTAMPDIFF(YEAR, e.dob, CURDATE()) AS emp_age,
|
|
(
|
|
SELECT name FROM employees
|
|
WHERE relationship = "Self"
|
|
and emp_code = ' . $this->db->escape($emp_code) . '
|
|
and client_id = '.$client_id.'
|
|
and is_active = 1
|
|
and emp_status = "active"
|
|
LIMIT 1
|
|
) AS self,
|
|
|
|
ep.tpa_id,
|
|
ep.uhid,
|
|
cp.policy_end_date,
|
|
ep.basic_cover_si,
|
|
|
|
clients.client_name,
|
|
clients.short_name AS client_short_name,
|
|
|
|
cp.policy_start_date,
|
|
cp.policy_no,
|
|
|
|
insurers.name AS insurer_name,
|
|
insurers.short_name AS insurer_short_name,
|
|
insurers.insurer_logo,
|
|
|
|
insurer_branch.branch_name,
|
|
insurer_branch.branch_code,
|
|
insurer_branch.city as insurer_branch_city,
|
|
|
|
tpa.name AS tpa_name,
|
|
tpa.tpa_logo AS tpa_logo,
|
|
tpa.front_card,
|
|
tpa.back_card,
|
|
tpa.network_hospitals,
|
|
tpa.short_name AS tpa_short_name'
|
|
)
|
|
|
|
->join('employee_polices ep', 'ep.employee_id = e.id')
|
|
->join('client_policy cp', 'cp.id = ep.client_policy_id')
|
|
->join('clients', 'clients.id = cp.client_id')
|
|
->join('insurers', 'insurers.id = cp.insurer_id')
|
|
->join('insurer_branch', 'insurer_branch.id = cp.insurer_branch_id')
|
|
->join('tpa', 'tpa.id = cp.tpa_id')
|
|
->where("ep.tpa_id IS NOT NULL AND ep.tpa_id <> ''")
|
|
->where('e.is_active', '1')
|
|
->whereIn('ep.status', ['active', 'expired'])
|
|
->whereIn('e.emp_status', ['active', 'expired'])
|
|
->where('ep.is_active', '1')
|
|
->where('ep.rand_string', $rand_string)
|
|
->get()
|
|
->getResultArray();
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
public function getExisitingMobileNos(string $client_policy_id)
|
|
{
|
|
$result = $this->select(['employee_polices.id','emp.id as emp_id','emp.relationship','emp.emp_code','emp.name','emp.email_corporate','emp.mobile as mobile'])
|
|
->join('employees emp', 'employee_polices.employee_id = emp.id')
|
|
->join('client_policy cp', 'employee_polices.client_policy_id = cp.id')
|
|
->where('employee_polices.client_policy_id',$client_policy_id)
|
|
->whereIn('employee_polices.status', ['Active'])
|
|
->whereIn('emp.emp_status', ['Active'])
|
|
->where('emp.is_active', 1)
|
|
->where('emp.relationship', 'Self')
|
|
->where('emp.mobile is not null')
|
|
->where('employee_polices.is_active', 1)
|
|
->findAll();
|
|
|
|
return ($result);
|
|
}
|
|
|
|
|
|
public function bulkUpdate($emp_details)
|
|
{
|
|
// Extract IDs, tpa_ids, and uhids
|
|
$ids = array_map('intval', array_column($emp_details, 'id'));
|
|
$tpa_ids = array_column($emp_details, 'tpa_id');
|
|
$uhids = array_column($emp_details, 'uhid');
|
|
|
|
// Escape string values for SQL
|
|
$escapedTpaIds = array_map([$this->db, 'escape'], $tpa_ids);
|
|
$escapedUhids = array_map([$this->db, 'escape'], $uhids);
|
|
|
|
// Construct the CASE statements with int-cast IDs
|
|
$caseTpaId = array_map(function($id, $tpa_id) {
|
|
return "WHEN id = {$id} THEN {$tpa_id}";
|
|
}, $ids, $escapedTpaIds);
|
|
|
|
$caseUhid = array_map(function($id, $uhid) {
|
|
return "WHEN id = {$id} THEN {$uhid}";
|
|
}, $ids, $escapedUhids);
|
|
|
|
// Convert cases to a string
|
|
$caseTpaIdString = implode(' ', $caseTpaId);
|
|
$caseUhidString = implode(' ', $caseUhid);
|
|
|
|
// Convert ids to a string
|
|
$idsString = implode(', ', $ids);
|
|
|
|
// Construct the SQL query
|
|
$sql = "
|
|
UPDATE {$this->table}
|
|
SET
|
|
tpa_id = CASE {$caseTpaIdString} END,
|
|
uhid = CASE {$caseUhidString} END
|
|
WHERE id IN ({$idsString})
|
|
";
|
|
|
|
// Begin a transaction
|
|
$this->db->transBegin();
|
|
|
|
try {
|
|
// Execute the query
|
|
$this->db->query($sql);
|
|
|
|
|
|
// Commit the transaction
|
|
if ($this->db->transStatus() === FALSE) {
|
|
// If something went wrong, rollback
|
|
$this->db->transRollback();
|
|
throw new \Exception('Bulk update failed.');
|
|
} else {
|
|
// Otherwise, commit
|
|
$this->db->transCommit();
|
|
}
|
|
|
|
return $this->db->getLastQuery();
|
|
|
|
} catch (\Exception $e) {
|
|
// Rollback the transaction on error
|
|
$this->db->transRollback();
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
|
|
// public function bulkUpdateForEndorsement($endorsement_details)
|
|
// {
|
|
// // dd($endorsement_details, '---');
|
|
// // Extract IDs, endorsement_ids, and statuses
|
|
// $ids = array_column($endorsement_details, 'group_key');
|
|
// $endorsement_ids = array_column($endorsement_details, 'endorsement_id');
|
|
// $statuses = array_column($endorsement_details, 'status');
|
|
|
|
// // Escape values for SQL
|
|
// $escapedIds = array_map([$this->db, 'escape'], $ids);
|
|
// $escapedEndorsementIds = array_map([$this->db, 'escape'], $endorsement_ids);
|
|
// $escapedStatuses = array_map([$this->db, 'escape'], $statuses);
|
|
|
|
// // Construct the CASE statements
|
|
// $caseEndorsementId = array_map(function ($id, $endorsement_id) {
|
|
// return "WHEN group_key = $id THEN $endorsement_id";
|
|
// }, $escapedIds, $escapedEndorsementIds);
|
|
|
|
// // $caseStatus = array_map(function ($id, $status) {
|
|
// // return "WHEN status = $id THEN $status";
|
|
// // }, $escapedIds, $escapedStatuses);
|
|
|
|
// // Convert cases to a string
|
|
// $caseEndorsementIdString = implode(' ', $caseEndorsementId);
|
|
// // $caseStatusString = implode(' ', $caseStatus);
|
|
|
|
// // Convert ids to a string
|
|
// $idsString = implode(', ', $escapedIds);
|
|
|
|
// // Construct the SQL query
|
|
// $sql = "
|
|
// UPDATE emp_endorsement
|
|
// SET
|
|
// endorsement_id = CASE {$caseEndorsementIdString} END,
|
|
// status = 'complete'
|
|
// WHERE group_key IN ({$idsString})
|
|
// ";
|
|
|
|
|
|
// // dd($sql);
|
|
// // Begin a transaction
|
|
// $this->db->transBegin();
|
|
|
|
// try {
|
|
// // Start the transaction
|
|
// $this->db->transBegin();
|
|
|
|
// // Execute the query
|
|
// $this->db->query($sql);
|
|
|
|
// // Check transaction status
|
|
// if ($this->db->transStatus() === false) {
|
|
// $error = $this->db->error(); // Get the last database error
|
|
// $this->db->transRollback();
|
|
|
|
// // Optionally log the error
|
|
// log_message('error', 'Bulk update failed. Error: ' . json_encode($error));
|
|
|
|
// throw new \Exception('Bulk update failed. Error: ' . $error['message']);
|
|
// }
|
|
|
|
// // Commit if everything is fine
|
|
// $this->db->transCommit();
|
|
|
|
// return $this->db->getLastQuery(); // Optional: return last executed query for debugging
|
|
// } catch (\Exception $e) {
|
|
// $this->db->transRollback();
|
|
|
|
// // Optionally log the exception
|
|
// log_message('error', 'Exception during bulk update: ' . $e->getMessage());
|
|
|
|
// // Re-throw with detailed context
|
|
// throw new \RuntimeException('Exception during bulk update: ' . $e->getMessage(), $e->getCode(), $e);
|
|
// }
|
|
|
|
// }
|
|
|
|
public function bulkUpdateForEndorsement(array $endorsement_details)
|
|
{
|
|
if (empty($endorsement_details)) {
|
|
throw new \InvalidArgumentException("No endorsement details provided.");
|
|
}
|
|
|
|
$caseParts = [];
|
|
$groupKeys = [];
|
|
|
|
foreach ($endorsement_details as $row) {
|
|
$groupKey = (int)$row['group_key'];
|
|
$endorsementId = $this->db->escape($row['endorsement_id']);
|
|
$caseParts[] = "WHEN group_key = {$groupKey} THEN {$endorsementId}";
|
|
$groupKeys[] = $groupKey;
|
|
}
|
|
|
|
$groupKeysStr = implode(', ', $groupKeys);
|
|
$sql = "
|
|
UPDATE emp_endorsement
|
|
SET
|
|
endorsement_id = CASE " . implode(' ', $caseParts) . " END,
|
|
status = 'complete'
|
|
WHERE group_key IN ({$groupKeysStr})
|
|
";
|
|
|
|
$this->db->query($sql);
|
|
|
|
// Check if query was successful
|
|
if ($this->db->affectedRows() === 0) {
|
|
throw new \RuntimeException('No rows were updated.');
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
public function bulkUpdateForCorrection($emp_details){
|
|
|
|
$ids = [];
|
|
$caseStatements = [];
|
|
|
|
$employeeTableFields = $this->db->getFieldNames('employees');
|
|
|
|
foreach ($emp_details as $employee) {
|
|
$id = (int)$employee['id'];
|
|
$ids[] = $id;
|
|
|
|
foreach ($employee as $field => $value) {
|
|
if ($field === 'id') continue;
|
|
|
|
$safeField = preg_replace('/[^a-zA-Z0-9_]/', '', $field);
|
|
if (!in_array($safeField, $employeeTableFields, true)) {
|
|
continue;
|
|
}
|
|
|
|
$escapedValue = $this->db->escape($value);
|
|
|
|
if (!isset($caseStatements[$safeField])) {
|
|
$caseStatements[$safeField] = [];
|
|
}
|
|
|
|
$caseStatements[$safeField][] = "WHEN id = {$id} THEN {$escapedValue}";
|
|
}
|
|
}
|
|
|
|
// Construct the CASE strings
|
|
$caseStrings = [];
|
|
foreach ($caseStatements as $field => $cases) {
|
|
$caseStrings[] = "{$field} = CASE " . implode(' ', $cases) . " END";
|
|
}
|
|
|
|
// Convert ids to a string
|
|
$idsString = implode(', ', $ids);
|
|
|
|
// Construct the SQL query
|
|
$sql = "
|
|
UPDATE employees
|
|
SET " . implode(', ', $caseStrings) . "
|
|
WHERE id IN ($idsString)
|
|
";
|
|
|
|
// Begin a transaction
|
|
$this->db->transBegin();
|
|
|
|
try {
|
|
// Execute the query
|
|
$this->db->query($sql);
|
|
|
|
// Commit the transaction
|
|
if ($this->db->transStatus() === FALSE) {
|
|
// If something went wrong, rollback
|
|
$this->db->transRollback();
|
|
throw new \Exception('Bulk update failed.');
|
|
} else {
|
|
// Otherwise, commit
|
|
$this->db->transCommit();
|
|
}
|
|
|
|
return $this->db->getLastQuery();
|
|
|
|
} catch (\Exception $e) {
|
|
// Rollback the transaction on error
|
|
$this->db->transRollback();
|
|
throw $e;
|
|
}
|
|
|
|
}
|
|
|
|
//for truncate get deletion data
|
|
public function getDeletionDataForTruncated($file_id)
|
|
{
|
|
|
|
$file_id = (int)$file_id;
|
|
|
|
// Fetch the necessary details in a single query using JOINs
|
|
$result = $this->db->table('files f')
|
|
->select('i.deletion_add_day')
|
|
->join('client_policy cp', 'cp.id = f.policy_id', 'left')
|
|
->join('insurers i', 'i.id = cp.insurer_id', 'left')
|
|
->where('f.id', $file_id)
|
|
->get()
|
|
->getRowArray();
|
|
|
|
// Determine if one day should be added for deletion
|
|
$add_one_day = (int)((!empty($result) && $result['deletion_add_day'] == 1) ? 1 : 0);
|
|
|
|
|
|
$query = $this->db->query("
|
|
|
|
SELECT DISTINCT
|
|
|
|
a.id as endorsement_primarykey,
|
|
a.group_key,
|
|
employee_polices.id as primaryKey,
|
|
employees.name AS emp_name,
|
|
employees.emp_code AS emp_code,
|
|
employees.dob AS emp_dob,
|
|
employees.gender AS emp_gender,
|
|
employees.relationship AS emp_relationship,
|
|
employees.relationship_code AS emp_relationship_code,
|
|
employees.emp_type as emp_type,
|
|
'D' as event_type_data,
|
|
TIMESTAMPDIFF(YEAR, employees.dob, CURDATE()) AS emp_age,
|
|
|
|
employees.doj AS emp_doj,
|
|
employees.mobile AS emp_mobile,
|
|
employees.email_corporate AS emp_email_c,
|
|
employees.email_personal AS emp_email_p,
|
|
employees.band AS emp_grade,
|
|
employees.designation AS emp_designation,
|
|
employees.basic_pay AS emp_basic_pay,
|
|
|
|
employee_polices.basic_cover_si,
|
|
employee_polices.uhid as uhid,
|
|
employee_polices.policy_end_date,
|
|
employee_polices.rata_premimum as premium,
|
|
employee_polices.claim_status,
|
|
|
|
deletiondata.empstatus,
|
|
deletiondata.changeevent,
|
|
deletiondata.dateofexit,
|
|
deletiondata.reasonforexit,
|
|
deletiondata.status,
|
|
deletiondata.claimstatus,
|
|
|
|
DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + '$add_one_day' AS no_of_days,
|
|
|
|
CASE
|
|
WHEN deletiondata.claimstatus = 0 OR deletiondata.claimstatus IS NULL THEN
|
|
ROUND((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365, 2)
|
|
ELSE
|
|
0
|
|
END AS pro_rata_premium,
|
|
|
|
CASE
|
|
WHEN deletiondata.claimstatus = 0 OR deletiondata.claimstatus IS NULL THEN
|
|
ROUND(((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365) * 0.18, 2)
|
|
ELSE
|
|
0
|
|
END AS gst,
|
|
|
|
CASE
|
|
WHEN deletiondata.claimstatus = 0 OR deletiondata.claimstatus IS NULL THEN
|
|
ROUND(((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365) +
|
|
(((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365) * 0.18), 2)
|
|
ELSE
|
|
0
|
|
END AS total,
|
|
|
|
CASE
|
|
WHEN deletiondata.claimstatus = 0 OR deletiondata.claimstatus IS NULL THEN
|
|
'No claim'
|
|
ELSE
|
|
'Claim'
|
|
END AS claim_status
|
|
|
|
FROM
|
|
emp_endorsement a
|
|
LEFT JOIN
|
|
employee_polices ON a.pk = employee_polices.id
|
|
LEFT JOIN
|
|
employees ON employee_polices.employee_id = employees.id
|
|
|
|
LEFT JOIN (
|
|
SELECT
|
|
emp_code,
|
|
group_key,
|
|
MAX(CASE WHEN field_name = 'emp_status' THEN new_value END) AS empstatus,
|
|
MAX(CASE WHEN field_name = 'change_event' THEN new_value END) AS changeevent,
|
|
MAX(CASE WHEN field_name = 'date_of_exit' THEN new_value END) AS dateofexit,
|
|
MAX(CASE WHEN field_name = 'reason_for_exit' THEN new_value END) AS reasonforexit,
|
|
MAX(CASE WHEN field_name = 'status' THEN new_value END) AS status,
|
|
MAX(CASE WHEN field_name = 'claim_status' THEN new_value END) AS claimstatus
|
|
FROM
|
|
emp_endorsement
|
|
WHERE
|
|
status != 'truncated'
|
|
GROUP BY
|
|
group_key
|
|
|
|
) AS deletiondata
|
|
|
|
ON a.emp_code = deletiondata.emp_code AND a.status != 'truncated'
|
|
|
|
WHERE a.file_id = {$file_id}
|
|
AND a.actions = 'd'
|
|
AND a.status != 'truncated'
|
|
AND employee_polices.is_active = 1
|
|
AND employees.is_active = 1
|
|
group by group_key
|
|
");
|
|
|
|
|
|
$result = $query->getResultArray();
|
|
// dd($this->db->getLastQuery(), $result);
|
|
// dd($result);
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
//for truncate get addition data
|
|
public function getAdditionDataForTruncated($file_id, $event_type)
|
|
{
|
|
$action = "a";
|
|
if($event_type == "dependent_addition"){
|
|
$action = "da";
|
|
}
|
|
|
|
$file_id = (int)$file_id;
|
|
|
|
$query = $this->db->query("
|
|
|
|
SELECT
|
|
ROUND(SUM(ep.rata_premimum + ep.gst), 2) AS total
|
|
FROM
|
|
emp_endorsement ee
|
|
JOIN
|
|
employee_polices ep ON ee.pk = ep.id
|
|
WHERE
|
|
ee.file_id = $file_id
|
|
AND ee.actions = '$action'
|
|
AND ep.status != 'truncated'
|
|
AND ee.status != 'truncated'
|
|
AND ee.is_active = 1
|
|
AND ep.is_active = 1;
|
|
");
|
|
|
|
|
|
$result = $query->getResultArray();
|
|
// dd($this->db->getLastQuery(), $result);
|
|
// dd($result);
|
|
|
|
|
|
return $result[0];
|
|
|
|
}
|
|
|
|
// reverse the employee policy table data for the truncated the deletion file
|
|
public function updateEmployeePolicyTruncateReverse($file_id)
|
|
{
|
|
log_message('error', 'updateEmployeePolicyTruncateReverse model function called');
|
|
log_message('error', 'FILE ID : {data}', ['data' => $file_id]);
|
|
|
|
$file_id = (int)$file_id;
|
|
|
|
$this->db->query("
|
|
UPDATE employee_polices
|
|
SET
|
|
is_active = 1,
|
|
status = 'active',
|
|
date_of_exit = NULL,
|
|
reason_for_exit = NULL,
|
|
claim_status = 0
|
|
WHERE
|
|
id IN (
|
|
SELECT pk
|
|
FROM emp_endorsement
|
|
WHERE file_id = $file_id
|
|
GROUP BY group_key
|
|
)
|
|
AND status = 'inactive'
|
|
");
|
|
|
|
}
|
|
|
|
//update employee policy table status truncated and is_active 0 for truncated to the addition file
|
|
public function updateEmpEndorsementAddition($array)
|
|
{
|
|
$caseStatus = "CASE ";
|
|
$caseEndorsementId = "CASE ";
|
|
$ids = [];
|
|
foreach ($array as $item) {
|
|
$safeId = (int)$item['id'];
|
|
$safeStatus = $this->db->escape($item['status']);
|
|
$safeEndorsementId = $this->db->escape($item['endorsement_id']);
|
|
$caseStatus .= "WHEN id = {$safeId} THEN {$safeStatus} ";
|
|
$caseEndorsementId .= "WHEN id = {$safeId} THEN {$safeEndorsementId} ";
|
|
$ids[] = $safeId;
|
|
}
|
|
$caseStatus .= "END";
|
|
$caseEndorsementId .= "END";
|
|
$ids = implode(',', $ids);
|
|
$query = "UPDATE emp_endorsement SET status = $caseStatus, endorsement_id = $caseEndorsementId WHERE id IN ($ids);";
|
|
$this->db->query($query);
|
|
}
|
|
|
|
//calculate the CD Transaction sum of the amount for the inception, addition, dependent addition, missed inception
|
|
public function calculateCdTranctionAmount($file_id)
|
|
{
|
|
|
|
$file_id = (int)$file_id;
|
|
|
|
$query = $this->db->query("
|
|
|
|
SELECT
|
|
ROUND(SUM(ep.rata_premimum + ep.gst), 2) AS total
|
|
FROM
|
|
employee_polices ep
|
|
WHERE
|
|
ep.file_id = $file_id
|
|
AND ep.uhid IS NOT NULL
|
|
AND ep.status != 'truncated'
|
|
AND ep.status != 'truncated'
|
|
AND ep.is_active = 1;
|
|
");
|
|
|
|
|
|
$result = $query->getResultArray();
|
|
// dd($this->db->getLastQuery(), $result);
|
|
// dd($result);
|
|
|
|
return $result[0];
|
|
}
|
|
|
|
public function getHospitalLinkByPolicyandEmp($emp_policy_id){
|
|
$data = $this->db->table('employee_polices')
|
|
->select('tpa.network_hospitals')
|
|
->where('employee_polices.id', $emp_policy_id)
|
|
->where('employee_polices.is_active', 1)
|
|
->where('employee_polices.status', 'active')
|
|
// ->where('client_policy.id', $client_policy_id)
|
|
// ->where('employee_polices.is_active', 1)
|
|
->join('client_policy', 'employee_polices.client_policy_id = client_policy.id AND client_policy.is_active = 1')
|
|
->join('tpa', 'tpa.id = client_policy.tpa_id AND tpa.is_active = 1')
|
|
// ->join('employees', 'employees.id = employee_polices.employee_id AND employees.id = ' . (int) $emp_id)
|
|
->get()->getResultArray();
|
|
|
|
// var_dump($this->db->getLastQuery());
|
|
return $data;
|
|
}
|
|
|
|
public function getTPADataVariationReport($client_id, $client_policy_id, $file_id,$emp_codes = [],$all = false)
|
|
{
|
|
$result = $this->select([
|
|
'employee_polices.*',
|
|
'tpam.name as tpa_name',
|
|
'tpam.short_name as tpa_short_name',
|
|
'emp.relationship',
|
|
'emp.relationship_code',
|
|
'emp.change_event',
|
|
'emp.emp_code',
|
|
'emp.name',
|
|
'emp.email_corporate',
|
|
'emp.dob',
|
|
'emp.gender',
|
|
'emp.emp_status',
|
|
'emp.is_active as emp_is_active',
|
|
'emp.mobile as mobile',
|
|
'emp.doj',
|
|
'emp.basic_pay',
|
|
'emp.band as grade',
|
|
'cp.policy_no',
|
|
'cp.policy_type_id',
|
|
|
|
])
|
|
->join('employees emp', 'employee_polices.employee_id = emp.id')
|
|
->join('client_policy cp', 'employee_polices.client_policy_id = cp.id')
|
|
->join('tpa tpam', 'cp.tpa_id = tpam.id', 'left') //tpam - tpa master
|
|
// ->orderBy('emp.emp_code', 'ASC')
|
|
// ->orderBy('employee_polices.employee_id', 'ASC');
|
|
->where('employee_polices.status', 'active')
|
|
->where('employee_polices.is_active', 1)
|
|
->where('emp.is_active', 1)
|
|
->where('employee_polices.status !=', 'inactive')
|
|
->where('cp.id', $client_policy_id)
|
|
->where('employee_polices.client_policy_id', $client_policy_id)
|
|
->where('emp.client_id', $client_id);
|
|
|
|
if(count($emp_codes) == 0 && $all == false)
|
|
{
|
|
$result->where('employee_polices.tpa_id IS NULL');
|
|
}
|
|
else if(count($emp_codes) > 0 && $all == false)
|
|
{
|
|
$result->whereNotIn('employee_polices.id',$emp_codes);
|
|
}
|
|
else if(count($emp_codes) == 0 && $all == true)
|
|
{
|
|
$result->groupBy('emp.emp_code');
|
|
}
|
|
|
|
return $result->findAll();
|
|
// print_r($result);
|
|
// return $result;
|
|
}
|
|
|
|
// for this function using bulk e-card download as a zip
|
|
public function getEmployeeDataWithPolicyUsingClientPolicyIdOrEmployeePolicyIds($params, $limit = 100, $last_id = 0)
|
|
{
|
|
$client_policy_id = $params['client_policy_id'] ?? null;
|
|
$emp_policy_ids = $params['emp_policy_ids'] ?? null;
|
|
|
|
if (empty($client_policy_id) && empty($emp_policy_ids)) {
|
|
return [];
|
|
}
|
|
|
|
$builder = $this->db->table('employee_polices');
|
|
$builder->select('
|
|
employee_polices.id as emp_policy_id,
|
|
employee_polices.client_policy_id,
|
|
employees.name,
|
|
employees.emp_code,
|
|
employees.id as emp_id,
|
|
tpa.short_name,
|
|
employee_polices.tpa_id,
|
|
client_policy.policy_no,
|
|
clients.client_name as client_name,
|
|
clients.short_name as client_short_name
|
|
')
|
|
->join('client_policy', 'client_policy.id = employee_polices.client_policy_id')
|
|
->join('clients', 'clients.id = client_policy.client_id')
|
|
->join('employees', 'employees.id = employee_polices.employee_id')
|
|
->join('tpa', 'tpa.id = client_policy.tpa_id')
|
|
->where([
|
|
'employees.emp_status' => 'active',
|
|
'employees.is_active' => '1',
|
|
'employee_polices.status' => 'active',
|
|
'employee_polices.is_active' => '1',
|
|
])
|
|
->where("employee_polices.tpa_id IS NOT NULL AND employee_polices.tpa_id <> ''");
|
|
|
|
// BATCHING LOGIC: Only get records greater than the last processed ID
|
|
if ($last_id > 0) {
|
|
$builder->where('employee_polices.id >', $last_id);
|
|
}
|
|
|
|
if ($client_policy_id) $builder->where('employee_polices.client_policy_id', $client_policy_id);
|
|
if ($emp_policy_ids) $builder->whereIn('employee_polices.id', $emp_policy_ids);
|
|
|
|
$builder->orderBy('employee_polices.id', 'ASC'); // Critical for keyset pagination
|
|
$builder->limit($limit);
|
|
|
|
return $builder->get()->getResultArray();
|
|
}
|
|
|
|
public function getClientPolicyDetailsByClientPolicyIdOrEmployeePolicyId($params)
|
|
{
|
|
$client_policy_id = $params['client_policy_id'] ?? null;
|
|
$emp_policy_id = $params['emp_policy_id'] ?? null;
|
|
|
|
if (empty($client_policy_id) && empty($emp_policy_id)) {
|
|
return [];
|
|
}
|
|
|
|
$builder = $this->db->table('client_policy');
|
|
$builder->select('client_policy.*')
|
|
->join('employee_polices ep', 'ep.client_policy_id = client_policy.id', 'left');
|
|
|
|
if ($client_policy_id) $builder->where('employee_polices.client_policy_id', $client_policy_id);
|
|
if ($emp_policy_id) $builder->where('employee_polices.id', $emp_policy_id);
|
|
|
|
return $builder->get()->getResultArray();
|
|
}
|
|
|
|
|
|
} |