MERGE_TEST_MINOR_ISSUE&HR_DASHBOARD
This commit is contained in:
commit
e5d48a7ee3
@ -1611,7 +1611,7 @@ class ClientController extends AdminController
|
||||
}
|
||||
|
||||
|
||||
public function createClientBranch()
|
||||
public function createClientBranchNew()
|
||||
{
|
||||
|
||||
$this->myLogger->logme('error', 'Client branch CREATE function called');
|
||||
@ -1796,7 +1796,7 @@ class ClientController extends AdminController
|
||||
}
|
||||
}
|
||||
|
||||
public function editClientBranch()
|
||||
public function editClientBranchNew()
|
||||
{
|
||||
|
||||
$this->myLogger->logme('error', 'Client branch EDIT function called');
|
||||
@ -1916,11 +1916,9 @@ class ClientController extends AdminController
|
||||
$level_contact_data = [];
|
||||
|
||||
if (!empty($level_contact_data_raw)) {
|
||||
$level_contact_data_decoded = json_decode($level_contact_data_raw, true);
|
||||
$level_contact_data_decoded = json_decode($level_contact_data_raw ?? '{}', true);
|
||||
|
||||
if (json_last_error() === JSON_ERROR_NONE && is_array($level_contact_data_decoded)) {
|
||||
$level_contact_data = sanitizeInputArrayAdvanced($level_contact_data_decoded);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($level_contact_data)) {
|
||||
@ -1949,6 +1947,367 @@ class ClientController extends AdminController
|
||||
}
|
||||
}
|
||||
|
||||
public function saveLevelContactsNew($level_contact_data, $branch_id)
|
||||
{
|
||||
if (!empty($level_contact_data) && is_array($level_contact_data)) {
|
||||
foreach ($level_contact_data as $value) {
|
||||
if (!empty($value['id'])) {
|
||||
$id = $value['id'];
|
||||
unset($value['id']);
|
||||
$this->levelContactModel->update($id, $value);
|
||||
} else {
|
||||
unset($value['id']);
|
||||
$value['contact_type'] = "client";
|
||||
$value['ref_id'] = $branch_id ?? null;
|
||||
$this->levelContactModel->insert($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function removeLevelContactsNew()
|
||||
{
|
||||
$id = $this->request->getGet('id');
|
||||
try {
|
||||
if (empty($id)) {
|
||||
return $this->respond([
|
||||
'status' => false,
|
||||
'message' => 'Invalid ID provided. ID is empty',
|
||||
'data' => $id
|
||||
], 400);
|
||||
}
|
||||
|
||||
$updated = $this->levelContactModel->update($id, ['is_active' => 0]);
|
||||
|
||||
if ($updated === false) {
|
||||
return $this->respond([
|
||||
'status' => false,
|
||||
'message' => 'Failed to remove contact'
|
||||
], 500);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => true,
|
||||
'message' => 'Contact removed successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([
|
||||
'status' => false,
|
||||
'message' => 'An error occurred: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function createClientBranch()
|
||||
{
|
||||
|
||||
$this->myLogger->logme('error', 'Client branch CREATE function called');
|
||||
|
||||
$rules = [
|
||||
'branch_name' => [
|
||||
'rules' => 'required',
|
||||
'errors' => [
|
||||
'required' => 'Branch Name is required',
|
||||
]
|
||||
],
|
||||
'branch_code' => [
|
||||
'rules' => 'required',
|
||||
'errors' => [
|
||||
'required' => 'Branch Code is required',
|
||||
]
|
||||
],
|
||||
'address1' => [
|
||||
'rules' => 'required',
|
||||
'errors' => [
|
||||
'required' => 'Address Line 1 is required',
|
||||
]
|
||||
],
|
||||
'state' => [
|
||||
'rules' => 'required',
|
||||
'errors' => [
|
||||
'required' => 'State is required',
|
||||
]
|
||||
],
|
||||
'district' => [
|
||||
'rules' => 'required',
|
||||
'errors' => [
|
||||
'required' => 'District is required.',
|
||||
]
|
||||
],
|
||||
'city' => [
|
||||
'rules' => 'required',
|
||||
'errors' => [
|
||||
'required' => 'City is required.',
|
||||
]
|
||||
],
|
||||
'pincode' => [
|
||||
'rules' => 'required',
|
||||
'errors' => [
|
||||
'required' => 'Pincode is required.',
|
||||
]
|
||||
],
|
||||
'gst' => [
|
||||
'rules' => 'required|regex_match[/^\d{2}[A-Z]{5}\d{4}[A-Z]{1}[A-Z\d]{1}Z[A-Z\d]{1}$/]',
|
||||
'errors' => [
|
||||
'required' => 'GST number is required',
|
||||
'regex_match' => 'Invalid GST Number. Example: 12ABCDE1234F5Z6'
|
||||
]
|
||||
],
|
||||
'name.*' => [
|
||||
'rules' => 'required|alpha_space',
|
||||
'errors' => [
|
||||
'required' => 'Contact name is required',
|
||||
'alpha_space' => 'Contact name may contain only letters and spaces'
|
||||
]
|
||||
],
|
||||
'designation.*' => [
|
||||
'rules' => 'required|alpha_space',
|
||||
'errors' => [
|
||||
'required' => 'Designation is required',
|
||||
'alpha_space' => 'Designation may contain only letters and spaces'
|
||||
]
|
||||
],
|
||||
'email.*' => [
|
||||
'rules' => 'required|valid_email',
|
||||
'errors' => [
|
||||
'required' => 'Email is required',
|
||||
'valid_email' => 'Please enter a valid email address'
|
||||
]
|
||||
],
|
||||
'mobile.*' => [
|
||||
'rules' => 'required|numeric|exact_length[10]',
|
||||
'errors' => [
|
||||
'required' => 'Mobile number is required',
|
||||
'numeric' => 'Mobile number must contain digits only',
|
||||
'exact_length' => 'Mobile number must be exactly 10 digits'
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
if (!$this->validate($rules)) {
|
||||
return $this->response->setStatusCode(400)->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'Input validation failed',
|
||||
'code' => 400,
|
||||
'errors' => $this->validator->getErrors()
|
||||
]);
|
||||
}
|
||||
|
||||
$data = $this->request->getPost();
|
||||
$data = sanitizeInputArrayAdvanced($data);
|
||||
|
||||
|
||||
if (!isset($data['sez'])) {
|
||||
$data['sez'] = 0;
|
||||
} elseif ($data['sez']) {
|
||||
$data['sez'] = 1;
|
||||
}
|
||||
|
||||
$units = json_decode($data['units'], true) ?? [];
|
||||
|
||||
if (!is_array($units) || empty($units)) {
|
||||
$client_data = $this->clientModel->where('id', $data['client_id'])->first();
|
||||
$default_unit = trim(($client_data['short_name'] ?? '') . '-' . ($data['branch_code'] ?? ''), '-');
|
||||
$data['units'] = json_encode([$default_unit]);
|
||||
}
|
||||
|
||||
$data['created_by'] = get_session_userid();
|
||||
|
||||
|
||||
// before updating check if pre_branch_id is already existing in the current db
|
||||
|
||||
if(isset($data['pre_branch_id']) && !empty($data['pre_branch_id']))
|
||||
{
|
||||
$existing_pre_branch = $this->clientBranchModel
|
||||
->where('pre_branch_id',$data['pre_branch_id'])
|
||||
//->where('id !=',$post_branch_id)
|
||||
->first();
|
||||
|
||||
if($existing_pre_branch)
|
||||
{
|
||||
return $this->respond([
|
||||
'status' => false,
|
||||
'code' => 409,
|
||||
'message' => 'The branch is already mapped with another branch. Please check.',
|
||||
], 409);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$insert = $this->clientBranchModel->insert($data);
|
||||
|
||||
$post_branch_id = $insert;
|
||||
|
||||
if ($insert) {
|
||||
$level_contact_data = $this->request->getPost('level_contect_data');
|
||||
$level_contact_data = !empty($level_contact_data) ? json_decode($level_contact_data, true) : null;
|
||||
$this->saveLevelContacts($level_contact_data, $insert);
|
||||
}
|
||||
|
||||
if($post_branch_id && isset($data['pre_branch_id']) && !empty($data['pre_branch_id']))
|
||||
{
|
||||
// need to update the client_branch in the pre
|
||||
$result = $this->updatePreClientBranch($data['pre_branch_id'],$post_branch_id , "create");
|
||||
|
||||
log_message('error','Pre client_branch update result for pre_branch_id '.$data['pre_branch_id'].' and post_branch_id '.$post_branch_id.' is '.json_encode($result));
|
||||
}
|
||||
|
||||
if ($insert) {
|
||||
$branchData = $this->clientBranchModel->where('client_id', $this->request->getPost('client_id'))->findAll();
|
||||
$branchData['role'] = get_role_id();
|
||||
return $this->respond([
|
||||
'status' => true,
|
||||
'code' => 200,
|
||||
'data' => $branchData,
|
||||
'message' => 'Client branch created successfully',
|
||||
], 200);
|
||||
} else {
|
||||
return $this->respond([
|
||||
'status' => false,
|
||||
'code' => 404,
|
||||
'message' => 'Failed to create client branch ',
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
public function editClientBranch()
|
||||
{
|
||||
|
||||
$this->myLogger->logme('error', 'Client branch EDIT function called');
|
||||
$id = $this->request->getPost('branch_id_primarykey');
|
||||
$client_id = $this->request->getPost('client_id');
|
||||
$pre_branch_id = $this->request->getPost('pre_branch_id') ?? '';
|
||||
|
||||
$data = $this->request->getPost();
|
||||
$data = sanitizeInputArrayAdvanced($data);
|
||||
$data['pre_branch_id'] = $pre_branch_id;
|
||||
|
||||
$units = $this->request->getPost('units');
|
||||
|
||||
$emp_unit_count = 0;
|
||||
$rr_unit_count = 0;
|
||||
$rr_unit_count2 = 0;
|
||||
$total_count = 0;
|
||||
|
||||
$list_of_branch_units = $this->clientBranchModel->find((int)$id);
|
||||
$units = json_decode($list_of_branch_units['units']);
|
||||
|
||||
if (!is_array($units) || empty($units)) {
|
||||
$client_data = $this->clientModel->where('id', $data['client_id'])->first();
|
||||
$default_unit = trim(($client_data['short_name'] ?? '') . '-' . ($data['branch_code'] ?? ''), '-');
|
||||
$data['units'] = json_encode([$default_unit]);
|
||||
}
|
||||
|
||||
if (!empty($units)) {
|
||||
foreach ($units as $unit) {
|
||||
$emp_unit_count += $this->employeeModel->where('unit', $unit)->countAllResults();
|
||||
$rr_unit_count += $this->policyPremium2Model->where('unit', $unit)->countAllResults();
|
||||
$rr_unit_count2 += $this->policyPremium1Model->where('unit', $unit)->countAllResults();
|
||||
}
|
||||
|
||||
$total_count = $emp_unit_count + $rr_unit_count + $rr_unit_count2;
|
||||
}
|
||||
|
||||
$uncommonValues = [];
|
||||
|
||||
if ($total_count > 0) {
|
||||
$units = (string) $this->request->getPost('units'); // Assuming 'units' is an array
|
||||
|
||||
$list_of_branch_units = $this->clientBranchModel->find((int)$id);
|
||||
$branch_units = json_decode($list_of_branch_units['units'], true);
|
||||
$units = json_decode($units);
|
||||
|
||||
$uncommonValues = array_diff($branch_units, $units);
|
||||
|
||||
if (count($uncommonValues) > 0) {
|
||||
|
||||
$branchData = $this->clientBranchModel->where('client_id', $client_id)->findAll();
|
||||
|
||||
return $this->respond([
|
||||
'status' => false,
|
||||
'code' => 404,
|
||||
'message' => "Deleted unit(s) in use. couldn't complete this operation.",
|
||||
'uncommonValues' => $uncommonValues,
|
||||
'data' => $branchData,
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($data['sez'])) {
|
||||
$data['sez'] = 0;
|
||||
} elseif ($data['sez']) {
|
||||
$data['sez'] = 1;
|
||||
}
|
||||
|
||||
$data['updated_by'] = get_session_userid();
|
||||
|
||||
$post_branch_id = $id;
|
||||
|
||||
// before updating check if pre_branch_id is already existing in the current db
|
||||
|
||||
if(isset($data['pre_branch_id']) && !empty($data['pre_branch_id']))
|
||||
{
|
||||
$existing_pre_branch = $this->clientBranchModel
|
||||
->where('pre_branch_id',$data['pre_branch_id'])
|
||||
->where('id !=',$post_branch_id)
|
||||
->first();
|
||||
|
||||
if($existing_pre_branch)
|
||||
{
|
||||
return $this->respond([
|
||||
'status' => false,
|
||||
'code' => 409,
|
||||
'message' => 'The branch is already mapped with another branch. Please check.',
|
||||
], 409);
|
||||
}
|
||||
}
|
||||
|
||||
$insert = $this->clientBranchModel->update($id, $data);
|
||||
|
||||
|
||||
|
||||
if($post_branch_id && isset($data['pre_branch_id']) && !empty($data['pre_branch_id']))
|
||||
{
|
||||
// need to update the client_branch in the pre
|
||||
$result = $this->updatePreClientBranch($data['pre_branch_id'],$post_branch_id , "update");
|
||||
|
||||
log_message('error','Pre client_branch update result for pre_branch_id '.$data['pre_branch_id'].' and post_branch_id '.$post_branch_id.' is '.json_encode($result));
|
||||
}
|
||||
|
||||
|
||||
$this->myLogger->logme('error', 'Client branch EDITED by {data}', ['data' => get_session_userid()]);
|
||||
|
||||
|
||||
if ($insert) {
|
||||
|
||||
$level_contact_data = $this->request->getPost('level_contect_data');
|
||||
$level_contact_data = !empty($level_contact_data) ? json_decode($level_contact_data, true) : null;
|
||||
$this->saveLevelContacts($level_contact_data, $id);
|
||||
}
|
||||
|
||||
if ($insert) {
|
||||
$branchData = $this->clientBranchModel->where('client_id', $client_id)->findAll();
|
||||
return $this->respond([
|
||||
'status' => true,
|
||||
'code' => 200,
|
||||
'data' => $branchData,
|
||||
'emp_unit_count' => $emp_unit_count,
|
||||
'rr_unit_count' => $rr_unit_count,
|
||||
'list_of_branch_units' => $list_of_branch_units,
|
||||
'total_count' => $total_count,
|
||||
'uncommonValues' => $uncommonValues,
|
||||
'message' => 'Client branch updated successfully',
|
||||
'response_data' => $this->request->getPost()
|
||||
|
||||
], 200);
|
||||
} else {
|
||||
return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to update client branch'], 200);
|
||||
}
|
||||
}
|
||||
|
||||
public function saveLevelContacts($level_contact_data, $branch_id)
|
||||
{
|
||||
if (!empty($level_contact_data) && is_array($level_contact_data)) {
|
||||
|
||||
@ -606,6 +606,7 @@ class EmployeeRestController extends AdminController
|
||||
public function getEmployeeAndDependenceByClientId()
|
||||
{
|
||||
try {
|
||||
|
||||
$empData = $this->employeePolicyModel->getEmployeePolicy(client_id: $this->request->getGet('client_id'), policy_id: $this->request->getGet('client_policy_id'), status: 0, branch_id: $this->request->getGet('client_branch_id'));
|
||||
|
||||
if ($empData) {
|
||||
@ -4526,11 +4527,12 @@ class EmployeeRestController extends AdminController
|
||||
|
||||
$post_data = [
|
||||
'client_id' => $this->request->getPost('client_id') ?? null,
|
||||
'client_branch_id' => $this->request->getPost('client_branch_id'),
|
||||
'policy_id' => $this->request->getPost('policy_id'),
|
||||
'file_action' => $this->request->getPost('file_action'),
|
||||
'created_by' => $this->request->getPost('created_by'),
|
||||
'file_name' => $this->request->getFile('file_name')
|
||||
'client_branch_id' => $this->request->getPost('client_branch_id') ?? null,
|
||||
'policy_id' => $this->request->getPost('policy_id') ?? null,
|
||||
'file_action' => $this->request->getPost('file_action') ?? null,
|
||||
'created_by' => $this->request->getPost('created_by') ?? null,
|
||||
'file_name' => $this->request->getFile('file_name') ?? null,
|
||||
'policy_no' => $this->request->getPost('policy_no') ?? null,
|
||||
];
|
||||
// print_r($post_data); die;
|
||||
|
||||
@ -4722,28 +4724,40 @@ class EmployeeRestController extends AdminController
|
||||
try {
|
||||
|
||||
$file_id = $this->request->getGet('id') ?? $id;
|
||||
$client_id = $this->request->getGet('cliend_id') ?? null;
|
||||
|
||||
$client_data = [];
|
||||
if(!empty($client_id)){
|
||||
if (is_string($client_id) && preg_match('/^[a-f0-9]{32}$/i', $client_id)) {
|
||||
$client_data = $this->clientModel->where('MD5(id)', $client_id)->first();
|
||||
} else {
|
||||
$client_data = $this->clientModel->where('id', $client_id)->first();
|
||||
}
|
||||
}
|
||||
|
||||
// Find record
|
||||
$record = $this->hrFileUploadModel->where('id', (int)$file_id)->find();
|
||||
|
||||
// print_rr( $record);die;
|
||||
if($client_data && $client_data['hr_file_processed_by'] == 1){
|
||||
$record = $this->fileModel->where('id', (int)$file_id)->find();
|
||||
$uploadPath = WRITEPATH . 'uploads/excel/';
|
||||
}else{
|
||||
$record = $this->hrFileUploadModel->where('id', (int)$file_id)->find();
|
||||
$uploadPath = WRITEPATH . 'uploads/hr_files/';
|
||||
}
|
||||
|
||||
if (!$record) {
|
||||
return $this->failNotFound("File record not found");
|
||||
}
|
||||
|
||||
$uploadPath = WRITEPATH . 'uploads/hr_files/';
|
||||
$filePath = $uploadPath . $record[0]['file_name'];
|
||||
$filePath = $uploadPath . $record[0]['file_name'];
|
||||
|
||||
if (!file_exists($filePath)) {
|
||||
// return $this->failNotFound("File not found on server");
|
||||
$data['message'] = 'The Physical File Not Found';
|
||||
return view('errors/404', $data);
|
||||
return $this->failNotFound("File not found on server");
|
||||
}
|
||||
|
||||
// Force file download
|
||||
return $this->response->download($filePath, null)
|
||||
->setFileName($record[0]['file_name']);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError($e->getMessage());
|
||||
}
|
||||
@ -4802,7 +4816,14 @@ class EmployeeRestController extends AdminController
|
||||
$data = $this->getDataFromHrFileUploadTable($search_data);
|
||||
$table = "hr_file_upload";
|
||||
}else{
|
||||
$client_data = $this->clientModel->where('MD5(id)', $search_data['client_id'])->first();
|
||||
|
||||
if (is_string($search_data['client_id']) && preg_match('/^[a-f0-9]{32}$/i', $search_data['client_id'])) {
|
||||
$client_data = $this->clientModel->where('MD5(id)', $search_data['client_id'])->first();
|
||||
$search_data['client_id'] = $client_data['id'];
|
||||
} else {
|
||||
$client_data = $this->clientModel->where('id', $search_data['client_id'])->first();
|
||||
}
|
||||
|
||||
if($client_data['hr_file_processed_by'] == 1){
|
||||
$data = $this->getDataFromHrFilesTable($search_data);
|
||||
$table = "files";
|
||||
@ -5453,7 +5474,7 @@ class EmployeeRestController extends AdminController
|
||||
// 'dashboard' => 1
|
||||
'dashboard' => 2
|
||||
],
|
||||
'params' => (object)['client_policy_id' => $received_data['client_policy_id']], // MUST be object for Metabase
|
||||
'params' => (object)['client_policy' => $received_data['client_policy_id']], // MUST be object for Metabase
|
||||
'exp' => time() + (10 * 60) // 10 minutes
|
||||
];
|
||||
|
||||
|
||||
@ -996,7 +996,7 @@ class TestingController extends BaseController
|
||||
// 'dashboard' => 1
|
||||
'dashboard' => 2
|
||||
],
|
||||
'params' => (object)['client_policy' => 108], // MUST be object for Metabase
|
||||
'params' => (object)['client_policy' => 4687], // MUST be object for Metabase
|
||||
'exp' => time() + (10 * 60) // 10 minutes
|
||||
];
|
||||
// dd($payload);
|
||||
|
||||
@ -93,7 +93,9 @@ class TicketMasterModel extends Model
|
||||
'required_docs',
|
||||
'policy_transaction_id',
|
||||
'tpa_claim_type',
|
||||
'tpa_ailments'
|
||||
'claim_dump_ref_id',
|
||||
|
||||
];
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user