From 9efc4a568fce00f7b4f139d1acd33dea92e7f0b5 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 14 Feb 2025 11:59:48 +0530 Subject: [PATCH 1/2] FIX_RFQ_CHANGES : RV --- app/Controllers/ClientController.php | 68 +++-- app/Controllers/EmployeeController.php | 3 +- app/Controllers/LeadsController.php | 378 ++++++++++++++++++++----- app/Models/RFQModel.php | 1 + app/Views/view_rfq.php | 57 +++- 5 files changed, 388 insertions(+), 119 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index d7581c63..1cb8e029 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -187,23 +187,28 @@ class ClientController extends AdminController } //Function for Testing Member Review and Summery Confirmation Mail - public function testingForReviewMail($client_id = 77, $emp_code = 'EMP001-K1', $mail_active = 0) //this function for only tsesting some logics not use for business logic + public function testingForReviewMail($client_id = 77, $emp_code = 'EMP001-K1', $policy_id = "", $mail_active = 0) //this function for only tsesting some logics not use for business logic { - // dd($client_id, $emp_code, $mail_active); + // dd($client_id, $emp_code, $policy_id, $mail_active); - $client_policy_ids = $this->employeeModel - ->select('employee_polices.client_policy_id') - ->join('employee_polices', 'employees.id = employee_polices.employee_id') - ->where('employees.client_id', $client_id ) - ->where('employees.emp_code', $emp_code ) - ->where('employee_polices.is_active', 1 ) - ->where('employees.is_active', 1 ) - ->findAll(); + if(empty($policy_id)){ - $client_policy_ids2 = array_column($client_policy_ids, 'client_policy_id'); + $client_policy_ids = $this->employeeModel + ->select('employee_polices.client_policy_id') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.client_id', $client_id ) + ->where('employees.emp_code', $emp_code ) + ->where('employee_polices.is_active', 1 ) + ->where('employees.is_active', 1 ) + ->findAll(); - $client_policy_id = array_unique($client_policy_ids2); + $client_policy_ids2 = array_column($client_policy_ids, 'client_policy_id'); + $client_policy_id = array_unique($client_policy_ids2); + + }else{ + $client_policy_id = json_decode($policy_id, true); + } // echo '
';
         // dd($client_policy_id);
@@ -259,7 +264,7 @@ class ClientController extends AdminController
                 $wholeData =sendMailNotification::sendMailNotification('member_review_and_summary_mail', $params);
                 // print_r($wholeData); die;
 
-                if($mail_active > 0){
+                if($mail_active == 1){
                     $mail_send_return =  MailHelper::send_email($wholeData[0]);
                     $this->myLogger->logme("info", $mail_send_return);
                 }
@@ -324,19 +329,29 @@ class ClientController extends AdminController
     }
 
     //Function for Send Member Review and Summery Confirmation Mail
