diff --git a/app/Config/Routes.php b/app/Config/Routes.php index dfe10c9b..34478d0c 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -298,6 +298,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get("base_policy_for_policy_inception/(:any)", "PolicyTransactionController::getBasePolicy/$1"); $routes->get("sentTestMail/(:any)", "NotificationController::sentTestMail/$1"); $routes->get("send_manual_reminder/(:any)", "DashboardController::sendManualReminder/$1"); + $routes->get("send_manual_ecard/(:any)", "DashboardController::sendManualEcard/$1"); $routes->get("get_client_policy_list_for_remainder/(:any)", "EmployeeController::get_client_policy_list_for_remainder/$1"); $routes->get("get_client_branch_data/(:any)", "ClientController::get_client_branch_data/$1"); $routes->get("getLevelContects", "LeadsController::getLevelContects"); diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index bd126144..dfa0841a 100755 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -20,6 +20,7 @@ use App\Models\ClientPolicyModel; use App\Models\NotificationModel; use App\Models\EmployeePolicyModel; use App\Controllers\PendingActionsContrller; +use App\Controllers\EmpDataServiceController; class DashboardController extends AdminController { @@ -544,6 +545,35 @@ class DashboardController extends AdminController } } + public function sendManualEcard($client_id, $client_branch_id, $policy_id) + { + $this->myLogger->logme('error', "sendManualEcard called with client_id: {$client_id}, client_branch_id: {$client_branch_id}, policy id : {$policy_id}"); + + $notification = $this->notificationModel->where('client_id', $client_id)->where('template_name', 'member_ecard_mail')->first(); + // print_r(($notification)); die; + if($notification && $notification['enabled'] == 0 && $notification['mail_content'] == '') + { + return $this->respond(['status' => false, 'code' => 400, 'message' => 'No template found','message2' => 'Failed' ], 200); + } + + $emp_data = $this->employeePolicyModel->getEmployeePolicyForEcard($policy_id); + if(count($emp_data) == 0) + { + return $this->respond(['status' => false, 'code' => 400, 'message' => 'No employees found','message2' => 'Failed' ], 200); + } + $ids = array_column($emp_data, 'id'); + // print_r(($ids)); die; + // print_r($this->clientPolicyModel->getLastQuery()); die; + // $this->myLogger->logme('error', "Policy details fetched: " . json_encode($client_policy_data)); + Jobs::addJob(['job_name' => 'sendMailForDownloadingECard', 'payload' => $ids]); + // $empEmpDataServiceController = new EmpDataServiceController(); + // $empEmpDataServiceController->sendMailForDownloadingECard($ids); + + + return $this->respond(['status' => true, 'code' => 200, 'message' => 'Mail Queued'], 200); + + } + public function data_construct_for_bds($data){ $groupedData = [ diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 5cefd249..42fa56e2 100755 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -168,19 +168,23 @@ class EmpDataServiceController extends BaseController $cash_balance['balance'] = $balance['opening_bal']; } - - // Calculate the total amount from the objects - $totals = 0; - foreach ($objects as $item) { - $totals = $totals + $item->total; - } - $totals = round($totals, 2); - if (!empty($cash_balance)) { - 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]); - return 0; + // Calculate the total amount from the objects + $totals = 0; + foreach ($objects as $item) { + $totals = $totals + $item->total; + } + + $totals = round($totals, 2); + + if($export_data['insurer_or_tpa'] == 'insurer') //check CD amt related issue for only insurer, not tpa + { + if (!empty($cash_balance)) { + 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]); + return 0; + } } } @@ -408,7 +412,7 @@ class EmpDataServiceController extends BaseController ], [ 'column_index' => 18, - 'column_name' => 'PR0 RATA PREMIUM', + 'column_name' => 'PRO RATA PREMIUM', 'db_column_name' => 'pro_rata_premium' ], [ @@ -921,18 +925,23 @@ class EmpDataServiceController extends BaseController $cash_balance['balance'] = $balance['opening_bal']; } - // Calculate the total amount from the objects - $totals = 0; - foreach ($inceptionData as $item) { - $totals = $totals + $item->total; - } + - $totals = round($totals, 2); - if (!empty($cash_balance)) { - 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]); - return 0; + // Calculate the total amount from the objects + $totals = 0; + foreach ($inceptionData as $item) { + $totals = $totals + $item->total; + } + $totals = round($totals, 2); + + if($export_data['insurer_or_tpa'] != 'tpa')// check overal emp premium amt with cd balance only for insurer export, not tpa export + { + if (!empty($cash_balance)) { + 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]); + return 0; + } } } } diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 27b68354..e5c6a9ab 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -445,28 +445,25 @@ class EmployeeController extends AdminController 'actions' => $actions, 'file_name' => $file_name, ]; - if ($actions == 'export') { - if ($event_type == 'inception' || $event_type == 'addition' || $event_type == 'dependent_addition' || $event_type == 'missed_inception') { + if ($event_type == 'inception' || $event_type == 'addition' || $event_type == 'dependent_addition' || $event_type == 'missed_inception' || ($event_type == 'MultipleEvents' && $insurer_or_tpa == 'tpa')) { $return = $empDataServiceController->generateExcelForAdditionandInception($batch_data); + if ($return === 0) { + session()->setFlashdata('error', "Insufficient deposit amount."); + return redirect()->to(base_url('employee/upload')); - if ($return === 0) { + }else if($return === 5){ - session()->setFlashdata('error', "Insufficient deposit amount."); - return redirect()->to(base_url('employee/upload')); + session()->setFlashdata('error', "The policy does not have a CD account number."); + return redirect()->to(base_url('employee/upload')); + } + else if($return === 6){ - }else if($return === 5){ - - session()->setFlashdata('error', "The policy does not have a CD account number."); - return redirect()->to(base_url('employee/upload')); - } - else if($return === 6){ - - session()->setFlashdata('error', "The Insurer does not have an Excel export template format."); - return redirect()->to(base_url('employee/upload')); - } + session()->setFlashdata('error', "The Insurer does not have an Excel export template format."); + return redirect()->to(base_url('employee/upload')); + } if (!$return) { @@ -1111,6 +1108,7 @@ class EmployeeController extends AdminController $htmlContent = $tmplt_data; $placeholders = [ + '{CLIENT_NAME}' => $value['client_name'], '{TPA_ID}' => $value['tpa_id'], '{NAME}' => $value['name'], '{UHID}' => $value['uhid'], diff --git a/app/Controllers/Jobs.php b/app/Controllers/Jobs.php index 56855efd..ad10f86d 100755 --- a/app/Controllers/Jobs.php +++ b/app/Controllers/Jobs.php @@ -49,7 +49,7 @@ class Jobs extends AdminController } $uuid = generate_uuid(); - $jobid = $jobModel->insert(['name' => $payload['job_name'],'uuid' => $uuid,'payload' => json_encode($payload['payload'])]); + $jobid = $jobModel->insert(['name' => $payload['job_name'],'uuid' => $uuid,'payload' => json_encode($payload['payload']), 'status' => isset($payload['status']) ? $payload['status'] : 'queued']); // echo $jobid; $myLogger->logme('error','new job {jobid} added to queue',['jobid' => $jobid]); return ['id' => $jobid,'uuid' => $uuid,'job_name' => $payload['job_name']]; diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 18dff3a9..4f265aff 100755 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -157,6 +157,27 @@ class EmployeePolicyModel extends Model return $result->findAll(); } + public function getEmployeePolicyForEcard($policy_id = 0) + { + $result = $this->select([ + 'employee_polices.id' + ]) + ->join('employees emp', 'employee_polices.employee_id = emp.id AND emp.relationship = "Self" '); + if ($policy_id !=0 && !empty($policy_id)) { + $result->where('employee_polices.client_policy_id', $policy_id); + } + // Always check these conditions + $result->where('employee_polices.is_active', 1) + ->where('employee_polices.status', 'active') + ->where('employee_polices.tpa_id is not null') + ->where('emp.relationship','Self'); + + return $result->findAll(); + // $result->findAll(); + // print_r($this->db->getLastQuery());die(); + } + + //for emp onboard do not change public function checkExistingEmpPolicy($arr) { @@ -845,7 +866,7 @@ class EmployeePolicyModel extends Model e.doj, e.band, TIMESTAMPDIFF(YEAR, e.dob, CURDATE()) AS emp_age, - (SELECT name FROM employees WHERE relationship = "Self" and emp_code = ' . $this->db->escape($emp_code) . ' and client_id = '.$client_id.') AS self, + (SELECT name FROM employees WHERE relationship = "Self" and emp_code = ' . $this->db->escape($emp_code) . ' and client_id = '.$client_id.' LIMIT 1) AS self, ep.tpa_id, @@ -910,7 +931,7 @@ class EmployeePolicyModel extends Model e.doj, e.band, TIMESTAMPDIFF(YEAR, e.dob, CURDATE()) AS emp_age, - (SELECT name FROM employees WHERE relationship = "Self" and emp_code = ' . $this->db->escape($emp_code) . ' and client_id = '.$client_id.') AS self, + (SELECT name FROM employees WHERE relationship = "Self" and emp_code = ' . $this->db->escape($emp_code) . ' and client_id = '.$client_id.' LIMIT 1) AS self, ep.tpa_id, diff --git a/app/Views/employee_list.php b/app/Views/employee_list.php index d615e7db..fed29d5d 100755 --- a/app/Views/employee_list.php +++ b/app/Views/employee_list.php @@ -70,8 +70,13 @@ table.dataTable tbody td { -