CHANGE_ in email login api : GWM

This commit is contained in:
Gowtham M 2024-12-11 16:19:35 +05:30
parent f2de214a48
commit 22aeb2b558
5 changed files with 331 additions and 84 deletions

View File

@ -448,11 +448,11 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) {
$routes->get("getFEContent", "EmployeeRestController::getFEContent"); $routes->get("getFEContent", "EmployeeRestController::getFEContent");
$routes->get("getAdvertisementImage", "EmployeeRestController::getAdvertisementImage"); $routes->get("getAdvertisementImage", "EmployeeRestController::getAdvertisementImage");
}); });
$routes->get("getEmployeeActiveOrInactivePolicy", "EmployeeRestController::getEmployeeActiveOrInactivePolicy");
$routes->get("sendPushNotification", "EmployeeRestController::sendPushNotification"); $routes->get("sendPushNotification", "EmployeeRestController::sendPushNotification");
$routes->post("sendEmail", "EmployeeRestController::send_email"); $routes->post("sendEmail", "EmployeeRestController::send_email");
$routes->get("getFamilyPolicyDetails", "EmployeeRestController::getFamilyPolicyDetails"); $routes->get("getBackToEnrolledDetails", "EmployeeRestController::getBackToEnrolledDetails");
// Ticketing System // Ticketing System

View File

@ -73,7 +73,7 @@ class ChatBotController extends AdminController
public function getChatResponse() public function getChatResponse()
{ {
// try { try {
$emp_code = $this->request->getVar('emp_code'); $emp_code = $this->request->getVar('emp_code');
$client_id = $this->request->getVar('client_id'); $client_id = $this->request->getVar('client_id');
$client_branch_id = $this->request->getVar('client_branch_id'); $client_branch_id = $this->request->getVar('client_branch_id');
@ -236,9 +236,9 @@ class ChatBotController extends AdminController
return $this->respond(['status' => 'failed','code' => 404,'data' => 'No Data'],404); return $this->respond(['status' => 'failed','code' => 404,'data' => 'No Data'],404);
} }
// } catch (\Throwable $th) { } catch (\Throwable $th) {
// return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
// } }
} }

View File