-    public function sendMemberReviewConfirmationMail($client_id = 77, $emp_code = 'EMP001-K1', $mail_active = 0)
+    public function sendMemberReviewConfirmationMail($client_id = 77, $emp_code = 'EMP001-K1', $policy_id = "", $mail_active = 0)
     {
-        $client_policy_ids = $this->employeeModel
-            ->select('employee_polices.client_policy_id')
-            ->join('employee_polices', 'employees.id = employee_polices.employee_id')
-            ->where('employees.client_id', $client_id)
-            ->where('employees.emp_code', $emp_code)
-            ->where('employee_polices.is_active', 1)
-            ->where('employees.is_active', 1)
-            ->findAll();
-    
-        $client_policy_ids2 = array_column($client_policy_ids, 'client_policy_id');
-        $client_policy_id = array_unique($client_policy_ids2);
+        // dd($client_id, $emp_code, $policy_id, $mail_active);
+
+        if(empty($policy_id)){
+
+            $client_policy_ids = $this->employeeModel
+                                ->select('employee_polices.client_policy_id')
+                                ->join('employee_polices', 'employees.id = employee_polices.employee_id')
+                                ->where('employees.client_id', $client_id ) 
+                                ->where('employees.emp_code', $emp_code )
+                                ->where('employee_polices.is_active', 1 )
+                                ->where('employees.is_active', 1 )
+                                ->findAll();
+
+            $client_policy_ids2 = array_column($client_policy_ids, 'client_policy_id');
+            $client_policy_id = array_unique($client_policy_ids2);
+
+        }else{
+            $client_policy_id = json_decode($policy_id, true);
+        }
+
+        // dd($client_policy_id);
     
         if (!is_null($client_policy_id) && is_array($client_policy_id)) {
 
@@ -396,8 +411,9 @@ class ClientController extends AdminController
     
                 $wholeData = sendMailNotification::sendMailNotification('member_review_and_summary_mail', $params);
     
-                if ($mail_active > 0) {
+                if ($mail_active == 0) {
 
+                    // $mail_send_result = [];
                     $mail_send_result = MailHelper::send_email($wholeData[0]);
     
                     if ($mail_send_result['status'] === 'success') {
diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php
index e81684f7..09092020 100755
--- a/app/Controllers/EmployeeController.php
+++ b/app/Controllers/EmployeeController.php
@@ -1605,9 +1605,8 @@ class EmployeeController extends AdminController
                     $db = db_connect();
                     $query = "
                                 UPDATE employee_polices 
-                                JOIN employees ON employees.id = employee_polices.employee_id
                                 SET employee_polices.status = 'truncated', employee_polices.is_active = 0 
-                                WHERE employees.file_id = $file_id
+                                WHERE employee_polices.file_id = $file_id
                             ";
                 
                     $db->query($query);
diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php
index d274600b..bea4ebd8 100644
--- a/app/Controllers/LeadsController.php
+++ b/app/Controllers/LeadsController.php
@@ -12,6 +12,8 @@ use PhpOffice\PhpSpreadsheet\Style\Border;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
 use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
 use PhpOffice\PhpSpreadsheet\Style\Fill;
+use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
+use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
 
 use App\Models\UserModel;
 use App\Models\ClientModel;
@@ -31,7 +33,7 @@ use App\Helpers\MailHelper;
 use App\Helpers\ExcelMergeHelper;
 use App\Helpers\ExcelSanitizeHelper;
 use Google\Service\CloudSearch\PushItem;
-use Kint;
+use Kint\Kint;
 
 use App\Controllers\Jobs;
 use App\Controllers\JobWorker;
@@ -435,7 +437,9 @@ class LeadsController extends BaseController
                 ->where('lead_id', $id)
                 // ->where('type', $type)
                 ->where('is_active', 1)
+                ->orderBy('id', 'desc')
                 ->first();
+        // dd($data);
 
         $data['rfq_count'] = $this->RFQModel
                 ->where('lead_id', $id)
@@ -453,8 +457,15 @@ class LeadsController extends BaseController
 
         $data['lead_id'] = $id;
         $lead_data = $this->leadsModel
-                ->select('leads.*, policy_type.question_json, policy_type.policy_type')
+                ->select('
+                    leads.*, 
+                    policy_type.question_json, 
+                    policy_type.policy_type,
+                    policy_type.long_name, 
+                    user_profiles.email as created_person_email
+                ')
                 ->join('policy_type', 'leads.policy_type_id = policy_type.id')
+                ->join('user_profiles', 'leads.created_by = user_profiles.id', 'left')
                 ->where('leads.id', $id)
                 ->where('leads.is_active', 1)
                 ->first();
@@ -472,7 +483,21 @@ class LeadsController extends BaseController
         $data['userList'] = $this->userModel->getUserListForRFQ();
         $data['lead_data'] = $lead_data;
 
-        $data['mail_content'] = $this->transformMailContent($id);
+        $mail_content = "
+            

Dear Sir,

+

Greetings From Nhance India!

+

Please find attached the {{RFQ_OR_QCR}} for {{POLICY_TYPE}} policy pertaining to {{CLIENT_NAME}}.

+

Kindly request you to share the competitive quotes at the earliest.

+

In case of any query, please feel free to contact us.

+

Thank You!

+ "; + + + $subject = "{{CLIENT_NAME}} _ {{POLICY_TYPE}} _ {{RFQ_OR_QCR}} _ {{POLICY_YEAR}}"; + + $data['mail_content'] = $this->transformMailContent($lead_data, $mail_content, $data['page_name']); + $data['subject'] = $this->transformMailContent($lead_data, $subject, $data['page_name']); + // dd($data); $this->loadLayout('view_rfq.php', $data); @@ -591,13 +616,13 @@ class LeadsController extends BaseController public function constructExcelToSaveTemp($lead_id, $type, $propsal_and_insurer = null) { $rfq_data = $this->RFQModel->getRFQTableDataWithLeadIDAndType($lead_id, $type); - + // dd($rfq_data, $lead_id, $type, $propsal_and_insurer); // print_r($propsal_and_insurer); die; - if($rfq_data['lead_type'] == 1){ + if ($rfq_data['lead_type'] == 1) { - if($rfq_data['policy_type_id'] == 2){ + if ($rfq_data['policy_type_id'] == 2) { $lead_data = [ 'Insured' => $rfq_data['client_name'], @@ -607,23 +632,22 @@ class LeadsController extends BaseController 'No of Dependents' => $rfq_data['incept_dept_count'], 'Total Lives' => $rfq_data['incept_no_of_lives'], - 'Period of Insurance ' => date('d/m/Y', strtotime($rfq_data['policy_start_date'])).' to '. date('d/m/Y', strtotime($rfq_data['policy_end_date'])), + 'Period of Insurance ' => date('d/m/Y', strtotime($rfq_data['policy_start_date'])) . ' to ' . date('d/m/Y', strtotime($rfq_data['policy_end_date'])), 'Policy Run Days' => $rfq_data['policy_run_days'], ]; - }else if($rfq_data['policy_type_id'] == 1){ + } else if ($rfq_data['policy_type_id'] == 1) { $lead_data = [ 'Insured' => $rfq_data['client_name'], 'No of Employees at Inception' => $rfq_data['incept_emp_count'], 'Total Sum Insured at Inception ' => $rfq_data['total_si_at_incept'], - 'Policy Period' => date('d/m/Y', strtotime($rfq_data['policy_start_date'])).' to '. date('d/m/Y', strtotime($rfq_data['policy_end_date'])), + 'Policy Period' => date('d/m/Y', strtotime($rfq_data['policy_start_date'])) . ' to ' . date('d/m/Y', strtotime($rfq_data['policy_end_date'])), 'Policy Status' => $rfq_data['status'], 'Existing Insurer' => $rfq_data['insurer_name'], 'TPA ' => $rfq_data['tpa_name'], ]; } - - }else{ - if($rfq_data['policy_type_id'] == 2){ + } else { + if ($rfq_data['policy_type_id'] == 2) { $lead_data = [ 'Insured' => $rfq_data['client_name'], @@ -641,7 +665,7 @@ class LeadsController extends BaseController 'No of Dependents at Renewal' => $rfq_data['renewal_dept_count'], 'Total Lives at Renewal ' => $rfq_data['renewal_no_of_lives'], - 'Period of Insurance ' => date('d/m/Y', strtotime($rfq_data['policy_start_date'])).' to '. date('d/m/Y', strtotime($rfq_data['policy_end_date'])), + 'Period of Insurance ' => date('d/m/Y', strtotime($rfq_data['policy_start_date'])) . ' to ' . date('d/m/Y', strtotime($rfq_data['policy_end_date'])), 'Policy Run Days' => $rfq_data['policy_run_days'], 'Inception Premium' => $rfq_data['premium_at_inception'], 'Premium as on (Date - DD MM YYYY should be entered based on the claims dump report)' => $rfq_data['premium_date'], @@ -651,12 +675,12 @@ class LeadsController extends BaseController 'Incurred Claims Ratio' => $rfq_data['incurred_claims_ratio'], 'Earned Claims Ratio' => $rfq_data['earned_claims_ratio'], ]; - }else if($rfq_data['policy_type_id'] == 1){ + } else if ($rfq_data['policy_type_id'] == 1) { $lead_data = [ 'Insured' => $rfq_data['client_name'], 'No of Employees at Renewal' => $rfq_data['renewal_emp_count'], 'Total Sum Insured at Renewal ' => $rfq_data['total_si_at_renewal'], - 'Policy Period' => date('d/m/Y', strtotime($rfq_data['policy_start_date'])).' to '. date('d/m/Y', strtotime($rfq_data['policy_end_date'])), + 'Policy Period' => date('d/m/Y', strtotime($rfq_data['policy_start_date'])) . ' to ' . date('d/m/Y', strtotime($rfq_data['policy_end_date'])), 'Policy Status' => $rfq_data['status'], 'Existing Insurer' => $rfq_data['insurer_name'], 'TPA ' => $rfq_data['tpa_name'], @@ -665,14 +689,15 @@ class LeadsController extends BaseController } $data = json_decode($rfq_data['json'], true); + // dd($data); - if($type == 2){ + if ($type == 2) { $data = $this->convertJsonForQCR($data, $type); - if($propsal_and_insurer !== null){ + if ($propsal_and_insurer !== null) { list($proposal_key, $insurer_key) = explode('-', $propsal_and_insurer, 2); $data = $this->transformProposelData($data, $proposal_key, $insurer_key); } - }else if($type == 1){ + } else if ($type == 1) { $data = $this->convertJsonForQCR($data, $type); // dd($data); } @@ -680,17 +705,123 @@ class LeadsController extends BaseController $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); + // Start with lead_data at the top $rowNumber = 1; + + $mergeRange1 = "A{$rowNumber}:C{$rowNumber}"; + $sheet->mergeCells($mergeRange1); + $sheet->setCellValue("A{$rowNumber}", "Nhance India Insurance Broking Pvt Ltd"); + $sheet->getStyle("A{$rowNumber}")->applyFromArray([ + 'font' => [ + 'bold' => true, + 'size' => 20 + ], + 'alignment' => [ + 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, + 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER, + ], + ]); + + // Set column width to fit the image properly + $sheet->getColumnDimension('D')->setWidth(20); // Adjust as needed + $sheet->getRowDimension($rowNumber)->setRowHeight(40); // Adjust as needed + + $drawing = new Drawing(); + $path = ROOTPATH . "public/assets/images/Nhance-Logo-Final.png"; // Use FCPATH for server path + $drawing->setPath($path); + $drawing->setCoordinates("D{$rowNumber}"); // Set position in column B + $drawing->setHeight(35); // Adjust image height + + // Center align the image in the cell + $drawing->setOffsetX(30); // Adjust horizontal offset + $drawing->setOffsetY(5); // Adjust vertical offset + + $drawing->setWorksheet($sheet); + + // Apply center alignment to the cell + $sheet->getStyle("D{$rowNumber}")->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); + $sheet->getStyle("D{$rowNumber}")->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER); + + + $rowNumber = $rowNumber + 1; + + // Initialize max width tracking variables + $maxWidthA = 0; + $maxWidthB = 0; + foreach ($lead_data as $key => $value) { + + // Merge A:B for key and C:D for value + $mergeRangeKey = "A{$rowNumber}:B{$rowNumber}"; + $mergeRangeValue = "C{$rowNumber}:D{$rowNumber}"; + $sheet->mergeCells($mergeRangeKey); + $sheet->mergeCells($mergeRangeValue); + + // Set values in merged cells $sheet->setCellValue("A{$rowNumber}", $key); - $sheet->setCellValue("B{$rowNumber}", $value); - $sheet->getStyle("A{$rowNumber}")->applyFromArray(['font' => ['bold' => true]]); + $sheet->setCellValue("C{$rowNumber}", $value); + + // Apply styles for alignment and bold text in A:B + $sheet->getStyle($mergeRangeKey)->applyFromArray([ + 'font' => ['bold' => true], + 'alignment' => [ + 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, + 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER, + ], + ]); + + // Apply bold style to B column if the key is "Insured" + if ($key == "Insured") { + $sheet->getStyle("C{$rowNumber}")->applyFromArray([ + 'font' => ['bold' => true], + ]); + } + + // Track max width needed for columns + $maxWidthA = max($maxWidthA, mb_strlen($key)); + $maxWidthB = max($maxWidthB, mb_strlen($value)); + $rowNumber++; } - $leadRange = "A1:B" . (count($lead_data)); - $sheet->getStyle($leadRange)->applyFromArray([ + // Set column width based on max content length (adjusted for padding) + $sheet->getColumnDimension('A')->setWidth($maxWidthA * 1.2); + $sheet->getColumnDimension('B')->setWidth($maxWidthA * 1.2); + $sheet->getColumnDimension('C')->setWidth($maxWidthB * 1.2); + $sheet->getColumnDimension('D')->setWidth($maxWidthB * 1.2); + + // $rowNumber += 2; + + // Add headers and subheaders + $headers = $data['table_data']['headers']; + + $sheet->setCellValue("A{$rowNumber}", "Details of Coverage"); + $sheet->getStyle("A{$rowNumber}")->applyFromArray([ + 'font' => [ + 'bold' => true, + ], + 'fill' => [ + 'fillType' => Fill::FILL_SOLID, + 'startColor' => ['rgb' => 'ADD8E6'], + ], + 'borders' => [ + 'allBorders' => [ + 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, + 'color' => ['argb' => 'FF000000'], // Black color + ], + ], + ]); + $subheader_count = array_sum(array_map(fn($header) => count($header['subHeaders']), $data['table_data']['headers'])); + $subheader_count = $subheader_count - 2; + $headerCount = count($data['table_data']['headers']); + $lastColumn = Coordinate::stringFromColumnIndex($subheader_count); + // dd( $headerCount, $lastColumn); + + // Merge cells from A to the last column + $mergeRange = "A{$rowNumber}:{$lastColumn}{$rowNumber}"; + + $sheet->getStyle($mergeRange)->applyFromArray([ 'borders' => [ 'allBorders' => [ 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, @@ -699,21 +830,25 @@ class LeadsController extends BaseController ], ]); + $sheet->mergeCells($mergeRange); + $rowNumber = $rowNumber + 1; - $rowNumber += 2; - - // Add headers and subheaders - $headers = $data['table_data']['headers']; $subHeaderRow = $rowNumber + 1; $columnLetter = 'A'; foreach ($headers as $header) { + if (in_array($header['parentHeader'], ['Item Key', 'Action'])) { continue; } if ($header['parentHeader'] === 'Sno') { $header['parentHeader'] = 'S.No.'; + $sheet->getColumnDimension('A')->setWidth(10); + } + + if ($header['parentHeader'] === 'Particulars') { + $sheet->getColumnDimension('B')->setWidth(40); } $startColumn = $columnLetter; // Start of the current header range @@ -740,6 +875,13 @@ class LeadsController extends BaseController // Add subheaders foreach ($header['subHeaders'] as $subHeader) { $sheet->setCellValue("{$columnLetter}{$subHeaderRow}", $subHeader); + + if ($columnLetter != "A" && $columnLetter != "B" && $columnLetter != "C" && $columnLetter != "D") { + $sheet->getColumnDimension($columnLetter)->setWidth(35); + } else { + $sheet->getColumnDimension('A')->setWidth(10); + } + $sheet->getStyle("{$columnLetter}{$subHeaderRow}")->applyFromArray([ 'font' => ['bold' => true], 'alignment' => [ @@ -763,12 +905,13 @@ class LeadsController extends BaseController ]); // Increase row height for headers and subheaders - $sheet->getRowDimension($rowNumber)->setRowHeight(30); // Header row height - $sheet->getRowDimension($subHeaderRow)->setRowHeight(25); // Subheader row height + $sheet->getRowDimension($rowNumber)->setRowHeight(25); // Header row height + $sheet->getRowDimension($subHeaderRow)->setRowHeight(20); // Subheader row height $rowNumber = $subHeaderRow + 2; $column_data = $data['table_data']['data']; $serial_no = 1; + $maxColumnWidths = []; // Add table data rows foreach ($column_data as $dataRow) { @@ -806,6 +949,7 @@ class LeadsController extends BaseController $rowNumber += 2; // Add premium data + // dd($data); $labelArray = ["Premium", "GST (%)", "GST Amount (₹)", "Total"]; $premiumData = $data['premium_data']['data']; $premium = [$labelArray[0]]; @@ -814,7 +958,7 @@ class LeadsController extends BaseController $total = [$labelArray[3]]; foreach ($premiumData as $proposal => $insurers) { - if($proposal != 'Particulars'){ + if ($proposal != 'Particulars') { foreach ($insurers as $insurer => $values) { $premium[] = $values[$labelArray[0]]; $gst[] = $values[$labelArray[1]]; @@ -836,7 +980,8 @@ class LeadsController extends BaseController $rowNumber++; } - $premiumRange = "B" . ($rowNumber - 3) . ":" . chr(ord($columnLetter) - 1) . ($rowNumber - 1); + $premiumRange = "B" . ($rowNumber - 4) . ":" . chr(ord($columnLetter) - 2) . ($rowNumber - 1); + // dd($premiumRange); $sheet->getStyle($premiumRange)->applyFromArray([ 'borders' => [ 'allBorders' => [ @@ -848,10 +993,53 @@ class LeadsController extends BaseController } // Auto-size columns - foreach ($sheet->getColumnIterator() as $column) { - $sheet->getColumnDimension($column->getColumnIndex())->setAutoSize(true); + // foreach ($sheet->getColumnIterator() as $column) { + // $sheet->getColumnDimension($column->getColumnIndex())->setAutoSize(true); + // } + + $dataRange = $sheet->calculateWorksheetDimension(); + + $sheet->getStyle($dataRange)->getAlignment() + ->setHorizontal(Alignment::HORIZONTAL_CENTER) + ->setVertical(Alignment::VERTICAL_CENTER) + ->setWrapText(true); + + $sheet->getStyle('A1')->applyFromArray([ + 'alignment' => [ + 'wrapText' => false, // Disables text wrapping for A1 + ], + ]); + + // Apply border to the entire sheet + preg_match('/([A-Z]+)(\d+):([A-Z]+)(\d+)/', $dataRange, $matches); + + if ($matches) { + $startColumn = $matches[1]; // A + $startRow = $matches[2]; // 1 + $endColumn = $matches[3]; // G + $endRow = $matches[4]; // 75 + + // Convert column letter to index, reduce by 1, and convert back + $endColumnIndex = Coordinate::columnIndexFromString($endColumn) - 1; + $newEndColumn = Coordinate::stringFromColumnIndex($endColumnIndex); + + // Generate the new range (e.g., "A1:F75" instead of "A1:G75") + $newDataRange = "{$startColumn}{$startRow}:{$newEndColumn}{$endRow}"; + // $sheet->getStyle($newDataRange)->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN); } + $lastRow = count($lead_data) + 1; + $leadRange = "A1:D{$lastRow}"; + + $sheet->getStyle($leadRange)->applyFromArray([ + 'borders' => [ + 'allBorders' => [ + 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, + 'color' => ['argb' => 'FF000000'], // Black color + ], + ], + ]); + // Set filename $string = ($type == 2) ? 'QCR' : 'RFQ'; $filename = "{$string}_{$rfq_data['client_short_name']}_{$rfq_data['policy_type']}_" . date('YmdHis') . '.xlsx'; @@ -1495,8 +1683,10 @@ class LeadsController extends BaseController $message = str_replace("{{DURATION}}", calculate_days_bw_dates($lead_data['policy_end_date'] ?? "", $lead_data['policy_start_date'] ?? "")->days, $message) ?? '--'; // print_rr($message);calculate_days_bw_dates + $string = implode(", ", $cc_mails); + $bcc_string = implode(", ", $bcc_mails); - $res = MailHelper::send_email(['mail' => $recipient['email'], 'cc' => $cc_mails, 'subject' => $subject, 'message' => $message, 'attachments' => $attachments, 'reply_to' => $reply_to, 'bcc' => $bcc_mails]); + $res = MailHelper::send_email(['mail' => $recipient['email'], 'cc' => $string, 'subject' => $subject, 'message' => $message, 'attachments' => $attachments, 'reply_to' => $reply_to, 'bcc' => $bcc_string]); // !dd($res); $result_data[] = ['mail' => $recipient['email'], 'status' => $res]; } @@ -2053,54 +2243,90 @@ class LeadsController extends BaseController //------------------------------------------------------------------------------------------------ - public function transformMailContent($lead_id) + // public function transformMailContent($lead_id, $page_name) + // { + // helper('excel_util_helper'); + // // $params = $this->request->getGet(); + + // // print_r($params); die; + // // $lead_id = $params['lead_id']; + // // $file_type = $params['file_type']; //rfq or qcr + // // $recipient_type = $params['recipient_type']; //insurer or client or internal or placement + // // $recipient_mail = $params['recipient_mail']; // - only primary key of contacts + // // $propsal_and_insurer = isset($params['proposal_insurer']) ? $params['proposal_insurer'] : null; + + // // if ($recipient_type == 'insurer' && empty($recipient_mail)) { + // // return $this->respond(['status' => 'failed', 'code' => 400, 'data' => '', 'messgae' => 'Recipient mail not found ! '], 200); + // // } + + // //gather lead info + // $lead_data = $this->leadsModel + // ->select('leads.*,policy_type.long_name,policy_type.policy_type,user_profiles.email as created_person_email') + // ->join('policy_type', 'leads.policy_type_id = policy_type.id', 'left') + // ->join('user_profiles', 'leads.created_by = user_profiles.id', 'left') + // ->where('leads.id', $lead_id) + // ->first(); + + // // dd($lead_data); + + // if($lead_data){ + + // $recipient_data = ['name' => "Team"]; + // // $original_message = '

Request for Quotation (RFQ)

Dear {{RECIPIENT_NAME}},

We are reaching out to request a quotation for the following insurance coverage. Please review the details below and provide your quote at your earliest convenience.

RFQ Details

Client name{{CLIENT_NAME}}
Coverage Type{{POLICY_LONG_NAME}}
Policy Start Date{{POLICY_START_DATE}}
Policy Duration{{DURATION}}
Please note: Additional terms and details are included in the attachment for your reference.

Please feel free to reach out if you require any further information to prepare the quote. We look forward to receiving your proposal.

Best regards,

Nhance India Pvt Ltd

© Nhance India Pvt Ltd. All rights reserved.

'; + // $original_message = `Dear Sir, + + // Greetings From Nhance India! + + // Please find attached the RFQ for {{POLICY_TYPE}} policy pertaining to {{RECIPIENT_NAME}} + // Kindly request you to share the competitive quotes at the earliest + // In case of any query, Please feel free to contact us. + // Thank You !`; + + // $message = $original_message; + // $message = str_replace("{{RECIPIENT_NAME}}", $lead_data['client_name'], $message); + // $message = str_replace("{{POLICY_LONG_NAME}}", $lead_data['long_name'] ?? $lead_data['policy_type'], $message); + // $message = str_replace("{{POLICY_TYPE}}", $lead_data['policy_type'], $message); + // $message = str_replace("{{RFQ_OR_QCR}}", $page_name, $message); + + // $message = str_replace("{{CLIENT_NAME}}", $lead_data['client_name'], $message); + // $message = str_replace("{{POLICY_START_DATE}}", change_date_format($lead_data['policy_start_date'], 'Y-m-d', 'd-m-Y'), $message); + // $message = str_replace("{{DURATION}}", calculate_days_bw_dates($lead_data['policy_end_date'] ?? "", $lead_data['policy_start_date'] ?? "")->days, $message) ?? '--'; + + // dd($message); + // // return $this->respond(['status' => true, 'code' => 200, 'data' => $message], 200); + // return $message; + + // }else{ + + // // return $this->respond(['status' => false, 'code' => 404, 'message' => "This lead has not data"], 200); + // return ''; + // } + + + + // } + + public function transformMailContent($lead_data, $mail_content, $page_name) { - helper('excel_util_helper'); - // $params = $this->request->getGet(); + $current_year = date('Y'); + $next_year = $current_year + 1; + $policy_year = "$current_year-$next_year"; - // print_r($params); die; - // $lead_id = $params['lead_id']; - // $file_type = $params['file_type']; //rfq or qcr - // $recipient_type = $params['recipient_type']; //insurer or client or internal or placement - // $recipient_mail = $params['recipient_mail']; // - only primary key of contacts - // $propsal_and_insurer = isset($params['proposal_insurer']) ? $params['proposal_insurer'] : null; + if ($lead_data) { + + // Replacing placeholders with actual values + $message = $mail_content; + $message = str_replace("{{CLIENT_NAME}}", $lead_data['client_name'] ?? "Valued Client", $message); + $message = str_replace("{{POLICY_LONG_NAME}}", $lead_data['long_name'] ?? $lead_data['policy_type'] ?? "Insurance Policy", $message); + $message = str_replace("{{POLICY_TYPE}}", $lead_data['policy_type'] ?? "Insurance Policy", $message); + $message = str_replace("{{RFQ_OR_QCR}}", $page_name, $message); + $message = str_replace("{{POLICY_YEAR}}", $policy_year, $message); - // if ($recipient_type == 'insurer' && empty($recipient_mail)) { - // return $this->respond(['status' => 'failed', 'code' => 400, 'data' => '', 'messgae' => 'Recipient mail not found ! '], 200); - // } - - //gather lead info - $lead_data = $this->leadsModel - ->select('leads.*,policy_type.long_name,policy_type.policy_type,user_profiles.email as created_person_email') - ->join('policy_type', 'leads.policy_type_id = policy_type.id', 'left') - ->join('user_profiles', 'leads.created_by = user_profiles.id', 'left') - ->where('leads.id', $lead_id) - ->first(); - - // dd($lead_data); - - if($lead_data){ - - $recipient_data = ['name' => "Team"]; - $original_message = '

Request for Quotation (RFQ)

Dear {{RECIPIENT_NAME}},

We are reaching out to request a quotation for the following insurance coverage. Please review the details below and provide your quote at your earliest convenience.

RFQ Details

Client name{{CLIENT_NAME}}
Coverage Type{{POLICY_LONG_NAME}}
Policy Start Date{{POLICY_START_DATE}}
Policy Duration{{DURATION}}
Please note: Additional terms and details are included in the attachment for your reference.

Please feel free to reach out if you require any further information to prepare the quote. We look forward to receiving your proposal.

Best regards,

Nhance India Pvt Ltd

© Nhance India Pvt Ltd. All rights reserved.

'; - - $message = $original_message; - $message = str_replace("{{RECIPIENT_NAME}}", $recipient_data['name'], $message); - $message = str_replace("{{CLIENT_NAME}}", $lead_data['client_name'], $message); - $message = str_replace("{{POLICY_LONG_NAME}}", $lead_data['long_name'], $message); - $message = str_replace("{{POLICY_START_DATE}}", change_date_format($lead_data['policy_start_date'], 'Y-m-d', 'd-m-Y'), $message); - $message = str_replace("{{DURATION}}", calculate_days_bw_dates($lead_data['policy_end_date'] ?? "", $lead_data['policy_start_date'] ?? "")->days, $message) ?? '--'; - - // return $this->respond(['status' => true, 'code' => 200, 'data' => $message], 200); return $message; - }else{ - - // return $this->respond(['status' => false, 'code' => 404, 'message' => "This lead has not data"], 200); - return ''; + } else { + return ''; // Return empty if no lead data found } - - - } + } diff --git a/app/Models/RFQModel.php b/app/Models/RFQModel.php index 2b1560e0..2e51f2aa 100644 --- a/app/Models/RFQModel.php +++ b/app/Models/RFQModel.php @@ -77,6 +77,7 @@ class RFQModel extends Model ->where('rfq.lead_id', $lead_id) // ->where('rfq.type', $type) ->where('rfq.is_active', 1) + ->orderBy('rfq.id', 'desc') ->first(); } diff --git a/app/Views/view_rfq.php b/app/Views/view_rfq.php index 11dbe2aa..a26313e5 100644 --- a/app/Views/view_rfq.php +++ b/app/Views/view_rfq.php @@ -58,6 +58,7 @@ left: 0; background-color: #bfe0e2; z-index: 2; + width: 10px; } .suggestion-box { @@ -194,6 +195,14 @@ background-color: #f0f0f0; color: #666; } + + table th.action, + table th.disableborder, + table td.action, + table td.disableborder { + border: none !important; + } + @@ -411,9 +420,9 @@ -
+
- + ">
@@ -508,9 +517,9 @@
-
+
- + " placeholder="Enter Subject">
@@ -3150,9 +3159,9 @@ function appendInput(data) { } html += ` -
+
- + '" placeholder="Subject">
`; @@ -3210,9 +3219,9 @@ function appendInput(data) { `; html += ` -
+
- + " type="text" id="mail_subject" class="form-control" placeholder="Subject">
`; @@ -3589,7 +3598,7 @@ function ajaxRequest(formData) { $('#cc').val('').select2({ placeholder : 'select CC Mail' }); - $('#subject').val(''); + // $('#subject').val(''); $('#proposals').val(''); $('#placement_to').val('').select2({ placeholder : 'select To Mail' @@ -3666,7 +3675,7 @@ $('.close').click(function(){ $('#cc').val('').select2({ placeholder : 'select CC Mail' }); - $('#subject').val(''); + // $('#subject').val(''); $('#proposals').val(''); $('#placement_to').val('').select2({ placeholder : 'select To Mail' @@ -4454,7 +4463,7 @@ function jsonToTable(json) { //Premium Calculation child table function populateTable(json) { - console.log(json); + console.log('populateTable json data', json); const table = document.getElementById("rfqTable_for_calc"); const thead = document.createElement("thead"); @@ -4471,7 +4480,7 @@ function populateTable(json) { let randomColor = 'hsl(' + Math.random() * 360 + ', 100%, 93%)'; // Skip unwanted parent headers - if (!["Item Key", "Action"].includes(header.parentHeader)) { + if (!["Item Key"].includes(header.parentHeader)) { // console.log(header.parentHeader); // Create the parent header @@ -4486,7 +4495,12 @@ function populateTable(json) { th.classList.add('sticky'); } - if(header.parentHeader !== 'Particulars' && header.parentHeader !== 'Sno'){ + if (header.parentHeader === "Action") { + th.classList.add('readonly-select'); + th.textContent = " "; + } + + if(header.parentHeader !== 'Particulars' && header.parentHeader !== 'Sno' && header.parentHeader !== "Action"){ th.style.backgroundColor = randomColor; } // Calculate colspan based on the number of subheaders @@ -4520,7 +4534,12 @@ function populateTable(json) { subTh.classList.add('sticky'); } - if(header.parentHeader != "Particulars" && header.parentHeader !== 'Sno'){ + if (header.parentHeader === "Action") { + subTh.classList.add('readonly-select'); + subTh.textContent = " "; + } + + if(header.parentHeader != "Particulars" && header.parentHeader !== 'Sno' && header.parentHeader !== "Action"){ subTh.style.backgroundColor = randomColor; } @@ -4567,7 +4586,7 @@ function populateTable(json) { // Create a td for each subheader json.table_data.headers.forEach((header, headerIndexForCalc) => { - if (!["Item Key", "Sno", "Particulars", "Action"].includes(header.parentHeader)) { + if (!["Item Key", "Sno", "Particulars"].includes(header.parentHeader)) { header.subHeaders.forEach((value, index) => { // if(value != '-'){ @@ -4581,6 +4600,13 @@ function populateTable(json) { td.setAttribute("contenteditable", "true"); } + if(header.parentHeader == "Action"){ + td.setAttribute("contenteditable", false); + td.classList.add('action'); + td.classList.add('disableborder'); + td.classList.add('readonly-select'); + } + td.classList.add( 'editablecolumnsforcalc', label.toLowerCase().replace(/\s+/g, '').replace(/[%₹()]/g, '') @@ -4595,6 +4621,7 @@ function populateTable(json) { } // td.id = `${label.toLowerCase()}`; + console.log('child table', header.parentHeader); td.textContent = json.premium_data?.data?.[header.parentHeader]?.[value]?.[label] || ""; tr.appendChild(td); // } From 917f0b4769afcf4c5c1f28cfe42d3f76e36adb73 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 14 Feb 2025 16:48:14 +0530 Subject: [PATCH 2/2] FIX_POLICY_LONG_NAME : RV --- app/Controllers/EmployeeRestController.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 0b26b442..40e85cd0 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -2502,7 +2502,7 @@ class EmployeeRestController extends AdminController function getEmployeeActiveOrInactivePolicy() { if($this->request->getGet('type') == 'Active'){ $policy_status = 1; }else{ $policy_status = 0; } - $ClientPolicyData = $this->clientPolicyModel->select('client_policy.* , policy_type.policy_type as policy_type,insurers.name as insurer_name,tpa.name as tpa_name,tpa.network_hospitals as network_hospitals_url') + $ClientPolicyData = $this->clientPolicyModel->select('client_policy.* , policy_type.policy_type as policy_type,insurers.name as insurer_name,tpa.name as tpa_name,tpa.network_hospitals as network_hospitals_url, policy_type.long_name as policy_long_name') ->join('insurers', 'client_policy.insurer_id = insurers.id', 'left') ->join('tpa', 'client_policy.tpa_id = tpa.id', 'left') ->join('policy_type', 'client_policy.policy_type_id = policy_type.id', 'left') @@ -2555,13 +2555,15 @@ class EmployeeRestController extends AdminController $data['network_hospitals_url'] = $ClientPolicyValue['network_hospitals_url']; $data['policy_start_date'] = $this->convertDateFormatDisplay($ClientPolicyValue['policy_start_date']); $data['policy_end_date'] = $this->convertDateFormatDisplay($ClientPolicyValue['policy_end_date']); + $data['heading'] = $ClientPolicyValue['policy_long_name']; // $data['policy_terms'] = $terms; - if($ClientPolicyValue['policy_type_id'] == 1){ $data['heading'] = 'Group Personal Accident Coverage'; }else - if($ClientPolicyValue['policy_type_id'] == 2){ $data['heading'] = 'Group Medical Coverage'; }else - if($ClientPolicyValue['policy_type_id'] == 3){ $data['heading'] = 'Group Medical Coverage - Parents'; }else - if($ClientPolicyValue['policy_type_id'] == 4){ $data['heading'] = 'Group Medical Coverage - Top Up'; }else - if($ClientPolicyValue['policy_type_id'] == 5){ $data['heading'] = 'Group Medical Coverage - Parents (Top Up)'; } + // if($ClientPolicyValue['policy_type_id'] == 1){ $data['heading'] = 'Group Personal Accident Coverage'; }else + // if($ClientPolicyValue['policy_type_id'] == 2){ $data['heading'] = 'Group Medical Coverage'; }else + // if($ClientPolicyValue['policy_type_id'] == 3){ $data['heading'] = 'Group Medical Coverage - Parents'; }else + // if($ClientPolicyValue['policy_type_id'] == 4){ $data['heading'] = 'Group Medical Coverage - Top Up'; }else + // if($ClientPolicyValue['policy_type_id'] == 5){ $data['heading'] = 'Group Medical Coverage - Parents (Top Up)'; }else + // if($ClientPolicyValue['policy_type_id'] == 7){ $data['heading'] = 'Group Term Life Insurance'; } if($ClientPolicyValue['policy_type_id'] == 1 || $ClientPolicyValue['policy_type_id'] == 6 || $ClientPolicyValue['policy_type_id'] == 7) {