CHANGE_Pre_app_having_post_branch_id - VADIVEL J 2025-09-06

This commit is contained in:
vadivelJ96 2025-10-06 18:35:47 +05:30
parent 0084e8be96
commit 88aedee6fb
2 changed files with 40 additions and 6 deletions

View File

@ -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()

View File

@ -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);