diff --git a/app/Config/Routes.php b/app/Config/Routes.php index c217dd5b..a9cd0ae2 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -329,6 +329,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get("getCDAccNoByClientAndInsurer/(:any)", "ClientController::getCDAccNoByClientAndInsurer/$1"); $routes->post("createClientWithMinimalData", "ClientController::createClientWithMinimalData"); $routes->post("createVehicleWithMinimalData", "ClientController::createVehicleWithMinimalData"); + $routes->post("createVehicleWithMinimalDataForBDS", "ClientController::createVehicleWithMinimalDataForBDS"); $routes->post("createClientBranchWithMinamalData", "ClientController::createClientBranchWithMinamalData"); $routes->post("createClientPolicyWithMinimalData", "ClientController::createClientPolicyWithMinimalData"); $routes->post("createCDAccountNumberUsingAjax", "MasterController::createCDAccountNumberUsingAjax"); @@ -690,6 +691,7 @@ $routes->group('test', function($routes) { $routes->get('generatePDF', 'TestingController::generatePDF'); $routes->get('viewPDF', 'TestingController::viewPDF'); $routes->get('generate-pdf-view', 'TestingController::generatePDFWithView'); + $routes->get('param/(:any)', 'TestingController::ptedfitdata/$1'); }); $routes->cli('cli/testcli', 'TestingController::testcli'); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 8ecf4184..74daba0b 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -999,31 +999,52 @@ class ClientController extends AdminController $data['client_id'] = $this->request->getPost('client_id'); $data['updated_by'] = get_session_userid(); $inserted = false; + // print_r($this->request->getPost()); die; if ($this->request->getPost('head')) { + $data['user_id'] = $this->request->getPost('head'); - $checkHead = $this->clientRMModel->checkExistenceOfClientRelation($id, $this->request->getPost('head'), 1); - if ($checkHead) { - $inserted = $this->clientRMModel->where('client_id', $id)->where('level', 1)->set($data)->update(); - } else { - $data['level'] = "1"; - $data['user_id'] = $this->request->getPost('head'); - $inserted = $this->clientRMModel->insert($data); - } + $this->clientRMModel->where('client_id', $id)->where('level', 1)->delete(); + + $data['level'] = "1"; + $data['user_id'] = $this->request->getPost('head'); + $inserted = $this->clientRMModel->insert($data); } if ($this->request->getPost('manager')) { + $data['user_id'] = $this->request->getPost('manager'); - $checkHead = $this->clientRMModel->checkExistenceOfClientRelation($id, $this->request->getPost('manager'), 2); - if ($checkHead) { - $inserted = $this->clientRMModel->where('client_id', $id)->where('level', 2)->set($data)->update(); - } else { - $data['level'] = "2"; - $data['user_id'] = $this->request->getPost('manager'); - $inserted = $this->clientRMModel->insert($data); - } + $this->clientRMModel->where('client_id', $id)->where('level', 2)->delete(); + + $data['level'] = "2"; + $data['user_id'] = $this->request->getPost('manager'); + $inserted = $this->clientRMModel->insert($data); } + // if ($this->request->getPost('head')) { + // $data['user_id'] = $this->request->getPost('head'); + // $checkHead = $this->clientRMModel->checkExistenceOfClientRelation($id, $this->request->getPost('head'), 1); + // if ($checkHead) { + // $inserted = $this->clientRMModel->where('client_id', $id)->where('level', 1)->set($data)->update(); + // } else { + // $data['level'] = "1"; + // $data['user_id'] = $this->request->getPost('head'); + // $inserted = $this->clientRMModel->insert($data); + // } + // } + + // if ($this->request->getPost('manager')) { + // $data['user_id'] = $this->request->getPost('manager'); + // $checkHead = $this->clientRMModel->checkExistenceOfClientRelation($id, $this->request->getPost('manager'), 2); + // if ($checkHead) { + // $inserted = $this->clientRMModel->where('client_id', $id)->where('level', 2)->set($data)->update(); + // } else { + // $data['level'] = "2"; + // $data['user_id'] = $this->request->getPost('manager'); + // $inserted = $this->clientRMModel->insert($data); + // } + // } + if ($this->request->getPost('account_manager')) { $this->clientRMModel->where('client_id', $id)->where('level', 3)->delete(); @@ -4422,7 +4443,9 @@ class ClientController extends AdminController // } // } - public function createClientWithMinimalData() + // ------------- CLIENT AND VEHICLE ------------------------------------------------------------------------------------------------ + + public function createClientWithMinimalData2() { $postData = $this->request->getPost(); // print_r($postData); die; @@ -4474,7 +4497,6 @@ class ClientController extends AdminController 'name' => $postData['name'], 'mobile' => $postData['mobile'], 'email' => $postData['email'], - ]; $this->levelContactModel->insert($contact_data); } @@ -4489,6 +4511,89 @@ class ClientController extends AdminController ], 200); } + public function createClientWithMinimalData() + { + $postData = $this->request->getPost(); + + // print_r($postData); die; + $client_type = $postData['client_type'] ?? null; + + $client_insert = null; + if($client_type == 2){ + + $client_data = [ + 'client_type' => $postData['client_type'], + 'client_name' => $postData['client_name'], + 'email' => $postData['short_name'] ?? $postData['client_name'], + 'phone' => $postData['mobile'], + 'client_code' => generate_client_code() + ]; + + $client_insert = $this->clientModel->insert($client_data); + + }else if($client_type == 1){ + + $client_data = [ + 'client_type' => $postData['client_type'], + 'client_name' => $postData['client_name'], + 'short_name' => $postData['short_name'] ?? $postData['client_name'], + 'client_code' => generate_client_code(), + 'entity_type_id' => 2 + ]; + + $client_insert = $this->clientModel->insert($client_data); + } + + if (!$client_insert) { + return $this->respond(['status' => false, 'message' => 'Failed to create client'], 200); + } + + // Additional logic for non-individual clients (client_type != 2) + $branch_insert = null; + if ($client_type != 2) { + $unit[] = $postData['short_name'] . '-' . 001; + $branch_data = [ + 'client_id' => $client_insert, + 'branch_name' => $postData['branch_name'], + 'branch_code' => 001, + 'gst' => $postData['gst'], + 'units' => json_encode($unit) ?? null, + ]; + + $branch_insert = $this->clientBranchModel->insert($branch_data); + if ($branch_insert) { + $contact_data = [ + 'ref_id' => $branch_insert, + 'contact_type' => 'client', + 'name' => $postData['name'], + 'email' => $postData['email'], + ]; + $this->levelContactModel->insert($contact_data); + } + } + + $clients = $this->clientModel + ->select("*, DATE_FORMAT(dob, '%d-%m-%Y') as dob") + ->where('is_active', 1) + ->findAll(); + + // Fetch branches in a single query + $branches = $this->clientBranchModel + ->where('client_id', $client_insert) + ->where('is_active', 1) + ->findAll(); + + return $this->respond([ + 'status' => true, + 'data' => $postData, + 'client_id' => $client_insert, + 'branch_id' => $branch_insert ?? null, + 'clients' => $clients, + 'branches' => $branches, + 'message' => 'Client created successfully' + ], 200); + } + public function createVehicleWithMinimalData() { $data = $this->request->getPost(); @@ -4508,7 +4613,13 @@ class ClientController extends AdminController $vehicle_insert = $this->vehicleModel->insert($data); if ($vehicle_insert) { - $vehicles = $this->vehicleModel->where('is_active', 1)->findAll(); + + // $vehicles = $this->vehicleModel->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(); + return $this->respond([ 'status' => true, 'vehicle_id' => $vehicle_insert, @@ -4525,6 +4636,160 @@ class ClientController extends AdminController } } + public function createVehicleWithMinimalDataForBDS() + { + $data = $this->request->getPost(); + // print_r($data); die; + if (isset($data['client_name']) && !empty($data['client_name'])) { + + $client_type = $data['client_type'] ?? null; + + $client_insert = null; + if ($client_type == 2) { + + $client_data = [ + 'client_type' => $data['client_type'], + 'client_name' => $data['client_name'], + 'email' => $data['short_name'] ?? $data['client_name'], + 'phone' => $data['mobile'], + 'client_code' => generate_client_code() + ]; + + $client_insert = $this->clientModel->insert($client_data); + + } else if ($client_type == 1) { + + $client_data = [ + 'client_type' => $data['client_type'], + 'client_name' => $data['client_name'], + 'short_name' => $data['short_name'] ?? $data['client_name'], + 'client_code' => generate_client_code(), + 'entity_type_id' => 2 + ]; + + $client_insert = $this->clientModel->insert($client_data); + } + + // Additional logic for non-individual clients (client_type != 2) + $branch_insert = null; + if ($client_type != 2) { + $unit[] = $data['short_name'] . '-' . 001; + $branch_data = [ + 'client_id' => $client_insert, + 'branch_name' => $data['branch_name'], + 'branch_code' => 001, + 'gst' => $data['gst'], + 'units' => json_encode($unit) ?? null, + ]; + + $branch_insert = $this->clientBranchModel->insert($branch_data); + if ($branch_insert) { + $contact_data = [ + 'ref_id' => $branch_insert, + 'contact_type' => 'client', + 'name' => $data['name'], + 'email' => $data['email'], + ]; + $this->levelContactModel->insert($contact_data); + } + } + + $vehicle_data = [ + 'vehicle_no' => $data['vehicle_no'], + 'type' => $data['type'], + 'rc' => $data['rc'], + 'branch_id' => $branch_insert, + 'owner' => $client_insert, + ]; + + $vehicle_insert = $this->vehicleModel->insert($vehicle_data); + + if ($vehicle_insert) { + + // $vehicles = $this->vehicleModel->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(); + + $clients = $this->clientModel + ->select("*, DATE_FORMAT(dob, '%d-%m-%Y') as dob") + ->where('is_active', 1) + ->findAll(); + + // Fetch branches in a single query + $branches = $this->clientBranchModel + ->where('client_id', $client_insert) + ->where('is_active', 1) + ->findAll(); + + return $this->respond([ + 'status' => true, + 'vehicle_id' => $vehicle_insert, + 'client_id' => $client_insert, + 'branch_id' => $branch_insert, + 'data' => $data, + 'clients' => $clients, + 'branches' => $branches, + 'vehicles' => $vehicles, + 'message' => 'Vehicle created successfully' + ], 200); + + } else { + return $this->respond(['status' => false, 'message' => 'Failed to created vehicle'], 200); + } + + } else if (isset($data['owner']) && !empty($data['owner'])) { + + $vehicle_data = [ + 'vehicle_no' => $data['vehicle_no'], + 'type' => $data['type'], + 'rc' => $data['rc'], + 'branch_id' => $data['branch_id'] ?? null, + 'owner' => $data['owner'], + ]; + + $vehicle_insert = $this->vehicleModel->insert($vehicle_data); + + $vehicles = $this->vehicleModel->select('vehicle.*, clients.client_type') + ->join('clients', 'clients.id = vehicle.owner') + ->where('vehicle.is_active', 1) + ->findAll(); + + $clients = $this->clientModel + ->select("*, DATE_FORMAT(dob, '%d-%m-%Y') as dob") + ->where('is_active', 1) + ->findAll(); + + // Fetch branches in a single query + $branches = $this->clientBranchModel + ->where('client_id', $data['owner']) + ->where('is_active', 1) + ->findAll(); + + if ($vehicle_insert) { + + return $this->respond([ + 'status' => true, + 'vehicle_id' => $vehicle_insert, + 'client_id' => $data['owner'], + 'branch_id' => $data['branch_id'], + 'data' => $data, + 'clients' => $clients, + 'branches' => $branches, + 'vehicles' => $vehicles, + 'message' => 'Vehicle created successfully' + ], 200); + + } else { + return $this->respond(['status' => false, 'message' => 'Failed to created vehicle'], 200); + } + } else { + + return $this->respond(['status' => false, 'message' => 'Failed to created vehicle'], 200); + } + } + public function createClientPolicyWithMinimalData() { $data = $this->request->getPost(); @@ -4560,6 +4825,9 @@ class ClientController extends AdminController } } + // ------------- CLIENT AND VEHICLE ------------------------------------------------------------------------------------------------ + + public function getPolicyDetailsByPolicyId($id) { $policies = $this->clientPolicyModel @@ -4604,6 +4872,68 @@ class ClientController extends AdminController } } + // public function get_client_policy_data_using_policy_no() + // { + // $received_data = $this->request->getGet(); + // $policy_no = $this->request->getGet('policy_no'); + // $client_id = $this->request->getGet('client_id'); + // $client_branch_id = $this->request->getGet('client_branch_id'); + // $policy_type_id = $this->request->getGet('policy_type_id'); + // $client_type = $this->request->getGet('client_type'); + + // $data = $this->clientPolicyModel + // ->select(" + // client_policy.*, + // policy_type.policy_type, + // clients.client_type, + // clients.client_name, + // 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('clients', 'client_policy.client_id = clients.id') + // ->join('policy_type', 'client_policy.policy_type_id = policy_type.id') + // ->where('client_policy.policy_no', $policy_no) + // ->where('client_policy.is_active', 1) + // ->where('client_policy.policy_status', 1) + // ->first(); + + // if ($data) { + + // if ($client_type == 1) { + // if ($data['client_id'] == $client_id && $data['client_branch_id'] == $client_branch_id) { + + // if ($data['policy_type_id'] == $policy_type_id) { + // return $this->respond(['status' => true, 'data' => $data, 'code' => 200, 'received_data' => $received_data], 200); + // } else { + // $policy_type = $this->policyTypeModel->where('id', $policy_type_id)->first(); + // $message = 'This policy number is mapped to the selected client with policy type: ' . (!empty($data['policy_type']) ? $data['policy_type'] : 'N/A') . '. You selected: ' . (!empty($policy_type['policy_type']) ? $policy_type['policy_type'] : 'N/A') . '. Please check.'; + // return $this->respond(['status' => true, 'data' => $data, 'code' => 409, "message" => $message, 'received_data' => $received_data], 200); + // } + // } else { + // $message = 'This policy number is already linked to another client' . (!empty($data['client_name']) ? '. Client name : ' . $data['client_name'] : '') . '. Please check'; + // return $this->respond(['status' => true, 'code' => 409, "message" => $message, 'received_data' => $received_data, 'db_data' => $data], 200); + // } + // } else { + // if ($data['client_id'] == $client_id) { + + // if ($data['policy_type_id'] == $policy_type_id) { + // return $this->respond(['status' => true, 'data' => $data, 'code' => 200, 'received_data' => $received_data], 200); + // } else { + // $policy_type = $this->policyTypeModel->where('id', $policy_type_id)->first(); + // $message = 'This policy number is mapped to the selected client with policy type: ' . (!empty($data['policy_type']) ? $data['policy_type'] : 'N/A') . '. You selected: ' . (!empty($policy_type['policy_type']) ? $policy_type['policy_type'] : 'N/A') . '. Please check.'; + // return $this->respond(['status' => true, 'data' => $data, 'code' => 409, "message" => $message, 'received_data' => $received_data], 200); + // } + // } else { + // $message = 'This policy number is already linked to another client' . (!empty($data['client_name']) ? '. Client name : ' . $data['client_name'] : '') . '. Please check'; + // return $this->respond(['status' => true, 'code' => 409, "message" => $message, 'received_data' => $received_data, 'db_data' => $data], 200); + // } + // } + + // } else { + // return $this->respond(['status' => false, 'message' => 'No Data Found', 'code' => 404, 'received_data' => $received_data], 200); + // } + // } + public function get_client_policy_data_using_policy_no() { $received_data = $this->request->getGet(); @@ -4613,54 +4943,14 @@ class ClientController extends AdminController $policy_type_id = $this->request->getGet('policy_type_id'); $client_type = $this->request->getGet('client_type'); - $data = $this->clientPolicyModel - ->select(" - client_policy.*, - policy_type.policy_type, - clients.client_type, - clients.client_name, - 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('clients', 'client_policy.client_id = clients.id') - ->join('policy_type', 'client_policy.policy_type_id = policy_type.id') - ->where('client_policy.policy_no', $policy_no) - ->where('client_policy.is_active', 1) - ->where('client_policy.policy_status', 1) - ->first(); + $data = $this->policyTransactionModel + ->where('is_active', 1) + ->where('action_type', 'inception') + ->where('policy_no', $policy_no) + ->countAllResults(); - if ($data) { - - if ($client_type == 1) { - if ($data['client_id'] == $client_id && $data['client_branch_id'] == $client_branch_id) { - - if ($data['policy_type_id'] == $policy_type_id) { - return $this->respond(['status' => true, 'data' => $data, 'code' => 200, 'received_data' => $received_data], 200); - } else { - $policy_type = $this->policyTypeModel->where('id', $policy_type_id)->first(); - $message = 'This policy number is mapped to the selected client with policy type: ' . (!empty($data['policy_type']) ? $data['policy_type'] : 'N/A') . '. You selected: ' . (!empty($policy_type['policy_type']) ? $policy_type['policy_type'] : 'N/A') . '. Please check.'; - return $this->respond(['status' => true, 'data' => $data, 'code' => 409, "message" => $message, 'received_data' => $received_data], 200); - } - } else { - $message = 'This policy number is already linked to another client' . (!empty($data['client_name']) ? '. Client name : ' . $data['client_name'] : '') . '. Please check'; - return $this->respond(['status' => true, 'code' => 409, "message" => $message, 'received_data' => $received_data, 'db_data' => $data], 200); - } - } else { - if ($data['client_id'] == $client_id) { - - if ($data['policy_type_id'] == $policy_type_id) { - return $this->respond(['status' => true, 'data' => $data, 'code' => 200, 'received_data' => $received_data], 200); - } else { - $policy_type = $this->policyTypeModel->where('id', $policy_type_id)->first(); - $message = 'This policy number is mapped to the selected client with policy type: ' . (!empty($data['policy_type']) ? $data['policy_type'] : 'N/A') . '. You selected: ' . (!empty($policy_type['policy_type']) ? $policy_type['policy_type'] : 'N/A') . '. Please check.'; - return $this->respond(['status' => true, 'data' => $data, 'code' => 409, "message" => $message, 'received_data' => $received_data], 200); - } - } else { - $message = 'This policy number is already linked to another client' . (!empty($data['client_name']) ? '. Client name : ' . $data['client_name'] : '') . '. Please check'; - return $this->respond(['status' => true, 'code' => 409, "message" => $message, 'received_data' => $received_data, 'db_data' => $data], 200); - } - } - + if ($data > 0) { + return $this->respond(['status' => true, 'message' => 'This policy number is already linked to another client', 'data' => $data, 'code' => 409, 'received_data' => $received_data], 200); } else { return $this->respond(['status' => false, 'message' => 'No Data Found', 'code' => 404, 'received_data' => $received_data], 200); } @@ -5259,7 +5549,7 @@ class ClientController extends AdminController // ---------- EMP SERVICE CONTROLLER -------------------------------------------------------------------------------- $empServiceController = new EmployeeServiceController(); - // $res = $empServiceController->excelFileFormatValidation(['file_id' => '865']); + $res = $empServiceController->excelFileFormatValidation(['file_id' => '2055']); // $res = $empServiceController->excelFileDataValidation(['file_id' => '865']); // $res = $empServiceController->employeesOnboardPreprocess(['file_id' => 726]); // $res = $empServiceController->employeesOnboardProcess(['file_id' => 835]); @@ -5267,7 +5557,7 @@ class ClientController extends AdminController // $res = $empServiceController->employeesSIEnhanceProcess(['file_id' => '978']); // $res = $empServiceController->employeeDisembark(['file_id' => '1681']); // $res = $empServiceController->employeesCorrectionProcess(['file_id' => '2033']); - // dd( $res); + dd( $res); $EmployeeMultiEventServiceController = new EmployeeMultiEventServiceController(); // $res = $EmployeeMultiEventServiceController->constructMultiEventData(['file_id' => '1069']); diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index c144fb0f..1c9fac18 100755 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -2020,7 +2020,16 @@ class EmpDataServiceController extends BaseController // dd($emp_endorsement_table_data, $enrollment_file_id, $no_of_insured, $no_of_dependent); //update the employee policy data (TPAID or UHID) - $return = $this->employeePolicyModel->bulkUpdate($emp_details); + if(!empty($emp_details)){ + $return = $this->employeePolicyModel->bulkUpdate($emp_details); + }else{ + $this->batchFileModel->update($file_id, [ + 'count' => 0, + 'status' => "failed-6", + 'amount' => 0, + ]); + return ['status' => 'error', 'message' => 'There is no data to update']; // Return error code + } if(in_array($file['event_type'], ['addition', 'dependent_addition']) && !empty($emp_endorsement_table_data)){ $this->employeePolicyModel->updateEmpEndorsementAddition($emp_endorsement_table_data); @@ -2048,7 +2057,6 @@ class EmpDataServiceController extends BaseController $this->storeEndorsementNumber($file_id, $endorsement_id, $enrollment_file_id); } - $this->myLogger->logme('error', 'Inception Update TPA and UHID -- set cashDepositCalculationForInception and sendMailForDownloadingECard in JOB QUEUE'); $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index e33a96ac..341bfcf2 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -134,12 +134,25 @@ class EmployeeRestController extends AdminController $client_branch_id = $this->request->getGet('client_branch_id'); if ($emp_code) { $relationship = 'self'; - $employee = $this->employeeModel->where('emp_code', $emp_code) - ->where('client_id', $client_id) - ->where('client_branch_id', $client_branch_id) - ->where('is_active', 1 ) - ->where('relationship', $relationship) - ->first(); + // $employee = $this->employeeModel->where('emp_code', $emp_code) + // ->where('client_id', $client_id) + // ->where('client_branch_id', $client_branch_id) + // ->where('is_active', 1 ) + // ->where('relationship', $relationship) + // ->first(); + $employee = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.emp_code', $emp_code) + ->where('employees.client_id', $client_id) + ->where('employees.client_branch_id', $client_branch_id) + ->where('employees.is_active', 1 ) + ->where('employees.relationship', $relationship) + ->where('employee_polices.status', ['active']) + ->where('employees.is_active', 1) + ->where('employees.emp_status', ['active']) + ->first(); + if (null !== $this->request->getGet('client_policy_id')) { $date_coverage = $this->employeePolicyModel->where('employee_id',$employee['id'])->where('client_policy_id',$this->request->getGet('client_policy_id'))->get()->getRow()->date_coverage; diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 60d3b955..c26d6fb8 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -1550,6 +1550,14 @@ class MasterController extends AdminController $date = (string) $this->request->getPost('opening_date'); $data['opening_date'] = date('Y-m-d', strtotime($date)); + $insurer_id = null; + $insurer_branch_id = null; + if(isset($data['insurer_and_insurer_branch']) && !empty($data['insurer_and_insurer_branch'])){ + list($insurer_branch_id, $insurer_id) = explode('-', $data['insurer_and_insurer_branch']); + } + + $data['insurer_branch_id'] = $insurer_branch_id; + // array with data for CD Traction table $cd_tranction_data = [ @@ -1578,7 +1586,16 @@ 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, 'cd_ac_no'=>$data['cd_ac_no'], 'message' => 'CD Account number created successfully', "FOR BDS PURPOSE"], 200); + return $this->respond([ + 'status' => true, + 'cd_ac_pk' => $insert, + 'data' => $cd_data, + 'received_data' => $data, + 'cd_ac_no'=>$data['cd_ac_no'], + 'message' => 'CD Account number created successfully', + "FOR BDS PURPOSE" + ], 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 2b9afb78..09274d01 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -36,6 +36,7 @@ use App\Models\BdsPlacementModel; use Kint\Kint; use App\Helpers\MailHelper; use App\Helpers\ExcelSanitizeHelper; +use App\Models\NhanceBranchModel; use Exception; class PolicyTransactionController extends BaseController @@ -69,6 +70,7 @@ class PolicyTransactionController extends BaseController protected $filesModel; protected $coShareStmtDetailsModel; protected $BdsPlacementModel; + protected $nhanceBranchModel; public function __construct() { @@ -100,6 +102,7 @@ class PolicyTransactionController extends BaseController $this->filesModel = new FileModel(); $this->coShareStmtDetailsModel = new COShareStmtDetailsModel(); $this->BdsPlacementModel = new BdsPlacementModel(); + $this->nhanceBranchModel = new NhanceBranchModel(); $this->invoiceStatus = [ 'pending' => 'Pending', 'generated' => 'Generated', @@ -115,6 +118,7 @@ class PolicyTransactionController extends BaseController // Static arrays for dropdowns $data['issuer'] = [1 => 'JIBS', 2 => 'Nhance']; + $data['issuer_branch'] = $this->nhanceBranchModel->where('is_active', 1)->findAll(); $data['client_type'] = [1 => 'Group', 2 => 'Individual']; $data['issuing_type'] = [1 => 'Fresh', 2 => 'Renewal', 3 => 'Roll Over']; $data['policy_status'] = [ @@ -255,6 +259,7 @@ class PolicyTransactionController extends BaseController $id = $this->request->getPost('id'); $data = $this->preparePolicyData(); $data['cd_ac_pk'] = $this->request->getPost('cd_ac_no'); + $data['issuer'] = 2; $this->myLogger->logme('error', 'Policy Trancaction modified form data ( insert data ) : '. json_encode($data)); @@ -334,11 +339,8 @@ class PolicyTransactionController extends BaseController $data['policy_with_corr'] = 1; } - if (!isset($data['is_cd_reduce_from_bds'])) { - $data['is_cd_reduce_from_bds'] = 0; - } elseif ($data['is_cd_reduce_from_bds']) { - $data['is_cd_reduce_from_bds'] = 1; - } + $data['is_cd_reduce_from_bds'] = ($data['policy_type_id'] > 7 && $data['client_type'] == 1) ? 1 : 0; + if ($data['ct_type'] == "") { $data['ct_type'] = 1; @@ -400,6 +402,8 @@ class PolicyTransactionController extends BaseController private function updateInceptionPolicy($id, $data) { // print_r($data); die; + $old_pt_data = $this->policyTransactionModel->where('is_active', 1)->where("id", $id)->first(); + $old_pt_co_share_data = $this->PTCOShareDetailsModel->where('is_active', 1)->where("id", $id)->first(); if ($this->policyTransactionModel->update($id, $data)) { $this->insertTransactionStatus($id, $data, 1); @@ -427,15 +431,22 @@ class PolicyTransactionController extends BaseController } } - if ($data['status'] == 'completed' && $data['ct_type'] == 2) { - if ($data['client_type'] == 1 && $data['is_cd_reduce_from_bds'] == 1) { - $this->processCompletedStatus($data, $data['client_policy_id'], $data['insurer_id']); + if($old_pt_data['status'] != "completed"){ + if ($data['status'] == 'completed' && $data['ct_type'] == 2) { + if ($data['client_type'] == 1 && $data['is_cd_reduce_from_bds'] == 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(); } + if(isset($data['cd_amt_changed']) && !empty($data['cd_amt_changed'])){ + $policy_data = $this->policyTransactionModel->where('is_active', 1)->where('id', $id)->first(); + $this->cdCorrection($policy_data, $data['cd_amt_changed']); + } + $client_data = $this->clientModel->where('id', $data['client_id'])->first(); $data['client_kyc'] = $this->clientKYCDocsModel->where('client_id', $data['client_id'])->findAll(); @@ -621,6 +632,30 @@ class PolicyTransactionController extends BaseController DepositHelper::saveDeposit($cdTransactionData, get_session_userid()); } + private function cdCorrection($data, $amt) + { + $totalAmount = (int)($amt ?? 0); + $description = 'The following amount of Rs. ' . $totalAmount . '/- has been debited towards the difference arising from the change in the BDS base premium.'; + + $cdTransactionData = [ + 'amount' => abs($totalAmount), + 'sub_type_id' => 4, + 'client_id' => $data['client_id'], + 'client_policy_id' => $data['client_policy_id'] ?? 0, + 'endorsement_no' => null, + 'cd_ac_no' => $data['cd_ac_no'] ?? null, + 'insurer_id' => $data['insurer_id'], + 'description' => $description, + 'transaction_type' => $totalAmount < 0 ? 'Credit' : 'Debit', + 'updated_by' => get_session_userid(), + 'event_name' => 'inception', + 'is_active' => 1, + 'cd_ac_pk' => $data['cd_ac_pk'] + ]; + + DepositHelper::saveDeposit($cdTransactionData, get_session_userid()); + } + private function processInsertIndividualMemberInEmpTable($data) { // print_r($data); @@ -753,31 +788,6 @@ class PolicyTransactionController extends BaseController ->where('policy_transaction.is_active', 1) ->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'])) - // : 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; - - // $data['month'] = (isset($data['month']) && $data['month'] !== null && $data['month'] !== '') - // ? date('M/Y', strtotime($data['month'])) - // : 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'])) : null; @@ -821,8 +831,6 @@ class PolicyTransactionController extends BaseController $data['month'] = null; } - - // print_r($data); die; $data['renewal_policy'] = $this->clientPolicyModel @@ -833,7 +841,6 @@ 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') @@ -843,6 +850,16 @@ class PolicyTransactionController extends BaseController ->where('client_policy.is_active', 1) ->findAll(); + $pt_bp_amt = $this->PTCOShareDetailsModel + ->select('bp_amt, amount') + ->where('pt_id', $id) + ->where('co_share_type', 1) + ->where('is_active', 1) + ->first(); + + // dd(db_connect()->getLastQuery() ,$pt_bp_amt); + $data['base_cd_amount'] = $pt_bp_amt['amount'] ?? null; + $ptFileQuery = $this->PTFileModel ->join('policy_transaction', 'pt_files.pt_id = policy_transaction.id') @@ -999,7 +1016,7 @@ class PolicyTransactionController extends BaseController ->findAll(); // print_r( $data['pt_co_share_details']); die; - + // return $data; if ($data) { return $this->respond(['status' => true, 'data' => $data], 200); } else { @@ -1059,8 +1076,8 @@ class PolicyTransactionController extends BaseController // !dd($this->getEndorsementDataForEdit(17)); $data['page_name'] = 'Endorsement'; - $data['issuer'] = [1 => 'JIBS', 2 => 'Nhance']; + $data['issuer_branch'] = $this->nhanceBranchModel->where('is_active', 1)->findAll(); $data['client_type'] = [1 => 'Group', 2 => 'Individual']; $data['policy_status'] = [ @@ -1170,11 +1187,14 @@ class PolicyTransactionController extends BaseController $data['policy_with_corr'] = 1; } - if (!isset($data['is_cd_reduce_from_bds'])) { - $data['is_cd_reduce_from_bds'] = 0; - } elseif ($data['is_cd_reduce_from_bds']) { - $data['is_cd_reduce_from_bds'] = 1; - } + // if (!isset($data['is_cd_reduce_from_bds'])) { + // $data['is_cd_reduce_from_bds'] = 0; + // } elseif ($data['is_cd_reduce_from_bds']) { + // $data['is_cd_reduce_from_bds'] = 1; + // } + + $data['is_cd_reduce_from_bds'] = ($data['policy_type_id'] > 7 && $data['client_type'] == 1) ? 1 : 0; + if (empty($data['data_received_date'])) { $data['data_received_date'] = null; @@ -1242,7 +1262,8 @@ class PolicyTransactionController extends BaseController if (!$data['id']) { $data += [ - 'issuer' => $issue_type['issuer'] ?? null, + 'issuer' => 2, + 'issuer_branch' => $data['issuer_branch'] ?? 1, 'client_type' => $data['client_type'] ?? $issue_type['client_type'] ?? null, 'policy_type_id' => $issue_type['policy_type_id'] ?? null, 'issue_type' => $issue_type['issue_type'] ?? null, diff --git a/app/Controllers/TestingController.php b/app/Controllers/TestingController.php index d866cb7f..cb432d24 100644 --- a/app/Controllers/TestingController.php +++ b/app/Controllers/TestingController.php @@ -4,6 +4,7 @@ namespace App\Controllers; use App\Controllers\BaseController; use App\Models\EmployeePolicyModel; +use App\Models\InsurerBranchModel; use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\API\ResponseTrait; use Dompdf\Dompdf; @@ -236,4 +237,80 @@ class TestingController extends BaseController ->findAll(); } + + public function ptedfitdata($id){ + $policy_transaction = new PolicyTransactionController(); + $data = $policy_transaction->getInceptionDataForEdit($id); + // dd($data); + $insurerBranchModel = new InsurerBranchModel(); + $insurer_branch = $insurerBranchModel->getInsurerBranchesWithInsurerNames(); + + $dataArray = $data['pt_co_share_details']; // Example + $cd_ac_pk = 'CD12345'; + $role_id = 1; + $team_id = ['6']; + $insurer_branch = $insurer_branch; + + return view('pt_calc_table', [ + 'dataArray' => $dataArray, + 'cd_ac_pk' => $cd_ac_pk, + 'role_id' => $role_id, + 'team_id' => $team_id, + 'insurer_branch' => $insurer_branch + ]); + } + + function generateInsurerTable($dataArray, $cd_ac_pk, $role_id, $team_id, $insurer_branch) + { + $html = '
| '; + + // Leader toggle + $checked = ($data['co_share_type'] == 1) ? 'checked' : ''; + $html .= ' | '; + + // CD Account + $html .= ' | '; + + // CD Amount + $html .= ' | '; + + // Example of follower policy no + $html .= ' | '; + + // Add other fields (bp_amt, tp_amt, gst, etc.) + $html .= ' | '; + $html .= ' | '; + $html .= ' | '; + $html .= ' | '; + + $html .= ' |