diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 6ad4f058..655da7e1 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -327,6 +327,9 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get('view_log/(:any)', 'EmployeeController::viewLog/$1'); $routes->get('download_log/(:any)', 'EmployeeController::downloadLog/$1'); $routes->post('checkDuplicateTableFieldValue', 'ClientController::checkDuplicateTableFieldValue'); + $routes->get('getCoShareStatementDetails/(:any)', 'PolicyTransactionController::getCoShareStatementDetails/$1'); + $routes->get('getClientPolicyDataBasedOnClientAndInsuer', 'PolicyTransactionController::getClientPolicyDataBasedOnClientAndInsuer'); + $routes->get('checkCDAmountForBasePremium', 'PolicyTransactionController::checkCDAmountForBasePremium'); }); $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) { @@ -362,6 +365,8 @@ $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) { $routes->get("deletePaymentEntry/(:any)", "PolicyTransactionController::deletePaymentEntry/$1"); $routes->get("downloadSampleInsurerStatement", "PolicyTransactionController::downloadSampleInsurerStatement"); $routes->get("getFileErr/(:any)", "PolicyTransactionController::getFileErr/$1"); + $routes->get("getInsurerStatementMonth", "PolicyTransactionController::getInsurerStatementMonth"); + $routes->get("deleteStatement/(:any)", "PolicyTransactionController::deleteStatement/$1"); }); }); @@ -375,6 +380,7 @@ $routes->group("leads", ["filter" => "authMVC"], function ($routes) { $routes->get("exportQCRandRFQ/(:any)", "LeadsController::exportQCRandRFQ/$1"); $routes->get("featchLeadDataAndInsertClient/(:any)", "LeadsController::featchLeadDataAndInsertClient/$1"); $routes->get("featchClientPolicyFromLead/(:any)", "LeadsController::featchClientPolicyFromLead/$1"); + }); $routes->group("rfq", ["filter" => "authMVC"], function ($routes) { diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index fcdd14e4..eba1c8de 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -3298,11 +3298,10 @@ class ClientController extends AdminController public function getClientAndBranchAndPolicy() { + // ---------for client----------------------------------------------------------------------------- + $clients = $this->clientModel->where('is_active', 1)->findAll(); - $vehicles = $this->vehicleModel - ->select('vehicle.*, clients.client_type') - ->join('clients', 'clients.id=vehicle.owner') - ->where('vehicle.is_active', 1)->findAll(); + $clientIds = array_column($clients, 'id'); // Fetch branches in a single query @@ -3311,6 +3310,29 @@ class ClientController extends AdminController ->where('is_active', 1) ->findAll(); + // -----------for vehicle --------------------------------------------------------------------------- + + $vehicles = $this->vehicleModel + ->select('vehicle.*, clients.client_type') + ->join('clients', 'clients.id=vehicle.owner') + ->where('vehicle.is_active', 1)->findAll(); + + // -----------for Insurer --------------------------------------------------------------------------- + + //fetch all insurer data + $insurers = $this->insurerModel->where('is_active', 1)->findAll(); + + //map the insurer primary key to column + $insurersIds = array_column($insurers, 'id'); + + // Fetch insurer branches in a single query + $insurerBranches = $this->insurerBranchModel + ->whereIn('insurer_id', $insurersIds) + ->where('is_active', 1) + ->findAll(); + + // -----------for Policy --------------------------------------------------------------------------- + // Fetch policies in a single query $policies = $this->clientPolicyModel ->select(" @@ -3329,16 +3351,26 @@ class ClientController extends AdminController ->where('client_policy.is_active', 1) ->findAll(); + // -------------------------------------------------------------------------------------- + $branchList = []; $policyList = []; $policyListByClient = []; $unitList = []; + $insurerBranchList = []; + //for client branch mapping to the client foreach ($branches as $branch) { $branchList[$branch['client_id']][] = $branch; $unitList[$branch['id']][] = json_decode($branch['units']); } + //for insurer branch mapping to the insurer + foreach ($insurerBranches as $branch) { + $insurerBranchList[$branch['insurer_id']][] = $branch; + } + + //for client policy mapping to the branch and client foreach ($policies as $policy) { $policyList[$policy['client_branch_id']][] = $policy; $policyListByClient[$policy['client_id']][] = $policy; @@ -3349,6 +3381,7 @@ class ClientController extends AdminController } } + //get policy count foreach ($clients as &$client) { $client['client_policy_count'] = $policyCount[$client['id']] ?? 0; } @@ -3361,6 +3394,8 @@ class ClientController extends AdminController 'branch_data' => $branchList, 'policy_data' => $policyList, 'policyListByClient' => $policyListByClient, + 'insurer_data' => $insurers, + 'insurer_branch_data' => $insurerBranchList, 'unit_data' => $unitList, ], 200); } else { @@ -3832,6 +3867,10 @@ class ClientController extends AdminController // $PolicyTransactionController = new PolicyTransactionController(); // $res = $PolicyTransactionController->validateInsurerStatement(['file_id' => '36']); + + // $empServiceController = new EmployeeServiceController(); + // $res = $empServiceController->excelFileDataValidation(['file_id' => '319']); + // dd($res); } // ------------------------------------------------------------------------------------------------------- diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 1e4366ca..78baac0b 100755 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -3315,7 +3315,7 @@ class EmpDataServiceController extends BaseController $employee_policy_table_primaryKey[] = $result['emp_policy_primarykey']; //for cash deposite $employee_policy_table_data[] = array('id' => $result['emp_policy_primarykey'], 'date_of_exit' => $result['date_of_exit'], 'reason_for_exit' => $result['reason_for_exit'], 'status' => $result['status']); - $employees_table_data[] = array('id' => $result['employees_id'], 'emp_status' => $result['status']); + // $employees_table_data[] = array('id' => $result['employees_id'], 'emp_status' => $result['status']); $emp_endorsement_table_data[] = array('id' => $result['emp_endorsement_primarykey'], 'group_key' => $result['group_key'], 'endorsement_id' => $value[15], 'status' => 'complete'); } @@ -3329,9 +3329,9 @@ class EmpDataServiceController extends BaseController // Check if $employees_table_data is null or empty - if (empty($employees_table_data)) { - return ['status' => 'error', 'message' => 'Employees table data is empty or null.']; - } + // if (empty($employees_table_data)) { + // return ['status' => 'error', 'message' => 'Employees table data is empty or null.']; + // } // Check if $employee_policy_table_data is null or empty if (empty($employee_policy_table_data)) { @@ -3343,7 +3343,7 @@ class EmpDataServiceController extends BaseController return ['status' => 'error', 'message' => 'Employee endorsement table data is empty or null.']; } - $this->employeeModel->updateBatch($employees_table_data, 'id'); + // $this->employeeModel->updateBatch($employees_table_data, 'id'); $this->employeePolicyModel->updateBatch($employee_policy_table_data, 'id'); $this->employeePolicyModel->bulkUpdateForEndorsement($emp_endorsement_table_data); $this->storeEndorsementNumber($file_id, $endorsement_id); diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index d5e6d6f7..f94d4f6e 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -1328,7 +1328,7 @@ class EmployeeServiceController extends AdminController // } // dd($row[4]); //for emp table - $this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'emp_status','old_value' => $data['emp_status'],'new_value' => 'deactivate','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']); + // $this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'emp_status','old_value' => $data['emp_status'],'new_value' => 'deactivate','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']); // dd( $this->empEndorsementModel->getLastQuery()); // $this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'change_event','old_value' => $data['change_event'],'new_value' => 'deletion','created_by' => $file['created_by'],'remarks' => 'general deletion']); diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index a1169767..2ad7a1e8 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -182,7 +182,14 @@ class LeadsController extends BaseController { // print_r($data); die; $processedData = []; - foreach ($data['policy_type_id'] as $index => $value) { + $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){ // Separate the insurer and insurer branch, handle missing or invalid data @@ -229,6 +236,20 @@ class LeadsController extends BaseController $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'], @@ -250,20 +271,43 @@ class LeadsController extends BaseController 'policy_type_id' => $value, '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, + '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, + '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, ]; @@ -344,16 +388,16 @@ class LeadsController extends BaseController { $data['rfq_data'] = $this->RFQModel - ->where('lead_id', $id) - ->where('type', $type) - ->where('is_active', 1) - ->first(); + ->where('lead_id', $id) + // ->where('type', $type) + ->where('is_active', 1) + ->first(); $data['rfq_count'] = $this->RFQModel - ->where('lead_id', $id) - ->where('type', 1) - ->where('is_active', 1) - ->countAllResults(); + ->where('lead_id', $id) + // ->where('type', 1) + ->where('is_active', 1) + ->countAllResults(); $data['qcr_count'] = $this->RFQModel ->where('lead_id', $id) @@ -365,11 +409,11 @@ class LeadsController extends BaseController $data['lead_id'] = $id; $lead_data = $this->leadsModel - ->select('leads.*, policy_type.question_json') - ->join('policy_type', 'leads.policy_type_id = policy_type.id') - ->where('leads.id', $id) - ->where('leads.is_active', 1) - ->first(); + ->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) + ->first(); // dd($lead_data); @@ -388,8 +432,9 @@ class LeadsController extends BaseController $this->loadLayout('view_rfq.php', $data); } - public function createRFQ() - { + public function createRFQ(){ + + // print_r($this->request->getPost('json')); die(); $data = $this->request->getPost(); $lead_id = $data['lead_id']; @@ -473,8 +518,9 @@ class LeadsController extends BaseController public function constructExcelToSaveTemp($lead_id, $type, $propsal_and_insurer = null) { $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'], @@ -484,12 +530,14 @@ class LeadsController extends BaseController $data = json_decode($rfq_data['json'], true); - if ($type == 2) { - $data = $this->convertJsonForQCR($data, 'stc'); - if ($propsal_and_insurer !== null) { + if($type == 2){ + $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(); @@ -1104,11 +1152,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 @@ -1116,6 +1166,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 @@ -1131,12 +1182,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); } } @@ -1225,7 +1277,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(); @@ -1266,8 +1323,7 @@ class LeadsController extends BaseController } } - function transformProposelData($data, $proposel, $insurer) - { + public function transformProposelData($data, $proposel, $insurer){ // print_r($data['premium_data']['data']); die; @@ -1373,15 +1429,18 @@ class LeadsController extends BaseController return $data; } - - 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) { @@ -1399,8 +1458,8 @@ 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]); } @@ -1427,7 +1486,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']]); } } @@ -1786,4 +1845,12 @@ class LeadsController extends BaseController return $this->respond(['status' => false, 'message' => 'Failed to create policy', 'data' => $data], 200); } + + //------------------------------------------------------------------------------------------------ + + + public function transformMailContent() + { + + } } diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index a875e437..6a81ebf5 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -1502,25 +1502,34 @@ class MasterController extends AdminController } - public function duplicateTemplate($template_id, $event_name) + // Duplicate the insuer same policy type other events template + public function duplicateTemplate($template_id, $event_name, $insurer_id) { + // Fetch the template data based on the provided ID and ensure it is active $insurer_template_data = $this->insurerTemplateModel->where('id', $template_id) - ->where('is_active', 1) - ->first(); + ->where('is_active', 1) + ->first(); + + // Check if the event name matches the existing template's event name + $insurer_template_data_check_duplicate = $this->insurerTemplateModel + ->where('insurer_id', $insurer_id) + ->where('event_name', $event_name) + ->where('policy_type_id', $insurer_template_data['policy_type_id']) + ->where('is_active', 1) + ->findAll(); + + //if the template already exist than return the message + if (!empty($insurer_template_data_check_duplicate) && count($insurer_template_data_check_duplicate) > 0) { + return $this->respond([ + 'status' => false, + 'message' => 'Template with the same event already exists.', + 'data' => $insurer_template_data_check_duplicate + ]); + } - if ($insurer_template_data) { - - // Check if the event name matches the existing template's event name - if ($insurer_template_data['event_name'] == $event_name) { - return $this->respond([ - 'status' => false, - 'message' => 'Template with the same event already exists.', - 'data' => $insurer_template_data - ]); - } - + // Prepare data for insertion as a duplicate $data_to_insert = [ "insurer_id" => $insurer_template_data['insurer_id'], @@ -1531,28 +1540,28 @@ class MasterController extends AdminController "created_by" => get_session_user(), "is_active" => 1, ]; - + // Insert the duplicate template data $insert_result = $this->insurerTemplateModel->insert($data_to_insert); - + if ($insert_result) { return $this->respond([ - 'status' => true, - 'message' => 'Template duplicated successfully.', + 'status' => true, + 'message' => 'Template duplicated successfully.', 'data' => $insurer_template_data ]); } else { return $this->respond([ - 'status' => false, - 'message' => 'Failed to duplicate template.', + 'status' => false, + 'message' => 'Failed to duplicate template.', 'data' => $insurer_template_data ]); } } else { // No matching active template found return $this->respond([ - 'status' => false, - 'message' => 'No active template data found.', + 'status' => false, + 'message' => 'No active template data found.', 'data' => null ]); } @@ -1674,6 +1683,7 @@ class MasterController extends AdminController 'template_bg' => ROOTPATH . 'public/uploads/template_bg/', 'attachments' => WRITEPATH . 'uploads/attachments/', 'sample_import_excel' => ROOTPATH . 'public/sample_import_excel', + 'lead_files' => WRITEPATH . 'uploads/lead_files/', ]; foreach ($folders as $folderName => $folderPath) { diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 5e94b340..9873b33a 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -179,6 +179,7 @@ class PolicyTransactionController extends BaseController // Fetch additional data $data['client'] = $this->clientModel->where('is_active', 1)->findAll(); + $data['client_branch'] = $this->clientBranchModel->where('is_active', 1)->findAll(); $data['policy_type'] = $this->policyTypeModel->where('is_active', 1)->findAll(); $data['insurer'] = $this->insurerModel->where('is_active', 1)->findAll(); $data['entity'] = $this->kycEntityTypeModel->where('is_active', 1)->findAll(); @@ -473,6 +474,7 @@ class PolicyTransactionController extends BaseController 'created_by' => get_session_userid() ?? null, 'updated_by' => get_session_userid() ?? null, 'id' => $data['co_share_id'][$index] ?? null, // Assuming this is the ID to identify existing records + 'follower_policy_no' => $data['follower_policy_no'][$index] ?? null, // Assuming this is the ID to identify existing records ]; } @@ -786,10 +788,24 @@ class PolicyTransactionController extends BaseController ->findAll(); $data['pt_co_share_details'] = $this->PTCOShareDetailsModel - ->where('pt_id', $id) - ->where('is_active', 1) - ->orderBy('id', 'asc') - ->findAll(); + ->select(" + pt_co_share_details.*, + + ( + SELECT + COUNT(*) + FROM + co_share_stmt_details + WHERE + co_share_stmt_details.co_share_id = pt_co_share_details.id + AND co_share_stmt_details.is_active = 1 + ) AS record_count + ") + ->where('pt_id', $id) + ->where('is_active', 1) + ->orderBy('id', 'asc') + ->findAll(); + $data['emp_data'] = $this->employeeModel ->select('employees.*, employee_polices.id as emp_policy_id') ->join('employee_polices', 'employees.id = employee_polices.employee_id', 'left') @@ -1329,8 +1345,8 @@ class PolicyTransactionController extends BaseController //--------------------------------------------------------------------------------------------------- - //get BDS Reports data - public function reportBDS() + //get BDS Reports data old function + public function reportBDSOld() { $data['page_name'] = 'BDS Report'; @@ -1390,6 +1406,81 @@ class PolicyTransactionController extends BaseController $this->loadLayout('report_bds_filter', $data); } + //get BDS Reports data New Function + public function reportBDS() + { + + $data['page_name'] = 'BDS Report'; + + $data['issuer'] = [1 => 'JIBS', 2 => 'Nhance']; + $data['client_type'] = [1 => 'Group', 2 => 'Individual']; + $data['issuing_type'] = [1 => 'Fresh', 2 => 'Renewal', 3 => 'Roll Over']; + $data['policy_status'] = [ + 'pending' => 'Pending', + 'exported_to_insurer' => 'Exported to Insurer', + 'imported_from_insurer' => 'Imported from Insurer', + 'exported_to_tpa' => 'Exported to TPA', + 'imported_from_tpa' => 'Imported from TPA', + 'completed' => 'Completed' + ]; + $data['invoice_status_array'] = [ + 'yet_to_generate' => 'Yet to Generate', + 'generated' => 'Generated', + 'send' => 'Send', + 'recived' => 'Recived', + ]; + $data['date_type'] = [ + 'policy_issue_date' => 'Policy Issue Date', + 'policy_start_date' => 'Policy Start Date', + 'policy_end_date' => 'Policy End Date', + 'data_received_date' => 'Data Received Date', + 'closure_date' => 'Closure Date', + 'statement_month' => 'Statement Month', + ]; + + $data['insurer'] = $this->insurerModel->where('is_active', 1)->findAll(); + $data['policy_types'] = $this->policyTypeModel->where('is_active', 1)->findAll(); + $data['clients'] = $this->clientModel->where('is_active', 1)->findAll(); + + //filter datas + $start_date = $this->request->getGet('start_date'); + $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'); + $client_branch_id = $this->request->getGet('client_branch_id'); + $insurer_branch_id = $this->request->getGet('insurer_branch_id'); + $client_policy_id = $this->request->getGet('client_policy_id'); + + if($date_type == 'statement_month'){ + $start_date = (string)date('Y-m-01', strtotime($start_date)); + $end_date = (string)date('Y-m-31', strtotime($end_date)); + } + + // dd($start_date, $end_date, $date_type); + + $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; + $client_branch_id = (!isset($client_branch_id) || $client_branch_id === '' || $client_branch_id === null) ? 0 : $client_branch_id; + $insurer_branch_id = (!isset($insurer_branch_id) || $insurer_branch_id === '' || $insurer_branch_id === null) ? 0 : $insurer_branch_id; + $client_policy_id = (!isset($client_policy_id) || $client_policy_id === '' || $client_policy_id === null) ? 0 : $client_policy_id; + + + //Actual data for the list + $data['report_list'] = $this->policyTransactionModel->getBDSReportList($start_date, $end_date, $client_id, $insurer_id, $policy_type_id, $date_type, $issuer, $client_branch_id, $insurer_branch_id, $client_policy_id); + // dd($data['report_list']); + + $this->loadLayout('report_bds_filter', $data); + } + public function reportVarience() { $data['page_name'] = 'Variance Report'; @@ -1414,6 +1505,10 @@ class PolicyTransactionController extends BaseController $policy_type_id = $this->request->getGet('policy_type_id'); $date_type = $this->request->getGet('date_type'); $issuer = $this->request->getGet('issuer'); + $client_branch_id = $this->request->getGet('client_branch_id'); + $insurer_branch_id = $this->request->getGet('insurer_branch_id'); + $client_policy_id = $this->request->getGet('client_policy_id'); + $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; @@ -1424,7 +1519,12 @@ class PolicyTransactionController extends BaseController $date_type = (!isset($date_type) || $date_type === '' || $date_type === null) ? 0 : $date_type; $issuer = (!isset($issuer) || $issuer === '' || $issuer === null) ? 0 : $issuer; - $data['varience_list'] = $this->policyTransactionModel->getVarienceReportLIst($start_date, $end_date, $client_id, $insurer_id, $policy_type_id, $date_type, $issuer); + $client_branch_id = (!isset($client_branch_id) || $client_branch_id === '' || $client_branch_id === null) ? 0 : $client_branch_id; + $insurer_branch_id = (!isset($insurer_branch_id) || $insurer_branch_id === '' || $insurer_branch_id === null) ? 0 : $insurer_branch_id; + $client_policy_id = (!isset($client_policy_id) || $client_policy_id === '' || $client_policy_id === null) ? 0 : $client_policy_id; + + + $data['varience_list'] = $this->policyTransactionModel->getVarienceReportLIst($start_date, $end_date, $client_id, $insurer_id, $policy_type_id, $date_type, $issuer, $client_branch_id, $insurer_branch_id, $client_policy_id); $this->loadLayout('variance_report_list', $data); } @@ -2120,5 +2220,143 @@ class PolicyTransactionController extends BaseController } + + //--------------------------------------------------------------------------------------------------- + + public function getCoShareStatementDetails($pt_id) + { + if (!$pt_id) { + return $this->respond([ + 'status' => false, + 'code' => 400, + 'message' => 'No data found' + ], 200); + } + + // Fetch data from the database + $data = db_connect()->table("co_share_stmt_details") + ->select(" + co_share_stmt_details.*, + insurer_statements.month, + insurer_statements.invoice_status, + insurer_statements.invoice_date, + insurer_statements.invoice_no, + insurer_statements.invoice_amount, + insurer_statements.stmt_sno, + (co_share_stmt_details.actual_bp_amt + co_share_stmt_details.actual_tp_amt + co_share_stmt_details.actual_tep_amt) AS sum_of_actual_amt + ") + ->join('insurer_statements', 'co_share_stmt_details.statement_id = insurer_statements.id') + ->where([ + 'co_share_stmt_details.is_active' => 1, + 'insurer_statements.is_active' => 1, + 'co_share_stmt_details.co_share_id' => $pt_id + ]) + ->get() + ->getResultArray(); + + // Check if data exists before formatting + if ($data) { + + foreach ($data as &$row) { + // Check if invoice_date is not null before formatting + $row['invoice_date'] = $row['invoice_date'] ? change_date_format($row['invoice_date'], 'Y-m-d', 'd/m/Y') : null; + + // Check if month is not null before formatting + $row['month'] = $row['month'] ? change_date_format($row['month'], 'Y-m-d', 'M-Y') : null; + } + + return $this->respond([ + 'status' => true, + 'code' => 200, + 'data' => $data + ], 200); + } else { + return $this->respond([ + 'status' => false, + 'code' => 400, + 'message' => 'No data found' + ], 200); + } + } + + public function getClientPolicyDataBasedOnClientAndInsuer() + { + + $client_id = $this->request->getGet('client_id') ?? 0; + $client_branch_id = $this->request->getGet('client_branch_id') ?? 0; + $insurer_id = $this->request->getGet('insurer_id') ?? 0; + $insurer_branch_id = $this->request->getGet('insurer_branch_id') ?? 0; + $policy_type_id = $this->request->getGet('policy_type_id') ?? 0; + + $builder = db_connect()->table("client_policy") + ->select(" + client_policy.*, + policy_type.policy_type, + ") + ->join('policy_type', 'client_policy.policy_type_id = policy_type.id') + ->where([ + 'client_policy.is_active' => 1, + ]); + + if (!empty($client_id)) { + $builder->where('client_policy.client_id', $client_id); + } + if (!empty($client_branch_id)) { + $builder->where('client_policy.client_branch_id', $client_branch_id); + } + if (!empty($insurer_id)) { + $builder->where('client_policy.insurer_id', $insurer_id); + } + if (!empty($insurer_branch_id)) { + $builder->where('client_policy.insurer_branch_id', $insurer_branch_id); + } + if (!empty($policy_type_id)) { + $builder->where('client_policy.policy_type_id', $policy_type_id); + } + + $result = $builder->get()->getResultArray(); + + if ($result) { + return $this->respond(['status' => true,'code' => 200,'data' => $result, 'getData' => $this->request->getGet()], 200); + } else { + return $this->respond(['status' => false,'code' => 400,'message' => 'No data found'], 200); + } + } + + public function checkCDAmountForBasePremium() + { + $base_premium = $this->request->getGet('base_premium') ?? 0; + $cd_ac_no = $this->request->getGet('cd_ac_no') ?? 0; + + // Validate inputs + if (empty($cd_ac_no)) { + return $this->respond(['status' => false, 'code' => 400, 'message' => 'CD Account Number is required'], 200); + } + + // Build query + $db = db_connect(); + $builder = $db->table("cash_deposit") + ->where('cd_ac_no', $cd_ac_no) + ->where('is_active', 1) + ->orderBy('id', 'desc') + ->limit(1); + + $result = $builder->get()->getRowArray(); + + if ($result) { + // Check if base premium exceeds balance + $base_premium_greater_than_balance = $base_premium > $result['balance']; + + return $this->respond([ + 'status' => true, + 'code' => 200, + 'data' => $result, + 'base_premium_greater_than_balance' => $base_premium_greater_than_balance, + ], 200); + } + + return $this->respond(['status' => false, 'code' => 400, 'message' => 'No data found for this CD'], 200); + } + } \ No newline at end of file diff --git a/app/Models/COShareStmtDetailsModel.php b/app/Models/COShareStmtDetailsModel.php new file mode 100644 index 00000000..df007cf9 --- /dev/null +++ b/app/Models/COShareStmtDetailsModel.php @@ -0,0 +1,38 @@ +join('employees', 'employees.id = ep.employee_id'); $query1->join('client_policy', 'client_policy.id = ep.client_policy_id'); $query1->join('client_branch', 'client_branch.id = employees.client_branch_id'); - $query1->join('policies', 'policies.id = client_policy.policy_id'); - $query1->join('policy_type', 'policy_type.id = policies.policy_type_id'); - $query1->join('insurers', 'insurers.id = policies.insurer_id'); + // $query1->join('policies', 'policies.id = client_policy.policy_id'); + $query1->join('policy_type', 'policy_type.id = client_policy.policy_type_id'); + $query1->join('insurers', 'insurers.id = client_policy.insurer_id'); $query1->whereIn('e.actions', ['c']); $query1->where('ep.client_policy_id', $policy_id); $query1->where('employees.client_id', $client_id); @@ -874,7 +873,6 @@ class EmployeePolicyModel extends Model e.endorsement_id, e.remarks, ep.client_policy_id, - policies.name as policy_name, insurers.short_name as insurer_short_name, client_policy.policy_no, policy_type.policy_type @@ -883,10 +881,10 @@ class EmployeePolicyModel extends Model $query2->join('employees', 'employees.id = ep.employee_id'); $query2->join('client_policy', 'client_policy.id = ep.client_policy_id'); $query2->join('client_branch', 'client_branch.id = employees.client_branch_id'); - $query2->join('policies', 'policies.id = client_policy.policy_id'); - $query2->join('policy_type', 'policy_type.id = policies.policy_type_id'); - $query2->join('insurers', 'insurers.id = policies.insurer_id'); - $query2->whereIn('e.actions', ['si', 'd']); + // $query2->join('policies', 'policies.id = client_policy.policy_id'); + $query2->join('policy_type', 'policy_type.id = client_policy.policy_type_id'); + $query2->join('insurers', 'insurers.id = client_policy.insurer_id'); + $query2->whereIn('e.actions', ['si', 'd', 'a']); $query2->where('ep.client_policy_id', $policy_id); $query2->where('employees.client_id', $client_id); $query2->where('employees.client_branch_id', $branch_id); @@ -900,6 +898,8 @@ class EmployeePolicyModel extends Model $results2 = $query2->get()->getResultArray(); $results = array_merge($results1, $results2); + + // dd($this->db->getLastQuery()); return $results; diff --git a/app/Models/InsurerModel.php b/app/Models/InsurerModel.php index a19cd02a..61572263 100755 --- a/app/Models/InsurerModel.php +++ b/app/Models/InsurerModel.php @@ -60,7 +60,7 @@ class InsurerModel extends Model { $insurer_data = $this->db->table('insurer_excel_export_template') ->select('insurer_excel_export_template.*, insurers.name as insurer_name, insurers.is_multi_event') - ->select('CASE WHEN insurers.is_multi_event = 1 THEN "All" ELSE insurer_excel_export_template.event_name END as event_name', false) + // ->select('CASE WHEN insurers.is_multi_event = 1 THEN "All" ELSE insurer_excel_export_template.event_name END as event_name', false) ->select('insurer_excel_export_template.type_name, insurer_excel_export_template.jsoncolumns, policy_type.policy_type') ->join('insurers', 'insurers.id = insurer_excel_export_template.insurer_id') ->join('policy_type', 'policy_type.id = insurer_excel_export_template.policy_type_id') diff --git a/app/Models/InsurerStatements.php b/app/Models/InsurerStatements.php index 0e2dc2ec..257624cd 100644 --- a/app/Models/InsurerStatements.php +++ b/app/Models/InsurerStatements.php @@ -23,7 +23,11 @@ class InsurerStatements extends Model "invoice_no", "invoice_amount", "invoice_date", - "updated_by" + "updated_by", + "stmt_sno", + "gst_per", + "gst_value", + "invoice_value" ]; diff --git a/app/Models/InvPaymentDetailsModel.php b/app/Models/InvPaymentDetailsModel.php index 262f76d6..7f7a7522 100644 --- a/app/Models/InvPaymentDetailsModel.php +++ b/app/Models/InvPaymentDetailsModel.php @@ -16,6 +16,7 @@ class InvPaymentDetailsModel extends Model 'inv_amt', 'utr_no', 'tds', + 'gst', 'received_date', 'created_by', 'is_active', 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/PTCOShareDetailsModel.php b/app/Models/PTCOShareDetailsModel.php index 385645ed..bb2eb359 100644 --- a/app/Models/PTCOShareDetailsModel.php +++ b/app/Models/PTCOShareDetailsModel.php @@ -63,11 +63,15 @@ class PTCOShareDetailsModel extends Model 'amount', 'stamp_duty', 'cop_amt', - 'statement_id' + 'statement_id', + 'follower_policy_no', ]; - public function getNonReconcileredPolicyTransactions(string $month,string $year,string $insurer_id,string $insurer_branch_id) + public function getNonReconcileredPolicyTransactions(string $insurer_id,string $insurer_branch_id) { + $currentDate = date('Y-m-d'); + $sixMonthsAgo = date('Y-m-01', strtotime('-6 months')); + return $this->db->table('pt_co_share_details pt_co') ->select(' pt_co.id, @@ -93,12 +97,15 @@ class PTCOShareDetailsModel extends Model ->join('policy_transaction pt', 'pt_co.pt_id = pt.id') ->join('clients c', 'pt.client_id = c.id') ->where('pt_co.is_active', 1) - ->where('MONTH(pt.month)', $month) - ->where('YEAR(pt.month)', $year) + ->where('pt.is_active', 1) + // ->where('MONTH(pt.month)', $month) + // ->where('YEAR(pt.month)', $year) ->where('pt_co.insurer_id', $insurer_id) ->where('pt_co.insurer_branch_id', $insurer_branch_id) - ->where('pt_co.statement_id is null') + // ->where('pt_co.statement_id is null') ->where('pt.status','completed') + ->where('DATE(pt.created_at) >=', $sixMonthsAgo) + ->where('DATE(pt.created_at) <=', $currentDate) // ->where('pt_co.exp_amt', 0.00) // ->orWhere('pt_co.exp_amt is null') ->get() diff --git a/app/Models/PolicyTransactionModel.php b/app/Models/PolicyTransactionModel.php index ba54a5ce..d87d3f45 100644 --- a/app/Models/PolicyTransactionModel.php +++ b/app/Models/PolicyTransactionModel.php @@ -113,8 +113,9 @@ class PolicyTransactionModel extends Model return $data; } + // BDS Report OLD Functin for QUERY // public function getBDSReportList($client_id, $policy_id, $branch_id, $issuer) - public function getBDSReportList($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0) + public function getBDSReportListOld($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0) { $builder = $this->db->table('policy_transaction') ->select(" @@ -311,6 +312,256 @@ class PolicyTransactionModel extends Model return $builder->get()->getResultArray(); } + + // BDS Report NEW Functin for QUERY + // public function getBDSReportList($client_id, $policy_id, $branch_id, $issuer) + public function getBDSReportList($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $client_branch_id = 0, $insurer_branch_id = 0, $client_policy_id = 0) + { + + $date_condition = ''; + if($date_type == 'statement_month' && $start_date != 0 && $end_date != 0) { + $date_condition = " + AND insurer_statements.month >= '".$start_date ."' + AND insurer_statements.month <= '".$end_date ."' + "; + } + + $builder = $this->db->table('policy_transaction') + ->select(" + policy_transaction.*, + DATE_FORMAT(policy_transaction.policy_issue_date, '%d %b %Y') AS policy_issue_date, + DATE_FORMAT( + IF(policy_transaction.month IS NULL, + policy_transaction.policy_issue_date, + policy_transaction.month), + '%b %Y') AS policy_issue_month, + CASE + WHEN clients.client_type = 1 THEN 'Group' + WHEN clients.client_type = 2 THEN 'Retail' + ELSE '-' + END AS client_type, + CASE + WHEN policy_transaction.revenue_type = 'NA' THEN 'Fresh' + ELSE 'Renewal' + END AS revenue_type, + CASE + WHEN policy_transaction.action_type = 'inception' THEN 'Policy' + ELSE 'Endorsement' + END AS action_type, + clients.client_name AS client_name, + clients.short_name AS client_short_name, + client_branch.branch_name AS client_branch_name, + client_branch.address1 AS client_address, + policy_type.policy_type, + policy_type.bap, + insurers.name AS insurer_name, + insurers.short_name AS insurer_short_name, + insurer_branch.branch_name AS insurer_branch_name, + insurer_branch.branch_code AS insurer_branch_code, + user_profiles.first_name as user_name, + vehicle.vehicle_no, + tpa.name as tpa_name, + pt_co_share_details.remark as remarks, + pt_co_share_details.reward, + pt_co_share_details.bp_amt, + pt_co_share_details.exp_amt, + pt_co_share_details.id as pt_id, + sales_user.first_name as salse_person_name, + service_user.first_name as service_person_name, + + ROUND((pt_co_share_details.bp_amt + pt_co_share_details.tp_amt + pt_co_share_details.tep_amt), 2) AS premium_wo_gst, + + ROUND((ROUND((pt_co_share_details.bp_amt + pt_co_share_details.tp_amt + pt_co_share_details.tep_amt), 2) * 18 / 100), 2) AS gst_amount, + + ROUND((ROUND((pt_co_share_details.bp_amt + pt_co_share_details.tp_amt + pt_co_share_details.tep_amt), 2) + ROUND((ROUND((pt_co_share_details.bp_amt + pt_co_share_details.tp_amt + pt_co_share_details.tep_amt), 2) * 18 / 100), 2)), 2) AS total_premium, + + ROUND((pt_co_share_details.tp_amt + pt_co_share_details.tep_amt), 2) AS tp_or_ter, + + DATEDIFF(policy_transaction.policy_end_date, CURDATE()) AS days, + + (pt_co_share_details.agreed_tp_per + pt_co_share_details.agreed_tep_per) AS agreed_tp_or_ter_per, + + pt_co_share_details.agreed_bp_per, + + ROUND( + ( + SELECT + ( + SUM(co_share_stmt_details.actual_bp_brokerage_amt) + + SUM(co_share_stmt_details.actual_tp_brokerage_amt) + + SUM(co_share_stmt_details.actual_tep_brokerage_amt) + + SUM(co_share_stmt_details.reward) + + ) AS total_irda_amt + FROM + co_share_stmt_details + JOIN insurer_statements ON co_share_stmt_details.statement_id = insurer_statements.id + WHERE + co_share_stmt_details.co_share_id = pt_co_share_details.id + AND co_share_stmt_details.is_active = 1 + $date_condition + ), + 2 + ) AS total_irda_amt, + + ROUND( + ( + SELECT + SUM( + COALESCE(co_share_stmt_details.actual_bp_brokerage_amt, 0) + + COALESCE(co_share_stmt_details.actual_tp_brokerage_amt, 0) + + COALESCE(co_share_stmt_details.actual_tep_brokerage_amt, 0) + + COALESCE(co_share_stmt_details.reward, 0) + ) AS total_irda_amt + FROM + co_share_stmt_details + JOIN pt_co_share_details AS pt_table ON co_share_stmt_details.co_share_id = pt_table.id + JOIN insurer_statements ON co_share_stmt_details.statement_id = insurer_statements.id + WHERE + co_share_stmt_details.co_share_id = pt_co_share_details.id + 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 + $date_condition + + ), + 2 + ) AS billed_amt, + + ROUND( + ( + ( + SELECT + SUM( + COALESCE(co_share_stmt_details.actual_bp_brokerage_amt, 0) + + COALESCE(co_share_stmt_details.actual_tp_brokerage_amt, 0) + + COALESCE(co_share_stmt_details.actual_tep_brokerage_amt, 0) + + COALESCE(co_share_stmt_details.reward, 0) + ) + FROM + co_share_stmt_details + JOIN insurer_statements ON co_share_stmt_details.statement_id = insurer_statements.id + WHERE + co_share_stmt_details.co_share_id = pt_co_share_details.id + AND co_share_stmt_details.is_active = 1 + $date_condition + ) + - + ( + SELECT + SUM( + COALESCE(co_share_stmt_details.actual_bp_brokerage_amt, 0) + + COALESCE(co_share_stmt_details.actual_tp_brokerage_amt, 0) + + COALESCE(co_share_stmt_details.actual_tep_brokerage_amt, 0) + + COALESCE(co_share_stmt_details.reward, 0) + ) + FROM + co_share_stmt_details + JOIN pt_co_share_details AS pt_table ON co_share_stmt_details.co_share_id = pt_table.id + JOIN insurer_statements ON co_share_stmt_details.statement_id = insurer_statements.id + WHERE + co_share_stmt_details.co_share_id = pt_co_share_details.id + 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 + $date_condition + ) + ), + 2 + ) AS unbilled_amt + + ") + ->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id', 'left') + ->join('insurer_statements', 'pt_co_share_details.statement_id = insurer_statements.id', 'left') + ->join('clients', 'clients.id = policy_transaction.client_id') + ->join('client_branch', 'policy_transaction.client_branch_id = client_branch.id', 'left') + ->join('client_policy', 'policy_transaction.client_policy_id = client_policy.id', 'left') + ->join('user_profiles', 'policy_transaction.created_by = user_profiles.id', 'left') + ->join('vehicle', 'policy_transaction.vehicle_id = vehicle.id', 'left') + ->join('policy_type', 'policy_transaction.policy_type_id = policy_type.id', 'left') + ->join('insurers', 'policy_transaction.insurer_id = insurers.id', 'left') + ->join('insurer_branch', 'policy_transaction.insurer_branch_id = insurer_branch.id', 'left') + ->join('tpa', 'policy_transaction.tpa_id = tpa.id', 'left') + ->join('tpa_branch', 'policy_transaction.tpa_branch_id = tpa_branch.id', 'left') + ->join('user_profiles AS sales_user', 'policy_transaction.sales_generated_by = sales_user.id', 'left') + ->join('user_profiles AS service_user', 'policy_transaction.serviced_by = service_user.id', 'left') + ->where('policy_transaction.is_active', 1) + ->where('pt_co_share_details.is_active', 1); + + // Check if the start date and end date are provided + if ($start_date != 0 && $end_date != 0 && $date_type != 0 && $date_type != 'statement_month') { + + $startDate = date('Y-m-d 00:00:00', strtotime($start_date)); + $endDate = date('Y-m-d 23:59:59', strtotime($end_date)); + + $builder->where('policy_transaction.'.$date_type.'>=', $startDate) + ->where('policy_transaction.'.$date_type.'<=', $endDate); + + }else{ + + // $fromDate = date('Y-m-d', strtotime('-30 days')); + // $toDate = date('Y-m-d 23:59:59'); + + // $builder->where('policy_transaction.created_at >=', $fromDate) + // ->where('policy_transaction.created_at <=', $toDate); + } + + if($date_type == 'statement_month' && $start_date != 0 && $end_date != 0){ + + $builder->where('policy_transaction.month >=', $startDate) + ->where('policy_transaction.month <=', $endDate); + } + + if ($client_id != 0) { + $builder->where('policy_transaction.client_id', $client_id); + } + + if ($insurer_id != 0) { + $builder->where('policy_transaction.insurer_id', $insurer_id); + } + + if ($client_branch_id != 0) { + $builder->where('policy_transaction.client_branch_id', $client_branch_id); + } + + if ($insurer_branch_id != 0) { + $builder->where('policy_transaction.insurer_branch_id', $insurer_branch_id); + } + + if ($client_policy_id != 0) { + $builder->where('policy_transaction.client_policy_id', $client_policy_id); + } + + + + if ($policy_type_id != 0) { + $builder->where('client_policy.policy_type_id', $policy_type_id); + } + + if ($issuer != 0) { + $builder->where('policy_transaction.issuer', $issuer); + } + + if($client_id == 0 && $insurer_id == 0 && $policy_type_id == 0 && $date_type == 0 && $issuer == 0){ + + $fromDate = date('Y-m-d', strtotime('-30 days')); + $toDate = date('Y-m-d 23:59:59'); + + $builder->where('policy_transaction.created_at >=', $fromDate) + ->where('policy_transaction.created_at <=', $toDate); + + } + + $builder->orderBy('policy_transaction.id', 'desc'); + + $result = $builder->get()->getResultArray(); + + // dd($this->db->getLastQuery()); + + return $result; + } public function getInceptionTranctionListData($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0) { @@ -466,50 +717,74 @@ class PolicyTransactionModel extends Model return $builder->get()->getResultArray(); } - public function getVarienceReportLIst($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0) + public function getVarienceReportLIst($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $client_branch_id = 0, $insurer_branch_id = 0, $client_policy_id = 0) { $builder = $this->db->table('policy_transaction') ->select(" + policy_transaction.id, clients.client_name, + client_branch.branch_name as client_branch_name, insurers.name AS insurer_name, + insurer_branch.branch_name AS insurer_branch_name, policy_type.policy_type, policy_transaction.policy_no, policy_transaction.endorsement_no, - CASE - WHEN policy_transaction.action_type = 'inception' THEN 'I' - ELSE 'E' - END AS action_type, + pt_co_share_details.exp_amt, pt_co_share_details.variance, - insurer_statements.invoice_amount, - insurer_statements.invoice_status, - - ROUND((pt_co_share_details.actual_bp_brokerage_amt + pt_co_share_details.actual_tp_brokerage_amt + pt_co_share_details.actual_tep_brokerage_amt), 2) AS realization_amount2, + ROUND( ( SELECT - (SUM(inv_payment_details.inv_amt) + SUM(inv_payment_details.tds)) AS realization_amount + ( + SUM(co_share_stmt_details.actual_bp_brokerage_amt) + SUM(co_share_stmt_details.actual_tp_brokerage_amt) + SUM(co_share_stmt_details.actual_tep_brokerage_amt) + ) AS total_irda_amt FROM - inv_payment_details + co_share_stmt_details + JOIN insurer_statements ON co_share_stmt_details.statement_id = insurer_statements.id WHERE - inv_payment_details.statement_id = insurer_statements.id - AND inv_payment_details.is_active = 1 - - ) AS realization_amount, + co_share_stmt_details.co_share_id = pt_co_share_details.id + AND co_share_stmt_details.is_active = 1 + ), + 2 + ) AS statement_amount, + + ROUND( + pt_co_share_details.exp_amt - + ( + SELECT + ( + SUM(co_share_stmt_details.actual_bp_brokerage_amt) + + SUM(co_share_stmt_details.actual_tp_brokerage_amt) + + SUM(co_share_stmt_details.actual_tep_brokerage_amt) + ) + FROM co_share_stmt_details + JOIN insurer_statements + ON co_share_stmt_details.statement_id = insurer_statements.id + WHERE + co_share_stmt_details.co_share_id = pt_co_share_details.id + AND co_share_stmt_details.is_active = 1 + ), + 2 + ) AS variance_amt + ") ->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id', 'left') ->join('insurer_statements', 'pt_co_share_details.statement_id = insurer_statements.id', 'left') - ->join('inv_payment_details', 'insurer_statements.id = inv_payment_details.statement_id', 'left') ->join('clients', 'clients.id = policy_transaction.client_id', 'left') + ->join('client_branch', 'client_branch.id = policy_transaction.client_branch_id', 'left') ->join('insurers', 'pt_co_share_details.insurer_id = insurers.id', 'left') + ->join('insurer_branch', 'pt_co_share_details.insurer_branch_id = insurer_branch.id', 'left') ->join('client_policy', 'policy_transaction.client_policy_id = client_policy.id', 'left') ->join('policy_type', 'policy_transaction.policy_type_id = policy_type.id', 'left') ->where('policy_transaction.is_active', 1) - ->where('pt_co_share_details.actual_bp_brokerage_amt IS NOT NULL AND pt_co_share_details.actual_bp_brokerage_amt != 0') - ->where('pt_co_share_details.variance IS NOT NULL') - ->where('pt_co_share_details.variance !=', 0); + ->where('pt_co_share_details.is_active', 1) + ->having('variance_amt IS NOT NULL'); + // ->where('pt_co_share_details.actual_bp_brokerage_amt IS NOT NULL AND pt_co_share_details.actual_bp_brokerage_amt != 0'); + // ->where('pt_co_share_details.variance IS NOT NULL') + // ->where('pt_co_share_details.variance !=', 0); if ($start_date != 0 && $end_date != 0 && $date_type != 0) { @@ -543,9 +818,18 @@ class PolicyTransactionModel extends Model $builder->where('policy_transaction.issuer', $issuer); } - if ($status != 0) { - $builder->where('policy_transaction.status', $status); + if ($client_branch_id != 0) { + $builder->where('policy_transaction.client_branch_id', $client_branch_id); } + + if ($insurer_branch_id != 0) { + $builder->where('policy_transaction.insurer_branch_id', $insurer_branch_id); + } + + if ($client_policy_id != 0) { + $builder->where('policy_transaction.client_policy_id', $client_policy_id); + } + $builder->orderBy('policy_transaction.id', 'desc'); @@ -694,7 +978,7 @@ class PolicyTransactionModel extends Model return $builder->get()->getResultArray(); } - public function getOutstandingReportList($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0) + public function getOutstandingReportList_OLD($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0) { $builder = $this->db->table('policy_transaction') ->select(" @@ -791,5 +1075,53 @@ class PolicyTransactionModel extends Model return $builder->get()->getResultArray(); } + + public function getOutstandingReportList($start_date = 0, $end_date = 0, $insurer_id = 0,$insurer_branch_id = 0) + { + $builder = $this->db->table('insurer_statements s') + ->select(' + s.id, + s.insurer_id, + s.branch_id, + ins.short_name, + ib.branch_name, + s.month, + s.line_items, + s.stmt_sno, + s.invoice_status, + s.invoice_date, + s.invoice_no, + s.invoice_amount, + COALESCE(SUM(p.inv_amt) + SUM(p.tds) + SUM(p.gst), 0) AS total_paid, + (s.invoice_amount - COALESCE(SUM(p.inv_amt) + SUM(p.tds) + SUM(p.gst), 0)) AS outstanding_amount + ') + ->join('inv_payment_details p', 's.id = p.statement_id', 'left') + ->join('insurers ins', 's.insurer_id = ins.id') + ->join('insurer_branch ib', 's.branch_id = ib.id') + ->where('s.is_active', 1) + ->where('p.is_active', 1) + ->groupBy('s.id, s.invoice_no, s.invoice_date, s.invoice_amount') + ->having('outstanding_amount >', 0); + // ->get(); + + + // Date range filtering + if ($start_date != 0 && $end_date != 0) { + + $builder->where('s.month >=', $start_date) + ->where('s.month <=', $end_date); + } + + if ($insurer_id != 0) { + $builder->where('s.insurer_id', $insurer_id); + } + if ($insurer_branch_id != 0) { + $builder->where('s.branch_id', $insurer_branch_id); + } + + $builder->orderBy('s.id', 'desc'); + + return $builder->get()->getResultArray(); + } } diff --git a/app/Models/RFQModel.php b/app/Models/RFQModel.php index 006ac637..d165b339 100644 --- a/app/Models/RFQModel.php +++ b/app/Models/RFQModel.php @@ -77,7 +77,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/insurer_export_templete.php b/app/Views/insurer_export_templete.php index 6934ab5e..19c96574 100755 --- a/app/Views/insurer_export_templete.php +++ b/app/Views/insurer_export_templete.php @@ -91,7 +91,7 @@