From 88aedee6fb21a624e0efae8691439e12388c3556 Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Mon, 6 Oct 2025 18:35:47 +0530 Subject: [PATCH] CHANGE_Pre_app_having_post_branch_id - VADIVEL J 2025-09-06 --- app/Controllers/ClientController.php | 45 ++++++++++++++++++++++++---- app/Views/client_branch.php | 1 + 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 34830575..bf8f9438 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -801,6 +801,8 @@ class ClientController extends AdminController $editData['api_data'] = $this->clientApi->where("client_id", $id)->where("is_active", 1)->first(); // dd($editData); + $edit['pre_branch_id'] = $this->clientBranchModel->select('pre_branch_id')->where('client_id',$id)->get()->getResultArray()[0]['pre_branch_id']??""; + $editData['auto_fetch_client_list'] = $this->getClientListFromPre(); @@ -6856,7 +6858,15 @@ class ClientController extends AdminController return $combinedHrAccessData; } - $pre_client_data = $db2->table('clients')->where('is_active', 1)->where('short_name', $post_client_data['short_name'])->get()->getRowArray(); + $post_branch = $this->clientBranchModel->select('pre_branch_id')->where('client_id',$client_id)->get()->getResultArray()[0]??[]; + + $pre_client_data = $db2->table('client_branch cb') + ->join('clients c', "c.id = cb.client_id") + ->where('c.is_active',1) + ->where('cb.is_active', 1) + ->where('cb.id', $post_branch['pre_branch_id']??'') + ->get()->getRowArray(); + if (empty($pre_client_data)) { @@ -7092,11 +7102,16 @@ class ClientController extends AdminController $post = array_values(array_filter($allowed_modules, fn($v) => $v !== 1)); $value['allowed_modules'] = json_encode(['pre' => $pre, 'post' => $post]); + $post_client_id = $value['post_client_id']; + $post_branch_id = $value['post_branch_id']; + $post_hr_id = $value['post_hr_id']; + + $value['pre_client_id'] = $this->getPreClientId($post_branch_id); + $value['pre_branch_id'] = $this->getPreBranchId($post_branch_id); + $value["pre_hr_id"] = $this->getPreHrId($post_branch_id); + // INSERT or UPDATE if (empty($value['pk']) || (int)$value['pk'] === 0) { - print_rr("inside insert block"); - print_rr($value);die; - unset($value['pk']); // Prevent insert error $insertedId = $this->HRAccessControlModel->insert($value); @@ -7106,8 +7121,6 @@ class ClientController extends AdminController $success[] = "Inserted row at index {$index} with ID {$insertedId}."; } else { $update = $this->HRAccessControlModel->update($value['pk'], $value); - print_rr("inside update block"); - print_rr($value);die; if ($update === false) { throw new \Exception('Update failed for ID ' . $value['pk'] . ': ' . json_encode($this->HRAccessControlModel->errors())); @@ -7162,6 +7175,26 @@ class ClientController extends AdminController } } + private function getPreClientId($post_branch_id){ + $db2 = \Config\Database::connect('preDB'); + $pre_client_id = $db2->table('client_branch')->where('post_branch_id',$post_branch_id)->where('is_Active',1)->get()->getResultArray()[0]['client_id']??[]; + return $pre_client_id; + } + + private function getPreBranchId($post_branch_id){ + $db2 = \Config\Database::connect('preDB'); + $pre_branch_id = $db2->table('client_branch')->where('post_branch_id',$post_branch_id)->where('is_Active',1)->get()->getResultArray()[0]['id']??[]; + return $pre_branch_id; + } + private function getPreHrId($post_branch_id){ + $db2 = \Config\Database::connect('preDB'); + $pre_hr_id = $db2->table('client_branch cb') + ->select('lc.id') + ->join('level_contacts lc','lc.ref_id = cb.id') + ->where('post_branch_id',$post_branch_id)->where('is_Active',1)->get()->getResultArray()[0]['id']??[]; + return $pre_hr_id; + } + // ------------------- DEMO CLIENT FUNCTION -------------------------------------------------------------------------------- public function wipeDemoClient() diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php index 5db4a112..940cf017 100755 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -546,6 +546,7 @@ $('body').on('click', '.btnBranchEdit', function() { $('#district').val(res.data.district); $('#branch_city').val(res.data.city); $('#branch_PrimaryKey').val(res.data.id); + $('#pre_branch_id').val(res.data.pre_branch_id) if(res.data.sez == 1){ $('#sez').prop('checked', true);