FIX_POS_SAVING_ISSUE

This commit is contained in:
VENKATESHWARAN 2026-04-22 11:31:38 +05:30
parent 553ba9069b
commit 0fd039d3bd
2 changed files with 306 additions and 188 deletions

View File

@ -277,61 +277,61 @@ class MasterController extends AdminController
echo view('insurer_onboarding', $data); echo view('insurer_onboarding', $data);
echo view('layout/footer'); echo view('layout/footer');
} }
public function createInsurerGeneralInfo() public function createInsurerGeneralInfo()
{ {
$this->myLogger->logme('error','Insurer general info function called'); $this->myLogger->logme('error', 'Insurer general info function called');
$rules = [ $rules = [
'name' => [ 'name' => [
'label' => 'Insurer Name', 'label' => 'Insurer Name',
'rules' => ['required', 'regex_match[/^[a-zA-Z0-9\s\-_]+$/]'], 'rules' => ['required', 'regex_match[/^[a-zA-Z0-9\s\-_]+$/]'],
'errors' => [ 'errors' => [
'required' => 'Insurer Name is required.', 'required' => 'Insurer Name is required.',
'regex_match' => 'Insurer Name can only contain letters, numbers, spaces, hyphens, and underscores.', 'regex_match' => 'Insurer Name can only contain letters, numbers, spaces, hyphens, and underscores.',
] ]
], ],
'short_name' => [ 'short_name' => [
'label' => 'Insurer Short Name', 'label' => 'Insurer Short Name',
'rules' => ['required', 'regex_match[/^[a-zA-Z0-9\-_]+$/]'], 'rules' => ['required', 'regex_match[/^[a-zA-Z0-9\-_]+$/]'],
'errors' => [ 'errors' => [
'required' => 'Short Name is required.', 'required' => 'Short Name is required.',
'regex_match' => 'Short Name can only contain letters, numbers, hyphens, and underscores.', 'regex_match' => 'Short Name can only contain letters, numbers, hyphens, and underscores.',
] ]
], ],
'type' => [ 'type' => [
'label' => 'Insurer Type', 'label' => 'Insurer Type',
'rules' => 'permit_empty|in_list[pvt,psu]', 'rules' => 'permit_empty|in_list[pvt,psu]',
'errors' => [ 'errors' => [
'in_list' => 'Please select a valid Insurer Type (PVT or PSU).' 'in_list' => 'Please select a valid Insurer Type (PVT or PSU).'
] ]
], ],
'category' => [ 'category' => [
'label' => 'Insurer Category', 'label' => 'Insurer Category',
'rules' => 'permit_empty|in_list[life,general]', 'rules' => 'permit_empty|in_list[life,general]',
'errors' => [ 'errors' => [
'in_list' => 'Please select a valid Category (Life or General).' 'in_list' => 'Please select a valid Category (Life or General).'
] ]
], ],
'addition_add_day' => [ 'addition_add_day' => [
'rules' => 'permit_empty' // Checkboxes return null if unchecked 'rules' => 'permit_empty' // Checkboxes return null if unchecked
], ],
'deletion_add_day' => [ 'deletion_add_day' => [
'rules' => 'permit_empty' 'rules' => 'permit_empty'
], ],
'is_multi_event' => [ 'is_multi_event' => [
'rules' => 'permit_empty' 'rules' => 'permit_empty'
], ],
'insurer_logo' => [ 'insurer_logo' => [
'rules' => 'if_exist|is_image[insurer_logo]|max_size[insurer_logo,200]|ext_in[insurer_logo,jpg,jpeg,png]', 'rules' => 'if_exist|is_image[insurer_logo]|max_size[insurer_logo,200]|ext_in[insurer_logo,jpg,jpeg,png]',
'errors' => [ 'errors' => [
'is_image' => 'The uploaded file must be an image', 'is_image' => 'The uploaded file must be an image',
'max_size' => 'File size should not exceed 200 KB', 'max_size' => 'File size should not exceed 200 KB',
'ext_in' => 'Allowed file types: jpg, jpeg, png', 'ext_in' => 'Allowed file types: jpg, jpeg, png',
] ]
], ],
]; ];
// $rules = [ // $rules = [
// 'name' => [ // 'name' => [
// 'rules' => 'required', // 'rules' => 'required',
@ -3538,8 +3538,9 @@ class MasterController extends AdminController
{ {
$posModel = new PartnerPosModel(); $posModel = new PartnerPosModel();
$method = $this->request->getMethod(); $method = $this->request->getMethod();
if ($this->request->getMethod() === 'post') { if ($this->request->getMethod() === 'post') {
try {
$rules = [ $rules = [
'manager_id' => [ 'manager_id' => [
@ -3555,7 +3556,7 @@ class MasterController extends AdminController
'required' => 'Name is required', 'required' => 'Name is required',
'min_length' => 'Name must be at least 3 characters', 'min_length' => 'Name must be at least 3 characters',
'max_length' => 'Name cannot exceed 100 characters', 'max_length' => 'Name cannot exceed 100 characters',
'alpha_space'=> 'Name can contain only letters and spaces' 'alpha_space' => 'Name can contain only letters and spaces'
] ]
], ],
'pos_code' => [ 'pos_code' => [
@ -3589,27 +3590,27 @@ class MasterController extends AdminController
] ]
], ],
'state' => [ 'state' => [
'label' => 'State', 'label' => 'State',
'rules' => 'required|regex_match[/^[a-zA-Z0-9\/\-\_\.\s]+$/]', 'rules' => 'required|regex_match[/^[a-zA-Z0-9\/\-\_\.\s]+$/]',
'errors' => [ 'errors' => [
'required' => 'State is required.', 'required' => 'State is required.',
'regex_match' => 'State name can only contain letters, spaces, and hyphens.' 'regex_match' => 'State name can only contain letters, spaces, and hyphens.'
] ]
], ],
'city' => [ 'city' => [
'rules' => 'required|regex_match[/^[a-zA-Z0-9\s\-]+$/]', 'rules' => 'required|regex_match[/^[a-zA-Z0-9\s\-]+$/]',
'errors' => [ 'errors' => [
'regex_match' => 'City can contain letters, numbers, spaces, and hyphens.' 'regex_match' => 'City can contain letters, numbers, spaces, and hyphens.'
] ]
], ],
'pincode' => [ 'pincode' => [
'rules' => 'required|numeric|exact_length[6]', 'rules' => 'required|numeric|exact_length[6]',
'errors' => [ 'errors' => [
'required' => 'Pincode is required.', 'required' => 'Pincode is required.',
'numeric' => 'Pincode must be digits only.', 'numeric' => 'Pincode must be digits only.',
'exact_length' => 'Pincode must be exactly 6 digits.' 'exact_length' => 'Pincode must be exactly 6 digits.'
] ]
], ],
'aadhar' => [ 'aadhar' => [
'rules' => 'required|numeric|exact_length[12]', 'rules' => 'required|numeric|exact_length[12]',
'errors' => [ 'errors' => [
@ -3632,25 +3633,22 @@ class MasterController extends AdminController
] ]
], ],
'aadhar_file_name' => [ 'aadhar_file_name' => [
'rules' => 'permit_empty|uploaded[aadhar_file_name]|max_size[aadhar_file_name,5120]|ext_in[aadhar_file_name,pdf,jpg,jpeg,png]', 'rules' => 'if_exist|max_size[aadhar_file_name,5120]|ext_in[aadhar_file_name,pdf,jpg,jpeg,png]',
'errors' => [ 'errors' => [
'uploaded' => 'Invalid Aadhaar file',
'max_size' => 'Aadhaar file size should not exceed 5MB', 'max_size' => 'Aadhaar file size should not exceed 5MB',
'ext_in' => 'Aadhaar must be PDF or image (jpg, jpeg, png)' 'ext_in' => 'Aadhaar must be PDF or image (jpg, jpeg, png)'
] ]
], ],
'pan_file_name' => [ 'pan_file_name' => [
'rules' => 'permit_empty|uploaded[pan_file_name]|max_size[pan_file_name,5120]|ext_in[pan_file_name,pdf,jpg,jpeg,png]', 'rules' => 'if_exist|max_size[pan_file_name,5120]|ext_in[pan_file_name,pdf,jpg,jpeg,png]',
'errors' => [ 'errors' => [
'uploaded' => 'Invalid PAN file',
'max_size' => 'PAN file size should not exceed 5MB', 'max_size' => 'PAN file size should not exceed 5MB',
'ext_in' => 'PAN must be PDF or image (jpg, jpeg, png)' 'ext_in' => 'PAN must be PDF or image (jpg, jpeg, png)'
] ]
], ],
'certificate_file_name' => [ 'certificate_file_name' => [
'rules' => 'permit_empty|uploaded[certificate_file_name]|max_size[certificate_file_name,5120]|ext_in[certificate_file_name,pdf,jpg,jpeg,png]', 'rules' => 'if_exist|max_size[certificate_file_name,5120]|ext_in[certificate_file_name,pdf,jpg,jpeg,png]',
'errors' => [ 'errors' => [
'uploaded' => 'Invalid Certificate file',
'max_size' => 'Certificate file size should not exceed 5MB', 'max_size' => 'Certificate file size should not exceed 5MB',
'ext_in' => 'Certificate must be PDF or image (jpg, jpeg, png)' 'ext_in' => 'Certificate must be PDF or image (jpg, jpeg, png)'
] ]
@ -3669,138 +3667,217 @@ class MasterController extends AdminController
$data = $this->request->getPost(); $data = $this->request->getPost();
$sanitized_post_data = sanitizeInputArrayAdvanced($data); $sanitized_post_data = sanitizeInputArrayAdvanced($data);
$id = $sanitized_post_data['pk'] ?? null; $id = $sanitized_post_data['pk'] ?? null;
unset($sanitized_post_data['pk']); unset($sanitized_post_data['pk']);
try { try {
// Certificate // Certificate
$certificate = $this->uploadPOSFile('certificate_file_name', 'pos_certificate_files'); $certificate = $this->uploadPOSFile('certificate_file_name', 'pos_certificate_files');
if ($certificate !== null) { $sanitized_post_data['certificate_file_name'] = $certificate; } else { unset($sanitized_post_data['certificate_file_name']); } if ($certificate !== null) {
$sanitized_post_data['certificate_file_name'] = $certificate;
} else {
unset($sanitized_post_data['certificate_file_name']);
}
// PAN file // PAN file
$panFile = $this->uploadPOSFile('pan_file_name', 'pos_certificate_files'); $panFile = $this->uploadPOSFile('pan_file_name', 'pos_certificate_files');
if ($panFile !== null) { $sanitized_post_data['pan_file_name'] = $panFile; } else { unset($sanitized_post_data['pan_file_name']);} if ($panFile !== null) {
$sanitized_post_data['pan_file_name'] = $panFile;
} else {
unset($sanitized_post_data['pan_file_name']);
}
// Aadhaar file // Aadhaar file
$aadharFile = $this->uploadPOSFile('aadhar_file_name', 'pos_certificate_files'); $aadharFile = $this->uploadPOSFile('aadhar_file_name', 'pos_certificate_files');
if ($aadharFile !== null) { $sanitized_post_data['aadhar_file_name'] = $aadharFile; } else { unset($sanitized_post_data['aadhar_file_name']);} if ($aadharFile !== null) {
$sanitized_post_data['aadhar_file_name'] = $aadharFile;
} catch (\RuntimeException $e) { } else {
return $this->respond([ 'status' => false, 'code' => 400, 'message' => $e->getMessage(), 'data' => $sanitized_post_data ], 400); unset($sanitized_post_data['aadhar_file_name']);
}
} catch (\Exception $e) {
log_message('error', 'File upload error: ' . $e->getMessage() . ' | POST data: ' . json_encode($sanitized_post_data) . $e->getTraceAsString());
return $this->respond(['status' => false, 'code' => 400, 'message' => $e->getMessage(), 'data' => $sanitized_post_data], 400);
} }
foreach ($sanitized_post_data as $k => $v) { foreach ($sanitized_post_data as $k => $v) {
if ($v === '' || $v === null) { if ($v === '' || $v === null) {
unset($sanitized_post_data[$k]); unset($sanitized_post_data[$k]);
}
} }
}
// INSERT / UPDATE // INSERT / UPDATE
if (empty($id)) { try {
$status = $posModel->insert($sanitized_post_data); if (empty($id)) {
} else { $status = $posModel->insert($sanitized_post_data);
$status = $posModel->update($id, $sanitized_post_data); } else {
} $status = $posModel->update($id, $sanitized_post_data);
}
if ($status) { if ($status) {
return $this->respond([ 'status' => true, 'code' => 200, 'message' => 'POS updated successfully', 'data' => $sanitized_post_data ], 200); return $this->respond(['status' => true, 'code' => 200, 'message' => 'POS updated successfully', 'data' => $sanitized_post_data], 200);
} }
return $this->respond([ 'status' => false, 'code' => 400, 'message' => 'Failed to update', 'data' => $sanitized_post_data ], 400); $modelErrors = method_exists($posModel, 'errors') ? $posModel->errors() : [];
} return $this->respond([
elseif ($method === 'get') { 'status' => false,
'code' => 400,
'message' => 'Failed to update',
'errors' => $modelErrors,
'data' => $sanitized_post_data
], 400);
} catch (\Throwable $e) {
log_message('error', 'partnerPOS DB error: ' . $e->getMessage() . ' | payload: ' . json_encode($sanitized_post_data) . ' | trace: ' . $e->getTraceAsString());
$id = $this->request->getGet('pk') ?? null; $message = 'Something went wrong while saving POS details.';
$statusCode = 500;
$db = db_connect(); if (stripos($e->getMessage(), 'Duplicate entry') !== false) {
$statusCode = 400;
$builder = $db->table('partner_staff'); if (stripos($e->getMessage(), 'email') !== false) {
$message = 'Email already exists.';
$data['manager_list'] = $builder->select('partner_staff.id, partner_staff.name') } elseif (stripos($e->getMessage(), 'mobile') !== false) {
->where('partner_staff.is_active', 1) $message = 'Mobile number already exists.';
->where('partner_staff.role_id', 1) } else {
->get() $message = 'Duplicate data found. Please check email/mobile.';
->getResultArray();
if (!empty($id)) {
$data['pos_list'] = $posModel
->select('partner_pos.*, partner_staff.name AS manager_name')
->join('partner_staff', 'partner_staff.id = partner_pos.manager_id', 'left')
->where('partner_pos.id', $id)
->orderBy('partner_pos.id', 'DESC')
->findAll();
if (!empty($data)) {
return $this->respond(['status' => true, 'code' => 200, 'data' => $data], 200);
} else {
return $this->respond(['status' => false, 'code' => 400, 'message' => 'No data found'], 200);
}
}
$data['pos_list'] = $posModel
->select('partner_pos.*, ps.name AS manager_name')
->join('partner_staff ps', 'ps.id = partner_pos.manager_id', 'left')
->orderBy('partner_pos.id', 'DESC')
->findAll();
return $this->loadLayout('pos_list', ['data' => $data,'tab_name' => 'POS details','page_name' => 'POS details']);
} elseif ($method === 'delete') {
// $input = $this->request->getRawInput();
$id = $this->request->getGet('pk'); // ✅ THIS
$id = $id ?? null;
if (empty($id)) {
return $this->respond([
'status' => false,
'code' => 404,
'message' => 'No ID provided for deletion'
], 200);
}
$update_status = $posModel->where('id', $id)->set(['is_active' => 0])->update();
if ($update_status) {
return $this->respond([
'status' => true,
'code' => 200,
'message' => 'Data removed successfully',
'pk' => $id
], 200);
} else {
return $this->respond([
'status' => false,
'code' => 400,
'message' => 'Failed to remove data',
'pk' => $id
], 200);
}
} }
} }
private function uploadPOSFile(string $fieldName, string $uploadDir) return $this->respond([
{ 'status' => false,
$file = $this->request->getFile($fieldName); 'code' => $statusCode,
'message' => $message
], $statusCode);
}
} catch (\Throwable $e) {
log_message(
'error',
'partnerPOS fatal error: ' . $e->getMessage() .
' | file: ' . $e->getFile() .
' | line: ' . $e->getLine() .
' | trace: ' . $e->getTraceAsString()
);
return $this->respond([
'status' => false,
'code' => 500,
'message' => 'Internal server error while processing POS request.'
], 500);
}
} elseif ($method === 'get') {
if (!$file || !$file->isValid()) { return null; } $id = $this->request->getGet('pk') ?? null;
$allowedMime = [ 'image/jpg', 'image/jpeg', 'image/png', 'image/webp', 'application/pdf']; $db = db_connect();
if (!in_array($file->getMimeType(), $allowedMime)) { throw new \RuntimeException('Invalid file format'); } $builder = $db->table('partner_staff');
$path = ROOTPATH . 'public/uploads/' . $uploadDir . '/'; $data['manager_list'] = $builder->select('partner_staff.id, partner_staff.name')
->where('partner_staff.is_active', 1)
->where('partner_staff.role_id', 1)
->get()
->getResultArray();
if (!is_dir($path)) { mkdir($path, 0755, true); }
$newName = $file->getRandomName(); if (!empty($id)) {
$file->move($path, $newName);
return $newName; $data['pos_list'] = $posModel
->select('partner_pos.*, partner_staff.name AS manager_name')
->join('partner_staff', 'partner_staff.id = partner_pos.manager_id', 'left')
->where('partner_pos.id', $id)
->orderBy('partner_pos.id', 'DESC')
->findAll();
if (!empty($data)) {
return $this->respond(['status' => true, 'code' => 200, 'data' => $data], 200);
} else {
return $this->respond(['status' => false, 'code' => 400, 'message' => 'No data found'], 200);
} }
}
$data['pos_list'] = $posModel
->select('partner_pos.*, ps.name AS manager_name')
->join('partner_staff ps', 'ps.id = partner_pos.manager_id', 'left')
->orderBy('partner_pos.id', 'DESC')
->findAll();
} return $this->loadLayout('pos_list', ['data' => $data, 'tab_name' => 'POS details', 'page_name' => 'POS details']);
} elseif ($method === 'delete') {
// $input = $this->request->getRawInput();
$id = $this->request->getGet('pk'); // ✅ THIS
$id = $id ?? null;
if (empty($id)) {
return $this->respond([
'status' => false,
'code' => 404,
'message' => 'No ID provided for deletion'
], 200);
}
$update_status = $posModel->where('id', $id)->set(['is_active' => 0])->update();
if ($update_status) {
return $this->respond([
'status' => true,
'code' => 200,
'message' => 'Data removed successfully',
'pk' => $id
], 200);
} else {
return $this->respond([
'status' => false,
'code' => 400,
'message' => 'Failed to remove data',
'pk' => $id
], 200);
}
}
}
private function uploadPOSFile(string $fieldName, string $uploadDir)
{
$file = $this->request->getFile($fieldName);
if (!$file) {
return null;
}
// No file selected for this optional input.
if ($file->getError() === UPLOAD_ERR_NO_FILE) {
return null;
}
if (!$file->isValid()) {
throw new \RuntimeException('File upload failed for ' . $fieldName);
}
$allowedMime = [
'image/jpg',
'image/jpeg',
'image/pjpeg',
'image/png',
'image/x-png',
'image/webp',
'application/pdf'
];
$mimeType = (string) $file->getMimeType();
if (!in_array($mimeType, $allowedMime, true)) {
throw new \RuntimeException('Invalid file format for ' . $fieldName);
}
$path = ROOTPATH . 'public/uploads/' . $uploadDir . '/';
if (!is_dir($path)) {
mkdir($path, 0755, true);
}
$newName = $file->getRandomName();
$file->move($path, $newName);
return $newName;
}
}

