FEAT_CD_HR_MAIL_SENT_INSUFF_CD_BAL

This commit is contained in:
VENKATESHWARAN 2026-01-29 15:20:35 +05:30
parent d90a8dd448
commit 17be27e4ea
9 changed files with 973 additions and 25 deletions

View File

@ -428,6 +428,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) {
$routes->get('proceedExcelFileDataValidation', 'EmployeeController::proceedExcelFileDataValidation');
$routes->get('checkTpaApiEnable', 'EmployeeRestController::checkTpaApiEnable');
$routes->get('generateDemographyDataTable', 'LeadsController::generateDemographyDataTable');
$routes->post('insufficientCdBalanceHrMailSend', 'EmployeeController::insufficientCdBalanceHrMailSend');
});
$routes->post("policy_tranction/sendInstallmentRemainderMail","PolicyTransactionController::sendInstallmentRemainderMail");

View File

@ -6638,23 +6638,23 @@ class ClientController extends AdminController
// ----------EMP DATA SERVICE CONTROLLER--------------------------------------------------------------------------------
$batch_data = [
'client_id' => 51,
'client_branch_id' => 40,
'client_policy_id' => 63,
'insurer_or_tpa' => "insurer",
'event_type' => "correction",
'actions' => "export",
'file_name' => "deletion_enhancement_test_file.xlsx",
];
// $batch_data = [
// 'client_id' => 51,
// 'client_branch_id' => 40,
// 'client_policy_id' => 63,
// 'insurer_or_tpa' => "insurer",
// 'event_type' => "correction",
// 'actions' => "export",
// 'file_name' => "deletion_enhancement_test_file.xlsx",
// ];
// $batch_data = [
// 'client_id' => 20,
// 'client_policy_id' => 77,
// 'client_branch_id' => 72,
// 'client_id' => 12,
// 'client_policy_id' => 8063,
// 'client_branch_id' => 1,
// 'insurer_or_tpa' => "insurer",
// // 'insurer_or_tpa' => "tpa",
// 'event_type' => "si_enhancement",
// 'event_type' => "inception",
// 'file_name' => "si_enhancement_test_file.xlsx",
// 'actions' => "export",
// ];
@ -6713,6 +6713,19 @@ class ClientController extends AdminController
// $EmpDataServiceController->cashDepositCalculationForDeletion($array);
// $result = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($batch_data);
// $totals = 0;
// foreach ($result as $item) {
// $totals = $totals + $item->total;
// }
// $data = [
// session()->get('cd_balance'),
// session()->get('cd_amount'),
// session()->get('hr_data'),
// session()->has('cd_balance'),
// get_cd_balance()
// ];
// dd($data);
// $result = $this->employeePolicyModel->getCorrectionEmployeesDataForExportExcel($batch_data);
// dd(db_connect()->getLastQuery());

View File

@ -33,6 +33,8 @@ use App\Models\LeadsModel;
use App\Models\LeadInstallmentPaymentDetails;
use App\Models\PolicyTransactionModel;
use App\Models\PTCOShareDetailsModel;
use App\Models\LevelContactModel;
use App\Controllers\Jobs;
use App\Controllers\JobWorker;
@ -71,6 +73,8 @@ class EmpDataServiceController extends BaseController
protected $leadInstallmentPaymentDetailesModel;
protected $policyTransactionModel;
protected $PTCOShareDetailsModel;
protected $LevelContactModel;
public function __construct()
@ -99,6 +103,7 @@ class EmpDataServiceController extends BaseController
$this->leadInstallmentPaymentDetailesModel = new LeadInstallmentPaymentDetails();
$this->policyTransactionModel = new PolicyTransactionModel();
$this->PTCOShareDetailsModel = new PTCOShareDetailsModel();
$this->LevelContactModel = new LevelContactModel();
}
@ -208,14 +213,19 @@ class EmpDataServiceController extends BaseController
if ((int) $cash_balance['balance'] < (int) $totals) {
$this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount.');
$this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount. CASH BALANCE : {balance} and TOTAL AMOUNT : {total}', ['balance' => $cash_balance['balance'], 'total' => $totals]);
session()->set('cd_balance', false);
session()->set('cd_amount', $cash_balance['balance']);
session()->set('excel_file_amt', $totals);
$cd_session_data = json_encode(['cd_balance' => false, 'cd_amount' => $cash_balance['balance'], 'excel_file_amt' => $totals]);
session()->set('cd_balance_info', $cd_session_data);
session()->set('cd_balance', false);
$hr_data = $this->getHrdataForInsufficientMailSend($export_data['client_branch_id']);
$session_data = json_encode(['client_id' => $export_data['client_id'], 'hr_data' => $hr_data]);
session()->set('hr_data', $session_data);
}else{
session()->set('cd_balance', true);
session()->set('cd_amount', $cash_balance['balance']);
session()->set('excel_file_amt', $totals);
}
}
}
@ -5858,4 +5868,16 @@ class EmpDataServiceController extends BaseController
'gst' => round($amount['gst'] ?? 0, 2)
];
}
public function getHrdataForInsufficientMailSend($ref_id)
{
$data = $this->LevelContactModel
->select('id, name, email')
->where('ref_id', $ref_id)
->where('is_active', 1)
->where('contact_type', 'client')
->findAll();
return $data;
}
}

