Merge branch 'dev' of bitbucket.org:jubilian/nhance-enrollment into dev
This commit is contained in:
commit
d99f0bfe78
@ -71,6 +71,20 @@ class Database extends Config
|
||||
'busyTimeout' => 1000,
|
||||
];
|
||||
|
||||
public $postDB = [
|
||||
'DSN' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'root',
|
||||
'database' => 'other_db',
|
||||
'DBDriver' => 'MySQLi',
|
||||
'DBPrefix' => '',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => (ENVIRONMENT !== 'production'),
|
||||
'charset' => 'utf8',
|
||||
'DBCollat' => 'utf8_general_ci',
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
@ -344,7 +344,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) {
|
||||
$routes->post('saveSIMapping','ClientController::saveSIMapping');
|
||||
$routes->post('checkSIMapping','ClientController::checkSIMapping');
|
||||
$routes->post('deleteMapping','ClientController::deleteMapping');
|
||||
|
||||
$routes->get('removeLevelContacts','ClientController::removeLevelContacts');
|
||||
|
||||
});
|
||||
|
||||
@ -435,6 +435,7 @@ $routes->post("/employeeRest/verifyEmployeeEmailId", "RestAuthenticationControll
|
||||
|
||||
//HR login api's
|
||||
$routes->post("/employeeRest/verifyHrWithMobileNumber", "RestAuthenticationController::verifyHrWithMobileNumber");
|
||||
$routes->post("/employeeRest/verifyHrWithEmail", "RestAuthenticationController::verifyHrWithEmail");
|
||||
$routes->post("/employeeRest/getVerifiedHrData", "RestAuthenticationController::getVerifiedHrData");
|
||||
|
||||
$routes->group("/api", ["filter" => "authJWT"], function ($routes) {
|
||||
@ -444,6 +445,7 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) {
|
||||
|
||||
$routes->post("employeeRest/saveMpin", "RestAuthenticationController::saveMpin");
|
||||
$routes->post("employeeRest/updateMpin", "RestAuthenticationController::updateMpin");
|
||||
$routes->post("employeeRest/forgotMPIN", "RestAuthenticationController::forgotMPIN");
|
||||
$routes->post("calculatePremium", "EmployeeRestController::calculatePremium");
|
||||
|
||||
// $routes->post("employeeRest/createOrUpdateEmployeePolicySiAmount", "EmployeeRestController::createOrUpdateEmployeePolicySiAmount");
|
||||
@ -476,7 +478,8 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) {
|
||||
$routes->post("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn");
|
||||
|
||||
$routes->get("exportDataByClientPolicyId", "EmployeeRestController::exportDataByClientPolicyId");
|
||||
$routes->get("getCashDepositData", "EmployeeRestController::getCashDepositData");
|
||||
|
||||
$routes->get("getPolicyLevelEmployeeSummaryData", "EmployeeRestController::getPolicyLevelEmployeeSummaryData");
|
||||
$routes->get("exportCashDepositData", "EmployeeRestController::exportCashDepositData");
|
||||
|
||||
$routes->get("removeEmpAndEmpPolicyData", "EmployeeRestController::removeEmpAndEmpPolicyData");
|
||||
@ -487,10 +490,13 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) {
|
||||
$routes->get("getEmployeeActiveOrInactivePolicy", "EmployeeRestController::getEmployeeActiveOrInactivePolicy");
|
||||
$routes->get("getFEContent", "EmployeeRestController::getFEContent");
|
||||
$routes->get("getAdvertisementImage", "EmployeeRestController::getAdvertisementImage");
|
||||
$routes->post("logHrActivity", "RestAuthenticationController::logHrActivity");
|
||||
|
||||
});
|
||||
$routes->get("getEmployeeActiveOrInactivePolicy", "EmployeeRestController::getEmployeeActiveOrInactivePolicy");
|
||||
$routes->get("sendPushNotification", "EmployeeRestController::sendPushNotification");
|
||||
$routes->post("sendEmail", "EmployeeRestController::send_email");
|
||||
$routes->get("getPolicyLevelEmployeeSummaryData", "EmployeeRestController::getPolicyLevelEmployeeSummaryData");
|
||||
|
||||
$routes->get("getBackToEnrolledDetails", "EmployeeRestController::getBackToEnrolledDetails");
|
||||
|
||||
@ -503,5 +509,7 @@ $routes->get("sendCroneRemainderMail", "DashboardController::sendCroneRemainderM
|
||||
$routes->get("getEmployeePolicy", "EmployeeRestController::getEmployeePolicy");
|
||||
$routes->get("getAddOnPolicy", "EmployeeRestController::getAddOnPolicy");
|
||||
$routes->post("addEmployeeAndDependence", "EmployeeRestController::addEmployeeAndDependence");
|
||||
$routes->post("getPreEmployeePolicyCount", "EmployeeRestController::getPreEmployeePolicyCount");
|
||||
|
||||
|
||||
|
||||
|
||||
@ -138,7 +138,7 @@ class ClientController extends AdminController
|
||||
|
||||
// Perform the query
|
||||
$builder = $db->table($table);
|
||||
$isDuplicate = $builder->where($field, $value)->countAllResults() > 0;
|
||||
$isDuplicate = $builder->where($field, $value)->where('is_active', 1)->countAllResults() > 0;
|
||||
|
||||
// Return the result
|
||||
return $this->response->setJSON(['isDuplicate' => $isDuplicate]);
|
||||
@ -866,6 +866,12 @@ class ClientController extends AdminController
|
||||
$data['created_by'] = get_session_userid();
|
||||
$insert = $this->clientBranchModel->insert($data);
|
||||
|
||||
if ($insert) {
|
||||
$level_contact_data = $this->request->getPost('level_contect_data');
|
||||
$level_contact_data = !empty($level_contact_data) ? json_decode($level_contact_data, true) : null;
|
||||
$this->saveLevelContacts($level_contact_data, $insert);
|
||||
}
|
||||
|
||||
// if ($insert) {
|
||||
// for ($i = 0; $i < count($this->request->getPost('name')); $i++) {
|
||||
// // Prepare data to insert
|
||||
@ -968,6 +974,11 @@ class ClientController extends AdminController
|
||||
$insert = $this->clientBranchModel->update($id, $data);
|
||||
$this->myLogger->logme('error', 'Client branch EDITED by {data}', ['data' => get_session_userid()]);
|
||||
|
||||
if ($insert) {
|
||||
$level_contact_data = $this->request->getPost('level_contect_data');
|
||||
$level_contact_data = !empty($level_contact_data) ? json_decode($level_contact_data, true) : null;
|
||||
$this->saveLevelContacts($level_contact_data, $id);
|
||||
}
|
||||
|
||||
// if ($insert) {
|
||||
|
||||
@ -1005,6 +1016,57 @@ class ClientController extends AdminController
|
||||
}
|
||||
}
|
||||
|
||||
public function saveLevelContacts($level_contact_data, $branch_id)
|
||||
{
|
||||
if (!empty($level_contact_data) && is_array($level_contact_data)) {
|
||||
foreach ($level_contact_data as $value) {
|
||||
if (!empty($value['id'])) {
|
||||
$id = $value['id'];
|
||||
unset($value['id']);
|
||||
$this->levelContactModel->update($id, $value);
|
||||
} else {
|
||||
unset($value['id']);
|
||||
$value['contact_type'] = "client";
|
||||
$value['ref_id'] = $branch_id ?? null;
|
||||
$this->levelContactModel->insert($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function removeLevelContacts()
|
||||
{
|
||||
$id = $this->request->getGet('id');
|
||||
try {
|
||||
if (empty($id)) {
|
||||
return $this->respond([
|
||||
'status' => false,
|
||||
'message' => 'Invalid ID provided. ID is empty',
|
||||
'data' => $id
|
||||
], 400);
|
||||
}
|
||||
|
||||
$updated = $this->levelContactModel->update($id, ['is_active' => 0]);
|
||||
|
||||
if ($updated === false) {
|
||||
return $this->respond([
|
||||
'status' => false,
|
||||
'message' => 'Failed to remove contact'
|
||||
], 500);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => true,
|
||||
'message' => 'Contact removed successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([
|
||||
'status' => false,
|
||||
'message' => 'An error occurred: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function createClientPolicy()
|
||||
@ -4435,11 +4497,13 @@ class ClientController extends AdminController
|
||||
|
||||
$employeeRestController = new EmployeeServiceController();
|
||||
// $employeeRestController->excelFileDataValidation(['file_id' => 823]);
|
||||
// $res = $employeeRestController->excelFileFormatValidation(['file_id' => 897]);
|
||||
// $res = $employeeRestController->getExcelErrorData(['file_id' => 897]);
|
||||
// $employeeRestController->employeesOnboardPreprocess(['file_id' => 644]);
|
||||
// $employeeRestController->employeesOnboardProcess(['file_id' => 835]);
|
||||
// $employeeRestController->employeesEnrollmentInsert(['file_id' => 836]);
|
||||
// $r = Jobs::addJob(['job_name' => 'employeesEnrollmentInsert','payload' => ['file_id' => 721]]);
|
||||
|
||||
// dd($res);
|
||||
|
||||
// ----------EMP DATA SERVICE CONTROLLER--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@ -1325,7 +1325,7 @@ class EmployeeController extends AdminController
|
||||
}
|
||||
|
||||
//STEP:3 - Update files table status
|
||||
$this->fileModel->where('id', $file_id)->set(['status' => 'truncated'])->update();
|
||||
$this->fileModel->where('id', $file_id)->set(['status' => 'truncated','updated_by' => $loggedInUserID])->update();
|
||||
$this->myLogger->logme('error', '---- files table updated ----');
|
||||
|
||||
//FINAL STEP - Update reverse entry in cash_deposite table
|
||||
@ -1407,7 +1407,7 @@ class EmployeeController extends AdminController
|
||||
|
||||
// dd($affectedRows);
|
||||
$affectedRows = $affectedRows * 2;
|
||||
$this->fileModel->where('id', $file_id)->set(['status' => 'truncated'])->update();
|
||||
$this->fileModel->where('id', $file_id)->set(['status' => 'truncated','updated_by' => $loggedInUserID])->update();
|
||||
|
||||
}
|
||||
|
||||
@ -1472,7 +1472,7 @@ class EmployeeController extends AdminController
|
||||
|
||||
// STEP 3:
|
||||
//update files table status to "truncated"
|
||||
$this->fileModel->where('id', $file_id)->set(['status' => 'truncated'])->update();
|
||||
$this->fileModel->where('id', $file_id)->set(['status' => 'truncated','updated_by' => $loggedInUserID])->update();
|
||||
$this->myLogger->logme('error', 'files table updated');
|
||||
|
||||
|
||||
|
||||
@ -31,6 +31,7 @@ use App\Models\AddImgModel;
|
||||
use App\Models\ClientBranchModel;
|
||||
use App\Models\AuditHistoryModel;
|
||||
use App\Models\SIMappingModel;
|
||||
use App\Models\InsurerModel;
|
||||
|
||||
|
||||
use App\Controllers\Jobs ;
|
||||
@ -77,6 +78,7 @@ class EmployeeRestController extends AdminController
|
||||
protected $auditHistoryModel;
|
||||
protected $siMappingModel;
|
||||
protected $employeeHelper;
|
||||
protected $insurerModel;
|
||||
|
||||
|
||||
public function __construct()
|
||||
@ -103,6 +105,7 @@ class EmployeeRestController extends AdminController
|
||||
$this->auditHistoryModel = new AuditHistoryModel();
|
||||
$this->siMappingModel = new SIMappingModel();
|
||||
$this->employeeHelper = new EmployeeHelper();
|
||||
$this->insurerModel = new InsurerModel();
|
||||
|
||||
}
|
||||
|
||||
@ -230,19 +233,23 @@ class EmployeeRestController extends AdminController
|
||||
try {
|
||||
$data = $this->request->getJSON();
|
||||
|
||||
// dd($data);
|
||||
//enrolment check
|
||||
$openForEnrollment = $this->findThePolicyIsOpenForEnrollment($data[0]->client_policy_id);
|
||||
if($openForEnrollment == false){
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => [],'message' => 'Enrollment closed.'], 200);
|
||||
}
|
||||
|
||||
//dependent duplicate check
|
||||
if ( ! isset($data[0]->id) ) {
|
||||
$validationFailed = $this->employeeHelper->validation_addEmployeeAndDependence($data);
|
||||
|
||||
if($validationFailed){
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => "validation_addEmployeeAndDependence failed ..!!"], 404);
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => [],'message' => "Relation already exists."], 200);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$openForEnrollment = $this->findThePolicyIsOpenForEnrollment($data[0]->client_policy_id);
|
||||
if($openForEnrollment == false){ return $this->respond(['status' => 'failed','code' => 404,'data' => 'Enrollment closed'], 404); }
|
||||
|
||||
|
||||
if ($data) {
|
||||
|
||||
@ -291,14 +298,14 @@ class EmployeeRestController extends AdminController
|
||||
$this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code , $data[0]->client_branch_id);
|
||||
|
||||
$result = [];
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200);
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result,'message' => "Successfully updated."], 200);
|
||||
} else {
|
||||
$result = "No Matches";
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => $result], 404);
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => $result,'message' => "Action failed."], 200);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage(),'message' => "Action failed."], 500);
|
||||
}
|
||||
|
||||
}
|
||||
@ -744,7 +751,7 @@ class EmployeeRestController extends AdminController
|
||||
$jwt = $this->request->getHeaderLine('Authorization');
|
||||
$jwtParts = explode(' ', $jwt);
|
||||
|
||||
$token = $jwtParts[2];
|
||||
$token = $jwtParts[1];
|
||||
|
||||
$decodedPayload = json_decode(base64_decode(explode('.', $token)[1]), true);
|
||||
|
||||
@ -1068,6 +1075,7 @@ class EmployeeRestController extends AdminController
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "Client id and Client Policy id is Not Match!" ], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->myLogger->logme("error", ($e->getMessage().' --- '.$e->getLine() . '----' . $e->getTraceAsString()));
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
@ -1705,22 +1713,128 @@ class EmployeeRestController extends AdminController
|
||||
|
||||
}
|
||||
|
||||
// public function getClientDetails()
|
||||
// {
|
||||
// try {
|
||||
|
||||
// $jwt = $this->request->getHeaderLine('Authorization');
|
||||
// $jwtParts = explode(' ', $jwt);
|
||||
// $token = $jwtParts[1];
|
||||
// $decodedPayload = json_decode(base64_decode(explode('.', $token)[1]), true);
|
||||
// $token_type = $decodedPayload['token_type'];
|
||||
|
||||
// if ($token_type == 'pre') {
|
||||
// $client = $this->clientModel->where('id', $this->request->getGet('client_id'))->first();
|
||||
// if ($client) {
|
||||
// $client['client_logo'] = base_url() . 'public/uploads/logo/' . $client['client_logo'];
|
||||
// $clientPolicy = $this->clientPolicyModel->where('client_id', $this->request->getGet('client_id'))
|
||||
// ->where('client_branch_id', $this->request->getGet('client_branch_id'))->findAll();
|
||||
// return $this->respond(['status' => 'success', 'code' => 200, 'data' => ['client' => $client, 'client_policy' => $clientPolicy]], 200);
|
||||
// } else if ($token_type == 'post') {
|
||||
|
||||
// $restAuthController = new RestAuthenticationController;
|
||||
|
||||
// //call and get Client Details data from post enrollment
|
||||
// $queryParams = [
|
||||
// 'client_id' => $this->request->getGet('client_id'),
|
||||
// 'client_branch_id' => $this->request->getGet('client_branch_id')
|
||||
// ];
|
||||
|
||||
// return $restAuthController->callThirdPartyGETAPI($queryParams, 'getClientDetails');
|
||||
// } else {
|
||||
// return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404);
|
||||
// }
|
||||
// } else {
|
||||
// return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404);
|
||||
// }
|
||||
// } catch (\Exception $e) {
|
||||
// return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
// }
|
||||
// }
|
||||
|
||||
public function getClientDetails()
|
||||
{
|
||||
{
|
||||
log_message('error', 'STEP 1: getClientDetails called');
|
||||
|
||||
try {
|
||||
// STEP 2: Extract Authorization header
|
||||
$jwt = $this->request->getHeaderLine('Authorization');
|
||||
log_message('error', 'STEP 2: Authorization header: ' . $jwt);
|
||||
|
||||
$client = $this->clientModel->where('id',$this->request->getGet('client_id'))->first();
|
||||
if($client) {
|
||||
$client['client_logo'] = base_url().'public/uploads/logo/'.$client['client_logo'];
|
||||
$clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id'))
|
||||
->where('client_branch_id',$this->request->getGet('client_branch_id'))->findAll();
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => ['client'=>$client,'client_policy'=>$clientPolicy]], 200);
|
||||
|
||||
}else{
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404);
|
||||
$jwtParts = explode(' ', $jwt);
|
||||
if (count($jwtParts) < 2) {
|
||||
log_message('error', 'STEP 2.1: Invalid Authorization header format');
|
||||
return $this->respond(['status' => 'failed', 'code' => 400, 'data' => 'Invalid Authorization header'], 400);
|
||||
}
|
||||
|
||||
$token = $jwtParts[1];
|
||||
log_message('error', 'STEP 3: Extracted JWT token');
|
||||
|
||||
$tokenParts = explode('.', $token);
|
||||
if (count($tokenParts) !== 3) {
|
||||
log_message('error', 'STEP 3.1: Invalid JWT structure');
|
||||
return $this->respond(['status' => 'failed', 'code' => 400, 'data' => 'Invalid JWT token'], 400);
|
||||
}
|
||||
|
||||
$decodedPayload = json_decode(base64_decode($tokenParts[1]), true);
|
||||
log_message('error', 'STEP 4: Decoded JWT payload: ' . json_encode($decodedPayload));
|
||||
|
||||
$token_type = $decodedPayload['token_type'] ?? null;
|
||||
log_message('error', 'STEP 5: Token type = ' . $token_type);
|
||||
|
||||
$client_id = $this->request->getGet('client_id');
|
||||
$client_branch_id = $this->request->getGet('client_branch_id');
|
||||
log_message('error', 'STEP 6: Query params - client_id: ' . $client_id . ', client_branch_id: ' . $client_branch_id);
|
||||
|
||||
if ($token_type === 'pre') {
|
||||
log_message('error', 'STEP 7: Handling "pre" token type');
|
||||
|
||||
$client = $this->clientModel->where('id', $client_id)->first();
|
||||
if ($client) {
|
||||
log_message('error', 'STEP 8: Found client: ' . json_encode($client));
|
||||
|
||||
$client['client_logo'] = base_url() . 'public/uploads/logo/' . $client['client_logo'];
|
||||
|
||||
$clientPolicy = $this->clientPolicyModel
|
||||
->where('client_id', $client_id)
|
||||
->where('client_branch_id', $client_branch_id)
|
||||
->findAll();
|
||||
|
||||
log_message('error', 'STEP 9: Found client policy count: ' . count($clientPolicy));
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'data' => [
|
||||
'client' => $client,
|
||||
'client_policy' => $clientPolicy
|
||||
]
|
||||
], 200);
|
||||
} else {
|
||||
log_message('error', 'STEP 10: No client found for client_id: ' . $client_id);
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404);
|
||||
}
|
||||
} elseif ($token_type === 'post') {
|
||||
log_message('error', 'STEP 11: Handling "post" token type');
|
||||
|
||||
$restAuthController = new RestAuthenticationController;
|
||||
|
||||
$queryParams = [
|
||||
'client_id' => $client_id,
|
||||
'client_branch_id' => $client_branch_id
|
||||
];
|
||||
|
||||
log_message('error', 'STEP 12: Calling post enrollment API with params: ' . json_encode($queryParams));
|
||||
|
||||
return $restAuthController->callThirdPartyGETAPI($queryParams, 'getClientDetails', ['token' => $jwt]);
|
||||
} else {
|
||||
log_message('error', 'STEP 13: Unknown token_type: ' . $token_type);
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
|
||||
log_message('error', 'STEP 14: Exception occurred - ' . $e->getMessage());
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2483,72 +2597,71 @@ class EmployeeRestController extends AdminController
|
||||
}
|
||||
|
||||
|
||||
public function getCashDepositData()
|
||||
public function getPolicyLevelEmployeeSummaryData()
|
||||
{
|
||||
|
||||
$ClientPolicyData = $this->clientPolicyModel->select('client_policy.client_id as clientId , client_policy.insurer_id as insurerId,insurers.name as insurer_name')
|
||||
->join('insurers', 'client_policy.insurer_id = insurers.id', 'left')
|
||||
->where('client_policy.client_id', $this->request->getGet('client_id') )
|
||||
->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') )
|
||||
->where('client_policy.is_active', 1 )
|
||||
->where('client_policy.policy_status', 1)
|
||||
->groupBy('client_policy.insurer_id')
|
||||
->findAll();
|
||||
$result = [];
|
||||
$hr_id = $this->request->getGet('hr_id');
|
||||
$restAuthController = new RestAuthenticationController;
|
||||
//call and get allowed policy data from post enrollment
|
||||
$queryParams = [
|
||||
'hr_id' => $hr_id,
|
||||
'request_for' => 'pre_enrollment'
|
||||
];
|
||||
$HRAccessRes = $restAuthController->callThirdPartyGETAPI($queryParams,'getHRAccessData');
|
||||
$HRAccessData = json_decode($HRAccessRes,true);
|
||||
if(isset($HRAccessData['data']['allowed_pre_policies']))
|
||||
{
|
||||
$policyId = json_decode($HRAccessData['data']['allowed_pre_policies'],true);
|
||||
}else{
|
||||
$policyId = [];
|
||||
}
|
||||
|
||||
if(count($ClientPolicyData))
|
||||
{
|
||||
foreach ($ClientPolicyData as $key => $value) {
|
||||
if(count($policyId) == 0){
|
||||
return $this->respond(['status' => 'failed','code' => (count($policyId) ? 200 : 404),'data' => [] ], 200);
|
||||
}
|
||||
|
||||
|
||||
$data['clientId'] = $value['clientId'];
|
||||
$data['insurerId'] = $value['insurerId'];
|
||||
$data['insurerName'] = $value['insurer_name'];
|
||||
$data['depositData'] = $this->clientPolicyModel->getdepositData($value['clientId'],$value['insurerId']);
|
||||
$data['balance'] = count($data['depositData']) ? $data['depositData'][0]->balance : 0;
|
||||
|
||||
$data['policyDetails'] = [];
|
||||
$ClientPolicyData = $this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, client_policy.policy_type_id as policy_type_id, client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type ')
|
||||
|
||||
->where('client_policy.insurer_id', $value['insurerId'] )
|
||||
->where('client_policy.client_id', $this->request->getGet('client_id') )
|
||||
->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') )
|
||||
->where('client_policy.is_active', 1 )
|
||||
->where('client_policy.policy_status', 1)
|
||||
->findAll();
|
||||
// dd( $ClientPolicyData);
|
||||
foreach ($ClientPolicyData as $key => $value)
|
||||
$ClientPolicyData = $this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, client_policy.policy_type_id as policy_type_id, client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type, client_policy.policy_no as policy_no, client_policy.insurer_id as insurer_id, DATE_FORMAT(client_policy.policy_end_date, "%d-%m-%Y") AS policy_expiry_date ')
|
||||
->where('client_policy.client_id', $this->request->getGet('client_id') )
|
||||
->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') )
|
||||
->where('client_policy.is_active', 1 )
|
||||
->where('client_policy.policy_status', 1)
|
||||
->whereIn('client_policy.id', $policyId)
|
||||
->findAll();
|
||||
$result = [];
|
||||
// dd( $ClientPolicyData);
|
||||
foreach ($ClientPolicyData as $key => $value)
|
||||
{
|
||||
$policyTypeData = $this->policyTypeModel->where('id',$value['policy_type_id'])->get()->getRow();
|
||||
$insurerData = $this->insurerModel->where('id',$value['insurer_id'])->get()->getRow();
|
||||
|
||||
$value['type'] = $policyTypeData->policy_type;
|
||||
$value['policy_name'] = $policyTypeData->long_name;
|
||||
$value['insurer_name'] = $insurerData->name ?? null;
|
||||
$value['insurer_short_name'] = $insurerData->short_name ?? null;
|
||||
$employeeDetails = $this->employeePolicyModel->getEmployeePolicy( client_id:$value['client_id'],policy_id: $value['client_policy_id'],status:0,branch_id:$this->request->getGet('client_branch_id'));
|
||||
$enrolledCount = 0;
|
||||
$draftCount = 0;
|
||||
if(count($employeeDetails))
|
||||
{
|
||||
$policyTypeData = $this->policyTypeModel->where('id',$value['policy_type_id'])->get()->getRow();
|
||||
$value['type'] = $policyTypeData->policy_type;
|
||||
$value['policy_name'] = $policyTypeData->long_name;
|
||||
$employeeDetails = $this->employeePolicyModel->getEmployeePolicy( client_id:$value['client_id'],policy_id: $value['client_policy_id'],status:0,branch_id:$this->request->getGet('client_branch_id'));
|
||||
$enrolledCount = 0;
|
||||
$draftCount = 0;
|
||||
if(count($employeeDetails))
|
||||
{
|
||||
foreach ($employeeDetails as $item) {
|
||||
if ($item['emp_status'] === 'enrolled') {
|
||||
$enrolledCount++;
|
||||
} elseif ($item['emp_status'] === 'draft') {
|
||||
$draftCount++;
|
||||
}
|
||||
foreach ($employeeDetails as $item) {
|
||||
if ($item['emp_status'] === 'enrolled') {
|
||||
$enrolledCount++;
|
||||
} elseif ($item['emp_status'] === 'draft') {
|
||||
$draftCount++;
|
||||
}
|
||||
}
|
||||
|
||||
$value['totalMembersCount'] = count($employeeDetails);
|
||||
$value['membersCountOfEnrolled'] = $enrolledCount;
|
||||
$value['membersCountOfDraft'] = $draftCount;
|
||||
|
||||
array_push($data['policyDetails'],$value);
|
||||
}
|
||||
|
||||
|
||||
array_push($result,$data);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$value['totalMembersCount'] = count($employeeDetails);
|
||||
$value['membersCountOfEnrolled'] = $enrolledCount;
|
||||
$value['membersCountOfDraft'] = $draftCount;
|
||||
|
||||
|
||||
array_push($result,$value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if($result)
|
||||
{
|
||||
@ -3308,10 +3421,77 @@ class EmployeeRestController extends AdminController
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getPreEmployeePolicyCount()
|
||||
{
|
||||
log_message('error', 'STEP 1: getPreEmployeePolicyCount API called');
|
||||
|
||||
$request = $this->request->getJSON(true);
|
||||
$mobile_no = $request['mobile_number'] ?? null;
|
||||
$client_short_name = $request['client_short_name'] ?? null;
|
||||
|
||||
log_message('error', 'STEP 2: Received input - ' . json_encode($request));
|
||||
|
||||
// Step 3: Fetch client ID based on short name
|
||||
$clientId = null;
|
||||
if (!empty($client_short_name)) {
|
||||
log_message('error', 'STEP 3: Looking up client with short_name: ' . $client_short_name);
|
||||
$client_data = $this->clientModel
|
||||
->where('is_active', 1)
|
||||
->where('short_name', $client_short_name)
|
||||
->first();
|
||||
|
||||
if ($client_data) {
|
||||
$clientId = $client_data['id'];
|
||||
log_message('error', 'STEP 4: Found client ID: ' . $clientId);
|
||||
} else {
|
||||
log_message('error', 'STEP 4: No client found for short_name: ' . $client_short_name);
|
||||
}
|
||||
} else {
|
||||
log_message('error', 'STEP 3: client_short_name is empty.');
|
||||
}
|
||||
|
||||
// Step 5: Validate mobile number
|
||||
if (empty($mobile_no)) {
|
||||
log_message('error', 'STEP 5: Mobile number is empty or null. Returning 0.');
|
||||
return $this->respond(['data' => 0]);
|
||||
}
|
||||
|
||||
try {
|
||||
log_message('error', 'STEP 6: Building employee policy count query');
|
||||
|
||||
$builder = $this->employeeModel
|
||||
->join('employee_polices', 'employees.id = employee_polices.employee_id')
|
||||
->join('client_policy cp', 'employee_polices.client_policy_id = cp.id')
|
||||
->where('employees.is_active', 1)
|
||||
->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
->where('employee_polices.is_active', 1)
|
||||
->whereIn('employee_polices.status', ['draft', 'enrolled'])
|
||||
->where('cp.enrolment_visibility', 1)
|
||||
->where('cp.open_for_enrollment', 1)
|
||||
->where('cp.policy_status', 1)
|
||||
->whereIn('cp.policy_type_id', [1, 2, 6, 7])
|
||||
->where('employees.mobile', $mobile_no)
|
||||
->orderBy('employees.created_at', 'desc')
|
||||
->groupBy('employee_polices.client_policy_id');
|
||||
|
||||
if (!empty($clientId)) {
|
||||
$builder->where('employees.client_id', $clientId);
|
||||
log_message('error', 'STEP 7: Applied client ID filter: ' . $clientId);
|
||||
} else {
|
||||
log_message('error', 'STEP 7: No client ID filter applied.');
|
||||
}
|
||||
|
||||
$count = $builder->get()->getNumRows();
|
||||
log_message('error', 'STEP 8: Final policy count = ' . $count);
|
||||
|
||||
return $this->respond(['data' => $count]);
|
||||
} catch (\Throwable $e) {
|
||||
log_message('error', 'STEP 9: Exception occurred - ' . $e->getMessage());
|
||||
return $this->respond(['data' => 0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -24,6 +24,7 @@ use App\Helpers\sendMailNotification;
|
||||
|
||||
use App\Controllers\Jobs ;
|
||||
use App\Controllers\JobWorker ;
|
||||
use App\Controllers\EmpDataServiceController;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use Kint\Kint;
|
||||
@ -1804,9 +1805,10 @@ class EmployeeServiceController extends AdminController
|
||||
public function getExcelErrorData($file_id){
|
||||
|
||||
try {
|
||||
$file = $this->fileModel->find($file_id);
|
||||
$error_data = json_decode($file['reason']);
|
||||
// dd($error_data);
|
||||
// $file = $this->fileModel->find($file_id);
|
||||
$file = $this->fileModel->where('id', $file_id)->first();
|
||||
$error_data = json_decode($file['reason']);
|
||||
// dd($error_data);
|
||||
// return $error_data;
|
||||
|
||||
$file_name_with_path = WRITEPATH."/uploads/excel/".$file['file_name'];
|
||||
@ -1822,10 +1824,21 @@ class EmployeeServiceController extends AdminController
|
||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
$highestRowAndColumn = $sheet->getHighestRowAndColumn();
|
||||
$excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
|
||||
$excelErrorData['excel_header'] = $excel_data[0];
|
||||
unset($excel_data[0]);
|
||||
$highestRowAndColumn = $sheet->getHighestRowAndColumn();
|
||||
$excel_data = $sheet->rangeToArray('A1:' . 'N' . $highestRowAndColumn['row']);
|
||||
$excelErrorData['excel_header'] = $excel_data[0];
|
||||
unset($excel_data[0]);
|
||||
|
||||
$excel_data = array_filter($excel_data, function($row) {
|
||||
// Check if all cells in the row are empty or null
|
||||
foreach ($row as $cell) {
|
||||
if (!is_null($cell) && $cell !== '') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
// echo '<pre>';
|
||||
// Kint::dump($excel_data);
|
||||
if($error_data->error_type == 1){
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
436
app/Helpers/RestAuthHelper.php
Normal file
436
app/Helpers/RestAuthHelper.php
Normal file
@ -0,0 +1,436 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use App\Models\ClientModel;
|
||||
use App\Models\ClientPolicyModel;
|
||||
use App\Models\EmployeeModel;
|
||||
use App\Models\EmployeePolicyModel;
|
||||
|
||||
|
||||
class RestAuthHelper
|
||||
{
|
||||
// public static function getPreAndPostDataByEmailOrMobile($params)
|
||||
// {
|
||||
// // print_r($params); die;
|
||||
// $mobile_number = $params['mobile_number'] ?? null;
|
||||
// $email_id = $params['email_id'] ?? null;
|
||||
// $otp = $params['otp'] ?? null;
|
||||
// $old_mpin = $params['$old_mpin'] ?? null;
|
||||
|
||||
// // Return null if both inputs are empty
|
||||
// if (empty($mobile_number) && empty($email_id)) {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// $params = [
|
||||
// 'mobile_number' => $mobile_number,
|
||||
// 'email_id' => $email_id,
|
||||
// 'otp' => $otp,
|
||||
// '$old_mpin' => $old_mpin,
|
||||
// ];
|
||||
|
||||
// $pre_data = self::getPreEmployeeData($params);
|
||||
// $post_data = self::getPostEmployeeData($params);
|
||||
|
||||
// // Return empty array if both are missing
|
||||
// if (empty($pre_data) && empty($post_data)) {
|
||||
// return [];
|
||||
// }
|
||||
|
||||
// // Determine the latest record
|
||||
// $latest_key = null;
|
||||
// if (!empty($pre_data) && !empty($post_data)) {
|
||||
// $latest_key = strtotime($pre_data['created_at']) > strtotime($post_data['created_at']) ? 'pre' : 'post';
|
||||
// } elseif (!empty($pre_data)) {
|
||||
// $latest_key = 'pre';
|
||||
// } elseif (!empty($post_data)) {
|
||||
// $latest_key = 'post';
|
||||
// }
|
||||
|
||||
// // Compare client_short_name only if both records exist
|
||||
// if (!empty($pre_data) && !empty($post_data)) {
|
||||
// $latest_data = $latest_key === 'pre' ? $pre_data : $post_data;
|
||||
// $other_data = $latest_key === 'pre' ? $post_data : $pre_data;
|
||||
|
||||
// if ($latest_data['client_short_name'] === $other_data['client_short_name']) {
|
||||
// return [
|
||||
// 'pre' => $pre_data,
|
||||
// 'post' => $post_data,
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
|
||||
// // If one of the data is missing or client names mismatch
|
||||
// return [
|
||||
// 'pre' => $latest_key === 'pre' ? $pre_data : [],
|
||||
// 'post' => $latest_key === 'post' ? $post_data : [],
|
||||
// ];
|
||||
// }
|
||||
|
||||
// public static function getPreEmployeeData(array $params)
|
||||
// {
|
||||
// $employeeModel = new EmployeeModel();
|
||||
|
||||
// $mobile_number = $params['mobile_number'] ?? null;
|
||||
// $email_id = $params['email_id'] ?? null;
|
||||
// $otp = $params['otp'] ?? null;
|
||||
// $old_mpin = $params['old_mpin'] ?? null;
|
||||
|
||||
// if (!empty($mobile_number)) {
|
||||
// $builder = $employeeModel
|
||||
// ->select('employees.id as employee_id, employees.*')
|
||||
// ->join('employee_polices EP', 'EP.employee_id = employees.id', 'inner')
|
||||
// ->where('employees.is_active', 1)
|
||||
// ->where("TRIM(employees.relationship) = 'self'", null, false)
|
||||
// ->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
// ->where('employees.mobile', $mobile_number)
|
||||
// ->where('EP.is_active', 1)
|
||||
// ->whereIn('EP.status', ['draft', 'enrolled']);
|
||||
|
||||
// if (!empty($old_mpin)) {
|
||||
// $builder->where('employees.mpin', $old_mpin);
|
||||
// }
|
||||
|
||||
// $employeeData = $builder->orderBy('employees.id', 'desc')->first();
|
||||
|
||||
// } elseif (!empty($email_id)) {
|
||||
// $builder = $employeeModel
|
||||
// ->select('employees.id as employee_id, employees.*')
|
||||
// ->join('employee_polices EP', 'EP.employee_id = employees.id', 'inner')
|
||||
// ->where('employees.is_active', 1)
|
||||
// ->where("TRIM(employees.relationship) = 'self'", null, false)
|
||||
// ->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
// ->where('employees.email_corporate', $email_id)
|
||||
// ->where('EP.is_active', 1)
|
||||
// ->whereIn('EP.status', ['draft', 'enrolled']);
|
||||
|
||||
// if (!empty($otp)) {
|
||||
// $builder->where('employees.otp', $otp);
|
||||
// }
|
||||
|
||||
// if (!empty($old_mpin)) {
|
||||
// $builder->where('employees.mpin', $old_mpin);
|
||||
// }
|
||||
|
||||
// $employeeData = $builder->orderBy('employees.id', 'desc')->first();
|
||||
|
||||
// } else {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// if($employeeData){
|
||||
// $clientModel = new ClientModel;
|
||||
// $client_data = $clientModel->where('is_active', 1)->where('id', $employeeData['client_id'])->first();
|
||||
// $employeeData['client_short_name'] = $client_data['short_name'];
|
||||
// }
|
||||
|
||||
// return $employeeData;
|
||||
// }
|
||||
|
||||
// public static function getPostEmployeeData(array $params)
|
||||
// {
|
||||
// // print_r($params); die;
|
||||
// $mobile_number = $params['mobile_number'] ?? null;
|
||||
// $email_id = $params['email_id'] ?? null;
|
||||
// $otp = $params['otp'] ?? null;
|
||||
// $old_mpin = $params['old_mpin'] ?? null;
|
||||
|
||||
|
||||
// if (!empty($mobile_number) || !empty($email_id)) {
|
||||
|
||||
// $client = \Config\Services::curlrequest();
|
||||
// $endPoint = 'getPostEmployeeDataForAuth';
|
||||
// $url = env('POST_ENROLLMENT_BASEURL') . $endPoint;
|
||||
|
||||
// $postData = [];
|
||||
|
||||
// if (!empty($mobile_number)) {
|
||||
// $postData['mobile_number'] = $mobile_number;
|
||||
// }
|
||||
|
||||
// if (!empty($email_id)) {
|
||||
// $postData['email_id'] = $email_id;
|
||||
// }
|
||||
|
||||
// if (!empty($otp)) {
|
||||
// $postData['otp'] = $otp;
|
||||
// }
|
||||
|
||||
// if (!empty($old_mpin)) {
|
||||
// $postData['old_mpin'] = $old_mpin;
|
||||
// }
|
||||
|
||||
// $response = $client->post( $url, ['json' => $postData, 'http_errors' => false]);
|
||||
// $post_json = $response->getBody();
|
||||
// $post_data = json_decode($post_json, true);
|
||||
|
||||
// return $post_data['data'];
|
||||
// }
|
||||
// }
|
||||
|
||||
public static function getPreAndPostDataByEmailOrMobile($params)
|
||||
{
|
||||
log_message('error', 'Function getPreAndPostDataByEmailOrMobile called with: ' . json_encode($params));
|
||||
|
||||
$mobile_number = $params['mobile_number'] ?? null;
|
||||
$email_id = $params['email_id'] ?? null;
|
||||
$otp = $params['otp'] ?? null;
|
||||
$old_mpin = $params['old_mpin'] ?? null;
|
||||
$check_mpin = $params['check_mpin'] ?? null;
|
||||
|
||||
if (empty($mobile_number) && empty($email_id)) {
|
||||
log_message('error', 'Both mobile_number and email_id are empty. Returning null.');
|
||||
return null;
|
||||
}
|
||||
|
||||
$params = [
|
||||
'mobile_number' => $mobile_number,
|
||||
'email_id' => $email_id,
|
||||
'otp' => $otp,
|
||||
'old_mpin' => $old_mpin,
|
||||
];
|
||||
|
||||
$pre_data = self::getPreEmployeeData($params);
|
||||
$post_data = self::getPostEmployeeData($params);
|
||||
|
||||
log_message('error', 'Pre Data: ' . json_encode($pre_data));
|
||||
log_message('error', 'Post Data: ' . json_encode($post_data));
|
||||
|
||||
if (empty($pre_data) && empty($post_data)) {
|
||||
log_message('error', 'Both pre_data and post_data are empty. Returning empty array.');
|
||||
return [];
|
||||
}
|
||||
|
||||
$latest_key = null;
|
||||
if (!empty($pre_data) && !empty($post_data)) {
|
||||
$latest_key = strtotime($pre_data['created_at']) > strtotime($post_data['created_at']) ? 'pre' : 'post';
|
||||
} elseif (!empty($pre_data)) {
|
||||
$latest_key = 'pre';
|
||||
} elseif (!empty($post_data)) {
|
||||
$latest_key = 'post';
|
||||
}
|
||||
|
||||
log_message('error', 'Latest key determined as: ' . $latest_key);
|
||||
|
||||
if (!empty($pre_data) && !empty($post_data)) {
|
||||
$latest_data = $latest_key === 'pre' ? $pre_data : $post_data;
|
||||
$other_data = $latest_key === 'pre' ? $post_data : $pre_data;
|
||||
|
||||
if ($latest_data['client_short_name'] === $other_data['client_short_name']) {
|
||||
log_message('error', 'client_short_name match. Returning both records.');
|
||||
|
||||
if ($check_mpin !== null && ($pre_data['mpin'] !== null || $post_data['mpin'] !== null)) {
|
||||
|
||||
// Case: Pre MPIN is missing, update it from Post
|
||||
if ($pre_data['mpin'] === null && $post_data['mpin'] !== null) {
|
||||
$data = [
|
||||
'client_id' => $pre_data['client_id'],
|
||||
'employee_id' => $pre_data['id'],
|
||||
'mpin' => $post_data['mpin'],
|
||||
'is_mpin_skipped' => $post_data['is_mpin_skipped'],
|
||||
'is_biometric_enabled' => $post_data['is_biometric_enabled'],
|
||||
];
|
||||
$response = self::updatePreMpin($data);
|
||||
|
||||
// Case: Post MPIN is missing, update it from Pre
|
||||
} elseif ($post_data['mpin'] === null && $pre_data['mpin'] !== null) {
|
||||
$data = [
|
||||
'client_id' => $post_data['client_id'],
|
||||
'employee_id' => $post_data['id'],
|
||||
'mpin' => $pre_data['mpin'],
|
||||
'is_mpin_skipped' => $pre_data['is_mpin_skipped'],
|
||||
'is_biometric_enabled' => $pre_data['is_biometric_enabled'],
|
||||
];
|
||||
$response = self::updatePostMpin($data);
|
||||
}
|
||||
}
|
||||
|
||||
return ['pre' => $pre_data, 'post' => $post_data];
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
'pre' => $latest_key === 'pre' ? $pre_data : [],
|
||||
'post' => $latest_key === 'post' ? $post_data : [],
|
||||
];
|
||||
|
||||
log_message('error', 'Returning data: ' . json_encode($result));
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getPreEmployeeData(array $params)
|
||||
{
|
||||
log_message('error', 'Function getPreEmployeeData called with: ' . json_encode($params));
|
||||
|
||||
$employeeModel = new EmployeeModel();
|
||||
|
||||
$mobile_number = $params['mobile_number'] ?? null;
|
||||
$email_id = $params['email_id'] ?? null;
|
||||
$otp = $params['otp'] ?? null;
|
||||
$old_mpin = $params['old_mpin'] ?? null;
|
||||
|
||||
$employeeData = null;
|
||||
|
||||
if (!empty($mobile_number)) {
|
||||
log_message('error', 'Searching employee by mobile_number: ' . $mobile_number);
|
||||
|
||||
$builder = $employeeModel
|
||||
->select('employees.id as employee_id, employees.*')
|
||||
->join('employee_polices EP', 'EP.employee_id = employees.id', 'inner')
|
||||
->where('employees.is_active', 1)
|
||||
->where("TRIM(employees.relationship) = 'self'", null, false)
|
||||
->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
->where('employees.mobile', $mobile_number)
|
||||
->where('EP.is_active', 1)
|
||||
->whereIn('EP.status', ['draft', 'enrolled']);
|
||||
|
||||
if (!empty($old_mpin)) {
|
||||
$builder->where('employees.mpin', $old_mpin);
|
||||
}
|
||||
|
||||
$employeeData = $builder->orderBy('employees.id', 'desc')->first();
|
||||
} elseif (!empty($email_id)) {
|
||||
log_message('error', 'Searching employee by email_id: ' . $email_id);
|
||||
|
||||
$builder = $employeeModel
|
||||
->select('employees.id as employee_id, employees.*')
|
||||
->join('employee_polices EP', 'EP.employee_id = employees.id', 'inner')
|
||||
->where('employees.is_active', 1)
|
||||
->where("TRIM(employees.relationship) = 'self'", null, false)
|
||||
->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
->where('employees.email_corporate', $email_id)
|
||||
->where('EP.is_active', 1)
|
||||
->whereIn('EP.status', ['draft', 'enrolled']);
|
||||
|
||||
if (!empty($otp)) {
|
||||
$builder->where('employees.otp', $otp);
|
||||
}
|
||||
|
||||
if (!empty($old_mpin)) {
|
||||
$builder->where('employees.mpin', $old_mpin);
|
||||
}
|
||||
|
||||
$employeeData = $builder->orderBy('employees.id', 'desc')->first();
|
||||
} else {
|
||||
log_message('warning', 'No mobile or email found. Returning null.');
|
||||
return null;
|
||||
}
|
||||
|
||||
log_message('error', 'Pre employee data fetched: ' . json_encode($employeeData));
|
||||
|
||||
if ($employeeData) {
|
||||
$clientModel = new ClientModel;
|
||||
$client_data = $clientModel->where('is_active', 1)->where('id', $employeeData['client_id'])->first();
|
||||
$employeeData['client_short_name'] = $client_data['short_name'] ?? '';
|
||||
log_message('error', 'Client short name attached: ' . $employeeData['client_short_name']);
|
||||
}
|
||||
|
||||
return $employeeData;
|
||||
}
|
||||
|
||||
public static function getPostEmployeeData(array $params)
|
||||
{
|
||||
log_message('error', 'Function getPostEmployeeData called with: ' . json_encode($params));
|
||||
|
||||
$mobile_number = $params['mobile_number'] ?? null;
|
||||
$email_id = $params['email_id'] ?? null;
|
||||
$otp = $params['otp'] ?? null;
|
||||
$old_mpin = $params['old_mpin'] ?? null;
|
||||
|
||||
if (!empty($mobile_number) || !empty($email_id)) {
|
||||
$client = \Config\Services::curlrequest();
|
||||
$endPoint = 'getPostEmployeeDataForAuth';
|
||||
$url = env('POST_ENROLLMENT_BASEURL') . $endPoint;
|
||||
|
||||
$postData = [];
|
||||
|
||||
if (!empty($mobile_number)) {
|
||||
$postData['mobile_number'] = $mobile_number;
|
||||
}
|
||||
|
||||
if (!empty($email_id)) {
|
||||
$postData['email_id'] = $email_id;
|
||||
}
|
||||
|
||||
if (!empty($otp)) {
|
||||
$postData['otp'] = $otp;
|
||||
}
|
||||
|
||||
if (!empty($old_mpin)) {
|
||||
$postData['old_mpin'] = $old_mpin;
|
||||
}
|
||||
|
||||
log_message('error', 'Sending POST to external API: ' . $url);
|
||||
log_message('error', 'POST payload: ' . json_encode($postData));
|
||||
|
||||
$response = $client->post($url, ['json' => $postData, 'http_errors' => false]);
|
||||
|
||||
$post_json = $response->getBody();
|
||||
// log_message('error', 'Response from API: ' . $post_json);
|
||||
|
||||
$post_data = json_decode($post_json, true);
|
||||
|
||||
$data = $post_data['data'] ?? [];
|
||||
log_message('error', 'Parsed post_data: ' . json_encode($data));
|
||||
return $data;
|
||||
}
|
||||
|
||||
log_message('warning', 'No mobile or email present in params for post fetch.');
|
||||
}
|
||||
|
||||
public static function updatePreMpin(array $params)
|
||||
{
|
||||
log_message('info', 'Function updatePostMpin called with: ' . json_encode($params));
|
||||
|
||||
$employee_id = $params['employee_id'] ?? null;
|
||||
$mpin = $params['mpin'] ?? null;
|
||||
|
||||
if (empty($employee_id) || empty($mpin)) {
|
||||
log_message('error', 'Missing employee_id or mpin in updatePreMpin');
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$employeeModel = new EmployeeModel();
|
||||
$result = $employeeModel
|
||||
->where('id', $employee_id)
|
||||
->set('mpin', $mpin)
|
||||
->update();
|
||||
|
||||
log_message('info', 'MPIN update status (Pre): ' . var_export($result, true));
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Exception in updatePreMpin: ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function updatePostMpin(array $params)
|
||||
{
|
||||
if (isset($params['mpin']) && isset($params['employee_id'])) {
|
||||
|
||||
$client = \Config\Services::curlrequest();
|
||||
$endPoint = 'updateEmpMPIN';
|
||||
$url = env('POST_ENROLLMENT_BASEURL') . $endPoint;
|
||||
|
||||
log_message('info', '[updatePostMpin] Sending POST to external API: ' . $url);
|
||||
log_message('debug', '[updatePostMpin] Request Payload: ' . json_encode($params));
|
||||
|
||||
$response = $client->post($url, ['json' => $params, 'http_errors' => false]);
|
||||
|
||||
$post_json = $response->getBody();
|
||||
log_message('info', '[updatePostMpin] Raw API Response: ' . $post_json);
|
||||
|
||||
$post_data = json_decode($post_json, true);
|
||||
|
||||
$data = $post_data['data'] ?? [];
|
||||
log_message('debug', '[updatePostMpin] Parsed Response Data: ' . json_encode($data));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
log_message('warning', '[updatePostMpin] Missing required parameters: employee_id or mpin');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -42,7 +42,9 @@ class EmployeeModel extends Model
|
||||
"token_time_out",
|
||||
"emp_type",
|
||||
"unit",
|
||||
"mpin"
|
||||
"mpin",
|
||||
"is_mpin_skipped",
|
||||
"is_biometric_enabled",
|
||||
];
|
||||
|
||||
// Callbacks
|
||||
|
||||
@ -19,7 +19,8 @@ class FileModel extends Model
|
||||
"client_id",
|
||||
"policy_id",
|
||||
"client_branch_id",
|
||||
"uploaded_by"
|
||||
"uploaded_by",
|
||||
"updated_by"
|
||||
];
|
||||
|
||||
|
||||
|
||||
@ -98,7 +98,7 @@ input:checked + .slider:before {
|
||||
<label for="short_name">Client Short Name<span
|
||||
class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" id="short_name"
|
||||
placeholder="Enter Short Name" value="<?= isset($client['short_name']) ? $client['short_name'] : '' ?>" name="short_name" required>
|
||||
placeholder="Enter Short Name" value="<?= isset($client['short_name']) ? $client['short_name'] : '' ?>" name="short_name" onkeyup="validateInput(this, 'clients', 'short_name', 'clientBtnSubmit')" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -137,7 +137,7 @@ input:checked + .slider:before {
|
||||
|
||||
<div class="form-group text-right m-b-0">
|
||||
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
|
||||
id="btnSubmit">Submit</button>
|
||||
id="clientBtnSubmit">Submit</button>
|
||||
<button type="button" class="btn btn-secondary waves-effect btnBack"
|
||||
id="btnBack">Cancel</button>
|
||||
</div>
|
||||
|
||||
@ -160,7 +160,7 @@
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
<!--
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-6">
|
||||
<label>Contact 1</label>
|
||||
@ -168,6 +168,7 @@
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<input type="hidden" name="branch_table_pk[]" id="branch_table_pk" >
|
||||
<div class="form-group col-md-6">
|
||||
<label for="first_name">Name<span class="text-danger">*</span></label>
|
||||
<input value="" type="text" class="form-control" placeholder="Enter Contact Name"
|
||||
@ -179,22 +180,24 @@
|
||||
name="designation[]" id="designation" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-6">
|
||||
<label for="last_name">Email<span class="text-danger">*</span></label>
|
||||
<input value="" type="text" class="form-control" placeholder="Enter Contact Email"
|
||||
name="email[]" id="email" data-parsley-trigger="change" data-parsley-type="email" required>
|
||||
name="email[]" id="email" data-parsley-trigger="change" data-parsley-type="email" onkeyup="validateInput(this, 'level_contacts', 'email', 'branchBtnSubmit')" required>
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label for="mobile">Mobile<span class="text-danger">*</span></label>
|
||||
<input value="" type="text" class="form-control" placeholder="Enter Contact Mobile"
|
||||
name="mobile[]" id="mobile" onchange="checkMobileNumber(this)"
|
||||
name="mobile[]" id="mobile" onkeyup="validateInput(this, 'level_contacts', 'mobile', 'branchBtnSubmit')"
|
||||
onkeypress="return onlyNumbers(event)" maxlength="10" minlength="10"
|
||||
data-parsley-type-message="Please enter a valid 10-digit mobile number."
|
||||
data-parsley-required-message="Please enter a valid 10-digit mobile number."
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="display: flex;">
|
||||
<button style="margin-right: 10px;" type="button" class="btn btn-primary btn-sm ac"
|
||||
onclick="appendContactHtml()" id="add">Add Contact</button>
|
||||
@ -202,12 +205,12 @@
|
||||
id="remove_btn">Remove</button>
|
||||
</div>
|
||||
|
||||
<div id="container"></div> -->
|
||||
<div id="container"></div>
|
||||
|
||||
</div>
|
||||
<div class="form-group text-right m-b-0">
|
||||
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
|
||||
id="btnSubmit">Submit</button>
|
||||
id="branchBtnSubmit">Submit</button>
|
||||
<button type="button" class="btn btn-secondary waves-effect btnBack"
|
||||
id="btnBack">Cancel</button>
|
||||
</div>
|
||||
@ -352,6 +355,9 @@ $("#branch_form").submit(function(event) {
|
||||
var selectedValues = $("#selected").val();
|
||||
console.log(selectedValues, selectedValues);
|
||||
|
||||
let level_contect_data = getContactsData();
|
||||
console.log('level_contect_data', level_contect_data);
|
||||
|
||||
event.preventDefault();
|
||||
branch_PrimaryKey = $('#client_id_branch').val();
|
||||
|
||||
@ -375,11 +381,14 @@ $("#branch_form").submit(function(event) {
|
||||
var formData = new FormData($('#branch_form')[0]);
|
||||
|
||||
const jsonString = JSON.stringify(selectedValues);
|
||||
const level_contect_data_json_string = JSON.stringify(level_contect_data);
|
||||
console.log('jsonString', jsonString);
|
||||
console.log('level_contect_data_json_string', level_contect_data_json_string);
|
||||
|
||||
|
||||
// Append the JSON string to the FormData object
|
||||
formData.append('units', jsonString);
|
||||
formData.append('level_contect_data', level_contect_data_json_string);
|
||||
|
||||
$.ajax({
|
||||
data: formData,
|
||||
@ -500,6 +509,8 @@ $('body').on('click', '.btnBranchEdit', function() {
|
||||
dataType: 'json',
|
||||
success: function(res) {
|
||||
|
||||
console.log('client branch edit data response : ', res);
|
||||
|
||||
setTimeout(function() {
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(350).fadeOut('slow');
|
||||
@ -530,10 +541,24 @@ $('body').on('click', '.btnBranchEdit', function() {
|
||||
|
||||
appendOption(res.data.units)
|
||||
|
||||
$('#name').val(res.contact[0].name);
|
||||
$('#email').val(res.contact[0].email);
|
||||
$('#mobile').val(res.contact[0].mobile);
|
||||
$('#designation').val(res.contact[0].designation);
|
||||
// $('#name').val(res.contact[0].name);
|
||||
// $('#email').val(res.contact[0].email);
|
||||
// $('#mobile').val(res.contact[0].mobile);
|
||||
// $('#designation').val(res.contact[0].designation);
|
||||
|
||||
if (res.contact && res.contact.length > 0 && res.contact[0]) {
|
||||
$('#branch_table_pk').val(res.contact[0].id || '');
|
||||
$('#name').val(res.contact[0].name || '');
|
||||
$('#email').val(res.contact[0].email || '');
|
||||
$('#mobile').val(res.contact[0].mobile || '');
|
||||
$('#designation').val(res.contact[0].designation || '');
|
||||
} else {
|
||||
$('#branch_table_pk').val('');
|
||||
$('#name').val('');
|
||||
$('#email').val('');
|
||||
$('#mobile').val('');
|
||||
$('#designation').val('');
|
||||
}
|
||||
|
||||
res.contact.shift();
|
||||
// console.log(res.contact.length)
|
||||
@ -559,12 +584,12 @@ $('body').on('click', '.btnBranchEdit', function() {
|
||||
console.log(branch_form_action);
|
||||
});
|
||||
|
||||
$("#remove_btn").click(function() {
|
||||
$("#name").val('');
|
||||
$("#email").val('');
|
||||
$("#mobile").val('');
|
||||
$("#designation").val('');
|
||||
})
|
||||
// $("#remove_btn").click(function() {
|
||||
// $("#name").val('');
|
||||
// $("#email").val('');
|
||||
// $("#mobile").val('');
|
||||
// $("#designation").val('');
|
||||
// })
|
||||
|
||||
// Initialize the contact count
|
||||
function appendContactHtml(contact = false, reset = false) {
|
||||
@ -584,6 +609,7 @@ function appendContactHtml(contact = false, reset = false) {
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<input type="hidden" name="branch_table_pk[]" id="${uniqueId}_branch_table_pk" value="${contact !== undefined && contact !== false ? contact.id : ''}">
|
||||
<div class="form-group col-md-6">
|
||||
<label for="${uniqueId}_first_name">Name<span class="text-danger">*</span></label>
|
||||
<input value="${contact !== undefined && contact !== false ? contact.name : ''}" type="text" class="form-control" placeholder="Enter Contact Name" name="name[]" id="${uniqueId}_name" required>
|
||||
@ -596,11 +622,11 @@ function appendContactHtml(contact = false, reset = false) {
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-6">
|
||||
<label for="${uniqueId}_last_name">Email<span class="text-danger">*</span></label>
|
||||
<input value="${contact !== undefined && contact !== false ? contact.email : ''}" type="text" class="form-control" placeholder="Enter Contact Email" name="email[]" id="${uniqueId}_email" data-parsley-trigger="change" data-parsley-type="email" required>
|
||||
<input value="${contact !== undefined && contact !== false ? contact.email : ''}" type="text" class="form-control" placeholder="Enter Contact Email" name="email[]" id="${uniqueId}_email" data-parsley-trigger="change" data-parsley-type="email" onchange="validateInput(this, 'level_contacts', 'email', 'branchBtnSubmit')" required>
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label for="${uniqueId}_mobile">Mobile<span class="text-danger">*</span></label>
|
||||
<input value="${contact !== undefined && contact !== false ? contact.mobile : ''}" type="text" class="form-control" placeholder="Enter Contact Mobile" name="mobile[]" id="${uniqueId}_mobile" onchange="checkMobileNumber(this)" onkeypress = "return onlyNumbers(event)" maxlength="10" min="10" data-parsley-type-message="Please enter a valid 10-digit mobile number." data-parsley-required-message="Please enter a valid 10-digit mobile number." required>
|
||||
<input value="${contact !== undefined && contact !== false ? contact.mobile : ''}" type="text" class="form-control" placeholder="Enter Contact Mobile" name="mobile[]" id="${uniqueId}_mobile" onkeyup="validateInput(this, 'level_contacts', 'mobile', 'branchBtnSubmit')" onkeypress = "return onlyNumbers(event)" maxlength="10" min="10" data-parsley-type-message="Please enter a valid 10-digit mobile number." data-parsley-required-message="Please enter a valid 10-digit mobile number." required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" style="display: flex;">
|
||||
@ -623,20 +649,50 @@ function appendContactHtml(contact = false, reset = false) {
|
||||
}
|
||||
|
||||
function removeContact(button) {
|
||||
|
||||
var uniqueId = button.id.split("_")[0];
|
||||
console.log('uniqueId', uniqueId);
|
||||
var contactSection = document.getElementById(uniqueId);
|
||||
console.log('contactSection', contactSection);
|
||||
|
||||
if (contactSection) {
|
||||
contactSection.parentNode.removeChild(contactSection);
|
||||
contactCount--;
|
||||
confirmActionSweertAlert("Do you want to remove this contact?", "Yes, Proceed!", "No, Cancel").then((confirmed) => {
|
||||
if(confirmed){
|
||||
if (contactSection) {
|
||||
|
||||
if (contactCount < 3) {
|
||||
var addButton = document.querySelector('.ac');
|
||||
if (addButton) {
|
||||
addButton.style.display = 'block';
|
||||
let unique_param = uniqueId + '_branch_table_pk';
|
||||
console.log('unique_param', unique_param);
|
||||
let other_id = $('#' + unique_param).val();
|
||||
console.log('other_id', other_id);
|
||||
|
||||
contactSection.parentNode.removeChild(contactSection);
|
||||
contactCount--;
|
||||
|
||||
if (contactCount < 3) {
|
||||
var addButton = document.querySelector('.ac');
|
||||
if (addButton) {
|
||||
addButton.style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
if(other_id){
|
||||
removeLevelContacts(other_id);
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
$("#name").val('');
|
||||
$("#email").val('');
|
||||
$("#mobile").val('');
|
||||
$("#designation").val('');
|
||||
|
||||
let first_id = $('#branch_table_pk').val();
|
||||
console.log('first_id', first_id);
|
||||
if(first_id){
|
||||
removeLevelContacts(first_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function storeButtonId(id) {
|
||||
@ -772,6 +828,75 @@ function checkMobileNumber(input) {
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function validateInput(input, table, field, submitBtnId){
|
||||
|
||||
let value = $(input).val();
|
||||
let label = $(input).closest('.form-group').find('label').text().replace('*', '').trim();
|
||||
|
||||
let message = "Value is duplicate!";
|
||||
if(label){
|
||||
message = label + " already exists!";
|
||||
}
|
||||
|
||||
checkDuplicateTableFieldValue(table, field, value, function(isDuplicate) {
|
||||
if (isDuplicate) {
|
||||
toastr.warning(message, 'WARNING');
|
||||
// $(input).val('')
|
||||
$('#'+submitBtnId).prop('disabled', true);
|
||||
} else{
|
||||
$('#'+submitBtnId).prop('disabled', false);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function getContactsData() {
|
||||
const contacts = [];
|
||||
|
||||
const ids = $('input[name="branch_table_pk[]"]');
|
||||
const names = $('input[name="name[]"]');
|
||||
const mobiles = $('input[name="mobile[]"]');
|
||||
const emails = $('input[name="email[]"]');
|
||||
const designations = $('input[name="designation[]"]');
|
||||
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
contacts.push({
|
||||
id: $(ids[i]).val() || null,
|
||||
name: $(names[i]).val(),
|
||||
mobile: $(mobiles[i]).val(),
|
||||
email: $(emails[i]).val(),
|
||||
designation: $(designations[i]).val()
|
||||
});
|
||||
}
|
||||
|
||||
return contacts;
|
||||
}
|
||||
|
||||
function removeLevelContacts(id){
|
||||
|
||||
let url = '<?= base_url('util/removeLevelContacts') ?>';
|
||||
|
||||
let requestData = {
|
||||
id: id,
|
||||
};
|
||||
|
||||
// Send AJAX request
|
||||
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
|
||||
|
||||
console.log('Data fetched successfully:', response);
|
||||
if (response.status == true) {
|
||||
toastr.success(response.message, 'SUCCESS');
|
||||
} else {
|
||||
toastr.warning(response.message, 'WARNING');
|
||||
}
|
||||
|
||||
}, function(xhr, status, error) {
|
||||
console.error('Error fetching data:', error);
|
||||
console.error(xhr.responseText);
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<script>
|
||||
|
||||
@ -91,6 +91,14 @@
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
body[data-sidebar-size=condensed] .navbar-custom {
|
||||
left: 155px !important;
|
||||
}
|
||||
|
||||
body[data-sidebar-size=condensed] .logo-box {
|
||||
width: 155px !important;
|
||||
}
|
||||
|
||||
.navbar-custom {
|
||||
top: -10px !important;
|
||||
height: 61px !important;
|
||||
@ -536,7 +544,7 @@
|
||||
|
||||
<a href="<?= base_url('/dashboard/view') ?>" class="logo logo-light text-center">
|
||||
<span class="logo-sm">
|
||||
<img src="<?= base_url() . "public"; ?>/assets/images/Nhance_Favi_white_2.png" alt="" width="30" height="30">
|
||||
<img src="<?= base_url() . "public"; ?>/assets/images/nhance_white_logo.svg" alt="" width="130" height="30">
|
||||
</span>
|
||||
<!-- <span class="logo-lg">
|
||||
<img src="<?= base_url() . "public"; ?>./assets/images/logo-light.png" alt="" height="20">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user