FEAT_E_CARD_MAIL_SEND : RV

This commit is contained in:
VENKATESHWARAN 2024-04-26 11:25:07 +05:30
parent be852ec756
commit 0db6fdfead
6 changed files with 314 additions and 239 deletions

View File

@ -17,7 +17,7 @@ $routes->get('/logout', 'LoginController::logout');
$routes->get('/oauth2callback', 'LoginController::receiveGoogleOAuthResponse');
$routes->get('/auth/google', 'LoginController::initiateGoogleOAuth');
$routes->get('/update-emp-policy-status', 'ClientController::updateEmpAndPolicyStatus');
$routes->get('download-e-card/(:segment)/(:segment)', 'EmployeeController::generateIDCardForEmployee/$1/$2');
$routes->get('download-e-card/(:segment)', 'EmployeeController::generateIDCardForEmployee/$1');

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;
@ -645,6 +646,9 @@ class EmpDataServiceController extends BaseController
$this->cashDepositCalculationForInception($depositeData);
$this->sendMailForDownloadingECard($empty_emp_tpa_uh_ids);
}
@ -1586,4 +1590,69 @@ class EmpDataServiceController extends BaseController
return true;
}
public function sendMailForDownloadingECard(array $ids)
{
try {
foreach ($ids as $key => $id) {
$get_emp_email_and_other_details = $this->employeePolicyModel
->select('employee_polices.client_policy_id, employees.emp_code, employees.email_corporate, employees.name, employee_polices.rand_string, employee_polices.tpa_id')
->join('employees', 'employees.id = employee_polices.employee_id')
->where('employees.emp_status', 'active')
->where('employees.is_active', '1')
->where('employee_polices.status', 'active')
->where('employee_polices.is_active', '1')
->where('employee_polices.id', $id)->first();
if ($get_emp_email_and_other_details != null && $get_emp_email_and_other_details != "") {
$name = $get_emp_email_and_other_details['name'];
$email = $get_emp_email_and_other_details['email_corporate'];
$rand_string = $get_emp_email_and_other_details['rand_string'];
$tpa_id = $get_emp_email_and_other_details['tpa_id'];
$link = generate_download_link($rand_string);
$subject = 'Download E-Card';
$html = '<body>
<p>Dear ' .$name .',</p>
<p>Your Policy( ' .$tpa_id .' ) has been successfully created. Please click the link below to download the insurance card:</p>
<p><a href="'.$link.'">Download Insurance Card</a></p>
<p>Thank you,</p>
</body>';
if ($email != null && $email != "") {
$mail_data = [
'mail' => $email,
'subject' => $subject,
'message' => $html
];
// dd($mail_data);
$result = Mailhelper::send_email($mail_data);
$decoded_result = (array) json_decode($result);
$data = [
'status' => $decoded_result['status'],
'message'=>$decoded_result['message'] ?? 'Internal Server Error',
'email' => $decoded_result['data']
];
// dd($data);
$this->myLogger->logme('error', 'status : {status}, message : {message}, email : {email}', $data);
}
}
}
return true; // Email(s) sent successfully
} catch (\Exception $e) {
// Log the error
$this->myLogger->log('error', 'Error occurred while sending email: ' . $e->getMessage());
return false; // Email(s) sending failed
}
}
}

View File