View File

@ -8,6 +8,7 @@ use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Helpers\DepositHelper;
use App\Helpers\MailHelper;
use App\Models\EmployeeModel;
@ -29,6 +30,7 @@ use App\Models\AuditHistoryModel;
use App\Models\UserModel;
use App\Models\PartnerEndorsementRequestModel;
use App\Models\TpaApiDataModel;
use App\Models\LevelContactModel;
use App\Controllers\Jobs;
@ -74,6 +76,7 @@ class EmployeeController extends AdminController
protected $auditHistory;
protected $userModel;
protected $partnerEndorsementRequestModel;
protected $LevelContactModel;
public function __construct()
{
@ -97,6 +100,7 @@ class EmployeeController extends AdminController
$this->auditHistory = new AuditHistoryModel();
$this->userModel = new userModel();
$this->partnerEndorsementRequestModel = new PartnerEndorsementRequestModel();
$this->LevelContactModel = new LevelContactModel();
}
public function list()
@ -4453,5 +4457,46 @@ class EmployeeController extends AdminController
}
public function insufficientCdBalanceHrMailSend()
{
$post_data = $this->request->getJson(true);
if(empty($post_data) || (!isset($post_data['mails']) && !empty($post_data['mails'])) || (!isset($post_data['client_id']) && !empty($post_data['client_id']))){
return $this->respond(['status' => false, 'code' => 404, 'message' => 'No data send mail'], 200);
}
$client_data = $this->clientModel->where('is_active', 1)->where('id', $post_data['client_id'])->first();
$common['mail_type'] = "insufficient_cd_balance_by_hr";
$common['client_id'] = $post_data['client_id'];
$subject = 'Insufficient CD Balance Notification';
$mail_content = '
Dear {{HR_NAME}},
Greetings from Nhance.
We would like to inform you that the CD balance for {{CLIENT_NAME}} is currently low / insufficient, which may impact further processing of insurance-related activities.
Kindly request you to credit the required amount at the earliest to avoid any service disruption.
Please let us know once the amount is credited, or if you need any clarification from our end.
Thank you for your support and cooperation.
';
foreach ($post_data['mails'] as $hr_id => $hr_data) {
$mail_content = str_ireplace('{{HR_NAME}}', $hr_data['name'], $mail_content);
$mail_content = str_ireplace('{{CLIENT_NAME}}', $client_data['client_name'], $mail_content);
$res = MailHelper::send_email(['mail' => $hr_data['mail'], 'subject' => $subject, 'message' => $mail_content, 'common' => $common]);
}
return $this->respond(['status' => true, 'code' => 200, 'message' => 'Mail send successfully'], 200);
}
}

View File

@ -62,7 +62,7 @@ class LoginController extends BaseController
set_session_data($session_data);
// Bind session to device
set_session_data(['fingerprint' => generateFingerprint()]);
// set_session_data(['fingerprint' => generateFingerprint()]);
log_message('error', 'Set The UserId : `'. $user->id .'` in Session');
log_message('error', 'User Login Sucessfully');

View File

