diff --git a/app/Config/Routes.php b/app/Config/Routes.php index ef4c655c..f11f6451 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -332,7 +332,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get("send_manual_ecard/(:any)", "DashboardController::sendManualEcard/$1"); $routes->get("get_client_policy_list_for_remainder/(:any)", "EmployeeController::get_client_policy_list_for_remainder/$1"); $routes->get("get_client_branch_data/(:any)", "ClientController::get_client_branch_data/$1"); - $routes->get("getLevelContects", "LeadsController::getLevelContects"); + $routes->get("getLevelContects", "LeadsControllerg::getLevelContects"); $routes->get("get_emp_master_data_for_update/(:any)", "EmployeeController::get_emp_master_data_for_update/$1"); $routes->get("send_mail_for_individual_employee_ecard/(:any)", "EmployeeController::send_mail_for_individual_employee_ecard/$1"); $routes->post("update_emp_data", "EmployeeController::update_emp_data"); @@ -365,6 +365,9 @@ $routes->cli("cli/sendInstallmentRemainderMail","PolicyTransactionController::se $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) { + $routes->post("getMoreInfo","PolicyTransactionController::getMoreInfo"); + $routes->post("saveInstallment","PolicyTransactionController::saveInstallment"); + $routes->group("inception", ["filter" => "authMVC"], function ($routes) { $routes->match(['get', 'post'], 'list', 'PolicyTransactionController::viewInception'); $routes->post("create", "PolicyTransactionController::createInceptionPolicy"); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 9bf373ce..968fc9f9 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1243,40 +1243,8 @@ class ClientController extends AdminController $data['created_by'] = get_session_userid(); - $policy_tranction_data = [ - - 'issuer' => 2, - 'client_id' => $this->request->getPost('client_id'), - 'client_branch_id' => $this->request->getPost('client_branch_id'), - 'insurer_id' => $insurerId, - 'insurer_branch_id' => $insurerBranchId, - 'issue_type' => 1, - 'policy_no' => $this->request->getPost('policy_no'), - 'cd_ac_pk' => $this->request->getPost('cd_ac_no'), - 'policy_issue_date' => date('Y-m-d'), - 'policy_start_date' => change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d'), - 'policy_end_date' => change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d'), - 'action_type' => 'inception', - 'status' => 'pending', - 'created_by' => get_session_userid(), - ]; - - $insert = $this->clientPolicyModel->insert($data); if ($insert) { - - $policy_tranction_data['client_policy_id'] = $insert; - $policy_tranction_data_insert = $this->policyTransactionModel->insert($data); - if ($policy_tranction_data_insert) { - $statusData = [ - 'policy_tran_id' => $policy_tranction_data_insert, - 'status' => 'pending', - 'created_by' => get_session_userid(), - ]; - $this->policyTransactionStatusModel->insert($statusData); - } - - $clientPoliceData = $this->clientPolicyModel->getClientPolicyByClientId($this->request->getPost('client_id')); $clientPoliceData['role'] = get_role_id(); return $this->respond(['status' => true, 'code' => 200, 'data' => $clientPoliceData, 'method' => 'CERATE', 'post_data' => $data], 200); @@ -3839,13 +3807,13 @@ class ClientController extends AdminController 'dob' => change_date_format($postData['dob'],'d/m/Y','Y-m-d'), 'aadhar' => $postData['aadhar'], 'phone' => $postData['phone'], - 'email' => $postData['email'], 'entity_type_id' => 7 ]); } else { $client_data['entity_type_id'] = $postData['entity_type_id']; } + // print_rr($client_data);die(); // Insert client data $client_insert = $this->clientModel->insert($client_data); @@ -3871,6 +3839,8 @@ class ClientController extends AdminController 'contact_type' => 'client', 'name' => $postData['name'], 'mobile' => $postData['mobile'], + 'email' => $postData['email'], + ]; $this->levelContactModel->insert($contact_data); } @@ -4050,7 +4020,8 @@ class ClientController extends AdminController ->join('clients', 'client_branch.client_id = clients.id') ->where(['client_branch.id' => $id, 'client_branch.is_active' => 1]) ->first(); - $branch_contact_data = $this->levelContactModel->where(['ref_id' => $id, 'contact_type' => 'client', 'is_active' => 1])->orderBy('id','asc')->first(); + $branch_contact_data = $this->levelContactModel->where(['ref_id' => $id, 'contact_type' => 'client', 'is_active' => 1])->findAll(); + // print_rr($branch_contact_data);die(); return $this->respond(['status' => true, 'code' => 200, 'data' => $branch_data, 'contact' => $branch_contact_data], 200); } else { return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200); @@ -4664,6 +4635,13 @@ class ClientController extends AdminController // $EmpDataServiceController->importDeletionValidation(['file_id' => 171]); // $EmpDataServiceController->importDeletionUpdateEndorsementID(['file_id' => 171]); // $EmpDataServiceController->importCorrectionUpdateEndorsementID(['file_id' => 188]); + + $params = [ + 'client_policy_id' => 6090, + 'action_type' => "inception", + ]; + $res = $EmpDataServiceController->makeEntryForBDSPolicyTransaction($params); + dd($res); // $array = [ // "employeeIds" => ["12800", "12798", "12797", "12799"], diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 19d57a7d..5709b0ae 100755 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -28,6 +28,11 @@ use App\Models\CDMasterModel; use App\Models\InsurerExcelExportTemplateModel; use App\Models\ClientBranchModel; use App\Models\EndorsementModel; +use App\Models\BdsPlacementModel; +use App\Models\LeadsModel; +use App\Models\LeadInstallmentPaymentDetails; +use App\Models\PolicyTransactionModel; +use App\Models\PTCOShareDetailsModel; use App\Controllers\Jobs; use App\Controllers\JobWorker; @@ -60,6 +65,11 @@ class EmpDataServiceController extends BaseController protected $excelExportTemplateModel; protected $clientBranchModel; protected $endorsementModel; + protected $BdsPlacementModel; + protected $leadsModel; + protected $leadInstallmentPaymentDetailesModel; + protected $policyTransactionModel; + protected $PTCOShareDetailsModel; public function __construct() @@ -83,6 +93,11 @@ class EmpDataServiceController extends BaseController $this->excelExportTemplateModel = new InsurerExcelExportTemplateModel(); $this->clientBranchModel = new ClientBranchModel(); $this->endorsementModel = new EndorsementModel(); + $this->BdsPlacementModel = new BdsPlacementModel(); + $this->leadsModel = new LeadsModel(); + $this->leadInstallmentPaymentDetailesModel = new LeadInstallmentPaymentDetails(); + $this->policyTransactionModel = new PolicyTransactionModel(); + $this->PTCOShareDetailsModel = new PTCOShareDetailsModel(); } @@ -1976,6 +1991,13 @@ class EmpDataServiceController extends BaseController 'user_id' => $user_id, ]]); + $r = Jobs::addJob(['job_name' => 'makeEntryForBDSPolicyTransaction', 'payload' => [ + 'client_policy_id' => $client_policy_id ?? null, + 'endorsement_no' => $endorsement_id ?? null, + 'emp_count' => $emp_count ?? null, + 'action_type' => $file['event_type'] ?? null, + ]]); + // $this->cashDepositCalculationForInception($depositeData); // $this->sendMailForDownloadingECard($emp_policy_ids); @@ -2400,6 +2422,13 @@ class EmpDataServiceController extends BaseController $file_data = $this->getDataByFileId($file_id, 'success'); $this->setPullNotification($file_data); + $r = Jobs::addJob(['job_name' => 'makeEntryForBDSPolicyTransaction', 'payload' => [ + 'client_policy_id' => $client_policy_id ?? null, + 'endorsement_no' => $endorsement_id[0] ?? null, + 'emp_count' => $emp_count ?? null, + 'action_type' => $file['event_type'] ?? null, + ]]); + //import file to upload Google Drive // if(excelFileGDriveUpload($file_id, 'batch_file')){ @@ -3024,6 +3053,13 @@ class EmpDataServiceController extends BaseController 'user_id' => $user_id, ]]); + $r = Jobs::addJob(['job_name' => 'makeEntryForBDSPolicyTransaction', 'payload' => [ + 'client_policy_id' => $client_policy_id ?? null, + 'endorsement_no' => $endorsement_id ?? null, + 'emp_count' => $emp_count ?? null, + 'action_type' => $file['event_type'] ?? null, + ]]); + } $file_data = $this->getDataByFileId($file_id, 'success'); @@ -3498,6 +3534,13 @@ class EmpDataServiceController extends BaseController 'policy_name' => $policy_name['policy_name'], 'user_id' => $user_id, ]]); + + $r = Jobs::addJob(['job_name' => 'makeEntryForBDSPolicyTransaction', 'payload' => [ + 'client_policy_id' => $client_policy_id ?? null, + 'endorsement_no' => $endorsement_id ?? null, + 'emp_count' => $emp_count ?? null, + 'action_type' => $file['event_type'] ?? null, + ]]); } $file_data = $this->getDataByFileId($file_id, 'success'); @@ -4675,7 +4718,171 @@ class EmpDataServiceController extends BaseController $this->myLogger->logme('error',"storeEndorsementNumber --- Function execution completed for file_id: $file_id"); } + // -------------------------------------------------------------------------------------------------------------------------------- + public function makeEntryForBDSPolicyTransaction($params) + { + try { + $this->myLogger->logme("error", "makeEntryForBDSPolicyTransaction() started: " . json_encode(['params' => $params])); + + if (empty($params) || !isset($params['client_policy_id']) || empty($params['client_policy_id'])) { + $this->myLogger->logme("error", "Invalid parameters provided: " . json_encode(['params' => $params])); + return ['status' => "Failed", 'message' => "Client Policy ID is missing or empty", 'data' => ['params' => $params]]; + } + + if (!isset($params['action_type']) || empty($params['action_type'])) { + $this->myLogger->logme("error", "Invalid action type: " . json_encode(['params' => $params])); + return ['status' => "Failed", 'message' => "Action type is missing or empty", 'data' => ['params' => $params]]; + } + + $policy_data = $this->clientPolicyModel + ->where('id', $params['client_policy_id']) + ->where('is_active', 1) + ->first(); + + if (empty($policy_data)) { + $this->myLogger->logme("error", "No policy data found: " . json_encode(['client_policy_id' => $params['client_policy_id']])); + return ['status' => "Failed", 'message' => "No policy data found for the given client policy ID", 'data' => ['params' => $params]]; + } + + $lead_data = $this->leadsModel + ->where('is_policy_created', $params['client_policy_id']) + ->where('is_active', 1) + ->first(); + + if (empty($lead_data)) { + $this->myLogger->logme("error", "No lead data found: " . json_encode(['client_policy_id' => $params['client_policy_id']])); + return ['status' => "Failed", 'message' => "No lead data found for the given client policy ID", 'data' => ['params' => $params]]; + } + + $this->myLogger->logme("error", "Constructing policy transaction data: " . json_encode(['policy_data' => $policy_data, 'lead_data' => $lead_data])); + + $policyTransactionData = $this->constructBDSData($policy_data, $lead_data, $params); + + $insert_id = $this->policyTransactionModel->insert($policyTransactionData); + + if (!$insert_id) { + $this->myLogger->logme("error", "Failed to insert into policy_transaction: " . json_encode($policyTransactionData)); + return ['status' => "Failed", 'message' => "Failed to insert policy transaction record", 'data' => ['params' => $params]]; + } + + $this->myLogger->logme("error", "Policy transaction inserted successfully: " . json_encode(['insert_id' => $insert_id])); + + //do not remove this commented item + // $coShareDetails = $this->ConstructPTShareData($policy_data, $insert_id); + // $pt_co_share_id = $this->PTCOShareDetailsModel->insert($coShareDetails); + + // $this->myLogger->logme("error", "PT Co share data inserted successfully: " . json_encode(['pt_co_share_id' => $pt_co_share_id])); + + $lead_installment_data = $this->leadInstallmentPaymentDetailesModel + ->select('lead_id, installment_amount, payment_date, utr_no') + ->where('lead_id', $lead_data['id']) + ->where('is_active', 1) + ->findAll(); + + if (!empty($lead_installment_data) && (isset($params['action_type']) && $params['action_type'] == "inception")) { + $this->myLogger->logme("error", "Found lead installment data: " . json_encode($lead_installment_data)); + + $installment_ids = $this->constructInstallmentData($lead_installment_data, $insert_id); + + $this->myLogger->logme("error", "Installment data inserted: " . json_encode(['installment_ids' => $installment_ids])); + }else{ + $this->myLogger->logme("error", "Failed to insert Installment data : " . json_encode($params)); + } + + return ['status' => "Success", 'message' => "Policy transaction entry created successfully", 'data' => ['params' => $params, 'insert_id' => $insert_id]]; + } catch (\Throwable $e) { + $this->myLogger->logme("error", "Exception occurred in makeEntryForBDSPolicyTransaction(): " . json_encode([ + 'error' => $e->getMessage(), + 'trace' => $e->getTraceAsString() + ])); + + return ['status' => "Error", 'message' => "An unexpected error occurred", 'data' => ['error' => $e]]; + } + } + + private function constructBDSData($policy_data, $lead_data, $params) + { + + $policyTransactionData = [ + + 'issuer' => 2, + 'client_id' => $policy_data['client_id'] ?? null, + 'client_branch_id' => $policy_data['client_branch_id'] ?? null, + 'insurer_id' => $policy_data['insurer_id'] ?? null, + 'insurer_branch_id' => $policy_data['insurer_branch_id'] ?? null, + 'tpa_id' => $policy_data['tpa_id'] ?? null, + 'tpa_branch_id' => $policy_data['tpa_branch_id'] ?? null, + 'policy_type_id' => $policy_data['policy_type_id'] ?? null, + 'client_policy_id' => $policy_data['id'] ?? null, + 'policy_no' => $policy_data['policy_no'] ?? null, + 'cd_ac_no' => $policy_data['cd_ac_no'] ?? null, + 'cd_ac_pk' => $policy_data['cd_ac_pk'] ?? null, + 'policy_issue_date' => $policy_data['policy_start_date'] ?? null, + 'policy_start_date' => $policy_data['policy_start_date'] ?? null, + 'policy_end_date' => $policy_data['policy_end_date'] ?? null, + 'data_received_date' => $policy_data['data_received_date'] ?? null, + 'closure_date' => $policy_data['closure_date'] ?? null, + 'emp_count' => $policy_data['emp_count'] ?? null, + 'dependent_count' => $policy_data['dependent_count'] ?? null, + 'revenue_type' => ($lead_data['lead_type'] == 1 ? "NA" : ($lead_data['lead_type'] == 2 ? "EA" : "EANR") ) ?? null, + 'co_share' => $policy_data['co_share'] ?? 0, + 'pre_payable_by' => $policy_data['pre_payable_by'] ?? 1, + 'renewal_date' => $policy_data['policy_end_date'] ?? null, + 'month' => date('Y-m-01', strtotime($policy_data['policy_start_date'])) ?? null, + 'ct_type' => 1, + 'is_cd_reduce_from_bds' => 0, + 'client_type_id' => 0, + + 'status' => "completed", + 'action_type' => $params['action_type'] ?? null, + 'endorsement_no' => $params['endorsement_no'] ?? null, + 'issue_type' => $lead_data['lead_type'] ?? null, + 'source_client_policy_id' => $lead_data['source_policy_id'] ?? null, + 'tsi' => generate_tsi_code($lead_data['lead_type']) ?? null, + 'installment' => $lead_data['no_of_installment'] ?? null, + ]; + + $this->myLogger->logme("error", "Constructed policy transaction data: " . json_encode($policyTransactionData)); + + return $policyTransactionData; + } + + private function ConstructPTShareData($policy_data, $pt_id) + { + $coShareData = [ + 'pt_id' => $pt_id, + 'insurer_id' => $policy_data['insurer_id'], + 'insurer_branch_id' => $policy_data['insurer_branch_id'], + 'co_share_type' => 1, + ]; + + $this->myLogger->logme("error", "Constructed PT co-share data: " . json_encode($coShareData)); + + + return $coShareData; + } + + private function constructInstallmentData($data, $pt_id) + { + if (!empty($data)) { + $installment_ids = []; + foreach ($data as $key => &$value) { + $value['pt_id'] = $pt_id; + $installment_ids[] = $this->BdsPlacementModel->insert($value); + } + unset($value); + + return $installment_ids; + } + } + + + + public function retriveBDSPolicyTransactionEntry() + { + + } } diff --git a/app/Controllers/JobWorker.php b/app/Controllers/JobWorker.php index fcaf2096..c471a9e6 100755 --- a/app/Controllers/JobWorker.php +++ b/app/Controllers/JobWorker.php @@ -123,6 +123,10 @@ class JobWorker extends AdminController 'type' => 'CC', // Handler Category 'handler' => 'App\Controllers\EmpDataServiceController', ], + 'makeEntryForBDSPolicyTransaction' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmpDataServiceController', + ], 'employeesEnrollmentInsert' => [ 'type' => 'CC', // Handler Category 'handler' => 'App\Controllers\EmployeeServiceController', diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 6e6c6952..77a6ba81 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -241,8 +241,12 @@ class LeadsController extends BaseController $form_file_name = "file_name_" . $index_plus_one; $form_docs_name = "docs_name_" . $index_plus_one; $leads_file_primary_key = $data['leads_file_id'] ?? []; - $files = $this->request->getFileMultiple($form_file_name); - $multi_file_data = $this->uploadMultiFiles($files, $data[$form_docs_name], $leads_file_primary_key); + + $multi_file_data = []; + if(isset($data[$form_docs_name])){ + $files = $this->request->getFileMultiple($form_file_name); + $multi_file_data = $this->uploadMultiFiles($files, $data[$form_docs_name], $leads_file_primary_key); + } // Separate the insurer and insurer branch, handle missing or invalid data if (isset($data['insurer']) && strpos($data['insurer'], '-') !== false) { @@ -631,10 +635,8 @@ class LeadsController extends BaseController } } - //--------RFQ----------------------------------------------------------------------------------------------- - public function viewRFQ($id, $type = 1) { @@ -679,7 +681,9 @@ class LeadsController extends BaseController if ($lead_data['lead_type'] != 1) { $client_policy_data = $this->clientPolicyModel->where('is_active', 1)->where('id', $lead_data['source_policy_id'])->first(); - $data['policy_terms'] = $client_policy_data['policy_terms']; + if (isset($client_policy_data)) { + $data['policy_terms'] = $client_policy_data['policy_terms']; + } } $data['question_json'] = $lead_data['question_json']; @@ -738,7 +742,10 @@ class LeadsController extends BaseController if ($lead_data['lead_type'] != 1 && $data['rfq_count'] == 0) { $client_policy_data = $this->clientPolicyModel->where('is_active', 1)->where('id', $lead_data['source_policy_id'])->first(); - $data['rfq_data']['json'] = $client_policy_data['placement_json']; + if (isset($client_policy_data)) { + + $data['rfq_data']['json'] = $client_policy_data['placement_json']; + } } if (!empty($data['question_json'])) { @@ -2686,64 +2693,103 @@ class LeadsController extends BaseController public function featchLeadDataAndInsertClient($lead_id) { - $data = $this->leadsModel->where('leads.id', $lead_id)->where('leads.is_active', 1)->first(); + try { + $data = $this->leadsModel->where('leads.id', $lead_id)->where('leads.is_active', 1)->first(); - if (!$data) { - return $this->respond(['status' => false, 'message' => 'Failed to create Client', 'data' => null], 200); + if (!$data) { + $this->myLogger->logme('featchLeadDataAndInsertClient', "Lead not found or inactive", ['lead_id' => $lead_id]); + return $this->respond(['status' => false, 'message' => 'Failed to create Client', 'data' => null], 200); + } + + $result = $this->createClientWithLeadData($data); + + if ($result) { + $policy_data = $this->clientPolicyModel->where('client_id', $result)->where('is_active', 1)->first(); + return $this->respond([ + 'status' => true, + 'message' => 'New Client created successfully', + 'client_id' => $result, + 'data' => $data, + 'client_policy_id' => $policy_data['id'] ?? null, + ], 200); + } + + $this->myLogger->logme('featchLeadDataAndInsertClient', "Client creation failed after processing", ['lead_id' => $lead_id]); + return $this->respond(['status' => false, 'message' => 'Failed to create client', 'data' => $data], 200); + } catch (\Throwable $e) { + $this->myLogger->logme('error', 'featchLeadDataAndInsertClient failed'); + return $this->respond(['status' => false, 'message' => 'Internal server error', 'error' => $e->getMessage()], 500); } - - $result = $this->createClientWithLeadData($data); - - if ($result) { - - $policy_data = $this->clientPolicyModel->where('client_id', $result)->where('is_active', 1)->first(); - return $this->respond(['status' => true, 'message' => 'New Client created successfully', 'client_id' => $result, 'data' => $data, 'client_policy_id' => $policy_data['id']], 200); - } - - return $this->respond(['status' => false, 'message' => 'Failed to create client', 'data' => $data], 200); } public function createClientWithLeadData($data) { - $client_data = $this->prepareClientData($data); - $client_id = $this->clientModel->insert($client_data); + try { + $client_data = $this->prepareClientData($data); + $client_id = $this->clientModel->insert($client_data); - if ($client_id) { - $this->createClientBranchAndContactWithLeadData($data, $client_id); - $this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update(); + if ($client_id) { + $this->createClientBranchAndContactWithLeadData($data, $client_id); + $this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update(); + } + + return $client_id; + } catch (\Throwable $e) { + $this->myLogger->logme('error','createClientWithLeadData failed'); + return false; } + } - return $client_id; + public function createClientBranchAndContactWithLeadData($data, $client_id) + { + try { + $branch_data = $this->prepareClientBranchData($data, $client_id); + $branch_id = $this->clientBranchModel->insert($branch_data); + + if ($branch_id) { + $this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update(); + $contact_data = $this->prepareContactData($data, $branch_id); + $this->levelContactModel->insert($contact_data); + $this->createClientPolicyWithLeadData($data, $client_id, $branch_id); + } + + return $branch_id; + } catch (\Throwable $e) { + $this->myLogger->logme('error','createClientBranchAndContactWithLeadData failed'); + return false; + } + } + + public function createClientPolicyWithLeadData($data, $client_id, $branch_id) + { + try { + $client_policy_data = $this->prepareClientPolicyData($data, $client_id, $branch_id); + $client_policy_id = $this->clientPolicyModel->insert($client_policy_data); + + if ($client_policy_id) { + $this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update(); + $this->leadsModel->where('id', $data['id'])->set('is_policy_created', $client_policy_id)->update(); + } + + return $client_policy_id; + } catch (\Throwable $e) { + $this->myLogger->logme('error','createClientPolicyWithLeadData failed'); + return false; + } } private function prepareClientData($data) { return [ - 'client_type' => $data['client_type'], - 'entity_type_id' => $data['entity_type_id'], - 'client_code' => $data['client_code'], - 'client_name' => $data['client_name'], - 'short_name' => $data['client_short_name'], - 'pan' => $data['pan'], + 'client_type' => $data['client_type'] ?? null, + 'entity_type_id' => $data['entity_type_id'] ?? null, + 'client_code' => $data['client_code'] ?? null, + 'client_name' => $data['client_name'] ?? null, + 'short_name' => $data['client_short_name'] ?? null, + 'pan' => $data['pan'] ?? null, ]; } - public function createClientBranchAndContactWithLeadData($data, $client_id) - { - $branch_data = $this->prepareClientBranchData($data, $client_id); - $branch_id = $this->clientBranchModel->insert($branch_data); - - if ($branch_id) { - $this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update(); - $contact_data = $this->prepareContactData($data, $branch_id); - $this->levelContactModel->insert($contact_data); - - $this->createClientPolicyWithLeadData($data, $client_id, $branch_id); - } - - return $branch_id; - } - private function prepareClientBranchData($data, $client_id) { $default_unit = trim(($data['client_short_name'] ?? '') . '-' . ($data['branch_code'] ?? ''), '-'); @@ -2768,19 +2814,6 @@ class LeadsController extends BaseController ]; } - public function createClientPolicyWithLeadData($data, $client_id, $branch_id) - { - $client_policy_data = $this->prepareClientPolicyData($data, $client_id, $branch_id); - $client_policy_id = $this->clientPolicyModel->insert($client_policy_data); - - - if ($client_policy_id) { - $this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update(); - } - - return $client_policy_id; - } - private function prepareClientPolicyData($data, $client_id, $branch_id) { $proposel_data = json_decode($data['proposel_data'], true); @@ -2830,17 +2863,46 @@ class LeadsController extends BaseController private function preparePolicyTermsFromRFQ($data) { - $proposel_data = json_decode($data['proposel_data'], true); + try { + $proposel_data = json_decode($data['proposel_data'], true); + $QCRData = $this->RFQModel->where('is_active', 1)->where('lead_id', $data['id'])->first(); - $QCRData = $this->RFQModel->where('is_active', 1)->where('lead_id', $data['id'])->first(); + if (!$QCRData) { + throw new \Exception('RFQ Data not found'); + } - $JSON = json_decode($QCRData['json'], true); + $JSON = json_decode($QCRData['json'], true); + $converted_json = $this->transformProposelData($JSON, $proposel_data['proposel_name'], $proposel_data['insurer_name']); - $converted_json = $this->transformProposelData($JSON, $proposel_data['proposel_name'], $proposel_data['insurer_name']); - - return $this->convertQCRJsonToPolicyTerms($converted_json, $data['policy_type_id'], $proposel_data['proposel_name'], $proposel_data['insurer_name']); + return $this->convertQCRJsonToPolicyTerms($converted_json, $data['policy_type_id'], $proposel_data['proposel_name'], $proposel_data['insurer_name']); + } catch (\Throwable $e) { + $this->myLogger->logme('error','preparePolicyTermsFromRFQ'); + return null; + } } + public function featchClientPolicyFromLead($client_id, $branch_id, $lead_id) + { + $data = $this->leadsModel->where('leads.id', $lead_id)->where('leads.is_active', 1)->first(); + + if (!$data) { + return $this->respond(['status' => false, 'message' => 'Failed to create policy', 'data' => null], 200); + } + + $result = $this->createClientPolicyWithLeadData($data, $client_id, $branch_id); + // print_r($result); die; + + if ($result) { + + $policy_data = $this->clientPolicyModel->where('id', $result)->where('is_active', 1)->first(); + return $this->respond(['status' => true, 'message' => 'New Policy created successfully', 'client_policy_id' => $result, 'data' => $data, 'client_id' => $policy_data['client_id']], 200); + } + + return $this->respond(['status' => false, 'message' => 'Failed to create policy', 'data' => $data], 200); + } + + // --------------------------------------------------------------------------------------------------------------- + //Function for convert the RFQ and QCR Json to Policy Terms Json public function convertQCRJsonToPolicyTerms($data, $policy_type, $proposel_name, $insurer_name) { @@ -2965,26 +3027,6 @@ class LeadsController extends BaseController } } - public function featchClientPolicyFromLead($client_id, $branch_id, $lead_id) - { - $data = $this->leadsModel->where('leads.id', $lead_id)->where('leads.is_active', 1)->first(); - - if (!$data) { - return $this->respond(['status' => false, 'message' => 'Failed to create policy', 'data' => null], 200); - } - - $result = $this->createClientPolicyWithLeadData($data, $client_id, $branch_id); - // print_r($result); die; - - if ($result) { - - $policy_data = $this->clientPolicyModel->where('id', $result)->where('is_active', 1)->first(); - return $this->respond(['status' => true, 'message' => 'New Policy created successfully', 'client_policy_id' => $result, 'data' => $data, 'client_id' => $policy_data['client_id']], 200); - } - - return $this->respond(['status' => false, 'message' => 'Failed to create policy', 'data' => $data], 200); - } - public function getPlacementJson(array $data): ?string { $proposel_data = json_decode($data['proposel_data'], true); @@ -3082,7 +3124,7 @@ class LeadsController extends BaseController } - function getLastFiveFinancialYears() + public function getLastFiveFinancialYears() { $currentYear = date('Y'); $currentMonth = date('m'); diff --git a/app/Controllers/LoginController.php b/app/Controllers/LoginController.php index f5f31844..bf7f116c 100755 --- a/app/Controllers/LoginController.php +++ b/app/Controllers/LoginController.php @@ -94,7 +94,7 @@ class LoginController extends BaseController // setcookie('session_data', '', time() - 3600, $path); $path = getenv('cookie.Path'); $domain = getenv('cookie.Domain'); - $https = getenv('ccokie.secure'); + $https = getenv('cookie.secure'); setcookie('session_data',null, time() -3600, $path, $domain, $https, true); return redirect()->to(base_url('login')); } diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index d7270335..ee8dfe6c 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -235,8 +235,7 @@ class PolicyTransactionController extends BaseController ->where('role', 3) // Assuming `role` is in `user_profiles` ->where('is_active', 1) ->findAll(); - - // echo '
';
+ // echo '';
// print_r($data['ppTeamsData']); die;
// dd($data);
@@ -357,7 +356,9 @@ class PolicyTransactionController extends BaseController
// print_r($data); die;
$insert = $this->policyTransactionModel->insert($data);
+
if ($insert) {
+
$this->insertTransactionStatus($insert, $data, 1);
$emp_data = $this->processInsertIndividualMemberInEmpTable($data);
@@ -366,19 +367,15 @@ class PolicyTransactionController extends BaseController
$pt_co_share_details = $this->insertOrUpdateCoShareDetails($data, $insert);
if ($data['ct_type'] == 2) {
-
$client_policy_insert_data = $this->prepareClientPolicyInsertData($data);
$client_policy_id = $this->clientPolicyModel->insert($client_policy_insert_data);
$this->policyTransactionModel->update($insert, ['client_policy_id' => $client_policy_id]);
$emp_policy_insert = $this->InsertIndividualEmpPolicyTable($emp_data, $client_policy_id);
-
- if ($data['client_type'] == 1 && $data['status'] == 'completed' && $data['is_cd_reduce_from_bds'] == 1) {
- $this->processCompletedStatus($data, $client_policy_id, $data['insurer_id']);
- }
}
-
- $data['pt_co_share_details'] = $this->PTCOShareDetailsModel->where('pt_id', $insert)->where('is_active', 1)->findAll();
+ if ($data['client_type'] == 1 && $data['status'] == 'completed' && $data['is_cd_reduce_from_bds'] == 1) {
+ $this->processCompletedStatus($data, $client_policy_id, $data['insurer_id']);
+ }
}
$client_data = $this->clientModel->where('id', $data['client_id'])->first();
@@ -387,6 +384,7 @@ class PolicyTransactionController extends BaseController
return $this->respondSuccess($insert, "Policy transaction created successfully", $data);
}
+
return $this->respondError("Failed to create policy transaction");
}
@@ -2906,4 +2904,52 @@ class PolicyTransactionController extends BaseController
$this->myLogger->logme('error', 'Exception: ' . $e->getMessage() . 'Page: ' . $e->getFile() . ' Line: ' . $e->getLine());
}
}
+
+ public function getMoreInfo() {
+
+ $pt_id = $this->request->getPost("pt_id");
+ $data_to_send['bds_data'] = $this->BdsPlacementModel->where("is_active",1)->where("pt_id",$pt_id)->findAll();
+
+ foreach ($data_to_send['bds_data'] as &$data) {
+
+ $data['payment_date'] = (new \DateTime($data['payment_date']))->format('d-m-Y');
+ }
+
+ if (!empty($data_to_send)) {
+
+ return $this->respond(['status' => true , "data" => $data_to_send],200);
+ }else {
+
+ return $this->respond(['status' => false,"No Data Found For the Policy Transaction"],404);
+ }
+
+ }
+
+ public function saveInstallment() {
+
+ $installments = $this->request->getPost('installments');
+
+ if (!$installments || !is_array($installments)) {
+ return $this->respond(['status' => false, 'message' => 'No data received'], 400);
+ }
+
+ $this->myLogger->logme("error",json_encode($installments));
+ // die();
+
+ foreach ($installments as &$row) {
+ // Convert date from d-m-Y to Y-m-d
+ if (!empty($row['payment_date'])) {
+ $date = \DateTime::createFromFormat('d-m-Y', $row['payment_date']);
+ if ($date) {
+ $row['payment_date'] = $date->format('Y-m-d');
+ }
+ }
+ $this->BdsPlacementModel->save($row);
+ }
+
+ return $this->respond(['status' => true, 'message' => 'Data saved successfully'], 200);
+ }
+
+
+
}
diff --git a/app/Models/BdsPlacementModel.php b/app/Models/BdsPlacementModel.php
index 2cd7c6f4..82edfce5 100644
--- a/app/Models/BdsPlacementModel.php
+++ b/app/Models/BdsPlacementModel.php
@@ -22,6 +22,39 @@ class BdsPlacementModel extends Model
'is_active'
];
+ // Callbacks
+ protected $allowCallbacks = true;
+ protected $beforeInsert = ["checkAndADDCreatedByValue"];
+ protected $afterInsert = [];
+ protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
+ protected $afterUpdate = [];
+ protected $beforeFind = [];
+ protected $afterFind = [];
+ protected $beforeDelete = [];
+ protected $afterDelete = [];
+
+ protected function checkAndADDCreatedByValue(array $data)
+ {
+ // Check if 'updated_by' value is null or empty
+ if (empty($data['data']['created_by'])) {
+ // Set 'updated_by' value to the current session user ID
+ $data['data']['created_by'] = get_session_userid();
+ }
+
+ return $data;
+ }
+
+ protected function checkAndUpdateUpdatedByValue(array $data)
+ {
+ // Check if 'updated_by' value is null or empty
+ if (empty($data['data']['updated_by'])) {
+ // Set 'updated_by' value to the current session user ID
+ $data['data']['updated_by'] = get_session_userid();
+ }
+
+ return $data;
+ }
+
public function getClientInstallmentDetails()
{
diff --git a/app/Models/LeadsModel.php b/app/Models/LeadsModel.php
index a345a14e..fc0e2bb3 100644
--- a/app/Models/LeadsModel.php
+++ b/app/Models/LeadsModel.php
@@ -96,6 +96,7 @@ class LeadsModel extends Model
'is_installment',
'no_of_installment',
+ 'is_policy_created',
];
@@ -176,7 +177,8 @@ class LeadsModel extends Model
->where('leads.is_active', 1)
->where('leads.status', 'won')
->where("leads.proposel_data IS NOT NULL AND leads.proposel_data <> ''")
- ->where("(leads.is_client_created = '' OR leads.is_client_created IS NULL)");
+ ->where("(leads.is_client_created = '' OR leads.is_client_created IS NULL)")
+ ->where("(leads.is_policy_created = '' OR leads.is_policy_created IS NULL)");
diff --git a/app/Views/client_list.php b/app/Views/client_list.php
index 592031dc..673c5eaf 100755
--- a/app/Views/client_list.php
+++ b/app/Views/client_list.php
@@ -17,6 +17,10 @@ table.dataTable thead th {
max-width: 98% !important;
}
+.btn-filter{
+ margin-left: 20px !important;
+}
+
.custom-dropdown-menu {
display: none;
position: absolute;
@@ -53,12 +57,12 @@ table.dataTable thead th {
Client List
-
+