CHANGE_Post_app_having_pre_branch_id - VADIVEL J 2025-09-10
This commit is contained in:
parent
6914c0d928
commit
3e13091b34
@ -700,6 +700,7 @@ $routes->group('test', function($routes) {
|
|||||||
$routes->get('viewrfq', 'TestingController::viewRFQNonEb');
|
$routes->get('viewrfq', 'TestingController::viewRFQNonEb');
|
||||||
$routes->get('exportexcel', 'TestingController::exportExcel');
|
$routes->get('exportexcel', 'TestingController::exportExcel');
|
||||||
$routes->post('saverfq', 'TestingController::saverfq');
|
$routes->post('saverfq', 'TestingController::saverfq');
|
||||||
|
$routes->get('mapping_client_id_and_branch_id','TestingController::mapping_client_id_and_branch_id');
|
||||||
});
|
});
|
||||||
$routes->cli('cli/testcli', 'TestingController::testcli');
|
$routes->cli('cli/testcli', 'TestingController::testcli');
|
||||||
|
|
||||||
|
|||||||
@ -1098,14 +1098,47 @@ class ClientController extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data['created_by'] = get_session_userid();
|
$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 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);
|
||||||
|
|
||||||
|
$post_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');
|
||||||
$level_contact_data = !empty($level_contact_data) ? json_decode($level_contact_data, true) : null;
|
$level_contact_data = !empty($level_contact_data) ? json_decode($level_contact_data, true) : null;
|
||||||
$this->saveLevelContacts($level_contact_data, $insert);
|
$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) {
|
if ($insert) {
|
||||||
$branchData = $this->clientBranchModel->where('client_id', $this->request->getPost('client_id'))->findAll();
|
$branchData = $this->clientBranchModel->where('client_id', $this->request->getPost('client_id'))->findAll();
|
||||||
$branchData['role'] = get_role_id();
|
$branchData['role'] = get_role_id();
|
||||||
@ -1130,7 +1163,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');
|
||||||
|
$pre_branch_id = $this->request->getPost('pre_branch_id') ?? '';
|
||||||
|
|
||||||
$data = $this->request->getPost();
|
$data = $this->request->getPost();
|
||||||
|
$data['pre_branch_id'] = $pre_branch_id;
|
||||||
|
|
||||||
$units = $this->request->getPost('units');
|
$units = $this->request->getPost('units');
|
||||||
|
|
||||||
$emp_unit_count = 0;
|
$emp_unit_count = 0;
|
||||||
@ -1189,7 +1226,41 @@ class ClientController extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data['updated_by'] = get_session_userid();
|
$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 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($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()]);
|
$this->myLogger->logme('error', 'Client branch EDITED by {data}', ['data' => get_session_userid()]);
|
||||||
|
|
||||||
|
|
||||||
@ -7107,9 +7178,15 @@ class ClientController extends AdminController
|
|||||||
$post_branch_id = $value['post_branch_id'];
|
$post_branch_id = $value['post_branch_id'];
|
||||||
$post_hr_id = $value['post_hr_id'];
|
$post_hr_id = $value['post_hr_id'];
|
||||||
|
|
||||||
$value['pre_client_id'] = $this->getPreClientId($post_branch_id);
|
$preBranchId = $this->getPreBranchIdByPostBranchId($post_branch_id);
|
||||||
$value['pre_branch_id'] = $this->getPreBranchId($post_branch_id);
|
|
||||||
$value["pre_hr_id"] = $this->getPreHrId($post_branch_id);
|
if (!empty($preBranchId)) {
|
||||||
|
$value['pre_branch_id'] = $preBranchId;
|
||||||
|
$value['pre_client_id'] = $this->getPreClientIdByPreBranchId($preBranchId);
|
||||||
|
$value["pre_hr_id"] = $this->getPreHrIdByPreBranchId($preBranchId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// INSERT or UPDATE
|
// INSERT or UPDATE
|
||||||
if (empty($value['pk']) || (int)$value['pk'] === 0) {
|
if (empty($value['pk']) || (int)$value['pk'] === 0) {
|
||||||
@ -7176,26 +7253,28 @@ class ClientController extends AdminController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPreClientId($post_branch_id){
|
private function getPreClientIdByPreBranchId($pre_branch_id){
|
||||||
$db2 = \Config\Database::connect('preDB');
|
$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']??[];
|
$pre_client_id = $db2->table('client_branch')->where('id',$pre_branch_id)->where('is_Active',1)->get()->getResultArray()[0]['client_id']??"";
|
||||||
return $pre_client_id;
|
return $pre_client_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPreBranchId($post_branch_id){
|
private function getPreHrIdByPreBranchId($pre_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');
|
$db2 = \Config\Database::connect('preDB');
|
||||||
$pre_hr_id = $db2->table('client_branch cb')
|
$pre_hr_id = $db2->table('client_branch cb')
|
||||||
->select('lc.id')
|
->select('lc.id')
|
||||||
->join('level_contacts lc','lc.ref_id = cb.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']??[];
|
->where('cb.id',$pre_branch_id)->where('cb.is_Active',1)->where('lc.is_Active',1)->get()->getResultArray()[0]['id']??"";
|
||||||
return $pre_hr_id;
|
return $pre_hr_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getPreBranchIdByPostBranchId($post_branch_id){
|
||||||
|
$db2 = \Config\Database::connect();
|
||||||
|
$pre_branch_id = $db2->table('client_branch')->where('id',$post_branch_id)->where('is_Active',1)->get()->getResultArray()[0]['pre_branch_id']??"";
|
||||||
|
return $pre_branch_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ------------------- DEMO CLIENT FUNCTION --------------------------------------------------------------------------------
|
// ------------------- DEMO CLIENT FUNCTION --------------------------------------------------------------------------------
|
||||||
|
|
||||||
public function wipeDemoClient()
|
public function wipeDemoClient()
|
||||||
@ -7584,6 +7663,26 @@ class ClientController extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function updatePreClientBranch($pre_branch_id,$post_branch_id ,$operation)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$preDB = \Config\Database::connect('preDB');
|
||||||
|
|
||||||
|
if($operation != 'create'){
|
||||||
|
|
||||||
|
$builder = $preDB->table('client_branch');
|
||||||
|
$builder->where('post_branch_id', $post_branch_id);
|
||||||
|
$builder->update(['post_branch_id' => null]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$builder = $preDB->table('client_branch');
|
||||||
|
$builder->where('id', $pre_branch_id);
|
||||||
|
$builder->update(['post_branch_id' => $post_branch_id]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -236,10 +236,10 @@ class TestingController extends BaseController
|
|||||||
->where('employees.emp_code', $emp_code)
|
->where('employees.emp_code', $emp_code)
|
||||||
->groupBy('employee_polices.client_policy_id')
|
->groupBy('employee_polices.client_policy_id')
|
||||||
->findAll();
|
->findAll();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ptedfitdata($id){
|
public function ptedfitdata($id)
|
||||||
|
{
|
||||||
$policy_transaction = new PolicyTransactionController();
|
$policy_transaction = new PolicyTransactionController();
|
||||||
$data = $policy_transaction->getInceptionDataForEdit($id);
|
$data = $policy_transaction->getInceptionDataForEdit($id);
|
||||||
// dd($data);
|
// dd($data);
|
||||||
@ -323,7 +323,8 @@ class TestingController extends BaseController
|
|||||||
return $this->loadLayout('view_rfq_non_eb_new', $data);
|
return $this->loadLayout('view_rfq_non_eb_new', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saverfq(){
|
public function saverfq()
|
||||||
|
{
|
||||||
$json = $this->request->getPost('json');
|
$json = $this->request->getPost('json');
|
||||||
$json = json_encode($json);
|
$json = json_encode($json);
|
||||||
print_r($json);
|
print_r($json);
|
||||||
@ -342,8 +343,147 @@ class TestingController extends BaseController
|
|||||||
// print_rr($policy_data['json']); die;
|
// print_rr($policy_data['json']); die;
|
||||||
$policy_data = json_decode($policy_data['json'], true);
|
$policy_data = json_decode($policy_data['json'], true);
|
||||||
$policy_data = array_slice($policy_data, 0, -2);
|
$policy_data = array_slice($policy_data, 0, -2);
|
||||||
print_rr($policy_data); die;
|
print_rr($policy_data);
|
||||||
|
die;
|
||||||
dd($policy_data);
|
dd($policy_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function mapping_client_id_and_branch_id()
|
||||||
|
{
|
||||||
|
|
||||||
|
$post_clients_list = $this->getNonDuplicatePostClients();
|
||||||
|
|
||||||
|
$pre_clients_list = $this->getNonDuplicatePreClients();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (
|
||||||
|
!empty($pre_clients_list) &&
|
||||||
|
!empty($post_clients_list)
|
||||||
|
) {
|
||||||
|
|
||||||
|
$postDB = \Config\Database::connect();
|
||||||
|
$preDB = \Config\Database::connect('preDB');
|
||||||
|
|
||||||
|
foreach ($post_clients_list as $post_client) {
|
||||||
|
|
||||||
|
foreach ($pre_clients_list as $pre_client) {
|
||||||
|
|
||||||
|
if (trim($post_client['short_name']) == trim($pre_client['short_name'])) {
|
||||||
|
|
||||||
|
$postDB->table('clients')->where('id', $post_client['id'])->update(['pre_client_id' => $pre_client['id']]);
|
||||||
|
|
||||||
|
$preDB->table('clients')->where('id', $pre_client['id'])->update(['post_client_id' => $post_client['id']]);
|
||||||
|
|
||||||
|
// upto here we updated client_id in both dbs.
|
||||||
|
|
||||||
|
$post_branches = $postDB->table('client_branch')
|
||||||
|
->where('client_id', $post_client['id'])
|
||||||
|
->get()
|
||||||
|
->getResultArray() ?? [];
|
||||||
|
|
||||||
|
$pre_branches = $preDB->table('client_branch')
|
||||||
|
->where('client_id', $pre_client['id'])
|
||||||
|
->get()
|
||||||
|
->getResultArray() ?? [];
|
||||||
|
|
||||||
|
if (!empty($post_branches) && !empty($pre_branches)) {
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($post_branches as $post_branch) {
|
||||||
|
|
||||||
|
$pre_branch = $preDB->table('client_branch')
|
||||||
|
->where('client_id', $pre_client['id'])
|
||||||
|
->where('branch_code', $post_branch['branch_code'])
|
||||||
|
->get()
|
||||||
|
->getRowArray() ?? [];
|
||||||
|
|
||||||
|
if (!empty($pre_branch)) {
|
||||||
|
$postDB->table('client_branch')->where('id', $post_branch['id'])->update(['pre_branch_id' => $pre_branch['id']]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($pre_branches as $pre_branch) {
|
||||||
|
|
||||||
|
$post_branch = $postDB->table('client_branch')
|
||||||
|
->where('client_id', $post_client['id'])
|
||||||
|
->where('branch_code', $pre_branch['branch_code'])
|
||||||
|
->get()
|
||||||
|
->getRowArray() ?? [];
|
||||||
|
|
||||||
|
if (!empty($post_branch)) {
|
||||||
|
$preDB->table('client_branch')->where('id', $pre_branch['id'])->update(['post_branch_id' => $post_branch['id']]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function getNonDuplicatePostClients()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
$postDB = \Config\Database::connect();
|
||||||
|
|
||||||
|
$sql = "SELECT *
|
||||||
|
FROM clients AS post_clients
|
||||||
|
WHERE post_clients.client_type = 1
|
||||||
|
AND post_clients.is_active = 1
|
||||||
|
AND (post_clients.short_name NOT IN
|
||||||
|
(
|
||||||
|
SELECT ir_post_clients.short_name
|
||||||
|
FROM clients as ir_post_clients
|
||||||
|
WHERE ir_post_clients.client_type = 1
|
||||||
|
AND ir_post_clients.short_name IS NOT NULL
|
||||||
|
AND TRIM(ir_post_clients.short_name) <> ''
|
||||||
|
AND ir_post_clients.is_active = 1
|
||||||
|
GROUP BY ir_post_clients.short_name
|
||||||
|
HAVING COUNT(*) > 1)
|
||||||
|
)
|
||||||
|
ORDER BY post_clients.short_name";
|
||||||
|
|
||||||
|
$binds = [];
|
||||||
|
|
||||||
|
$query = $postDB->query($sql, $binds);
|
||||||
|
|
||||||
|
$results = $query->getResultArray() ?? [];
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getNonDuplicatePreClients()
|
||||||
|
{
|
||||||
|
|
||||||
|
$preDB = \Config\Database::connect('preDB');
|
||||||
|
|
||||||
|
$sql = "SELECT *
|
||||||
|
FROM clients AS pre_clients
|
||||||
|
WHERE pre_clients.client_type = 1
|
||||||
|
AND pre_clients.is_active = 1
|
||||||
|
AND (pre_clients.short_name NOT IN
|
||||||
|
(
|
||||||
|
SELECT ir_pre_clients.short_name
|
||||||
|
FROM clients as ir_pre_clients
|
||||||
|
WHERE ir_pre_clients.client_type = 1
|
||||||
|
AND ir_pre_clients.short_name IS NOT NULL
|
||||||
|
AND TRIM(ir_pre_clients.short_name) <> ''
|
||||||
|
AND ir_pre_clients.is_active = 1
|
||||||
|
GROUP BY ir_pre_clients.short_name
|
||||||
|
HAVING COUNT(*) > 1)
|
||||||
|
)
|
||||||
|
ORDER BY pre_clients.short_name";
|
||||||
|
|
||||||
|
$binds = [];
|
||||||
|
|
||||||
|
$query = $preDB->query($sql, $binds);
|
||||||
|
|
||||||
|
$results = $query->getResultArray() ?? [];
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,13 +86,18 @@
|
|||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<form role="form" class="parsley-examples" method="post" id="branch_form" enctype="multipart/form-data">
|
<form role="form" class="parsley-examples" method="post" id="branch_form" enctype="multipart/form-data">
|
||||||
|
|
||||||
|
|
||||||
<input type="hidden" class="form-control" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
|
<input type="hidden" class="form-control" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
|
||||||
|
|
||||||
|
|
||||||
|
<!-- post_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'] : '' ?>" />
|
||||||
|
<!-- pre_branch_id -->
|
||||||
<input type="hidden" name="pre_branch_id" id="pre_branch_id"
|
<input type="hidden" name="pre_branch_id" id="pre_branch_id"
|
||||||
value="<?= isset($pre_branch_id) ? $pre_branch_id : '' ?>" />
|
value="<?= isset($pre_branch_id) ? $pre_branch_id : '' ?>" />
|
||||||
|
<!-- post_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" />
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@ -479,6 +484,9 @@ $("#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);
|
||||||
},
|
},
|
||||||
complete: function() {
|
complete: function() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user