View File

@ -233,6 +233,7 @@ $pos_col_width_px = nhance_dt_column_widths_px($pos_header_labels, $pos_col_max_
<input type="file" class="form-control" name="aadhar_file_name" id="aadhar_file_name" accept=".pdf,.jpg,.jpeg,.png" data-parsley-file-validation> <input type="file" class="form-control" name="aadhar_file_name" id="aadhar_file_name" accept=".pdf,.jpg,.jpeg,.png" data-parsley-file-validation>
<i class="mdi mdi-upload additional-icon"></i> <i class="mdi mdi-upload additional-icon"></i>
</div> </div>
<small id="aadhar_file_name_display" class="text-muted d-block" style="display:none !important;"></small>
<small class="text-muted d-block">Allowed: PDF, PNG, JPG, JPEG.</small> <small class="text-muted d-block">Allowed: PDF, PNG, JPG, JPEG.</small>
</div> </div>
<div class="form-group col-md-4"> <div class="form-group col-md-4">
@ -241,6 +242,7 @@ $pos_col_width_px = nhance_dt_column_widths_px($pos_header_labels, $pos_col_max_
<input type="file" class="form-control" name="pan_file_name" id="pan_file_name" accept=".pdf,.jpg,.jpeg,.png" data-parsley-file-validation> <input type="file" class="form-control" name="pan_file_name" id="pan_file_name" accept=".pdf,.jpg,.jpeg,.png" data-parsley-file-validation>
<i class="mdi mdi-upload additional-icon"></i> <i class="mdi mdi-upload additional-icon"></i>
</div> </div>
<small id="pan_file_name_display" class="text-muted d-block" style="display:none !important;"></small>
<small class="text-muted d-block">Allowed: PDF, PNG, JPG, JPEG.</small> <small class="text-muted d-block">Allowed: PDF, PNG, JPG, JPEG.</small>
</div> </div>
<div class="form-group col-md-4"> <div class="form-group col-md-4">
@ -249,6 +251,7 @@ $pos_col_width_px = nhance_dt_column_widths_px($pos_header_labels, $pos_col_max_
<input type="file" class="form-control" name="certificate_file_name" id="certificate_file_name" accept=".pdf,.jpg,.jpeg,.png" data-parsley-file-validation> <input type="file" class="form-control" name="certificate_file_name" id="certificate_file_name" accept=".pdf,.jpg,.jpeg,.png" data-parsley-file-validation>
<i class="mdi mdi-upload additional-icon"></i> <i class="mdi mdi-upload additional-icon"></i>
</div> </div>
<small id="certificate_file_name_display" class="text-muted d-block" style="display:none !important;"></small>
<small class="text-muted d-block">Allowed: PDF, PNG, JPG, JPEG.</small> <small class="text-muted d-block">Allowed: PDF, PNG, JPG, JPEG.</small>
</div> </div>
</div> </div>
@ -433,11 +436,17 @@ $pos_col_width_px = nhance_dt_column_widths_px($pos_header_labels, $pos_col_max_
}, },
error: function (xhr) { error: function (xhr) {
$('.loader, .loader-mask').fadeOut(); $('.loader, .loader-mask').fadeOut();
let response = null;
try {
response = xhr.responseText ? JSON.parse(xhr.responseText) : null;
} catch (e) {
response = null;
}
if (xhr.status === 400) { if (xhr.status === 400) {
let response = JSON.parse(xhr.responseText);
let errorMessages = ""; let errorMessages = "";
let seenMessages = []; // Array to store unique messages let seenMessages = []; // Array to store unique messages
if (response.errors) { if (response && response.errors) {
$.each(response.errors, function (field, message) { $.each(response.errors, function (field, message) {
if (!seenMessages.includes(message)) { if (!seenMessages.includes(message)) {
errorMessages += `• ${message}<br>`; errorMessages += `• ${message}<br>`;
@ -446,16 +455,15 @@ $pos_col_width_px = nhance_dt_column_widths_px($pos_header_labels, $pos_col_max_
}); });
toastr.error(errorMessages, 'Validation Error', { "allowHtml": true }); toastr.error(errorMessages, 'Validation Error', { "allowHtml": true });
} else { } else {
toastr.warning(response.message || 'Validation failed', 'Warning'); toastr.warning((response && response.message) ? response.message : 'Validation failed', 'Warning');
} }
} else if (xhr.status === 403) { } else if (xhr.status === 403) {
let response = JSON.parse(xhr.responseText); toastr.error((response && response.message) ? response.message : 'Security policy error', 'Security Policy');
toastr.error(response.message, 'Security Policy');
} else if (xhr.status === 500) { } else if (xhr.status === 500) {
toastr.error('Something went wrong . Please try again later.', 'Server Error'); toastr.error((response && response.message) ? response.message : 'Something went wrong . Please try again later.', 'Server Error');
} else { } else {
toastr.error('An unexpected error occurred. Please try again later.', 'Error'); toastr.error((response && response.message) ? response.message : 'An unexpected error occurred. Please try again later.', 'Error');
} }
console.error('Unexpected error:', xhr.responseText); console.error('Unexpected error:', xhr.responseText);
@ -470,9 +478,32 @@ $pos_col_width_px = nhance_dt_column_widths_px($pos_header_labels, $pos_col_max_
$('#partnerPOSForm').parsley().reset(); $('#partnerPOSForm').parsley().reset();
} }
$('#manager_id').val(null).trigger('change'); $('#manager_id').val(null).trigger('change');
updateFileNameDisplay('#aadhar_file_name', '#aadhar_file_name_display', '');
updateFileNameDisplay('#pan_file_name', '#pan_file_name_display', '');
updateFileNameDisplay('#certificate_file_name', '#certificate_file_name_display', '');
} }
function updateFileNameDisplay(inputSelector, displaySelector, existingName = '') {
const $display = $(displaySelector);
let fileName = '';
if (existingName && String(existingName).trim() !== '') {
fileName = String(existingName).trim();
} else {
const inputEl = $(inputSelector)[0];
if (inputEl && inputEl.files && inputEl.files.length > 0) {
fileName = inputEl.files[0].name || '';
}
}
if (fileName) {
$display.text('Uploaded: ' + fileName).show();
} else {
$display.text('').hide();
}
}
function appendEditData(data){ function appendEditData(data){
$('#pos_id').val(data.id); $('#pos_id').val(data.id);
@ -481,14 +512,12 @@ $pos_col_width_px = nhance_dt_column_widths_px($pos_header_labels, $pos_col_max_
$('#mobile').val(data.mobile); $('#mobile').val(data.mobile);
$('#pos_code').val(data.pos_code); $('#pos_code').val(data.pos_code);
// Instead of setting the file input
$('#current_file_name').text(data['certificate_file_name'] || 'No file uploaded');
$('#aadhar').val(data.aadhar); $('#aadhar').val(data.aadhar);
$('#aadhar_file_name').text(data['aadhar_file_name'] || 'No file uploaded'); updateFileNameDisplay('#aadhar_file_name', '#aadhar_file_name_display', data['aadhar_file_name'] || '');
$('#pan').val(data.pan); $('#pan').val(data.pan);
$('#pan_file_name').text(data['pan_file_name'] || 'No file uploaded'); updateFileNameDisplay('#pan_file_name', '#pan_file_name_display', data['pan_file_name'] || '');
updateFileNameDisplay('#certificate_file_name', '#certificate_file_name_display', data['certificate_file_name'] || '');
$('#bank_name').val(data.bank_name); $('#bank_name').val(data.bank_name);
$('#account_holder_name').val(data.account_holder_name); $('#account_holder_name').val(data.account_holder_name);
@ -508,6 +537,18 @@ $pos_col_width_px = nhance_dt_column_widths_px($pos_header_labels, $pos_col_max_
}); });
} }
$('#aadhar_file_name').on('change', function () {
updateFileNameDisplay('#aadhar_file_name', '#aadhar_file_name_display');
});
$('#pan_file_name').on('change', function () {
updateFileNameDisplay('#pan_file_name', '#pan_file_name_display');
});
$('#certificate_file_name').on('change', function () {
updateFileNameDisplay('#certificate_file_name', '#certificate_file_name_display');
});
$('#aadhar').on('input', function () { $('#aadhar').on('input', function () {
this.value = this.value.replace(/[^0-9]/g, ''); this.value = this.value.replace(/[^0-9]/g, '');