diff --git a/app/Config/Routes.php b/app/Config/Routes.php index ede8146b..34478d0c 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -19,7 +19,7 @@ $routes->get("update_rack_rate_json", "ClientController::updateRackRateJson"); $routes->get("updatajson", "EmpDataServiceController::updatajson"); $routes->get("view", "EmployeeController::viewECard/$1"); // $routes->get("exportQCRandRFQ", "LeadsController::exportQCRandRFQ"); - +$routes->get("smapletest", "ClientController::smapletest"); $routes->post("add_advertise_image", "AppContentManagementController::add_advertise_image"); @@ -298,10 +298,10 @@ $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"); - }); $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) { @@ -347,6 +347,7 @@ $routes->group("leads", ["filter" => "authMVC"], function ($routes) { $routes->get("list/(:any)", "LeadsController::getLeadDataForEdit/$1"); $routes->get("sendMail", "LeadsController::sendMailWithAttachement"); $routes->get("exportQCRandRFQ/(:any)", "LeadsController::exportQCRandRFQ/$1"); + $routes->get("featchLeadDataAndInsertClient/(:any)", "LeadsController::featchLeadDataAndInsertClient/$1"); }); $routes->group("rfq", ["filter" => "authMVC"], function ($routes) { @@ -371,12 +372,12 @@ $routes->cli('cli/check_bounce_mail_cli', 'MasterController::testCheckBounceMail $routes->cli('cli/app_check_list', 'MasterController::appCheckList'); $routes->cli('cli/new_gdrive_token', 'GoogleDriveController::generateNewGoogleDriveAccessToken'); - //Employee login api's $routes->post("/employeeRest/verifyEmployeeNumber", "RestAuthenticationController::verifyEmployeeWithMobileNumber"); $routes->post("/employeeRest/getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData"); $routes->post("/employeeRest/verifyMpin", "RestAuthenticationController::verifyMpin"); $routes->post("/employeeRest/checkMpin", "RestAuthenticationController::checkMpin"); + //HR login api's $routes->post("/employeeRest/verifyHrWithMobileNumber", "RestAuthenticationController::verifyHrWithMobileNumber"); $routes->post("/employeeRest/getVerifiedHrData", "RestAuthenticationController::getVerifiedHrData"); @@ -386,9 +387,6 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) { $routes->post("getId", "RestAuthenticationController::getUserIdFromToken"); }); - - - $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->post("getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData"); @@ -431,17 +429,9 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { }); $routes->get("sendPushNotification", "EmployeeRestController::sendPushNotification"); - - - - $routes->post("sendEmail", "EmployeeRestController::send_email"); - - - - // Ticketing System // Ticketing System End's diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index c6b3f152..78c8c7a5 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -38,6 +38,7 @@ use App\Models\PolicyTypeModel; use App\Models\PolicyTransactionModel; use App\Models\PolicyTransactionStatusModel; use App\Models\VehicleModel; +use App\Models\LeadsModel; use App\Controllers\EmpDataServiceController; use App\Controllers\GoogleDriveController; @@ -78,6 +79,7 @@ class ClientController extends AdminController protected $policyTransactionModel; protected $policyTransactionStatusModel; protected $vehicleModel; + protected $leadsModel; @@ -113,6 +115,14 @@ class ClientController extends AdminController $this->policyTransactionModel = new PolicyTransactionModel(); $this->policyTransactionStatusModel = new PolicyTransactionStatusModel(); $this->vehicleModel = new VehicleModel(); + $this->leadsModel = new LeadsModel(); + } + + public function smapletest(){ + + $headers = ['S.No','EMP ID','EMP NAME','DOB','GENDER','RELATIONSHIP','SUM INSURED','Date of Leaving','Policy End Date','No Of Days','Premium','Pro Rata Premium','GST','Total','Claim Status','ENDORSEMENT_ID']; + $filePath = generateExcelWithHeader($headers); + echo "Excel file created at: $filePath"; } public function testingForReviewMail($client_id = 77, $emp_code = 'MGL-004', $mail_active = 0) //this function for only tsesting some logics not use for business logic @@ -238,6 +248,7 @@ class ClientController extends AdminController $headerData['page_name'] = 'Client List'; $data['clientList'] = $this->clientModel->getCreatedByUserName(); $data['client_rm'] = $this->clientRMModel->getAllClientRM(); + $data['lead_data'] = $this->leadsModel->getLeadForInsertClientList(); // dd($data); @@ -1705,15 +1716,6 @@ class ClientController extends AdminController } - public function editUploadVehicleFile() {} - - public function listVehicleFiles() {} - - public function deleteVehicleFiles() {} - - - - public function getKycDocsById($id = null) { 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 569f1c65..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'], @@ -1417,7 +1415,11 @@ class EmployeeController extends AdminController $excelErrorData['excel_header'] = $excel_data[0]; unset($excel_data[0]); - if($event_type == 'inception' || $event_type == 'deletion'){ + // if($event_type == 'inception' || $event_type == 'deletion'){ + // array_pop($excel_data); + // } + + if($event_type == 'deletion'){ array_pop($excel_data); } 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/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index d359c7d9..2d4a68ef 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -215,6 +215,7 @@ class LeadsController extends BaseController 'branch_code' => $data['branch_code'], 'contact_person_name' => $data['contact_person_name'], 'contact_person_mobile' => $data['contact_person_mobile'], + 'contact_person_email' => $data['contact_person_email'], 'client_id' => $data['client_id'] ?? 0, 'client_branch_id' => $data['client_branch_id'] ?? 0, 'source_policy_id' => $data['source_policy_id'] ?? 0, @@ -394,8 +395,10 @@ class LeadsController extends BaseController return $this->respond(['status' => false, 'id' => $result, 'message' => "Failed to create QCR", 'data' =>$data], 200); } + //-----RFQ and QCR EXPORT------------------------------------------------------------------------------------------------ + //export main route function public function exportQCRandRFQ($lead_id, $type, $export_type){ @@ -654,7 +657,8 @@ class LeadsController extends BaseController } - public function getLevelContects(){ + public function getLevelContects() + { $data = $this->levelContactModel->getContectForRFQ(); @@ -667,4 +671,134 @@ class LeadsController extends BaseController } + //----- Featch Lead data and insert Client ------------------------------------------------------------------------------------------- + + + + public function featchLeadDataAndInsertClient($lead_id) + { + $data = $this->leadsModel->where('leads.id', $lead_id)->where('leads.is_active', 1)->first(); + + if (!$data) { + return $this->respond(['status' => false, 'message' => 'Failed to create Client', 'data' => null], 200); + } + + $result = $this->createClientWithLeadData($data); + + if ($result) { + return $this->respond(['status' => true, 'message' => 'New Client created successfully', 'client_id' => $result, 'data' => $data], 200); + } + + return $this->respond(['status' => false, 'message' => 'Failed to create client', 'data' => $data], 200); + } + + public function createClientWithLeadData($data) + { + $client_data = $this->prepareClientData($data); + $client_id = $this->clientModel->insert($client_data); + + if ($client_id) { + $this->createClientBranchAndContactWithLeadData($data, $client_id); + } + + return $client_id; + } + + private function prepareClientData($data) + { + return [ + 'client_type' => $data['client_type'], + 'entity_type_id' => $data['entity_type_id'], + 'client_code' => $data['client_code'], + 'client_name' => $data['client_name'], + 'short_name' => $data['client_short_name'], + 'pan' => $data['pan'], + ]; + } + + public function createClientBranchAndContactWithLeadData($data, $client_id) + { + $branch_data = $this->prepareClientBranchData($data, $client_id); + $branch_id = $this->clientBranchModel->insert($branch_data); + + if ($branch_id) { + + $contact_data = $this->prepareContactData($data, $branch_id); + $this->levelContactModel->insert($contact_data); + + $this->createClientPolicyWithLeadData($data, $client_id, $branch_id); + } + + return $branch_id; + } + + + private function prepareClientBranchData($data, $client_id) + { + $default_unit = trim(($data['client_short_name'] ?? '') . '-' . ($data['branch_code'] ?? ''), '-'); + + return [ + 'client_id' => $client_id, + 'branch_name' => $data['branch_name'], + 'branch_code' => $data['branch_code'], + 'gst' => $data['gst'], + 'units' => json_encode([$default_unit]), + ]; + } + + private function prepareContactData($data, $branch_id) + { + return [ + 'name' => $data['contact_person_name'], + 'mobile' => $data['contact_person_mobile'], + 'email' => $data['contact_person_email'], + 'contact_type' => 'client', + 'ref_id' => $branch_id, + ]; + } + + public function createClientPolicyWithLeadData($data, $client_id, $branch_id) + { + $client_policy_data = $this->prepareClientPolicyData($data, $client_id, $branch_id); + return $this->clientPolicyModel->insert($client_policy_data); + } + + private function prepareClientPolicyData($data, $client_id, $branch_id) + { + $client_policy_data = [ + 'client_id' => $client_id, + 'client_branch_id' => $branch_id, + 'policy_type_id' => $data['policy_type_id'], + 'insurer_id' => $data['insurer_id'], + 'insurer_branch_id' => $data['insurer_branch_id'], + 'tpa_id' => $data['tpa_id'], + 'tpa_branch_id' => $data['tpa_branch_id'], + 'policy_start_date' => $data['policy_start_date'], + 'policy_end_date' => $data['policy_end_date'], + 'policy_status' => 1, + ]; + + $policy_type_id = $data['policy_type_id']; + if (in_array($policy_type_id, [1, 2, 6, 7])) { + $client_policy_data['is_addon'] = 1; // Base Policy + } elseif (in_array($policy_type_id, [4, 5])) { + $client_policy_data['is_addon'] = 2; // SI TOPUP + } elseif ($policy_type_id == 3) { + // if ($base_policy) { + // $data['is_addon'] = 3; // Dependent Addon + // } else { + $data['is_addon'] = 1; + // } + } + + return $client_policy_data; + } + + private function preparePolicyTermsFromRFQ($data) + { + + } + + + } diff --git a/app/Helpers/excel_import_export_helper.php b/app/Helpers/excel_import_export_helper.php index b7eb87c8..3355253e 100755 --- a/app/Helpers/excel_import_export_helper.php +++ b/app/Helpers/excel_import_export_helper.php @@ -972,3 +972,39 @@ if(!function_exists('query_construct_second_stage')){ } } +if (!function_exists('generateExcelWithHeader')) { + /** + * Generate an Excel file with the specified headers + * + * @param array $header The header row for the Excel file + * @param string $filename The name of the Excel file to be created + * @return string Path to the generated Excel file + */ + function generateExcelWithHeader(array $header, string $filename = 'InceptionHeader.xlsx') + { + // Create a new Spreadsheet + $spreadsheet = new Spreadsheet(); + $sheet = $spreadsheet->getActiveSheet(); + + // Set header row + $column = 'A'; + foreach ($header as $headerText) { + $sheet->setCellValue($column . '1', $headerText); + $column++; + } + + // // Style the header row (optional) + // $sheet->getStyle('A1:' . $column . '1')->getFont()->setBold(true); + // $sheet->getStyle('A1:' . $column . '1')->getAlignment()->setHorizontal('center'); + + // Define the file path + $filePath = WRITEPATH . 'uploads/' . $filename; // WRITEPATH is typically for writable directories + + // Save the file + $writer = new Xlsx($spreadsheet); + $writer->save($filePath); + + return $filePath; + } +} + 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/Models/LeadsModel.php b/app/Models/LeadsModel.php index 9de34d05..705f1587 100644 --- a/app/Models/LeadsModel.php +++ b/app/Models/LeadsModel.php @@ -24,6 +24,7 @@ class LeadsModel extends Model 'branch_code', 'contact_person_name', 'contact_person_mobile', + 'contact_person_email', 'client_id', 'client_branch_id', 'source_policy_id', @@ -85,7 +86,8 @@ class LeadsModel extends Model return $data; } - public function getLeadDataForLising(){ + public function getLeadDataForLising() + { return $this->select(' leads.*, @@ -116,6 +118,14 @@ class LeadsModel extends Model ->findAll(); } + + public function getLeadForInsertClientList() + { + return $this + ->where('leads.is_active', 1) + ->where('leads.status', 'won') + ->findAll(); + } } diff --git a/app/Views/client_list.php b/app/Views/client_list.php index 8d015165..e9499095 100755 --- a/app/Views/client_list.php +++ b/app/Views/client_list.php @@ -26,8 +26,11 @@ table.dataTable thead th {