@ -131,8 +131,8 @@ class EmployeeController extends AdminController
// print_r($this->request->getPost('policies'));
// print_r($this->request->getPost('upload-action-type'));
// die();
// $empServiceController = new EmployeeServiceController();
// $res = $empServiceController->excelFileFormatValidation(['file_id' => '42']);
$empServiceController = new EmployeeServiceController();
$res = $empServiceController->excelFileFormatValidation(['file_id' => '42']);
// dd($res);
// $empServiceController = new EmployeeServiceController();
@ -723,7 +723,7 @@ class EmployeeController extends AdminController
}
public function downloadFullExcelErrorFile($file_id = 137, $rowIndex = 1, $colIndex = 1)
public function downloadFullExcelErrorFile($file_id, $rowIndex = 1, $colIndex = 1)
{
// Get file data from the database
$file_data = $this->fileModel->find($file_id);
@ -833,98 +833,62 @@ class EmployeeController extends AdminController
return $response;
}
public function generateIDCardForEmployee($emp_code, $client_policy_id)
public function generateIDCardForEmployee($rand_string)
{
$dompdf = new Dompdf();
$get_emp_code_and_client_policy_id = $this->employeePolicyModel
->select('employee_polices.client_policy_id, employees.emp_code')
->join('employees', 'employees.id = employee_polices.employee_id')
->where('employees.emp_status', 'active')
->where('employees.is_active', '1')
->where('employee_polices.status', 'active')
->where('employee_polices.is_active', '1')
->where('employee_polices.rand_string', $rand_string)->first();
if($get_emp_code_and_client_policy_id == null || $get_emp_code_and_client_policy_id == ""){
$data['message'] = 'Record Not Found';
return view('errors/404', $data);
}
$client_policy_id = $get_emp_code_and_client_policy_id['client_policy_id'];
$emp_code = $get_emp_code_and_client_policy_id['emp_code'];
$data['data'] = $this->employeePolicyModel->getECardDataUsingMd5($client_policy_id, $emp_code);
// $this->loadLayout('id_card_view', $data); exit;
// $this->loadLayout('id_card_view', $data);exit;
$html = view('id_card_view', $data);
// $html = str_replace('<body>', '<body style="text-align: center;">', $html);
$dompdf = new Dompdf();
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
$filename = 'ECard.pdf'; // Default filename
foreach ($data['data'] as $key => $value) {
if ($value['relationship'] == "Self") {
$filename = $value['tpa_id']; // Update filename if relationship is "Self"
} elseif (!empty($value['tpa_id']) && $filename == 'ECard.pdf') {
$filename = $value['tpa_id'];
}
}
$dompdf->stream($filename);
}
public function viewECard()
{
$this->loadLayout('id_card_view');
}
public function truncateFileData() //truncateFileDataIn DB (de activate rows)
{
$file_id = $this->request->uri->getSegment(3);
// $file_id = 112;
$file = $this->fileModel->find($file_id);
// $file['action'] = 'si_enhancement';
// $result = [];
// !dd($file);
if($file['action'] == 'inception' || $file['action'] == 'dependent_addition' || $file['action'] == 'addition')
{
$result = $this->employeeModel->getEmpListByFileId(file_id: $file_id,emp_status: ['active'],policy_status:['active']);
// ~dd($result);
if(count($result))
{
return $this->respond(['dataStatus' => false,'code' => 404,'message' => 'File data already processed'], 200);
}
else
{
//update emp and emp plocies
$db = db_connect();
$query = "UPDATE employees JOIN employee_polices ON employees.id = employee_polices.employee_id and employees.file_id = $file_id SET employees.emp_status = 'truncated', employee_polices.status = 'truncated', employees.is_active = 0,employee_polices.is_active = 0 WHERE employees.file_id = $file_id";
$db->query($query);
$affectedRows = $db->affectedRows();
// $affectedRows = 10;
//update file status
$this->fileModel->where('id', $file_id)->set(['status' => 'truncated'])->update();
return $this->respond(['dataStatus' => true,'code' => 200,'data' => round($affectedRows/2)], 200);
}
}
else if($file['action'] == 'si_enhancement' || $file['action'] == 'correction' || $file['action'] == 'deletion')
{
$res = $this->empEndorsementModel->select(['count(id) as count'])
->where('emp_endorsement.file_id',$file_id)
->groupStart()
->where('emp_endorsement.endorsement_id is not null')
->orwhereIn('emp_endorsement.status',['complete'])
->groupEnd()
->get()
->getResult();
// print_r($this->empEndorsementModel->getLastQuery());
// echo $res[0]->count;die();
if($res[0]->count == 0)
{
//update truncated status to db
$this->empEndorsementModel->where('file_id',$file_id)
->set(['status' => 'truncated'])
->update();
//update file status
$this->fileModel->where('id', $file_id)->set(['status' => 'truncated'])->update();
return $this->respond(['dataStatus' => true,'code' => 200,'data' => 'success'], 200);
}
else
{
return $this->respond(['dataStatus' => false,'code' => 404,'message' => 'File data already processed'], 200);
}
}
}
}

View File

@ -132,5 +132,41 @@ if(!function_exists('check_string_date'))
if (!function_exists('generate_download_link')) {
function generate_download_link($rand_string) {
// Generate the link using provided emp_code and client_policy_id
$link = htmlspecialchars(base_url('download-e-card/' . $rand_string));
// Return the link wrapped in anchor tag
// return '<a href="' . $link . '" target="_blank">Click To </a>';
return $link;
}
}
if (!function_exists('generate_random_alphanumeric')) {
function generate_random_alphanumeric($length = 6) {
$random_string = '';
for ($i = 0; $i < $length; $i++) {
$random_ascii = rand(0, 61);
if ($random_ascii < 10) {
$random_character = chr($random_ascii + 48);
} elseif ($random_ascii < 36) {
$random_character = chr($random_ascii + 55);
} else {
$random_character = chr($random_ascii + 61);
}
$random_string .= $random_character;
}
return $random_string;
}
}

View File

@ -30,12 +30,13 @@ class EmployeePolicyModel extends Model
"created_by",
"updated_by",
"updated_at",
"rand_string",
"is_active",
];
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = ["checkAndADDCreatedByValue"];
protected $beforeInsert = ["checkAndADDCreatedByValue", "addRandomNumberBeforeInsert"];
protected $afterInsert = [];
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
protected $afterUpdate = [];
@ -66,6 +67,14 @@ class EmployeePolicyModel extends Model
return $data;
}
protected function addRandomNumberBeforeInsert(array $data)
{
$random_number = generate_random_alphanumeric();
$data['data']['rand_string'] = $random_number;
return $data;
}
// -----------------------------------------------------------------------------------------------------
public function getEmployeePolicy($client_id,$policy_id,$status)
{
@ -737,12 +746,14 @@ class EmployeePolicyModel extends Model
->where('e.is_active', '1')
->where('ep.status', 'active')
->where('ep.is_active', '1')
->where('MD5(e.emp_code)', $emp_code)
->where('MD5(ep.client_policy_id)', $client_policy_id)
->where('e.emp_code', $emp_code)
->where('ep.client_policy_id', $client_policy_id)
->get()
->getResultArray();
return $result;
}
}

View File

@ -70,11 +70,6 @@
<?php } ?>
</table>
<?php if(!isset($data)) { ?>
<a href="<?= htmlspecialchars(base_url('util/digital-id-card/'.md5('EMP004').'/'.md5('12'))) ?>"
target="_blank">button</a>
<?php } ?>
</body>
</html>