From 0eb65b9a1b61696efc05b269771497996243424f Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Tue, 9 Sep 2025 15:50:12 +0530 Subject: [PATCH] FIX_KYC_DOCS : RV --- app/Controllers/ClientController.php | 47 ++++- app/Controllers/EmployeeRestController.php | 2 +- .../PolicyTransactionController.php | 19 +- app/Views/client_kyc.php | 169 +++--------------- app/Views/client_kyc_other_table.php | 14 ++ app/Views/client_kyc_primary_table.php | 28 +++ .../policy_transaction_inception_form.php | 22 ++- 7 files changed, 148 insertions(+), 153 deletions(-) create mode 100644 app/Views/client_kyc_other_table.php create mode 100644 app/Views/client_kyc_primary_table.php diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 3ba36f45..2e9e11c9 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -772,6 +772,8 @@ class ClientController extends AdminController $editData['client'] = $this->clientModel->where(['id' => $id])->first(); $editData['client_kyc'] = $this->clientKYCDocsModel->where('client_id', $id)->findAll(); + $editData['client_kyc_primary_table'] = $this->generateKycPrimaryTable($id); + $editData['client_kyc_other_table'] = $this->generateKycOthersTable($id); $editData['client_branch'] = $this->clientBranchModel->where(['client_id' => $id, 'is_active' => 1])->findAll(); $editData['client_relation'] = $this->clientRMModel->where(['client_id' => $id, 'is_active' => 1])->findAll(); $editData['client_branch']['role'] = get_role_id(); @@ -870,6 +872,8 @@ class ClientController extends AdminController { $this->myLogger->logme('error', 'create Client kyc function called'); $data = $this->request->getPost(); + $form_type = $this->request->getPost('form_type') ?? null; + // print_r($data); die; unset($data['file_name']); $uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents'; @@ -885,8 +889,12 @@ class ClientController extends AdminController $data['created_by'] = get_session_userid(); $insert = $this->clientKYCDocsModel->insert($data); if ($insert) { - - $kycDocs = $this->clientKYCDocsModel->where('client_id', $this->request->getPost('client_id'))->findAll(); + // $kycDocs = $this->clientKYCDocsModel->where('client_id', $this->request->getPost('client_id'))->findAll(); + if($form_type == "others"){ + $kycDocs = $this->generateKycOthersTable($this->request->getPost('client_id')); + }else{ + $kycDocs = $this->generateKycPrimaryTable($this->request->getPost('client_id')); + } return $this->respond(['status' => true, 'code' => 200, 'data' => $kycDocs, 'file_name' => $File], 200); } else { return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200); @@ -899,6 +907,8 @@ class ClientController extends AdminController $this->myLogger->logme('error', 'edit client kyc function called'); $uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents'; $File = file_Upload($this->request->getFile('file_name'), $uploadFilePath); + $form_type = $this->request->getPost('form_type') ?? null; + if (!empty($File)) { $data['file_name'] = $File; } @@ -907,8 +917,14 @@ class ClientController extends AdminController $data['kyc_doc_type_id'] = $this->request->getPost('kyc_doc_id'); $data['updated_by'] = get_session_userid(); $insert = $this->clientKYCDocsModel->insert($data); + if ($insert) { - $kycDocs = $this->clientKYCDocsModel->getKycDocsName($id); + // $kycDocs = $this->clientKYCDocsModel->getKycDocsName($id); + if($form_type == "others"){ + $kycDocs = $this->generateKycOthersTable($this->request->getPost('client_id')); + }else{ + $kycDocs = $this->generateKycPrimaryTable($this->request->getPost('client_id')); + } return $this->respond(['status' => true, 'code' => 200, 'data' => $kycDocs], 200); } else { return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200); @@ -2163,11 +2179,32 @@ class ClientController extends AdminController $builder->groupBy(['kd.id', 'ck.file_name']); $query = $builder->get(); - $result['data'] = $query->getResult(); + $result['data'] = $query->getResultArray(); + $result['client_id'] = $client_id; $table = view('client_kyc_primary_table', $result); - print_r($table); + return $table; + // print_r($table); die; + + } + + public function generateKycOthersTable($client_id){ + + $result['data'] = $this->clientKYCDocsModel + ->where('is_active', 1) + ->where('client_id', $client_id) + ->groupStart() + ->where('kyc_doc_type_id', null) + ->orWhere('kyc_doc_type_id', 0) + ->groupEnd() + ->findAll(); + + $result['client_id'] = $client_id; + $table = view('client_kyc_other_table', $result); + + return $table; + // print_r($table); die; } diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 72ea2e99..7854fb21 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -3423,7 +3423,7 @@ class EmployeeRestController extends AdminController $client_policy_id = $received_data['client_policy_id']; $insured_emp_id = $received_data['insured_emp_id']; - $file_data = ""; + $file_data = []; if(isset($get_file_data) && !empty($get_file_data)){ $file_path = WRITEPATH . 'uploads/claim_files/'; $file_data = multi_file_Upload($get_file_data, $file_path); diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index cada5a8f..2b9afb78 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -383,7 +383,12 @@ class PolicyTransactionController extends BaseController } $client_data = $this->clientModel->where('id', $data['client_id'])->first(); - $data['client_kyc'] = $this->clientKYCDocsModel->where('client_id', $data['client_id'])->findAll(); + $data['client_kyc'] = $this->clientKYCDocsModel->where('client_id', $data['client_id'])->findAll(); + + $clientController = new ClientController(); + $data['client_kyc_primary_table'] = $clientController->generateKycPrimaryTable($data['client_id']); + $data['client_kyc_other_table'] = $clientController->generateKycOthersTable($data['client_id']); + $data['entity_type_id'] = $client_data['entity_type_id']; return $this->respondSuccess($insert, "Policy transaction created successfully", $data); @@ -433,6 +438,11 @@ class PolicyTransactionController extends BaseController $client_data = $this->clientModel->where('id', $data['client_id'])->first(); $data['client_kyc'] = $this->clientKYCDocsModel->where('client_id', $data['client_id'])->findAll(); + + $clientController = new ClientController(); + $data['client_kyc_primary_table'] = $clientController->generateKycPrimaryTable($data['client_id']); + $data['client_kyc_other_table'] = $clientController->generateKycOthersTable($data['client_id']); + $data['entity_type_id'] = $client_data['entity_type_id']; return $this->respondSuccess($id, "Policy transaction updated successfully", $data); @@ -977,7 +987,12 @@ class PolicyTransactionController extends BaseController ->join('employee_polices', 'employees.id = employee_polices.employee_id', 'left') ->where('employees.client_id', $data['client_id']) ->where('employees.is_active', 1)->findAll(); - $data['client_kyc'] = $this->clientKYCDocsModel->where('client_id', $data['client_id'])->findAll(); + // $data['client_kyc'] = $this->clientKYCDocsModel->where('client_id', $data['client_id'])->findAll(); + + $clientController = new ClientController(); + $data['client_kyc_primary_table'] = $clientController->generateKycPrimaryTable($data['client_id']); + $data['client_kyc_other_table'] = $clientController->generateKycOthersTable($data['client_id']); + $data['vehicle_docs'] = $this->clientKYCDocsModel ->where('client_id', $data['client_id']) ->where('vehicle_id', $data['vehicle_id']) diff --git a/app/Views/client_kyc.php b/app/Views/client_kyc.php index 0c3e8b40..78a5a094 100755 --- a/app/Views/client_kyc.php +++ b/app/Views/client_kyc.php @@ -50,7 +50,7 @@ - + @@ -71,7 +71,7 @@ - +
@@ -113,10 +113,10 @@ +
-
@@ -131,10 +131,6 @@ $(document).ready(function(){ kycPrimaryKey = $('#kyc_PrimaryKey').val(); - - $('#others').hide() - $('#other_docs_table').hide(); - $(document).on('click', '.submit', function(e) { e.preventDefault(); @@ -145,7 +141,6 @@ var fileInputs = form.find('input[type="file"]'); var allowedExtensions = ['pdf', 'png', 'jpeg', 'jpg']; - if (kycPrimaryKey === '') { toastr.error('Client is required', 'Error'); form.trigger('reset') @@ -175,7 +170,6 @@ return; } - $('.loader').fadeIn(); $('.loader-mask').fadeIn(); @@ -186,94 +180,32 @@ processData: false, contentType: false, success: function (res) { - setTimeout(function() { - $('.loader').fadeOut(); - $('.loader-mask').delay(350).fadeOut('slow'); - }, 1000); - // res = JSON.parse(res) - console.log(res); - if(res){ - setTimeout(function() { - $('.loader').fadeOut(); - $('.loader-mask').delay(350).fadeOut('slow'); - toastr.success('File Uploaded successfully', 'Success'); - }, 500); + console.log('KYC PRIMARY SUBMIT', res); + + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + + if(res.status == true){ + $('#tbody').empty(); + $('#tbody').append(res.data); + toastr.success('File uploaded successfully', 'Success'); + }else{ + toastr.warning('File uploaded failed', 'WARNING'); } - - form.trigger('reset') - $.each(res.data, function (index, item) { - - $('#name_'+item.kyc_doc_type_id).show(); - $('#name_'+item.kyc_doc_type_id).html(item.file_name); - $('#form_'+item.kyc_doc_type_id).hide(); - - // var url = "" + - // "?client_id=" + item.client_id + - // "&file_type=kyc" + - // "&file_name=" + item.file_name + - // "&client_policy_id=client_policy_id"; - - var url = '' + item.file_name; - - // console.log('step 1') - - if(item.file_name != null && item.file_name != ""){ - // console.log('step 2') - - $('#download_'+item.kyc_doc_type_id).show(); - $('#download_' + item.kyc_doc_type_id).attr('href', url); - $('#delete_'+item.kyc_doc_type_id).show(); - - } - else{ - // console.log('step 3') - - $('#download_'+item.kyc_doc_type_id).hide(); - $('#download_' + item.kyc_doc_type_id).attr('href', '#'); - $('#delete_'+item.kyc_doc_type_id).hide(); - - } - // console.log('step 4') - - }); - }, error: function (xhr, status, error) { console.error(xhr.responseText); console.error(status, error); - - setTimeout(function() { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); toastr.warning('Something Wrong!', 'warning'); - }, 1000); - } }); }); - if(kycPrimaryKey !== ''){ - - $('.loader').fadeIn(); - $('.loader-mask').fadeIn(); - - var entity_type_id = '' - var client_id = '' - getKYCEntityDocument(entity_type_id, client_id); - - var data = ; - appendKycTableListData(data) - - } - }) - $('#btn_other_docs').click(function(){ - $('#others').toggle(); - $('#other_docs_table').toggle(); - }); - /*** for Others documents form submit ***/ $("#kyc_form").submit(function(event) { event.preventDefault(); @@ -289,6 +221,7 @@ form_action = ''; } var formData = new FormData($('#kyc_form')[0]); + formData.append("form_type", "others"); $('.loader').fadeIn(); $('.loader-mask').fadeIn(); @@ -302,74 +235,27 @@ contentType: false, success: function(res) { - setTimeout(function() { + console.log('KYC OTHERS SUBMIT', res); + $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); - }, 1000); - // console.log(res); - $('#kyc_form').trigger('reset'); - if(res){ - setTimeout(function() { - $('.loader').fadeOut(); - $('.loader-mask').delay(350).fadeOut('slow'); - var message = (kycPrimaryKey === '') ? 'KYC Other Docs Uploaded successfully' : 'KYC Other Docs Uploaded successfully'; - toastr.success(message, 'Success'); - }, 500); + + if(res.status == true){ + $('#other_docs').empty(); + $('#other_docs').append(res.data); + toastr.success('File uploaded successfully', 'Success'); + }else{ + toastr.warning('File uploaded failed', 'WARNING'); } - var other_docs_count = 0; - - $('#other_docs tr').remove(); - $.each(res.data, function(index, item) { - - if(item.other_docs_name != ""){ - - other_docs_count++; - } - - // var url = "" + - // "?client_id=" + item.client_id + - // "&file_type=kyc" + - // "&file_name=" + item.file_name + - // "&client_policy_id=client_policy_id"; - - - var url = '' + item.file_name; - - // console.log("Current item:", item); - if (item.kyc_doc_type_id == '0') { - // console.log("Appending item:", item); - var rowHtml = ` - - ${item.other_docs_name} - ${item.file_name} - - - - - `; - } - $('#other_docs').append(rowHtml); - - // - - - if(other_docs_count > 0){ - $('#others').show() - $('#other_docs_table').show(); - } - }); + $('#kyc_form').trigger('reset'); }, error: function(xhr, status, error) { console.error(xhr.responseText); console.error(status, error); - - setTimeout(function() { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); toastr.warning('Something Wrong!', 'warning'); - }, 1000); - } }); @@ -436,6 +322,8 @@ contentType: false, success: function (res) { + console.log("KYC DOCUMENTS TABLE RSPONSE", res); + setTimeout(function() { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); @@ -519,9 +407,8 @@ `; - } -// + // }); diff --git a/app/Views/client_kyc_other_table.php b/app/Views/client_kyc_other_table.php new file mode 100644 index 00000000..04bcce83 --- /dev/null +++ b/app/Views/client_kyc_other_table.php @@ -0,0 +1,14 @@ + + $item): ?> + + + + + + + + + + No records found + + diff --git a/app/Views/client_kyc_primary_table.php b/app/Views/client_kyc_primary_table.php new file mode 100644 index 00000000..4373a373 --- /dev/null +++ b/app/Views/client_kyc_primary_table.php @@ -0,0 +1,28 @@ + + $item): ?> + + + + + + +
+ + + + + +
+ + + + + + + + + + + No records found + + diff --git a/app/Views/policy_transaction_inception_form.php b/app/Views/policy_transaction_inception_form.php index 285cb00b..c7491956 100644 --- a/app/Views/policy_transaction_inception_form.php +++ b/app/Views/policy_transaction_inception_form.php @@ -1741,8 +1741,16 @@ function getPolicyTransactionDataForEdit(input) { $('#cd_ac_pk_for_leader').val(res.data.cd_ac_pk); // $('#entity_type_id').val(res.data.entity_type_id); - getKYCEntityDocument(res.data.entity_type_id, res.data.client_id); - appendKycTableListData(res.data.client_kyc); + // getKYCEntityDocument(res.data.entity_type_id, res.data.client_id); + // appendKycTableListData(res.data.client_kyc); + + $('#tbody').empty(); + $('#tbody').append(res.data.client_kyc_primary_table); + + $('#other_docs').empty(); + $('#other_docs').append(res.data.client_kyc_other_table); + + // Setting values to correct fields @@ -3351,8 +3359,14 @@ $("#inception_form_id").submit(function(event) { $('#client_id_for_vehicle_file_upload').val(res.data.client_id); $('#vehicle_id_for_file_upload').val(res.data.vehicle_id); - getKYCEntityDocument(res.data.entity_type_id, res.data.client_id); - appendKycTableListData(res.data.client_kyc); + // getKYCEntityDocument(res.data.entity_type_id, res.data.client_id); + // appendKycTableListData(res.data.client_kyc); + + $('#tbody').empty(); + $('#tbody').append(res.data.client_kyc_primary_table); + + $('#other_docs').empty(); + $('#other_docs').append(res.data.client_kyc_other_table); //setTimeout(function(){ //}, 1000)