MERGE_UAT_MPIN&HR_ADD
This commit is contained in:
commit
3071002c59
@ -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');
|
||||
|
||||
});
|
||||
|
||||
@ -445,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");
|
||||
@ -489,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");
|
||||
|
||||
@ -505,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();
|
||||
|
||||
}
|
||||
|
||||
@ -748,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);
|
||||
|
||||
@ -1072,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);
|
||||
}
|
||||
|
||||
@ -1709,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2490,20 +2600,45 @@ class EmployeeRestController extends AdminController
|
||||
public function getPolicyLevelEmployeeSummaryData()
|
||||
{
|
||||
|
||||
$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($policyId) == 0){
|
||||
return $this->respond(['status' => 'failed','code' => (count($policyId) ? 200 : 404),'data' => [] ], 200);
|
||||
}
|
||||
|
||||
$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 ')
|
||||
|
||||
$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;
|
||||
@ -3286,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){
|
||||
|
||||
@ -9,6 +9,7 @@ use App\Controllers\LoginController;
|
||||
use App\Helpers\DepositHelper;
|
||||
use App\Helpers\JWTToken;
|
||||
use App\Helpers\HttpRequestHelper;
|
||||
use App\Helpers\RestAuthHelper;
|
||||
|
||||
use CodeIgniter\HTTP\IncomingRequest;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
@ -73,6 +74,45 @@ class RestAuthenticationController extends AdminController
|
||||
return $response->getBody();
|
||||
}
|
||||
|
||||
// public function callThirdPartyGETAPI($queryParams, $endPoint)
|
||||
// {
|
||||
// $client = \Config\Services::curlrequest();
|
||||
// $url = env('POST_ENROLLMENT_BASEURL') . $endPoint;
|
||||
|
||||
// $response = $client->get($url, [
|
||||
// 'query' => $queryParams, // pass as query parameters
|
||||
// 'http_errors' => false // prevent exception on non-200 status
|
||||
// ]);
|
||||
|
||||
// return $response->getBody();
|
||||
// }
|
||||
|
||||
public function callThirdPartyGETAPI($queryParams, $endPoint, $params = [])
|
||||
{
|
||||
$client = \Config\Services::curlrequest();
|
||||
$url = env('POST_ENROLLMENT_BASEURL') . $endPoint;
|
||||
|
||||
$options = [
|
||||
'query' => $queryParams,
|
||||
'http_errors' => false,
|
||||
];
|
||||
|
||||
if (isset($params['token']) && !empty($params['token'])) {
|
||||
$options['headers'] = [
|
||||
'Authorization' => 'Bearer ' . $params['token'],
|
||||
'Accept' => 'application/json'
|
||||
];
|
||||
}
|
||||
|
||||
$response = $client->get($url, $options);
|
||||
|
||||
return $response->getBody();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// employee auth api's start
|
||||
@ -82,6 +122,12 @@ class RestAuthenticationController extends AdminController
|
||||
try {
|
||||
$mobile_number = $this->request->getJSON()->mobile_number;
|
||||
|
||||
$empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['mobile_number' => $mobile_number]);
|
||||
|
||||
if(empty($empdata)){
|
||||
$result = ['user_verification' => false , 'message' => "User not found"];
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200);
|
||||
}
|
||||
|
||||
$employeeData = $this->employeeModel->select('employees.relationship,EP.employee_id')
|
||||
->join('employee_polices EP', 'EP.employee_id = employees.id', 'inner')
|
||||
@ -92,8 +138,14 @@ class RestAuthenticationController extends AdminController
|
||||
->where('EP.is_active', 1)
|
||||
->whereIn('EP.status', ['draft', 'enrolled', 'expired'])
|
||||
->first();
|
||||
|
||||
|
||||
|
||||
$employeeData = [];
|
||||
if (isset($empdata['pre']) && !empty($empdata['pre'])) {
|
||||
$employeeData = $empdata['pre'];
|
||||
} elseif (isset($empdata['post']) && !empty($empdata['post'])) {
|
||||
$employeeData = $empdata['post'];
|
||||
}
|
||||
|
||||
|
||||
if (isset($employeeData['employee_id']))
|
||||
{
|
||||
@ -102,7 +154,6 @@ class RestAuthenticationController extends AdminController
|
||||
} else {
|
||||
// Call the third-party API function
|
||||
return $this->callThirdPartyAPI($this->request->getJSON(),'verifyEmployeeNumber');
|
||||
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
|
||||
@ -114,9 +165,16 @@ class RestAuthenticationController extends AdminController
|
||||
try {
|
||||
|
||||
$data = $this->request->getJSON();
|
||||
|
||||
$email = $data->email;
|
||||
|
||||
$empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email]);
|
||||
// print_r($empdata); die;
|
||||
|
||||
if(empty($empdata)){
|
||||
$result = ['user_verification' => false , 'message' => "User not found"];
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200);
|
||||
}
|
||||
|
||||
$employeeData = $this->employeeModel->select('
|
||||
employees.relationship,
|
||||
EP.employee_id,
|
||||
@ -132,7 +190,13 @@ class RestAuthenticationController extends AdminController
|
||||
->where('employees.email_corporate', $email)
|
||||
->where('EP.is_active', 1)
|
||||
->whereIn('EP.status', ['draft', 'enrolled', 'expired'])
|
||||
->first();
|
||||
->first();
|
||||
|
||||
$employeeData = [];
|
||||
if (isset($empdata['pre']) && !empty($empdata['pre'])) {
|
||||
$employeeData = $empdata['pre'];
|
||||
}
|
||||
|
||||
|
||||
if (isset($employeeData['employee_id'])) {
|
||||
|
||||
@ -146,7 +210,7 @@ class RestAuthenticationController extends AdminController
|
||||
UPDATE employees
|
||||
INNER JOIN employee_polices ON employee_polices.employee_id = employees.id
|
||||
SET employees.otp = ?
|
||||
WHERE employees.email_corporate = ?
|
||||
WHERE employees.id = ?
|
||||
AND employees.relationship = 'self'
|
||||
AND employees.is_active = 1
|
||||
AND employee_polices.is_active = 1
|
||||
@ -154,12 +218,17 @@ class RestAuthenticationController extends AdminController
|
||||
";
|
||||
|
||||
$db = db_connect();
|
||||
$update = $db->query($sql, [$otp, $email]);
|
||||
// $update = $db->query($sql, [$otp, $email]);
|
||||
$update = $db->query($sql, [$otp, $employeeData['employee_id']]);
|
||||
|
||||
|
||||
if($update)
|
||||
{
|
||||
$data->otp = $otp;
|
||||
if (isset($empdata['post']['client_id']) && !empty($empdata['post']['client_id'])) {
|
||||
$data->client_id = $empdata['post']['client_id'];
|
||||
$data->employee_id = $empdata['post']['employee_id'];
|
||||
}
|
||||
$this->callThirdPartyAPI($data, 'updateEmpOTP');
|
||||
|
||||
|
||||
@ -189,10 +258,17 @@ class RestAuthenticationController extends AdminController
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200);
|
||||
}
|
||||
} else {
|
||||
|
||||
$apiParams = $this->request->getJSON();
|
||||
if (!empty($empdata['post']['client_id'])) {
|
||||
$apiParams->client_id = $empdata['post']['client_id'];
|
||||
}
|
||||
// print_r($apiParams); die;
|
||||
// Call the third-party API function
|
||||
return $this->callThirdPartyAPI($this->request->getJSON(), 'verifyEmployeeEmailId');
|
||||
return $this->callThirdPartyAPI($apiParams, 'verifyEmployeeEmailId');
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
$this->myLogger->logme("error", ($th->getMessage().' --- '.$th->getLine()));
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $th], 500);
|
||||
}
|
||||
}
|
||||
@ -211,6 +287,14 @@ class RestAuthenticationController extends AdminController
|
||||
{
|
||||
$employeeData = $this->employeeModel->where('id', $this->request->getJSON()->employee_id)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first();
|
||||
}else{
|
||||
|
||||
$empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'otp' => $otp ]);
|
||||
// print_r($empdata); die;
|
||||
|
||||
if(empty($empdata)){
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => []],200);
|
||||
}
|
||||
|
||||
if (isset($mobile_number))
|
||||
{
|
||||
// $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first();
|
||||
@ -226,11 +310,36 @@ class RestAuthenticationController extends AdminController
|
||||
->whereIn('EP.status', ['draft', 'enrolled'])
|
||||
->first();
|
||||
} else {
|
||||
$employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('otp', $otp)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first();
|
||||
// $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('otp', $otp)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first();
|
||||
$employeeData = $this->employeeModel
|
||||
->select('employees.*')
|
||||
->join('employee_polices', 'employees.id = employee_polices.employee_id')
|
||||
->where('employees.email_corporate', $email_id)
|
||||
->where('employees.relationship', 'Self')
|
||||
->where('employee_polices.is_active', 1)
|
||||
->whereIn('employee_polices.status', ['draft', 'enrolled'])
|
||||
->where('employees.is_active', 1)
|
||||
->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
->where('employees.otp', $otp)
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
}
|
||||
|
||||
$employeeData = [];
|
||||
if (isset($empdata['pre']) && !empty($empdata['pre'])) {
|
||||
$employeeData = $empdata['pre'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$requestData = $this->request->getJSON();
|
||||
if (isset($empdata['post']['client_id']) && !empty($empdata['post']['client_id'])) {
|
||||
$requestData->client_id = $empdata['post']['client_id'];
|
||||
$requestData->employee_id = $empdata['post']['employee_id'];
|
||||
}
|
||||
|
||||
// print_r($requestData); die;
|
||||
|
||||
if ($employeeData && $otp_verification == true || $employeeData && isset($this->request->getJSON()->login_by_hr) || $employeeData && isset($this->request->getJSON()->otp) )
|
||||
{
|
||||
$auth = HttpRequestHelper::getRequestInfo();
|
||||
@ -245,26 +354,28 @@ class RestAuthenticationController extends AdminController
|
||||
$this->authHistoryModel->insert($data);
|
||||
}
|
||||
|
||||
|
||||
// print_r($employeeData); die;
|
||||
unset($employeeData['employee_id']);
|
||||
$result = JWTToken::encode($employeeData);
|
||||
|
||||
if(isset($this->request->getJSON()->otp)){
|
||||
$this->employeeModel->where('email_corporate', $email_id)->where('otp', $otp)->where('relationship', 'self')->set(['otp'=>null])->update();
|
||||
$this->employeeModel->where('id', $employeeData['id'])->where('otp', $otp)->where('relationship', 'self')->set(['otp'=>null])->update();
|
||||
}
|
||||
|
||||
// Call the third-party API function
|
||||
$apiResponse = $this->callThirdPartyAPI($this->request->getJSON(),'getVerifiedUserData');
|
||||
$apiResponse = $this->callThirdPartyAPI($requestData,'getVerifiedUserData');
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result , 'post_enrollment'=> json_decode($apiResponse, true)],200);
|
||||
|
||||
} else {
|
||||
|
||||
// Call the third-party API function
|
||||
$apiResponse = $this->callThirdPartyAPI($this->request->getJSON(),'getVerifiedUserData');
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => "Invalid OTP" , 'post_enrollment'=> json_decode($apiResponse, true)],200);
|
||||
$apiResponse = $this->callThirdPartyAPI($requestData,'getVerifiedUserData');
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => [] , 'post_enrollment'=> json_decode($apiResponse, true)],200);
|
||||
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500);
|
||||
$this->myLogger->logme("error", ($e->getMessage().' --- '.$e->getLine()));
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' =>[], 'error' => $e->getMessage()],500);
|
||||
}
|
||||
}
|
||||
|
||||
@ -369,7 +480,7 @@ class RestAuthenticationController extends AdminController
|
||||
try {
|
||||
// mobile number
|
||||
$otp_verification = isset($this->request->getJSON()->otp_verification) ? $this->request->getJSON()->otp_verification : null;
|
||||
$mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null;
|
||||
$mobile_number = isset($this->request->getJSON()->mobile_no) ? $this->request->getJSON()->mobile_no : null;
|
||||
// email id
|
||||
$otp = isset($this->request->getJSON()->otp) ? $this->request->getJSON()->otp : null;
|
||||
$email = isset($this->request->getJSON()->email) ? $this->request->getJSON()->email : null;
|
||||
@ -399,7 +510,7 @@ class RestAuthenticationController extends AdminController
|
||||
}
|
||||
|
||||
|
||||
if(isset($this->request->getJSON()->mobile_number)){
|
||||
if(isset($this->request->getJSON()->mobile_no)){
|
||||
|
||||
$hrData = $this->hrModel ->select('level_contacts.* , client_branch.client_id as client_id')
|
||||
->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left')
|
||||
@ -418,8 +529,18 @@ class RestAuthenticationController extends AdminController
|
||||
->find();
|
||||
}
|
||||
|
||||
//call and get allowed module data from post enrollment
|
||||
$queryParams = [
|
||||
'hr_id' => $hrData['0']['id'],
|
||||
'request_for' => 'pre_enrollment'
|
||||
];
|
||||
$HRAccessRes = $this->callThirdPartyGETAPI($queryParams,'getHRAccessData');
|
||||
$HRAccessData = json_decode($HRAccessRes,true);
|
||||
if(isset($HRAccessData['data']['allowed_modules'])){ $hrData['0']['allowed_modules'] = json_decode($HRAccessData['data']['allowed_modules'],true)['pre']; }else{ $hrData['0']['allowed_modules'] = []; }
|
||||
|
||||
$hrData['0']['token_type'] = 'pre';
|
||||
$result = JWTToken::encode($hrData['0']);
|
||||
|
||||
|
||||
// Call the third-party API function
|
||||
$apiResponse = $this->callThirdPartyAPI($this->request->getJSON(),'getVerifiedHrData');
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result , 'post_enrollment'=> json_decode($apiResponse, true)],200);
|
||||
@ -462,22 +583,68 @@ class RestAuthenticationController extends AdminController
|
||||
$mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null;
|
||||
$email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null;
|
||||
|
||||
if (isset($mobile_number)) {
|
||||
$employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first();
|
||||
} else {
|
||||
$employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first();
|
||||
$empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'mobile_number' => $mobile_number ]);
|
||||
// print_r($empdata); die;
|
||||
|
||||
if(empty($empdata)){
|
||||
$result = ['user_verification' => false , 'message' => "User not found"];
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200);
|
||||
}
|
||||
|
||||
$mpin = $this->request->getJSON()->mpin;
|
||||
|
||||
if (isset($mobile_number)) {
|
||||
// $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first();
|
||||
$employeeData = $this->employeeModel
|
||||
->select('employees.*')
|
||||
->join('employee_polices', 'employees.id = employee_polices.employee_id')
|
||||
->where('employees.mobile', $mobile_number)
|
||||
->where('employees.relationship', 'Self')
|
||||
->where('employee_polices.is_active', 1)
|
||||
->whereIn('employee_polices.status', ['draft', 'enrolled'])
|
||||
->where('employees.is_active', 1)
|
||||
->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
} else {
|
||||
// $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first();
|
||||
$employeeData = $this->employeeModel
|
||||
->select('employees.*')
|
||||
->join('employee_polices', 'employees.id = employee_polices.employee_id')
|
||||
->where('employees.email_corporate', $email_id)
|
||||
->where('employees.relationship', 'Self')
|
||||
->where('employee_polices.is_active', 1)
|
||||
->whereIn('employee_polices.status', ['draft', 'enrolled'])
|
||||
->where('employees.is_active', 1)
|
||||
->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
}
|
||||
|
||||
|
||||
$employeeData = [];
|
||||
if (isset($empdata['pre']) && !empty($empdata['pre'])) {
|
||||
$employeeData = $empdata['pre'];
|
||||
}
|
||||
|
||||
$mpin = $this->request->getJSON()->mpin;
|
||||
$is_mpin_skipped = $this->request->getJSON()->is_mpin_skipped;
|
||||
$is_biometric_enabled = $this->request->getJSON()->is_biometric_enabled;
|
||||
|
||||
$mpin_data_to_updata = [
|
||||
'mpin' => $mpin,
|
||||
'is_mpin_skipped' => $is_mpin_skipped,
|
||||
'is_biometric_enabled' => $is_biometric_enabled
|
||||
];
|
||||
|
||||
$requestData = $this->request->getJSON();
|
||||
if (isset($empdata['post']['client_id']) && !empty($empdata['post']['client_id'])) {
|
||||
$requestData->client_id = $empdata['post']['client_id'];
|
||||
$requestData->employee_id = $empdata['post']['employee_id'];
|
||||
}
|
||||
|
||||
if ($employeeData) {
|
||||
$id= $employeeData["id"];
|
||||
$updateMpin = $this->employeeModel->where('id', $id)->set('mpin', $mpin)->update();
|
||||
$updateMpin = $this->employeeModel->where('id', $id)->set($mpin_data_to_updata)->update();
|
||||
if($updateMpin){
|
||||
$this->callThirdPartyAPI($this->request->getJSON(), 'updateEmpMPIN');
|
||||
$this->callThirdPartyAPI($requestData, 'saveMpin');
|
||||
$result = ['user_verification' => true , 'message' => "Mpin Updated"];
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
|
||||
}else{
|
||||
@ -488,10 +655,11 @@ class RestAuthenticationController extends AdminController
|
||||
|
||||
} else {
|
||||
|
||||
return $this->callThirdPartyAPI($this->request->getJSON(), 'saveMpin');
|
||||
return $this->callThirdPartyAPI($requestData, 'saveMpin');
|
||||
}
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
$this->myLogger->logme("error", ($th->getMessage().' --- '.$th->getLine()));
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
|
||||
}
|
||||
}
|
||||
@ -505,20 +673,60 @@ class RestAuthenticationController extends AdminController
|
||||
$old_mpin = $this->request->getJSON()->old_mpin;
|
||||
$mpin = $this->request->getJSON()->new_mpin;
|
||||
|
||||
if (isset($mobile_number))
|
||||
{
|
||||
$employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('mpin', $old_mpin)->where('relationship', 'self')->first();
|
||||
}else{
|
||||
$employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('mpin', $old_mpin)->where('relationship', 'self')->first();
|
||||
$empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'mobile_number' => $mobile_number, 'old_mpin' => $old_mpin ]);
|
||||
// print_r($empdata); die;
|
||||
|
||||
if(empty($empdata)){
|
||||
$result = ['user_verification' => false , 'message' => "User not found"];
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200);
|
||||
}
|
||||
|
||||
if (isset($mobile_number)) {
|
||||
// $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('mpin', $old_mpin)->where('relationship', 'self')->first();
|
||||
$employeeData = $this->employeeModel
|
||||
->select('employees.*')
|
||||
->join('employee_polices', 'employees.id = employee_polices.employee_id')
|
||||
->where('employees.mobile', $mobile_number)
|
||||
->where('employees.relationship', 'Self')
|
||||
->where('employee_polices.is_active', 1)
|
||||
->whereIn('employee_polices.status', ['draft', 'enrolled'])
|
||||
->where('employees.is_active', 1)
|
||||
->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
->where('employees.mpin', $old_mpin)
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
} else {
|
||||
// $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('mpin', $old_mpin)->where('relationship', 'self')->first();
|
||||
$employeeData = $this->employeeModel
|
||||
->select('employees.*')
|
||||
->join('employee_polices', 'employees.id = employee_polices.employee_id')
|
||||
->where('employees.email_corporate', $email_id)
|
||||
->where('employees.relationship', 'Self')
|
||||
->where('employee_polices.is_active', 1)
|
||||
->whereIn('employee_polices.status', ['draft', 'enrolled'])
|
||||
->where('employees.is_active', 1)
|
||||
->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
->where('employees.mpin', $old_mpin)
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
}
|
||||
|
||||
|
||||
$employeeData = [];
|
||||
if (isset($empdata['pre']) && !empty($empdata['pre'])) {
|
||||
$employeeData = $empdata['pre'];
|
||||
}
|
||||
|
||||
$requestData = $this->request->getJSON();
|
||||
if (isset($empdata['post']['client_id']) && !empty($empdata['post']['client_id'])) {
|
||||
$requestData->client_id = $empdata['post']['client_id'];
|
||||
}
|
||||
|
||||
|
||||
if ($employeeData) {
|
||||
$id= $employeeData["id"];
|
||||
$updateMpin = $this->employeeModel->where('id', $id)->set('mpin', $mpin)->update();
|
||||
if($updateMpin){
|
||||
$this->callThirdPartyAPI($this->request->getJSON(), 'updateEmpMPIN');
|
||||
$this->callThirdPartyAPI($requestData, 'updateMpin');
|
||||
$result = ['mpin_verification' => true , 'message' => "Mpin Updated"];
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
|
||||
}else{
|
||||
@ -528,10 +736,11 @@ class RestAuthenticationController extends AdminController
|
||||
|
||||
|
||||
} else {
|
||||
return $this->callThirdPartyAPI($this->request->getJSON(), 'updateMpin');
|
||||
return $this->callThirdPartyAPI($requestData, 'updateMpin');
|
||||
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
$this->myLogger->logme("error", ($th->getMessage().' --- '.$th->getLine()));
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
|
||||
}
|
||||
}
|
||||
@ -544,12 +753,52 @@ class RestAuthenticationController extends AdminController
|
||||
$email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null;
|
||||
$mpin = $this->request->getJSON()->mpin;
|
||||
|
||||
if (isset($mobile_number)) {
|
||||
$employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first();
|
||||
} else {
|
||||
$employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first();
|
||||
$empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'mobile_number' => $mobile_number]);
|
||||
// print_r($empdata); die;
|
||||
|
||||
if(empty($empdata)){
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => 'Invalid MPIN'], 200);
|
||||
}
|
||||
|
||||
if (isset($mobile_number)) {
|
||||
// $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first();
|
||||
$employeeData = $this->employeeModel
|
||||
->select('employees.*')
|
||||
->join('employee_polices', 'employees.id = employee_polices.employee_id')
|
||||
->where('employees.mobile', $mobile_number)
|
||||
->where('employees.relationship', 'Self')
|
||||
->where('employee_polices.is_active', 1)
|
||||
->whereIn('employee_polices.status', ['draft', 'enrolled'])
|
||||
->where('employees.is_active', 1)
|
||||
->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
} else {
|
||||
// $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first();
|
||||
$employeeData = $this->employeeModel
|
||||
->select('employees.*')
|
||||
->join('employee_polices', 'employees.id = employee_polices.employee_id')
|
||||
->where('employees.email_corporate', $email_id)
|
||||
->where('employees.relationship', 'Self')
|
||||
->where('employee_polices.is_active', 1)
|
||||
->whereIn('employee_polices.status', ['draft', 'enrolled'])
|
||||
->where('employees.is_active', 1)
|
||||
->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
}
|
||||
|
||||
$employeeData = [];
|
||||
if (isset($empdata['pre']) && !empty($empdata['pre'])) {
|
||||
$employeeData = $empdata['pre'];
|
||||
}
|
||||
|
||||
$requestData = $this->request->getJSON();
|
||||
if (isset($empdata['post']['client_id']) && !empty($empdata['post']['client_id'])) {
|
||||
$requestData->client_id = $empdata['post']['client_id'];
|
||||
}
|
||||
|
||||
|
||||
if ($employeeData && $mpin == $employeeData["mpin"]) {
|
||||
$auth = HttpRequestHelper::getRequestInfo();
|
||||
if ($auth) {
|
||||
@ -564,22 +813,25 @@ class RestAuthenticationController extends AdminController
|
||||
$authdata = $this->authHistoryModel->insert($data);
|
||||
}
|
||||
|
||||
unset($employeeData['employee_id']);
|
||||
$result = JWTToken::encode($employeeData);
|
||||
// Call the third-party API function
|
||||
$apiResponse = $this->callThirdPartyAPI($this->request->getJSON(), 'verifyMpin');
|
||||
$apiResponse = $this->callThirdPartyAPI($requestData, 'verifyMpin');
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result, 'post_enrollment' => json_decode($apiResponse, true)], 200);
|
||||
} else {
|
||||
|
||||
// Call the third-party API function
|
||||
|
||||
$apiResponse = $this->callThirdPartyAPI($this->request->getJSON(), 'verifyMpin');
|
||||
$apiResponse = $this->callThirdPartyAPI($requestData, 'verifyMpin');
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => "Invalid OTP", 'post_enrollment' => json_decode($apiResponse, true)], 200);
|
||||
|
||||
//$apiResponse = $this->callThirdPartyAPI($this->request->getJSON(),'/getVerifiedUserData');
|
||||
// return $this->respond(['status' => 'failed','code' => 404,'data' => "Invalid OTP", 'post_enrollment'=> json_decode($apiResponse, true)],200);
|
||||
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->myLogger->logme("error", ($e->getMessage().' --- '.$e->getLine()));
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
return $this->respond(['status' => 'failed', 'code' => 200, 'post_enrollment' => json_decode($apiResponse, true)], 200);
|
||||
}
|
||||
@ -591,26 +843,191 @@ class RestAuthenticationController extends AdminController
|
||||
$mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null;
|
||||
$email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null;
|
||||
|
||||
$empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'mobile_number' => $mobile_number, 'check_mpin' => true]);
|
||||
// print_r($empdata); die;
|
||||
|
||||
if(empty($empdata)){
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => "Mpin - not found", 'Mpin' =>null],200);
|
||||
}
|
||||
|
||||
|
||||
if (isset($mobile_number))
|
||||
{
|
||||
$employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first();
|
||||
// $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first();
|
||||
$employeeData = $this->employeeModel
|
||||
->select('employees.*')
|
||||
->join('employee_polices', 'employees.id = employee_polices.employee_id')
|
||||
->where('employees.mobile', $mobile_number)
|
||||
->where('employees.relationship', 'Self')
|
||||
->where('employee_polices.is_active', 1)
|
||||
->whereIn('employee_polices.status', ['draft', 'enrolled'])
|
||||
->where('employees.is_active', 1)
|
||||
->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
}else{
|
||||
$employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first();
|
||||
// $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first();
|
||||
$employeeData = $this->employeeModel
|
||||
->select('employees.*')
|
||||
->join('employee_polices', 'employees.id = employee_polices.employee_id')
|
||||
->where('employees.email_corporate', $email_id)
|
||||
->where('employees.relationship', 'Self')
|
||||
->where('employee_polices.is_active', 1)
|
||||
->whereIn('employee_polices.status', ['draft', 'enrolled'])
|
||||
->where('employees.is_active', 1)
|
||||
->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
}
|
||||
|
||||
|
||||
$employeeData = [];
|
||||
if (isset($empdata['pre']) && !empty($empdata['pre'])) {
|
||||
$employeeData = $empdata['pre'];
|
||||
}
|
||||
|
||||
$requestData = $this->request->getJSON();
|
||||
if (isset($empdata['post']['client_id']) && !empty($empdata['post']['client_id'])) {
|
||||
$requestData->client_id = $empdata['post']['client_id'];
|
||||
}
|
||||
|
||||
|
||||
if ($employeeData && $employeeData["mpin"] != null) {
|
||||
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => "Mpin - exist" , 'Mpin' =>$employeeData["mpin"]],200);
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => "Mpin - exist" , 'Mpin' =>$employeeData["mpin"], 'is_mpin_skipped' => $employeeData['is_mpin_skipped'], 'is_biometric_enabled' => $employeeData['is_biometric_enabled']],200);
|
||||
} else {
|
||||
// return $this->respond(['status' => 'failed','code' => 404,'data' => "Mpin - not found", 'Mpin' =>null],200);
|
||||
return $this->callThirdPartyAPI($this->request->getJSON(), 'checkMpin');
|
||||
return $this->callThirdPartyAPI($requestData, 'checkMpin');
|
||||
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->myLogger->logme("error", ($e->getMessage().' --- '.$e->getLine()));
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500);
|
||||
}
|
||||
}
|
||||
|
||||
public function forgotMPIN()
|
||||
{
|
||||
try {
|
||||
log_message('info', 'forgotMPIN() called.');
|
||||
|
||||
$json = $this->request->getJSON();
|
||||
$mobile_number = $json->mobile_number ?? null;
|
||||
$email_id = $json->email_id ?? null;
|
||||
|
||||
log_message('info', 'Received input - Mobile: ' . var_export($mobile_number, true) . ', Email: ' . var_export($email_id, true));
|
||||
|
||||
// Step 1: Check input
|
||||
if (!$mobile_number && !$email_id) {
|
||||
log_message('error', 'Mobile number and email ID are both missing.');
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 400,
|
||||
'message' => 'Mobile number or email ID is required.'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'mobile_number' => $mobile_number]);
|
||||
// print_r($empdata); die;
|
||||
|
||||
if(empty($empdata)){
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => "Mpin - not found", 'Mpin' =>null],200);
|
||||
}
|
||||
|
||||
// Step 2: Fetch employee data
|
||||
if ($mobile_number) {
|
||||
log_message('info', 'Looking up employee by mobile number: ' . $mobile_number);
|
||||
$employeeData = $this->employeeModel
|
||||
->select('employees.*')
|
||||
->join('employee_polices', 'employees.id = employee_polices.employee_id')
|
||||
->where('employees.mobile', $mobile_number)
|
||||
->where('employees.relationship', 'Self')
|
||||
->where('employee_polices.is_active', 1)
|
||||
->whereIn('employee_polices.status', ['draft', 'enrolled'])
|
||||
->where('employees.is_active', 1)
|
||||
->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
} else {
|
||||
log_message('info', 'Looking up employee by email: ' . $email_id);
|
||||
$employeeData = $this->employeeModel
|
||||
->select('employees.*')
|
||||
->join('employee_polices', 'employees.id = employee_polices.employee_id')
|
||||
->where('employees.email_corporate', $email_id)
|
||||
->where('employees.relationship', 'Self')
|
||||
->where('employee_polices.is_active', 1)
|
||||
->whereIn('employee_polices.status', ['draft', 'enrolled'])
|
||||
->where('employees.is_active', 1)
|
||||
->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
}
|
||||
|
||||
$employeeData = [];
|
||||
if (isset($empdata['pre']) && !empty($empdata['pre'])) {
|
||||
$employeeData = $empdata['pre'];
|
||||
}
|
||||
|
||||
if (isset($empdata['post']['client_id']) && !empty($empdata['post']['client_id'])) {
|
||||
$json->client_id = $empdata['post']['client_id'];
|
||||
}
|
||||
|
||||
// Step 3: Found employee
|
||||
if (!empty($employeeData)) {
|
||||
log_message('info', 'Employee found: ID = ' . $employeeData['id']);
|
||||
|
||||
$updateData = [
|
||||
'mpin' => null,
|
||||
'is_mpin_skipped' => null,
|
||||
'is_biometric_enabled' => null
|
||||
];
|
||||
|
||||
log_message('info', 'Updating employee MPIN fields to null for ID: ' . $employeeData['id']);
|
||||
|
||||
$updated = $this->employeeModel
|
||||
->where('id', $employeeData['id'])
|
||||
->set($updateData)
|
||||
->update();
|
||||
|
||||
if ($updated) {
|
||||
$this->callThirdPartyAPI($json, 'forgotMPIN');
|
||||
log_message('info', 'MPIN reset successful for employee ID: ' . $employeeData['id']);
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'message' => 'MPIN reset successfully.'
|
||||
], 200);
|
||||
} else {
|
||||
log_message('error', 'Failed to update MPIN fields for employee ID: ' . $employeeData['id']);
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 500,
|
||||
'message' => 'Could not reset MPIN values.',
|
||||
], 500);
|
||||
}
|
||||
} else {
|
||||
// Step 4: Not found in local DB — call external fallback
|
||||
log_message('warning', 'Employee not found locally. Falling back to third-party API.');
|
||||
return $this->callThirdPartyAPI($json, 'forgotMPIN');
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$this->myLogger->logme("error", ($e->getMessage().' --- '.$e->getLine()));
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 500,
|
||||
'message' => 'Server error: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function logHrActivity()
|
||||
{
|
||||
$log_data = $this->request->getJSON();
|
||||
$postDB = \Config\Database::connect('postDB');
|
||||
// print_r($json);die();
|
||||
$postDB->table('user_activity_history')->insert($log_data);
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => "logged",],200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
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