From 9cac014d444298f27271970240b462acd8f69420 Mon Sep 17 00:00:00 2001 From: venba-Inspriron-3558 Date: Fri, 5 Dec 2025 09:48:53 +0530 Subject: [PATCH 1/9] FIX_policy KYC Docs redesigned --- app/Config/Routes.php | 5 + app/Controllers/ClientController.php | 177 ++++++++++ .../PolicyTransactionController.php | 5 + app/Views/client_kyc_2.php | 322 ++++++++++++++++++ app/Views/client_kyc_single_table.php | 70 ++++ app/Views/layout/header.php | 12 +- .../policy_transaction_inception_form_2.php | 170 +++++++-- .../policy_transaction_inception_list_2.php | 18 +- app/Views/pt_form_file_upload_tab_2.php | 12 +- 9 files changed, 756 insertions(+), 35 deletions(-) create mode 100755 app/Views/client_kyc_2.php create mode 100644 app/Views/client_kyc_single_table.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 86e47622..e17d17cf 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -162,6 +162,11 @@ $routes->group("/client", ["filter" => "authMVC"], function ($routes) { $routes->post("edit", "ClientController::editClientKYCInfo"); $routes->get("list/(:any)", "ClientController::getKycDocsById/$1"); $routes->get("delete/(:any)", "ClientController::deleteClientKycDocs/$1"); + + $routes->post("create_2", "ClientController::createClientKYCInfo_2"); + $routes->post("edit_2", "ClientController::editClientKYCInfo_2"); + $routes->post("delete_2", "ClientController::deleteClientKycDocs_2/$1"); + }); $routes->group("premimum", ["filter" => "authMVC"], function ($routes) { diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index e0a556db..b67ae501 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1005,6 +1005,153 @@ class ClientController extends AdminController + public function createClientKYCInfo_2() + { + $this->myLogger->logme('error', 'create Client kyc function called'); + $data = $this->request->getPost(); + + $uploadedFile = $this->request->getFile('file_name'); + + if ($uploadedFile && $uploadedFile->isValid() && !$uploadedFile->hasMoved()) { + $this->myLogger->logme('info', 'File is valid and ready to move.'); + } else { + $this->myLogger->logme('error', 'File failed validation or was not uploaded.'); + } + + $uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents'; + + $File = file_Upload($uploadedFile, $uploadFilePath); + $this->myLogger->logme('info', 'Result of file_Upload: ' . $File); + unset($data['file_name']); + + if (!empty($File)) { $data['file_name'] = $File; } + + $data['created_by'] = get_session_userid(); + $insert = $this->clientKYCDocsModel->insert($data); + + if ($insert) { + $html = $this->generateKycSingleTable($data['client_id']); + $dropdown = $this->fetch_dropdown($data['client_id']); + return $this->respond(['status' => true, 'code' => 200, 'file_name' => $File, 'html' => $html,'dropdown'=>$dropdown], 200); + } else { + $this->myLogger->logme('error', 'Database insert failed.'); + return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to add document'], 200); + } + } + + public function editClientKYCInfo_2() + { + + $kyc_id = $this->request->getPost('id'); + $client_id = $this->request->getPost('client_id'); + $old_file_name = $this->request->getPost('old_file_name'); + $uploadedFile = $this->request->getFile('file_name'); + $new_file_name = null; + $uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents'; + + + if ($uploadedFile && $uploadedFile->isValid() && !$uploadedFile->hasMoved()) { + + + $new_file_name = file_Upload($uploadedFile, $uploadFilePath); + + if (!empty($new_file_name)) { + + $updateData['file_name'] = $new_file_name; + + // Delete the old file from the storage if it exists + // if (!empty($old_file_name)) { + // $old_file_path = $uploadFilePath . '/' . $old_file_name; + // if (file_exists($old_file_path)) { + // unlink($old_file_path); + // // Optionally delete from G-Drive here if applicable + // } + // } + } else { + // New file upload failed + return $this->respond(['status' => false, 'code' => 500, 'message' => 'New file upload failed on server.'], 200); + } + } + + // 2. Perform the database update + if (!empty($updateData)) { + + $updateData['updated_by'] = get_session_userid(); + $update = $this->clientKYCDocsModel->update($kyc_id, $updateData); + $html = $this->generateKycSingleTable($client_id); + $dropdown = $this->fetch_dropdown($client_id); + + if ($update) { + return $this->respond(['status' => true, 'code' => 200, 'message' => 'Document updated successfully.','html' => $html,'dropdown' => $dropdown], 200); + } + } else { + + return $this->respond(['status' => true, 'code' => 200, 'message' => 'No changes detected. Document remains the same.'], 200); + } + + + return $this->respond(['status' => false, 'code' => 404, 'message' => 'Database update failed or record not found.'], 200); + } + + + public function deleteClientKycDocs_2() + { + + $kyc_id = $this->request->getPost('id'); + $client_id = $this->request->getPost('client_id'); + + if (empty($kyc_id)) { + return $this->respond(['status' => false, 'code' => 400, 'message' => 'Missing document ID.'], 200); + } + $updateData['updated_by'] = get_session_userid(); + $updateData['is_active'] = $this->request->getPost('is_active'); + + $delete = $this->clientKYCDocsModel->update($kyc_id, $updateData); + + if ($delete) { + $html = $this->generateKycSingleTable($client_id); + $dropdown = $this->fetch_dropdown($client_id); + return $this->respond(['status' => true, 'code' => 200, 'id' => $kyc_id, 'message' => 'Document successfully deactivated.','html' => $html,'dropdown' => $dropdown], 200); + } else { + return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to update record (ID not found or DB error).'], 200); + } + } + + public function fetch_dropdown($client_id){ + + $db = db_connect(); + + + $submitted_ids_subquery = $db->table('client_kyc_documents ckd') + ->select('ckd.kyc_doc_type_id') + ->where('ckd.client_id', $client_id) + ->where('ckd.is_active', 1) + ->getCompiledSelect(); + + + $result = $db->table('kyc_docs kd') + ->select('kd.*') + ->join('clients c', 'kd.kyc_type_id = c.entity_type_id') + ->where('c.id', $client_id) + ->where("kd.kyc_type_id NOT IN ({$submitted_ids_subquery})") + ->groupBy('kd.id') + ->get() + ->getResultArray(); + + + $dropdown = ''; + $dropdown .= ''; + + foreach ($result as $row) { + $dropdown .= ''; + } + + return $dropdown; + } + + public function createClientRelation() { @@ -2361,6 +2508,36 @@ class ClientController extends AdminController } + + public function generateKycSingleTable($client_id) + { + + + $result['ckdlist'] = db_connect()->table('client_kyc_documents ckd') + ->select("ckd.id,ckd.client_id,ckd.kyc_doc_type_id,ckd.file_name,kd.file_name AS kd_docs_name,ckd.other_docs_name,ckd.vehicle_id,ckd.is_active, + CASE + WHEN ckd.kyc_doc_type_id IS NULL + OR ckd.kyc_doc_type_id = 0 + OR ckd.kyc_doc_type_id = '' + THEN ckd.other_docs_name + ELSE kd.file_name + END AS ui_docs_name") + ->join('kyc_docs kd','ckd.kyc_doc_type_id = kd.kyc_type_id','left') + ->where('ckd.client_id',$client_id) + ->where('ckd.is_active',1) + ->groupBy('ckd.id') + ->get() + ->getResultArray(); + + + $result['client_id'] = $client_id; + $table = view('client_kyc_single_table', $result); + + return $table; + // print_r($table); die; + + } + public function getPolicesByInsurerId($id = null) { $this->myLogger->logme('error', 'getPolicesByInsurerId function called'); diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index e60d0be1..5b348a0f 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -994,6 +994,7 @@ $clientController = new ClientController(); $data['client_kyc_primary_table'] = $clientController->generateKycPrimaryTable($data['client_id']); $data['client_kyc_other_table'] = $clientController->generateKycOthersTable($data['client_id']); + // $data['client_kyc_single_table'] = $clientController->generateKycSingleTable($data['client_id']); $data['entity_type_id'] = $client_data['entity_type_id']; return $this->respondSuccess($insert, "Policy transaction created successfully", $data); @@ -1056,6 +1057,7 @@ $clientController = new ClientController(); $data['client_kyc_primary_table'] = $clientController->generateKycPrimaryTable($data['client_id']); $data['client_kyc_other_table'] = $clientController->generateKycOthersTable($data['client_id']); + // $data['client_kyc_single_table'] = $clientController->generateKycSingleTable($data['client_id']); $data['entity_type_id'] = $client_data['entity_type_id']; @@ -1624,6 +1626,8 @@ $clientController = new ClientController(); $data['client_kyc_primary_table'] = $clientController->generateKycPrimaryTable($data['client_id']); $data['client_kyc_other_table'] = $clientController->generateKycOthersTable($data['client_id']); + $data['client_kyc_single_table'] = $clientController->generateKycSingleTable($data['client_id']); + $data['client_kyc_dd_data'] = $clientController->fetch_dropdown($data['client_id']); $data['vehicle_docs'] = $this->clientKYCDocsModel ->where('client_id', $data['client_id']) @@ -1894,6 +1898,7 @@ $clientController = new ClientController(); $data['client_kyc_primary_table'] = $clientController->generateKycPrimaryTable($data['client_id']); $data['client_kyc_other_table'] = $clientController->generateKycOthersTable($data['client_id']); + $data['client_kyc_single_table'] = $clientController->generateKycSingleTable($data['client_id']); $data['vehicle_docs'] = $this->clientKYCDocsModel ->where('client_id', $data['client_id']) diff --git a/app/Views/client_kyc_2.php b/app/Views/client_kyc_2.php new file mode 100755 index 00000000..8a2ce5ed --- /dev/null +++ b/app/Views/client_kyc_2.php @@ -0,0 +1,322 @@ + + +
+ +
+
+
+
+

Documents

+
+ + + + +
+ +
+
+ + +
+ + + +
+ + +
+ +
+ +
+ + +
+ +
+
+
+
+
+
+
+
+
+
+ + + + + + + + + + + + +
S. NoDocument NameFile NameAction
+
+ +
+
+
+ +
+ + + + \ No newline at end of file diff --git a/app/Views/client_kyc_single_table.php b/app/Views/client_kyc_single_table.php new file mode 100644 index 00000000..4982bcdf --- /dev/null +++ b/app/Views/client_kyc_single_table.php @@ -0,0 +1,70 @@ + + + No data found + + + $value) : + $sno = $index + 1; + $fileName = !empty($value['file_name']) ? $value['file_name'] : '-'; + ?> + + + + + + + + + + + + + + + + +
+ + + + +
+
+ + +
+ +
+ +
+
+ +
+
+
+ + + + + diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 43ba28ee..68950c44 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -1890,9 +1890,9 @@
  • Policy
  • -
  • +
  • Endorsement
  • @@ -2040,6 +2040,14 @@ + +
  • + + + Policy 2 + +
  • + diff --git a/app/Views/policy_transaction_inception_form_2.php b/app/Views/policy_transaction_inception_form_2.php index d73ab07d..79ac1444 100644 --- a/app/Views/policy_transaction_inception_form_2.php +++ b/app/Views/policy_transaction_inception_form_2.php @@ -873,8 +873,8 @@ -
    - +
    +
    @@ -1788,7 +1788,7 @@ if (res.status == true) { - hide_list_show_add(); + hide_list_show_add_2(); var page_title = 'Edit Policy' + (res.data.client_short_name || res.data.policy_type || res.data.policy_no ? ' - ' + [res.data.client_short_name, res.data.policy_type, res.data.policy_no] @@ -1811,12 +1811,140 @@ // getKYCEntityDocument(res.data.entity_type_id, res.data.client_id); // appendKycTableListData(res.data.client_kyc); + + // please don't forgot this ==> look at here please don't don't forgot + $('#docs_type_id').empty(); // ✅ clear old options + $('#docs_type_id').append(res.data.client_kyc_dd_data); $('#tbody').empty(); - $('#tbody').append(res.data.client_kyc_primary_table); + $('#tbody').append(res.data.client_kyc_single_table); - $('#other_docs').empty(); - $('#other_docs').append(res.data.client_kyc_other_table); + + // let tbody = $('#tbody'); + // tbody.empty(); // ✅ Always clear first + // let ckdlist = res.data.client_kyc_document_list; + + // if (!ckdlist || ckdlist.length === 0) { + + // // ✅ Show single merged row when no data + // let emptyRow = ` + // + // + // No data found + // + // + // `; + + // tbody.append(emptyRow); + // // return; // ✅ Stop further execution + // } + // else{ + // $.each(ckdlist, function (index, value) { + + // let sno = index + 1; + + // // ✅ If kyc_doc_type_id is null → use other_docs_name + // let docName = (value.kyc_doc_type_id === null || value.kyc_doc_type_id === '') + // ? value.other_docs_name + // : value.kyc_doc_type_id; + + // let fileName = value.file_name ? value.file_name : '-'; + + // let downloadBtn = ` + // + // + // `; + + // // Inside your $.each(list, function (index, value) { ... }) loop + // let editBtn = ` + // `; + + // // The edit UI block to be toggled + // let editUI = ` + // + // + //
    + // + // + // + + //
    + + //
    + // + // + //
    + + //
    + // + //
    + + //
    + // + //
    + + //
    + + //
    + // + // + // `; + + + + // let deleteBtn = ` + // + // `; + + // let row = ` + // ${sno} + // ${value.ui_docs_name} + // ${fileName} + // + // ${downloadBtn} + // ${editBtn} + // ${deleteBtn} + // + // + // ${editUI} `; + + // tbody.append(row); + // }); + // } + // // docs_type_id + // // res.data.client_kyc_dd_data // Setting values to correct fields $('#policy_tranction_primarykey').val(res.data.id); @@ -1888,6 +2016,7 @@ if (res.data.pt_co_share_details) { + if (!res.data.pt_co_share_details[0].follower_policy_no) {res.data.pt_co_share_details[0].follower_policy_no = res.data.policy_no;} setTimeout(function() { // populateTable(res.data.pt_co_share_details, res.data.cd_ac_pk); populateCards(res.data.pt_co_share_details, res.data.cd_ac_pk); @@ -1985,7 +2114,7 @@ $('#cop_yes').prop('checked', true); $('.add-insurer-button').removeClass('d-none'); $('.payby').removeClass('d-none'); - $('.card_group_2').removeClass('d-none'); + $('.card_group_2').show(); $('.card_group_3').removeClass('d-none'); $('.card_group_7').removeClass('d-none'); $('.card_group_35').removeClass('d-none'); @@ -1993,7 +2122,7 @@ $('#cop_yes').prop('checked', false); $('.add-insurer-button').addClass('d-none'); $('.payby').addClass('d-none'); - $('.card_group_2').addClass('d-none'); + $('.card_group_2').hide(); $('.card_group_3').addClass('d-none'); $('.card_group_7').addClass('d-none'); $('.card_group_35').addClass('d-none'); @@ -3202,7 +3331,6 @@ } }); }else{ - console.error('Client type Not found') console.log('client_type', client_type); } }else{ @@ -3547,7 +3675,7 @@ if (res.data.pt_co_share_details && res.data.pt_co_share_details.length > 0) { - $('#tab_content').empty() + // $('#tab_content').empty() count = 0 $.each(res.data.pt_co_share_details, function(index, item) { // appendNewTab(item); @@ -3743,7 +3871,7 @@ $('.card_group_2').show() $('.card_group_3').show() $('.card_group_7').show() - $('.card_group_35').show() + $('.card_group_35').removeClass('d-none'); var selectedOption = $('#policy_type_id').find('option:selected'); var bap = selectedOption.data('bap'); @@ -3804,7 +3932,7 @@ $('.card_group_2').hide() $('.card_group_3').hide() $('.card_group_7').hide() - $('.card_group_35').hide() + $('.card_group_35').addClass('d-none'); $('.hidecoter').hide() $('.hidecotp').hide() @@ -4427,21 +4555,21 @@
    - BP + BP   %
    - TP + TP   %
    - +
    @@ -575,7 +575,7 @@ $(document).ready(function() { text: ' Add ', className: 'btn app-btn-primary mr-2', action: function (e, dt, node, config) { - hide_list_show_add(); + hide_list_show_add_2(); addInsurerColumn() ; } }, @@ -688,8 +688,9 @@ $(document).ready(function(){ //-------------------------------------------------------------------------------------------------------- -function hide_list_show_add() -{ +function hide_list_show_add_2() +{ + $('#pt_onboarding2').show(); $('#page_title').text('Add Policy') $('#inception_form_id')[0].reset(); $('#client_id').val('').change().prop('disabled', false); @@ -711,7 +712,7 @@ function hide_list_show_add() $('.current_date').hide() $('#invoice_no').attr('required', false) - $('#pt_onboarding').show() + $('#inception_list').hide() $('#inception_filter').hide() $('#policyholdernamediv').hide(); @@ -720,11 +721,12 @@ function hide_list_show_add() function show_list_hide_add() { - $('#pt_onboarding').hide() + $('#pt_onboarding2').hide(); $('#inception_list').show() $('#inception_filter').show(); - $('#nav_pills').empty() - $('#tab_content').empty() + $('#nav_pills').empty(); + // $('#tab_content').empty(); + count = 0 } diff --git a/app/Views/pt_form_file_upload_tab_2.php b/app/Views/pt_form_file_upload_tab_2.php index 3190bf8a..65727ea4 100644 --- a/app/Views/pt_form_file_upload_tab_2.php +++ b/app/Views/pt_form_file_upload_tab_2.php @@ -1,4 +1,4 @@ -