Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev

This commit is contained in:
VENKATESHWARAN 2025-10-09 12:50:18 +05:30
commit 7de7358cd8
15 changed files with 590 additions and 183 deletions

View File

@ -101,6 +101,6 @@ class Autoload extends AutoloadConfig
* @phpstan-var list<string>
*/
public $helpers = ['uuid','session','utility', 'form', 'url', 'oauth', 'fileupload',
'excel_import_export', 'file', 'drive','ExcelSanitizeHelper', 'api_helper','exception'
'excel_import_export', 'file', 'drive','ExcelSanitizeHelper', 'api_helper','exception','sms_helper'
];
}

View File

@ -90,11 +90,13 @@ $routes->group("/dashboard", ["filter" => "authMVC"], function ($routes) {
$routes->group("/client", ["filter" => "authMVC"], function ($routes) {
$routes->get("list", "ClientController::index");
$routes->get("type/(:any)", "ClientController::type/$1");
$routes->get("create", "ClientController::clientOnboarding");
$routes->get('deposit/(:num)', 'ClientController::deposit/$1');
$routes->get('remove/(:num)', 'ClientController::removeClient/$1');
$routes->get("list/(:any)", "ClientController::editClientOnboarding/$1");
$routes->post('wipe', 'ClientController::wipeDemoClient');
$routes->get("typeList/(:any)", "ClientController::typeList/$1");
// application/config/routes.php

View File

@ -471,7 +471,7 @@ class ClientController extends AdminController
$this->myLogger->logme('error', 'Client list function called');
$headerData['tab_name'] = 'Client List';
$headerData['page_name'] = 'Clients'; // Both Browser Tab name And Page name are same.
$data['clientList'] = $this->clientModel->getCreatedByUserName();
$data['clientList'] = $this->clientModel->getCreatedByUserName(1); // passing client_type
$data['client_rm'] = $this->clientRMModel->getAllClientRM();
$data['lead_data'] = $this->leadsModel->getLeadForInsertClientList();
@ -484,6 +484,29 @@ class ClientController extends AdminController
// $this->loadLayout('client_onboarding', $data);
}
public function typeList($id = null)
{
try {
$data = $this->clientModel->getCreatedByUserName($id); // passing client_type
if (empty($data)) {
return $this->response
->setJSON(['status' => 'error', 'message' => 'No Records found'])
->setStatusCode(404);
}
return $this->response
->setJSON(['status' => 'success', 'data' => $data])
->setStatusCode(200);
} catch (\Throwable $e) {
return $this->response
->setJSON(['status' => 'error', 'message' => $e->getMessage()])
->setStatusCode(500);
}
}
public function updateEmpAndPolicyStatus()
{
@ -801,6 +824,8 @@ class ClientController extends AdminController
$editData['api_data'] = $this->clientApi->where("client_id", $id)->where("is_active", 1)->first();
// dd($editData);
$edit['pre_branch_id'] = $this->clientBranchModel->select('pre_branch_id')->where('client_id',$id)->get()->getResultArray()[0]['pre_branch_id']??"";
$editData['auto_fetch_client_list'] = $this->getClientListFromPre();
@ -6857,7 +6882,15 @@ class ClientController extends AdminController
return $combinedHrAccessData;
}
$pre_client_data = $db2->table('clients')->where('is_active', 1)->where('short_name', $post_client_data['short_name'])->get()->getRowArray();
$post_branch = $this->clientBranchModel->select('pre_branch_id')->where('client_id',$client_id)->get()->getResultArray()[0]??[];
$pre_client_data = $db2->table('client_branch cb')
->join('clients c', "c.id = cb.client_id")
->where('c.is_active',1)
->where('cb.is_active', 1)
->where('cb.id', $post_branch['pre_branch_id']??'')
->get()->getRowArray();
if (empty($pre_client_data)) {
@ -7093,11 +7126,16 @@ class ClientController extends AdminController
$post = array_values(array_filter($allowed_modules, fn($v) => $v !== 1));
$value['allowed_modules'] = json_encode(['pre' => $pre, 'post' => $post]);
$post_client_id = $value['post_client_id'];
$post_branch_id = $value['post_branch_id'];
$post_hr_id = $value['post_hr_id'];
$value['pre_client_id'] = $this->getPreClientId($post_branch_id);
$value['pre_branch_id'] = $this->getPreBranchId($post_branch_id);
$value["pre_hr_id"] = $this->getPreHrId($post_branch_id);
// INSERT or UPDATE
if (empty($value['pk']) || (int)$value['pk'] === 0) {
print_rr("inside insert block");
print_rr($value);die;
unset($value['pk']); // Prevent insert error
$insertedId = $this->HRAccessControlModel->insert($value);
@ -7107,8 +7145,6 @@ class ClientController extends AdminController
$success[] = "Inserted row at index {$index} with ID {$insertedId}.";
} else {
$update = $this->HRAccessControlModel->update($value['pk'], $value);
print_rr("inside update block");
print_rr($value);die;
if ($update === false) {
throw new \Exception('Update failed for ID ' . $value['pk'] . ': ' . json_encode($this->HRAccessControlModel->errors()));
@ -7163,6 +7199,26 @@ class ClientController extends AdminController
}
}
private function getPreClientId($post_branch_id){
$db2 = \Config\Database::connect('preDB');
$pre_client_id = $db2->table('client_branch')->where('post_branch_id',$post_branch_id)->where('is_Active',1)->get()->getResultArray()[0]['client_id']??[];
return $pre_client_id;
}
private function getPreBranchId($post_branch_id){
$db2 = \Config\Database::connect('preDB');
$pre_branch_id = $db2->table('client_branch')->where('post_branch_id',$post_branch_id)->where('is_Active',1)->get()->getResultArray()[0]['id']??[];
return $pre_branch_id;
}
private function getPreHrId($post_branch_id){
$db2 = \Config\Database::connect('preDB');
$pre_hr_id = $db2->table('client_branch cb')
->select('lc.id')
->join('level_contacts lc','lc.ref_id = cb.id')
->where('post_branch_id',$post_branch_id)->where('is_Active',1)->get()->getResultArray()[0]['id']??[];
return $pre_hr_id;
}
// ------------------- DEMO CLIENT FUNCTION --------------------------------------------------------------------------------
public function wipeDemoClient()

View File

@ -67,24 +67,57 @@ class ICICILombardController extends AdminController
//Prepare body data
$db = \Config\Database::connect();
$data = $db->table('employee_polices ep')
->select('cp.policy_no as policyNumber, cp.cd_ac_no as CDBGAccountNumber,
e.id,e.emp_code as MemberEmpId, e.doj as DOJ, e.name as InsuredName, e.dob as DOB, e.relationship as Relationship,
e.gender as Gender, ep.date_coverage as DOC,ep.basic_cover_si as SumInsured, e.email_corporate as EmailId
')
->join('employees e', 'e.id = ep.employee_id')
->join('client_policy cp', 'ep.client_policy_id = cp.id')
->where('ep.client_policy_id', $policy_id)
->where('ep.status', 'active')
->where('ep.is_active', 1)
// ->where('ep.uhid', null)
->get()
->getResultArray();
// $db = \Config\Database::connect();
// $data = $db->table('employee_polices ep')
// ->select('cp.policy_no as policyNumber, cp.cd_ac_no as CDBGAccountNumber,
// e.id,e.emp_code as MemberEmpId, e.doj as DOJ, e.name as InsuredName, e.dob as DOB, e.relationship as Relationship,
// e.gender as Gender, ep.date_coverage as DOC,ep.basic_cover_si as SumInsured, e.email_corporate as EmailId
// ')
// ->join('employees e', 'e.id = ep.employee_id')
// ->join('client_policy cp', 'ep.client_policy_id = cp.id')
// ->where('ep.client_policy_id', $policy_id)
// ->where('ep.status', 'active')
// ->where('ep.is_active', 1)
// // ->where('ep.uhid', null)
// ->get()
// ->getResultArray();
$body = $this->formatPolicyData($data);
// $body = $this->formatPolicyData($data);
// dd($body);
$body = [
"PolicyNumber" => "4016/A/O/53130557/00/000",
"CDBGAccountNumber" => "CD-MUM-0026",
"CorrelationId" => "550e8400-e29b-41d4-a716-446655440010",
"MemberDetails" => [
[
"MemberEmpId" => "EMPID3625557",
"DOJ" => "21-MAR-2019",
"InsuredName" => "Kumar",
"DOB" => "7-JUL-1983",
"Relationship" => "SELF",
"Gender" => "MALE",
"DOC" => "05-SEP-2025",
"SumInsured" => "400000",
"EmailId" => "KUMAR@GMAIL.COM",
"FlagStatus" => "A"
],
[
"MemberEmpId" => "EMPID3625557",
"DOJ" => "21-MAR-2019",
"InsuredName" => "Saranya",
"DOB" => "8-AUG-1970",
"Relationship" => "MOTHER",
"Gender" => "FEMALE",
"DOC" => "05-SEP-2025",
"SumInsured" => "400000",
"EmailId" => "Saranya@GMAIL.COM",
"FlagStatus" => "A"
],
]
];
$response = call_third_party_api($url, 'POST', $headers, $body, true); // true = raw body mode
// print_rr(json_encode($response));die();
return $this->response->setJSON($response);
@ -115,9 +148,9 @@ class ICICILombardController extends AdminController
// dd($headers);
$body = [
"PolicyNumber" => "4016/A/O/53077718/00/000",
"BatchId" => "3646145",
"CorrelationId" => "550e8400-e29b-41d4-a716-446655440001"
"PolicyNumber" => "4016/A/O/53130557/00/000",
"BatchId" => "3658147",
"CorrelationId" => "550e8400-e29b-41d4-a716-446655440010"
];
$response = call_third_party_api($url, 'POST', $headers, $body, true);

View File

@ -79,10 +79,6 @@ class RestAuthenticationController extends AdminController
public function verifyEmployeeWithMobileNumber()
{
log_message('error', ' ');
@ -93,6 +89,7 @@ class RestAuthenticationController extends AdminController
try {
$mobile_number = $this->request->getJSON()->mobile_number;
$otp = $this->request->getJSON()->otp;
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: Received mobile_number = " . $mobile_number);
@ -112,12 +109,49 @@ class RestAuthenticationController extends AdminController
if (isset($employeeData['employee_id']))
{
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: Employee found: employee_id = " . $employeeData['employee_id']);
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: Employee verified with ID = " . $employeeData['employee_id']);
log_message('error', ' ');
log_message('error', ' ************************************* POST END **************************************** ');
log_message('error', ' ');
$result = ['user_verification' => true ,'message' => "Verified Successfully"];
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
log_message('error', '************************ POST END ********************************');
$sql = "
UPDATE employees
INNER JOIN employee_polices ON employee_polices.employee_id = employees.id
SET employees.otp = ?
WHERE employees.id = ?
AND employees.relationship = 'self'
AND employees.is_active = 1
AND employee_polices.is_active = 1
AND employee_polices.status IN ('active')
";
$db = db_connect();
$update = $db->query($sql, [$otp, $employeeData['employee_id']]);
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: OTP update query executed. SQL = " . $db->getLastQuery());
if($update)
{
//send sms
$SMSResult = sendOtpSms($mobile_number, $otp);
if ($SMSResult['status'] == 'success')
{
$result = ['user_verification' => true ,'message' => "Verified Successfully" ];
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
}else{
$result = ['user_verification' => false, 'message' => "SMS sending failed , try again"];
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200);
}
}else{
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: OTP update query Failed. SQL = " . $db->getLastQuery());
$result = ['user_verification' => false, 'message' => "Try again. , try again"];
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200);
}
} else {
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: No matching employee found");
log_message('error', ' ');
@ -148,6 +182,7 @@ class RestAuthenticationController extends AdminController
try {
$email = $this->request->getJSON()->email;
$otp = $this->request->getJSON()->otp;
$client_id = $this->request->getJSON()->client_id ?? null;
@ -181,11 +216,6 @@ class RestAuthenticationController extends AdminController
if (isset($employeeData['employee_id'])) {
$otp = random_int(100000, 999999);
// $update = $this->employeeModel->where('email_corporate', $email)->where('relationship', 'Self')
// ->where('is_active', 1)->set(array('otp' => $otp))
// ->update();
$builder = $this->employeeModel
->where('email_corporate', $email)
@ -265,24 +295,23 @@ class RestAuthenticationController extends AdminController
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateEmpOTP: Received payload = " . json_encode($this->request->getJSON() ?? []));
$email = $this->request->getJSON()->email;
$email = $this->request->getJSON()->email ?? null;
$mobile_number = $this->request->getJSON()->mobile_number ?? null;
$otp = $this->request->getJSON()->otp;
$client_id = $this->request->getJSON()->client_id ?? null;
$employee_id = $this->request->getJSON()->employee_id ?? null;
$builder = $this->employeeModel
->where('email_corporate', $email)
->where('relationship', 'Self')
->where('is_active', 1);
// $builder = $this->employeeModel
// ->join('employee_polices EP', 'EP.employee_id = employees.id', 'inner')
// ->where('employees.email_corporate', $email)
// ->where('employees.relationship', 'Self')
// ->where('employees.is_active', 1)
// ->whereIn('employees.emp_status', ['active', 'expired'])
// ->where('EP.is_active', 1)
// ->whereIn('EP.status', ['active', 'expired']);
if (!empty($email)) {
$builder->where('email_corporate', $email);
}
if (!empty($mobile_number)) {
$builder->where('mobile', $mobile_number);
}
if (!empty($client_id)) {
@ -306,58 +335,7 @@ class RestAuthenticationController extends AdminController
}
// public function updateEmpMPIN()
// {
// $requestData = $this->request->getJSON();
// print_r($requestData); die;
// $mobile_number = $requestData->mobile_number ?? null;
// $email_id = $requestData->email_id ?? null;
// $new_mpin = $requestData->new_mpin ?? $requestData->mpin ?? null;
// $old_mpin = $requestData->old_mpin ?? null;
// $is_mpin_skipped = $requestData->is_mpin_skipped ?? null;
// $is_biometric_enabled = $requestData->is_biometric_enabled ?? null;
// if (!$new_mpin) {
// return $this->response->setJSON(['status' => false, 'message' => 'MPIN is required.']);
// }
// $query = $this->employeeModel->where('relationship', 'self');
// if ($mobile_number) {
// $query->where('mobile', $mobile_number);
// } elseif ($email_id) {
// $query->where('email_corporate', $email_id);
// } else {
// return $this->response->setJSON(['status' => false, 'message' => 'Mobile number or Email ID is required.']);
// }
// if (!empty($old_mpin)) {
// $query->where('mpin', $old_mpin);
// }
// // Fetch employee data
// $employeeData = $query->first();
// if (!$employeeData) {
// return $this->response->setJSON(['status' => false, 'message' => 'Employee not found or invalid MPIN.']);
// }
// if(!empty($is_mpin_skipped) && !empty($is_biometric_enabled)){
// $mpin_data_to_updata = [
// 'mpin' => $new_mpin,
// 'is_mpin_skipped' => $is_mpin_skipped,
// 'is_biometric_enabled' => $is_biometric_enabled
// ];
// }else{
// $mpin_data_to_updata = ['mpin' => $new_mpin];
// }
// // Update MPIN
// $updated = $this->employeeModel->update($employeeData['id'], $mpin_data_to_updata);
// return true;
// }
public function updateEmpMPIN()
{
try {
@ -415,17 +393,11 @@ class RestAuthenticationController extends AdminController
try {
$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;
$otp = isset($this->request->getJSON()->otp) ? $this->request->getJSON()->otp : null;
$email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null;
$otp = isset($this->request->getJSON()->otp) ? $this->request->getJSON()->otp : null;
$client_id = $this->request->getJSON()->client_id ?? null;
if (isset($this->request->getJSON()->login_by_hr))
{
$employeeData = $this->employeeModel->where('id', $this->request->getJSON()->employee_id)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first();
}else{
if (isset($mobile_number))
{
// $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first();
@ -437,7 +409,8 @@ class RestAuthenticationController extends AdminController
->where('employee_polices.is_active', 1)
->whereIn('employee_polices.status', ['active', 'expired'])
->where('employees.is_active', 1)
->whereIn('employees.emp_status', ['active', 'expired']);
->whereIn('employees.emp_status', ['active', 'expired'])
->where('otp', $otp);
if (!empty($client_id)) {
$builder->where('employees.client_id', $client_id);
@ -464,14 +437,15 @@ class RestAuthenticationController extends AdminController
$employeeData = $builder->orderBy('employees.id', 'desc')->first();
}
}
$lastQuery = $this->employeeModel->db->getLastQuery();
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - getVerifiedUserData: Last Executed Query: " . $lastQuery);
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - getVerifiedUserData: employeeData: " . json_encode($employeeData ?? []));
if ($employeeData && $otp_verification == true || $employeeData && isset($this->request->getJSON()->login_by_hr) || $employeeData && isset($this->request->getJSON()->otp) ) {
if ($employeeData && isset($this->request->getJSON()->otp) )
{
$auth = HttpRequestHelper::getRequestInfo();
if ($auth) {
$data = [
@ -524,17 +498,43 @@ class RestAuthenticationController extends AdminController
public function verifyHrWithMobileNumber()
{
try {
$mobile_number = $this->request->getJSON()->mobile_number;
$data = $this->request->getJSON();
$mobile_number = $data->mobile_number;
$otp = $data->otp;
$HrData = $this->hrModel->where('mobile', $mobile_number)
->where('contact_type', 'client')
->where('is_active', 1)
->first();
if ($HrData) {
$result = ['user_verification' => true ,'message' => "Verified Successfully"];
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
$sql = "UPDATE level_contacts SET otp = ? WHERE mobile = ? AND contact_type = 'client' AND is_active = 1";
$db = db_connect();
$update = $db->query($sql, [$otp, $mobile_number]);
if($update)
{
//send sms
$SMSResult = sendOtpSms($mobile_number, $otp);
if ($SMSResult['status'] == 'success')
{
$result = ['user_verification' => true, 'message' => "Verified Successfully"];
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} else {
$result = ['user_verification' => false, 'message' => "SMS sending failed , try again"];
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200);
}
}else {
$result = ['user_verification' => false, 'message' => "SMS sending failed , try again"];
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200);
}
} else {
$result = ['user_verification' => false , 'message' => "User not found"];
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200);
@ -552,6 +552,7 @@ class RestAuthenticationController extends AdminController
$data = $this->request->getJSON();
$email = $data->email;
$otp = $data->otp;
$HrData = $this->hrModel->where('email', $email)
->where('contact_type', 'client')
@ -559,8 +560,6 @@ class RestAuthenticationController extends AdminController
->first();
if ($HrData) {
$otp = random_int(100000, 999999);
$sql = "
UPDATE level_contacts
@ -575,7 +574,7 @@ class RestAuthenticationController extends AdminController
if($update)
{
$data->otp = $otp;
$common = [
'login_type' => 'HR login',
@ -608,39 +607,53 @@ class RestAuthenticationController extends AdminController
return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
}
}
public function updateHROTP()
{
$email = $this->request->getJSON()->email;
$otp = $this->request->getJSON()->otp;
$this->hrModel->where('email', $email) ->where('contact_type', 'client')
->where('is_active', 1)->set(array('otp' => $otp))
->update();
$email = $this->request->getJSON()->email ?? null;
$mobile_number = $this->request->getJSON()->mobile_number ?? null;
$otp = $this->request->getJSON()->otp ?? null;
return true;
$builder = $this->hrModel
->where('contact_type', 'client')
->where('is_active', 1);
if (!empty($email)) {
$builder->where('email', $email);
} elseif (!empty($mobile_number)) {
$builder->where('mobile', $mobile_number);
}
$builder->set(['otp' => $otp])->update();
if ($this->hrModel->db->affectedRows() > 0) {
return true;
}
}
public function getVerifiedHrData()
{
// try {
// mobile number
$otp_verification = isset($this->request->getJSON()->otp_verification) ? $this->request->getJSON()->otp_verification : null;
$mobile_number = isset($this->request->getJSON()->mobile_no) ? $this->request->getJSON()->mobile_no : null;
// email id
try {
$otp = isset($this->request->getJSON()->otp) ? $this->request->getJSON()->otp : null;
$email = isset($this->request->getJSON()->email) ? $this->request->getJSON()->email : null;
$mobile_number = isset($this->request->getJSON()->mobile_no) ? $this->request->getJSON()->mobile_no : null;
if (isset($mobile_number))
{
$hrData = $this->hrModel->where('mobile', $mobile_number)->where('contact_type', 'client')->first();
$hrData = $this->hrModel->where('mobile', $mobile_number)->where('contact_type', 'client')->where('otp', $otp)->first();
}else{
$hrData = $this->hrModel->where('email', $email)->where('contact_type', 'client')->where('otp', $otp)->first();
}
if ($hrData && $otp_verification == true || $hrData && isset($this->request->getJSON()->otp) )
if ($hrData)
{
$auth = HttpRequestHelper::getRequestInfo();
@ -660,23 +673,25 @@ class RestAuthenticationController extends AdminController
if(isset($this->request->getJSON()->mobile_no)){
$getAllhrData = $this->hrModel->select('level_contacts.id ,level_contacts.mobile , level_contacts.email , clients.id as client_id, clients.client_name, clients.short_name , client_branch.id as client_branch_id,client_branch.branch_name, client_branch.pre_branch_id')
$getAllhrData = $this->hrModel->select('level_contacts.id ,level_contacts.mobile , level_contacts.email , clients.id as client_id, clients.client_name, clients.short_name , client_branch.id as client_branch_id,client_branch.branch_name , client_branch.pre_branch_id')
->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left')
->join('clients', 'client_branch.client_id = clients.id', 'left')
->where('level_contacts.mobile', $mobile_number )
->where('level_contacts.contact_type', 'client')
->findAll();
//set otp value null
$this->hrModel->where('mobile', $mobile_number)->where('otp', $otp)->where('contact_type', 'client')->set(['otp'=>null])->update();
}else if(isset($this->request->getJSON()->otp)){
}else if(isset($this->request->getJSON()->email)){
$getAllhrData = $this->hrModel->select('level_contacts.id ,level_contacts.mobile , level_contacts.email , clients.id as client_id, clients.client_name, clients.short_name , client_branch.id as client_branch_id,client_branch.branch_name , client_branch.pre_branch_id')
->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left')
->join('clients', 'client_branch.client_id = clients.id', 'left')
->where('level_contacts.email', $email )
->where('level_contacts.contact_type', 'client')
->findAll();
//set otp value null
$this->hrModel->where('email', $email)->where('otp', $otp)->where('contact_type', 'client')->set(['otp'=>null])->update();
$getAllhrData = $this->hrModel->select('level_contacts.id ,level_contacts.mobile , level_contacts.email , clients.id as client_id, clients.client_name, clients.short_name , client_branch.id as client_branch_id,client_branch.branch_name, client_branch.pre_branch_id')
->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left')
->join('clients', 'client_branch.client_id = clients.id', 'left')
->where('level_contacts.email', $email )
->where('level_contacts.contact_type', 'client')
->findAll();
}
if(count($getAllhrData))
@ -705,29 +720,26 @@ class RestAuthenticationController extends AdminController
}
}
return $this->respond(['status' => 'success','code' => 200,'data' => $getAllhrData ],200);
}else {
return $this->respond(['status' => 'failed','code' => 404,'data' => "" , 'message' => 'User not found' ],200);
}
return $this->respond(['status' => 'success','code' => 200,'data' => $getAllhrData ],200);
// $HRAccessData = $this->getHRAccessData( $hrData['0']['id'] , 'post_enrollment');
// if(isset($HRAccessData['allowed_modules'])){ $hrData['0']['allowed_modules'] = json_decode($HRAccessData['allowed_modules'],true)['post']; }else{ $hrData['0']['allowed_modules'] = []; }
// $hrData['0']['token_type'] = 'post';
// $result = JWTToken::encode($hrData['0']);
// return $this->respond(['status' => 'success','code' => 200,'data' => $result ],200);
} else {
return $this->respond(['status' => 'failed','code' => 404,'data' => "" ],200);
return $this->respond(['status' => 'failed','code' => 404,'data' => "" , 'message' => 'User not found' ],200);
}
// } catch (\Exception $e) {
// return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500);
// }
} catch (\Exception $e) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500);
}
}
@ -1394,6 +1406,10 @@ class RestAuthenticationController extends AdminController
->where('employees.mobile', $mobile_number)
->where('EP.is_active', 1)
->whereIn('EP.status', ['active', 'expired']);
if (!empty($otp)) {
$builder->where('employees.otp', $otp);
}
if (!empty($old_mpin)) {
$builder->where('employees.mpin', $old_mpin);

View File

@ -627,17 +627,24 @@ class UserController extends AdminController
if (!$staff) {
return $this->response->setJSON(['status' => 'error','message' => 'Staff not found'])->setStatusCode(404);
}
$role = $staff['role_id'];
$text = $role == 1 ? "Manager" : "Staff";
if ($staff['is_active'] == 1) {
if($role == 1){ // manager
$result = $this->partnerStaffModel->updateByKey($id);
$message = $result;
}else{ // staff
$result = $this->partnerStaffModel->update($id, ['is_active' => 0]);
$message = "Staff deleted successfully";
$message = $text." deleted successfully";
}
} else {
return $this->response->setJSON(['status' => 'error','message' => 'Staff already deleted'])->setStatusCode(400);
return $this->response->setJSON(['status' => 'error','message' => $text.' already deleted'])->setStatusCode(400);
}
return $this->response->setJSON([
'status' => $result ? 'success' : 'error',
'message' => $result ? $message : "Unable to delete staff. Please try again.",
'message' => $result ? $message : "Unable to delete ".$text.". Please try again.",
'id' => $id
])->setStatusCode($result ? 200 : 400);
}

View File

@ -0,0 +1,44 @@
<?php
use CodeIgniter\Database\BaseConnection;
if (!function_exists('sendOtpSms')) {
function sendOtpSms(string $mobile, string $otp)
{
$apiKey = env('SMS_API_KEY');
$senderId = env('SMS_SENDER_ID');
$templateId = env('SMS_TEMPLATE_ID');
$serviceName = env('SMS_SERVICE_NAME');
$appName = env('SMS_APP_NAME');
// Replace variables {#var#}
$message = "Hi, Your One Time Code for logging into Nhance {$appName} App is {$otp}. Valid for 3 minutes. Please do not share this with anyone. -NHANCE";
log_message('info' , 'SMS - Message '.$message);
// Build the API URL
$url = "https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?" . http_build_query([
'APIKEY' => $apiKey,
'MobileNo' => $mobile,
'SenderID' => $senderId,
'Message' => $message,
'ServiceName' => $serviceName,
'DLTTemplateID' => $templateId,
]);
// Send request
$response = @file_get_contents($url);
log_message('info' , 'SMS - Response '.$response);
// If response failed
if ($response === FALSE) {
return ['status' => 'failed', 'message' => 'Failed to send SMS.'];
}
return ['status' => 'success', 'message' => 'OTP sent successfully', 'api_response' => $response];
}
}

View File

@ -108,7 +108,7 @@ class ClientModel extends Model
}
public function getCreatedByUserName(){
public function getCreatedByUserName($client_type = null){
$role_id = get_role_id();
$user_id = get_session_userid();
@ -118,6 +118,10 @@ class ClientModel extends Model
->join('client_rm', 'client_rm.client_id = clients.id','left')
->where('clients.is_active', 1);
if (!empty($client_type)) {
$query->where('clients.client_type', $client_type);
}
if (in_array($role_id, [2, 3])) {
// If the user is a Account Manager or Manager, filter by user_id

View File

@ -47,4 +47,55 @@ class PartnerStaffModel extends Model
// ];
// protected $skipValidation = false;
public function updateByKey($key)
{
$db = \Config\Database::connect();
$message = "";
// Start transaction
$db->transStart();
try {
// 1. Update manager
$db->table('partner_staff')
->where('id', $key)
->set('is_active', 0)
->update();
$managerRows = $db->affectedRows();
$message = "{$managerRows} manager(s), ";
// 2. Update agents under manager
$db->table('partner_agent')
->where('manager_id', $key)
->set('is_active', 0)
->update();
$agentRows = $db->affectedRows();
$message .= "{$agentRows} agent(s), ";
// 3. Update staff under manager
$db->table('partner_staff')
->where('manager_id', $key)
->set('is_active', 0)
->update();
$staffRows = $db->affectedRows();
$message .= "{$staffRows} staff(s)";
// Complete transaction
$db->transComplete();
// Check transaction status
if ($db->transStatus() === false) {
return "Transaction failed. No updates were applied.";
}
return $message . " are deleted successfully";
} catch (\Exception $e) {
// Rollback in case of exception
$db->transRollback();
return "Error: " . $e->getMessage();
}
}
}

View File

@ -37,10 +37,10 @@ table.dataTable tbody td {
</style> -->
<style>
body {
/* body {
font-family: Arial, sans-serif;
padding: 20px;
}
} */
#mobile::placeholder,
#mobile_no::placeholder {
@ -353,8 +353,7 @@ table.dataTable tbody td {
<h4 style="position: relative;">Users</h4>
</div>
</div> -->
<table data-custom-table-css="table" class="table table-sm table-hover m-0 table-centered dt-responsive nowrap w-100" cellspacing="1" id="user-table">
<table data-custom-table-css="table" class="table table-sm m-0 table-centered dt-responsive nowrap w-100" cellspacing="a" id="user-table">
<thead class="bg-light">
<tr>
<th class="font-weight-medium">Name</th>
@ -874,13 +873,19 @@ table.dataTable tbody td {
{
extend: 'csv',
text: '<i class="mdi mdi-file-delimited"></i><span class="btn-custom"> CSV </span>',
className: 'app-btn-primary'
className: 'app-btn-primary',
exportOptions: {
columns: ':not(:last-child)'
}
},
{
extend: 'excel',
text: '<i class="mdi mdi-file-excel"></i><span class="btn-custom"> EXCEL </span>',
exportOptions: { orthogonal: 'sort' },
className: 'app-btn-primary'
className: 'app-btn-primary',
exportOptions: {
columns: ':not(:last-child)'
}
}
]
}
@ -1027,9 +1032,17 @@ table.dataTable tbody td {
});
$('body').on('click', '.btnPartnerDelete', function () {
var partner_role = $(this).attr('data-role');
var alertText = "You need to remove this user";
if (partner_role == 2) {
alertText = "You need to remove this Staff";
} else if (partner_role == 1) {
alertText = "You need to remove this Manager and related agent and staff are also delete";
}
Swal.fire({
title: "Are you sure?",
text: "You need to remove this user",
text: alertText,
icon: "info",
showCancelButton: true,
confirmButtonColor: "#3085d6",
@ -1165,6 +1178,9 @@ table.dataTable tbody td {
complete: function() {
btn.disabled = false;
btn.innerText = "Submit";
$('#nhance-partner-modal').removeClass('show').hide();
$('.modal-backdrop').remove();
loadPartner();
}
});
}
@ -1263,7 +1279,7 @@ table.dataTable tbody td {
row.name,
row.email,
row.mobile,
'Staff',
row.role_id == 1 ? "Manager" : "Staff",
`<span class="badge ${statusClass}">${statusText}</span>`,
`<div class="btn-group dropdown">
<a href="javascript:void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown">
@ -1273,8 +1289,8 @@ table.dataTable tbody td {
<a data-toggle="modal" data-target="#nhance-partner-modal" class="dropdown-item btnPartnerEdit" data-obj='${JSON.stringify(row)}'>
<i data-obj='${JSON.stringify(row)}' class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle btnPartnerEdit"></i>Edit
</a>
<a class="dropdown-item btnPartnerDelete" data-id="${row.id}">
<i data-id="${row.id}" class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle btnPartnerDelete"></i>Delete
<a class="dropdown-item btnPartnerDelete" data-id="${row.id}" data-role="${row.role_id}">
<i data-id="${row.id}" data-role="${row.role_id}" class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle btnPartnerDelete"></i>Delete
</a>
<a class="dropdown-item btnPartnerPerformance" data-id="${row.id}">
<i data-id="${row.id}" class="mdi mdi-speedometer mr-2 text-muted font-18 vertical-middle btnPartnerPerformance"></i>View Performance
@ -1699,10 +1715,11 @@ table.dataTable tbody td {
});
$(document).on('click', '#btnNhancePartnerAdd', function(){
$('#partner_name').val('');
$('#email').val('');
$('#email_addr').val('');
$('#partner_id').val('');
$('#mobile_no').val('');
$('#locn').val('');
$('#locn').val('');
$('.modal-title').html('Add Nhance Partner');
$('#PartnerForm').attr('action', '<?php echo base_url('/user/partner');?>');
let myModal = new bootstrap.Modal(document.getElementById('nhance-partner-modal'));
myModal.show(); // open modal

View File

@ -110,13 +110,14 @@ input:checked + .slider:before {
<div class="form-group col-md-4">
<label for="client_name">Client Name<span
class="text-danger">*</span></label>
<input type="text" class="form-control" id="client_name"
<input type="text" class="form-control" id="client_name" data-old-name="<?= isset($client['client_name']) ? $client['client_name'] : '' ?>"
placeholder="Enter Client Name" value="<?= isset($client['client_name']) ? $client['client_name'] : '' ?>" name="client_name" required>
</div>
<div class="form-group col-md-4">
<label for="short_name">Client Short Name<span
class="text-danger">*</span></label>
<input type="text" class="form-control" id="short_name"
data-old-short="<?= isset($client['short_name']) ? $client['short_name'] : '' ?>"
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>

View File

@ -546,6 +546,7 @@ $('body').on('click', '.btnBranchEdit', function() {
$('#district').val(res.data.district);
$('#branch_city').val(res.data.city);
$('#branch_PrimaryKey').val(res.data.id);
$('#pre_branch_id').val(res.data.pre_branch_id)
if(res.data.sez == 1){
$('#sez').prop('checked', true);
@ -861,6 +862,83 @@ function checkMobileNumber(input) {
}
// function generateShortName() {
// let clientName = $("#client_name").val().trim();
// if (clientName.length > 0) {
// let shortName = clientName.substring(0, 10).replace(/\s+/g, '').toUpperCase(); // Take first 10 chars , space removed, converted caps
// $("#short_name").val(shortName);
// makeUniqueShortName(shortName);
// }else{
// $("#short_name").val('');
// }
// }
let shortNameTimer;
$("#client_name").on("input change keyup", function() {
clearTimeout(shortNameTimer); // cancel previous call
shortNameTimer = setTimeout(() => {
generateShortName(); // only runs after 200ms pause
}, 200); // adjust debounce delay as needed
});
function generateShortName() {
let clientInput = $("#client_name");
let shortInput = $("#short_name");
let oldClientName = clientInput.data("old-name"); // from DB
let oldShortName = shortInput.data("old-short"); // from DB
let newClientName = clientInput.val().trim();
console.log(`LN 882 : NEW - ${newClientName} | OLD - ${oldClientName} | OLD SN - ${oldShortName}`);
if (newClientName.toUpperCase() === (oldClientName || '').toUpperCase()) {
shortInput.val(oldShortName);
return;
}
if (newClientName.length == 0) {
shortInput.val('');
return;
}
if (newClientName.length > 0) {
let shortName = newClientName.substring(0, 10).replace(/\s+/g, '').toUpperCase();
shortInput.val(shortName);
makeUniqueShortName(shortName);
}
}
function makeUniqueShortName(baseName) {
let input = $("#short_name")[0]; // input element
checkDuplicateTableFieldValue("clients", "short_name", baseName, function(isDuplicate) {
if (isDuplicate) {
// Append sequence until unique
let counter = 1;
function tryNext() {
let padded = String(counter).padStart(3, '0'); // 001, 002, 003
let newName = baseName + padded;
checkDuplicateTableFieldValue("clients", "short_name", newName, function(exists) {
if (exists) {
counter++;
tryNext(); // keep checking
} else {
$("#short_name").val(newName);
validateInput(input, "clients", "short_name", "clientBtnSubmit");
}
});
}
tryNext();
} else {
$("#short_name").val(baseName);
validateInput(input, "clients", "short_name", "clientBtnSubmit");
}
});
}
function validateInput(input, table, field, submitButId){
let value = $(input).val();

View File

@ -294,10 +294,10 @@ table.dataTable thead th {
$(document).ready(function(){
$('#lead_id').select2();
})
var table;
$(document).ready(function()
{
$('#tickets-table').DataTable({
table = $('#tickets-table').DataTable({
dom: "<'row'<'col-12 d-flex justify-content-between align-items-center'<'datatable-search dataTables_filter'f><'datatable-buttons dt-buttons'B>>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>",
@ -326,6 +326,11 @@ $(document).ready(function()
extend: 'csv',
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
title: 'Client-List',
// title: function() {
// return $('#toggleButtons').is(':checked')
// ? 'GC-Client-List'
// : 'RC-Client-List';
// },
className: 'app-btn-primary ',
exportOptions: {
columns: ':not(:last-child)'
@ -340,13 +345,104 @@ $(document).ready(function()
_INPUT_
<i class="mdi mdi-magnify datatable-search-icon"></i>
</div>`,
searchPlaceholder: "Search"
searchPlaceholder: "Search",
emptyTable: '<div class="text-center text-muted">No Data found</div>'
},
paging: true ,
// pagingType: 'full_numbers'
});
// $(".datatable-buttons").prepend(`
// <label class="switch">
// <input type="checkbox" id="toggleButtons">
// <span">Group</span>
// </label>
// `);
$(".datatable-buttons").prepend(`
<span id="statusSwitchWrapper" class="dt-switch-wrapper">
<span class="custom-switch" style="text-align: left;">
<input type="checkbox" class="custom-control-input" id="toggleButtons" checked>
<label class="custom-control-label" for="toggleButtons" style="vertical-align: middle !important;">Group Client</label>
</span>
</span>
`);
$('#toggleButtons').on('change', function() {
let type = $(this).is(':checked') ? 1 : 2;
// $('div.col-6 h4').text(
// $(this).is(':checked')
// ? "GC Client List"
// : "RC Client List"
// );
let url = '<?= base_url('client/typeList/') ?>' + type;
$.ajax({
url: url,
method: 'GET',
success: function(response) {
if (response.status === "success" && Array.isArray(response.data)) {
renderRows(response.data);
} else {
renderRows([]);
}
},
error: function(xhr, status, error) {
console.error("Error loading:", error);
renderRows([]);
}
});
});
})
function renderRows(data) {
table.clear();
if (Array.isArray(data) && data.length) {
data.forEach((row, index) => {
let clientrm = <?= json_encode($client_rm) ?>;
let account_managers = "";
clientrm.forEach(client => {
if (client.client_id == row.id) {
account_managers += client.account_manager + ", ";
}
});
account_managers = account_managers.replace(/,\s*$/, "");
if (account_managers === "") account_managers = "N/A";
let rowData = [
index + 1,
`<span class="client_info" data-id="${row.id}">${row.client_name} (${row.short_name})</span>`,
account_managers,
`<div class="btn-group dropdown">
<a href="javascript:void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown">
<i class="mdi mdi-dots-horizontal"></i>
</a>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="<?= base_url("client/list/") ?>${row.id}">
<i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit
</a>
<a class="dropdown-item" href="<?= base_url("client/deposit/") ?>${row.id}">
<i class="mdi mdi-cash mr-2 text-muted font-18 vertical-middle"></i>CD Transactions
</a>
<?php if(in_array(get_role_id(), [1, 5])) { ?>
<a class="dropdown-item" data-id="${row.id}" onclick="removeClient(this)">
<i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete
</a>
<?php } ?>
</div>
</div>`
];
let newRow = table.row.add(rowData);
$(newRow.node()).find('td:eq(0)').addClass('text-center');
$(newRow.node()).find('td:eq(1)').addClass('client_info').attr('data-id', row.id);
});
}
table.draw();
}
//DO NOT REMOVE THIS FUNCTION >>> THI FUNCTION FOR CLIENT SOFT DELETE
// function removeClient(element)
// {

View File

@ -332,7 +332,8 @@
<li class="nav-item">
<a href="#hr-access-tab" data-toggle="tab" aria-expanded="false" class="nav-link px-3 py-2" id="hr_access_tab" onclick="appendHrAccessControllHtml(this)">
<span class="mr-1"><i class="mdi mdi-book-open-page-variant"></i></span>
<span class="d-none d-sm-inline-block">HR Access Control</span>
<span class="d-none d-sm-inline-block">Client Access Control</span>
<!-- Name Changed "HR Access Controll" into "Client Access Control" -->
</a>
</li>
<li class="nav-item">
@ -563,7 +564,7 @@
client_notification();
});
//HR Access Controll
//HR Access Controll also know as "Client Access Control"
function appendHrAccessControllHtml(input) {
console.log(input.id);
let client_id = $('#general_PrimaryKey').val();

View File

@ -200,7 +200,8 @@
<span class="slider round" style="height: 27px;"></span>
</label>
<label for="policy_visibility" style="position: relative;bottom: 5px;left: 85px;">Policy Visibilty in Enrollment App</label>
<!-- <label for="policy_visibility" style="position: relative;bottom: 5px;left: 85px;">Policy Visibilty in Enrollment App</label> -->
<label for="policy_visibility" style="position: relative;bottom: 5px;left: 85px;">Policy Visibilty in Employee App</label>
</div>
<div class="form-group col-md-4 EB">