From cfb3d25c96aa2e3e7fc72f3797879f360527c6da Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Mon, 23 Dec 2024 10:33:09 +0530 Subject: [PATCH 01/11] MERGE_CODE_MERGE : RV --- app/Controllers/LeadsController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index c2b8f2bf..dad5ffb2 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -482,7 +482,7 @@ class LeadsController extends BaseController //FOR EXCEL public function exportExcelForQCRandRFQ($lead_id, $type) { - //$filepath = $this->constructExcelToSaveTemp($lead_id, $type); + $filepath = $this->constructExcelToSaveTemp($lead_id, $type); $filepath = $filepath['filePath']; if (file_exists($filepath)) { @@ -734,10 +734,11 @@ class LeadsController extends BaseController { $lead_id = $params['lead_id']; $lead_data = $this->leadsModel->find($lead_id); + $file_name_with_path = WRITEPATH."/uploads/lead_files/".$lead_data['file_name']; + // print_rr($lead_data); if($lead_data['file_name']) { - $file_name_with_path = WRITEPATH."/uploads/lead_files/".$lead_data['file_name']; //check physical file if(!file_exists($file_name_with_path)) @@ -766,7 +767,7 @@ class LeadsController extends BaseController //check age or dob column $members_heading = $members[0]; - Kint::dump($members_heading); + // Kint::dump($members_heading); $available_col = null; $col_index = null; From 898945893bce73d7d12cfb1bd0aa0c613b1cb899 Mon Sep 17 00:00:00 2001 From: velz Date: Mon, 23 Dec 2024 12:23:42 +0530 Subject: [PATCH 02/11] FIX_BDS --- app/Controllers/PolicyTransactionController.php | 4 ++-- app/Helpers/excel_util_helper.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 9873b33a..054b341b 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -1841,7 +1841,7 @@ class PolicyTransactionController extends BaseController //get no of line items and update in DB $line_items = count($excel_data); // get uploaded month transactions data - $source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(month:$month,year:$year,insurer_id:$file['insurer_id'],insurer_branch_id:$file['branch_id']); + $source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(insurer_id:$file['insurer_id'],insurer_branch_id:$file['branch_id']); // var_dump($source_data);die(); // Kint::dump($source_data);//die(); @@ -1942,7 +1942,7 @@ class PolicyTransactionController extends BaseController //get no of line items and update in DB $line_items = count($excel_data); // get uploaded month transactions data - $source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(month:$month,year:$year,insurer_id:$file['insurer_id'],insurer_branch_id:$file['branch_id']); + $source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(insurer_id:$file['insurer_id'],insurer_branch_id:$file['branch_id']); // Kint::dump($source_data);die; // Kint::dump($excel_data); diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index d1fdf7d2..0cd9afa6 100755 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -979,7 +979,7 @@ if (!function_exists('calculate_premium_new')) 'isEmployeeSourceEnrollment' => $fileArr['id'] == null, 'isEmployeeSourceExcelFile' => $transformed_familiy_member_data['temp']['source'] == 'excel', 'isCurrentActionDependentAddition' => $fileArr['action'] == 'dependent_addition', - // 'isPrimaryGridPremiumTypeSingle' => $transformed_familiy_member_data['temp']['premium_type'] == 1, + 'isPrimaryGridPremiumTypeSingle' => $transformed_familiy_member_data['temp']['premium_type'] == 1, 'isCurrentRelationshipSelf' => (strtolower($transformed_familiy_member_data['relationship']) == 'self' || (isset($transformed_familiy_member_data['temp']['acting_self']) && $transformed_familiy_member_data['temp']['acting_self'] === true)), 'isBasicCoverCalculatedToCurrentEmployee' => ($transformed_familiy_member_data['policy_details']['basic_cover_si'] != null && $transformed_familiy_member_data['policy_details']['basic_cover_si'] != 0) ]; From 942d184914d3f28202f2cb7f84a8e4f9709e39ac Mon Sep 17 00:00:00 2001 From: velz Date: Mon, 23 Dec 2024 17:16:33 +0530 Subject: [PATCH 03/11] FIX_LIVE_ONBOARD_ISSUE --- app/Controllers/EmployeeServiceController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index f94d4f6e..75f24f6e 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -1611,7 +1611,7 @@ class EmployeeServiceController extends AdminController // echo '---------------------------------------'; //start implemet of si enhancement of grid type 10,11 - if(count($employee) && $file['action'] == 'dependent_addition' && $temp['source'] == 'db' && in_array($value['temp']['grid_id'],[10,11]) && ( ($value['temp']['premium_type'] == 1 && (strtolower($value['relationship']) == 'self' || $temp['acting_self'])) || ($value['temp']['premium_type'] == 2 || $value['temp']['premium_type'] == null))) + if(count($employee) && $file['action'] == 'dependent_addition' && $temp['source'] == 'db' && in_array($temp['grid_id'],[10,11]) && ( ($temp['premium_type'] == 1 && (strtolower($value['relationship']) == 'self' || $temp['acting_self'])) || ($temp['premium_type'] == 2 || $temp['premium_type'] == null))) { $log_message = 'Employee record from DB,Checking SI for - '.$employee[0]['name'].'('.$employee[0]['emp_code'].')'; $this->myLogger->logme('error',$log_message); @@ -1620,7 +1620,7 @@ class EmployeeServiceController extends AdminController break;//skip db employee } //end implemet of si enhancement of grid type - + dd('s'); //save employee table $value['relationship'] = ucfirst(trim($value['relationship'])); if(count($employee)) From c92ae834deccd27e2c667fe15b5b899fc6f2dec0 Mon Sep 17 00:00:00 2001 From: velz Date: Tue, 24 Dec 2024 12:29:45 +0530 Subject: [PATCH 04/11] FIX_BDS_CODE_CONFLICT --- .../PolicyTransactionController.php | 98 ++++++++++++++++--- app/Models/PolicyTransactionModel.php | 3 +- app/Views/insurer_statement_list.php | 50 +++++++--- app/Views/report_bds.php | 3 +- 4 files changed, 123 insertions(+), 31 deletions(-) diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 054b341b..d7d2748b 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -31,6 +31,7 @@ use App\Models\InsurerStatements; use App\Models\InvPaymentDetailsModel; use App\Models\BatchFileModel; use App\Models\FileModel; +use App\Models\COShareStmtDetailsModel; use Kint; class PolicyTransactionController extends BaseController @@ -62,6 +63,7 @@ class PolicyTransactionController extends BaseController protected $invPaymentDetailsModel; protected $batchFileModel; protected $filesModel; + protected $coShareStmtDetailsModel; public function __construct() { @@ -91,11 +93,12 @@ class PolicyTransactionController extends BaseController $this->invPaymentDetailsModel = new InvPaymentDetailsModel(); $this->batchFileModel = new BatchFileModel(); $this->filesModel = new FileModel(); + $this->coShareStmtDetailsModel = new COShareStmtDetailsModel(); $this->invoiceStatus = [ 'pending' => 'Pending', 'generated' => 'Generated', 'sent' => 'Sent', - 'payment_received' => 'Payment Received', + 'payment_received' => 'Payment
Received', ]; } @@ -1631,20 +1634,17 @@ class PolicyTransactionController extends BaseController $end_date = $this->request->getGet('end_date'); $client_id = $this->request->getGet('client_id'); $insurer_id = $this->request->getGet('insurer_id'); - $policy_type_id = $this->request->getGet('policy_type_id'); - $date_type = $this->request->getGet('date_type'); - $issuer = $this->request->getGet('issuer'); + $insurer_branch_id = $this->request->getGet('insurer_branch_id'); + + $start_date = (!isset($start_date) || $start_date === '' || $start_date === null) ? 0 : change_date_format($start_date,'d-m-Y','Y-m-01'); + $end_date = (!isset($end_date) || $end_date === '' || $end_date === null) ? 0 : change_date_format($end_date,'d-m-Y','Y-m-31'); + // dd([$start_date,$end_date]); - $start_date = (!isset($start_date) || $start_date === '' || $start_date === null) ? 0 : $start_date; - $end_date = (!isset($end_date) || $end_date === '' || $end_date === null) ? 0 : $end_date; - $client_id = (!isset($client_id) || $client_id === '' || $client_id === null) ? 0 : $client_id; $insurer_id = (!isset($insurer_id) || $insurer_id === '' || $insurer_id === null) ? 0 : $insurer_id; - $policy_type_id = (!isset($policy_type_id) || $policy_type_id === '' || $policy_type_id === null) ? 0 : $policy_type_id; - $date_type = (!isset($date_type) || $date_type === '' || $date_type === null) ? 0 : $date_type; - $issuer = (!isset($issuer) || $issuer === '' || $issuer === null) ? 0 : $issuer; + $insurer_branch_id = (!isset($insurer_branch_id) || $insurer_branch_id === '' || $insurer_branch_id === null) ? 0 : $insurer_branch_id; - $data['outstanting_list'] = $this->policyTransactionModel->getOutstandingReportLIst($start_date, $end_date, $client_id, $insurer_id, $policy_type_id, $date_type, $issuer); + $data['outstanting_list'] = $this->policyTransactionModel->getOutstandingReportLIst($start_date, $end_date,$insurer_id, $insurer_branch_id); // dd($this->policyTransactionModel->getLastQuery()); // dd($data); $this->loadLayout('outstanding_report_list', $data); @@ -1676,7 +1676,7 @@ class PolicyTransactionController extends BaseController WHERE pt_co_share_details.is_active = 1 AND pt_co_share_details.statement_id = insurer_statements.id ) AS exp_inv_amt, - (SELECT SUM(inv_payment_details.inv_amt) + SUM(inv_payment_details.tds) + (SELECT SUM(inv_payment_details.inv_amt) + SUM(inv_payment_details.tds) + SUM(inv_payment_details.gst) FROM inv_payment_details WHERE inv_payment_details.is_active = 1 AND inv_payment_details.statement_id = insurer_statements.id @@ -1749,9 +1749,10 @@ class PolicyTransactionController extends BaseController $month = $month.'-01'; // print_r($month);die; $month = change_date_format($month,'Y-M-d','Y-m-d'); + $stmt_sno = $this->request->getPost('statement_no'); // print_r($month);die; - $file_id = $this->insurerStatements->insert(['insurer_id' => $insurer_id, 'branch_id' => $branch_id, 'file_name' => $filename,'month' => $month, 'created_by' => $loggedInUserID]); //here field policy_id have client_policy_id and not policy id from policy master + $file_id = $this->insurerStatements->insert(['insurer_id' => $insurer_id, 'branch_id' => $branch_id, 'file_name' => $filename,'month' => $month, 'created_by' => $loggedInUserID,'stmt_sno' => $stmt_sno]); //here field policy_id have client_policy_id and not policy id from policy master $this->myLogger->logme("error", '{file_id} statement uploaded success', ['file_id' => $file_id]); //validate file @@ -1839,7 +1840,7 @@ class PolicyTransactionController extends BaseController unset($excel_data[0]); // Kint::dump($excel_data); //get no of line items and update in DB - $line_items = count($excel_data); + $line_items = 0; // get uploaded month transactions data $source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(insurer_id:$file['insurer_id'],insurer_branch_id:$file['branch_id']); // var_dump($source_data);die(); @@ -1866,6 +1867,7 @@ class PolicyTransactionController extends BaseController if( ($policy_no == $source_row['policy_no']) && $endorsement_no == $source_endorsement_no && change_date_format($policy_start_date,'d-m-Y','Y-m-d') == $source_row['policy_start_date'] && change_date_format($policy_end_date,'d-m-Y','Y-m-d') == $source_row['policy_end_date'] && $client_name == $source_row['client_name']) { $is_source_found = 1; + $line_items = $line_items + 1; unset($source_data[$source_key]); continue 2; } @@ -2034,7 +2036,7 @@ class PolicyTransactionController extends BaseController //find variance $variance_amt = $source_row['exp_amt'] - $total_amt; - $data_to_update[] = ['id' => $source_row['id'],'actual_bp_amt' => $actual_bp_amt,'actual_tp_amt' => $actual_tp_amt,'actual_tep_amt' => $actual_tep_amt,'actual_bp_per' => $actual_bp_per,'actual_tp_per' => $actual_tp_per,'actual_tep_per' => $actual_tep_per,'variance' => $variance_amt,'actual_tep_brokerage_amt' => $actual_tep_brokerage,'actual_tp_brokerage_amt' => $actual_tp_brokerage,'actual_bp_brokerage_amt' => $actual_bp_brokerage,'reward' => trim($excel_row[15]),'statement_id' => $file_id]; + $data_to_update[] = ['co_share_id' => $source_row['id'],'actual_bp_amt' => $actual_bp_amt,'actual_tp_amt' => $actual_tp_amt,'actual_tep_amt' => $actual_tep_amt,'actual_bp_per' => $actual_bp_per,'actual_tp_per' => $actual_tp_per,'actual_tep_per' => $actual_tep_per,'variance' => $variance_amt,'actual_tep_brokerage_amt' => $actual_tep_brokerage,'actual_tp_brokerage_amt' => $actual_tp_brokerage,'actual_bp_brokerage_amt' => $actual_bp_brokerage,'reward' => trim($excel_row[15]),'statement_id' => $file_id]; unset($source_data[$source_key]); continue 2; @@ -2044,7 +2046,7 @@ class PolicyTransactionController extends BaseController } } // dd($data_to_update); - $this->PTCOShareDetailsModel->updateBatch($data_to_update, 'id'); + $this->coShareStmtDetailsModel->insertBatch($data_to_update, 'id'); // dd($data_to_update); // if($error_data['error_code']) // { @@ -2066,8 +2068,24 @@ class PolicyTransactionController extends BaseController ->where('is_active',1) ->get() ->getResultArray(); + if(!$inv_details['invoice_value']) + { + $stmt_level_value = $this->coShareStmtDetailsModel->select('sum(actual_tep_brokerage_amt) + sum(actual_tp_brokerage_amt) + sum(actual_bp_brokerage_amt) + sum(reward) as invoice_value') + ->where('statement_id',$statement_id) + ->groupBy('statement_id') + ->get() + ->getResultArray(); + // print_r($stmt_level_value); + if($stmt_level_value && count($stmt_level_value) && isset($stmt_level_value[0])) + { + $inv_details['invoice_value'] = $stmt_level_value[0]['invoice_value']; + } + } // ~dd($inv_details); $data = [ 'invoice_status' => $inv_details['invoice_status'], + 'gst_per' => isset($inv_details['gst_per']) ? $inv_details['gst_per'] : 18 , + 'invoice_value' => $inv_details['invoice_value'], + 'gst_value' => $inv_details['gst_value'], 'invoice_no' => $inv_details['invoice_no'], 'invoice_amount' => $inv_details['invoice_amount'], 'invoice_date' => isset($inv_details['invoice_date']) ? change_date_format($inv_details['invoice_date'],'Y-m-d','d/m/Y') : null ]; @@ -2089,6 +2107,9 @@ class PolicyTransactionController extends BaseController $invoiceNo = $jsonData['invoice_no']; $invoiceDate = change_date_format($jsonData['invoice_date'],'d/m/Y','Y-m-d'); $invoice_amount = $jsonData['invoice_amount']; + $invoice_value = $jsonData['invoice_value']; + $gst_per = $jsonData['invoice_gst_per']; + $gst_value = $jsonData['invoice_gst']; //Update statement table $parentData = [ @@ -2096,6 +2117,9 @@ class PolicyTransactionController extends BaseController 'invoice_no' => $invoiceNo, 'invoice_date' => $invoiceDate, 'invoice_amount' => $invoice_amount, + 'gst_per' => $gst_per, + 'gst_value' => $gst_value, + 'invoice_value' => $invoice_value, 'updated_by' => get_session_userid() ]; @@ -2107,6 +2131,7 @@ class PolicyTransactionController extends BaseController $receivedAmounts = $jsonData['received_amount']; $utrNos = $jsonData['utr_no']; $tdsTotal = $jsonData['tds']; + $gstTotal = $jsonData['gst_amount']; $paymentDates = $jsonData['payment_date']; $pks = $jsonData['pk']; @@ -2114,6 +2139,7 @@ class PolicyTransactionController extends BaseController $pk = $pks[$index]; // Get the pk for the current record $utrNo = $utrNos[$index]; $tds = $tdsTotal[$index]; + $gst = $gstTotal[$index]; $paymentDate = $paymentDates[$index]; // Prepare data for insert/update @@ -2121,6 +2147,7 @@ class PolicyTransactionController extends BaseController 'inv_amt' => $receivedAmount, 'utr_no' => $utrNo, 'tds' => $tds, + 'gst' => $gst, 'received_date' => change_date_format($paymentDate,'d/m/Y','Y-m-d'), 'statement_id' => $hiddenStatementId ]; @@ -2357,6 +2384,45 @@ class PolicyTransactionController extends BaseController return $this->respond(['status' => false, 'code' => 400, 'message' => 'No data found for this CD'], 200); } + + public function getInsurerStatementMonth() + { + $insurer_id = $this->request->getGet('insurer_id'); + $month = $this->request->getGet('month'); + // echo $month; + $insurer_branch_id = explode('-',$insurer_id)[1]; + $insurer_id = explode('-',$insurer_id)[0]; + $month = $month.'-01'; + $month = change_date_format($month,'Y-M-d','Y-m-d'); + // echo $month; + + $res_data = $this->insurerStatements + ->where('insurer_id',$insurer_id) + ->where('branch_id',$insurer_branch_id) + ->where('month', $month) + ->where('is_active', 1) + ->where('file_status', 'success') + ->findAll(); + + return $this->respond(['dataStatus' => true, 'code' => 200,'data' => $res_data], 200); + + + } + + public function deleteStatement($id) + { + // echo $id;die(); + $this->coShareStmtDetailsModel->where('statement_id',$id) + ->set(['is_active' => 0]) + ->update(); + $this->invPaymentDetailsModel->where('statement_id',$id) + ->set(['is_active' => 0]) + ->update(); + $this->insurerStatements->where('id',$id) + ->set(['is_active' => 0]) + ->update(); + return $this->respond(['dataStatus' => true, 'code' => 200], 200); + } } \ No newline at end of file diff --git a/app/Models/PolicyTransactionModel.php b/app/Models/PolicyTransactionModel.php index d87d3f45..8ab22397 100644 --- a/app/Models/PolicyTransactionModel.php +++ b/app/Models/PolicyTransactionModel.php @@ -399,6 +399,7 @@ class PolicyTransactionModel extends Model WHERE co_share_stmt_details.co_share_id = pt_co_share_details.id AND co_share_stmt_details.is_active = 1 + AND insurer_statements.is_active = 1 $date_condition ), 2 @@ -465,7 +466,7 @@ class PolicyTransactionModel extends Model AND co_share_stmt_details.is_active = 1 AND pt_table.is_active = 1 AND insurer_statements.is_active = 1 - AND insurer_statements.invoice_no IS NOT NULL + AND insurer_statements.invoice_no IS NULL $date_condition ) ), diff --git a/app/Views/insurer_statement_list.php b/app/Views/insurer_statement_list.php index cc21636b..328e65db 100644 --- a/app/Views/insurer_statement_list.php +++ b/app/Views/insurer_statement_list.php @@ -441,6 +441,7 @@ table.dataTable tbody td { switchRequired('received_amount',false,'name'); switchRequired('tds',false,'name'); + switchRequired('gst_amount',false,'name'); switchRequired('utr_no',false,'name'); switchRequired('payment_date',false,'name'); switchRequired('pk',false,'name'); @@ -458,6 +459,7 @@ table.dataTable tbody td { switchRequired('received_amount',true,'name'); switchRequired('utr_no',true,'name'); switchRequired('tds',true,'name'); + switchRequired('gst_amount',true,'name'); switchRequired('payment_date',true,'name'); switchRequired('pk',true,'name'); }else if(invoiceStatus === 'pending') @@ -476,8 +478,11 @@ table.dataTable tbody td { switchRequired('payment_date',false,'name'); switchRequired('pk',false,'name'); switchRequired('tds',false,'name'); + switchRequired('gst_amount',false,'name'); } + + calcGSTValue(); }); @@ -704,6 +709,11 @@ function showInvoiceStatusModal(event) document.getElementById('invoice_value_modal').value = response.data.invoice_value; document.getElementById('gst_per_modal').value = response.data.gst_per; document.getElementById('gst_value_modal').value = response.data.gst_value; + console.log('response.data.gst_value - ' + response.data.gst_value); + if(response.data.gst_value == 0 || response.data.gst_value == '' || response.data.gst_value == null) + { + calcGSTValue(); + } if (!$('#invoice_date_modal').val()) { // alert('nope'); @@ -1051,20 +1061,34 @@ function getStatementNo() function calcGSTValue() { // alert('calcGSTValue'); - var gst_per = document.getElementById('gst_per_modal').value; - - var invoice_value_dom_obj = document.getElementById('invoice_value_modal'); - var invoice_value = invoice_value_dom_obj.value; - - var gst_value_dom_obj = document.getElementById('gst_value_modal'); - var gst_value = gst_value_dom_obj.value; - - var invoice_amount_dom_obj = document.getElementById('invoice_amount_no_modal'); - // var invoice_amount = invoice_amount_dom_obj.value(); + console.log('calcGSTValue called'); + var inv_status_element = document.getElementById('invoice_status'); - gst_value_dom_obj.value = (parseFloat(gst_per) / 100 ) * invoice_value; - invoice_amount_dom_obj.value = parseFloat(invoice_value_dom_obj.value) + parseFloat(gst_value_dom_obj.value); - checkInvAmont(); + if(inv_status_element.value == 'generated' || inv_status_element.value == 'send' || inv_status_element.value == 'payment_received') + { + + var gst_per = document.getElementById('gst_per_modal').value; + console.log('gst_per - ' + gst_per); + + var invoice_value_dom_obj = document.getElementById('invoice_value_modal'); + var invoice_value = invoice_value_dom_obj.value; + console.log('invoice_value - ' + invoice_value); + + var gst_value_dom_obj = document.getElementById('gst_value_modal'); + var gst_value = gst_value_dom_obj.value; + console.log('gst_value - ' + gst_value); + + var invoice_amount_dom_obj = document.getElementById('invoice_amount_no_modal'); + // var invoice_amount = invoice_amount_dom_obj.value(); + + gst_value_dom_obj.value = Math.round((parseFloat(gst_per) / 100 ) * invoice_value); + // gst_value_dom_obj.value = ((parseFloat(gst_per) / 100 ) * invoice_value); + invoice_amount_dom_obj.value = parseFloat(invoice_value_dom_obj.value) + parseFloat(gst_value_dom_obj.value); + if(inv_status_element.value == 'payment_received') + { + checkInvAmont(); + } + } } diff --git a/app/Views/report_bds.php b/app/Views/report_bds.php index 0dbdcc20..3fa60b7e 100644 --- a/app/Views/report_bds.php +++ b/app/Views/report_bds.php @@ -99,7 +99,8 @@ table.dataTable tbody td {  % - + + From dc480940d331b2a9d123d547776fae40e0a6d091 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Thu, 26 Dec 2024 08:47:52 +0530 Subject: [PATCH 05/11] CHANGE_BDS_FORM_AND_RFQ : RV --- app/Config/Routes.php | 2 + app/Controllers/EmpDataServiceController.php | 56 +- app/Controllers/LeadsController.php | 351 ++++++-- app/Helpers/MailHelper.php | 4 +- app/Helpers/excel_import_export_helper.php | 5 +- app/Models/EmployeePolicyModel.php | 224 ++++- app/Models/RFQModel.php | 4 +- app/Views/leads_form.php | 2 +- .../policy_transaction_inception_form.php | 64 +- app/Views/view_rfq.php | 852 +++++++++++++----- 10 files changed, 1218 insertions(+), 346 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 655da7e1..45f70e25 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -330,6 +330,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get('getCoShareStatementDetails/(:any)', 'PolicyTransactionController::getCoShareStatementDetails/$1'); $routes->get('getClientPolicyDataBasedOnClientAndInsuer', 'PolicyTransactionController::getClientPolicyDataBasedOnClientAndInsuer'); $routes->get('checkCDAmountForBasePremium', 'PolicyTransactionController::checkCDAmountForBasePremium'); + $routes->get('transformMailContent', 'LeadsController::transformMailContent'); }); $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) { @@ -377,6 +378,7 @@ $routes->group("leads", ["filter" => "authMVC"], function ($routes) { $routes->post("create", "LeadsController::createLead"); $routes->get("list/(:any)", "LeadsController::getLeadDataForEdit/$1"); $routes->get("sendMail", "LeadsController::sendMailWithAttachement"); + $routes->post("sendMail", "LeadsController::sendMailWithAttachement"); $routes->get("exportQCRandRFQ/(:any)", "LeadsController::exportQCRandRFQ/$1"); $routes->get("featchLeadDataAndInsertClient/(:any)", "LeadsController::featchLeadDataAndInsertClient/$1"); $routes->get("featchClientPolicyFromLead/(:any)", "LeadsController::featchClientPolicyFromLead/$1"); diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 78baac0b..5c79e589 100755 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -205,9 +205,6 @@ class EmpDataServiceController extends BaseController // Log the export file name $this->myLogger->logme('error', 'Inception export file name : {data}', ['data' => $export_data['file_name']]); - // remove existing batch file anf batch list data every time export - $this->removeOldExportInfoFromBatchFile($export_data); - // default excel header information $excel_header_columns = [ [ @@ -258,7 +255,7 @@ class EmpDataServiceController extends BaseController [ 'column_index' => 7, 'column_name' => 'DATE OF COVERAGE', - 'db_column_name' => 'date_coverage' + 'db_column_name' => 'date_of_coverage' ], [ 'column_index' => 8, @@ -368,7 +365,7 @@ class EmpDataServiceController extends BaseController [ 'column_index' => 7, 'column_name' => 'DATE OF COVERAGE', - 'db_column_name' => 'date_coverage' + 'db_column_name' => 'date_of_coverage' ], [ 'column_index' => 8, @@ -428,14 +425,35 @@ class EmpDataServiceController extends BaseController ]; }else{ // get excel export format structure array - $template_json = $this->clientPolicyModel - ->select('insurer_excel_export_template.jsoncolumns') - ->join('insurer_excel_export_template', 'insurer_excel_export_template.insurer_id = client_policy.insurer_id and insurer_excel_export_template.policy_type_id = client_policy.policy_type_id') - ->where('client_policy.id', $export_data['client_policy_id']) - ->where('insurer_excel_export_template.event_name', $export_data['event_type']) - ->where('insurer_excel_export_template.is_active', 1) //Live issue changes 17-10-2024 - ->where('insurer_excel_export_template.type_name', $export_data['actions']) - ->first(); + // $template_json = $this->clientPolicyModel + // ->select('insurer_excel_export_template.jsoncolumns') + // ->join('insurer_excel_export_template', 'insurer_excel_export_template.insurer_id = client_policy.insurer_id and insurer_excel_export_template.policy_type_id = client_policy.policy_type_id') + // ->where('client_policy.id', $export_data['client_policy_id']) + // ->where('insurer_excel_export_template.event_name', $export_data['event_type']) + // ->where('insurer_excel_export_template.is_active', 1) //Live issue changes 17-10-2024 + // ->where('insurer_excel_export_template.type_name', $export_data['actions']) + // ->first(); + + $sql = " + SELECT `insurer_excel_export_template`.`jsoncolumns` + FROM `client_policy` + JOIN `insurer_excel_export_template` + ON `insurer_excel_export_template`.`insurer_id` = `client_policy`.`insurer_id` + AND `insurer_excel_export_template`.`policy_type_id` = + CASE + WHEN `client_policy`.`policy_type_id` IN (2, 3, 4, 5) THEN 2 + ELSE `client_policy`.`policy_type_id` + END + WHERE `client_policy`.`id` = '".$export_data['client_policy_id']."' + AND `insurer_excel_export_template`.`event_name` = '".$export_data['event_type']."' + AND `insurer_excel_export_template`.`is_active` = 1 + AND `insurer_excel_export_template`.`type_name` = '".$export_data['actions']."' + LIMIT 1"; + + $query = db_connect()->query($sql); + $template_json = $query->getRowArray(); + + // dd(db_connect()->getLastQuery()); if(!empty($template_json) && $template_json != null){ $excel_header_columns = json_decode($template_json['jsoncolumns'], true); @@ -444,6 +462,10 @@ class EmpDataServiceController extends BaseController } } + // remove existing batch file anf batch list data every time export + $this->removeOldExportInfoFromBatchFile($export_data); + + //convert the excel data based on the insurer $excel_data_info = generate_insurer_based_excel($excel_header_columns, $objects); // Generate Excel file @@ -1343,7 +1365,7 @@ class EmpDataServiceController extends BaseController // employees.gender AS emp_gender, // employee_polices.pre_existing_alignments, // employee_polices.basic_cover_si, - // employee_polices.date_coverage, + // employee_polices.date_of_coverage, // TIMESTAMPDIFF(YEAR, employees.dob, CURDATE()) AS emp_age, // employees.relationship AS emp_relationship, // employees.change_event AS change_event, @@ -1954,12 +1976,14 @@ class EmpDataServiceController extends BaseController ->where("employees.is_active", 1) ->where("employees.emp_status", "active") ->where("emp_endorsement.actions", "c") + ->where("emp_endorsement.is_active", 1) + ->where("emp_endorsement.status !=", "truncated") ->where("(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = '')") ->findAll(); - // dd($endorsement_data, $excel_data); + dd($endorsement_data, $excel_data); if ($endorsement_data == null || empty($endorsement_data)) { @@ -2253,6 +2277,8 @@ class EmpDataServiceController extends BaseController ->where('employee_polices.status', 'active') ->where('employees.is_active', 1) ->where('employees.emp_status', 'active') + ->where("emp_endorsement.is_active", 1) + ->where("emp_endorsement.status !=", "truncated") ->first(); if (isset($result['id']) && $result['id'] !== null) { diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index b8d47cce..ea15cb12 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -32,6 +32,9 @@ use App\Helpers\ExcelMergeHelper; use Google\Service\CloudSearch\PushItem; use Kint; +use App\Controllers\Jobs; +use App\Controllers\JobWorker; + class LeadsController extends BaseController { @@ -98,7 +101,7 @@ class LeadsController extends BaseController { // $d = $this->constructExcelToSaveTemp(24, 1, $propsal_and_insurer = null); - $job_details = new Jobs(); + // $job_details = new Jobs(); // $r = Jobs::addJob(['job_name' => 'calculateMembersDemography', 'payload' => ['lead_id' => 24]]); // $d = $this->calculateMembersDemography(['lead_id' => 24]); //$this->mergeQuoteExcelFileWithMembersListExcelFile(24, 1, $propsal_and_insurer = null); @@ -323,6 +326,12 @@ class LeadsController extends BaseController $insert = $this->leadsModel->insert($value); $insertCount[] = $insert; $this->insertLeadStatus($insert, $value['status'], 3); + + //for this push the job to the calculateMembersDemography() function + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'calculateMembersDemography', 'payload' => [ + 'lead_id' => $insert, + ]]); } if (count($insertCount) > 0) { @@ -423,11 +432,13 @@ class LeadsController extends BaseController } $data['question_json'] = $lead_data['question_json']; - $data['page_name'] = isset($data['rfq_data']['type']) && $data['rfq_data']['type'] == 2 ? 'QCR' : 'RFQ'; + $data['page_name'] = $type == 2 ? 'QCR' : 'RFQ'; $data['insurer'] = $this->insurerBranchModel->getInsurerBranchesWithInsurerNames(); $data['userList'] = $this->userModel->getUserListForRFQ(); $data['lead_data'] = $lead_data; + $data['mail_content'] = $this->transformMailContent($id); + // dd($data); $this->loadLayout('view_rfq.php', $data); } @@ -449,7 +460,10 @@ class LeadsController extends BaseController $result = $this->RFQModel->insert($data); if ($result) { - return $this->respond(['status' => true, 'id' => $result, 'message' => 'RFQ created successfully', 'data' => $data], 200); + + $message = "RFQ submitted successfully"; + if($data['submit_type'] == 'QCR'){ $message = "QCR submitted successfully"; } + return $this->respond(['status' => true, 'id' => $result, 'message' => $message, 'data' => $data], 200); } return $this->respond(['status' => false, 'id' => $result, 'message' => "Failed to create RFQ", 'data' => $data], 200); @@ -492,6 +506,29 @@ class LeadsController extends BaseController public function exportExcelForQCRandRFQ($lead_id, $type) { $filepath = $this->constructExcelToSaveTemp($lead_id, $type); + $lead_data = $this->RFQModel->getRFQTableDataWithLeadIDAndType($lead_id, $type); + // dd($filepath); + + //Excel merging part + if ($lead_data['file_name'] != null && $lead_data['file_name'] != '') { + + $temp_file_path = $filepath['filePath']; + $temp_file_name = $filepath['fileName']; + $lead_file_path = WRITEPATH . 'uploads/lead_files/' . $lead_data['file_name']; + + // dd($lead_data, $temp_file_path, $temp_file_name, $lead_file_path); + + if ($lead_file_path) { + $filePaths = [ + ['file_path' => $temp_file_path, 'sheets' => []], + ['file_path' => $lead_file_path, 'sheets' => []] + ]; + // $outputPath = dirname($temp_file_path) . '/' . 'merged_' . $temp_file_name; + $result = ExcelMergeHelper::mergeExcelFiles($filePaths, $temp_file_path); + // print_rr($result); + } + } + $filepath = $filepath['filePath']; if (file_exists($filepath)) { @@ -522,11 +559,51 @@ class LeadsController extends BaseController // dd($rfq_data, $lead_id, $type, $propsal_and_insurer); // print_r($propsal_and_insurer); die; - $lead_data = [ - 'Insured' => $rfq_data['client_name'], - 'Insurer' => $rfq_data['insurer_name'] . ' - ' . $rfq_data['insurer_branch_name'], - 'TPA' => $rfq_data['tpa_name'] . ' - ' . $rfq_data['tpa_branch_name'], - ]; + if($rfq_data['lead_type'] == 1){ + + $lead_data = [ + + 'Insured' => $rfq_data['client_name'], + 'Policy Status' => $rfq_data['status'], + + 'No of Employees' => $rfq_data['incept_emp_count'], + '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'])), + 'Policy Run Days' => $rfq_data['policy_run_days'], + ]; + + }else{ + + $lead_data = [ + + 'Insured' => $rfq_data['client_name'], + 'Policy Status' => $rfq_data['status'], + + 'No of Employees at Inception' => $rfq_data['incept_emp_count'], + 'No of Dependents at Inception' => $rfq_data['incept_dept_count'], + 'Total Lives at Inception ' => $rfq_data['incept_no_of_lives'], + + 'No of Employees at Expiry' => $rfq_data['exp_emp_count'], + 'No of Dependents at Expiry' => $rfq_data['exp_dept_count'], + 'Total Lives at Expiry ' => $rfq_data['exp_no_of_lives'], + + 'No of Employees at Renewal' => $rfq_data['renewal_emp_count'], + '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'])), + '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'], + 'Earned Premium' => $rfq_data['earned_premium'], + 'Incurred Claims as on (Date - DD MM YYYY should be entered based on the claims dump report)' => $rfq_data['incurred_claims_date'], + 'Annualised Claims' => $rfq_data['annualised_claims'], + 'Incurred Claims Ratio' => $rfq_data['incurred_claims_ratio'], + 'Earned Claims Ratio' => $rfq_data['earned_claims_ratio'], + ]; + } $data = json_decode($rfq_data['json'], true); @@ -538,6 +615,7 @@ class LeadsController extends BaseController } }else if($type == 1){ $data = $this->convertJsonForQCR($data, $type); + // dd($data); } $spreadsheet = new Spreadsheet(); @@ -1135,14 +1213,18 @@ class LeadsController extends BaseController helper('excel_util_helper'); helper('MailHelper'); helper('ExcelMergeHelper'); - $params = $this->request->getGet(); + $params = $this->request->getPost(); + // 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 $recipient_mail = json_decode($params['recipient_mail'], true); // - only primary key of contacts $propsal_and_insurer = isset($params['proposal_insurer']) ? $params['proposal_insurer'] : null; + $mail_content = $params['mail_content']; + $mail_subject = $params['subject']; $result_data = []; // dd($recipient_mail); @@ -1161,9 +1243,10 @@ class LeadsController extends BaseController // print_r($lead_data ); die; $cc_mails = []; + $bcc_mails = []; //get CC Mails - if ($recipient_type == 'internal' || $recipient_type == 'placement') { + if ($recipient_type == 'internal' || $recipient_type == 'placement' || $recipient_type == 'insurer' || $recipient_type == 'client') { $cc_data = isset($params['cc']) ? $params['cc'] : ""; $param_cc_mail = json_decode($cc_data, true); @@ -1193,6 +1276,37 @@ class LeadsController extends BaseController } } + //get BCC Mails + if ($recipient_type == 'insurer' || $recipient_type == 'client') { + + $bcc_data = isset($params['bcc']) ? $params['bcc'] : ""; + $param_bcc_mail = json_decode($bcc_data, true); + + if (isset($param_bcc_mail) && is_array($param_bcc_mail) && count($param_bcc_mail) > 0) { + // Fetch user data where ID is in the param_cc_mail array + $userData = $this->userModel + ->where('is_active', 1) + ->whereIn('id', $param_bcc_mail) + ->findAll(); + + // print_r($userData); die; + + // Extract emails from the fetched user data + $bcc_mails = array_column($userData, 'email'); + + // print_r(json_encode($cc_mails)); die; + + // If no emails were found, return an error response + // if (empty($cc_mails)) { + // return $this->respond(['status' => 'failed','code' => 400,'data' => '','message' => 'No valid CC mail addresses found!'], 200); + // } + + } else { + // Handle case where param_cc_mail is not valid + // return $this->respond(['status' => 'failed','code' => 400,'data' => '','message' => 'CC mail not found!'], 200); + } + } + if ($recipient_type == 'client' && ($lead_data['contact_person_email'] == '' || $lead_data['contact_person_email'] == null)) { return $this->respond(['status' => 'failed', 'code' => 400, 'data' => '', 'messgae' => 'Recipient mail not found ! '], 200); } @@ -1248,6 +1362,18 @@ class LeadsController extends BaseController $subject = $file_type == 'rfq' ? 'Request for Quotation from ' . $lead_data['client_name'] . ' for ' . $lead_data['policy_type'] : 'Quotation Comparison Report for ' . $lead_data['policy_type']; $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.