@ -28,6 +28,7 @@ use App\Models\UserModel;
use App\Models\FEContentModel; use App\Models\FEContentModel;
use App\Models\AddImgModel; use App\Models\AddImgModel;
use App\Models\ClientBranchModel; use App\Models\ClientBranchModel;
use App\Models\AuditHistoryModel;
use App\Controllers\Jobs ; use App\Controllers\Jobs ;
@ -71,6 +72,7 @@ class EmployeeRestController extends AdminController
protected $feContentModel; protected $feContentModel;
protected $addImgModel; protected $addImgModel;
protected $clientBranchModel; protected $clientBranchModel;
protected $auditHistoryModel;
public function __construct() public function __construct()
@ -94,6 +96,7 @@ class EmployeeRestController extends AdminController
$this->feContentModel = new FEContentModel(); $this->feContentModel = new FEContentModel();
$this->addImgModel = new AddImgModel(); $this->addImgModel = new AddImgModel();
$this->clientBranchModel = new ClientBranchModel(); $this->clientBranchModel = new ClientBranchModel();
$this->auditHistoryModel = new AuditHistoryModel();
} }
@ -220,8 +223,6 @@ class EmployeeRestController extends AdminController
{ {
try { try {
$data = $this->request->getJSON(); $data = $this->request->getJSON();
if ($data) { if ($data) {
$Count = 0; $Count = 0;
@ -245,13 +246,11 @@ class EmployeeRestController extends AdminController
$item->dob = $this->convertDateFormatYMD($item->dob); $item->dob = $this->convertDateFormatYMD($item->dob);
$item->emp_status = 'draft'; $item->emp_status = 'draft';
$employee = $this->employeeModel->insert($item); $employee = $this->employeeModel->insert($item);
if ($employee) { if ($employee) {
$Count++; $Count++;
} }
} }
} }
@ -260,21 +259,15 @@ class EmployeeRestController extends AdminController
if(isset($data[0]->id)) if(isset($data[0]->id))
{ {
$this->createEmployeePolicyData($data[0]->id , $data[0]->emp_code , $data[0]->client_id , $data[0]->client_policy_id , $data[0]->basic_cover_si);
$this->createEmployeePolicyData($data[0]->id , $data[0]->emp_code , $data[0]->client_id , $data[0]->client_policy_id , $data[0]->basic_cover_si); }else
{
}else{ $payable_employee = $this->getEmployeePayableValue($data[0]->client_policy_id,$data[0]->relationship);
$this->createEmployeePolicyData($employee , $data[0]->emp_code , $data[0]->client_id , $data[0]->client_policy_id , $data[0]->basic_cover_si , $payable_employee);
$this->createEmployeePolicyData($employee , $data[0]->emp_code , $data[0]->client_id , $data[0]->client_policy_id , $data[0]->basic_cover_si);
} }
$this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code , $data[0]->client_branch_id); $this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code , $data[0]->client_branch_id);
$result = []; $result = [];
return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200); return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200);
} else { } else {
@ -288,7 +281,30 @@ class EmployeeRestController extends AdminController
} }
public function createEmployeePolicyData($employee_id,$emp_code,$client_id,$client_policy_id,$basic_cover_si = null) public function getEmployeePayableValue($client_policy_id,$relationship)
{
$terms = $this->clientPolicyModel->where('id',$client_policy_id)->get()->getRow()->policy_terms;
$is_payable_obj = json_decode($terms)->is_payable_employee;
if ($relationship === 'Mother' || $relationship === 'Father' || $relationship === 'Father in Law' || $relationship === 'Mother in Law')
{
return $is_payable_obj->elders;
}
else if($relationship === 'Son' || $relationship === 'Daughter')
{
return $is_payable_obj->childern;
}
else if($relationship === 'Spouse')
{
return $is_payable_obj->spouse;
}
}
public function createEmployeePolicyData($employee_id,$emp_code,$client_id,$client_policy_id,$basic_cover_si = null,$payable_employee = 0)
{ {
if($basic_cover_si == null) if($basic_cover_si == null)
@ -314,6 +330,7 @@ class EmployeeRestController extends AdminController
$data['employee_id']= $employee_id; $data['employee_id']= $employee_id;
$data['client_policy_id']= $client_policy_id; $data['client_policy_id']= $client_policy_id;
$data['basic_cover_si']= $basic_cover_si; $data['basic_cover_si']= $basic_cover_si;
$data['payable_employee']= $payable_employee;
$data['status']= 'draft'; $data['status']= 'draft';
$data['date_coverage'] = $this->getEmployeeCoverageDate($emp_code, $client_policy_id); $data['date_coverage'] = $this->getEmployeeCoverageDate($emp_code, $client_policy_id);
@ -687,7 +704,7 @@ class EmployeeRestController extends AdminController
$notification = $this->notificationModel->where('client_id',$client_id)->where('template_name','member_welcome_mail')->first(); $notification = $this->notificationModel->where('client_id',$client_id)->where('template_name','member_welcome_mail')->first();
$jwt = $this->request->getHeader('Authorization'); $jwt = $this->request->getHeaderLine('Authorization');
$jwtParts = explode(' ', $jwt); $jwtParts = explode(' ', $jwt);
$token = $jwtParts[2]; $token = $jwtParts[2];
@ -697,7 +714,6 @@ class EmployeeRestController extends AdminController
// get the employee id from token // get the employee id from token
$employee_id = $decodedPayload['id']; $employee_id = $decodedPayload['id'];
// $employee_id = 1;
$client_policy = $this->clientPolicyModel->where('id', $policy_id)->where('client_id', $client_id)->where('client_branch_id', $client_branch_id)->first(); $client_policy = $this->clientPolicyModel->where('id', $policy_id)->where('client_id', $client_id)->where('client_branch_id', $client_branch_id)->first();
if ($client_policy) { if ($client_policy) {
@ -1133,7 +1149,7 @@ class EmployeeRestController extends AdminController
// Generate Notes string based on familyFloates terms // Generate Notes string based on familyFloates terms
$array->notes = $this->FloterNotesConvertion($familyFloates); $array->notes = $this->FloterNotesConvertion($familyFloates);
if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1) if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1 || $getSlabAndGridData['slab_rates'][0]['premium_type'] == 3)
{ {
$array->floter_text_heading = 'Floater Sum Insured'; $array->floter_text_heading = 'Floater Sum Insured';
$array->floter_text_description = 'This is a floater sum insured. A floater is a type of sum insured that provides coverage to more than one member ot a family at the same time. Simply put, its a single insurance cover for the entire family.'; $array->floter_text_description = 'This is a floater sum insured. A floater is a type of sum insured that provides coverage to more than one member ot a family at the same time. Simply put, its a single insurance cover for the entire family.';
@ -1325,7 +1341,7 @@ class EmployeeRestController extends AdminController
// Generate Notes string based on familyFloates terms // Generate Notes string based on familyFloates terms
$array->notes = $this->FloterNotesConvertion($familyFloates); $array->notes = $this->FloterNotesConvertion($familyFloates);
if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1) if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1 || $getSlabAndGridData['slab_rates'][0]['premium_type'] == 3)
{ {
$array->floter_text_heading = 'Floater Sum Insured'; $array->floter_text_heading = 'Floater Sum Insured';
$array->floter_text_description = 'This is a floater sum insured. A floater is a type of sum insured that provides coverage to more than one member ot a family at the same time. Simply put, its a single insurance cover for the entire family.'; $array->floter_text_description = 'This is a floater sum insured. A floater is a type of sum insured that provides coverage to more than one member ot a family at the same time. Simply put, its a single insurance cover for the entire family.';
@ -1680,7 +1696,7 @@ class EmployeeRestController extends AdminController
} }
if(count($getSlabAndGridData['slab_rates'])){ if(count($getSlabAndGridData['slab_rates'])){
if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1) if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1 || $getSlabAndGridData['slab_rates'][0]['premium_type'] == 3)
{ {
$responce['floter_text_heading'] = 'Floater Sum Insured'; $responce['floter_text_heading'] = 'Floater Sum Insured';
}else{ }else{
@ -1961,13 +1977,6 @@ class EmployeeRestController extends AdminController
$emp_code = $postData['emp_code']; $emp_code = $postData['emp_code'];
$client_id = $postData['client_id']; $client_id = $postData['client_id'];
$this->employeeModel->where('emp_code', $emp_code )
->where('client_id', $client_id )
->where('is_active', 1 )
->where('emp_status', 'draft' )
->set(array('emp_status'=>'enrolled'))
->update();
$empData = $this->employeeModel->where('emp_code', $emp_code )->where('client_id', $client_id ) ->where('is_active', 1 )->findAll(); $empData = $this->employeeModel->where('emp_code', $emp_code )->where('client_id', $client_id ) ->where('is_active', 1 )->findAll();
//for mail common parameter //for mail common parameter
@ -2000,6 +2009,16 @@ class EmployeeRestController extends AdminController
} }
//update Employee table
$this->employeeModel->where('emp_code', $emp_code)->where('client_id', $client_id)->where('is_active', 1)
->groupStart()
->where('emp_status', 'draft')
->orWhere('emp_status', 'enrolled')
->groupEnd()
->set(['emp_status' => 'enrolled'])
->update();
$notification = $this->notificationModel->where('client_id' ,$client_id)->where('template_name', 'member_review_and_summary_mail')->first(); $notification = $this->notificationModel->where('client_id' ,$client_id)->where('template_name', 'member_review_and_summary_mail')->first();
@ -2429,7 +2448,7 @@ class EmployeeRestController extends AdminController
$si_gst_value = 0; $si_gst_value = 0;
foreach ($employee_policy as $key => $value) { foreach ($employee_policy as $key => $value) {
if(isset($value['basic_cover_si'])){ $si_value = $value['basic_cover_si']; } if(isset($value['basic_cover_si'])){ $si_value = ($si_value == 0) ? $value['basic_cover_si'] : $si_value; }
if(isset($value['premium'])){ $si_premium_value = $si_premium_value + $value['premium'];} if(isset($value['premium'])){ $si_premium_value = $si_premium_value + $value['premium'];}
if(isset($value['gst'])){ $si_gst_value = $si_gst_value + $value['gst'];} if(isset($value['gst'])){ $si_gst_value = $si_gst_value + $value['gst'];}
} }
@ -2665,59 +2684,223 @@ class EmployeeRestController extends AdminController
// } // }
public function getFamilyPolicyDetails() public function getBackToEnrolledDetails()
{ {
// Get query parameters // Get query parameters
$empCode = $this->request->getGet('emp_code'); $empCode = $this->request->getGet('emp_code');
$clientId = $this->request->getGet('client_id'); $clientId = $this->request->getGet('client_id');
$clientBranchId = $this->request->getGet('client_branch_id'); $clientBranchId = $this->request->getGet('client_branch_id');
if (!$empCode || !$clientId || !$clientBranchId) { if (!$empCode || !$clientId || !$clientBranchId) { return $this->fail("emp_code, client_id, and client_branch_id are required parameters."); }
return $this->fail("emp_code, client_id, and client_branch_id are required parameters.");
}
// Fetch employee family details //Fetch active employee details
$employees = $this->employeeModel->select('id,emp_code,name,relationship,dob,emp_status,is_addon_value')->where([ $employees = $this->employeeModel->select('id,emp_code,name,relationship,dob,emp_status,is_addon_value,created_at,updated_at')
'emp_code' => $empCode, ->where([
'client_id' => $clientId, 'emp_code' => $empCode,
'client_branch_id' => $clientBranchId, 'client_id' => $clientId,
'is_active' => 1 'client_branch_id' => $clientBranchId,
])->findAll(); 'is_active' => 1
])
->findAll();
if (empty($employees)) { //Find status of self
return $this->failNotFound("No employees found for the provided parameters."); $selfEmployee = array_filter($employees, function($employee) { return $employee['relationship'] === 'Self'; });
} $data['self_status'] = !empty($selfEmployee) ? array_values($selfEmployee)[0]['emp_status'] : null;
$data['self_enrolled_time'] = !empty($selfEmployee) ? array_values($selfEmployee)[0]['updated_at'] : null;
$data['self_employee_id'] = !empty($selfEmployee) ? array_values($selfEmployee)[0]['id'] : null;
// Collect employee IDs
//Fetch employee policy details
$employeeIds = array_column($employees, 'id'); $employeeIds = array_column($employees, 'id');
// Fetch policies related to the employee IDs
$policies = $this->employeePolicyModel->whereIn('employee_id', $employeeIds)->where('is_active',1)->findAll(); $policies = $this->employeePolicyModel->whereIn('employee_id', $employeeIds)->where('is_active',1)->findAll();
if (empty($policies)) {
return $this->failNotFound("No policies found for the provided employees."); //Find the stage of enrolment process
$employeeStatuses = array_column($employees, 'emp_status');
$employeePolicyStatuses = array_column($policies, 'status');
$uniqueStatuses = array_unique(array_merge($employeeStatuses, $employeePolicyStatuses));
if(count($uniqueStatuses) > 1){ $enrolmentStagekey = 1; }else{ if($uniqueStatuses[0] == 'draft'){ $enrolmentStagekey = 0; }else{ $enrolmentStagekey = 2; } }
$enrolmentStage = ['Draft Only','Intermittent Enrollment','Successful Enrollment'];
$data['enrolment_stage'] = $enrolmentStage[$enrolmentStagekey];
$data['revert_employee_data'] = [];
$data['revert_employee_policy_data'] = [];
if($enrolmentStagekey == 1)
{
//Find active employee history
$empIdsWithoutSelf = $employeeIds;
$key = array_search($data['self_employee_id'], $empIdsWithoutSelf);
unset($empIdsWithoutSelf[$key]);
foreach ($empIdsWithoutSelf as $key => $pk)
{
$retrivedData = $this->retriveOldData($data['self_enrolled_time'],'employees',$pk);
if($retrivedData != false)
array_push($data['revert_employee_data'] , $retrivedData);
}
//Find inactive employee history
$inActiveEmployees = $this->employeeModel->select('id,emp_code,name,relationship,dob,emp_status,is_addon_value,created_at,updated_at')
->where([
'emp_code' => $empCode,
'client_id' => $clientId,
'client_branch_id' => $clientBranchId,
'is_active' => 0
])
->findAll();
$inActiveEmployeeIds = array_column($inActiveEmployees, 'id');
foreach ($inActiveEmployeeIds as $key => $pk)
{
$retrivedData = $this->retriveOldData($data['self_enrolled_time'],'employees',$pk);
if($retrivedData != false)
array_push($data['revert_employee_data'] , $retrivedData);
}
//Merged active and inactive employees , employee_polict history
$mergedEmpIds = array_merge($employeeIds,$inActiveEmployeeIds);
$empPolicyData = $this->employeePolicyModel->whereIn('employee_id', $mergedEmpIds)->findAll();
$employeePolicyIds = array_column($empPolicyData, 'id');
foreach ($employeePolicyIds as $key => $pk)
{
$retrivedData = $this->retriveOldData($data['self_enrolled_time'],'employee_polices',$pk);
if($retrivedData != false)
array_push($data['revert_employee_policy_data'] , $retrivedData);
}
} }
// Structure the response
$result = []; if($this->request->getGet('revert_data') == 1)
{
//update data back to employee
if(count($data['revert_employee_data'])){
foreach ($data['revert_employee_data'] as $key => $val)
{
$this->employeeModel->where('id',$val['id'] )->set($val['data'])->update();
}
}
//update data back to employee policy
if(count($data['revert_employee_policy_data'])){
foreach ($data['revert_employee_policy_data'] as $key => $val)
{
$this->employeePolicyModel->where('id',$val['id'] )->set($val['data'])->update();
}
}
//update enrolled status for self
if(count($data['revert_employee_data']) || count($data['revert_employee_policy_data'])){
$this->employeeModel->where('id',$data['self_employee_id'] )->set(array('emp_status'=>'enrolled'))->update();
$data['retrieve_status'] = 'Data revert successfully';
}else{
$data['retrieve_status'] = 'There is no data to revert';
}
}
// Fetch all policies related to these employees who currently active
$current_employee_data = $this->employeeModel->select('id,emp_code,name,relationship,dob,emp_status,is_addon_value,created_at,updated_at')
->where([
'emp_code' => $empCode,
'client_id' => $clientId,
'client_branch_id' => $clientBranchId,
'is_active' => 1
])
->findAll();
$Ids = array_column($current_employee_data, 'id');
$policies = $this->employeePolicyModel->whereIn('employee_id', $Ids)->where('is_active',1)->findAll();
// Group policies by policy_id
$groupedPolicies = [];
foreach ($policies as $policy) { foreach ($policies as $policy) {
$policyEmployees = array_filter($employees, function ($emp) use ($policy) { $policyId = $policy['client_policy_id'];
return $emp['id'] === $policy['employee_id'];
}); if (!isset($groupedPolicies[$policyId])) {
$groupedPolicies[$policyId] = [
'policy_id' => $policy['id'],
'client_policy_id' => $policy['client_policy_id'],
'uhid' => $policy['uhid'],
'status' => $policy['status'],
'basic_cover_si' => $policy['basic_cover_si'],
'date_coverage' => $policy['date_coverage'],
'policy_end_date' => $policy['policy_end_date'],
'members' => []
];
}
$result[] = [ // Add member details to the current policy
'policy_id' => $policy['id'], foreach ($current_employee_data as $employee) {
'client_policy_id' => $policy['client_policy_id'], if ($employee['id'] === $policy['employee_id']) {
'uhid' => $policy['uhid'], $groupedPolicies[$policyId]['members'][] = [
'status' => $policy['status'], 'id' => $employee['id'],
'basic_cover_si' => $policy['basic_cover_si'], 'emp_code' => $employee['emp_code'],
'date_coverage' => $policy['date_coverage'], 'name' => $employee['name'],
'policy_end_date' => $policy['policy_end_date'], 'relationship' => $employee['relationship'],
'members' => array_values($policyEmployees), 'dob' => $employee['dob'],
]; 'emp_status' => $employee['emp_status'],
'is_addon_value' => $employee['is_addon_value']
];
}
}
} }
return $this->respond(['family_policies' => $result]); // Re-index the grouped policies
$data['currentPolicies'] = array_values($groupedPolicies);
return $this->respond(['data' => $data]);
}
public function retriveOldData($self_enrolled_time,$table,$pk)
{
$historyData = $this->auditHistoryModel->where('pk', $pk)->where('table_name',$table)->findAll();
$beforeEnrolled = [];
$afterEnrolled = [];
// Split the array
foreach ($historyData as $val) {
if ($val['created_at'] <= $self_enrolled_time) { $beforeEnrolled[] = $val; } else { $afterEnrolled[] = $val; }
}
if(count($beforeEnrolled) && count($afterEnrolled)){ //After enrolment edited some of the data
$temp['table'] = $table;
$temp['id'] = $pk;
// Extract earliest `old_value` for each `field_name`
$originalValues = [];
foreach ($afterEnrolled as $entry) {
$field = $entry['field_name'];
// If the field is not already in originalValues , update it
if (!isset($originalValues[$field])) {
$originalValues[$field] = $entry['old_value'];
}
}
$temp['data'] = $originalValues;
return $temp;
}else if(!count($beforeEnrolled) && !count($afterEnrolled)){ //After enrolment created new data
$temp['table'] = $table;
$temp['id'] = $pk;
$temp['data'] = ['is_active'=> 0 ];
return $temp;
}else if(!count($beforeEnrolled) && count($afterEnrolled)){ //After enrolment created new data and edited some of the data
$temp['table'] = $table;
$temp['id'] = $pk;
$temp['data'] = ['is_active'=> 0 ];
return $temp;
}else if(count($beforeEnrolled) && !count($afterEnrolled)){ //After enrolment nothing changes from the data
return false;
}
} }

View File

@ -4,7 +4,7 @@
namespace App\Controllers; namespace App\Controllers;
use App\Helpers\MailHelper;
use App\Controllers\LoginController; use App\Controllers\LoginController;
use App\Helpers\DepositHelper; use App\Helpers\DepositHelper;
use App\Helpers\JWTToken; use App\Helpers\JWTToken;
@ -97,16 +97,51 @@ class RestAuthenticationController extends AdminController
$email = $this->request->getJSON()->email; $email = $this->request->getJSON()->email;
$employeeData = $this->employeeModel->where('email', $email) $employeeData = $this->employeeModel->where('email_corporate', $email)->where('relationship', 'self')
->where('relationship', 'self') ->where('emp_status !=', 'truncated')->where('is_active', 1)
->where('emp_status !=', 'truncated')
->where('is_active', 1)
->first(); ->first();
if ($employeeData) { if ($employeeData) {
$otp = random_int(100000, 999999);
$update = $this->employeeModel->where('email_corporate', $email)->where('relationship', 'self')
->where('is_active', 1)->set(array('otp' => $otp ))
->update();
if($update)
{
$common = [
'client_id' => $employeeData->client_id,
'client_branch_id' => $employeeData->client_branch_id,
'client_policy_id' => null,
'employee_policy_id' => null,
'employee_id' => $employeeData->id,
'mail_type' => 'otp_mail',
];
$subject = 'Nhance user verification - OTP';
$mail_content = $otp.' is your verification code for Nhance.';
$res = MailHelper::send_email(['mail' => $employeeData->email_corporate, 'subject' => $subject ,'common'=>$common ,'message' => $mail_content]);
$this->myLogger->logme("info", $res);
if(json_decode($res)->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' => "Mail sending failed , try again"];
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200);
}
}else{
$result = ['user_verification' => false , 'message' => "Verification failed , try again"];
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200);
}
$result = ['user_verification' => true ,'message' => "Verified Successfully"];
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
} else { } else {
$result = ['user_verification' => false , 'message' => "User not found"]; $result = ['user_verification' => false , 'message' => "User not found"];
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200); return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200);
@ -122,8 +157,10 @@ class RestAuthenticationController extends AdminController
{ {
try { try {
$otp_verification = $this->request->getJSON()->otp_verification; $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_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; $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null;
if (isset($this->request->getJSON()->login_by_hr)) if (isset($this->request->getJSON()->login_by_hr))
@ -134,12 +171,12 @@ class RestAuthenticationController extends AdminController
{ {
$employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first(); $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first();
} else { } else {
$employeeData = $this->employeeModel->where('email', $email_id)->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();
} }
} }
if ($employeeData && $otp_verification == true || $employeeData && isset($this->request->getJSON()->login_by_hr)) { if ($employeeData && $otp_verification == true || $employeeData && isset($this->request->getJSON()->login_by_hr) || $employeeData && isset($this->request->getJSON()->otp) ) {
$auth = HttpRequestHelper::getRequestInfo(); $auth = HttpRequestHelper::getRequestInfo();
if ($auth) { if ($auth) {
$data = [ $data = [
@ -154,6 +191,11 @@ class RestAuthenticationController extends AdminController
$result = JWTToken::encode($employeeData); $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();
}
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
} else { } else {
@ -256,7 +298,7 @@ class RestAuthenticationController extends AdminController
if (isset($mobile_number)) { 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();
} else { } else {
$employeeData = $this->employeeModel->where('email', $email_id)->where('relationship', 'self')->first(); $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first();
} }
$mpin = $this->request->getJSON()->mpin; $mpin = $this->request->getJSON()->mpin;
@ -299,7 +341,7 @@ class RestAuthenticationController extends AdminController
{ {
$employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('mpin', $old_mpin)->where('relationship', 'self')->first();
}else{ }else{
$employeeData = $this->employeeModel->where('email', $email_id)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('mpin', $old_mpin)->where('relationship', 'self')->first();
} }
@ -338,7 +380,7 @@ class RestAuthenticationController extends AdminController
{ {
$employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first();
}else{ }else{
$employeeData = $this->employeeModel->where('email', $email_id)->where('relationship', 'self')->first(); $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first();
} }
if ($employeeData && $mpin == $employeeData["mpin"]) { if ($employeeData && $mpin == $employeeData["mpin"]) {
@ -379,7 +421,7 @@ class RestAuthenticationController extends AdminController
{ {
$employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first();
}else{ }else{
$employeeData = $this->employeeModel->where('email', $email_id)->where('relationship', 'self')->first(); $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first();
} }

View File

@ -0,0 +1,22 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class AuditHistoryModel extends Model
{
protected $table = 'auditing_history';
protected $primaryKey = 'id';
protected $allowedFields = [
"id",
"pk",
"table_name",
"field_name",
"old_value",
"new_value",
"created_by",
"created_at",
];
}
?>