diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 4f395843..34b77d02 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -25,6 +25,7 @@ $routes->get('download-kyc-docs/(:segment)', 'ClientController::downloadKYCDocum $routes->get('get-notification', 'DashboardController::getDashboardNotifications'); $routes->get('acknowledge-notification/(:segment)', 'DashboardController::acknowledgeMessage/$1'); +$routes->get('get-pending-action', 'PendingActionsController::getPendingActions'); diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 3fd972b8..c8bbe7ea 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -893,14 +893,18 @@ class EmployeeController extends AdminController '{DOB}' => date('d-M-Y', strtotime($value['dob'])), '{SELF_NAME}' => $value['self'] ?? $value['name'], '{POLICY_DATE}' => date('d-M-Y', strtotime($value['policy_end_date'])), - '{INSURER_NAME}' => $value['insurer_name'], + '{POLICY_START_DATE}' => date('d-M-Y', strtotime($value['policy_start_date'])), + '{POLICY_NO}' => date('d-M-Y', strtotime($value['policy_start_date'])), + '{INSURER_NAME}' => strtoupper($value['insurer_name']), '{INSURER_LOGO}' => base_url() . 'public/uploads/logo/' . $value['insurer_logo'], '{FRONT_CARD}' => base_url() . 'public/uploads/template_bg/' . $value['front_card'], - '{BACK_CARD}' => base_url() . 'public/uploads/logo/' . $value['back_card'], + '{BACK_CARD}' => base_url() . 'public/uploads/template_bg/' . $value['back_card'], '{EMP_ID}' =>$value['emp_code'], '{CORPORATE_NAME}' =>$value['client_name'], '{AGE}' =>$value['emp_age'], - '{TPA_NAME}' =>$value['emp_age'], + '{TPA_NAME}' =>$value['tpa_name'], + '{INSURER_BRANCH}' =>$value['insurer_branch_city'], + '{RELATION}' =>$value['relationship'], '{TPA_LOGO}' => base_url() . 'public/uploads/logo/' . $value['tpa_logo'], ]; @@ -1037,9 +1041,32 @@ class EmployeeController extends AdminController } - public function previewTemplate($id = null){ + public function previewTemplate($id = null) + { + + + $value = [ + 'tpa_id' => 'TPA12345', + 'name' => 'John Doe', + 'uhid' => 'UHID67890', + 'gender' => 'Male', + 'dob' => '1985-05-15', + 'self' => 'John Doe', + 'policy_end_date' => '2024-12-31', + 'policy_start_date' => '2023-01-01', + 'policy_no' => 'POL1234567890', + 'insurer_name' => 'Example Insurance Company', + 'emp_code' => 'EMP001122', + 'client_name' => 'Corporate Client Inc.', + 'emp_age' => 39, + 'tpa_name' => 'Example TPA', + 'insurer_branch_city' => 'New York', + 'relationship' => 'Self' + ]; + + $tpa_id = $this->TPAModel->where('id', $id)->first(); $template_data_path = WRITEPATH . 'e_card_template/'; @@ -1050,28 +1077,44 @@ class EmployeeController extends AdminController $data['message'] = 'Record Not Found'; return view('errors/404', $data); - } + } $tmplt_data = file_get_contents($final_path); $placeholders = [ + '{TPA_ID}' => $value['tpa_id'], + '{NAME}' => $value['name'], + '{UHID}' => $value['uhid'], + '{GENDER}' => $value['gender'], + '{DOB}' => date('d-M-Y', strtotime($value['dob'])), + '{SELF_NAME}' => $value['self'] ?? $value['name'], + '{POLICY_DATE}' => date('d-M-Y', strtotime($value['policy_end_date'])), + '{POLICY_START_DATE}' => date('d-M-Y', strtotime($value['policy_start_date'])), + '{POLICY_NO}' => $value['policy_no'], + '{INSURER_NAME}' => strtoupper($value['insurer_name']), + '{EMP_ID}' => $value['emp_code'], + '{CORPORATE_NAME}' => $value['client_name'], + '{AGE}' => $value['emp_age'], + '{TPA_NAME}' => $value['tpa_name'], + '{INSURER_BRANCH}' => $value['insurer_branch_city'], + '{RELATION}' => $value['relationship'], '{FRONT_CARD}' => base_url() . 'public/uploads/template_bg/' . $tpa_id['front_card'], - '{BACK_CARD}' => base_url() . 'public/uploads/logo/' . $tpa_id['back_card'], + '{BACK_CARD}' => base_url() . 'public/uploads/template_bg/' . $tpa_id['back_card'], + '{TPA_LOGO}' => base_url() . 'public/uploads/logo/' . $tpa_id['tpa_logo'], + '{INSURER_LOGO}' => base_url() . 'public/assets/images/sample_logo_3.png', ]; - + // Get the values to replace the placeholders $replaceValues = array_values($placeholders); - + // Get the placeholders to search for $searchPlaceholders = array_keys($placeholders); - + // Replace placeholders with values in HTML content $htmlContent = str_replace($searchPlaceholders, $replaceValues, $tmplt_data); - echo $htmlContent; - - + echo $htmlContent; } diff --git a/app/Controllers/PendingActionsController.php b/app/Controllers/PendingActionsController.php index 9670dbba..457b06b9 100644 --- a/app/Controllers/PendingActionsController.php +++ b/app/Controllers/PendingActionsController.php @@ -7,20 +7,351 @@ 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, + 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('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, 30]); + $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 builder + $subqueryBuilder = $this->db->table('emp_endorsement') + ->select(' + + clients.client_name as client_name, + clients.id as client_id, + 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') + ->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, + COUNT(subquery.id) AS subquery_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() + { + + // Build the subquery + $subqueryBuilder = $this->db->table('emp_endorsement') + ->select(' + clients.client_name as client_name, + clients.id as client_id, + 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('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, + COUNT(subquery.id) AS subquery_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() + { + + // Build the subquery + $subqueryBuilder = $this->db->table('emp_endorsement') + ->select(' + clients.client_name as client_name, + clients.id as client_id, + 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('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, + COUNT(subquery.id) AS subquery_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() + { + // Build the query + $builder = $this->db->table('employee_polices'); + $builder->select(' + employee_polices.client_policy_id, + employee_polices.uhid, + clients.short_name, + clients.client_name, + policies.name as policy_name, + clients.id as client_id + '); + $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('policies', 'policies.id = client_policy.policy_id'); + $builder->where('employee_polices.uhid', 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; + } + + + public function getPendingActionForTPAIDEmpty() + { + + // 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 + '); + $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('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; + } } diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 5b5caf18..852fcb1b 100644 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -731,6 +731,7 @@ class EmployeePolicyModel extends Model clients.short_name AS client_short_name, cp.policy_start_date, + cp.policy_no, policies.name AS policy_name, diff --git a/app/Views/batch_list.php b/app/Views/batch_list.php index c08961b8..1ba623f7 100644 --- a/app/Views/batch_list.php +++ b/app/Views/batch_list.php @@ -2,6 +2,10 @@ .table-responsive { overflow-x: auto; } + + .reload:hover { + cursor: pointer; + }