'; + //for mail content + if(!empty($mail_content)){ + $original_message = $mail_content; + } + + //for mail subject + if(!empty($mail_subject)){ + $subject = $mail_subject; + } + + // print_r($subject); die; + if ($recipient_data) { foreach ($recipient_data as $recipient) { @@ -1260,7 +1386,7 @@ class LeadsController extends BaseController // print_rr($message);calculate_days_bw_dates - $res = MailHelper::send_email(['mail' => $recipient['email'], 'cc' => $cc_mails, 'subject' => $subject, 'message' => $message, 'attachments' => $attachments, 'reply_to' => $reply_to]); + $res = MailHelper::send_email(['mail' => $recipient['email'], 'cc' => $cc_mails, 'subject' => $subject, 'message' => $message, 'attachments' => $attachments, 'reply_to' => $reply_to, 'bcc' => $bcc_mails]); // !dd($res); $result_data[] = ['mail' => $recipient['email'], 'status' => $res]; } @@ -1434,83 +1560,126 @@ class LeadsController extends BaseController public function convertJsonForQCR($json, $type) { if ($json) { + // Deep copy of JSON $first_json = json_decode(json_encode($json), true); - // dd($first_json); - // Column-wise Check: Remove headers and relevant data if qcr == 0 - foreach ($json['proposal_data']['over_all_column_data'] as $proposalKey => $proposalData) { + if($type == 2){ - if ($proposalData['stc'] == 0 || $proposalData['stc'] === false) { - // Remove matching parentHeader in headers - foreach ($first_json['table_data']['headers'] as $index => $header) { - if ($header['parentHeader'] === $proposalKey) { - unset($first_json['table_data']['headers'][$index]); - } - } + // Column-wise Check: Remove headers and relevant data if qcr == 0 + foreach ($json['proposal_data']['over_all_column_data'] as $proposalKey => $proposalData) { - // Remove data entries with matching parentth - foreach ($first_json['table_data']['data'] as &$item) { - $item['data'] = array_values(array_filter($item['data'], function ($entry) use ($proposalKey) { - return $entry['parentth'] !== $proposalKey; - })); - } + if (($proposalData['qcr'] == 0 || $proposalData['qcr'] === false) || ($proposalData['stc'] == 0 || $proposalData['stc'] === false)) { - // Remove proposalKey from over_all_column_data - unset($first_json['proposal_data']['over_all_column_data'][$proposalKey]); - - if($type == 2){ - // Remove proposalKey from premium_data - unset($first_json['premium_data']['data'][$proposalKey]); - } - } - - // Insurer Check: Remove subHeaders and relevant data for insurers with qcr == 0 - foreach ($proposalData['insurers'] as $insurerIndex => $insurer) { - if ($insurer['stc'] === 0 || $insurer['stc'] === false) { - foreach ($first_json['table_data']['headers'] as &$header) { - if (isset($header['subHeaders'])) { - $header['subHeaders'] = array_values(array_filter($header['subHeaders'], function ($sub) use ($insurer) { - return $sub !== $insurer['display_name']; - })); + // Remove matching parentHeader in headers + foreach ($first_json['table_data']['headers'] as $index => $header) { + if ($header['parentHeader'] === $proposalKey) { + unset($first_json['table_data']['headers'][$index]); } } - + // Remove data entries with matching parentth foreach ($first_json['table_data']['data'] as &$item) { - $item['data'] = array_values(array_filter($item['data'], function ($entry) use ($insurer) { - return $entry['subth'] !== $insurer['display_name']; + $item['data'] = array_values(array_filter($item['data'], function ($entry) use ($proposalKey) { + return $entry['parentth'] !== $proposalKey; })); } - // Remove insurer from proposal's insurers array - unset($first_json['proposal_data']['over_all_column_data'][$proposalKey]['insurers'][$insurerIndex]); - + // Remove proposalKey from over_all_column_data + unset($first_json['proposal_data']['over_all_column_data'][$proposalKey]); + if($type == 2){ - unset($first_json['premium_data']['data'][$proposalKey][$insurer['display_name']]); + // Remove proposalKey from premium_data + unset($first_json['premium_data']['data'][$proposalKey]); + } + } + + // Insurer Check: Remove subHeaders and relevant data for insurers with qcr == 0 + foreach ($proposalData['insurers'] as $insurerIndex => $insurer) { + if (($insurer['qcr'] === 0 || $insurer['qcr'] === false) || ($insurer['stc'] === 0 || $insurer['stc'] === false) ) { + foreach ($first_json['table_data']['headers'] as &$header) { + if (isset($header['subHeaders'])) { + $header['subHeaders'] = array_values(array_filter($header['subHeaders'], function ($sub) use ($insurer) { + return $sub !== $insurer['display_name']; + })); + } + } + + + foreach ($first_json['table_data']['data'] as &$item) { + $item['data'] = array_values(array_filter($item['data'], function ($entry) use ($insurer) { + return $entry['subth'] !== $insurer['display_name']; + })); + } + + // Remove insurer from proposal's insurers array + unset($first_json['proposal_data']['over_all_column_data'][$proposalKey]['insurers'][$insurerIndex]); + + if($type == 2){ + unset($first_json['premium_data']['data'][$proposalKey][$insurer['display_name']]); + } } } } - } - // Row-wise Check: Remove rows if qcr == 0 for actions - foreach ($first_json['table_data']['data'] as $rowKey => $rowData) { - foreach ($rowData['data'] as $data) { - if ($data['parentth'] === "Action" && isset($data['input_value']['stc']) && $data['input_value']['stc'] == 0) { - unset($first_json['table_data']['data'][$rowKey]); - break; + // Row-wise Check: Remove rows if qcr == 0 for actions + foreach ($first_json['table_data']['data'] as $rowKey => $rowData) { + foreach ($rowData['data'] as $data) { + if ($data['parentth'] === "Action" && (isset($data['input_value']['qcr']) && $data['input_value']['qcr'] == 0) || (isset($data['input_value']['stc']) && $data['input_value']['stc'] == 0)) { + unset($first_json['table_data']['data'][$rowKey]); + break; + } } } - } - // Reindex arrays to maintain proper structure - $first_json['table_data']['headers'] = array_values($first_json['table_data']['headers']); - $first_json['table_data']['data'] = array_values($first_json['table_data']['data']); - $first_json['proposal_data']['over_all_column_data'] = array_map(function ($proposal) { - $proposal['insurers'] = array_values($proposal['insurers']); - return $proposal; - }, $first_json['proposal_data']['over_all_column_data']); + // Reindex arrays to maintain proper structure + $first_json['table_data']['headers'] = array_values($first_json['table_data']['headers']); + $first_json['table_data']['data'] = array_values($first_json['table_data']['data']); + $first_json['proposal_data']['over_all_column_data'] = array_map(function ($proposal) { + $proposal['insurers'] = array_values($proposal['insurers']); + return $proposal; + }, $first_json['proposal_data']['over_all_column_data']); + + }else{ + + //remove insurer as Subheaders for RFQ + foreach ($first_json['table_data']['headers'] as &$header) { + $header['subHeaders'] = array_filter($header['subHeaders'], function ($subHeader) { + return in_array($subHeader, ['Quote Asked', '-']); + }); + } + + //Remove insurer Row wise data for RFQ + foreach ($first_json['table_data']['data'] as &$row) { + + // Filter the inner data array + $row['data'] = array_filter( + $row['data'], + function ($item) { + return in_array($item['subth'], ['Quote Asked', '-']); + } + ); + + $row['data'] = array_values($row['data']); + } + + // Ensure to unset the reference after the loop + unset($row); + + + // Remove insurers from Proposal Data key for RFQ + foreach ($first_json['proposal_data']['over_all_column_data'] as $key => &$proposal) { + if (isset($proposal['insurers'])) { + // Set the insurers array to empty + $proposal['insurers'] = []; + } + } + + // Ensure to reset the reference + unset($proposal); + + } return $first_json; } @@ -1850,8 +2019,54 @@ class LeadsController extends BaseController //------------------------------------------------------------------------------------------------ - public function transformMailContent() - { + public function transformMailContent($lead_id) + { + 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.

