CHANGE_ADD_NEW_API_FIREBASE_TOKEN_API_EMP_REST : AADHAVAN

This commit is contained in:
aadhavan valli 2024-07-20 09:57:35 +05:30
parent ba4ad6bb62
commit 5e3c126b0b
2 changed files with 1332 additions and 1275 deletions

View File

@ -136,6 +136,7 @@ $routes->group("/employee", ["filter" => "authMVC"], function ($routes) {
$routes->post("upload", "EmployeeController::employeesUplodWithEvents"); $routes->post("upload", "EmployeeController::employeesUplodWithEvents");
$routes->get("excel_error/(:any)", "EmployeeController::getExcelFileErrors/$1"); $routes->get("excel_error/(:any)", "EmployeeController::getExcelFileErrors/$1");
$routes->get("endorsement-list", "EmployeeController::endorsementList"); $routes->get("endorsement-list", "EmployeeController::endorsementList");
$routes->get("enrollment-list", "EmployeeController::enrollmentList");
$routes->get("truncate/(:any)", "EmployeeController::truncateFileData/$1"); $routes->get("truncate/(:any)", "EmployeeController::truncateFileData/$1");
}); });
@ -287,6 +288,7 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) {
$routes->get("getChatResponse", "ChatBotController::getChatResponse"); $routes->get("getChatResponse", "ChatBotController::getChatResponse");
$routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) {
$routes->post("storeFireBase", "EmployeeRestController::storeFireBase");
$routes->post("saveMpin", "RestAuthenticationController::saveMpin"); $routes->post("saveMpin", "RestAuthenticationController::saveMpin");
$routes->post("updateMpin", "RestAuthenticationController::updateMpin"); $routes->post("updateMpin", "RestAuthenticationController::updateMpin");
$routes->get("getChatResponse", "ChatBotController::getChatResponse"); $routes->get("getChatResponse", "ChatBotController::getChatResponse");

View File

@ -928,9 +928,9 @@ class EmployeeRestController extends AdminController
} }
//------------------------------------- //-------------------------------------
public function getAgeRange($terms,$familyFloatesValue) public function getAgeRange($terms,$familyFloatesValue)
{ {
$ageRangeArray = ['self' => ['min' => 18, 'max' => 60] , 'spouse' => ['min' => 18, 'max' => 60] , 'child' => ['min' => 0, 'max' => 25] , 'elders' => ['min' => 18, 'max' => 60] ]; $ageRangeArray = ['self' => ['min' => 18, 'max' => 60] , 'spouse' => ['min' => 18, 'max' => 60] , 'child' => ['min' => 0, 'max' => 25] , 'elders' => ['min' => 18, 'max' => 60] ];
@ -942,10 +942,10 @@ public function getAgeRange($terms,$familyFloatesValue)
} }
} }
public function getEmployeePolicy() public function getEmployeePolicy()
{ {
// try { // try {
$id = $this->request->getGet('id'); $id = $this->request->getGet('id');
@ -1159,11 +1159,11 @@ public function getEmployeePolicy()
// } catch (\Exception $e) { // } catch (\Exception $e) {
// return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); // return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
// } // }
} }
public function getGmcParrentsPolicy($GmcParrentsPolicy,$emp_code,$client_id,$client_branch_id) public function getGmcParrentsPolicy($GmcParrentsPolicy,$emp_code,$client_id,$client_branch_id)
{ {
$employeeData = $this->employeeModel->where('emp_code',$emp_code) $employeeData = $this->employeeModel->where('emp_code',$emp_code)
->where('client_id',$client_id) ->where('client_id',$client_id)
@ -1316,9 +1316,9 @@ public function getGmcParrentsPolicy($GmcParrentsPolicy,$emp_code,$client_id,$cl
} }
} }
public function FloterConvertion($array){ public function FloterConvertion($array){
$result = []; $result = [];
@ -1348,9 +1348,9 @@ public function FloterConvertion($array){
} }
return $result; return $result;
} }
public function FloterNotesConvertion($array){ public function FloterNotesConvertion($array){
$result = ' '; $result = ' ';
foreach ($array as $key => $value) { foreach ($array as $key => $value) {
@ -1374,10 +1374,10 @@ public function FloterNotesConvertion($array){
} }
return $result; return $result;
} }
public function getClientDetails() public function getClientDetails()
{ {
try { try {
$client = $this->clientModel->where('id',$this->request->getGet('client_id'))->first(); $client = $this->clientModel->where('id',$this->request->getGet('client_id'))->first();
@ -1393,10 +1393,10 @@ public function getClientDetails()
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
} }
} }
public function getAddOnPolicy() public function getAddOnPolicy()
{ {
try { try {
$addOnEmployeeData = $this->employeeModel->where('is_active', 1 ) $addOnEmployeeData = $this->employeeModel->where('is_active', 1 )
@ -1748,10 +1748,10 @@ public function getAddOnPolicy()
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
} }
} }
public function iAgreeForAddOn() public function iAgreeForAddOn()
{ {
$postData = json_decode($this->request->getBody(), true); $postData = json_decode($this->request->getBody(), true);
$client_policy_id = $postData['client_policy_id']; $client_policy_id = $postData['client_policy_id'];
sort($client_policy_id); sort($client_policy_id);
@ -1822,13 +1822,13 @@ public function iAgreeForAddOn()
} }
return $this->respond(['status' => 'success','code' => 200,'data' => [] ], 200); return $this->respond(['status' => 'success','code' => 200,'data' => [] ], 200);
} }
//Post method - which receives client_policy id and empcode of the family. //Post method - which receives client_policy id and empcode of the family.
//Pull records againest emp code and calculate premium //Pull records againest emp code and calculate premium
// retun array // retun array
public function calculatePremium($clientPolicyId = null , $empCode = null, $default_si = null)//family level public function calculatePremium($clientPolicyId = null , $empCode = null, $default_si = null)//family level
{ {
helper('excel_util_helper'); helper('excel_util_helper');
$client_policy_id = $this->request->getVar('client_policy_id') ?? $clientPolicyId; $client_policy_id = $this->request->getVar('client_policy_id') ?? $clientPolicyId;
$emp_code = $this->request->getVar('emp_code') ?? $empCode; $emp_code = $this->request->getVar('emp_code') ?? $empCode;
@ -1881,11 +1881,11 @@ public function calculatePremium($clientPolicyId = null , $empCode = null, $defa
} }
} }
public function getCashDepositData() public function getCashDepositData()
{ {
$ClientPolicyData = $this->clientPolicyModel->select('client_policy.client_id as clientId , client_policy.insurer_id as insurerId,insurers.name as insurer_name') $ClientPolicyData = $this->clientPolicyModel->select('client_policy.client_id as clientId , client_policy.insurer_id as insurerId,insurers.name as insurer_name')
->join('insurers', 'client_policy.insurer_id = insurers.id', 'left') ->join('insurers', 'client_policy.insurer_id = insurers.id', 'left')
@ -1957,13 +1957,13 @@ public function getCashDepositData()
return $this->respond(['status' => 'failed','code' => (count($result) ? 200 : 404),'data' => [] ], 200); return $this->respond(['status' => 'failed','code' => (count($result) ? 200 : 404),'data' => [] ], 200);
} }
} }
public function exportCashDepositData() public function exportCashDepositData()
{ {
$CashDepositData = $this->clientPolicyModel->getdepositData($this->request->getGet('client_id'),$this->request->getGet('insurer_id')); $CashDepositData = $this->clientPolicyModel->getdepositData($this->request->getGet('client_id'),$this->request->getGet('insurer_id'));
@ -2025,11 +2025,11 @@ public function exportCashDepositData()
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200); return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200);
} }
} }
public function removeEmpAndEmpPolicyData() public function removeEmpAndEmpPolicyData()
{ {
try { try {
$clientPolicy = $this->clientPolicyModel->where('id',$this->request->getGet('client_policy_id'))->findAll(); $clientPolicy = $this->clientPolicyModel->where('id',$this->request->getGet('client_policy_id'))->findAll();
@ -2091,11 +2091,11 @@ public function removeEmpAndEmpPolicyData()
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
} }
} }
function getEmployeeActiveOrInactivePolicy() function getEmployeeActiveOrInactivePolicy()
{ {
if($this->request->getGet('type') == 'Active'){ $policy_status = 1; }else{ $policy_status = 0; } if($this->request->getGet('type') == 'Active'){ $policy_status = 1; }else{ $policy_status = 0; }
$ClientPolicyData = $this->clientPolicyModel->select('client_policy.* , policies.name as policy_name , policy_type.policy_type as policy_type') $ClientPolicyData = $this->clientPolicyModel->select('client_policy.* , policies.name as policy_name , policy_type.policy_type as policy_type')
@ -2196,11 +2196,11 @@ function getEmployeeActiveOrInactivePolicy()
return $this->respond(['status' => 'failed','code' => 404,'data' => [] ], 200); return $this->respond(['status' => 'failed','code' => 404,'data' => [] ], 200);
} }
} }
function policyTermsFiter($terms , $type) function policyTermsFiter($terms , $type)
{ {
$gpa = [ $gpa = [
"sumInsured2" => "Sum Insured", "sumInsured2" => "Sum Insured",
@ -2262,11 +2262,11 @@ function policyTermsFiter($terms , $type)
return $finalarray; return $finalarray;
} }
private function convertDateFormatDisplay($dateString) private function convertDateFormatDisplay($dateString)
{ {
// Attempt to create a DateTime object from the provided date string // Attempt to create a DateTime object from the provided date string
$dateTime = \DateTime::createFromFormat('Y-m-d', $dateString); $dateTime = \DateTime::createFromFormat('Y-m-d', $dateString);
@ -2275,10 +2275,10 @@ private function convertDateFormatDisplay($dateString)
} else { } else {
return null; return null;
} }
} }
public function getFEContent() public function getFEContent()
{ {
try { try {
$feContentData = $this->feContentModel->findAll(); $feContentData = $this->feContentModel->findAll();
@ -2293,10 +2293,10 @@ public function getFEContent()
} 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);
} }
} }
public function getAdvertisementImage() public function getAdvertisementImage()
{ {
try { try {
$img = $this->addImgModel->where('is_active',1)->findAll(); $img = $this->addImgModel->where('is_active',1)->findAll();
@ -2317,6 +2317,61 @@ public function getAdvertisementImage()
} 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);
} }
} }
public function storeFireBase()
{
try {
$firebase_token = $this->request->getPost('firebase_token');
$mobile = $this->request->getPost('mobile');
// Ensure the mobile number is provided
if (empty($mobile)) {
return $this->respond(['status' => 'failed', 'code' => 400, 'message' => 'Mobile number is required'], 400);
}
// Fetch employee by mobile number
$employee = $this->employeeModel->where('mobile', $mobile)->first();
if ($employee) {
// Check if firebase_token is provided
if (!empty($firebase_token)) {
// Check if the current firebase_token is different from the new one
if ($employee['firebase_token'] !== $firebase_token) {
// Update the employee's firebase_token
$data['firebase_token'] = $firebase_token;
$id = $employee['id'];
// return json_encode($data);
// Direct database update query for testing
$db = \Config\Database::connect();
$builder = $db->table('employees');
$update_emp = $builder->update($data, ['id' => $id]);
// Check if the update was successful
if ($db->affectedRows() > 0) {
// Fetch the updated employee data
$updated_employee = $this->employeeModel->find($id);
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $updated_employee], 200);
} else {
log_message('error', 'Update failed. No rows affected.');
return $this->respond(['status' => 'failed', 'code' => 500, 'message' => 'Failed to update employee data'], 500);
}
} else {
return $this->respond(['status' => 'failed', 'code' => 400, 'message' => 'New Firebase Token is the same as the current one'], 400);
}
} else {
return $this->respond(['status' => 'failed', 'code' => 400, 'message' => 'Firebase Token is required'], 400);
}
} else {
return $this->respond(['status' => 'failed', 'code' => 404, 'message' => 'Employee not found'], 404);
}
} catch (\Throwable $th) {
log_message('error', 'An error occurred: ' . $th->getMessage());
return $this->respond(['status' => 'failed', 'code' => 500, 'message' => 'An error occurred', 'error' => $th->getMessage()], 500);
}
}
} }