489 lines
19 KiB
PHP
489 lines
19 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use CodeIgniter\HTTP\IncomingRequest;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
use App\Helpers\DepositHelper;
|
|
use App\Helpers\MailHelper;
|
|
use App\Helpers\sendMailNotification;
|
|
|
|
|
|
use App\Models\EmployeeModel;
|
|
use App\Models\EmployeePolicyModel;
|
|
use App\Models\ClientModel;
|
|
use App\Models\ClientPolicyModel;
|
|
use App\Models\BatchListModel;
|
|
use App\Models\BatchFileModel;
|
|
use App\Models\EmpEndorsementModel;
|
|
|
|
use App\Controllers\Jobs;
|
|
use App\Controllers\JobWorker;
|
|
|
|
use CodeIgniter\API\ResponseTrait;
|
|
|
|
|
|
|
|
class PendingActionsController extends AdminController
|
|
{
|
|
use ResponseTrait;
|
|
|
|
protected $myLogger;
|
|
protected $employeeModel;
|
|
protected $employeePolicyModel;
|
|
protected $clientModel;
|
|
protected $clientPolicyModel;
|
|
protected $batchListModel;
|
|
protected $batchFileModel;
|
|
protected $empEndorsementModel;
|
|
protected $db;
|
|
|
|
public function __construct()
|
|
{
|
|
//section
|
|
set_session_context('PendingActionsController Called');
|
|
|
|
//services
|
|
$this->myLogger = \Config\Services::mylogger();
|
|
$this->db = \Config\Database::connect();
|
|
|
|
//models
|
|
$this->employeeModel = new EmployeeModel();
|
|
$this->employeePolicyModel = new EmployeePolicyModel();
|
|
$this->clientModel = new ClientModel();
|
|
$this->clientPolicyModel = new ClientPolicyModel();
|
|
$this->batchListModel = new BatchListModel();
|
|
$this->batchFileModel = new BatchFileModel();
|
|
$this->empEndorsementModel = new EmpEndorsementModel();
|
|
}
|
|
|
|
|
|
public function getPendingActions()
|
|
{
|
|
//get pending actions like inception, corrections,deletions,SI enhanccnement to users
|
|
|
|
$inception = $this->getPendingActionForInception();
|
|
$correction = $this->getPendingActionForCorrection();
|
|
$si_enhancement = $this->getPendingActionForSIEnhancement();
|
|
$deletion = $this->getPendingActionForDeletion();
|
|
$tpa = $this->getPendingActionForTPAIDEmpty();
|
|
$uhid = $this->getPendingActionForUHIDEmpty();
|
|
|
|
// dd($inception, $si_enhancement, $correction, $deletion, $tpa, $uhid);
|
|
|
|
$data = ['inception' => $inception, 'correction' => $correction, 'si_enhancement' => $si_enhancement, 'deletion' => $deletion, 'tpa' => $tpa, 'uhid' => $uhid];
|
|
return $this->respond($data);
|
|
}
|
|
|
|
|
|
public function getPendingActionForInception()
|
|
{
|
|
|
|
// Build the query
|
|
$builder = $this->db->table('client_policy cp');
|
|
$builder->select('
|
|
clients.client_name,
|
|
policies.name as policy_name,
|
|
cp.id as client_policy_id,
|
|
cp.client_id,
|
|
cp.policy_id,
|
|
cp.policy_type_id,
|
|
cp.is_addon,
|
|
cp.policy_status,
|
|
cp.open_for_enrollment,
|
|
cp.inception_type,
|
|
cb.id as branch_id,
|
|
cb.branch_name,
|
|
COUNT(ep.id) AS employee_policy_count
|
|
');
|
|
$builder->join('employee_polices ep', 'cp.id = ep.client_policy_id AND ep.is_active = 1', 'left');
|
|
$builder->join('clients', 'cp.client_id = clients.id');
|
|
$builder->join('client_branch cb', 'cb.id = cp.client_branch_id');
|
|
$builder->join('policies', 'cp.policy_id = policies.id');
|
|
$builder->where('cp.is_active', 1);
|
|
$builder->where('cp.open_for_enrollment', 1);
|
|
$builder->where('cp.is_addon', 1);
|
|
$builder->where('cp.policy_status', 1);
|
|
$builder->where('cp.inception_type', 1);
|
|
$builder->whereIn('cp.policy_type_id', [1, 2, 3]);
|
|
$builder->groupBy('cp.id, cp.client_id, cp.policy_id, cp.policy_type_id, cp.is_addon, cp.policy_status, cp.open_for_enrollment');
|
|
$builder->having('employee_policy_count = 0 OR employee_policy_count IS NULL');
|
|
|
|
// Execute the query
|
|
$query = $builder->get();
|
|
|
|
// Fetch the results
|
|
$results = $query->getResultArray();
|
|
|
|
return $results;
|
|
}
|
|
|
|
|
|
public function getPendingActionForCorrection()
|
|
{
|
|
|
|
// Subquery for batch_export_count
|
|
$subQueryExport = $this->db->table('batch_files bl')
|
|
->select('COUNT(*)')
|
|
->where('bl.client_id = clients.id')
|
|
->where('bl.actions', 'export')
|
|
->where('bl.event_type', 'correction')
|
|
->where('bl.insurer_or_tpa', 'tpa')
|
|
->getCompiledSelect();
|
|
|
|
// Subquery for batch_import_count
|
|
$subQueryImport = $this->db->table('batch_files bl')
|
|
->select('COUNT(*)')
|
|
->where('bl.client_id = clients.id')
|
|
->where('bl.actions', 'import')
|
|
->where('bl.event_type', 'correction')
|
|
->where('bl.insurer_or_tpa', 'tpa')
|
|
->where('bl.status', 'success')
|
|
->getCompiledSelect();
|
|
|
|
// Subquery builder
|
|
$subqueryBuilder = $this->db->table('emp_endorsement')
|
|
->select('
|
|
|
|
clients.client_name as client_name,
|
|
clients.id as client_id,
|
|
client_branch.id as branch_id,
|
|
client_branch.branch_name,
|
|
emp_endorsement.id,
|
|
emp_endorsement.pk,
|
|
emp_endorsement.endorsement_id,
|
|
emp_endorsement.group_key,
|
|
emp_endorsement.emp_code,
|
|
emp_endorsement.table_name,
|
|
emp_endorsement.actions,
|
|
emp_endorsement.name,
|
|
emp_endorsement.status,
|
|
employees.name as ename
|
|
')
|
|
->join('employees', 'emp_endorsement.pk = employees.id AND employees.is_active = 1 AND employees.emp_status = \'active\'')
|
|
->join('clients', 'employees.client_id = clients.id AND clients.is_active = 1', 'left')
|
|
->join('client_branch', 'client_branch.id = employees.client_branch_id', 'left')
|
|
->where([
|
|
'emp_endorsement.actions' => 'c',
|
|
'emp_endorsement.is_active' => 1,
|
|
'emp_endorsement.status' => 'pending',
|
|
'emp_endorsement.endorsement_id' => null
|
|
])
|
|
->groupBy('emp_endorsement.pk, emp_endorsement.emp_code, emp_endorsement.table_name, emp_endorsement.actions, emp_endorsement.name');
|
|
|
|
// Main query builder
|
|
$builder = $this->db->table('clients');
|
|
$builder->select("
|
|
subquery.client_name,
|
|
subquery.client_id,
|
|
subquery.branch_name,
|
|
subquery.branch_id,
|
|
COUNT(subquery.id) AS subquery_count,
|
|
($subQueryExport) AS batch_export_count,
|
|
($subQueryImport) AS batch_import_count
|
|
");
|
|
$builder->join('(' . $subqueryBuilder->getCompiledSelect() . ') AS subquery', 'clients.id = subquery.client_id', 'left');
|
|
$builder->groupBy('clients.id');
|
|
|
|
// Execute the query
|
|
$query = $builder->get();
|
|
|
|
// Fetch the results
|
|
$results = $query->getResultArray();
|
|
|
|
|
|
$filteredResults = array_filter($results, function ($value) {
|
|
return $value['subquery_count'] != 0;
|
|
});
|
|
|
|
return $filteredResults;
|
|
}
|
|
|
|
|
|
public function getPendingActionForSIEnhancement()
|
|
{
|
|
|
|
// Subquery for batch_export_count
|
|
$subQueryExport = $this->db->table('batch_files bl')
|
|
->select('COUNT(*)')
|
|
->where('bl.client_id = clients.id')
|
|
->where('bl.actions', 'export')
|
|
->where('bl.event_type', 'si_enhancement')
|
|
->where('bl.insurer_or_tpa', 'tpa')
|
|
->getCompiledSelect();
|
|
|
|
// Subquery for batch_import_count
|
|
$subQueryImport = $this->db->table('batch_files bl')
|
|
->select('COUNT(*)')
|
|
->where('bl.client_id = clients.id')
|
|
->where('bl.actions', 'import')
|
|
->where('bl.event_type', 'si_enhancement')
|
|
->where('bl.insurer_or_tpa', 'tpa')
|
|
->where('bl.status', 'success')
|
|
->getCompiledSelect();
|
|
|
|
|
|
// Build the subquery
|
|
$subqueryBuilder = $this->db->table('emp_endorsement')
|
|
->select('
|
|
clients.client_name as client_name,
|
|
clients.id as client_id,
|
|
client_branch.id as branch_id,
|
|
client_branch.branch_name,
|
|
client_policy.id as client_policy_id,
|
|
policies.name as policy_name,
|
|
policies.id as pid,
|
|
emp_endorsement.id,
|
|
emp_endorsement.pk,
|
|
emp_endorsement.endorsement_id,
|
|
emp_endorsement.group_key,
|
|
emp_endorsement.emp_code,
|
|
emp_endorsement.table_name,
|
|
emp_endorsement.actions,
|
|
emp_endorsement.name,
|
|
emp_endorsement.status
|
|
')
|
|
->join('employee_polices', 'emp_endorsement.pk = employee_polices.id AND employee_polices.is_active = 1 AND employee_polices.status = \'active\'')
|
|
->join('client_policy', 'employee_polices.client_policy_id = client_policy.id AND client_policy.is_active = 1 AND client_policy.policy_status = 1')
|
|
->join('clients', 'client_policy.client_id = clients.id AND clients.is_active = 1')
|
|
->join('client_branch', 'client_branch.id = client_policy.client_branch_id')
|
|
->join('policies', 'client_policy.policy_id = policies.id AND policies.is_active = 1')
|
|
->where([
|
|
'emp_endorsement.actions' => 'si',
|
|
'emp_endorsement.is_active' => 1,
|
|
'emp_endorsement.status' => 'pending',
|
|
'emp_endorsement.endorsement_id' => null
|
|
])
|
|
->groupBy('emp_endorsement.pk, emp_endorsement.emp_code, emp_endorsement.table_name, emp_endorsement.actions, emp_endorsement.name');
|
|
|
|
// Build the main query
|
|
$builder = $this->db->table('clients');
|
|
$builder->select("
|
|
clients.id,
|
|
subquery.client_name,
|
|
subquery.client_id,
|
|
subquery.client_policy_id,
|
|
subquery.policy_name,
|
|
subquery.branch_name,
|
|
subquery.branch_id,
|
|
COUNT(subquery.id) AS subquery_count,
|
|
($subQueryExport) AS batch_export_count,
|
|
($subQueryImport) AS batch_import_count
|
|
");
|
|
$builder->join('(' . $subqueryBuilder->getCompiledSelect() . ') AS subquery', 'clients.id = subquery.client_id', 'left');
|
|
$builder->groupBy('clients.id');
|
|
|
|
// Execute the query
|
|
$query = $builder->get();
|
|
|
|
// Fetch the results
|
|
$results = $query->getResultArray();
|
|
|
|
|
|
$filteredResults = array_filter($results, function ($value) {
|
|
return $value['subquery_count'] != 0;
|
|
});
|
|
|
|
return $filteredResults;
|
|
}
|
|
|
|
|
|
public function getPendingActionForDeletion()
|
|
{
|
|
|
|
|
|
// Subquery for batch_export_count
|
|
$subQueryExport = $this->db->table('batch_files bl')
|
|
->select('COUNT(*)')
|
|
->where('bl.client_id = clients.id')
|
|
->where('bl.actions', 'export')
|
|
->where('bl.event_type', 'deletion')
|
|
->where('bl.insurer_or_tpa', 'insurer')
|
|
->getCompiledSelect();
|
|
|
|
// Subquery for batch_import_count
|
|
$subQueryImport = $this->db->table('batch_files bl')
|
|
->select('COUNT(*)')
|
|
->where('bl.client_id = clients.id')
|
|
->where('bl.actions', 'import')
|
|
->where('bl.event_type', 'deletion')
|
|
->where('bl.insurer_or_tpa', 'insurer')
|
|
->where('bl.status', 'success')
|
|
->getCompiledSelect();
|
|
|
|
// Build the subquery
|
|
$subqueryBuilder = $this->db->table('emp_endorsement')
|
|
->select('
|
|
clients.id as client_id,
|
|
clients.client_name as client_name,
|
|
client_branch.id as branch_id,
|
|
client_branch.branch_name,
|
|
client_policy.id as client_policy_id,
|
|
policies.name as policy_name,
|
|
policies.id as pid,
|
|
emp_endorsement.pk,
|
|
emp_endorsement.id,
|
|
emp_endorsement.group_key,
|
|
emp_endorsement.emp_code,
|
|
emp_endorsement.table_name,
|
|
emp_endorsement.actions,
|
|
emp_endorsement.name,
|
|
emp_endorsement.status
|
|
|
|
')
|
|
->join('employee_polices', 'emp_endorsement.pk = employee_polices.id AND employee_polices.is_active = 1 AND employee_polices.status = \'active\' AND emp_endorsement.table_name = \'employee_polices\'', 'left')
|
|
->join('client_policy', 'employee_polices.client_policy_id = client_policy.id AND client_policy.is_active = 1 AND client_policy.policy_status = 1', 'left')
|
|
->join('clients', 'client_policy.client_id = clients.id AND clients.is_active = 1', 'left')
|
|
->join('client_branch', 'client_branch.id = client_policy.client_branch_id', 'left')
|
|
->join('policies', 'client_policy.policy_id = policies.id AND policies.is_active = 1', 'left')
|
|
->where([
|
|
'emp_endorsement.actions' => 'd',
|
|
'emp_endorsement.is_active' => 1,
|
|
'emp_endorsement.status' => 'pending',
|
|
'emp_endorsement.endorsement_id' => null,
|
|
'emp_endorsement.table_name' => 'employee_polices'
|
|
])
|
|
->groupBy('emp_endorsement.pk, emp_endorsement.emp_code, emp_endorsement.actions, emp_endorsement.name');
|
|
|
|
// Build the main query
|
|
$builder = $this->db->table('clients');
|
|
$builder->select("
|
|
clients.id,
|
|
subquery.client_name,
|
|
subquery.client_id,
|
|
subquery.client_policy_id,
|
|
subquery.policy_name,
|
|
subquery.branch_name,
|
|
subquery.branch_id,
|
|
COUNT(subquery.id) AS subquery_count,
|
|
($subQueryExport) AS batch_export_count,
|
|
($subQueryImport) AS batch_import_count
|
|
");
|
|
$builder->join('(' . $subqueryBuilder->getCompiledSelect() . ') AS subquery', 'clients.id = subquery.client_id', 'left');
|
|
$builder->groupBy('clients.id');
|
|
|
|
// Execute the query
|
|
$query = $builder->get();
|
|
|
|
// Fetch the results
|
|
$results = $query->getResultArray();
|
|
|
|
$filteredResults = array_filter($results, function ($value) {
|
|
return $value['subquery_count'] != 0;
|
|
});
|
|
|
|
return $filteredResults;
|
|
}
|
|
|
|
|
|
public function getPendingActionForUHIDEmpty()
|
|
{
|
|
// Subquery for batch_export_count
|
|
$subQueryExport = $this->db->table('batch_files bl')
|
|
->select('COUNT(*)')
|
|
->where('bl.client_policy_id = cp.id')
|
|
->where('bl.actions', 'export')
|
|
->where('bl.event_type', 'inception')
|
|
->where('bl.insurer_or_tpa', 'insurer')
|
|
->getCompiledSelect();
|
|
|
|
// Subquery for batch_import_count
|
|
$subQueryImport = $this->db->table('batch_files bl')
|
|
->select('COUNT(*)')
|
|
->where('bl.client_policy_id = cp.id')
|
|
->where('bl.actions', 'import')
|
|
->where('bl.event_type', 'inception')
|
|
->where('bl.insurer_or_tpa', 'insurer')
|
|
->where('bl.status', 'success')
|
|
->getCompiledSelect();
|
|
|
|
// Main query
|
|
$query = $this->db->table('employee_polices ep')
|
|
->select('c.id as client_id')
|
|
->select('ep.client_policy_id')
|
|
->select('c.client_name')
|
|
->select('c.short_name')
|
|
->select('p.name as policy_name')
|
|
->select('ep.uhid')
|
|
->select('cb.branch_name, cb.id as branch_id')
|
|
->select("($subQueryExport) AS batch_export_count", false)
|
|
->select("($subQueryImport) AS batch_import_count", false)
|
|
->join('client_policy cp', 'ep.client_policy_id = cp.id AND cp.is_active = 1 AND cp.policy_status = 1')
|
|
->join('clients c', 'c.id = cp.client_id')
|
|
->join('client_branch cb', 'cb.id = cp.client_branch_id')
|
|
->join('policies p', 'p.id = cp.policy_id')
|
|
->where('ep.uhid IS NULL')
|
|
->where('ep.status', 'active')
|
|
->where('ep.is_active', 1)
|
|
->groupBy('ep.client_policy_id, ep.uhid, c.short_name, p.name')
|
|
->get();
|
|
|
|
// Fetch the results
|
|
$results = $query->getResultArray();
|
|
|
|
return $results;
|
|
}
|
|
|
|
|
|
public function getPendingActionForTPAIDEmpty()
|
|
{
|
|
|
|
// Subquery for batch_export_count
|
|
$subQueryExport = $this->db->table('batch_files bl')
|
|
->select('COUNT(*)')
|
|
->where('bl.client_policy_id = client_policy.id')
|
|
->where('bl.actions', 'export')
|
|
->where('bl.event_type', 'inception')
|
|
->where('bl.insurer_or_tpa', 'tpa')
|
|
->getCompiledSelect();
|
|
|
|
// Subquery for batch_import_count
|
|
$subQueryImport = $this->db->table('batch_files bl')
|
|
->select('COUNT(*)')
|
|
->where('bl.client_policy_id = client_policy.id')
|
|
->where('bl.actions', 'import')
|
|
->where('bl.event_type', 'inception')
|
|
->where('bl.insurer_or_tpa', 'tpa')
|
|
->where('bl.status', 'success')
|
|
->getCompiledSelect();
|
|
|
|
// Build the query
|
|
$builder = $this->db->table('employee_polices');
|
|
$builder->select('
|
|
|
|
employee_polices.client_policy_id,
|
|
employee_polices.uhid,
|
|
employee_polices.tpa_id,
|
|
clients.short_name,
|
|
clients.client_name,
|
|
policies.name as policy_name,
|
|
clients.id as client_id,
|
|
client_branch.id as branch_id,
|
|
client_branch.branch_name
|
|
');
|
|
$builder->select("($subQueryExport) AS batch_export_count", false);
|
|
$builder->select("($subQueryImport) AS batch_import_count", false);
|
|
|
|
$builder->join('client_policy', 'employee_polices.client_policy_id = client_policy.id AND client_policy.is_active = 1 AND client_policy.policy_status = 1');
|
|
$builder->join('clients', 'clients.id = client_policy.client_id');
|
|
$builder->join('client_branch', 'client_branch.id = client_policy.client_branch_id');
|
|
$builder->join('policies', 'policies.id = client_policy.policy_id');
|
|
$builder->where('employee_polices.tpa_id', null);
|
|
$builder->where('employee_polices.uhid IS NOT NULL');
|
|
$builder->where('employee_polices.status', 'active');
|
|
$builder->where('employee_polices.is_active', 1);
|
|
$builder->groupBy('employee_polices.client_policy_id');
|
|
|
|
// Execute the query
|
|
$query = $builder->get();
|
|
|
|
// Fetch the results
|
|
$results = $query->getResultArray();
|
|
|
|
return $results;
|
|
}
|
|
}
|