FEAT_ENROLLMENT_WINDOW_OPEN_CLOSE_DATE_CAPTURE

This commit is contained in:
VENKATESHWARAN 2025-12-22 18:27:31 +05:30
parent d978f45747
commit 35f096cf55
9 changed files with 209 additions and 35 deletions

View File

@ -279,10 +279,15 @@ class EmployeeController extends AdminController
$client_id = $this->request->getPost('client_id'); $client_id = $this->request->getPost('client_id');
$policy_id = $this->request->getPost('policy_id'); $policy_id = $this->request->getPost('policy_id');
$branch_id = $this->request->getPost('branch_id'); $branch_id = $this->request->getPost('branch_id');
$enrollment_open_date = $this->request->getPost('enrollment_open_date');
$enrollment_close_date = $this->request->getPost('enrollment_close_date');
$action = $this->request->getPost('upload-action-type'); $action = $this->request->getPost('upload-action-type');
$status = 'inprogress'; $status = 'inprogress';
$file_id = $this->fileModel->insert(['file_name' => $filename, 'client_id' => $client_id, 'policy_id' => $policy_id, 'created_by' => $loggedInUserID, 'status' => $status, 'action' => $action, 'client_branch_id' => $branch_id,'uploaded_by' => 1]); //here field policy_id have client_policy_id and not policy id from policy master $enrollment_open_date = change_date_format($enrollment_open_date, 'd/m/Y', 'Y-m-d');
$enrollment_close_date = change_date_format($enrollment_close_date, 'd/m/Y', 'Y-m-d');
$file_id = $this->fileModel->insert(['file_name' => $filename, 'client_id' => $client_id, 'policy_id' => $policy_id, 'created_by' => $loggedInUserID, 'status' => $status, 'action' => $action, 'client_branch_id' => $branch_id,'uploaded_by' => 1, 'enrollment_open_date' => $enrollment_open_date, 'enrollment_close_date' => $enrollment_close_date]); //here field policy_id have client_policy_id and not policy id from policy master
$this->myLogger->logme("error", '{file_id} uploaded success', ['file_id' => $file_id]); $this->myLogger->logme("error", '{file_id} uploaded success', ['file_id' => $file_id]);
//start validation process //start validation process
@ -328,7 +333,7 @@ class EmployeeController extends AdminController
$data['fileList'] = $this->fileModel $data['fileList'] = $this->fileModel
->select([ ->select([
'files.id','files.file_name','files.created_by','files.created_at','files.is_active','files.status','files.client_id','files.policy_id','files.client_branch_id','files.action','files.uploaded_by', 'files.id','files.file_name','files.created_by','files.created_at','files.is_active','files.status','files.client_id','files.policy_id','files.client_branch_id','files.action','files.uploaded_by', 'enrollment_open_date', 'enrollment_close_date',
'up.emp_code', 'up.emp_code',
'up.first_name', 'up.first_name',
'c.short_name', 'c.short_name',

View File

@ -236,7 +236,7 @@ class EmployeeRestController extends AdminController
$data = $this->request->getJSON(); $data = $this->request->getJSON();
//enrolment check //enrolment check
$openForEnrollment = $this->findThePolicyIsOpenForEnrollment($data[0]->client_policy_id); $openForEnrollment = $this->findThePolicyIsOpenForEnrollment($data[0]->client_policy_id, $data[0]->emp_code);
if($openForEnrollment == false){ if($openForEnrollment == false){
return $this->respond(['status' => 'failed','code' => 404,'data' => [],'message' => 'Enrollment closed.'], 200); return $this->respond(['status' => 'failed','code' => 404,'data' => [],'message' => 'Enrollment closed.'], 200);
} }
@ -573,7 +573,7 @@ class EmployeeRestController extends AdminController
// print_r($requestData); // print_r($requestData);
// dd($requestData); // dd($requestData);
$openForEnrollment = $this->findThePolicyIsOpenForEnrollment($requestData[0]->client_policy_id); $openForEnrollment = $this->findThePolicyIsOpenForEnrollment($requestData[0]->client_policy_id, $requestData[0]->emp_code);
if($openForEnrollment == false){ return $this->respond(['status' => 'failed','code' => 404,'data' => 'Enrollment closed'], 404); } if($openForEnrollment == false){ return $this->respond(['status' => 'failed','code' => 404,'data' => 'Enrollment closed'], 404); }
foreach ($requestData as $key => $value) foreach ($requestData as $key => $value)
@ -1455,16 +1455,47 @@ class EmployeeRestController extends AdminController
$array->family_floaters_of_dependent_and_gst_value = 0; $array->family_floaters_of_dependent_and_gst_value = 0;
} }
$checkGmcParentsPolicyExist = $this->clientPolicyModel->select('client_policy.id as ClientPolicyId , client_policy.client_id as ClientId, client_policy.policy_type_id as policy_type_id, policy_type.long_name as Policy_Name , client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type , client_policy.policy_terms as Policy_Terms , client_policy.is_premium_summery as is_premium_summery, client_policy.enrolment_visibility') $checkGmcParentsPolicyExist = $this->clientPolicyModel->select("
->join('policy_type', 'client_policy.policy_type_id = policy_type.id', 'left') client_policy.id as ClientPolicyId,
->where('client_policy.policy_type_id', 3 ) client_policy.client_id as ClientId,
->where('client_policy.is_addon', 1 ) client_policy.policy_type_id as policy_type_id,
->where('client_policy.client_id', $this->request->getGet('client_id') ) policy_type.long_name as Policy_Name ,
->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') ) client_policy.is_addon as is_addon ,
->where('client_policy.is_active', 1 ) (
->where('client_policy.enrolment_visibility', 1 ) SELECT COALESCE(
->get() MAX(
->getResult(); CASE
WHEN ep.enrollment_open_date <= CURDATE()
AND ep.enrollment_close_date >= CURDATE()
THEN 1
ELSE 0
END
), 0
)
FROM employee_polices ep
INNER JOIN employees e ON e.id = ep.employee_id
WHERE e.is_active = 1
AND ep.is_active = 1
AND ep.enrollment_open_date IS NOT NULL
AND ep.enrollment_close_date IS NOT NULL
AND e.emp_code = {$emp_code}
AND ep.client_policy_id = client_policy.id
) AS OpenForEnrollment,
-- client_policy.open_for_enrollment as OpenForEnrollment,
client_policy.inception_type as inception_type ,
client_policy.policy_terms as Policy_Terms ,
client_policy.is_premium_summery as is_premium_summery,
client_policy.enrolment_visibility
")
->join('policy_type', 'client_policy.policy_type_id = policy_type.id', 'left')
->where('client_policy.policy_type_id', 3 )
->where('client_policy.is_addon', 1 )
->where('client_policy.client_id', $this->request->getGet('client_id') )
->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') )
->where('client_policy.is_active', 1 )
->where('client_policy.enrolment_visibility', 1 )
->get()
->getResult();
if($checkGmcParentsPolicyExist) if($checkGmcParentsPolicyExist)
{ {
$GmcParrentsData = $this->getGmcParrentsPolicy($checkGmcParentsPolicyExist,$emp_code,$client_id,$client_branch_id); $GmcParrentsData = $this->getGmcParrentsPolicy($checkGmcParentsPolicyExist,$emp_code,$client_id,$client_branch_id);
@ -1746,7 +1777,37 @@ class EmployeeRestController extends AdminController
public function getAdditionalGPAPolicy($empData,$policy_type,$emp_code,$client_id,$client_branch_id,$login_by_hr) public function getAdditionalGPAPolicy($empData,$policy_type,$emp_code,$client_id,$client_branch_id,$login_by_hr)
{ {
$checkPolicyExist = $this->clientPolicyModel->select('client_policy.id as ClientPolicyId , client_policy.client_id as ClientId, client_policy.policy_type_id as policy_type_id, client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type , client_policy.policy_terms as Policy_Terms , client_policy.enrolment_visibility,client_policy.is_premium_summery') $checkPolicyExist = $this->clientPolicyModel->select("
client_policy.id as ClientPolicyId ,
client_policy.client_id as ClientId,
client_policy.policy_type_id as policy_type_id,
client_policy.is_addon as is_addon ,
(
SELECT COALESCE(
MAX(
CASE
WHEN ep.enrollment_open_date <= CURDATE()
AND ep.enrollment_close_date >= CURDATE()
THEN 1
ELSE 0
END
), 0
)
FROM employee_polices ep
INNER JOIN employees e ON e.id = ep.employee_id
WHERE e.is_active = 1
AND ep.is_active = 1
AND ep.enrollment_open_date IS NOT NULL
AND ep.enrollment_close_date IS NOT NULL
AND e.emp_code = {$emp_code}
AND ep.client_policy_id = client_policy.id
) AS OpenForEnrollment,
-- client_policy.open_for_enrollment as OpenForEnrollment ,
client_policy.inception_type as inception_type ,
client_policy.policy_terms as Policy_Terms ,
client_policy.enrolment_visibility,
client_policy.is_premium_summery
")
->where('client_policy.policy_type_id', $policy_type ) ->where('client_policy.policy_type_id', $policy_type )
->where('client_policy.is_addon', 1 ) ->where('client_policy.is_addon', 1 )
->where('client_policy.client_id', $client_id ) ->where('client_policy.client_id', $client_id )
@ -2062,6 +2123,7 @@ class EmployeeRestController extends AdminController
{ {
try { try {
$emp_code = $this->request->getGet('emp_code');
$addOnEmployeeData = $this->employeeModel->where('is_active', 1 ) $addOnEmployeeData = $this->employeeModel->where('is_active', 1 )
->where('emp_code',$this->request->getGet('emp_code')) ->where('emp_code',$this->request->getGet('emp_code'))
->where('client_id',$this->request->getGet('client_id')) ->where('client_id',$this->request->getGet('client_id'))
@ -2070,7 +2132,30 @@ class EmployeeRestController extends AdminController
$clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id')) $clientPolicy = $this->clientPolicyModel->select("
client_policy.*,
(
SELECT COALESCE(
MAX(
CASE
WHEN ep.enrollment_open_date <= CURDATE()
AND ep.enrollment_close_date >= CURDATE()
THEN 1
ELSE 0
END
), 0
)
FROM employee_polices ep
INNER JOIN employees e ON e.id = ep.employee_id
WHERE e.is_active = 1
AND ep.is_active = 1
AND ep.enrollment_open_date IS NOT NULL
AND ep.enrollment_close_date IS NOT NULL
AND e.emp_code = {$emp_code}
AND ep.client_policy_id = client_policy.id
) AS open_for_enrollment
")
->where('client_id',$this->request->getGet('client_id'))
->where('client_branch_id',$this->request->getGet('client_branch_id')) ->where('client_branch_id',$this->request->getGet('client_branch_id'))
->where('policy_status', 1) ->where('policy_status', 1)
->where('is_active', 1) ->where('is_active', 1)
@ -2079,6 +2164,7 @@ class EmployeeRestController extends AdminController
if(count($clientPolicy)) if(count($clientPolicy))
{ {
$self = $this->employeeModel->where('employees.is_active', 1) $self = $this->employeeModel->where('employees.is_active', 1)
->where('employees.emp_code', $this->request->getGet('emp_code')) ->where('employees.emp_code', $this->request->getGet('emp_code'))
->where('employees.client_id', $this->request->getGet('client_id')) ->where('employees.client_id', $this->request->getGet('client_id'))
@ -3632,15 +3718,25 @@ class EmployeeRestController extends AdminController
} }
public function findThePolicyIsOpenForEnrollment($plicy_id) public function findThePolicyIsOpenForEnrollment($plicy_id, $emp_code)
{ {
$policy = $this->clientPolicyModel->where('id',$plicy_id)->where('open_for_enrollment',1)->find(); // $policy = $this->clientPolicyModel->where('id',$plicy_id)->where('open_for_enrollment',1)->find();
$policy = $this->employeePolicyModel
->join('employees', 'employee_polices.employee_id = employees.id')
->where('employees.emp_code',$emp_code)
->where('employees.family_floater_key','self')
->where('employee_polices.client_policy_id',$plicy_id)
->where('employee_polices.enrollment_open_date <= CURDATE()', null, false)
->where('employee_polices.enrollment_close_date >= CURDATE()', null, false)
->where('employees.is_active', 1)
->where('employee_polices.is_active', 1)
->find();
if($policy) if($policy)
return true; return true;
else else
return false; return false;
} }
@ -3782,7 +3878,9 @@ class EmployeeRestController extends AdminController
->where('employees.is_active', 1) ->where('employees.is_active', 1)
->where('employee_polices.is_active', 1) ->where('employee_polices.is_active', 1)
->where('cp.enrolment_visibility', 1) ->where('cp.enrolment_visibility', 1)
->where('cp.open_for_enrollment', 1) // ->where('cp.open_for_enrollment', 1)
->where('employee_polices.enrollment_open_date <= CURDATE()', null, false)
->where('employee_polices.enrollment_close_date >= CURDATE()', null, false)
->where('cp.policy_status', 1) ->where('cp.policy_status', 1)
->whereIn('cp.policy_type_id', [1, 2, 3, 6, 7]) ->whereIn('cp.policy_type_id', [1, 2, 3, 6, 7])
->orderBy('employees.created_at', 'desc') ->orderBy('employees.created_at', 'desc')
@ -3834,7 +3932,9 @@ class EmployeeRestController extends AdminController
->where('employees.is_active', 1) ->where('employees.is_active', 1)
->where('employee_polices.is_active', 1) ->where('employee_polices.is_active', 1)
->where('cp.enrolment_visibility', 1) ->where('cp.enrolment_visibility', 1)
->where('cp.open_for_enrollment', 1) // ->where('cp.open_for_enrollment', 1)
->where('employee_polices.enrollment_open_date <= CURDATE()', null, false)
->where('employee_polices.enrollment_close_date >= CURDATE()', null, false)
->where('cp.policy_status', 1) ->where('cp.policy_status', 1)
->whereIn('cp.policy_type_id', [1, 2, 3, 6, 7]) ->whereIn('cp.policy_type_id', [1, 2, 3, 6, 7])
->orderBy('employees.created_at', 'desc'); ->orderBy('employees.created_at', 'desc');

View File

@ -2085,6 +2085,9 @@ public function getFileMetaDataByFileId($file_id, $status = 'success'){
$policy_data['basic_cover_si'] = $row[9]; $policy_data['basic_cover_si'] = $row[9];
$policy_data['date_coverage'] = $row[13] != "" && $row[13] != null ? change_date_format($row[13],'d-M-Y','Y-m-d') : null; $policy_data['date_coverage'] = $row[13] != "" && $row[13] != null ? change_date_format($row[13],'d-M-Y','Y-m-d') : null;
$policy_data['client_policy_id'] = $file['policy_id']; $policy_data['client_policy_id'] = $file['policy_id'];
$policy_data['enrollment_open_date'] = $file['enrollment_open_date'] ?? null;
$policy_data['enrollment_close_date'] = $file['enrollment_close_date'] ?? null;
$employee = $this->employeeModel->checkExistingEmployee($value,$file['client_branch_id']); $employee = $this->employeeModel->checkExistingEmployee($value,$file['client_branch_id']);
unset($value['temp']); unset($value['temp']);

View File

@ -556,7 +556,9 @@ if (!function_exists('change_date_format')) {
if ($source_format !== null && $output_format !== null) { if ($source_format !== null && $output_format !== null) {
$date = DateTime::createFromFormat($source_format, $date_str); $date = DateTime::createFromFormat($source_format, $date_str);
if (!$date) { if (!$date) {
throw new Exception("Invalid date string for source format: $source_format"); // throw new Exception("Invalid date string for source format: $source_format");
log_message('error', "❌ Date format error : Invalid date string | Params => date_str: {$date_str}, source_format: {$source_format}, output_format: {$output_format}");
return null;
} }
return $date->format($output_format); return $date->format($output_format);
} }
@ -565,7 +567,9 @@ if (!function_exists('change_date_format')) {
if ($source_format !== null && $output_format === null) { if ($source_format !== null && $output_format === null) {
$date = DateTime::createFromFormat($source_format, $date_str); $date = DateTime::createFromFormat($source_format, $date_str);
if (!$date) { if (!$date) {
throw new Exception("Invalid date string for source format: $source_format"); // throw new Exception("Invalid date string for source format: $source_format");
log_message('error', "❌ Date format error : Invalid date string | Params => date_str: {$date_str}, source_format: {$source_format}, output_format: {$output_format}");
return null;
} }
return $date->format('Y-m-d'); // MySQL default format return $date->format('Y-m-d'); // MySQL default format
} }
@ -580,10 +584,17 @@ if (!function_exists('change_date_format')) {
} }
// If no format matches, throw an exception // If no format matches, throw an exception
$allowed_placeholders = implode(', ', $allowed_formats); $allowed_placeholders = implode(', ', $allowed_formats);
throw new Exception("Invalid date string format. Allowed formats: $allowed_placeholders"); // throw new Exception("Invalid date string format. Allowed formats: $allowed_placeholders");
log_message(
'error',
"❌ Date format error: Invalid date string. Allowed formats: {$allowed_placeholders} | Params => date_str: {$date_str}, source_format: {$source_format}, output_format: {$output_format}"
);
return null;
} }
} catch (Exception $e) { } catch (Exception $e) {
return "Error: " . $e->getMessage(); // return "Error: " . $e->getMessage();
log_message('error', "❌ Date format error: {$e->getMessage()} | Params => date_str: {$date_str}, source_format: {$source_format}, output_format: {$output_format}");
return null;
} }
return null; return null;

View File

@ -159,10 +159,12 @@ class EmployeeModel extends Model
client_policy.policy_id as PolicyId, client_policy.policy_id as PolicyId,
client_policy.id as ClientPolicyId, client_policy.id as ClientPolicyId,
client_policy.is_premium_summery, client_policy.is_premium_summery,
CASE CASE
WHEN client_policy.open_for_enrollment IS NULL THEN 0 WHEN employee_polices.enrollment_open_date <= CURDATE()
ELSE client_policy.open_for_enrollment AND employee_polices.enrollment_close_date >= CURDATE()
END AS OpenForEnrollment, THEN 1
ELSE 0
END AS OpenForEnrollment
client_policy.disclaimer, client_policy.disclaimer,
client_policy.policy_type_id , client_policy.policy_type_id ,
employee_polices.tpa_id as tpa_id , employee_polices.tpa_id as tpa_id ,

View File

@ -35,7 +35,9 @@ class EmployeePolicyModel extends Model
"claim_status", "claim_status",
'ecard_sent_status', 'ecard_sent_status',
'payable_employee', 'payable_employee',
'file_id' 'file_id',
"enrollment_open_date",
"enrollment_close_date",
]; ];
// Callbacks // Callbacks

View File

@ -20,7 +20,9 @@ class FileModel extends Model
"policy_id", "policy_id",
"client_branch_id", "client_branch_id",
"uploaded_by", "uploaded_by",
"updated_by" "updated_by",
"enrollment_open_date",
"enrollment_close_date",
]; ];

View File

@ -71,6 +71,16 @@ option:disabled {
?> ?>
</select> </select>
</div> </div>
<div class="form-group col-md-4">
<label for="open_date">Enrollment Open Date<span class="text-danger">*</span></label>
<input value="" type="text" class="form-control" placeholder="Enter Open Date " name="enrollment_open_date" id="enrollment_open_date" required>
</div>
<div class="form-group col-md-4">
<label for="close_date">Enrollment Close Date<span class="text-danger">*</span></label>
<input value="" type="text" class="form-control" placeholder="Enter Close Date " name="enrollment_close_date" id="enrollment_close_date" required>
</div>
</div> </div>
<hr> <hr>
@ -180,6 +190,26 @@ $(document).ready(function() {
$("#policy_id").select2(); $("#policy_id").select2();
$("#branch_id").select2(); $("#branch_id").select2();
var enrollment_open_date = flatpickr("#enrollment_open_date", {
dateFormat: "d/m/Y",
allowInput: false,
minDate: "today",
onChange: function (selectedDates) {
if (selectedDates.length) {
enrollment_close_date.setDate(
new Date(selectedDates[0].getTime() + 15 * 24 * 60 * 60 * 1000),
true
);
}
}
});
var enrollment_close_date = flatpickr("#enrollment_close_date", {
dateFormat: "d/m/Y",
allowInput: false,
minDate: "today"
});
}); });
// Declare a global variable to store API response data // Declare a global variable to store API response data

View File

@ -44,8 +44,27 @@
// echo $reason; // echo $reason;
?> ?>
<tr> <td class="reload truncate"
<td><b><?php echo ($key + 1) ?></b></td> data-toggle="tooltip"
data-placement="top"
data-html="true"
title="<?php
echo 'Enrollment Open Date : ' .
(!empty($file['enrollment_open_date'])
? change_date_format($file['enrollment_open_date'], 'Y-m-d', 'd/m/Y')
: 'N/A'
) .
'<br>' .
'Enrollment Close Date : ' .
(!empty($file['enrollment_close_date'])
? change_date_format($file['enrollment_close_date'], 'Y-m-d', 'd/m/Y')
: 'N/A'
);
?>">
<b>
<?php echo ($key + 1) ?>
</b></td>
<td style="overflow: hidden;" class="reload truncate" data-toggle="tooltip" data-placement="top" title="<?php echo $file['file_name'] ?>"> <td style="overflow: hidden;" class="reload truncate" data-toggle="tooltip" data-placement="top" title="<?php echo $file['file_name'] ?>">
<?php echo $file['file_name']?> <?php echo $file['file_name']?>
</td> </td>