diff --git a/app/Config/Constants.php b/app/Config/Constants.php index 47b92f83..d86cf312 100755 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -92,3 +92,25 @@ define('EVENT_PRIORITY_NORMAL', 100); * @deprecated Use \CodeIgniter\Events\Events::PRIORITY_HIGH instead. */ define('EVENT_PRIORITY_HIGH', 10); + +/** + * @User Role Constant + */ + +define('ENROLLMENT_TEAM_ID', '1'); +define('CLAIMS_TEAM_ID', '2'); +define('BUSINESS_TEAM_ID', '3'); +define('FINANCE_TEAM_ID', '4'); +define('SALES_TEAM_ID', '5'); + +/** + * @User Teams Constant + */ + +define('ADMIN_ROLE_ID', 1); +define('MANAGER_ROLE_ID', 2); +define('ACCOUNT_MANAGER_ROLE_ID', 3); +define('STAFF_ROLE_ID', 4); +define('HEAD_ROLE_ID', 5); + + diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index e40b7c1f..07512fc2 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -3135,14 +3135,17 @@ class ClientController extends AdminController // Fetch policies in a single query $policies = $this->clientPolicyModel - ->select(' + ->select(" client_policy.*, policy_type.policy_type, policy_type.ebp, policy_type.etp, policy_type.iep, - policy_type.itp - ') + policy_type.itp, + policy_type.bap, + DATE_FORMAT(client_policy.policy_start_date, '%d/%m/%Y') as policy_start_date, + DATE_FORMAT(client_policy.policy_end_date, '%d/%m/%Y') as policy_end_date + ") ->join('policy_type', 'policy_type.id = client_policy.policy_type_id') ->whereIn('client_policy.client_id', $clientIds) ->where('client_policy.is_active', 1) @@ -3220,6 +3223,7 @@ class ClientController extends AdminController 'aadhar' => $postData['aadhar'], 'phone' => $postData['phone'], 'email' => $postData['email'], + 'entity_type_id' => 7 ]); } else { $client_data['entity_type_id'] = $postData['entity_type_id']; @@ -3397,8 +3401,4 @@ class ClientController extends AdminController } } - - - - } \ No newline at end of file diff --git a/app/Controllers/LoginController.php b/app/Controllers/LoginController.php index 42c885d2..10c42716 100755 --- a/app/Controllers/LoginController.php +++ b/app/Controllers/LoginController.php @@ -41,13 +41,20 @@ class LoginController extends BaseController $user = $UserModel->getUserByEmail($value->email); if($user){ if($user->is_active !== '0'){ + + $user_team = $UserModel->getUserTeamsByUserID($user->id); + // dd($user_team); + $session_data = [ 'isLoggedIn' => True , 'userid' => $user->id, 'userData' => $user, 'userProfile' => $value->picture, + 'user_team' => $user_team, ]; + set_session_data($session_data); + log_message('error', 'Set The UserId : `'. $user->id .'` in Session'); log_message('error', 'User Login Sucessfully'); diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 68ce024d..aa1fcd06 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -1388,7 +1388,7 @@ class MasterController extends AdminController $cd_data = $this->CDMasterModel->where('client_id', $data['client_id'])->where('insurer_id', $data['insurer_id'])->findAll(); - return $this->respond(['status' => true, 'data' => $cd_data, 'message' => 'CD Account number created successfully'], 200); + return $this->respond(['status' => true, 'data' => $cd_data, 'cd_ac_no'=>$data['cd_ac_no'], 'message' => 'CD Account number created successfully'], 200); }else{ return $this->respond(['status' => false, 'message' => 'Failed to created CD Account number'], 200); } diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index b73c9daf..e5f9348a 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -205,14 +205,36 @@ class PolicyTransactionController extends BaseController $data = $this->request->getPost(); // print_r($data); die; + // var_dump($data); die; // Format dates - $data['policy_issue_date'] = date('Y-m-d', strtotime($data['policy_issue_date'])) ?? null; - $data['policy_start_date'] = date('Y-m-d', strtotime($data['policy_start_date'])) ?? null; - $data['policy_end_date'] = date('Y-m-d', strtotime($data['policy_end_date'])) ?? null; - $data['renewal_date'] = date('Y-m-d', strtotime($data['renewal_date'])) ?? null; - $data['rollover_date'] = date('Y-m-d', strtotime($data['rollover_date'])) ?? null; - + // $data['policy_issue_date'] = change_date_format($this->request->getPost('policy_issue_date'), 'd/m/Y', 'Y-m-d') ?? null; + // $data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd/m/Y', 'Y-m-d') ?? null; + // $data['policy_end_date'] = change_date_format($this->request->getPost('policy_end_date'), 'd/m/Y', 'Y-m-d') ?? null; + // $data['renewal_date'] = change_date_format($this->request->getPost('renewal_date'), 'd/m/Y', 'Y-m-d') ?? null; + // $data['rollover_date'] = change_date_format($this->request->getPost('rollover_date'), 'd/m/Y', 'Y-m-d') ?? null; + + $data['policy_issue_date'] = (isset($data['policy_issue_date']) && $data['policy_issue_date'] !== null && $data['policy_issue_date'] !== '') + ? date('d/m/Y', strtotime($data['policy_issue_date'])) + : null; + + $data['policy_start_date'] = (isset($data['policy_start_date']) && $data['policy_start_date'] !== null && $data['policy_start_date'] !== '') + ? date('d/m/Y', strtotime($data['policy_start_date'])) + : null; + + $data['policy_end_date'] = (isset($data['policy_end_date']) && $data['policy_end_date'] !== null && $data['policy_end_date'] !== '') + ? date('d/m/Y', strtotime($data['policy_end_date'])) + : null; + + $data['renewal_date'] = (isset($data['renewal_date']) && $data['renewal_date'] !== null && $data['renewal_date'] !== '') + ? date('d/m/Y', strtotime($data['renewal_date'])) + : null; + + $data['rollover_date'] = (isset($data['rollover_date']) && $data['rollover_date'] !== null && $data['rollover_date'] !== '') + ? date('d/m/Y', strtotime($data['rollover_date'])) + : null; + + // Separate Insurer and TPA Branch IDs and IDs if(isset($data['insurer_id']) && !empty($data['insurer_id'])){ list($data['insurer_branch_id'], $data['insurer_id']) = explode('-', $data['insurer_id']); @@ -242,13 +264,19 @@ class PolicyTransactionController extends BaseController $data['same_as_proposer'] = 1; } - $month = '01-'.$data['month']; - $data['month'] = date('Y-m-d', strtotime($month)); + if($data['ct_type'] == ""){ + $data['ct_type'] = 1; + } + + $month = '01-'.(string)$this->request->getPost('month'); + $data['month'] = empty($data['month']) ? null : date('Y-m-d', strtotime($month)); // Determine $is_addon value $data['is_addon'] = in_array($data['policy_type_id'], [1, 2, 6, 7]) ? 1 : (in_array($data['policy_type_id'], [4, 5]) ? 2 : ($data['policy_type_id'] == 3 && $data['base_policy'] ? 3 : 1)); + // print_r($data); die; + return $data; } @@ -272,7 +300,7 @@ class PolicyTransactionController extends BaseController $this->policyTransactionModel->update($insert, ['client_policy_id' => $client_policy_id]); $emp_policy_insert = $this->InsertIndividualEmpPolicyTable($emp_data, $client_policy_id); - if ($data['status'] == 'completed') { + if ($data['client_type'] == 1 && $data['status'] == 'completed') { $this->processCompletedStatus($data, $client_policy_id, $data['insurer_id']); } } @@ -321,7 +349,9 @@ class PolicyTransactionController extends BaseController } if ($data['status'] == 'completed' && $data['ct_type'] == 2) { - $this->processCompletedStatus($data, $data['client_policy_id'], $data['insurer_id']); + if($data['client_type'] == 1){ + $this->processCompletedStatus($data, $data['client_policy_id'], $data['insurer_id']); + } } $data['pt_co_share_details'] = $this->PTCOShareDetailsModel->where('pt_id', $id)->where('is_active', 1)->findAll(); @@ -345,76 +375,89 @@ class PolicyTransactionController extends BaseController // print_r($data); // die; - foreach ($data['follow_insurer_id'] as $index => $insurer) { - // Separate the insurer and insurer branch - list($insurer_branch_id, $insurer_id) = explode('-', $insurer); - - // Prepare each co-share detail entry - $coShareDetails[] = [ - 'pt_id' => $pt_id, - 'insurer_id' => $insurer_id ?? 0, - 'insurer_branch_id' => $insurer_branch_id ?? 0, - 'co_share_type' => isset($data['co_share_type'][$index]) ? 2 : 1, - 'co_share_per' => $data['co_share_per'][$index] ?? 0, - 'bp_amt' => $data['base_premium'][$index] ?? 0, - 'bp_gst_amt' => $data['gst_amount'][$index] ?? 0, - 'bp_igst' => $data['igst'][$index] ?? 0, - 'bp_sgst' => $data['sgst'][$index] ?? 0, - 'bp_cgst' => $data['cgst'][$index] ?? 0, - 'tp_amt' => $data['tp_premium'][$index] ?? 0, - 'tep_amt' => $data['ter_premium'][$index] ?? 0, - 'agreed_amt' => $data['agreed_amount'][$index] ?? 0, - 'agreed_bp_per' => $data['agreed_bp'][$index] ?? 0, - 'agreed_tp_per' => $data['agreed_tp'][$index] ?? 0, - 'agreed_tep_per' => $data['agreed_ter'][$index] ?? 0, - 'standerd_bp_per' => $data['standard_bp'][$index] ?? 0, - 'standerd_tp_per' => $data['standard_tp'][$index] ?? 0, - 'standerd_tep_per' => $data['standard_ter'][$index] ?? 0, - 'actual_bp_amt' => $data['actual_bp_amt'][$index] ?? 0, - 'actual_tp_amt' => $data['actual_tp_amt'][$index] ?? 0, - 'actual_tep_amt' => $data['actual_tep_amt'][$index] ?? 0, - 'actual_bp_per' => $data['actual_bp_per'][$index] ?? 0, - 'actual_tp_per' => $data['actual_tp_per'][$index] ?? 0, - 'actual_tep_per' => $data['actual_tep_per'][$index] ?? 0, - 'actual_bp_brokerage_amt' => $data['actual_bp_brokerage_amt'][$index] ?? 0, - 'actual_tp_brokerage_amt' => $data['actual_tp_brokerage_amt'][$index] ?? 0, - 'actual_tep_brokerage_amt' => $data['actual_tep_brokerage_amt'][$index] ?? 0, - 'exp_amt' => $data['exp_amt'][$index] ?? 0, - 'amount' => $data['total'][$index] ?? 0, - 'stamp_duty' => $data['stamp_duty'][$index] ?? 0, - 'cop_amt' => $data['co_premium'][$index] ?? 0, - 'variance' => $data['variance'][$index] ?? 0, - 'reward' => $data['reward'][$index] ?? null, - '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 - ]; - } + if(isset($data['follow_insurer_id'])){ - // print_r($coShareDetails); die; - - // Separate data into insert and update batches - $insertData = array_filter($coShareDetails, function($detail) { - return empty($detail['id']); // Only insert new records - }); - - $updateData = array_filter($coShareDetails, function($detail) { - return !empty($detail['id']); // Only update existing records - }); - - // Insert new records - if (!empty($insertData)) { - $this->PTCOShareDetailsModel->insertBatch($insertData); - } - - // Update existing records - if (!empty($updateData)) { - $this->PTCOShareDetailsModel->updateBatch($updateData, 'id'); // Assuming 'id' is the unique identifier - } + foreach ($data['follow_insurer_id'] as $index => $insurer) { + + // Separate the insurer and insurer branch + list($insurer_branch_id, $insurer_id) = explode('-', $insurer); + + // Prepare each co-share detail entry + $coShareDetails[] = [ + 'pt_id' => $pt_id, + 'insurer_id' => $insurer_id ?? 0, + 'insurer_branch_id' => $insurer_branch_id ?? 0, + 'co_share_type' => $data['co_share_type'][$index] ?? null, + 'co_share_per' => $data['co_share_per'][$index] ?? 0, + 'bp_amt' => $data['base_premium'][$index] ?? 0, + 'bp_gst_amt' => $data['gst_amount'][$index] ?? 0, + 'bp_igst' => $data['igst'][$index] ?? 0, + 'bp_sgst' => $data['sgst'][$index] ?? 0, + 'bp_cgst' => $data['cgst'][$index] ?? 0, + 'tp_amt' => $data['tp_premium'][$index] ?? 0, + 'tep_amt' => $data['ter_premium'][$index] ?? 0, + 'agreed_amt' => $data['agreed_amount'][$index] ?? 0, + 'agreed_bp_per' => $data['agreed_bp'][$index] ?? 0, + 'agreed_tp_per' => $data['agreed_tp'][$index] ?? 0, + 'agreed_tep_per' => $data['agreed_ter'][$index] ?? 0, + 'standerd_bp_per' => $data['standard_bp'][$index] ?? 0, + 'standerd_tp_per' => $data['standard_tp'][$index] ?? 0, + 'standerd_tep_per' => $data['standard_ter'][$index] ?? 0, + 'actual_bp_amt' => $data['actual_bp_amt'][$index] ?? 0, + 'actual_tp_amt' => $data['actual_tp_amt'][$index] ?? 0, + 'actual_tep_amt' => $data['actual_tep_amt'][$index] ?? 0, + 'actual_bp_per' => $data['actual_bp_per'][$index] ?? 0, + 'actual_tp_per' => $data['actual_tp_per'][$index] ?? 0, + 'actual_tep_per' => $data['actual_tep_per'][$index] ?? 0, + 'actual_bp_brokerage_amt' => $data['actual_bp_brokerage_amt'][$index] ?? 0, + 'actual_tp_brokerage_amt' => $data['actual_tp_brokerage_amt'][$index] ?? 0, + 'actual_tep_brokerage_amt' => $data['actual_tep_brokerage_amt'][$index] ?? 0, + 'exp_amt' => $data['exp_amt'][$index] ?? 0, + 'amount' => $data['total'][$index] ?? 0, + 'stamp_duty' => $data['stamp_duty'][$index] ?? 0, + 'cop_amt' => $data['co_premium'][$index] ?? 0, + 'variance' => $data['variance'][$index] ?? 0, + 'reward' => $data['reward'][$index] ?? null, + '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 + ]; + } + + // print_r($pt_id); + // print_r($coShareDetails); + // die; - // print_r($this->PTCOShareDetailsModel->getLastQuery()); die; + // Separate data into insert and update batches + $insertData = array_filter($coShareDetails, function($detail) { + return empty($detail['id']); // Only insert new records + }); + + $updateData = array_filter($coShareDetails, function($detail) { + return !empty($detail['id']); // Only update existing records + }); + + // Insert new records + if (!empty($insertData)) { + $this->PTCOShareDetailsModel->insertBatch($insertData); + } + + // Update existing records + if (!empty($updateData)) { + $this->PTCOShareDetailsModel->updateBatch($updateData, 'id'); // Assuming 'id' is the unique identifier + } + + // print_r($this->PTCOShareDetailsModel->getLastQuery()); die; - return true; + // print_r($coShareDetails); + // die; + + return true; + + } + + // print_r($data); + // die; } private function prepareClientPolicyInsertData($data) @@ -598,35 +641,35 @@ class PolicyTransactionController extends BaseController ->first(); $data['policy_issue_date'] = (isset($data['policy_issue_date']) && $data['policy_issue_date'] !== null && $data['policy_issue_date'] !== '') - ? date('d-m-Y', strtotime($data['policy_issue_date'])) + ? date('d/m/Y', strtotime($data['policy_issue_date'])) : null; $data['policy_start_date'] = (isset($data['policy_start_date']) && $data['policy_start_date'] !== null && $data['policy_start_date'] !== '') - ? date('d-m-Y', strtotime($data['policy_start_date'])) + ? date('d/m/Y', strtotime($data['policy_start_date'])) : null; $data['policy_end_date'] = (isset($data['policy_end_date']) && $data['policy_end_date'] !== null && $data['policy_end_date'] !== '') - ? date('d-m-Y', strtotime($data['policy_end_date'])) + ? date('d/m/Y', strtotime($data['policy_end_date'])) : null; $data['renewal_date'] = (isset($data['renewal_date']) && $data['renewal_date'] !== null && $data['renewal_date'] !== '') - ? date('d-m-Y', strtotime($data['renewal_date'])) + ? date('d/m/Y', strtotime($data['renewal_date'])) : null; $data['rollover_date'] = (isset($data['rollover_date']) && $data['rollover_date'] !== null && $data['rollover_date'] !== '') - ? date('d-m-Y', strtotime($data['rollover_date'])) + ? date('d/m/Y', strtotime($data['rollover_date'])) : null; $data['created_at'] = (isset($data['created_at']) && $data['created_at'] !== null && $data['created_at'] !== '') - ? date('d-m-Y h:i:s A', strtotime($data['created_at'])) + ? date('d/m/Y h:i:s A', strtotime($data['created_at'])) : null; $data['updated_at'] = (isset($data['updated_at']) && $data['updated_at'] !== null && $data['updated_at'] !== '') - ? date('d-m-Y h:i:s A', strtotime($data['updated_at'])) + ? date('d/m/Y h:i:s A', strtotime($data['updated_at'])) : null; $data['month'] = (isset($data['month']) && $data['month'] !== null && $data['month'] !== '') - ? date('M-Y', strtotime($data['month'])) + ? date('M/Y', strtotime($data['month'])) : null; @@ -639,14 +682,17 @@ class PolicyTransactionController extends BaseController ->where('client_policy.is_active', 1) ->findAll(); - $data['base_policy_data'] = $this->clientPolicyModel - ->select('client_policy.*, policy_type.policy_type') - ->join('policy_type', 'policy_type.id = client_policy.policy_type_id') - ->where('client_policy.client_id', $data['client_id']) - ->where('client_policy.client_branch_id', $data['client_branch_id']) - ->where('client_policy.policy_type_id', 2) - ->where('client_policy.is_active', 1) - ->findAll(); + + // $data['base_policy_data'] = $this->clientPolicyModel + // ->select('client_policy.*, policy_type.policy_type') + // ->join('policy_type', 'policy_type.id = client_policy.policy_type_id') + // ->where('client_policy.client_id', $data['client_id']) + // ->where('client_policy.client_branch_id', $data['client_branch_id']) + // ->where('client_policy.policy_type_id', 2) + // ->where('client_policy.is_active', 1) + // ->findAll(); + + $data['base_policy_data'] = $this->clientPolicyModel->getPolicyDetailsForRemainder($data['client_id']); $data['pt_files'] = $this->PTFileModel ->join('policy_transaction', 'pt_files.pt_id = policy_transaction.id') @@ -776,8 +822,15 @@ class PolicyTransactionController extends BaseController $data_received_date = (string)$this->request->getPost('data_received_date'); $closure_date = (string)$this->request->getPost('closure_date'); - $data['data_received_date'] = date('Y-m-d', strtotime($data_received_date)); - $data['closure_date'] = date('Y-m-d', strtotime($closure_date)); + $endorse_eff_date = (string)$this->request->getPost('endorse_eff_date'); + $month = (string)$this->request->getPost('month'); + + $data['data_received_date'] = empty($data['data_received_date']) ? null : date('Y-m-d', strtotime($data_received_date)); + $data['closure_date'] = empty($data['closure_date']) ? null : date('Y-m-d', strtotime($closure_date)); + $data['endorse_eff_date'] = empty($data['endorse_eff_date']) ? null : date('Y-m-d', strtotime($endorse_eff_date)); + + $month = '01-'.$data['month']; + $data['month'] = empty($data['month']) ? null : date('Y-m-d', strtotime($month)); // Separate Insurer and TPA Branch IDs and IDs if(isset($data['insurer_id']) && !empty($data['insurer_id'])){ @@ -881,7 +934,7 @@ class PolicyTransactionController extends BaseController { if ($data['status'] == 'completed' && $data['ct_type'] == 2) { - $tolamt = $data['total'][0]; + $tolamt = $data['total'][0] ?? 0; $description = 'The following amount of Rs. ' . round($tolamt, 2) . '/- has been' . ($data['action_type'] == 'deletion' ? ' Credit ' : ' Debit ') . 'from the policy transaction'; @@ -920,10 +973,16 @@ class PolicyTransactionController extends BaseController ->where('policy_transaction.id', $id) ->first(); - $data['policy_start_date'] = date('d-m-Y', strtotime($data['s_date'])); - $data['policy_end_date'] = date('d-m-Y', strtotime($data['e_date'])); - $data['data_received_date'] = date('d-m-Y', strtotime($data['data_received_date'])); - $data['closure_date'] = date('d-m-Y', strtotime($data['closure_date'])); + $data['policy_start_date'] = empty($data['policy_start_date']) ? '' : date('d/m/Y', strtotime($data['s_date'])); + $data['policy_end_date'] = empty($data['policy_end_date']) ? '' : date('d/m/Y', strtotime($data['e_date'])); + $data['data_received_date'] = empty($data['data_received_date']) ? '' : date('d/m/Y', strtotime($data['data_received_date'])); + $data['closure_date'] = empty($data['closure_date']) ? '' : date('d/m/Y', strtotime($data['closure_date'])); + $data['endorse_eff_date'] = empty($data['endorse_eff_date']) ? '' : date('d/m/Y', strtotime($data['endorse_eff_date'])); + + $data['month'] = (isset($data['month']) && $data['month'] !== null && $data['month'] !== '') + ? date('M/Y', strtotime($data['month'])) + : null; + $data['pt_co_share_details'] = $this->PTCOShareDetailsModel->where('pt_id', $id)->where('is_active', 1)->findAll(); @@ -1218,7 +1277,6 @@ class PolicyTransactionController extends BaseController $issuer = (!isset($issuer) || $issuer === '' || $issuer === null) ? 0 : $issuer; - $data['business_list'] = $this->policyTransactionModel->getBusinessReportList($start_date, $end_date, $client_id, $insurer_id, $policy_type_id, $date_type, $issuer); $this->loadLayout('business_team_list', $data); } @@ -1467,7 +1525,7 @@ class PolicyTransactionController extends BaseController foreach ($source_data as $source_key => $source_row) { - if( ($policy_no == $source_row['policy_no']) && $endorsement_no == $source_row['endorsement_no'] && change_date_format($policy_start_date,'d-m-Y','Y-m-d') == $source_row['policy_start_date'] && change_date_format($policy_end_date,'d-m-Y','Y-m-d') == $source_row['policy_end_date'] && $client_name == $source_row['client_name']) + if( ($policy_no == $source_row['policy_no']) && $endorsement_no == $source_row['endorsement_no'] && change_date_format($policy_start_date,'d/m/Y','Y-m-d') == $source_row['policy_start_date'] && change_date_format($policy_end_date,'d/m/Y','Y-m-d') == $source_row['policy_end_date'] && $client_name == $source_row['client_name']) { $is_source_found = 1; unset($source_data[$source_key]); @@ -1558,8 +1616,8 @@ class PolicyTransactionController extends BaseController foreach ($source_data as $source_key => $source_row) { - // Kint::dump(change_date_format($excel_row[3],'d-m-Y','Y-m-d')); - if( ($policy_no == $source_row['policy_no']) && $endorsement_no == $source_row['endorsement_no'] && change_date_format($policy_start_date,'d-m-Y','Y-m-d') == $source_row['policy_start_date'] && change_date_format($policy_end_date,'d-m-Y','Y-m-d') == $source_row['policy_end_date'] && $client_name == $source_row['client_name']) + // Kint::dump(change_date_format($excel_row[3],'d/m/Y','Y-m-d')); + if( ($policy_no == $source_row['policy_no']) && $endorsement_no == $source_row['endorsement_no'] && change_date_format($policy_start_date,'d/m/Y','Y-m-d') == $source_row['policy_start_date'] && change_date_format($policy_end_date,'d/m/Y','Y-m-d') == $source_row['policy_end_date'] && $client_name == $source_row['client_name']) { $is_source_found = 1; @@ -1660,7 +1718,7 @@ class PolicyTransactionController extends BaseController $data = [ 'invoice_status' => $inv_details['invoice_status'], 'invoice_no' => $inv_details['invoice_no'], 'invoice_amount' => $inv_details['invoice_amount'], - 'invoice_date' => isset($inv_details['invoice_date']) ? change_date_format($inv_details['invoice_date'],'Y-m-d','d-m-Y') : null ]; + 'invoice_date' => isset($inv_details['invoice_date']) ? change_date_format($inv_details['invoice_date'],'Y-m-d','d/m/Y') : null ]; $data['payments'] = $inv_payment_details; return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => $data], 200); @@ -1677,7 +1735,7 @@ class PolicyTransactionController extends BaseController $invoiceStatus = $jsonData['invoice_status']; $hiddenStatementId = $jsonData['hidden_statement_id']; $invoiceNo = $jsonData['invoice_no']; - $invoiceDate = change_date_format($jsonData['invoice_date'],'d-m-Y','Y-m-d'); + $invoiceDate = change_date_format($jsonData['invoice_date'],'d/m/Y','Y-m-d'); $invoice_amount = $jsonData['invoice_amount']; //Update statement table @@ -1711,7 +1769,7 @@ class PolicyTransactionController extends BaseController 'inv_amt' => $receivedAmount, 'utr_no' => $utrNo, 'tds' => $tds, - 'received_date' => change_date_format($paymentDate,'d-m-Y','Y-m-d'), + 'received_date' => change_date_format($paymentDate,'d/m/Y','Y-m-d'), 'statement_id' => $hiddenStatementId ]; if($pk){ diff --git a/app/Helpers/session_helper.php b/app/Helpers/session_helper.php index 92f443d2..4a13df4d 100755 --- a/app/Helpers/session_helper.php +++ b/app/Helpers/session_helper.php @@ -140,6 +140,15 @@ if (!function_exists('get_session_context')) { } } +if (!function_exists('user_team')) { + function user_team() + { + // $CI =& get_instance(); + $session = \Config\Services::session(); + return $session->get('user_team'); + } +} + diff --git a/app/Models/PolicyTransactionModel.php b/app/Models/PolicyTransactionModel.php index 40e1f828..bb94a40e 100644 --- a/app/Models/PolicyTransactionModel.php +++ b/app/Models/PolicyTransactionModel.php @@ -124,7 +124,7 @@ class PolicyTransactionModel extends Model IF(policy_transaction.month IS NULL, policy_transaction.policy_issue_date, policy_transaction.month), - '%b') AS policy_issue_month, + '%b %Y') AS policy_issue_month, CASE WHEN clients.client_type = 1 THEN 'Group' WHEN clients.client_type = 2 THEN 'Retail' @@ -255,7 +255,7 @@ class PolicyTransactionModel extends Model ->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', 'client_policy.policy_type_id = policy_type.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') @@ -275,7 +275,7 @@ class PolicyTransactionModel extends Model }else{ // $fromDate = date('Y-m-d', strtotime('-30 days')); - // $toDate = date('Y-m-d'); + // $toDate = date('Y-m-d 23:59:59'); // $builder->where('policy_transaction.created_at >=', $fromDate) // ->where('policy_transaction.created_at <=', $toDate); @@ -300,12 +300,14 @@ class PolicyTransactionModel extends Model 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'); + $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'); return $builder->get()->getResultArray(); } @@ -347,7 +349,7 @@ class PolicyTransactionModel extends Model }else{ // $fromDate = date('Y-m-d', strtotime('-30 days')); - // $toDate = date('Y-m-d'); + // $toDate = date('Y-m-d 23:59:59'); // $builder->where('policy_transaction.created_at >=', $fromDate) // ->where('policy_transaction.created_at <=', $toDate); @@ -375,7 +377,7 @@ class PolicyTransactionModel extends Model 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'); + $toDate = date('Y-m-d 23:59:59'); $builder->where('policy_transaction.created_at >=', $fromDate) ->where('policy_transaction.created_at <=', $toDate); @@ -420,7 +422,7 @@ class PolicyTransactionModel extends Model }else{ // $fromDate = date('Y-m-d', strtotime('-30 days')); - // $toDate = date('Y-m-d'); + // $toDate = date('Y-m-d 23:59:59'); // $builder->where('policy_transaction.created_at >=', $fromDate) // ->where('policy_transaction.created_at <=', $toDate); @@ -448,7 +450,7 @@ class PolicyTransactionModel extends Model 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'); + $toDate = date('Y-m-d 23:59:59'); $builder->where('policy_transaction.created_at >=', $fromDate) ->where('policy_transaction.created_at <=', $toDate); @@ -463,26 +465,34 @@ class PolicyTransactionModel extends Model 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) { $builder = $this->db->table('policy_transaction') - ->select(' - policy_transaction.id, - clients.client_name, - insurers.name AS insurer_name, - policy_type.policy_type, - policy_transaction.policy_no, - policy_transaction.endorsement_no, - pt_co_share_details.exp_amt, - pt_co_share_details.variance - ') + ->select(" + policy_transaction.id, + clients.client_name, + insurers.name AS insurer_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, + + 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_amount + + ") ->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', 'left') ->join('insurers', 'pt_co_share_details.insurer_id = insurers.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) - ->groupStart() // Group the conditions for variance - ->where('pt_co_share_details.variance IS NULL') - ->orWhere('pt_co_share_details.variance', 0) - ->groupEnd(); + ->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) { @@ -494,7 +504,7 @@ class PolicyTransactionModel extends Model } else { $fromDate = date('Y-m-d', strtotime('-30 days')); - $toDate = date('Y-m-d'); + $toDate = date('Y-m-d 23:59:59'); $builder->where('policy_transaction.created_at >=', $fromDate) ->where('policy_transaction.created_at <=', $toDate); @@ -535,6 +545,11 @@ class PolicyTransactionModel extends Model '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", + 'policy_transaction.action_type as action_type_full', 'pt_co_share_details.bp_amt', 'pt_co_share_details.tp_amt', 'pt_co_share_details.tep_amt' @@ -558,7 +573,7 @@ class PolicyTransactionModel extends Model } else { $fromDate = date('Y-m-d', strtotime('-30 days')); - $toDate = date('Y-m-d'); + $toDate = date('Y-m-d 23:59:59'); $builder->where('policy_transaction.created_at >=', $fromDate) ->where('policy_transaction.created_at <=', $toDate); @@ -592,16 +607,21 @@ class PolicyTransactionModel extends Model public function getFinanceReportList($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(' + ->select(" policy_transaction.id, clients.client_name, insurers.name AS insurer_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, + policy_transaction.action_type as action_type_full, pt_co_share_details.exp_amt, pt_co_share_details.variance - ') + ") ->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id', 'left') ->join('clients', 'clients.id = policy_transaction.client_id', 'left') ->join('insurers', 'pt_co_share_details.insurer_id = insurers.id', 'left') @@ -609,6 +629,7 @@ class PolicyTransactionModel extends Model ->join('policy_type', 'policy_transaction.policy_type_id = policy_type.id', 'left') ->where('policy_transaction.is_active', 1) ->where('policy_transaction.status', 'completed') + ->where('pt_co_share_details.agreed_bp_per IS NULL OR pt_co_share_details.agreed_bp_per = 0') ->where('pt_co_share_details.actual_bp_amt IS NULL OR pt_co_share_details.actual_bp_amt = 0') ->where('pt_co_share_details.actual_bp_brokerage_amt IS NULL OR pt_co_share_details.actual_bp_brokerage_amt = 0'); @@ -624,7 +645,7 @@ class PolicyTransactionModel extends Model } else { $fromDate = date('Y-m-d', strtotime('-30 days')); - $toDate = date('Y-m-d'); + $toDate = date('Y-m-d 23:59:59'); $builder->where('policy_transaction.created_at >=', $fromDate) ->where('policy_transaction.created_at <=', $toDate); diff --git a/app/Models/UserModel.php b/app/Models/UserModel.php index 94ab4d18..8eb0e6f7 100755 --- a/app/Models/UserModel.php +++ b/app/Models/UserModel.php @@ -105,5 +105,24 @@ class UserModel extends Model ->getResult(); } + public function getUserTeamsByUserID($user_id){ + + $user_teams = $this->db->table('user_profiles') + ->select('user_teams.team_id') + ->join('user_teams', 'user_profiles.id = user_teams.user_id') + ->where('user_profiles.id', $user_id) + ->where('user_teams.is_active', 1) + ->get() + ->getResultArray(); + + if (!empty($user_teams)) { + // Extract only the 'team_id' values + $team_ids = array_column($user_teams, 'team_id'); + return $team_ids; // Return array of team IDs + } else { + return []; // Return empty array if no teams found + } + } + } ?> \ No newline at end of file diff --git a/app/Views/DashBoard.php b/app/Views/DashBoard.php index e167e919..b931e838 100755 --- a/app/Views/DashBoard.php +++ b/app/Views/DashBoard.php @@ -62,12 +62,18 @@ body { Enrolment -
-
-
-
-
+
+
+
+