@ -3173,6 +3173,13 @@ if (!function_exists('check_rto_data')) {
$vehicle_no = strtoupper(trim($row[2])); // Example: TN10AB1234
$new_vehicle = strtolower(trim($row[2]));
if(!validate_indian_vehicle_number($vehicle_no)['status']){
return [
'status' => false,
'error' => 'Invalid Vehicle Number. Format should be like TN82AX2024 (no spaces or special characters).'
];
};
// BH Series: 22BH1234AA
$bhPattern = '/^[0-9]{2}BH[0-9]{4}[A-Z]{2}$/';

View File

@ -1101,3 +1101,33 @@ if (!function_exists('convertGoogleDriveToDownloadLink')) {
}
}
if (!function_exists('get_cd_balance')) {
function get_cd_balance(): array
{
$session = session();
return [
'has_cd_balance' => $session->has('cd_balance'),
'hr_data' => $session->get('hr_data') ?? [],
'cd_balance_info' => $session->get('cd_balance_info') ?? [],
];
}
}
if (!function_exists('clear_cd_balance_session')) {
function clear_cd_balance_session(): void
{
$session = session();
$session->remove([
'cd_balance',
'hr_data',
'cd_balance_info'
]);
}
}

View File

@ -494,7 +494,6 @@ class EmployeePolicyModel extends Model
) as batch_data ON employee_polices.id = batch_data.emp_policy_id
WHERE employee_polices.client_policy_id = :client_policy_id:
AND (employee_polices.:id: IS NULL OR employee_polices.:id: = '')
AND employees.client_branch_id = :client_branch_id:
AND employee_polices.is_active = 1
AND employee_polices.status = 'active'
@ -502,6 +501,14 @@ class EmployeePolicyModel extends Model
AND employees.emp_status = 'active'
";
if($insurer_or_tpa == 'insurer'){
$sql .= "AND (employee_polices.uhid IS NULL OR employee_polices.uhid <> '')";
}
if($insurer_or_tpa == 'tpa'){
$sql .= "AND (employee_polices.tpa_id IS NULL OR employee_polices.tpa_id <> '')";
}
$binds = ["datas" => $datas,"event" => $event
,"insurer_or_tpa" => $insurer_or_tpa
,"client_policy_id" => $client_policy_id

View File

@ -5,6 +5,513 @@
}
</style>
<style>
.demo-button {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 16px 32px;
font-size: 16px;
font-weight: 700;
border-radius: 12px;
cursor: pointer;
font-family: 'Manrope', sans-serif;
box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
transition: all 0.3s ease;
letter-spacing: 0.5px;
}
.demo-button:hover {
transform: translateY(-2px);
box-shadow: 0 15px 30px rgba(102, 126, 234, 0.5);
}
/* Modal Overlay */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: var(--bg-overlay);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
opacity: 0;
visibility: hidden;
transition: all 0.3s ease;
backdrop-filter: blur(4px);
}
.modal-overlay.active {
opacity: 1;
visibility: visible;
}
/* Modal Container */
.modal-container {
background: var(--bg-modal);
border-radius: 20px;
box-shadow: var(--shadow-lg);
/* max-width: 600px; */
width: 100%;
max-height: 85vh;
overflow: hidden;
transform: scale(0.9) translateY(20px);
transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
display: flex;
flex-direction: column;
}
.modal-overlay.active .modal-container {
transform: scale(1) translateY(0);
}
/* Modal Header */
.modal-header {
padding: 10px 26px;
border-bottom: 2px solid var(--border-color);
background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
flex-shrink: 0;
}
.modal-title {
font-family: 'Manrope', sans-serif;
font-size: 24px;
font-weight: 700;
color: var(--text-primary);
margin-bottom: 8px;
}
.modal-subtitle {
font-size: 14px;
color: var(--text-secondary);
font-weight: 400;
}
/* Toggle Section */
.toggle-section {
padding: 14px 25px;
background: #fefefe;
border-bottom: 1px solid var(--border-color);
flex-shrink: 0;
}
.toggle-container {
display: flex;
align-items: center;
justify-content: space-between;
}
.toggle-label {
font-family: 'Manrope', sans-serif;
font-size: 15px;
font-weight: 600;
color: var(--text-primary);
}
/* Toggle Switch */
.toggle-switch {
position: relative;
width: 54px;
height: 28px;
cursor: pointer;
}
.toggle-switch input {
opacity: 0;
width: 0;
height: 0;
}
.toggle-slider {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #cbd5e1;
border-radius: 34px;
transition: all 0.3s ease;
}
.toggle-slider:before {
content: "";
position: absolute;
height: 22px;
width: 22px;
left: 3px;
bottom: 3px;
background-color: white;
border-radius: 50%;
transition: all 0.3s ease;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.toggle-switch input:checked + .toggle-slider {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.toggle-switch input:checked + .toggle-slider:before {
transform: translateX(26px);
}
/* HR List Section */
.hr-list-section {
max-height: 300px;
overflow-y: auto;
padding: 0;
display: none;
flex: 1 1 auto;
min-height: 0;
}
.hr-list-section.active {
display: block;
}
.hr-item {
padding: 5px 32px;
border-bottom: 1px solid var(--border-color);
display: flex;
align-items: center;
transition: background 0.2s ease;
cursor: pointer;
}
.hr-item:hover {
background: #f9fafb;
}
.hr-item:last-child {
border-bottom: none;
}
/* Checkbox Styling */
.hr-checkbox {
position: relative;
display: flex;
align-items: center;
margin-right: 16px;
}
.hr-checkbox input[type="checkbox"] {
position: absolute;
opacity: 0;
cursor: pointer;
}
.checkbox-custom {
width: 22px;
height: 22px;
border: 2px solid #cbd5e1;
border-radius: 6px;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s ease;
background: white;
}
.hr-checkbox input:checked ~ .checkbox-custom {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-color: #667eea;
}
.checkbox-custom:after {
content: "";
display: none;
width: 6px;
height: 10px;
border: solid white;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
}
.hr-checkbox input:checked ~ .checkbox-custom:after {
display: block;
}
/* HR Info */
.hr-info {
flex: 1;
}
.hr-name {
font-family: 'Manrope', sans-serif;
font-size: 16px;
font-weight: 700;
color: var(--text-primary);
margin-bottom: 4px;
}
.hr-email {
font-size: 13px;
font-weight: 500;
color: var(--text-secondary);
}
/* Modal Footer */
.modal-footer {
padding: 24px 32px;
background: #fafafa;
display: flex;
gap: 12px;
justify-content: flex-end;
flex-shrink: 0;
border-top: 1px solid var(--border-color);
}
.btn {
padding: 12px 24px;
border: none;
border-radius: 10px;
font-size: 15px;
font-weight: 600;
cursor: pointer;
font-family: 'Manrope', sans-serif;
transition: all 0.2s ease;
letter-spacing: 0.3px;
}
.btn-cancel {
background: white;
color: var(--text-secondary);
border: 2px solid var(--border-color);
}
.btn-cancel:hover {
background: #f9fafb;
border-color: #d1d5db;
}
.btn-submit {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}
.btn-submit:hover {
transform: translateY(-2px);
box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}
.btn-submit:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none;
}
/* Alert Styling */
.custom-alert {
position: fixed;
top: 20px;
right: 20px;
background: white;
padding: 20px 24px;
border-radius: 12px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
z-index: 2000;
max-width: 400px;
border-left: 4px solid var(--danger-color);
opacity: 0;
transform: translateX(400px);
transition: all 0.3s ease;
}
.custom-alert.show {
opacity: 1;
transform: translateX(0);
}
.alert-content {
display: flex;
align-items: flex-start;
gap: 12px;
}
.alert-icon {
font-size: 24px;
flex-shrink: 0;
}
.alert-text {
flex: 1;
}
.alert-title {
font-family: 'Manrope', sans-serif;
font-weight: 700;
color: var(--text-primary);
font-size: 16px;
margin-bottom: 4px;
}
.alert-message {
color: var(--text-secondary);
font-size: 14px;
}
/* Scrollbar Styling */
.hr-list-section::-webkit-scrollbar {
width: 8px;
}
.hr-list-section::-webkit-scrollbar-track {
background: #f1f5f9;
}
.hr-list-section::-webkit-scrollbar-thumb {
background: #cbd5e1;
border-radius: 4px;
}
.hr-list-section::-webkit-scrollbar-thumb:hover {
background: #94a3b8;
}
/* Empty State */
.empty-state {
padding: 60px 32px;
text-align: center;
color: var(--text-secondary);
}
.empty-state-icon {
font-size: 48px;
margin-bottom: 16px;
opacity: 0.5;
}
.empty-state-text {
font-size: 15px;
font-weight: 500;
}
/* Animations */
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.hr-item {
animation: slideIn 0.3s ease;
animation-fill-mode: backwards;
}
.hr-item:nth-child(1) { animation-delay: 0.05s; }
.hr-item:nth-child(2) { animation-delay: 0.1s; }
.hr-item:nth-child(3) { animation-delay: 0.15s; }
.hr-item:nth-child(4) { animation-delay: 0.2s; }
.hr-item:nth-child(5) { animation-delay: 0.25s; }
/* Confirmation Dialog */
.confirm-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.7);
display: flex;
align-items: center;
justify-content: center;
z-index: 2000;
opacity: 0;
visibility: hidden;
transition: all 0.3s ease;
}
.confirm-overlay.active {
opacity: 1;
visibility: visible;
}
.confirm-dialog {
background: white;
border-radius: 16px;
padding: 32px;
max-width: 420px;
width: 90%;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
transform: scale(0.9);
transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.confirm-overlay.active .confirm-dialog {
transform: scale(1);
}
.confirm-icon {
font-size: 48px;
text-align: center;
margin-bottom: 16px;
}
.confirm-title {
font-family: 'Manrope', sans-serif;
font-size: 22px;
font-weight: 700;
color: var(--text-primary);
text-align: center;
margin-bottom: 12px;
}
.confirm-message {
font-size: 15px;
color: var(--text-secondary);
text-align: center;
margin-bottom: 28px;
line-height: 1.6;
}
.confirm-buttons {
display: flex;
gap: 12px;
}
.confirm-btn {
flex: 1;
padding: 14px 24px;
border: none;
border-radius: 10px;
font-size: 15px;
font-weight: 600;
cursor: pointer;
font-family: 'Manrope', sans-serif;
transition: all 0.2s ease;
}
.confirm-btn-no {
background: white;
color: var(--text-secondary);
border: 2px solid var(--border-color);
}
.confirm-btn-no:hover {
background: #f9fafb;
border-color: #d1d5db;
}
.confirm-btn-yes {
background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
color: white;
box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}
.confirm-btn-yes:hover {
transform: translateY(-2px);
box-shadow: 0 6px 16px rgba(220, 38, 38, 0.4);
}
</style>
<div class="tab-pane fade" id="KYC-DOC-tab">
<div class="row">
<div class="col-xl-12">
@ -146,6 +653,10 @@
</form>
</div>
</div>
<!-- Demo Button -->
<button style="display: none" class="demo-button" onclick="openModal()">Open HR Email Modal</button>
</div>
</div>
@ -159,12 +670,57 @@
<!-- end row -->
</div>
<div class="modal fade" id="payout_modal" tabindex="-1" role="dialog" aria-hidden="true" aria-modal="true" data-backdrop="static" data-backdrop="static"
data-keyboard="false"
tabindex="-1">
<div class="modal-dialog modal-lg" style="max-width: 800px;">
<div class="modal-content">
<div class="modal-header" style="background-color: gainsboro;">
<h5 class="modal-title" id="myCenterModalLabel"> Insufficient CD Balance HR Notification</h5>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body" id="modal_body">
<!-- Form -->
<form id="hrEmailForm">
<input type="hidden", id="client_id_for_hr_mail_send" name="client_id" >
<!-- Toggle Section -->
<div class="toggle-section">
<div class="toggle-container">
<label class="toggle-label">Insufficient Balance HR Mail Send</label>
<label class="toggle-switch">
<input type="checkbox" id="mailToggle" onchange="toggleHRList()">
<span class="toggle-slider"></span>
</label>
</div>
</div>
<!-- HR List Section -->
<div class="hr-list-section" id="hrListSection">
<!-- HR items will be dynamically generated here -->
</div>
<!-- Footer Buttons -->
<div class="modal-footer">
<button type="button" class="btn btn-cancel" onclick="cancelModal()">Cancel</button>
<button type="submit" class="btn btn-submit" id="submitBtn">Send Notification</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
var client_id_param2 = 0;
var client_branch_id_param2 = 0;
var client_policy_param2 = 0;
var hr_data = [];
$(document).ready(function() {
// Initialize select2
@ -719,19 +1275,22 @@
var messageShown = false; // Flag to prevent duplicate messages
//function for checking the session
function checkCDBalance() {
function checkCDBalanceOld() {
const get_cd_balance = <?= json_encode(get_cd_balance()) ?>;
console.log({ get_cd_balance });
<?php if (session()->has('cd_balance')): ?>
var cdBalance = <?php echo json_encode(session()->get('cd_balance')); ?>;
var cdAmount = <?php echo json_encode(session()->get('cd_amount')); ?>;
var excel_file_amt = <?php echo json_encode(session()->get('excel_file_amt')); ?>;
hr_data = <?php echo json_encode(session()->get('hr_data')); ?>;
console.log("cdBalance : ", cdBalance);
console.log("cdAmount : ", cdAmount);
console.log("excel_file_amt : ", excel_file_amt);
console.log({cdBalance, cdAmount, excel_file_amt, hr_data})
// Only show message once and if status is false
if (cdBalance === false && !messageShown) {
if (get_cd_balance?.cd_balance === false && !messageShown) {
// toastr.warning('Insufficient CD Balance deducated. Please wait the file will be downloaded', 'WARNING');
var message1 = 'Insufficient CD Balance deducted. Please wait the file will be downloaded<br>' +
'<strong>CD Amount:</strong> ₹' + (cdAmount || 0) + '<br>' +
@ -742,8 +1301,11 @@
timeOut: 10000,
extendedTimeOut: 3000
});
messageShown = true; // Prevent showing message again
stopInterval();
openModal();
} else if (cdBalance === true) {
console.log("CD Balance is sufficient");
stopInterval();
@ -758,6 +1320,71 @@
<?php else: ?>
console.log("No cd_balance session found");
<?php endif; ?>
}
function checkCDBalance() {
const cdData = <?= json_encode(get_cd_balance()) ?>;
console.log(cdData, typeof cdData);
// cdData itself null / undefined safety
if (!cdData || typeof cdData !== 'object') {
console.log('CD data not available');
return;
}
let cd_balance_info = cdData.cd_balance_info
console.log('cd_balance_info', cd_balance_info);
cd_balance_info = JSON.parse(cd_balance_info);
console.log('cd_balance_info', cd_balance_info);
let hr_data = cdData.hr_data
console.log('hr_data', hr_data);
hr_data = JSON.parse(hr_data);
console.log('hr_data', hr_data);
let cd_balance = cd_balance_info.cd_balance;
let cd_amount = cd_balance_info.cd_amount;
let excel_file_amt = cd_balance_info.excel_file_amt;
console.log(cd_balance ,cd_amount ,excel_file_amt);
window.hr_data = hr_data.hr_data;
$('#client_id_for_hr_mail_send').val(hr_data.client_id)
console.log(cd_balance, typeof cd_balance);
if (cd_balance === false && messageShown === false) {
const message1 =
'Insufficient CD Balance deducted. Please wait the file will be downloaded<br>' +
'<strong>CD Amount:</strong> ₹' + cd_amount + '<br>' +
'<strong>Total Amount:</strong> ₹' + excel_file_amt;
toastr.warning(message1, 'WARNING', {
allowHtml: true,
timeOut: 10000,
extendedTimeOut: 3000
});
messageShown = true;
stopInterval();
openModal();
<?php clear_cd_balance_session(); ?>
}
else if (cd_balance === true) {
console.log('CD Balance is sufficient');
stopInterval();
}
else {
console.log('CD balance info not available');
}
}
// Start the interval
@ -766,7 +1393,7 @@
messageShown = false; // Reset message flag
submitInterval = setInterval(function() {
checkCDBalance();
}, 2000);
}, 5000);
console.log("Checking CD balance started...");
}
}
@ -796,6 +1423,7 @@
//------------------------------------------------------------------------------------------------------
</script>
<script>
function togglePolicyIssueDate() {
@ -873,4 +1501,199 @@
}
</script>
<script>
// Sample HR data (replace this with your actual data source)
const hrData = [
{ id: 1, name: 'Rajesh Kumar', email: 'rajesh.kumar@company.com' },
{ id: 2, name: 'Priya Sharma', email: 'priya.sharma@company.com' },
{ id: 3, name: 'Arun Patel', email: 'arun.patel@company.com' },
{ id: 4, name: 'Arun Patel', email: 'arun.patel@company.com' },
{ id: 5, name: 'Arun Patel', email: 'arun.patel@company.com' },
];
// Open Modal
function openModal() {
// document.getElementById('hrModal').classList.add('active');
var myModal = new bootstrap.Modal(document.getElementById('payout_modal'));
myModal.show();
}
// Toggle HR List
function toggleHRList() {
const toggle = document.getElementById('mailToggle');
const hrListSection = document.getElementById('hrListSection');
if (toggle.checked) {
hrListSection.classList.add('active');
renderHRList();
} else {
hrListSection.classList.remove('active');
}
}
// Render HR List
function renderHRList() {
const hrListSection = document.getElementById('hrListSection');
if (hr_data.length === 0) {
hrListSection.innerHTML = `
<div class="empty-state">
<div class="empty-state-icon">📭</div>
<div class="empty-state-text">No HR contacts available</div>
</div>
`;
return;
}
hrListSection.innerHTML = hr_data.map(hr => `
<div class="hr-item" onclick="toggleCheckbox(${hr.id}, event)">
<label class="hr-checkbox">
<input type="checkbox" name="hr_emails[]" value="${hr.id}" data-email="${hr.email}" data-name="${hr.name}" id="hr_${hr.id}">
<span class="checkbox-custom"></span>
</label>
<div class="hr-info">
<div class="hr-name">${hr.name}</div>
<div class="hr-email">${hr.email}</div>
</div>
</div>
`).join('');
}
// Toggle checkbox when clicking on the item
function toggleCheckbox(hrId, event) {
// Prevent double toggle if clicking directly on checkbox
if (event && event.target.tagName === 'INPUT') {
return;
}
const checkbox = document.getElementById(`hr_${hrId}`);
checkbox.checked = !checkbox.checked;
}
// Cancel Modal with Confirmation
function cancelModal() {
// document.getElementById('confirmDialog').classList.add('active');
Swal.fire({
title: "Cancel Confirmation",
text: "Are you sure you want to cancel? No emails will be sent to HR.",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "Yes, Procced!"
}).then((result) => {
if(result.isConfirmed){
confirmCancel()
}else{
return false
}
});
}
// Confirm Cancel
function confirmCancel() {
setTimeout(() => {
$('.close').click();
resetForm();
}, 300);
}
// Reset Form
function resetForm() {
document.getElementById('hrEmailForm').reset();
document.getElementById('hrListSection').classList.remove('active');
}
$('#hrEmailForm').on('submit', function (e) {
e.preventDefault();
const client_id = $('#client_id_for_hr_mail_send').val();
const mailToggle = $('#mailToggle');
const selectedHRs = $('input[name="hr_emails[]"]:checked');
if (!mailToggle.is(':checked')) {
toastr.warning('Please Enable the mail option.', 'WARNING');
return;
}
if (selectedHRs.length === 0) {
toastr.warning('Please select at least one HR.', 'WARNING');
return;
}
// Prepare mails object
const sendingMails = {};
selectedHRs.each(function () {
const hrId = $(this).val();
const hrEmail = $(this).data('email');
const hrName = $(this).data('name');
sendingMails[hrId] = {
mail: hrEmail,
name: hrName
};
});
const formData = {
mails: sendingMails,
client_id: client_id,
mail_enable_key: mailToggle.is(':checked') ? 1 : 0
};
console.log('Form Data:', formData);
const $submitBtn = $('#submitBtn');
$submitBtn.prop('disabled', true).text('Sending...');
const url = '<?= base_url('util/insufficientCdBalanceHrMailSend') ?>';
$.ajax({
url: url,
type: 'POST',
data: JSON.stringify(formData),
contentType: 'application/json',
dataType: 'json',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') || ''
},
success: function (data) {
console.log('Response Success:', data);
if (data.status === true) {
toastr.success(data.message, 'SUCCESS');
} else {
toastr.warning(data.message, 'WARNING');
}
},
error: function (xhr, status, error) {
console.error('Response Error:', error);
toastr.error('Something went wrong. Please try again.', 'ERROR');
},
complete: function () {
// Reset button state
$submitBtn.prop('disabled', false).text('Send Notification');
confirmCancel();
}
});
});
const modal = document.getElementById('payout_modal');
const modalDialog = modal.querySelector('.modal-dialog');
modal.addEventListener('mousedown', function (e) {
if (!modalDialog.contains(e.target)) {
e.preventDefault();
e.stopImmediatePropagation();
return false;
}
}, true); // 👈 capture phase
</script>