CHANGE_Pre_app_having_post_branch_id - VADIVEL J 2025-09-10
This commit is contained in:
parent
3d38917e16
commit
2867ed7535
@ -877,7 +877,29 @@ class ClientController extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data['created_by'] = get_session_userid();
|
$data['created_by'] = get_session_userid();
|
||||||
|
|
||||||
|
// before updating check if post_branch_id is already existing in the current db
|
||||||
|
|
||||||
|
if(isset($data['post_branch_id']) && !empty($data['post_branch_id']))
|
||||||
|
{
|
||||||
|
$existing_pre_branch = $this->clientBranchModel
|
||||||
|
->where('post_branch_id',$data['post_branch_id'])
|
||||||
|
// ->where('id !=',$pre_branch_id)
|
||||||
|
->where('is_active',1)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if($existing_pre_branch)
|
||||||
|
{
|
||||||
|
return $this->respond([
|
||||||
|
'status' => false,
|
||||||
|
'code' => 409,
|
||||||
|
'message' => 'The pre branch id '.$data['pre_branch_id'].' is already mapped with another branch. Please check.',
|
||||||
|
], 409);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$insert = $this->clientBranchModel->insert($data);
|
$insert = $this->clientBranchModel->insert($data);
|
||||||
|
$pre_branch_id = $insert;
|
||||||
|
|
||||||
if ($insert) {
|
if ($insert) {
|
||||||
$level_contact_data = $this->request->getPost('level_contect_data');
|
$level_contact_data = $this->request->getPost('level_contect_data');
|
||||||
@ -885,6 +907,16 @@ class ClientController extends AdminController
|
|||||||
$this->saveLevelContacts($level_contact_data, $insert);
|
$this->saveLevelContacts($level_contact_data, $insert);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($pre_branch_id && isset($data['post_branch_id']) && !empty($data['post_branch_id']))
|
||||||
|
{
|
||||||
|
// need to update the client_branch in the pre
|
||||||
|
$result = $this->updatePostClientBranch($data['post_branch_id'],$pre_branch_id , "create");
|
||||||
|
|
||||||
|
log_message('error','Post client_branch update result for post_branch_id '.$data['post_branch_id'].' and pre_branch_id '.$pre_branch_id.' is '.json_encode($result));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// if ($insert) {
|
// if ($insert) {
|
||||||
// for ($i = 0; $i < count($this->request->getPost('name')); $i++) {
|
// for ($i = 0; $i < count($this->request->getPost('name')); $i++) {
|
||||||
// // Prepare data to insert
|
// // Prepare data to insert
|
||||||
@ -925,7 +957,11 @@ class ClientController extends AdminController
|
|||||||
$this->myLogger->logme('error', 'Client branch EDIT function called');
|
$this->myLogger->logme('error', 'Client branch EDIT function called');
|
||||||
$id = $this->request->getPost('branch_id_primarykey');
|
$id = $this->request->getPost('branch_id_primarykey');
|
||||||
$client_id = $this->request->getPost('client_id');
|
$client_id = $this->request->getPost('client_id');
|
||||||
|
$post_branch_id = $this->request->getPost('post_branch_id') ?? "";
|
||||||
|
|
||||||
$data = $this->request->getPost();
|
$data = $this->request->getPost();
|
||||||
|
$data['post_branch_id'] = $post_branch_id;
|
||||||
|
|
||||||
$units = $this->request->getPost('units');
|
$units = $this->request->getPost('units');
|
||||||
|
|
||||||
$emp_unit_count = 0;
|
$emp_unit_count = 0;
|
||||||
@ -984,7 +1020,44 @@ class ClientController extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data['updated_by'] = get_session_userid();
|
$data['updated_by'] = get_session_userid();
|
||||||
|
|
||||||
|
$pre_branch_id = $id;
|
||||||
|
|
||||||
|
// before updating check if post_branch_id is already existing in the current db
|
||||||
|
|
||||||
|
if(isset($data['post_branch_id']) && !empty($data['post_branch_id']))
|
||||||
|
{
|
||||||
|
$existing_pre_branch = $this->clientBranchModel
|
||||||
|
->where('post_branch_id',$data['post_branch_id'])
|
||||||
|
->where('id !=',$pre_branch_id)
|
||||||
|
->where('is_active',1)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if($existing_pre_branch)
|
||||||
|
{
|
||||||
|
return $this->respond([
|
||||||
|
'status' => false,
|
||||||
|
'code' => 409,
|
||||||
|
'message' => 'The pre branch id '.$data['pre_branch_id'].' is already mapped with another branch. Please check.',
|
||||||
|
], 409);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$insert = $this->clientBranchModel->update($id, $data);
|
$insert = $this->clientBranchModel->update($id, $data);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if($pre_branch_id && isset($data['post_branch_id']) && !empty($data['post_branch_id']))
|
||||||
|
{
|
||||||
|
// need to update the client_branch in the post
|
||||||
|
$result = $this->updatePostClientBranch($data['post_branch_id'],$pre_branch_id , "update");
|
||||||
|
|
||||||
|
log_message('error','Post client_branch update result for post_branch_id '.$data['post_branch_id'].' and pre_branch_id '.$pre_branch_id.' is '.json_encode($result));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->myLogger->logme('error', 'Client branch EDITED by {data}', ['data' => get_session_userid()]);
|
$this->myLogger->logme('error', 'Client branch EDITED by {data}', ['data' => get_session_userid()]);
|
||||||
|
|
||||||
if ($insert) {
|
if ($insert) {
|
||||||
@ -5209,6 +5282,29 @@ class ClientController extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function updatePostClientBranch($post_branch_id,$pre_branch_id , $operation){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$postDB = \Config\Database::connect('postDB');
|
||||||
|
|
||||||
|
if($operation != 'create'){
|
||||||
|
|
||||||
|
$builder = $postDB->table('client_branch');
|
||||||
|
$builder->where('pre_branch_id', $pre_branch_id);
|
||||||
|
$builder->update(['pre_branch_id' => null]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$builder = $postDB->table('client_branch');
|
||||||
|
$builder->where('id', $post_branch_id);
|
||||||
|
$builder->update(['pre_branch_id' => $pre_branch_id]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -91,10 +91,14 @@
|
|||||||
|
|
||||||
|
|
||||||
<input type="hidden" class="form-control" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
|
<input type="hidden" class="form-control" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
|
||||||
|
|
||||||
|
<!-- pre_client_id as client_id -->
|
||||||
<input type="hidden" name="client_id" id="client_id_branch"
|
<input type="hidden" name="client_id" id="client_id_branch"
|
||||||
value="<?= isset($client['id']) ? $client['id'] : '' ?>" />
|
value="<?= isset($client['id']) ? $client['id'] : '' ?>" />
|
||||||
|
<!-- post_branch_id -->
|
||||||
<input type="hidden" name="post_branch_id" id="post_branch_id"
|
<input type="hidden" name="post_branch_id" id="post_branch_id"
|
||||||
value="<?= isset($post_branch_id) ? $post_branch_id : '' ?>" />
|
value="<?= isset($post_branch_id) ? $post_branch_id : '' ?>" />
|
||||||
|
<!-- pre_branch_id as branch_id_primarykey -->
|
||||||
<input type="hidden" name="branch_id_primarykey" id="branch_id_primarykey" />
|
<input type="hidden" name="branch_id_primarykey" id="branch_id_primarykey" />
|
||||||
|
|
||||||
|
|
||||||
@ -379,7 +383,7 @@ $("#branch_form").submit(function(event) {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
branch_PrimaryKey = $('#client_id_branch').val();
|
branch_PrimaryKey = $('#client_id_branch').val();
|
||||||
|
|
||||||
console.log('branch_PrimaryKey', branch_PrimaryKey)
|
console.log('branch_PrimaryKey', branch_PrimaryKey);
|
||||||
|
|
||||||
if (branch_PrimaryKey === '') {
|
if (branch_PrimaryKey === '') {
|
||||||
toastr.error('Client is required', 'Error');
|
toastr.error('Client is required', 'Error');
|
||||||
@ -488,6 +492,10 @@ $("#branch_form").submit(function(event) {
|
|||||||
$('.loader').fadeOut();
|
$('.loader').fadeOut();
|
||||||
$('.loader-mask').delay(350).fadeOut('slow');
|
$('.loader-mask').delay(350).fadeOut('slow');
|
||||||
console.log('Something Wrong!', 'warning');
|
console.log('Something Wrong!', 'warning');
|
||||||
|
if(xhr.status == 409){
|
||||||
|
alert('The Current Branch is Already Existing..!!');
|
||||||
|
}
|
||||||
|
|
||||||
}, 300);
|
}, 300);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user