CHANGE_BDS_CHANGE_1
This commit is contained in:
parent
3f6396ad4d
commit
887f3cfb6f
@ -1233,16 +1233,106 @@ class ClientController extends AdminController
|
||||
public function createClientKYCInfo()
|
||||
{
|
||||
$this->myLogger->logme('error', 'Create Client KYC function called');
|
||||
|
||||
$rules = [
|
||||
'other_docs_name' => [
|
||||
'label' => 'Documents Name',
|
||||
'rules' => 'permit_empty|regex_match[/^[a-zA-Z0-9_\- ]+$/]',
|
||||
'errors' => [
|
||||
'regex_match' => 'Document Name can only contain letters, numbers, hyphens, and underscores'
|
||||
]
|
||||
],
|
||||
$data = $this->request->getPost();
|
||||
$sanitized_data = sanitizeInputArrayAdvanced($data);
|
||||
$form_type = $sanitized_data['form_type'] ?? null;
|
||||
$client_id = $sanitized_data['client_id'] ?? null;
|
||||
$uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents';
|
||||
$allowedExtensions = ['pdf', 'jpg', 'jpeg', 'png'];
|
||||
$maxFileSize = 5 * 1024 * 1024; // 5MB
|
||||
|
||||
if (empty($client_id)) {
|
||||
return $this->response->setStatusCode(400)->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'Input validation failed',
|
||||
'code' => 400,
|
||||
'errors' => ['client_id' => 'Client is required']
|
||||
]);
|
||||
}
|
||||
|
||||
// Multi-row handler for Additional Documents form
|
||||
if ($form_type === 'others') {
|
||||
$docNames = $this->request->getPost('other_docs_name');
|
||||
if (!is_array($docNames)) {
|
||||
$docNames = [$docNames];
|
||||
}
|
||||
|
||||
$uploadedFiles = $this->request->getFileMultiple('file_name');
|
||||
if (!is_array($uploadedFiles)) {
|
||||
$uploadedFiles = [];
|
||||
}
|
||||
|
||||
$rows = max(count($docNames), count($uploadedFiles));
|
||||
$validationErrors = [];
|
||||
|
||||
if ($rows === 0) {
|
||||
return $this->response->setStatusCode(400)->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'Input validation failed',
|
||||
'code' => 400,
|
||||
'errors' => ['file_name' => 'At least one file is required']
|
||||
]);
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $rows; $i++) {
|
||||
$docName = trim((string)($docNames[$i] ?? ''));
|
||||
$fileObj = $uploadedFiles[$i] ?? null;
|
||||
|
||||
if ($docName === '') {
|
||||
$validationErrors["other_docs_name.$i"] = 'Documents Name is required';
|
||||
} elseif (!preg_match('/^[a-zA-Z0-9_\- ]+$/', $docName)) {
|
||||
$validationErrors["other_docs_name.$i"] = 'Document Name can only contain letters, numbers, hyphens, and underscores';
|
||||
}
|
||||
|
||||
if (!$fileObj || !$fileObj->isValid()) {
|
||||
$validationErrors["file_name.$i"] = 'KYC document file is required';
|
||||
} else {
|
||||
$extension = strtolower((string)$fileObj->getExtension());
|
||||
if (!in_array($extension, $allowedExtensions, true)) {
|
||||
$validationErrors["file_name.$i"] = 'Allowed file types: pdf, jpg, jpeg, png';
|
||||
}
|
||||
|
||||
if ((int)$fileObj->getSize() > $maxFileSize) {
|
||||
$validationErrors["file_name.$i"] = 'File size should not exceed 5MB';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($validationErrors)) {
|
||||
return $this->response->setStatusCode(400)->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'Input validation failed',
|
||||
'code' => 400,
|
||||
'errors' => $validationErrors
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($uploadedFiles as $index => $singleFile) {
|
||||
$fileName = file_Upload_for_lead($singleFile, $uploadFilePath, UPLOAD_EXT_KYC_DOCS);
|
||||
if (empty($fileName)) {
|
||||
return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to upload KYC document'], 200);
|
||||
}
|
||||
|
||||
$insertData = [
|
||||
'client_id' => $client_id,
|
||||
'kyc_doc_type_id' => $sanitized_data['kyc_doc_type_id'] ?? 0,
|
||||
'other_docs_name' => trim((string)($docNames[$index] ?? '')),
|
||||
'file_name' => $fileName,
|
||||
'created_by' => get_session_userid()
|
||||
];
|
||||
|
||||
$insertID = $this->clientKYCDocsModel->insert($insertData);
|
||||
if (!$insertID) {
|
||||
return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to upload KYC document'], 200);
|
||||
}
|
||||
}
|
||||
|
||||
$kycDocs = $this->generateKycOthersTable($client_id);
|
||||
return $this->respond(['status' => true, 'code' => 200, 'data' => $kycDocs], 200);
|
||||
}
|
||||
|
||||
// Backward compatible handler for primary KYC upload
|
||||
$rules = [
|
||||
'file_name' => [
|
||||
'rules' => 'uploaded[file_name]|max_size[file_name,5120]|ext_in[file_name,pdf,jpg,jpeg,png]',
|
||||
'errors' => [
|
||||
@ -1262,35 +1352,22 @@ class ClientController extends AdminController
|
||||
]);
|
||||
}
|
||||
|
||||
$data = $this->request->getPost();
|
||||
$sanitized_data = sanitizeInputArrayAdvanced($data);
|
||||
$form_type = $sanitized_data['form_type'] ?? null;
|
||||
$uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents';
|
||||
|
||||
unset($data['file_name']);
|
||||
|
||||
$file = $this->request->getFile('file_name');
|
||||
|
||||
$fileName = file_Upload($file, $uploadFilePath, UPLOAD_EXT_KYC_DOCS);
|
||||
$fileName = file_Upload_for_lead($file, $uploadFilePath, UPLOAD_EXT_KYC_DOCS);
|
||||
|
||||
if (!empty($fileName)) {
|
||||
$sanitized_data['file_name'] = $fileName;
|
||||
}
|
||||
|
||||
$sanitized_data['created_by'] = get_session_userid();
|
||||
|
||||
$insertID = $this->clientKYCDocsModel->insert($sanitized_data);
|
||||
|
||||
if ($insertID) {
|
||||
if ($form_type === 'others') {
|
||||
$kycDocs = $this->generateKycOthersTable($sanitized_data['client_id']);
|
||||
} else {
|
||||
$kycDocs = $this->generateKycPrimaryTable($sanitized_data['client_id']);
|
||||
}
|
||||
return $this->respond(['status' => true, 'code' => 200, 'data' => $kycDocs, 'file_name' => $file
|
||||
], 200);
|
||||
} else {
|
||||
return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to upload KYC document'], 200);
|
||||
$kycDocs = $this->generateKycPrimaryTable($client_id);
|
||||
return $this->respond(['status' => true, 'code' => 200, 'data' => $kycDocs, 'file_name' => $file], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to upload KYC document'], 200);
|
||||
}
|
||||
|
||||
/** Edit Client KYC Documents V1 */
|
||||
@ -1327,7 +1404,7 @@ class ClientController extends AdminController
|
||||
|
||||
$file = $this->request->getFile('file_name');
|
||||
|
||||
$fileName = file_Upload($file, $uploadFilePath, UPLOAD_EXT_KYC_DOCS);
|
||||
$fileName = file_Upload_for_lead($file, $uploadFilePath, UPLOAD_EXT_KYC_DOCS);
|
||||
|
||||
if (!empty($fileName)) {
|
||||
$sanitized_data['file_name'] = $fileName;
|
||||
@ -1352,24 +1429,40 @@ class ClientController extends AdminController
|
||||
|
||||
public function deleteClientKycDocs($id = null)
|
||||
{
|
||||
$client_id = $this->request->getGet('client_id');
|
||||
$updateData = [
|
||||
'is_active' => 0,
|
||||
'updated_by' => get_session_userid()
|
||||
];
|
||||
|
||||
$delete = $this->clientKYCDocsModel->where('kyc_doc_type_id', $id)->delete();
|
||||
$delete = $this->clientKYCDocsModel->update($id, $updateData);
|
||||
if ($delete) {
|
||||
return $this->respond(['status' => true, 'code' => 200, 'id' => $id], 200);
|
||||
} else {
|
||||
return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
|
||||
$response = ['status' => true, 'code' => 200, 'id' => $id];
|
||||
if (!empty($client_id)) {
|
||||
$response['data'] = $this->generateKycPrimaryTable($client_id);
|
||||
}
|
||||
return $this->respond($response, 200);
|
||||
}
|
||||
return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
|
||||
}
|
||||
|
||||
public function deleteClientKycOtherDocs($id = null)
|
||||
{
|
||||
$client_id = $this->request->getGet('client_id');
|
||||
$updateData = [
|
||||
'is_active' => 0,
|
||||
'updated_by' => get_session_userid()
|
||||
];
|
||||
|
||||
$delete = $this->clientKYCDocsModel->where('id', $id)->delete();
|
||||
$delete = $this->clientKYCDocsModel->update($id, $updateData);
|
||||
if ($delete) {
|
||||
return $this->respond(['status' => true, 'code' => 200, 'id' => $id], 200);
|
||||
} else {
|
||||
return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
|
||||
$response = ['status' => true, 'code' => 200, 'id' => $id];
|
||||
if (!empty($client_id)) {
|
||||
$response['data'] = $this->generateKycOthersTable($client_id);
|
||||
}
|
||||
return $this->respond($response, 200);
|
||||
}
|
||||
return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
|
||||
}
|
||||
|
||||
|
||||
@ -3660,7 +3753,7 @@ class ClientController extends AdminController
|
||||
|
||||
$db = db_connect();
|
||||
$builder = $db->table('kyc_docs kd');
|
||||
$builder->select('kd.*, ck.file_name AS upload_doc_name');
|
||||
$builder->select('kd.*, ck.file_name AS upload_doc_name, ck.id AS client_kyc_id');
|
||||
$builder->join('clients c', 'kd.kyc_type_id = c.entity_type_id');
|
||||
$builder->join(
|
||||
'client_kyc_documents ck',
|
||||
@ -4712,7 +4805,8 @@ class ClientController extends AdminController
|
||||
if (file_exists($file)) {
|
||||
return $this->response->download($file, null)->setFileName($file_name);
|
||||
} else {
|
||||
return "File not found.";
|
||||
$data['message'] = 'The Physical File Not Found';
|
||||
echo view('errors/404', $data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -9675,7 +9769,8 @@ class ClientController extends AdminController
|
||||
// download() takes the path as first param and null (or data) as second
|
||||
return $this->response->download($file, null);
|
||||
} else {
|
||||
return "File not found at: " . $file;
|
||||
$data['message'] = 'The Physical File Not Found';
|
||||
echo view('errors/404', $data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user