'; + + $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 ''; + } + + + } } diff --git a/app/Helpers/MailHelper.php b/app/Helpers/MailHelper.php index 6116bc0c..085c510f 100755 --- a/app/Helpers/MailHelper.php +++ b/app/Helpers/MailHelper.php @@ -97,7 +97,9 @@ class MailHelper //check BCC mail if (isset($params['bcc'])) { $bcc = $params['bcc']; - $bcc = explode(',', $bcc); + if(!is_array($bcc)){ + $bcc = explode(',', $bcc); + } }else{ $bcc = []; } diff --git a/app/Helpers/excel_import_export_helper.php b/app/Helpers/excel_import_export_helper.php index 3355253e..ad484ffe 100755 --- a/app/Helpers/excel_import_export_helper.php +++ b/app/Helpers/excel_import_export_helper.php @@ -128,7 +128,7 @@ if (! function_exists('transform_objects_to_array_for_inception')) { $obj->emp_gender, // Employee Gender $obj->pre_existing_alignments, // Pre-existing Alignments $obj->basic_cover_si, // Basic Cover SI - $obj->date_coverage, // Date Coverage + $obj->date_of_coverage, // Date Coverage $obj->emp_age, // Employee Age $obj->emp_relationship, // Employee Relationship $obj->change_event, // Change Event @@ -260,7 +260,6 @@ if (! function_exists('transform_objects_to_array_for_deletion')) { $obj->total, $claim_status, $endorsement_id - ]; // Append the row data to the main data array @@ -487,7 +486,7 @@ if (!function_exists('format_Excel_BasedOn_Client')) $rowData[] = $obj->basic_cover_si; // Employee BASIC COVER SI break; case 'dateofcoverage': - $rowData[] = $obj->date_coverage; // DATE OF COVERAGE + $rowData[] = $obj->date_of_coverage; // DATE OF COVERAGE break; case 'age': $rowData[] = $obj->emp_age; // Employee AGE diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index f0f7eaa2..9908c094 100755 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -179,7 +179,11 @@ class EmployeePolicyModel extends Model $result->where('employee_polices.is_active', 1) ->where('emp.is_active', 1); - return $result->findAll(); + $res = $result->findAll(); + + // dd($this->db->getLastQuery()); + + return $res; } public function getEmployeePolicyForEcard($policy_id = 0) @@ -275,7 +279,7 @@ class EmployeePolicyModel extends Model employee_polices.uhid, employee_polices.pre_existing_alignments, employee_polices.basic_cover_si, - employee_polices.date_coverage, + employee_polices.date_coverage as date_of_coverage, employee_polices.policy_end_date, employee_polices.days as no_of_days, employee_polices.premium, @@ -322,6 +326,9 @@ class EmployeePolicyModel extends Model }else{ $results = $query->getResult(); } + + // dd($this->db->getLastQuery()); + return $results; } @@ -556,6 +563,175 @@ class EmployeePolicyModel extends Model } + // DO NOT DELETE this DELETION QUERY FUNCTION + + // public function getDeletionEmployeeDataForExportExcel($ref_data, $return_type = 0) + // { + + // $client_id = $ref_data['client_id']; + // $client_policy_id = $ref_data['client_policy_id']; + // $client_branch_id = $ref_data['client_branch_id']; + // $insurer_or_tpa = $ref_data['insurer_or_tpa']; + + // $get_insurer_id_from_client_policy = $this->db->table('client_policy') + // ->select('insurer_id') + // ->where('id', $client_policy_id) + // ->get() + // ->getRowArray(); + + // $add_one_day = 0; + + // if (!empty($get_insurer_id_from_client_policy)) { + + // $get_the_insurer_add_one_for_delete = $this->db->table('insurers') + // ->select('deletion_add_day') + // ->where('id', $get_insurer_id_from_client_policy['insurer_id']) + // ->get() + // ->getRowArray(); + + // if (!empty($get_the_insurer_add_one_for_delete) && $get_the_insurer_add_one_for_delete['deletion_add_day'] == 1) { + // $add_one_day = 1; + // } + // } + + // $status_condition = "{$insurer_or_tpa}" === 'tpa' + // ? "employee_polices.status = 'inactive' AND employees.emp_status = 'inactive'" + // : "employee_polices.status = 'active' AND employees.emp_status = 'active'"; + + // $endorsement_condition = "{$insurer_or_tpa}" === 'tpa' ? "AND (a.endorsement_id IS NOT NULL OR a.endorsement_id != '')" : "AND (a.endorsement_id IS NULL OR a.endorsement_id = '')"; + + // $query = $this->db->query(" + // SELECT DISTINCT + // a.id as endorsement_primarykey, + // a.group_key, + // employee_polices.id as primaryKey, + // employees.name AS emp_name, + // employees.emp_code AS emp_code, + // employees.dob AS emp_dob, + // employees.gender AS emp_gender, + // employees.relationship AS emp_relationship, + // employees.relationship_code AS emp_relationship_code, + // employees.emp_type as emp_type, + // 'D' as event_type_data, + // TIMESTAMPDIFF(YEAR, employees.dob, CURDATE()) AS emp_age, + + // employees.doj AS emp_doj, + // employees.mobile AS emp_mobile, + // employees.email_corporate AS emp_email_c, + // employees.email_personal AS emp_email_p, + // employees.band AS emp_grade, + // employees.designation AS emp_designation, + // employees.basic_pay AS emp_basic_pay, + + // employee_polices.basic_cover_si, + // employee_polices.uhid as uhid, + // employee_polices.policy_end_date, + // employee_polices.rata_premimum as premium, + // employee_polices.claim_status, + + // batch_data.emp_policy_id AS emp_policy_id, + // batch_data.bl AS batch_list_batch_code, + // batch_data.bf AS batch_files_batch_code, + + // deletiondata.empstatus, + // deletiondata.changeevent, + // deletiondata.dateofexit, + // deletiondata.reasonforexit, + // deletiondata.status, + + // DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + '$add_one_day' AS no_of_days, + + + // CASE + // WHEN employee_polices.claim_status = 0 THEN + // ROUND((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365, 2) + // ELSE + // 0 + // END AS pro_rata_premium, + + // CASE + // WHEN employee_polices.claim_status = 0 THEN + // ROUND(((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365) * 0.18, 2) + // ELSE + // 0 + // END AS gst, + + // CASE + // WHEN employee_polices.claim_status = 0 THEN + // ROUND(((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365) + + // (((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365) * 0.18), 2) + // ELSE + // 0 + // END AS total, + + // CASE + // WHEN employee_polices.claim_status = 0 THEN + // 'No claim' + // ELSE + // 'Claim' + // END AS claim_status + + // FROM + // emp_endorsement a + // LEFT JOIN + // employees ON a.emp_code = employees.emp_code + // LEFT JOIN + // employee_polices ON employees.id = employee_polices.employee_id + + // LEFT JOIN( + + // select aa.emp_code, aa.new_value as 'empstatus', bb.new_value as 'changeevent', cc.new_value as 'dateofexit', dd.new_value as 'reasonforexit', ee.new_value as 'status' from + + // ( SELECT a1.emp_code, a1.field_name, a1.new_value from emp_endorsement as a1 where a1.field_name = 'emp_status' and a1.status != 'truncated') aa + // left join + // ( SELECT b1.emp_code, b1.field_name, b1.new_value from emp_endorsement as b1 where b1.field_name = 'change_event' and b1.status != 'truncated') bb on aa.emp_code = bb.emp_code + // left join + // ( SELECT c1.emp_code, c1.field_name, c1.new_value from emp_endorsement as c1 where c1.field_name = 'date_of_exit' and c1.status != 'truncated') cc on aa.emp_code = cc.emp_code + // left join + // ( SELECT d1.emp_code, d1.field_name, d1.new_value from emp_endorsement as d1 where d1.field_name = 'reason_for_exit' and d1.status != 'truncated') dd on aa.emp_code = dd.emp_code + // left JOIN + // ( SELECT e1.emp_code, e1.field_name, e1.new_value from emp_endorsement as e1 where e1.field_name = 'status' and e1.status != 'truncated') ee on aa.emp_code = ee.emp_code + + // ) as deletiondata on a.emp_code = deletiondata.emp_code and a.status != 'truncated' + + // LEFT JOIN + // ( + // SELECT + // batch_list.emp_policy_id, + // batch_list.batch_code AS bl, + // batch_files.batch_code AS bf + // FROM + // batch_files + // LEFT JOIN + // batch_list ON batch_files.batch_code = batch_list.batch_code + // WHERE + // batch_files.event_type = 'deletion' + // AND batch_files.actions = 'export' + // AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}' + // ) AS batch_data ON employee_polices.id = batch_data.emp_policy_id + + // WHERE employee_polices.client_policy_id = {$client_policy_id} + // AND employees.client_branch_id = {$client_branch_id} + // $endorsement_condition + // AND a.actions = 'd' + // AND a.status != 'truncated' + // AND employee_polices.is_active = 1 + // AND employees.is_active = 1 + // AND $status_condition + // group by group_key + // "); + + // if($return_type == 1){ + // $result = $query->getResultArray(); + // }else{ + // $result = $query->getResult(); + // } + + // // dd($this->db->getLastQuery(), $result); + + // return $result; + + // } public function getDeletionEmployeeDataForExportExcel($ref_data, $return_type = 0) { @@ -666,28 +842,31 @@ class EmployeePolicyModel extends Model FROM emp_endorsement a LEFT JOIN - employees ON a.emp_code = employees.emp_code and a.pk = employees.id + employee_polices ON a.pk = employee_polices.id LEFT JOIN - employee_polices ON employees.id = employee_polices.employee_id - - LEFT JOIN( - - select aa.emp_code, aa.new_value as 'empstatus', bb.new_value as 'changeevent', cc.new_value as 'dateofexit', dd.new_value as 'reasonforexit', ee.new_value as 'status' from - - ( SELECT a1.emp_code, a1.field_name, a1.new_value from emp_endorsement as a1 where a1.field_name = 'emp_status' and a1.status != 'truncated') aa - left join - ( SELECT b1.emp_code, b1.field_name, b1.new_value from emp_endorsement as b1 where b1.field_name = 'change_event' and b1.status != 'truncated') bb on aa.emp_code = bb.emp_code - left join - ( SELECT c1.emp_code, c1.field_name, c1.new_value from emp_endorsement as c1 where c1.field_name = 'date_of_exit' and c1.status != 'truncated') cc on aa.emp_code = cc.emp_code - left join - ( SELECT d1.emp_code, d1.field_name, d1.new_value from emp_endorsement as d1 where d1.field_name = 'reason_for_exit' and d1.status != 'truncated') dd on aa.emp_code = dd.emp_code - left JOIN - ( SELECT e1.emp_code, e1.field_name, e1.new_value from emp_endorsement as e1 where e1.field_name = 'status' and e1.status != 'truncated') ee on aa.emp_code = ee.emp_code - - ) as deletiondata on a.emp_code = deletiondata.emp_code and a.status != 'truncated' + employees ON employee_polices.employee_id = employees.id + + LEFT JOIN ( + SELECT + emp_code, + group_key, + MAX(CASE WHEN field_name = 'emp_status' THEN new_value END) AS empstatus, + MAX(CASE WHEN field_name = 'change_event' THEN new_value END) AS changeevent, + MAX(CASE WHEN field_name = 'date_of_exit' THEN new_value END) AS dateofexit, + MAX(CASE WHEN field_name = 'reason_for_exit' THEN new_value END) AS reasonforexit, + MAX(CASE WHEN field_name = 'status' THEN new_value END) AS status + FROM + emp_endorsement + WHERE + status != 'truncated' + GROUP BY + group_key + + ) AS deletiondata + ON a.emp_code = deletiondata.emp_code AND a.status != 'truncated' LEFT JOIN - ( + ( SELECT batch_list.emp_policy_id, batch_list.batch_code AS bl, @@ -700,7 +879,7 @@ class EmployeePolicyModel extends Model batch_files.event_type = 'deletion' AND batch_files.actions = 'export' AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}' - ) AS batch_data ON employee_polices.id = batch_data.emp_policy_id + ) AS batch_data ON employee_polices.id = batch_data.emp_policy_id WHERE employee_polices.client_policy_id = {$client_policy_id} AND employees.client_branch_id = {$client_branch_id} @@ -720,6 +899,7 @@ class EmployeePolicyModel extends Model } // dd($this->db->getLastQuery(), $result); + // dd($result); return $result; diff --git a/app/Models/RFQModel.php b/app/Models/RFQModel.php index d165b339..2b1560e0 100644 --- a/app/Models/RFQModel.php +++ b/app/Models/RFQModel.php @@ -60,15 +60,13 @@ class RFQModel extends Model public function getRFQTableDataWithLeadIDAndType($lead_id, $type){ return $this->select(' - leads.client_name, - leads.client_short_name, + leads.*, insurers.name as insurer_name, insurer_branch.branch_name as insurer_branch_name, tpa.name as tpa_name, tpa_branch.branch_name as tpa_branch_name, policy_type.policy_type, rfq.json, - file_name ') ->join('leads', 'rfq.lead_id = leads.id') ->join('policy_type', 'leads.policy_type_id = policy_type.id') diff --git a/app/Views/leads_form.php b/app/Views/leads_form.php index 0d04d44e..9674abf7 100644 --- a/app/Views/leads_form.php +++ b/app/Views/leads_form.php @@ -887,7 +887,7 @@ function addHTMLInput(check) { newRow7.innerHTML += `
- +
`; diff --git a/app/Views/policy_transaction_inception_form.php b/app/Views/policy_transaction_inception_form.php index 1f25dd2c..13fc0933 100644 --- a/app/Views/policy_transaction_inception_form.php +++ b/app/Views/policy_transaction_inception_form.php @@ -1649,6 +1649,13 @@ function getPolicyTransactionDataForEdit(input) { $('#table_tr_3').hide(); $('#table_tr_7').hide(); $('#table_tr_35').hide(); + + setTimeout(function(){ + $('input[name="co_share_per[]"], input[name="co_premium[]"]').each(function () { + $(this).val(''); // Clear value + console.log('Input cleared:', $(this).attr('name')); + }); + }, 4000); } // Handle "Same Insured Name" @@ -1820,17 +1827,32 @@ function amountCalculation(input) { console.log(gst_per); } + console.log('gst_per', gst_per); + console.log('igst', igst); + console.log('cgst', cgst); + console.log('sgst', sgst); + // Calculate the total premium (Base + TP + Co-Premium) let tpTotal = bp + tp + tep + cop; + console.log('bp', bp); + console.log('tp', tp); + console.log('tep', tep); + console.log('cop', cop); + console.log('tpTotal', tpTotal); + + let gst_per_amt = (tpTotal * gst_per) / 100; + console.log('gst_per_amt', gst_per_amt); + + // $('#gst_amount_' + input).val(gst_per_amt.toFixed(2)); $('#gst_amount_' + input).val(!isNaN(gst_per_amt) && isFinite(gst_per_amt) ? gst_per_amt.toFixed(2) : '0.00'); let finalTotal = tpTotal + gst_per_amt + stamp_duty_amt; - // console.log('Summed Amount:', finalTotal); + console.log('Summed Amount:', finalTotal); // $('#total_amt_' + input).val(finalTotal.toFixed(2)); $('#total_amt_' + input).val(!isNaN(finalTotal) && isFinite(finalTotal) ? finalTotal.toFixed(2) : '0.00'); @@ -3274,6 +3296,12 @@ $('#cop_yes').change(function() { $('#table_tr_3').show() $('#table_tr_7').show() $('#table_tr_35').show() + + $('input[name="co_share_per[]"], input[name="co_premium[]"]').each(function () { + $(this).val(''); // Clear value + console.log('Input cleared:', $(this).attr('name')); // Log cleared input + }); + } else { $('#add_more_row').addClass('d-none'); $('.payby').addClass('d-none'); @@ -3282,6 +3310,11 @@ $('#cop_yes').change(function() { $('#table_tr_3').hide() $('#table_tr_7').hide() $('#table_tr_35').hide() + + $('input[name="co_share_per[]"], input[name="co_premium[]"]').each(function () { + $(this).val(''); // Clear value + console.log('Input cleared:', $(this).attr('name')); // Log cleared input + }); } }); @@ -3621,6 +3654,10 @@ function addInsurerColumn() { if(team_id.includes('4')){ + console.log( + '################ TEAM ID 4 insurerTable '+ index + '########################' + ) + switch(index) { case 0: // Insurer selection newCell = ` @@ -3749,6 +3786,10 @@ function addInsurerColumn() { }else if(team_id.includes('3')){ + console.log( + '################ TEAM ID 3 ########################' + ) + switch(index) { case 0: // Insurer selection newCell = ` @@ -3841,6 +3882,10 @@ function addInsurerColumn() { }else if(team_id.includes('6')){ + console.log( + '################ TEAM ID 6 ########################' + ) + switch(index) { case 0: // Insurer selection newCell = ` @@ -3971,7 +4016,9 @@ function addInsurerColumn() { } } - + console.log('#################################################################'); + console.log(newCell); + console.log('#################################################################'); $(this).append(newCell); $('#follow_insurer_id_' + insurerCount).select2() @@ -4065,6 +4112,10 @@ function populateTable(dataArray) { if(team_id.includes('4')){ + console.log( + '################ TEAM ID 4 ########################' + ) + switch (rowIndex) { case 0: // Insurer selection cell.find('select').val(insurer).change().toggleClass('readonly-select', !!disable_td); @@ -4172,6 +4223,10 @@ function populateTable(dataArray) { }else if(team_id.includes('3')){ + console.log( + '################ TEAM ID 3 ########################' + ) + switch (rowIndex) { case 0: // Insurer selection cell.find('select').val(insurer).change().toggleClass('readonly-select', !!disable_td); @@ -4236,7 +4291,6 @@ function populateTable(dataArray) { case 20: // Standard Ter % cell.find('input').val(data.standerd_tep_per).toggleClass('readonly-select', !!disable_td); break; - case 21: // Co-share ID (hidden field) cell.find('input[type="hidden"]').val(data.id); break; @@ -4244,6 +4298,10 @@ function populateTable(dataArray) { }else if(team_id.includes('6')){ + console.log( + '################ TEAM ID 6 ########################' + ) + switch (rowIndex) { case 0: // Insurer selection cell.find('select').val(insurer).change().toggleClass('readonly-select', !!disable_td); diff --git a/app/Views/view_rfq.php b/app/Views/view_rfq.php index c0a4bef7..8700ecad 100644 --- a/app/Views/view_rfq.php +++ b/app/Views/view_rfq.php @@ -188,6 +188,12 @@ color: white !important; margin-right: 5px; } + + .readonly-select { + pointer-events: none; + background-color: #f0f0f0; + color: #666; + } @@ -345,7 +351,7 @@