diff --git a/app/Config/Routes.php b/app/Config/Routes.php index dc76e1fa..4f395843 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -23,6 +23,10 @@ $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->group("/user", ["filter" => "authMVC"], function ($routes) { $routes->post("create", "UserController::create"); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 8b0c17ee..1984e5dc 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(); 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..b0814d11 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]); } @@ -945,7 +967,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']; @@ -1051,6 +1076,7 @@ class EmpDataServiceController extends BaseController $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID total amount for cash deposite : {data}', ['data'=> $totals]); + if ($file['insurer_or_tpa'] == 'tpa') { $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID set cashDepositCalculationForInception and sendMailForDownloadingECard in JOB QUEUE'); @@ -1086,10 +1112,12 @@ class EmpDataServiceController extends BaseController // $this->cashDepositCalculationForInception($depositeData); // $this->sendMailForDownloadingECard($empty_emp_tpa_uh_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 +2091,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 +2121,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 +2213,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 b93c9105..f64d48a3 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -928,6 +928,7 @@ class EmployeeController extends AdminController '{CORPORATE_NAME}' =>$value['client_name'], '{AGE}' =>$value['emp_age'], '{TPA_NAME}' =>$value['emp_age'], + '{TPA_LOGO}' => base_url() . 'public/uploads/logo/' . $value['tpa_logo'], ]; // Replace placeholders with values in HTML content diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 79069da8..91c4b6b6 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/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/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/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/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/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/client_policy.php b/app/Views/client_policy.php index 8ee76ec5..e66f59b0 100644 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -54,7 +54,7 @@