diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 6e6c6952..0a16cb5e 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -631,10 +631,8 @@ class LeadsController extends BaseController } } - //--------RFQ----------------------------------------------------------------------------------------------- - public function viewRFQ($id, $type = 1) { @@ -2686,64 +2684,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('featchLeadDataAndInsertClient', $e->getMessage(), ['lead_id' => $lead_id, 'trace' => $e->getTraceAsString()]); + 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('createClientWithLeadData', $e->getMessage(), ['lead_id' => $data['id'], 'trace' => $e->getTraceAsString()]); + 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('createClientBranchAndContactWithLeadData', $e->getMessage(), ['lead_id' => $data['id'], 'trace' => $e->getTraceAsString()]); + 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_id)->update(); + } + + return $client_policy_id; + } catch (\Throwable $e) { + $this->myLogger->logme('createClientPolicyWithLeadData', $e->getMessage(), ['lead_id' => $data['id'], 'trace' => $e->getTraceAsString()]); + 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 +2805,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 +2854,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('preparePolicyTermsFromRFQ', $e->getMessage(), ['lead_id' => $data['id'], 'trace' => $e->getTraceAsString()]); + 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 +3018,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 +3115,7 @@ class LeadsController extends BaseController } - function getLastFiveFinancialYears() + public function getLastFiveFinancialYears() { $currentYear = date('Y'); $currentMonth = date('m'); diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index d7270335..ea4a45de 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -357,7 +357,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 +368,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 +385,7 @@ class PolicyTransactionController extends BaseController return $this->respondSuccess($insert, "Policy transaction created successfully", $data); } + return $this->respondError("Failed to create policy transaction"); } diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index 33f504c0..0d4529c3 100755 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -55,8 +55,8 @@ if (!function_exists('file_Upload')) { function file_Upload($fileToUpload, $filepath) { if ($fileToUpload !== null && $fileToUpload->isValid() && !$fileToUpload->hasMoved()) { + $fileToUpload->move($filepath); $fileName = $fileToUpload->getName(); - $fileToUpload->move($filepath, $fileName); return $fileName; } else { return ""; 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 {