diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 4aad7955..9c9d153f 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -13,8 +13,10 @@ use App\Models\LeadsModel; use App\Models\PolicyTypeModel; use App\Models\KYCEntityTypeModel; use App\Models\PolicyTransactionStatusModel; +use App\Models\InsurerBranchModel; +use App\Models\TPABranchModel; -class LeadsController extends AdminController +class LeadsController extends BaseController { use ResponseTrait; @@ -31,6 +33,8 @@ class LeadsController extends AdminController protected $policyTypeModel; protected $kycEntityTypeModel; protected $policyTransactionStatusModel; + protected $insurerBranchModel; + protected $tpaBranchModel; //variables for storing array protected $issuer; @@ -52,10 +56,12 @@ class LeadsController extends AdminController $this->policyTypeModel = new PolicyTypeModel(); $this->kycEntityTypeModel = new KYCEntityTypeModel(); $this->policyTransactionStatusModel = new PolicyTransactionStatusModel(); + $this->insurerBranchModel = new InsurerBranchModel(); + $this->tpaBranchModel = new TPABranchModel(); $this->issuer = [1 => 'JIBS', 2 => 'Nhance']; $this->clientType = [1 => 'Group', 2 => 'Individual']; - $this->leadType = [1 => 'Fresh', 2 => 'Renewal']; + $this->leadType = [1 => 'Fresh', 2 => 'Renewal', 3 => 'Roll Over']; $this->leadsStatus = [ 'queued' => 'Queued', 'qcr_sent' => 'QCR sent', @@ -71,13 +77,21 @@ class LeadsController extends AdminController { $data['page_name'] = 'Leads'; - $data['issuer'] = $this->issuer ; - $data['client_type'] = $this->clientType; - $data['lead_type'] = $this->leadType; + // Set basic data + $data['issuer'] = $this->issuer; + $data['client_type'] = $this->clientType; + $data['lead_type'] = $this->leadType; $data['lead_status'] = $this->leadsStatus; + // Fetch policy types and entity data $data['policy_type'] = $this->policyTypeModel->where('is_active', 1)->findAll(); - $data['entity'] = $this->kycEntityTypeModel->where('is_active', 1)->findAll(); + $data['entity'] = $this->kycEntityTypeModel->where('is_active', 1)->findAll(); + + // Fetch insurer and TPA branch data + $data['insurer'] = $this->insurerBranchModel->getInsurerBranchesWithInsurerNames(); + $data['tpa'] = $this->tpaBranchModel->getTpaBranchesWithTpaNames(); + + // Fetch sales team members who are active in team 5 $data['salse_team'] = $this->userModel ->select('user_profiles.*') ->join('user_teams', 'user_profiles.id = user_teams.user_id') @@ -86,9 +100,13 @@ class LeadsController extends AdminController ->where('user_profiles.is_active', 1) ->findAll(); - $data['lead_data_list'] = $this->leadsModel->getLeadDataForLising(); // dd($data); - $this->loadLayout('leads_list', $data); + + // Fetch leads data + $data['lead_data_list'] = $this->leadsModel->getLeadDataForLising(); + + // Load layout and pass data + $this->loadLayout('leads_list', $data); } public function createLead() @@ -126,9 +144,9 @@ class LeadsController extends AdminController if($data['client_code'] == 2){ $data['client_code'] = generate_client_code('IC'); } - + $data = $this->prepareMultipleLeadData($data); - + // print_r($data); die; return $data; } @@ -136,7 +154,41 @@ class LeadsController extends AdminController { $processedData = []; foreach($data['policy_type_id'] as $index => $value){ - $processedData = [ + + // Separate the insurer and insurer branch + list($insurer_branch_id, $insurer_id) = explode('-',$data['insurer'][$index]); + // Separate the tpa and tpa branch + list($tpa_branch_id, $tpa_id) = explode('-',$data['tpa'][$index]); + + // Separate the insurer and insurer branch, handle missing or invalid data + if (isset($data['proposed_insurer'][$index]) && strpos($data['proposed_insurer'][$index], '-') !== false) { + list($proposed_insurer_branch_id, $proposed_insurer_id) = explode('-', $data['proposed_insurer'][$index]); + } else { + $proposed_insurer_branch_id = 0; + $proposed_insurer_id = 0; + } + + // Separate the TPA and TPA branch, handle missing or invalid data + if (isset($data['proposed_tpa'][$index]) && strpos($data['proposed_tpa'][$index], '-') !== false) { + list($proposed_tpa_branch_id, $proposed_tpa_id) = explode('-', $data['proposed_tpa'][$index]); + } else { + $proposed_tpa_branch_id = 0; + $proposed_tpa_id = 0; + } + + if(!empty($data['policy_start_date'][$index])){ + $policy_start_date = change_date_format($data['policy_start_date'][$index], 'd/m/Y', 'Y-m-d'); + }else{ + $policy_start_date = null; + } + + if(!empty($data['policy_end_date'][$index])){ + $policy_end_date = change_date_format($data['policy_end_date'][$index], 'd/m/Y', 'Y-m-d'); + }else{ + $policy_end_date = null; + } + + $processedData[] = [ 'lead_type' => $data['lead_type'], 'issuer' => $data['issuer'], 'client_type' => $data['client_type'], @@ -144,23 +196,34 @@ class LeadsController extends AdminController 'client_short_name' => $data['client_short_name'], 'entity_type_id' => $data['entity_type_id'], 'client_code' => $data['client_code'], - 'cost_center' => $data['cost_center'], 'pan' => $data['pan'], 'gst' => $data['gst'], 'branch_name' => $data['branch_name'], 'branch_code' => $data['branch_code'], 'contact_person_name' => $data['contact_person_name'], 'contact_person_mobile' => $data['contact_person_mobile'], - 'client_id' => $data['client_id'], - 'client_branch_id' => $data['client_branch_id'], - 'source_policy_id' => $data['source_policy_id'], + 'client_id' => $data['client_id'] ?? 0, + 'client_branch_id' => $data['client_branch_id'] ?? 0, + 'source_policy_id' => $data['source_policy_id'] ?? 0, 'policy_type_id' => $value, - 'salse_person_id' => $data['salse_person_id'], - 'status' => $data['status'], - 'notes' => $data['notes'], - 'created_by' => $data['created_by'], - 'updated_by' => $data['updated_by'], - 'is_active' => $data['is_active'], + 'salse_person_id' => $data['salse_person_id'] ?? 0, + + 'insurer_id' => $insurer_id ?? 0, + 'insurer_branch_id' => $insurer_branch_id ?? 0, + 'tpa_id' => $tpa_id ?? 0, + 'tpa_branch_id' => $tpa_branch_id ?? 0, + 'policy_start_date' => $policy_start_date, + 'policy_end_date' => $policy_end_date, + 'no_of_lives' => $data['no_of_lives'][$index] ?? null, + 'claims' => $data['claims'][$index] ?? null, + 'location' => $data['location'][$index] ?? null, + 'proposed_insurer_id' => $proposed_insurer_id ?? 0, + 'proposed_insurer_branch_id' => $proposed_insurer_branch_id ?? 0, + 'proposed_tpa_id' => $proposed_tpa_id ?? 0, + 'proposed_tpa_branch_id' => $proposed_tpa_branch_id ?? 0, + + 'status' => $data['status'] ?? null, + 'notes' => $data['notes'] ?? null, ]; } @@ -169,21 +232,24 @@ class LeadsController extends AdminController private function insertNewLead($data) { - $insert = $this->leadsModel->insert($data); + $insertCount = []; + foreach($data as $value){ + $insert = $this->leadsModel->insert($value); + $insertCount[] = $insert; + $this->insertLeadStatus($insert, $value['status'], 3); + } - if ($insert) { - $this->insertLeadStatus($insert, $data['status'], 3); + if (count($insertCount) > 0) { return $this->respond(['status' => true, 'lead_id' => $insert, 'message' => 'New Lead created successfully', 'data' =>$data], 200); } - return $this->respond(['status' => true, 'lead_id' => $insert, 'message' => "Failed to create Lead", 'data' =>$data], 200); + return $this->respond(['status' => false, 'lead_id' => $insert, 'message' => "Failed to create Lead", 'data' =>$data], 200); } private function updateOldLead($id, $data) { - if ($this->leadsModel->update($id, $data)) { - - $this->insertLeadStatus($id, $data['status'], 3); + if ($this->leadsModel->where('id', $id)->set($data[0])->update()) { + $this->insertLeadStatus($id, $data[0]['status'], 3); return $this->respond(['status' => true, 'lead_id' => $id, 'message' => "Lead updated successfully", 'data' =>$data], 200); } return $this->respond(['status' => false, 'lead_id' => $id, 'message' => "Failed to update Lead", 'data' =>$data], 200); @@ -197,6 +263,18 @@ class LeadsController extends AdminController ->where('leads.id', $id) ->where('leads.is_active', 1) ->first(); + + if(!empty($data['policy_start_date'])){ + $data['policy_start_date'] = change_date_format($data['policy_start_date'], 'Y-m-d', 'd/m/Y'); + }else{ + $data['policy_start_date'] = null; + } + + if(!empty($data['policy_end_date'])){ + $data['policy_end_date'] = change_date_format($data['policy_end_date'], 'Y-m-d', 'd/m/Y'); + }else{ + $data['policy_end_date'] = null; + } if($data){ return $this->respond(['status' => true, 'data' => $data], 200); diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index c8d65de8..6a729c56 100755 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -234,13 +234,11 @@ class sendMailNotification $policy_name = $inner_item['policy_name']; if ($inner_item['relationship'] == 'Self') { - $emp_code = ' (' . $inner_item['emp_code'] . ')'; + $emp_code = '(' . $inner_item['emp_code'] . ')'; $mail = $inner_item['email_corporate']; - } else { - $emp_code = ''; - } + $name = $inner_item['name']; + } - $si = ''; $premium = ''; $gst_forself = ''; @@ -251,7 +249,7 @@ class sendMailNotification } $temp_data .= ''; - $temp_data .= '' . $inner_item['name'] . $emp_code . ''; + $temp_data .= '' . $inner_item['name'] . ($inner_item['relationship'] == 'Self' ? ' (' . $inner_item['emp_code'] . ')' : '') . ''; $temp_data .= '' . $inner_item['relationship'] . ''; $temp_data .= '' . \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') . ''; $temp_data .= '' . $si . ''; diff --git a/app/Models/LeadsModel.php b/app/Models/LeadsModel.php index 0f171b50..239ce3c5 100644 --- a/app/Models/LeadsModel.php +++ b/app/Models/LeadsModel.php @@ -29,6 +29,19 @@ class LeadsModel extends Model 'source_policy_id', 'policy_type_id', 'salse_person_id', + 'insurer_id', + 'insurer_branch_id', + 'tpa_id', + 'tpa_branch_id', + 'policy_start_date', + 'policy_end_date', + 'no_of_lives', + 'claims', + 'location', + 'proposed_insurer_id', + 'proposed_insurer_branch_id', + 'proposed_tpa_id', + 'proposed_tpa_branch_id', 'status', 'notes', 'created_at', @@ -86,6 +99,7 @@ class LeadsModel extends Model ->where('leads.is_active', 1) ->where('leads.is_active', 1) ->where('leads.is_active', 1) + ->orderBy('id', 'desc') ->findAll(); } diff --git a/app/Views/leads_form.php b/app/Views/leads_form.php index 83ba5210..15c97dbe 100644 --- a/app/Views/leads_form.php +++ b/app/Views/leads_form.php @@ -90,26 +90,11 @@ -
- - -
-
+
@@ -142,13 +127,13 @@
-
-
@@ -184,14 +169,14 @@
- +
+
+
@@ -204,32 +189,36 @@
-
-
-
-
+ +
+
+
@@ -287,13 +276,50 @@