MERGE_TEST_BUG_FIXES
This commit is contained in:
commit
50d17c837c
@ -10049,6 +10049,7 @@ class ClientController extends AdminController
|
||||
$member_common_mail_template = $this->notificationModel->where('client_id', NULL)->where('template_name', 'member_common_mail')->get()->getResultArray()[0] ?? [];
|
||||
|
||||
$hr_cd_insufficient_balance_mail_template = $this->notificationModel->where('client_id', NULL)->where('template_name', 'hr_cd_insufficient_balance_mail')->get()->getResultArray()[0] ?? [];
|
||||
$dependent_rejection_mail_template = $this->notificationModel->where('client_id', NULL)->where('template_name', 'dependent_rejection_mail')->get()->getResultArray()[0] ?? [];
|
||||
|
||||
$default_member_welcome_mail_template = [
|
||||
'client_id' => $client_id,
|
||||
@ -10134,6 +10135,19 @@ class ClientController extends AdminController
|
||||
'mail_content_copy' => null
|
||||
];
|
||||
|
||||
$default_dependent_rejection_mail_template = [
|
||||
'client_id' => $client_id,
|
||||
'template_name' => 'dependent_rejection_mail',
|
||||
'subject' => $dependent_rejection_mail_template['subject'] ?? 'Dependent Rejected - {{client_name}}',
|
||||
'mail_content' => $dependent_rejection_mail_template['mail_content'] ?? '<p>Dear {{employee_name}},</p><p>The dependent below has been rejected.</p><table border="1" cellpadding="6" cellspacing="0" style="border-collapse: collapse;"><tr><td><strong>Client</strong></td><td>{{client_name}}</td></tr><tr><td><strong>Branch</strong></td><td>{{branch_name}}</td></tr><tr><td><strong>Policy</strong></td><td>{{policy_no}}</td></tr><tr><td><strong>Employee</strong></td><td>{{employee_name}}</td></tr><tr><td><strong>Employee Code</strong></td><td>{{employee_code}}</td></tr><tr><td><strong>Dependent Name</strong></td><td>{{dependent_name}}</td></tr><tr><td><strong>Relationship</strong></td><td>{{relationship}}</td></tr><tr><td><strong>Date of Birth</strong></td><td>{{dob}}</td></tr><tr><td><strong>Effective Date</strong></td><td>{{effective_date}}</td></tr><tr><td><strong>Reject Reason</strong></td><td>{{reject_reason}}</td></tr><tr><td><strong>Processed By</strong></td><td>{{processed_by}}</td></tr></table><p>Best regards,<br>Nhance Team</p><p><small>This is an auto-generated email. Please do not reply.</small></p>',
|
||||
'mail_content_json' => $dependent_rejection_mail_template['mail_content_json'] ?? '',
|
||||
'created_by' => get_session_userid(),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_by' => null,
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
'mail_content_copy' => null
|
||||
];
|
||||
|
||||
$this->myLogger->logme('error', 'Default Mail Template Data ' . json_encode([
|
||||
$default_member_welcome_mail_template,
|
||||
$default_member_remainder_mail_template,
|
||||
@ -10149,6 +10163,7 @@ class ClientController extends AdminController
|
||||
$default_member_ecard_mail_template,
|
||||
$default_member_common_mail_template,
|
||||
$hr_cd_insufficient_balance_mail_template,
|
||||
$default_dependent_rejection_mail_template,
|
||||
]);
|
||||
|
||||
|
||||
|
||||
@ -354,12 +354,21 @@ class EmployeeRestController extends AdminController
|
||||
|
||||
if ($checkDataExist) {
|
||||
|
||||
$data = [
|
||||
'basic_cover_si' => $basic_cover_si,
|
||||
'updated_by' => $self_data['id'] ?? null,
|
||||
];
|
||||
|
||||
if (!empty($dependent_effective_date)) {
|
||||
$data['date_coverage'] = $this->convertDateFormatYMD($dependent_effective_date);
|
||||
}
|
||||
|
||||
$this->employeePolicyModel
|
||||
->where('client_policy_id', $client_policy_id)
|
||||
->where('employee_id', $employee_id)
|
||||
->where('is_active', 1)
|
||||
->set(['basic_cover_si' => $basic_cover_si, 'updated_by' => $self_data['id'] ?? null])
|
||||
->update();
|
||||
->set($data)->update();
|
||||
|
||||
} else {
|
||||
|
||||
$data['employee_id'] = $employee_id;
|
||||
@ -6311,7 +6320,7 @@ class EmployeeRestController extends AdminController
|
||||
|
||||
$downloadUrl = base_url('claim-form-download/' . md5((string) $clientPolicy['insurer_id']));
|
||||
|
||||
log_message('info', '[getInsurerClaimFormDownloadUrl] Success | ' . json_encode([
|
||||
log_message('error', '[getInsurerClaimFormDownloadUrl] Success | ' . json_encode([
|
||||
'client_policy_id' => (int) $clientPolicyId,
|
||||
'insurer_id' => (int) $clientPolicy['insurer_id'],
|
||||
'file_source' => $claimFormAvailability['source'],
|
||||
@ -6422,7 +6431,7 @@ class EmployeeRestController extends AdminController
|
||||
if ($Count > 0) {
|
||||
|
||||
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, null, ['dependent_effective_date' => $data[0]->dependent_effective_date, 'hr_id' => $data[0]->hr_id ?? null]);
|
||||
} 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, ['dependent_effective_date' => $data[0]->dependent_effective_date, 'hr_id' => $data[0]->hr_id ?? null]);
|
||||
@ -6523,7 +6532,7 @@ class EmployeeRestController extends AdminController
|
||||
})));
|
||||
|
||||
if (empty($recipientEmails)) {
|
||||
log_message('info', '[DependentAddMail] No recipient emails found for client_id=' . $clientId . ', branch_id=' . $branchId);
|
||||
log_message('error', '[DependentAddMail] No recipient emails found for client_id=' . $clientId . ', branch_id=' . $branchId);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -6570,14 +6579,112 @@ class EmployeeRestController extends AdminController
|
||||
];
|
||||
|
||||
$mailResult = MailHelper::send_email($mailPayload);
|
||||
$this->myLogger->logme('info', '[DependentAddMail] mail_result=' . json_encode($mailResult));
|
||||
|
||||
$this->myLogger->logme('error', '[DependentAddMail] mail_result=' . json_encode($mailResult));
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
log_message('error', '[DependentAddMail] ' . $th->getMessage() . ' in ' . $th->getFile() . ':' . $th->getLine());
|
||||
$this->myLogger->logme('error', '[DependentAddMail] ' . $th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send dependent rejection notification mail using client notification template
|
||||
* only when the template is enabled for that client.
|
||||
*/
|
||||
private function sendDependentRejectedNotificationMail(array $employee, array $employeePolicy, string $rejectReason, string $processedByRole): void
|
||||
{
|
||||
try {
|
||||
$clientId = (int) ($employee['client_id'] ?? 0);
|
||||
$branchId = (int) ($employee['client_branch_id'] ?? 0);
|
||||
$clientPolicyId = (int) ($employeePolicy['client_policy_id'] ?? 0);
|
||||
$empCode = (string) ($employee['emp_code'] ?? '');
|
||||
$dependentName = (string) ($employee['name'] ?? '');
|
||||
|
||||
if ($clientId <= 0 || $branchId <= 0 || $clientPolicyId <= 0) {
|
||||
log_message('error', '[DependentRejectMail] Skipped - invalid IDs | client_id=' . $clientId . ', branch_id=' . $branchId . ', client_policy_id=' . $clientPolicyId . ', emp_code=' . $empCode);
|
||||
return;
|
||||
}
|
||||
|
||||
$notificationData = $this->notificationModel
|
||||
->where('client_id', $clientId)
|
||||
->where('template_name', 'dependent_rejection_mail')
|
||||
->where('enabled', 1)
|
||||
->first();
|
||||
|
||||
if (empty($notificationData) || empty($notificationData['subject']) || empty($notificationData['mail_content'])) {
|
||||
log_message('error', '[DependentRejectMail] Skipped - template disabled or missing | client_id=' . $clientId . ', emp_code=' . $empCode . ', dependent=' . $dependentName);
|
||||
return;
|
||||
}
|
||||
|
||||
$clientData = $this->clientModel
|
||||
->select('client_name, common_mails')
|
||||
->where('id', $clientId)
|
||||
->first();
|
||||
|
||||
$branchData = $this->clientBranchModel
|
||||
->select('branch_name')
|
||||
->where('id', $branchId)
|
||||
->first();
|
||||
|
||||
$policyData = $this->clientPolicyModel
|
||||
->select('policy_no')
|
||||
->where('id', $clientPolicyId)
|
||||
->first();
|
||||
|
||||
$selfEmployee = $this->employeeModel
|
||||
->select('name, email_corporate, email_personal')
|
||||
->where('client_id', $clientId)
|
||||
->where('emp_code', (string) ($employee['emp_code'] ?? ''))
|
||||
->where('relationship', 'Self')
|
||||
->where('is_active', 1)
|
||||
->first();
|
||||
|
||||
$selfEmployeeEmail = trim((string) ($selfEmployee['email_corporate'] ?? $selfEmployee['email_personal'] ?? ''));
|
||||
if (! filter_var($selfEmployeeEmail, FILTER_VALIDATE_EMAIL)) {
|
||||
log_message('error', '[DependentRejectMail] Skipped - invalid self employee email | client_id=' . $clientId . ', emp_code=' . $empCode . ', dependent=' . $dependentName);
|
||||
return;
|
||||
}
|
||||
|
||||
$clientCommonMails = trim((string) ($clientData['common_mails'] ?? ''));
|
||||
|
||||
$placeholders = [
|
||||
'{{client_name}}' => (string) ($clientData['client_name'] ?? ''),
|
||||
'{{branch_name}}' => (string) ($branchData['branch_name'] ?? ''),
|
||||
'{{policy_no}}' => (string) ($policyData['policy_no'] ?? ''),
|
||||
'{{employee_name}}' => (string) ($selfEmployee['name'] ?? ''),
|
||||
'{{employee_code}}' => (string) ($employee['emp_code'] ?? ''),
|
||||
'{{dependent_name}}'=> (string) ($employee['name'] ?? ''),
|
||||
'{{relationship}}' => (string) ($employee['relationship'] ?? ''),
|
||||
'{{dob}}' => ! empty($employee['dob']) ? date('d/m/Y', strtotime((string) $employee['dob'])) : '-',
|
||||
'{{effective_date}}'=> ! empty($employeePolicy['date_coverage']) ? date('d/m/Y', strtotime((string) $employeePolicy['date_coverage'])) : '-',
|
||||
'{{reject_reason}}' => $rejectReason !== '' ? $rejectReason : '-',
|
||||
'{{processed_by}}' => $processedByRole,
|
||||
];
|
||||
|
||||
$subject = (string) $notificationData['subject'];
|
||||
$mailContent = (string) $notificationData['mail_content'];
|
||||
foreach ($placeholders as $key => $value) {
|
||||
$subject = str_ireplace($key, $value, $subject);
|
||||
$mailContent = str_ireplace($key, $value, $mailContent);
|
||||
}
|
||||
|
||||
log_message('error', '[DependentRejectMail] Sending mail | client_id=' . $clientId . ', emp_code=' . $empCode . ', dependent=' . $dependentName . ', to=' . $selfEmployeeEmail . ', bcc=' . ($clientCommonMails !== '' ? $clientCommonMails : '-'));
|
||||
|
||||
$mailResult = MailHelper::send_email([
|
||||
'mail' => $selfEmployeeEmail,
|
||||
'subject' => $subject,
|
||||
'message' => $mailContent,
|
||||
'bcc' => $clientCommonMails,
|
||||
]);
|
||||
|
||||
log_message('error', '[DependentRejectMail] mail_result=' . json_encode($mailResult));
|
||||
$this->myLogger->logme('error', '[DependentRejectMail] mail_result=' . json_encode($mailResult));
|
||||
} catch (\Throwable $th) {
|
||||
log_message('error', '[DependentRejectMail] ' . $th->getMessage() . ' in ' . $th->getFile() . ':' . $th->getLine());
|
||||
$this->myLogger->logme('error', '[DependentRejectMail] ' . $th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteDependencev2()
|
||||
{
|
||||
try {
|
||||
@ -7002,6 +7109,15 @@ class EmployeeRestController extends AdminController
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => 'Failed to update employee policy status'], 200);
|
||||
}
|
||||
|
||||
if ($status === 'rejected') {
|
||||
$this->sendDependentRejectedNotificationMail(
|
||||
employee: $employee,
|
||||
employeePolicy: $employee_policy,
|
||||
rejectReason: $reject_reason,
|
||||
processedByRole: $processed_by_role
|
||||
);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
|
||||
@ -96,6 +96,7 @@ class NotificationController extends AdminController
|
||||
'account_maneger_summary_mail_btn',
|
||||
'client_hr_summary_mail_btn',
|
||||
'hr_cd_insufficient_balance_mail_btn',
|
||||
'dependent_rejection_mail_btn',
|
||||
];
|
||||
$data = [];
|
||||
$emptyTemplate = [];
|
||||
|
||||
@ -132,6 +132,7 @@
|
||||
$account_maneger_summary_mail = 0;
|
||||
$client_hr_summary_mail = 0;
|
||||
$hr_cd_insufficient_balance_mail = 0;
|
||||
$dependent_rejection_mail = 0;
|
||||
|
||||
if (isset($notification)) {
|
||||
foreach ($notification as $value) {
|
||||
@ -167,6 +168,9 @@
|
||||
if ($value['template_name'] == 'hr_cd_insufficient_balance_mail') {
|
||||
$hr_cd_insufficient_balance_mail = $value['enabled'];
|
||||
}
|
||||
if ($value['template_name'] == 'dependent_rejection_mail') {
|
||||
$dependent_rejection_mail = $value['enabled'];
|
||||
}
|
||||
}
|
||||
}
|
||||
?></p>
|
||||
@ -349,6 +353,23 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-6 mail-row">
|
||||
<div class="mail-section">
|
||||
<div class="left">
|
||||
<label class="switch">
|
||||
<input id="dependent_rejection_mail_btn" type="checkbox" name="dependent_rejection_mail_btn" <?= $dependent_rejection_mail == 1 ? 'checked' : '' ?>>
|
||||
<span class="slider round"></span>
|
||||
</label>
|
||||
<span class="ml-2">Dependent Rejection Mail</span>
|
||||
</div>
|
||||
<div class="right">
|
||||
<a href="" data-toggle="modal" id="dependent_rejection_mail" onclick="getMailTemplateData(this)" data-target="#dependent_rejection_mail_modal">
|
||||
<i class="mdi mdi-pencil"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
@ -1016,6 +1037,92 @@
|
||||
</div> <!-- /.modal-dialog -->
|
||||
</div> <!-- /.modal -->
|
||||
|
||||
<!-- Modal content => Dependent Rejection mail -->
|
||||
<div class="modal fade" id="dependent_rejection_mail_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"
|
||||
aria-hidden="true" aria-modal="true" data-backdrop="static">
|
||||
<div class="modal-dialog modal-full-width">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" id="myLargeModalLabel">Dependent Rejection Mail <span id="nameOfThePolicy"></span></h4>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="text-center" id="no_data"></div>
|
||||
|
||||
<form role="form" class="parsley-examples" method="post" id="dependent_rejection_mail_form" enctype="multipart/form-data">
|
||||
<div class="form-group">
|
||||
|
||||
<div class="form-row" id="rac_rate_dropdown">
|
||||
<div class="form-group col-md-2">
|
||||
<label for="template_name">Template Name</label>
|
||||
</div>
|
||||
<div class="form-group col-md-5">
|
||||
<input type="text" id="template_name" name="template_name" value="Dependent Rejection Mail" readonly class="form-control" placeholder="Template Name">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row" id="rac_rate_dropdown">
|
||||
<div class="form-group col-md-2">
|
||||
<label for="subject">Subject</label>
|
||||
</div>
|
||||
<div class="form-group col-md-5">
|
||||
<input type="text" id="subject" name="subject" class="form-control" placeholder="Subject">
|
||||
</div>
|
||||
<div class="form-group col-md-5 testmail" style="display: none;">
|
||||
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="testMailSend(this,'send')">Test Mail</a>
|
||||
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="PreviewTheMail(this,'preview','dependent_rejection_mail')">Preview Mail</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dependent_rejection_mail_section">
|
||||
<div class="form-row" id="rac_rate_dropdown">
|
||||
<div class="form-group col-md-12">
|
||||
<select id="dependent_rejection_mail_customButton" class="form-control" style="border:none; right:6px; width:auto; position:absolute; z-index:1; top:17px; height:32px; float:right;" onchange="copyToClipboard(this)">
|
||||
<option value="">PlaceHolders</option>
|
||||
<option value="{{client_name}}">Client Name</option>
|
||||
<option value="{{branch_name}}">Branch Name</option>
|
||||
<option value="{{policy_no}}">Policy No</option>
|
||||
<option value="{{employee_name}}">Employee Name</option>
|
||||
<option value="{{employee_code}}">Employee Code</option>
|
||||
<option value="{{dependent_name}}">Dependent Name</option>
|
||||
<option value="{{relationship}}">Relationship</option>
|
||||
<option value="{{dob}}">DOB</option>
|
||||
<option value="{{effective_date}}">Effective Date</option>
|
||||
<option value="{{reject_reason}}">Reject Reason</option>
|
||||
<option value="{{processed_by}}">Processed By</option>
|
||||
</select>
|
||||
<span id="copy-feedback" style="display: none; position: absolute; top:50px; right:10px; color:green; font-size:12px;">Copied to clipboard!</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
<div class="form-row" id="rac_rate_dropdown">
|
||||
<div class="form-group col-md-12">
|
||||
<div id="dependent_rejection_mail_editor_container" style="height:600px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="editor"></div>
|
||||
<input type="file" id="Question_title_fileInput" style="display:none;">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-group text-right m-b-0 dependent_rejection_mail_action">
|
||||
<button type="button" class="btn btn-primary waves-effect waves-light mr-1 preview_button">Preview</button>
|
||||
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1" id="btnGridSubmit_2">Submit</button>
|
||||
</div>
|
||||
|
||||
<div class="dependent_rejection_mail_preview"></div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 7 Modal content for the Large example => CD balance insufficent HR mail sent -->
|
||||
<div class="modal fade" id="hr_cd_insufficient_balance_mail_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"
|
||||
aria-hidden="true" aria-modal="true" data-backdrop="static">
|
||||
@ -1959,7 +2066,8 @@
|
||||
"member_welcome_mail",
|
||||
"member_review_and_summary_mail",
|
||||
"client_hr_summary_mail",
|
||||
"hr_cd_insufficient_balance_mail"
|
||||
"hr_cd_insufficient_balance_mail",
|
||||
"dependent_rejection_mail"
|
||||
];
|
||||
console.log(`:) getMailTemplateData function called for ${template_name}`); // REF : PS
|
||||
if (!validTemplates.includes(template_name)) {
|
||||
@ -2465,6 +2573,54 @@
|
||||
});
|
||||
});
|
||||
|
||||
$('#dependent_rejection_mail_form').submit(function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
if (!editor) {
|
||||
console.error("Editor not initialized");
|
||||
toastr.error("Editor not ready. Please try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
editor.exportHtml(function(data) {
|
||||
|
||||
var formData = new FormData($('#dependent_rejection_mail_form')[0]);
|
||||
|
||||
formData.append('mailContent', data.html);
|
||||
formData.append('client_id', $('#general_PrimaryKey').val());
|
||||
formData.append('mailJson', JSON.stringify(data.design));
|
||||
|
||||
$('.loader').fadeIn();
|
||||
$('.loader-mask').fadeIn();
|
||||
|
||||
var form_action = '<?= base_url("client/notification/create") ?>';
|
||||
|
||||
$.ajax({
|
||||
url: form_action,
|
||||
type: "POST",
|
||||
data: formData,
|
||||
dataType: 'json',
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function(res) {
|
||||
$('#dependent_rejection_mail_modal').find('.close').click();
|
||||
toastr.success('Template saved successfully');
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(350).fadeOut('slow');
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error(xhr.responseText);
|
||||
console.error(status, error);
|
||||
setTimeout(function() {
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(350).fadeOut('slow');
|
||||
toastr.warning('Something Went Wrong!', 'Warning');
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('#hr_cd_insufficient_balance_mail_form').submit(function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
@ -2622,6 +2778,10 @@
|
||||
name: 'hr_cd_insufficient_balance_mail_btn',
|
||||
value: $('#hr_cd_insufficient_balance_mail_btn').prop('checked')
|
||||
});
|
||||
formData.push({
|
||||
name: 'dependent_rejection_mail_btn',
|
||||
value: $('#dependent_rejection_mail_btn').prop('checked')
|
||||
});
|
||||
|
||||
var form_action = '<?= base_url("client/notification/update_enable") ?>';
|
||||
$('.loader').fadeIn();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user