diff --git a/modules/AOW_Actions/actions/actionCreateRecord.php b/modules/AOW_Actions/actions/actionCreateRecord.php index ac5fc88c19b..93c0419ba19 100755 --- a/modules/AOW_Actions/actions/actionCreateRecord.php +++ b/modules/AOW_Actions/actions/actionCreateRecord.php @@ -301,13 +301,13 @@ public function set_record(SugarBean $record, SugarBean $bean, $params = array() case 'Round_Robin': case 'Least_Busy': case 'Random': + $users = array(); switch ($params['value'][$key][0]) { case 'security_group': require_once 'modules/SecurityGroups/SecurityGroup.php'; $security_group = BeanFactory::newBean('SecurityGroups'); $security_group->retrieve($params['value'][$key][1]); $group_users = $security_group->get_linked_beans('users', 'User'); - $users = array(); $r_users = array(); if ($params['value'][$key][2] != '') { require_once 'modules/ACLRoles/ACLRole.php'; @@ -315,6 +315,10 @@ public function set_record(SugarBean $record, SugarBean $bean, $params = array() $role->retrieve($params['value'][$key][2]); $role_users = $role->get_linked_beans('users', 'User'); foreach ($role_users as $role_user) { + if (checkUserStatus($role_user) || checkUserEmployeeStatus($role_user)) { + continue; + } + $r_users[$role_user->id] = $role_user->name; } } @@ -322,6 +326,11 @@ public function set_record(SugarBean $record, SugarBean $bean, $params = array() if ($params['value'][$key][2] != '' && !isset($r_users[$group_user->id])) { continue; } + + if (checkUserStatus($group_user) || checkUserEmployeeStatus($group_user)) { + continue; + } + $users[$group_user->id] = $group_user->name; } break; @@ -330,14 +339,24 @@ public function set_record(SugarBean $record, SugarBean $bean, $params = array() $role = BeanFactory::newBean('ACLRoles'); $role->retrieve($params['value'][$key][2]); $role_users = $role->get_linked_beans('users', 'User'); - $users = array(); foreach ($role_users as $role_user) { + if (checkUserStatus($role_user) || checkUserEmployeeStatus($role_user)) { + continue; + } + $users[$role_user->id] = $role_user->name; } break; case 'all': default: - $users = get_user_array(false); + $temporaryUsers = get_user_array(false); + foreach ($temporaryUsers as $user) { + if (checkUserEmployeeStatus($user)) { + continue; + } + + $users[$user->id] = $user->name; + } break; } diff --git a/modules/AOW_WorkFlow/aow_utils.php b/modules/AOW_WorkFlow/aow_utils.php index a380b340885..9d895331fcb 100755 --- a/modules/AOW_WorkFlow/aow_utils.php +++ b/modules/AOW_WorkFlow/aow_utils.php @@ -851,19 +851,43 @@ function getRoundRobinUser($users, $id) $file = create_cache_directory('modules/AOW_WorkFlow/Users/') . $id . 'lastUser.cache.php'; if (isset($_SESSION['lastuser'][$id]) && $_SESSION['lastuser'][$id] != '') { - $users_by_key = array_flip($users); // now keys are values - $key = $users_by_key[$_SESSION['lastuser'][$id]] + 1; - if (!empty($users[$key])) { - return $users[$key]; - } + $lastUserId = $_SESSION['lastuser'][$id]; + + return getNextUserId($lastUserId, $users); } elseif (is_file($file)) { require_once($file); if (isset($lastUser['User']) && $lastUser['User'] != '') { - $users_by_key = array_flip($users); // now keys are values - $key = $users_by_key[$lastUser['User']] + 1; - if (!empty($users[$key])) { - return $users[$key]; - } + $lastUserId = $lastUser['User']; + + return getNextUserId($lastUserId, $users); + } + } + + return $users[0]; +} + +function checkUserStatus($user): bool +{ + $employeeInactiveStatus = 'Inactive'; + + return $user->status === $employeeInactiveStatus; +} + +function checkUserEmployeeStatus($user): bool +{ + $employeeTerminatedStatus = 'Terminated'; + $employeeAbsenceStatus = 'Leave of Absence'; + + return $user->employee_status === $employeeTerminatedStatus || $user->employee_status === $employeeAbsenceStatus; +} + +function getNextUserId($userId, $users): string +{ + $usersByKey = array_flip($users); + $key = $usersByKey[$userId] + 1; + if ($key < count($usersByKey)) { + if (!empty($users[$key])) { + return $users[$key]; } }