diff --git a/.gitignore b/.gitignore index 1f8cb67a..2e2d6962 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,9 @@ writable/debugbar/* writable/**/*.db writable/**/*.sqlite +writable/e_card_template/* +!writable/e_card_template/.gitkeep + vendor/ build/ diff --git a/app/Config/Routes.php b/app/Config/Routes.php index d6624888..130ae94e 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -23,6 +23,11 @@ $routes->get('download-e-card/(:segment)', 'EmployeeController::generateIDCardFo $routes->get('download-kyc-docs/(:segment)', 'ClientController::downloadKYCDocument/$1'); +$routes->get('get-notification', 'DashboardController::getDashboardNotifications'); +$routes->get('acknowledge-notification/(:segment)', 'DashboardController::acknowledgeMessage/$1'); +$routes->get('get-pending-action', 'PendingActionsController::getPendingActions'); + + $routes->group("/user", ["filter" => "authMVC"], function ($routes) { $routes->post("create", "UserController::create"); @@ -228,6 +233,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get("id-card", "EmployeeController::viewECard/$1"); $routes->get("preview-card/(:any)", "EmployeeController::previewTemplate/$1"); $routes->get("export-import-error-list/(:any)", "EmployeeController::errorListExportImport/$1"); + $routes->get("has_policy_config_completed/(:any)", "EmployeeController::hasPolicyConfigCompleted/$1"); }); $routes->cli('cli/processjob', 'JobWorker::processJob'); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 8b0c17ee..5b210e39 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -653,6 +653,7 @@ class ClientController extends AdminController } + $data['policy_no'] = $this->request->getPost('policy_no'); $data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d'); $data['policy_end_date'] = change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d'); $data['created_by'] = get_session_userid(); @@ -696,6 +697,7 @@ class ClientController extends AdminController $data['tpa_id'] = $tpaId; $data['policy_id'] = $this->request->getPost('policy_id'); $data['policy_type_id'] = $this->request->getPost('policy_type_id'); + $data['policy_no'] = $this->request->getPost('policy_no'); $data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d'); $data['policy_end_date'] = change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d'); @@ -741,6 +743,7 @@ class ClientController extends AdminController // dd($data); $data['updated_by'] = get_session_userid(); + // print_r($data);die; $insert = $this->clientPolicyModel->update($id,$data); $lastQuery = $this->clientPolicyModel->getLastQuery(); @@ -767,18 +770,18 @@ class ClientController extends AdminController $policy_type = $this->request->getPost('policy_type'); $client_id = $this->request->getPost('client_id'); $client_policy_id = $this->request->getPost('client_policy_id'); - // $premium_type = $this->request->getPost('premium_type'); + $premium_type = $this->request->getPost('premium_type'); if (!empty($client_id) && $client_id != null) { $client_policy_data = $this->clientPolicyModel->where('id', $client_policy_id)->first(); $client_id = $client_policy_data['client_id']; } $policy_grid_id = $this->request->getPost('policy_grid_id'); - if($policy_grid_id == 10 || $policy_grid_id == 11){ - $premium_type = 1; - }else{ - $premium_type = 2; - } + // if($policy_grid_id == 10 || $policy_grid_id == 11){ + // $premium_type = 1; + // }else{ + // $premium_type = 2; + // } $si_or_bp = $this->request->getPost('si_or_bp'); $basic_multiplier = str_replace(',', '', $this->request->getPost('basic_multiplier')); @@ -1119,15 +1122,18 @@ class ClientController extends AdminController ->join('employee_polices ep', "cp.id = ep.client_policy_id AND employees.id = ep.employee_id") ->where("employees.client_id", $record['client_id']) ->where("employees.emp_status", 'active') + ->where("ep.status", 'active') + ->where("employees.is_active", 1) + ->where("ep.is_active", 1) ->countAllResults(); - $data = $this->employeePolicyModel->select('employee_polices.id') - ->where('employee_polices.is_active', 1) - ->where('employee_polices.client_policy_id', $client_policy_id) - ->findAll(); + // $data = $this->employeePolicyModel->select('employee_polices.id') + // ->where('employee_polices.is_active', 1) + // ->where('employee_polices.client_policy_id', $client_policy_id) + // ->findAll(); - $emp_count = count($data); + // $emp_count = count($data); // if($emp_count == 0){ // $emp_count = true; @@ -1173,24 +1179,25 @@ class ClientController extends AdminController if ($search_term === 'GMC') { - $resultss = []; + // $resultss = []; + $resultss = $results; - try { - foreach ($results as $index => $record) { - // if ($self->self == 1 && $self->spouse == 0 && $self->childrens == 0 && $self->parents == 0 && $self->{'parents-in-law'} == 0 && $self->{'either-parents-pil'} == 0 && $family_floater == 0) { - if ($family_floater == 1) { - if ($index == '7' || $index == '8' || $index == '9' || $index == '10') { - $resultss[$index] = $record; - } - } else { - if ($index == '0' || $index == '1' || $index == '2' || $index == '3' || $index == '4' || $index == '5' || $index == '6') { - $resultss[$index] = $record; - } - } - } - } catch (\Exception $e) { - $resultss = $results; // Reset $resultss to an empty array if an exception occurs - } + // try { + // foreach ($results as $index => $record) { + // // if ($self->self == 1 && $self->spouse == 0 && $self->childrens == 0 && $self->parents == 0 && $self->{'parents-in-law'} == 0 && $self->{'either-parents-pil'} == 0 && $family_floater == 0) { + // if ($family_floater == 1) { + // if ($index == '7' || $index == '8' || $index == '9' || $index == '10') { + // $resultss[$index] = $record; + // } + // } else { + // if ($index == '0' || $index == '1' || $index == '2' || $index == '3' || $index == '4' || $index == '5' || $index == '6') { + // $resultss[$index] = $record; + // } + // } + // } + // } catch (\Exception $e) { + // $resultss = $results; // Reset $resultss to an empty array if an exception occurs + // } @@ -1247,7 +1254,6 @@ class ClientController extends AdminController $data['corporatebuffer'] = $this->request->getPost("corporatebuffer") ? $this->request->getPost("corporatebuffer") : 0; $data['family_floaters'] = $this->request->getPost("family_floaters") ?? []; - // print_r($this->request->getPost());die; $data['age_ratio']['self']['min'] = $this->request->getPost("self_min_age") ? $this->request->getPost("self_min_age") :0; $data['age_ratio']['self']['max'] = $this->request->getPost("self_max_age") ? $this->request->getPost("self_max_age") : 0; $data['age_ratio']['spouse']['min'] = $this->request->getPost("spouse_min_age") ? $this->request->getPost("spouse_min_age") : 0; @@ -1255,7 +1261,7 @@ class ClientController extends AdminController $data['age_ratio']['child']['min'] = $this->request->getPost("child_min_age") ? $this->request->getPost("child_min_age") : 0; $data['age_ratio']['child']['max'] = $this->request->getPost("child_max_age") ? $this->request->getPost("child_max_age") : 0; $data['age_ratio']['elders']['min'] = $this->request->getPost("other_member_min_age") ? $this->request->getPost("other_member_min_age") :0; - $data['age_ratio']['elders']['max'] = $this->request->getPost("other_member_min_age") ? $this->request->getPost("other_member_min_age") : 0; + $data['age_ratio']['elders']['max'] = $this->request->getPost("other_member_max_age") ? $this->request->getPost("other_member_max_age") : 0; @@ -1331,6 +1337,8 @@ class ClientController extends AdminController $data['family_floaters']['elders_count'] =$this->request->getPost("member_count") ? $this->request->getPost("member_count") : 0; + // print_r($data);die; + $data['waiverofpreexistingdiseases'] =$this->request->getPost("waiverofpreexistingdiseases"); if ($data['waiverofpreexistingdiseases'] == 1) { $data['maternitycoverage'] =str_replace(',', '',$this->request->getPost("maternitycoverage")); diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 1a370981..1378abbf 100644 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -7,12 +7,22 @@ use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; +use CodeIgniter\API\ResponseTrait; + +use App\Models\MessageModel; +use App\Models\UserMessageModel; + class DashboardController extends AdminController { + use ResponseTrait; + protected $messageModel; + protected $userMessageModel; + public function __construct() { - + $this->messageModel = new MessageModel(); + $this->userMessageModel = new UserMessageModel(); } public function dashboard() @@ -22,11 +32,26 @@ class DashboardController extends AdminController echo view('layout/footer'); } - public function dashboardNotifications() + public function getDashboardNotifications() { //pull notofications to dashboard especially for file upload cases + $userId = get_session_userid(); + $roleId = 5; + $teamId = 1; + + $messages = $this->messageModel->getMessagesForUser($userId, $roleId, $teamId); + + return $this->respond($messages); + } + + public function acknowledgeMessage($messageId) + { + $userId = get_session_userid(); + + $this->userMessageModel->markAsRead($userId, $messageId); + + return $this->respond(['status' => 'success']); } - } diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 826c8a6b..69f19725 100644 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -22,6 +22,8 @@ use App\Models\BatchFileModel; use App\Models\EmpEndorsementModel; use App\Models\ClientDepositModel; use App\Models\NotificationModel; +use App\Models\MessageModel; +use App\Models\UserMessageModel; use App\Controllers\Jobs; use App\Controllers\JobWorker; @@ -48,6 +50,8 @@ class EmpDataServiceController extends BaseController protected $empEndorsementModel; protected $clientDepositModel; protected $notificationModel; + protected $messageModel; + protected $userMessageModel; public function __construct() { @@ -64,6 +68,8 @@ class EmpDataServiceController extends BaseController $this->empEndorsementModel = new EmpEndorsementModel(); $this->clientDepositModel = new ClientDepositModel(); $this->notificationModel = new NotificationModel(); + $this->messageModel = new MessageModel(); + $this->userMessageModel = new UserMessageModel(); } @@ -638,7 +644,10 @@ class EmpDataServiceController extends BaseController $this->batchFileModel->where('id', $file_id)->set($data)->update(); $this->myLogger->logme('error', 'importInceptionFileValidation TPAID already updated'); - return 3; + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'The list of employees provided has already been updated with the TPA ID, or this is not the correct file'; } else if ($insurer_or_tpa == 'insurer') { @@ -649,7 +658,10 @@ class EmpDataServiceController extends BaseController $this->batchFileModel->where('id', $file_id)->set($data)->update(); $this->myLogger->logme('error', 'importInceptionFileValidation UHID already updated'); - return 5; + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'The list of employees provided has already been updated with the UHID, or this is not the correct file'; } $this->myLogger->logme('error', 'importInceptionFileValidation UHID or TPAID already updated or the uploadedfile is not correct'); @@ -685,7 +697,10 @@ class EmpDataServiceController extends BaseController $this->batchFileModel->where('id', $file_id)->set($data)->update(); $this->myLogger->logme('error', 'importInceptionFileValidation excel file count ( {excel} ) exceeds db count ( {db} )', ['db' => $emp_data_count, 'excel' => $excel_data_count]); - return 6; + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'The Excel record count exceeds the DB record count. excel file count : ' . $excel_data_count . 'db count : ' . $emp_data_count; } @@ -877,11 +892,17 @@ class EmpDataServiceController extends BaseController if ($insurer_or_tpa == 'tpa') { - return 2; + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'The TPA ID column is either partially or entirely empty.'; } else if ($insurer_or_tpa == 'insurer') { - return 4; + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'The UHID column is either partially or entirely empty.'; } } @@ -923,6 +944,7 @@ class EmpDataServiceController extends BaseController $job_details = new Jobs(); $r = Jobs::addJob(['job_name' => 'importInceptionUpdateTPAandUHID','payload' => ['file_id' => $file_id]]); + // $this->importInceptionUpdateTPAandUHID(['file_id' => $file_id]); } @@ -938,6 +960,7 @@ class EmpDataServiceController extends BaseController $file_id = $params['file_id']; $file = $this->batchFileModel->find($file_id); if (!$file) { + $data = [ 'status' => 'failed-4', ]; @@ -945,7 +968,10 @@ class EmpDataServiceController extends BaseController $this->batchFileModel->where('id', $file_id)->set($data)->update(); $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID the Physical file not found - file id : {data}', ['data' => $file_id]); - return 0; // Return error code if file not found + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'importInceptionUpdateTPAandUHID the Physical file not found'; // Return error code if file not found } $client_id = $file['client_id']; @@ -955,6 +981,15 @@ class EmpDataServiceController extends BaseController $batch_code = $file['batch_code']; $user_id = $file['created_by']; + + $get_policy_type = $this->clientPolicyModel + ->select('policy_type.policy_type, policies.policy_type_id as policy_type_id') + ->join('policies', 'policies.id = client_policy.policy_id') + ->join('policy_type', 'policy_type.id = policies.policy_type_id') + ->where('client_policy.id', $client_policy_id) + ->first(); + + $status_val = 'success'; if ($status == 'in-progress-partially') { @@ -970,16 +1005,21 @@ class EmpDataServiceController extends BaseController array_pop($excel_data); // Remove footer row $totals = 0; - $empty_emp_tpa_uh_ids = []; + $emp_policy_ids = []; + $emp_details = []; + $tpa_id = []; + $uhid = []; + $emp_count = count($excel_data); $db = \Config\Database::connect(); + foreach ($excel_data as $key => $value) { $name = $value[1]; $emp_code = $value[2]; - $tpa_id = $value[15]; - $uhid = $value[16]; + $tpa_id[] = $value[15]; + $uhid[] = $value[16]; $amount = $value[20]; $totals += $amount; @@ -1006,38 +1046,41 @@ class EmpDataServiceController extends BaseController // Get the result $result = $query->get()->getRowArray(); if (isset($result['id']) && $result['id'] !== null) { - $empty_emp_tpa_uh_ids[] = $result['id']; + $emp_policy_ids[] = $result['id']; + $emp_details[] = array('id' => $result['id'],'tpa_id' => $value[15], 'uhid' => $value[16]); } - $sql = " - UPDATE employee_polices - JOIN employees ON employees.id = employee_polices.employee_id - SET tpa_id = ? - WHERE employees.name = ? - AND employees.emp_code = ? - AND employee_polices.client_policy_id = ? - AND (employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = '')"; + // $sql = " + // UPDATE employee_polices + // JOIN employees ON employees.id = employee_polices.employee_id + // SET tpa_id = ? + // WHERE employees.name = ? + // AND employees.emp_code = ? + // AND employee_polices.client_policy_id = ? + // AND (employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = '')"; - $params = [$tpa_id, $name, $emp_code, $client_policy_id]; - $db->query($sql, $params); + // $params = [$tpa_id, $name, $emp_code, $client_policy_id]; + // $db->query($sql, $params); - $sql = " - UPDATE employee_polices - JOIN employees ON employees.id = employee_polices.employee_id - SET employee_polices.uhid = ? - WHERE employees.name = ? - AND employees.emp_code = ? - AND employee_polices.client_policy_id = ? - AND (employee_polices.uhid IS NULL OR employee_polices.uhid = '')"; + // $sql = " + // UPDATE employee_polices + // JOIN employees ON employees.id = employee_polices.employee_id + // SET employee_polices.uhid = ? + // WHERE employees.name = ? + // AND employees.emp_code = ? + // AND employee_polices.client_policy_id = ? + // AND (employee_polices.uhid IS NULL OR employee_polices.uhid = '')"; - $params = [$uhid, $name, $emp_code, $client_policy_id]; - $db->query($sql, $params); + // $params = [$uhid, $name, $emp_code, $client_policy_id]; + // $db->query($sql, $params); } + $return = $this->employeePolicyModel->bulkUpdate($emp_details); + // Update batch file status and amount $this->batchFileModel->update($file_id, [ 'count' => $emp_count, @@ -1057,7 +1100,7 @@ class EmpDataServiceController extends BaseController $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id); $depositeData = [ - 'employeeIds' => $empty_emp_tpa_uh_ids, + 'employeeIds' => $emp_policy_ids, 'client_id' => $client_id, 'client_policy_id' => $client_policy_id, 'count' => $emp_count, @@ -1070,7 +1113,7 @@ class EmpDataServiceController extends BaseController $job_details = new Jobs(); $r = Jobs::addJob(['job_name' => 'cashDepositCalculationForInception','payload' => [ - 'employeeIds' => $empty_emp_tpa_uh_ids, + 'employeeIds' => $emp_policy_ids, 'client_id' => $client_id, 'client_policy_id' => $client_policy_id, 'count' => $emp_count, @@ -1079,17 +1122,23 @@ class EmpDataServiceController extends BaseController 'user_id' => $user_id, ]]); + if($get_policy_type['policy_type_id'] != 1){ - $job_details = new Jobs(); - $r = Jobs::addJob(['job_name' => 'sendMailForDownloadingECard','payload' => $empty_emp_tpa_uh_ids]); + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'sendMailForDownloadingECard','payload' => $emp_policy_ids]); + + } // $this->cashDepositCalculationForInception($depositeData); - // $this->sendMailForDownloadingECard($empty_emp_tpa_uh_ids); - + // $this->sendMailForDownloadingECard($emp_policy_ids); } - return 1; + $file_data = $this->getDataByFileId($file_id, 'success'); + $this->setPullNotification($file_data); + + + return 'Import Inception Updated '. $status_val . '- Updated Count : ' . $emp_count; } @@ -2063,10 +2112,12 @@ class EmpDataServiceController extends BaseController $this->myLogger->logme('error', 'sendMailForDownloadingECard - inside try'); $count = 0; + $counts = 0; + foreach ($ids as $key => $id) { $get_emp_email_and_other_details = $this->employeePolicyModel - ->select('employee_polices.client_policy_id, employees.emp_code, employees.email_corporate,employees.client_id as client_id, employees.name, employee_polices.rand_string, employee_polices.tpa_id') + ->select('employee_polices.client_policy_id, employees.relationship, employees.emp_code, employees.email_corporate,employees.client_id as client_id, employees.name, employee_polices.rand_string, employee_polices.tpa_id') ->join('employees', 'employees.id = employee_polices.employee_id') ->where('employees.emp_status', 'active') ->where('employees.is_active', '1') @@ -2091,19 +2142,28 @@ class EmpDataServiceController extends BaseController $params['notification'] = $notification; $params['notification'] = $notification; $params['get_emp_email_and_other_details'] = $get_emp_email_and_other_details; - $wholeData[] = sendMailNotification::sendMailNotification('member_ecard_mail', $params); + // $this->myLogger->logme('error', 'sendMailForDownloadingECard - Send Bulk Mail function end ',); - $count++; + if (isset($get_emp_email_and_other_details['email_corporate']) && !empty($get_emp_email_and_other_details['email_corporate']) && $get_emp_email_and_other_details['relationship'] === 'Self') { + $wholeData[] = sendMailNotification::sendMailNotification('member_ecard_mail', $params); + $count++; + } + $counts++; + - if ($count == 20 || $count == count($ids) - 1) { + if ($count == 20 || $counts == count($ids) - 1) { + if(count($wholeData) > 0){ - $this->myLogger->logme('error', 'sendMailForDownloadingECard - create a job to bulk mail',); + $this->myLogger->logme('error', 'sendMailForDownloadingECard - create a job to bulk mail',); + + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $wholeData]); + $wholeData = []; + $count = 0; + + } - $job_details = new Jobs(); - $r = Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $wholeData]); - $wholeData = []; - $count = 0; } $this->myLogger->logme('error', 'sendMailForDownloadingECard - Send Bulk Mail function end ',); @@ -2174,4 +2234,58 @@ class EmpDataServiceController extends BaseController } + + + public function getDataByFileId($file_id, $status = 'success'){ + + $data = $this->batchFileModel + ->select('batch_files.*, clients.client_name, clients.short_name, policies.name as policy_name') + ->join('clients', 'clients.id = batch_files.client_id') + ->join('client_policy', 'client_policy.id = batch_files.client_policy_id') + ->join('policies', 'policies.id = client_policy.policy_id') + ->where('batch_files.id', $file_id) + ->first(); + + + if($status == 'success'){ + + $msg_txt = $data['short_name'] . ' - ' . $data['policy_name'] . ' - ' . $data['event_type'] . ' - ' . $data['actions'] . ' - ' . $data['insurer_or_tpa']; + $msg_title = 'File Upload Success'; + + }else if ($status == 'failure'){ + + $msg_txt = $data['short_name'] . ' - ' . $data['policy_name'] . ' - ' . $data['event_type'] . ' - ' . $data['actions'] . ' - ' . $data['insurer_or_tpa']; + $msg_title = 'File Upload Failure'; + } + + $user_id = $data['created_by']; + $url = 'employee/upload#KYC-DOC-tab'; + + return ['msg_txt' => $msg_txt, 'user_id' => $user_id, 'url' => $url, 'status' => $status, 'title' => $msg_title]; + } + + + public function setPullNotification($data){ + + + $array = ['message_text' => $data['msg_txt'], 'action_url' => $data['url'], 'msg_status' => $data['status'], 'msg_title' => $data['title']]; + $jsonEncodeData = json_encode($array); + + $msg_data = [ + + 'message_text' => $jsonEncodeData, + 'user_id' => $data['user_id'], + 'role_id' => NULL, + 'team_id' => NULL, + 'message_type' => '1to1', + ]; + + + $this->messageModel->insert($msg_data); + + + } + + + } diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 5692668a..f6a0dc8f 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -11,6 +11,7 @@ use Psr\Log\LoggerInterface; use App\Models\EmployeeModel; use App\Models\EmployeePolicyModel; use App\Models\ClientModel; +use App\Models\PolicesModel; use App\Models\FileModel; use App\Models\BatchListModel; use App\Models\BatchFileModel; @@ -49,6 +50,7 @@ class EmployeeController extends AdminController protected $empEndorsementModel; protected $clientPolicyModel; protected $TPAModel; + protected $policiesModel; public function __construct() { @@ -64,6 +66,7 @@ class EmployeeController extends AdminController $this->empEndorsementModel = new EmpEndorsementModel(); $this->clientPolicyModel = new ClientPolicyModel(); $this->TPAModel = new TPAModel(); + $this->policiesModel = new PolicesModel(); } public function list() @@ -213,13 +216,40 @@ class EmployeeController extends AdminController $data['import_or_export'] = ['import' => 'Import', 'export' => 'Export']; $data['insurer_or_tpa'] = ['insurer' => 'Insurer', 'tpa' => 'TPA']; + // $data['fileList'] = $this->fileModel + // ->select(['files.*', 'up.emp_code', 'up.first_name', 'pm.name as policy_name', 'c.short_name', 'cp.id as client_policy_id']) + // ->join('user_profiles up', 'files.created_by = up.id') + // ->join('client_policy cp', 'files.policy_id = cp.id', 'left') + // ->join('policies pm', 'cp.policy_id = pm.id', 'left') + // ->join('clients c', 'files.client_id = c.id and files.client_id = cp.client_id', 'left') + // ->where('files.created_by', get_session_userid())->orderBy('files.created_at', 'desc')->findAll(); + // dd($this->fileModel->getLastQuery()); + $data['fileList'] = $this->fileModel - ->select(['files.*', 'up.emp_code', 'up.first_name', 'pm.name as policy_name', 'c.short_name', 'cp.id as client_policy_id']) - ->join('user_profiles up', 'files.created_by = up.id') - ->join('client_policy cp', 'files.policy_id = cp.id', 'left') - ->join('policies pm', 'cp.policy_id = pm.id', 'left') - ->join('clients c', 'files.client_id = c.id and files.client_id = cp.client_id', 'left') - ->where('files.created_by', get_session_userid())->orderBy('files.created_at', 'desc')->findAll(); + ->select([ + 'files.*', + 'up.emp_code', + 'up.first_name', + 'pm.name as policy_name', + 'c.short_name', + 'cp.id as client_policy_id', + '(SELECT COUNT(*) + FROM employees e + JOIN employee_polices ep ON e.id = ep.employee_id + WHERE e.file_id = files.id AND ep.client_policy_id = files.policy_id) as employee_count', + '(SELECT SUM(ep.rata_premimum) + SUM(ep.gst) + FROM employees e + JOIN employee_polices ep ON e.id = ep.employee_id + WHERE e.file_id = files.id AND ep.client_policy_id = files.policy_id) as total' + ]) + ->join('user_profiles up', 'files.created_by = up.id') + ->join('client_policy cp', 'files.policy_id = cp.id', 'left') + ->join('policies pm', 'cp.policy_id = pm.id', 'left') + ->join('clients c', 'files.client_id = c.id and files.client_id = cp.client_id', 'left') + ->where('files.created_by', get_session_userid()) + ->orderBy('files.created_at', 'desc') + ->findAll(); + // dd($data['fileList']); $data['batch_list'] = $this->batchFileModel->select('batch_files.*, policies.name as policy_name, clients.short_name as client_short_name') ->join('client_policy', 'client_policy.id = batch_files.client_policy_id') @@ -890,14 +920,19 @@ 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'], ]; // Replace placeholders with values in HTML content @@ -1033,9 +1068,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/'; @@ -1046,28 +1104,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; } @@ -1147,4 +1221,29 @@ class EmployeeController extends AdminController echo view('export_import_error_list', $excelErrorData); } + public function hasPolicyConfigCompleted() + { + $client_policy_id = $this->request->uri->getSegment(3); + $policy_details = $this->clientPolicyModel->find($client_policy_id); + // print_r($policy_details);die(); + $policy_terms = isset($policy_details['policy_terms']) ? true : false; + + $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$policy_details['client_id']); + + $message = null; + + if (!isset($policy_terms)) { + $message .= 'Policy terms'; + } + + if($slab_details['slab_rates'] == null && $slab_details['grid_master'] == null) + { + $message = isset($message) ? ($message . ' and rack rates ') : ($message . ' Rack rates'); + } + $message = isset($message) ? ($message . ' not defined for choosed policy') : null; + + return $this->respond(['dataStatus' => true, 'code' => 200, 'message' => $message], 200); + + } + } diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index d5613fc1..f9c09741 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -877,7 +877,7 @@ class EmployeeRestController extends AdminController if (isset($notification) && $notification['enabled'] == 1) { //trigger - if ($dataToInsert[$a]['relationship'] == 'Self') { + if ($dataToInsert[$a]['relationship'] == 'Self' && isset($dataToInsert[$a]['email_corporate']) && !empty($dataToInsert[$a]['email_corporate'])) { $params['dataToInsert'] = $dataToInsert[$a]; $params['notification'] = $notification; @@ -887,13 +887,12 @@ class EmployeeRestController extends AdminController $count++; } if($count == 20 || $a == count($dataToInsert)-1){ - $job_details = new Jobs(); - $r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $wholeData]); - // $wholeData[]= $r; - - // Mailhelper::bulk_mail($wholeData); - $wholeData = []; - $count = 0; + if (count($wholeData) > 0) { + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $wholeData]); + $wholeData = []; + $count = 0; + } } diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 085c2727..6e6bb123 100644 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -15,6 +15,7 @@ use App\Models\ClientPolicyModel; use App\Models\PolicesModel; use App\Models\FileModel; use App\Models\EmpEndorsementModel; +use App\Models\MessageModel; use App\Controllers\Jobs ; use App\Controllers\JobWorker ; @@ -33,6 +34,7 @@ class EmployeeServiceController extends AdminController protected $clientPolicyModel; protected $policiesModel; protected $empEndorsementModel; + protected $messageModel; protected $general_relationships = ['self' => ['name' => 'Self', 'gender' => 'M','age_min' => 18,'age_max' => null], 'spouse' => ['name' => 'Spouse', 'gender' => 'F','age_min' => 18,'age_max' => null], 'son' => ['name' => 'Son', 'gender' => 'M','age_min' => null,'age_max' => 25], 'daughter' => ['name' => 'Daughter', 'gender' => 'F','age_min' => null,'age_max' => 25], 'father' => ['name' => 'Father', 'gender' => 'M','age_min' => 18,'age_max' => null], 'mother' => ['name' => 'Mother', 'gender' => 'F','age_min' => 18,'age_max' => null], 'father-in-law' => ['name' => 'Father in Law', 'gender' => 'M','age_min' => 18,'age_max' => null], 'mother-in-law' => ['name' => 'Mother in Law', 'gender' => 'F','age_min' => 18,'age_max' => null]]; protected $inception_excel_columns = ['sno'=>['col_idx'=>0,'col_cell_name'=>'A','col_name'=>'S.No','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'emp_id'=>['col_idx'=>1,'col_cell_name'=>'B','col_name'=>'EMP ID','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'name_of_emp_dep'=>['col_idx'=>2,'col_cell_name'=>'C','col_name'=>'NAME OF EMP/DEP','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'dob'=>['col_idx'=>3,'col_cell_name'=>'D','col_name'=>'DOB','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'custom'=>'check_dob_diff','params'=>['row','relationship','default_age_ratio']],'gender'=>['col_idx'=>4,'col_cell_name'=>'E','col_name'=>'Gender','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>['M','F']],'relationship'=>['col_idx'=>5,'col_cell_name'=>'F','col_name'=>'RELATIONSHIP','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_relationship','params'=>['row','relationship','policy_terms']],'basic_cover_si'=>['col_idx'=>6,'col_cell_name'=>'G','col_name'=>'BASIC COVER SI','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom' => 'check_si','params' => ['row','policy_terms','slab_details']],'doc'=>['col_idx'=>7,'col_cell_name'=>'H','col_name'=>'Date of Coverage','is_mandatory'=>['A','DA'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'params'=>['row']],'doj'=>['col_idx'=>8,'col_cell_name'=>'I','col_name'=>'DOJ','is_mandatory'=>false,'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'custom'=>'check_doj','params'=>['row']],'basic_pay'=>['col_idx'=>9,'col_cell_name'=>'J','col_name'=>'Basic Pay','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_basic_pay','params'=>['row','policy_terms','slab_details']],'band_grade'=>['col_idx'=>10,'col_cell_name'=>'K','col_name'=>'Band/Grade','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_employee_band','params'=>['row','policy_terms','slab_details']],'designation'=>['col_idx'=>11,'col_cell_name'=>'L','col_name'=>'Designation','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'phone'=>['col_idx'=>12,'col_cell_name'=>'M','col_name'=>'Phone','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom' => 'check_dup_mobileno','params' => ['row','existing_mobilenos']],'email'=>['col_idx'=>13,'col_cell_name'=>'N','col_name'=>'Email','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'pre_existing_ailments'=>['col_idx'=>14,'col_cell_name'=>'O','col_name'=>'PRE EXISTING AILMENTS','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>['0','1']],'change_event'=>['col_idx'=>15,'col_cell_name'=>'P','col_name'=>'Change event','is_mandatory'=>['A','DA','D'],'data_type'=>'str','format'=>null,'allowed_values'=>null],'date_of_exit'=>['col_idx'=>16,'col_cell_name'=>'Q','col_name'=>'Date of exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null],'reason_for_exit'=>['col_idx'=>17,'col_cell_name'=>'R','col_name'=>'Reason for exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>null,'allowed_values'=>null]]; @@ -54,6 +56,7 @@ class EmployeeServiceController extends AdminController $this->clientPolicyModel = new ClientPolicyModel(); $this->policiesModel = new PolicesModel(); $this->empEndorsementModel = new EmpEndorsementModel(); + $this->messageModel = new MessageModel(); } public function excelFileFormatValidation($params) @@ -143,7 +146,7 @@ class EmployeeServiceController extends AdminController $policy_details = $this->clientPolicyModel->getPolicyDetails($file['client_id'],$file['policy_id']); $policy_terms = json_decode($policy_details[0]->policy_terms); $policy_terms = (array) $policy_terms;// convert obj to array - $default_age_ratio = isset($policy_details[0]->age_ratio) ? json_decode($policy_details[0]->age_ratio) : []; + $default_age_ratio = isset($policy_terms['age_ratio']) ? json_decode(json_encode($policy_terms['age_ratio']),true) : []; // // dd($default_age_ratio); @@ -271,6 +274,9 @@ class EmployeeServiceController extends AdminController $failure_reason = ((json_encode($result))); $this->fileModel->where('id', $file_id)->set(['status' => $status,'reason' => $failure_reason])->update(); $this->myLogger->logme("error",'{file_id} uploaded failed',['file_id' => $file_id]); + + //set failure msg to pull notifications + $this->setPullNotification($this->getFileMetaDataByFileId($file_id,'failure')); } else //trigger next data validation via job queue server { @@ -376,26 +382,28 @@ class EmployeeServiceController extends AdminController } } - if(($file['action'] == 'inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addition') && ($policy_details['policy_type_id'] != 3)) // 3 is GMC parents (base policy or dep addon) + //check self availbale in uploaded file + if(($file['action'] == 'inception' || $file['action'] == 'addition') && ($policy_details['policy_type_id'] == 3 && $policy_details['base_policy'] == null)) // 3 is GMC parents dep addon) { + // dd('file check'); $res = check_self_available_in_family($family,$file['action']); // dd($res); if(!$res['is_self_found']) { array_push($result['error_summary'],14); // Self not found - $result['error_data'][ $res['row_id'] ]['sno']['error'][] = "Self not found "; + $result['error_data'][ $res['row_id'] ]['sno']['error'][] = "Self not found in uploaded file"; } } - //check self avaialbe where self data is not available either in excel or same policy (i.e.) gMC parents - if($policy_details['policy_type_id'] == 3) // 3 is GMC parents (base policy or dep addon) + //check self avaialbe where self data is not available either same policy (i.e.) gMC parents + if($file['action'] == 'dependent_addition' || ($policy_details['policy_type_id'] == 3 && $policy_details['base_policy'] == null)) // 3 is GMC parents as base policy not as dep addon) { $self_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id,client_id: $file['client_id'],emp_status: ['active'],policy_status:['active']); // dd($self_details); if(!count($self_details)) { array_push($result['error_summary'],14); // Self not found - $result['error_data'][ $family[0][0] ]['sno']['error'][] = "Self not found "; + $result['error_data'][ $family[0][0] ]['sno']['error'][] = "Self not found in System"; } } @@ -446,8 +454,8 @@ class EmployeeServiceController extends AdminController $failure_reason = ((json_encode($result))); $this->fileModel->where('id', $file_id)->set(['status' => $status,'reason' => $failure_reason])->update(); $this->myLogger->logme("error",'{file_id} uploaded failed',['file_id' => $file_id]); - //return $this->respond(['dataStatus' => true,'code' => 404,'data' => 'file upload failed with errors'], 200); - // dd($failure_reason); + //set failure msg to pull notifications + $this->setPullNotification($this->getFileMetaDataByFileId($file_id,'failure')); } else if($file['action'] == 'deletion') { @@ -571,6 +579,8 @@ class EmployeeServiceController extends AdminController $this->fileModel->where('id', $file_id)->set(['status' => 'success','reason' => ''])->update(); $this->myLogger->logme("error",'{file_id} uploaded success',['file_id' => $file_id]); + $this->setPullNotification($this->getFileMetaDataByFileId($file_id,'success')); + } else if(isset($params['client_policy_id']))//handle data from enrollment to inception @@ -708,6 +718,9 @@ class EmployeeServiceController extends AdminController $this->fileModel->where('id', $file_id)->set(['status' => 'success','reason' => ''])->update(); $this->myLogger->logme("error",'{file_id} uploaded success',['file_id' => $file_id]); + + //set success msg to pull notifications + $this->setPullNotification($this->getFileMetaDataByFileId($file_id,'success')); return $endorsement_data; } @@ -768,6 +781,8 @@ class EmployeeServiceController extends AdminController } $this->fileModel->where('id', $file_id)->set(['status' => 'success','reason' => ''])->update(); $this->myLogger->logme("error",'{file_id} uploaded success',['file_id' => $file_id]); + //set success msg to pull notifications + $this->setPullNotification($this->getFileMetaDataByFileId($file_id,'success')); return true; } @@ -838,6 +853,8 @@ class EmployeeServiceController extends AdminController } $this->fileModel->where('id', $file_id)->set(['status' => 'success','reason' => ''])->update(); $this->myLogger->logme("error",'{file_id} uploaded success',['file_id' => $file_id]); + //set success msg to pull notifications + $this->setPullNotification($this->getFileMetaDataByFileId($file_id,'success')); return true; } @@ -1088,6 +1105,54 @@ class EmployeeServiceController extends AdminController // --------------------------------------------------------------------------------- + public function getFileMetaDataByFileId($file_id, $status = 'success'){ + + $data = $this->fileModel + ->select('files.*, clients.client_name, clients.short_name, policies.name as policy_name') + ->join('clients', 'clients.id = files.client_id') + ->join('client_policy', 'client_policy.id = files.policy_id') + ->join('policies', 'policies.id = client_policy.policy_id') + ->where('files.id', $file_id) + ->first(); + + if($status == 'success') + { + $msg_title = 'File Upload Success'; + } + else if ($status == 'failure') + { + $msg_title = 'File Upload Failure'; + } + + $msg_txt = $data['client_name'] . ' - ' . $data['policy_name'] . ' - ' . ucfirst($data['action']); + $user_id = $data['created_by']; + $url = 'employee/upload'; + + return ['msg_txt' => $msg_txt, 'user_id' => $user_id, 'url' => $url, 'status' => $status, 'title' => $msg_title]; + } + + + public function setPullNotification($data){ + + + $array = ['message_text' => $data['msg_txt'], 'action_url' => $data['url'], 'msg_status' => $data['status'], 'msg_title' => $data['title']]; + $jsonEncodeData = json_encode($array); + + $msg_data = [ + + 'message_text' => $jsonEncodeData, + 'user_id' => $data['user_id'], + 'role_id' => NULL, + 'team_id' => NULL, + 'message_type' => '1to1', + ]; + + + $this->messageModel->insert($msg_data); + + + } + } diff --git a/app/Controllers/JobWorker.php b/app/Controllers/JobWorker.php index 8d81699f..7b26d8cb 100644 --- a/app/Controllers/JobWorker.php +++ b/app/Controllers/JobWorker.php @@ -185,7 +185,7 @@ class JobWorker extends AdminController //die(); $job_status = self::STATUS_FAILED; $runtime = $runtime === null ? microtime(true) - $start : $runtime; - $response = $e->getMessage(); + $response = ['file_name' => $e->getFile(),'error' => $e->getMessage(),'line_no' => $e->getLine(),'info' => $e->getTraceAsString()]; } $db->query("UPDATE jobs SET status=?, run_time=?, response=? WHERE id=? AND uuid=?", [ diff --git a/app/Controllers/Jobs/SubJob.php b/app/Controllers/Jobs/SubJob.php index be74f0b8..c88920f2 100644 --- a/app/Controllers/Jobs/SubJob.php +++ b/app/Controllers/Jobs/SubJob.php @@ -6,8 +6,17 @@ use App\Controllers\PublicController; class SubJob extends PublicController { + protected $myLogger; + public function __construct() + { + $this->myLogger = \Config\Services::mylogger(); + } public function handle($payload) { + + $log = \Config\Services::mylogger(); + $log->logme('error', 'insdie handle called'); + $this->myLogger->logme('error', 'common handle called'); return $payload['a'] - $payload['b']; } diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index a2c011a2..b652d3eb 100644 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -427,6 +427,7 @@ class MasterController extends AdminController $data['tpa_logo'] = $file_name; $data['front_card'] = $front_card_file_name; $data['back_card'] = $back_card_file_name; + $data['network_hospitals'] = $this->request->getPost('network_hospitals'); $insert = $this->tpaModel->insert($data); @@ -566,6 +567,7 @@ class MasterController extends AdminController $data['back_card'] = $back_card_file_name; } + $data['network_hospitals'] = $this->request->getPost('network_hospitals'); $update = $this->tpaModel->update($id,$data); diff --git a/app/Controllers/NotificationController.php b/app/Controllers/NotificationController.php index e0a6280c..2c050523 100644 --- a/app/Controllers/NotificationController.php +++ b/app/Controllers/NotificationController.php @@ -147,11 +147,14 @@ class NotificationController extends AdminController $count++; $temp_whole_data[] = $value; if($count == 20 || $whole_index == count($wholeData)-1 && $index == count($values)-1){ - $job_details = new Jobs(); - $r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $temp_whole_data]); + if (count($temp_whole_data) > 0) { + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $temp_whole_data]); - $temp_whole_data = []; - $count = 0; + $temp_whole_data = []; + $count = 0; + } + } } } diff --git a/app/Controllers/PendingActionsController.php b/app/Controllers/PendingActionsController.php index 9670dbba..2e4bb8e8 100644 --- a/app/Controllers/PendingActionsController.php +++ b/app/Controllers/PendingActionsController.php @@ -7,20 +7,458 @@ 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 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, + 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, + ($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_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, + ($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.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, + ($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("($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('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 + '); + $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('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/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index f93e79f6..cfc96b17 100644 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -57,21 +57,32 @@ class sendMailNotification if ($value['relationship'] != 'Self') { $emp_data = $EmployeeModel->where('client_id', $client_data['id'])->where('emp_code', $value['emp_code'])->where('is_active',1)->findAll(); - - foreach ($emp_data as $key => $value) { - if ($value['relationship'] == 'Self') { - $employee_name =$value['name']; - $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); - $mail = $value['email_corporate']; + if(count($emp_data) > 1){ + $mail =''; + foreach ($emp_data as $key => $values) { + if ($value['relationship'] == 'Self') { + $employee_name =$values['name']; + $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); + + $mail = $values['email_corporate']; + } } + }else{ + $mail =''; } + }else{ $employee_name =$value['name']; $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); $mail = $value['email_corporate']; } + if (isset($mail) && !empty($mail)) { $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']]; + } + } + if (count($wholeData) < 1) { + $wholeData = []; } return $wholeData; }else{ @@ -194,8 +205,9 @@ class sendMailNotification $mail_content = str_replace("[[member_summary]]", $table_content , $mail_content); // $mail = "aadhavanvalli@gmail.com"; - - $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']]; + // if (isset($mail) && !empty($mail)) { + $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']]; + // } return $wholeData; diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index 220f06f6..5a1ea319 100644 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -185,6 +185,56 @@ if (!function_exists('get_base64_image')) { } +if (!function_exists('format_indian_number')) { + function format_indian_number($number) { + // Round the number to two decimal places + $number = round($number, 2); + + // Split the number into integer and decimal parts + $numberParts = explode('.', number_format($number, 2, '.', '')); + $integerPart = $numberParts[0]; + $decimalPart = isset($numberParts[1]) ? $numberParts[1] : '00'; + + // Format the integer part with commas + $length = strlen($integerPart); + $formattedStr = ''; + $counter = 0; + + for ($i = $length - 1; $i >= 0; $i--) { + $formattedStr = $integerPart[$i] . $formattedStr; + $counter++; + if ($counter == 3 && $i != 0) { + $formattedStr = ',' . $formattedStr; + $counter = 0; + } elseif ($counter == 2 && $i != 0 && $length - $i > 3) { + $formattedStr = ',' . $formattedStr; + $counter = 0; + } + } + + // Combine the integer and decimal parts + return $formattedStr . '.' . $decimalPart; + } +} +if (!function_exists('get_username')) { + function get_username($user_id) { + // Connect to the database + $db = \Config\Database::connect(); + + // Query the database + $query = $db->table('user_profiles') + ->select('first_name') + ->where('id', $user_id) + ->get(); + + // Get the result + $result = $query->getRow(); + + // Return the username if found, otherwise return null + return $result ? $result->first_name : null; + } +} + diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php index 27b48bc9..193b9b71 100644 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -41,8 +41,9 @@ class ClientModel extends Model foreach ($clients as &$client) { $clientPolicyModel = new ClientPolicyModel(); - $clientPolicies = $clientPolicyModel->select(['client_policy.id','p.name']) + $clientPolicies = $clientPolicyModel->select(['client_policy.id','p.name','pt.policy_type']) ->join('policies p', 'p.id = client_policy.policy_id') + ->join('policy_type pt','client_policy.policy_type_id = pt.id') ->where('client_policy.client_id',$client['id']) ->where('client_policy.is_active', 1) ->where('client_policy.policy_status', 1) diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index 291b13f9..4cdd36b5 100644 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -40,7 +40,8 @@ class ClientPolicyModel extends Model "updated_by", "Is_active", "date_of_exit", - "reason_for_exit" + "reason_for_exit", + "policy_no" ]; public function getClientPolicyById($id){ diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 5b5caf18..217e2013 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, @@ -789,4 +790,69 @@ class EmployeePolicyModel extends Model } + public function bulkUpdate($emp_details) + { + // Extract IDs, tpa_ids, and uhids + $ids = array_column($emp_details, 'id'); + $tpa_ids = array_column($emp_details, 'tpa_id'); + $uhids = array_column($emp_details, 'uhid'); + + // Escape values for SQL + $escapedIds = array_map([$this->db, 'escape'], $ids); + $escapedTpaIds = array_map([$this->db, 'escape'], $tpa_ids); + $escapedUhids = array_map([$this->db, 'escape'], $uhids); + + // Construct the CASE statements + $caseTpaId = array_map(function($id, $tpa_id) { + return "WHEN id = $id THEN $tpa_id"; + }, $escapedIds, $escapedTpaIds); + + $caseUhid = array_map(function($id, $uhid) { + return "WHEN id = $id THEN $uhid"; + }, $escapedIds, $escapedUhids); + + // Convert cases to a string + $caseTpaIdString = implode(' ', $caseTpaId); + $caseUhidString = implode(' ', $caseUhid); + + // Convert ids to a string + $idsString = implode(', ', $escapedIds); + + // 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; + } + } + + + } \ No newline at end of file diff --git a/app/Models/MessageModel.php b/app/Models/MessageModel.php new file mode 100644 index 00000000..eac21cbe --- /dev/null +++ b/app/Models/MessageModel.php @@ -0,0 +1,77 @@ +db->table($this->table); + $builder->select('messages.*'); + $builder->join('user_messages', 'user_messages.message_id = messages.id AND user_messages.user_id = ' . $this->db->escape($userId), 'left'); + $builder->groupStart(); + $builder->where('user_messages.is_read', null); + $builder->orWhere('user_messages.is_read', 0); + $builder->groupEnd(); + $builder->groupStart(); + $builder->orwhere('messages.message_type', 'broadcast'); + $builder->orWhere('messages.user_id', $userId); + $builder->orWhere('messages.role_id', $roleId); + $builder->orWhere('messages.team_id', $teamId); + $builder->groupEnd(); + + $query = $builder->get(); + return $query->getResult(); + dd($this->db->getLastQuery()); + } +} diff --git a/app/Models/PolicesModel.php b/app/Models/PolicesModel.php index d6a8182e..a56af6bc 100644 --- a/app/Models/PolicesModel.php +++ b/app/Models/PolicesModel.php @@ -39,6 +39,7 @@ class PolicesModel extends Model { $premium_slab_data = null; + $grid_type = null; $policyPremium1Model = new PolicyPremium1Model(); $premium_slab_data = $policyPremium1Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1])->findAll(); @@ -50,9 +51,13 @@ class PolicesModel extends Model $premium_slab_data = $policyPremium2Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1])->findAll(); } - $grid_id = $premium_slab_data[0]['policy_grid_id']; - $policyGridModel = new PolicyGridModel(); - $results = $policyGridModel->find($grid_id); - return ['slab_rates' => $premium_slab_data,'grid_master' => $results]; + if(isset($premium_slab_data[0]['policy_grid_id'])) + { + $grid_id = $premium_slab_data[0]['policy_grid_id']; + $policyGridModel = new PolicyGridModel(); + $grid_type = $policyGridModel->find($grid_id); + } + + return ['slab_rates' => $premium_slab_data,'grid_master' => $grid_type]; } } diff --git a/app/Models/TPAModel.php b/app/Models/TPAModel.php index 215c734d..fe3f30cd 100644 --- a/app/Models/TPAModel.php +++ b/app/Models/TPAModel.php @@ -15,6 +15,7 @@ class TPAModel extends Model "front_card", "back_card", "tpa_logo", + "network_hospitals", "created_by", "updated_by", "is_active", diff --git a/app/Models/UserMessageModel.php b/app/Models/UserMessageModel.php new file mode 100644 index 00000000..1b229269 --- /dev/null +++ b/app/Models/UserMessageModel.php @@ -0,0 +1,69 @@ + 1, + 'read_at' => date('Y-m-d H:i:s') + ]; + + $existingEntry = $this->where('user_id', $userId) + ->where('message_id', $messageId) + ->first(); + + if ($existingEntry) { + return $this->update($existingEntry['id'], $data); + } else { + $data['user_id'] = $userId; + $data['message_id'] = $messageId; + return $this->insert($data); + } + } +} diff --git a/app/Views/batch_list.php b/app/Views/batch_list.php index c08961b8..335818bf 100644 --- a/app/Views/batch_list.php +++ b/app/Views/batch_list.php @@ -1,7 +1,11 @@