diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 7c5eef43..dd23b93f 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -169,6 +169,13 @@ class LeadsController extends BaseController { // print_r($data); die; $processedData = []; + $uploadFilePath = WRITEPATH . 'uploads/lead_files/'; + + // Get all uploaded files for 'file_name[]' + $files = $this->request->getFileMultiple('file_name'); + + // print_r($files); die; + foreach($data['policy_type_id'] as $index => $value){ @@ -215,7 +222,21 @@ class LeadsController extends BaseController }else{ $policy_end_date = null; } - + + if(!empty($data['incurred_claims_date'][$index])){ + $incurred_claims_date = change_date_format($data['incurred_claims_date'][$index], 'd/m/Y', 'Y-m-d'); + }else{ + $incurred_claims_date = null; + } + + if(!empty($data['premium_date'][$index])){ + $premium_date = change_date_format($data['premium_date'][$index], 'd/m/Y', 'Y-m-d'); + }else{ + $premium_date = null; + } + + $file_name = file_Upload($files[$index], $uploadFilePath); + $processedData[] = [ 'lead_type' => $data['lead_type'], 'issuer' => $data['issuer'], @@ -244,13 +265,36 @@ class LeadsController extends BaseController '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, + 'incurred_claims' => $data['incurred_claims'][$index] ?? 0, '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, + 'renewal_emp_count' => $data['renewal_emp_count'][$index] ?? 0, + 'renewal_dept_count' => $data['renewal_dept_count'][$index] ?? 0, + 'renewal_no_of_lives' => $data['renewal_no_of_lives'][$index] ?? 0, + 'incept_emp_count' => $data['incept_emp_count'][$index] ?? 0, + 'incept_dept_count' => $data['incept_dept_count'][$index] ?? 0, + 'incept_no_of_lives' => $data['incept_no_of_lives'][$index] ?? 0, + 'exp_emp_count' => $data['exp_emp_count'][$index] ?? 0, + 'exp_dept_count' => $data['exp_dept_count'][$index] ?? 0, + 'exp_no_of_lives' => $data['exp_no_of_lives'][$index] ?? 0, + + 'incurred_claims_date' => $incurred_claims_date, + 'paid_claims' => $data['paid_claims'][$index] ?? 0, + 'outstanding_claims' => $data['outstanding_claims'][$index] ?? 0, + 'policy_run_days' => $data['policy_run_days'][$index] ?? 0, + 'premium_at_inception' => $data['premium_at_inception'][$index] ?? 0, + 'premium_date' => $premium_date, + 'earned_premium' => $data['earned_premium'][$index] ?? 0, + 'annualised_claims' => $data['annualised_claims'][$index] ?? 0, + 'incurred_claims_ratio' => $data['incurred_claims_ratio'][$index] ?? 0, + 'earned_claims_ratio' => $data['earned_claims_ratio'][$index] ?? 0, + + 'file_name' => $file_name, + 'status' => $data['status'] ?? null, 'notes' => $data['notes'] ?? null, ]; @@ -332,13 +376,13 @@ class LeadsController extends BaseController $data['rfq_data'] = $this->RFQModel ->where('lead_id', $id) - ->where('type', $type) + // ->where('type', $type) ->where('is_active', 1) ->first(); $data['rfq_count'] = $this->RFQModel ->where('lead_id', $id) - ->where('type', 1) + // ->where('type', 1) ->where('is_active', 1) ->countAllResults(); @@ -352,7 +396,7 @@ class LeadsController extends BaseController $data['lead_id'] = $id; $lead_data = $this->leadsModel - ->select('leads.*, policy_type.question_json') + ->select('leads.*, policy_type.question_json, policy_type.policy_type') ->join('policy_type', 'leads.policy_type_id = policy_type.id') ->where('leads.id', $id) ->where('leads.is_active', 1) @@ -376,6 +420,8 @@ class LeadsController extends BaseController } public function createRFQ(){ + + // print_r($this->request->getPost('json')); die(); $data = $this->request->getPost(); $lead_id = $data['lead_id']; @@ -459,7 +505,8 @@ class LeadsController extends BaseController { $rfq_data = $this->RFQModel->getRFQTableDataWithLeadIDAndType($lead_id, $type); - // dd($rfq_data, $lead_id, $type); + // dd($rfq_data, $lead_id, $type, $propsal_and_insurer); + // print_r($propsal_and_insurer); die; $lead_data = [ 'Insured' => $rfq_data['client_name'], @@ -470,11 +517,13 @@ class LeadsController extends BaseController $data = json_decode($rfq_data['json'], true); if($type == 2){ - $data = $this->convertJsonForQCR($data, 'stc'); + $data = $this->convertJsonForQCR($data, $type); if($propsal_and_insurer !== null){ list($proposal_key, $insurer_key) = explode('-', $propsal_and_insurer, 2); $data = $this->transformProposelData($data, $proposal_key, $insurer_key); } + }else if($type == 1){ + $data = $this->convertJsonForQCR($data, $type); } $spreadsheet = new Spreadsheet(); @@ -687,11 +736,13 @@ class LeadsController extends BaseController //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') - ->join('user_profiles', 'leads.created_by = user_profiles.id') + ->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(); + // print_r($lead_data ); die; + $cc_mails = []; //get CC Mails @@ -699,6 +750,7 @@ class LeadsController extends BaseController $cc_data = isset($params['cc']) ? $params['cc'] : ""; $param_cc_mail = json_decode($cc_data, true); + if (isset($param_cc_mail) && is_array($param_cc_mail) && count($param_cc_mail) > 0) { // Fetch user data where ID is in the param_cc_mail array $userData = $this->userModel @@ -714,13 +766,13 @@ class LeadsController extends BaseController // 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); - } + // 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); + // return $this->respond(['status' => 'failed','code' => 400,'data' => '','message' => 'CC mail not found!'], 200); } } @@ -793,7 +845,12 @@ class LeadsController extends BaseController $data = [ 'proposel_data' => json_encode($lead_update_data), - 'status' => 'won' + 'status' => 'won', + 'placement_date' => change_date_format($params['placement_date'], 'd/m/Y', 'Y-m-d'), + 'utr_no' => $params['utr_no'], + 'premium_amount' => $params['premium_amount'], + 'total_amount' => $params['total_amount'], + 'cd_amount' => $params['cd_amount'], ]; $this->leadsModel->where('id', $lead_id)->set($data)->update(); @@ -835,7 +892,7 @@ class LeadsController extends BaseController } } - function transformProposelData($data, $proposel, $insurer){ + public function transformProposelData($data, $proposel, $insurer){ // print_r($data['premium_data']['data']); die; @@ -943,14 +1000,17 @@ class LeadsController extends BaseController } - function convertJsonForQCR($json, $type) + 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 ($proposalData['stc'] == 0 || $proposalData['stc'] === false) { // Remove matching parentHeader in headers foreach ($first_json['table_data']['headers'] as $index => $header) { @@ -969,7 +1029,7 @@ class LeadsController extends BaseController // Remove proposalKey from over_all_column_data unset($first_json['proposal_data']['over_all_column_data'][$proposalKey]); - if($type == 'stc'){ + if($type == 2){ // Remove proposalKey from premium_data unset($first_json['premium_data']['data'][$proposalKey]); } @@ -996,7 +1056,7 @@ class LeadsController extends BaseController // Remove insurer from proposal's insurers array unset($first_json['proposal_data']['over_all_column_data'][$proposalKey]['insurers'][$insurerIndex]); - if($type == 'stc'){ + if($type == 2){ unset($first_json['premium_data']['data'][$proposalKey][$insurer['display_name']]); } } @@ -1302,4 +1362,11 @@ class LeadsController extends BaseController } + //------------------------------------------------------------------------------------------------ + + + public function transformMailContent() + { + + } } \ No newline at end of file diff --git a/app/Models/LeadsModel.php b/app/Models/LeadsModel.php index cae506f2..c9cdccbb 100644 --- a/app/Models/LeadsModel.php +++ b/app/Models/LeadsModel.php @@ -37,7 +37,7 @@ class LeadsModel extends Model 'policy_start_date', 'policy_end_date', 'no_of_lives', - 'claims', + 'incurred_claims', 'location', 'proposed_insurer_id', 'proposed_insurer_branch_id', @@ -52,6 +52,34 @@ class LeadsModel extends Model 'updated_by', 'is_active', 'is_client_created', + + 'renewal_emp_count', + 'renewal_dept_count', + 'renewal_no_of_lives', + 'incept_emp_count', + 'incept_dept_count', + 'incept_no_of_lives', + 'exp_emp_count', + 'exp_dept_count', + 'exp_no_of_lives', + 'file_name', + + 'incurred_claims_date', + 'paid_claims', + 'outstanding_claims', + 'policy_run_days', + 'premium_at_inception', + 'premium_date', + 'earned_premium', + 'annualised_claims', + 'incurred_claims_ratio', + 'earned_claims_ratio', + + 'placement_date', + 'utr_no', + 'premium_amount', + 'total_amount', + 'cd_amount', ]; diff --git a/app/Models/RFQModel.php b/app/Models/RFQModel.php index d616e517..c1ce649b 100644 --- a/app/Models/RFQModel.php +++ b/app/Models/RFQModel.php @@ -76,7 +76,7 @@ class RFQModel extends Model ->join('tpa', 'leads.tpa_id = tpa.id', 'left') ->join('tpa_branch', 'leads.tpa_branch_id = tpa_branch.id', 'left') ->where('rfq.lead_id', $lead_id) - ->where('rfq.type', $type) + // ->where('rfq.type', $type) ->where('rfq.is_active', 1) ->first(); diff --git a/app/Views/leads_form.php b/app/Views/leads_form.php index ce675ad4..0d04d44e 100644 --- a/app/Views/leads_form.php +++ b/app/Views/leads_form.php @@ -32,6 +32,7 @@ color: white !important; margin-right: 5px; } +