FEAT_RETAIL_POLICY
This commit is contained in:
parent
5a1570cade
commit
0690c9868e
@ -651,6 +651,7 @@ $routes->get("getPolicyLevelEmployeeSummaryData", "EmployeeRestController::getPo
|
||||
$routes->get("cdTransactionData", "EmployeeRestController::cdTransactionData");
|
||||
$routes->match( ['get', 'post'], 'claimsSearch','EmployeeRestController::claimsSearch');
|
||||
$routes->get("getBackToEnrolledDetails", "EmployeeRestController::getBackToEnrolledDetails");
|
||||
$routes->post("addEmpRetailPolicy", "EmployeeRestController::addEmpRetailPolicy");
|
||||
|
||||
// Ticketing System
|
||||
|
||||
|
||||
@ -39,6 +39,7 @@ use App\Models\TicketMessageModel;
|
||||
use App\Models\HRAccessControlModel;
|
||||
use App\Models\InsurerModel;
|
||||
use App\Models\HrFileUploadModel;
|
||||
use App\Models\EmployeeRetailPolicy;
|
||||
|
||||
|
||||
|
||||
@ -97,6 +98,7 @@ class EmployeeRestController extends AdminController
|
||||
protected $insurerModel;
|
||||
protected $hrFileUploadModel;
|
||||
protected $ticketMailTemplateModel;
|
||||
protected $employeeRetailPolicy;
|
||||
|
||||
|
||||
public function __construct()
|
||||
@ -124,6 +126,7 @@ class EmployeeRestController extends AdminController
|
||||
$this->claimStatusModel = new TicketClaimStatusModel();
|
||||
$this->ticketMaster = new TicketMasterModel();
|
||||
$this->ticketMessage = new TicketMessageModel();
|
||||
$this->employeeRetailPolicy = new EmployeeRetailPolicy();
|
||||
|
||||
$this->ticketController = new TicketController();
|
||||
$this->hrAccessControlModel = new HRAccessControlModel();
|
||||
@ -2993,7 +2996,9 @@ class EmployeeRestController extends AdminController
|
||||
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result, 'emp_name' => $employeeName, 'pre_policy_count' => $prePolicyCount], 200);
|
||||
$emp_reatail_policy_data = $this->getEmpRetailPolicy($employeeSelfData);
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result, 'emp_name' => $employeeName, 'pre_policy_count' => $prePolicyCount, 'retail_policy_data' => $emp_reatail_policy_data], 200);
|
||||
} else {
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200);
|
||||
}
|
||||
@ -4586,4 +4591,128 @@ class EmployeeRestController extends AdminController
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
public function addEmpRetailPolicy()
|
||||
{
|
||||
$this->myLogger->logme("error", "EMPLOYEE-RETAIL-POLICY-CONTROLLER - addEmpRetailPolicy: Received payload = " . json_encode($this->request->getJSON() ?? []));
|
||||
|
||||
try {
|
||||
|
||||
$payload = $this->request->getJSON(true);
|
||||
$emp_id = $payload['emp_id'] ?? null;
|
||||
|
||||
if (empty($emp_id)) {
|
||||
$this->myLogger->logme("error", "addEmpRetailPolicy: emp_id is missing");
|
||||
return $this->respond(['status' => 'failed','code' => 400,'message' => 'emp_id is required' ], 200);
|
||||
}
|
||||
|
||||
$payload['created_by'] = $emp_id;
|
||||
$emp_retail_policy_id = $this->employeeRetailPolicy->insert($payload);
|
||||
|
||||
if ($emp_retail_policy_id) {
|
||||
|
||||
$this->myLogger->logme("error", "addEmpRetailPolicy: Employee Retail Policy created successfully. Policy ID = " . $emp_retail_policy_id);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'message' => 'Employee Retail Policy created successfully',
|
||||
'data' => [
|
||||
'emp_retail_policy_id' => $emp_retail_policy_id
|
||||
]
|
||||
], 200);
|
||||
} else {
|
||||
$this->myLogger->logme( "error", "addEmpRetailPolicy: Failed to create Employee Retail Policy. Insert returned false" );
|
||||
return $this->respond(['status' => 'failed','code' => 500,'message' => 'Failed to create Employee Retail Policy'], 500);
|
||||
}
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
$this->myLogger->logme("error", "addEmpRetailPolicy: Exception occurred - " . $th->getMessage());
|
||||
return $this->respond(['status' => 'failed','code' => 500,'message' => 'Internal server error: ' . $th->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function getEmpRetailPolicy($employeeData)
|
||||
{
|
||||
$this->myLogger->logme("error", "EMPLOYEE-REST-CONTROLLER - getEmpRetailPolicy: Given params: " . json_encode($employeeData ?? []));
|
||||
|
||||
try {
|
||||
|
||||
$emp_id = $employeeData['id'];
|
||||
$mobile_number = $employeeData['mobile'] ?? null;
|
||||
|
||||
$emp_retail_policy_data = [];
|
||||
if (!empty($emp_id)) {
|
||||
|
||||
$emp_retail_policy_data = $this->employeeRetailPolicy
|
||||
->select('
|
||||
employee_retail_policies.emp_id,
|
||||
employee_retail_policies.insurer_id,
|
||||
employee_retail_policies.policy_type_id,
|
||||
employee_retail_policies.policy_no,
|
||||
employee_retail_policies.policy_start_date,
|
||||
employee_retail_policies.policy_end_date,
|
||||
policy_type.policy_type,
|
||||
policy_type.long_name as policy_type_name,
|
||||
insurers.name as insurer_name
|
||||
')
|
||||
->join('insurers', 'employee_retail_policies.insurer_id = insurers.id')
|
||||
->join('policy_type', 'employee_retail_policies.policy_type_id = policy_type.id')
|
||||
->where('is_active', 1)
|
||||
->where('emp_id', $emp_id)
|
||||
->findAll();
|
||||
}
|
||||
|
||||
$emp_retail_client_data = [];
|
||||
|
||||
if (!empty($mobile_number)) {
|
||||
$emp_retail_client_data = $this->clientModel
|
||||
->select("
|
||||
$emp_id as emp_id
|
||||
policy_transaction.insurer_id
|
||||
policy_transaction.policy_type_id
|
||||
policy_transaction.policy_no
|
||||
policy_transaction.policy_start_date
|
||||
policy_transaction.policy_end_date
|
||||
policy_type.policy_type,
|
||||
policy_type.long_name as policy_type_name,
|
||||
insurers.name as insurer_name
|
||||
")
|
||||
->join('policy_transaction', 'policy_transaction.client_id = clients.id')
|
||||
->join('insurers', 'policy_transaction.insurer_id = insurers.id')
|
||||
->join('policy_type', 'policy_transaction.policy_type_id = policy_type.id')
|
||||
->where('policy_transaction.is_active', 1)
|
||||
->where('clients.is_active', 1)
|
||||
->where('clients.phone', $mobile_number)
|
||||
->findAll();
|
||||
}
|
||||
|
||||
$complete_emp_retail_policy_data = array_values(
|
||||
array_column(
|
||||
array_merge($emp_retail_policy_data ?: [], $emp_retail_client_data ?: []),
|
||||
null,
|
||||
'policy_no'
|
||||
)
|
||||
);
|
||||
|
||||
return $complete_emp_retail_policy_data;
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
$errorData = [
|
||||
'message' => $th->getMessage(),
|
||||
'file' => $th->getFile(),
|
||||
'line' => $th->getLine(),
|
||||
'code' => $th->getCode(),
|
||||
'trace' => $th->getTraceAsString(),
|
||||
'trace_array' => $th->getTrace(), // full array version (optional)
|
||||
'function' => $th->getTrace()[0]['function'] ?? null,
|
||||
'class' => $th->getTrace()[0]['class'] ?? null,
|
||||
];
|
||||
|
||||
$this->myLogger->logme("error", "EMPLOYEE-REST-CONTROLLER - getEmpRetailPolicy: Exception: " . json_encode($errorData ?? []));
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
57
app/Models/EmployeeRetailPolicy.php
Normal file
57
app/Models/EmployeeRetailPolicy.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class EmployeeRetailPolicy extends Model
|
||||
{
|
||||
protected $table = 'employee_retail_policies';
|
||||
protected $primaryKey = 'id';
|
||||
protected $allowedFields = [
|
||||
'id',
|
||||
'emp_id',
|
||||
'insurer_id',
|
||||
'policy_type_id',
|
||||
'policy_no',
|
||||
'policy_start_date',
|
||||
'policy_end_date',
|
||||
'created_by',
|
||||
'updated_at',
|
||||
'created_at',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
// Callbacks
|
||||
protected $allowCallbacks = true;
|
||||
protected $beforeInsert = ["checkAndADDCreatedByValue"];
|
||||
protected $afterInsert = [];
|
||||
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
|
||||
protected $afterUpdate = [];
|
||||
protected $beforeFind = [];
|
||||
protected $afterFind = [];
|
||||
protected $beforeDelete = [];
|
||||
protected $afterDelete = [];
|
||||
|
||||
protected function checkAndADDCreatedByValue(array $data)
|
||||
{
|
||||
// Check if 'updated_by' value is null or empty
|
||||
if (empty($data['data']['created_by'])) {
|
||||
// Set 'updated_by' value to the current session user ID
|
||||
$data['data']['created_by'] = get_session_userid();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function checkAndUpdateUpdatedByValue(array $data)
|
||||
{
|
||||
// Check if 'updated_by' value is null or empty
|
||||
if (empty($data['data']['updated_by'])) {
|
||||
// Set 'updated_by' value to the current session user ID
|
||||
$data['data']['updated_by'] = get_session_userid();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user