FIX_ClientBranch
This commit is contained in:
parent
2308a77179
commit
8b6cc7544c
@ -1831,6 +1831,7 @@ class ClientController extends AdminController
|
|||||||
|
|
||||||
$this->myLogger->logme('error', 'Client branch EDIT function called');
|
$this->myLogger->logme('error', 'Client branch EDIT function called');
|
||||||
$data = $this->request->getPost();
|
$data = $this->request->getPost();
|
||||||
|
|
||||||
$sanitized_post_data = sanitizeInputArrayAdvanced($data);
|
$sanitized_post_data = sanitizeInputArrayAdvanced($data);
|
||||||
$id = $sanitized_post_data['branch_id_primarykey'] ?? null;
|
$id = $sanitized_post_data['branch_id_primarykey'] ?? null;
|
||||||
$client_id = $sanitized_post_data['client_id'] ?? null;
|
$client_id = $sanitized_post_data['client_id'] ?? null;
|
||||||
@ -1838,7 +1839,7 @@ class ClientController extends AdminController
|
|||||||
|
|
||||||
$data['pre_branch_id'] = $pre_branch_id;
|
$data['pre_branch_id'] = $pre_branch_id;
|
||||||
|
|
||||||
$units = $sanitized_post_data['units'] ?? null;
|
$raw_units = $this->request->getPost('units');
|
||||||
|
|
||||||
$emp_unit_count = 0;
|
$emp_unit_count = 0;
|
||||||
$rr_unit_count = 0;
|
$rr_unit_count = 0;
|
||||||
@ -1846,12 +1847,13 @@ class ClientController extends AdminController
|
|||||||
$total_count = 0;
|
$total_count = 0;
|
||||||
|
|
||||||
$list_of_branch_units = $this->clientBranchModel->find((int)$id);
|
$list_of_branch_units = $this->clientBranchModel->find((int)$id);
|
||||||
$units = json_decode($list_of_branch_units['units']);
|
$units = !empty($list_of_branch_units['units']) ? json_decode($list_of_branch_units['units'], true) : [];
|
||||||
|
|
||||||
if (!is_array($units) || empty($units)) {
|
if (!is_array($units) || empty($units)) {
|
||||||
$client_data = $this->clientModel->where('id', $sanitized_post_data['client_id'])->first();
|
$client_data = $this->clientModel->where('id', $sanitized_post_data['client_id'])->first();
|
||||||
$default_unit = trim(($client_data['short_name'] ?? '') . '-' . ($sanitized_post_data['branch_code'] ?? ''), '-');
|
$default_unit = trim(($client_data['short_name'] ?? '') . '-' . ($sanitized_post_data['branch_code'] ?? ''), '-');
|
||||||
$sanitized_post_data['units'] = json_encode([$default_unit]);
|
$sanitized_post_data['units'] = json_encode([$default_unit]);
|
||||||
|
$units = [$default_unit]; // Update local variable for counting
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($units)) {
|
if (!empty($units)) {
|
||||||
@ -1866,17 +1868,21 @@ class ClientController extends AdminController
|
|||||||
|
|
||||||
$uncommonValues = [];
|
$uncommonValues = [];
|
||||||
|
|
||||||
|
|
||||||
if ($total_count > 0) {
|
if ($total_count > 0) {
|
||||||
$units = (string) $sanitized_post_data('units'); // Assuming 'units' is an array
|
|
||||||
|
$post_units_raw = $sanitized_post_data['units'] ?? '[]';
|
||||||
|
|
||||||
$list_of_branch_units = $this->clientBranchModel->find((int)$id);
|
$branch_units = json_decode($list_of_branch_units['units'] ?? '[]', true);
|
||||||
$branch_units = json_decode($list_of_branch_units['units'], true);
|
|
||||||
$units = json_decode($units);
|
// Ensure we handle both string-json and array types
|
||||||
|
$incoming_units = is_array($post_units_raw) ? $post_units_raw : json_decode($post_units_raw, true);
|
||||||
$uncommonValues = array_diff($branch_units, $units);
|
|
||||||
|
if (is_array($branch_units) && is_array($incoming_units)) {
|
||||||
|
$uncommonValues = array_diff($branch_units, $incoming_units);
|
||||||
|
}
|
||||||
|
|
||||||
if (count($uncommonValues) > 0) {
|
if (count($uncommonValues) > 0) {
|
||||||
|
|
||||||
$branchData = $this->clientBranchModel->where('client_id', $client_id)->findAll();
|
$branchData = $this->clientBranchModel->where('client_id', $client_id)->findAll();
|
||||||
|
|
||||||
return $this->respond([
|
return $this->respond([
|
||||||
@ -1888,7 +1894,7 @@ class ClientController extends AdminController
|
|||||||
], 200);
|
], 200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($sanitized_post_data['sez'])) {
|
if (!isset($sanitized_post_data['sez'])) {
|
||||||
$sanitized_post_data['sez'] = 0;
|
$sanitized_post_data['sez'] = 0;
|
||||||
} elseif ($sanitized_post_data['sez']) {
|
} elseif ($sanitized_post_data['sez']) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user