/** * Calculate the extent of utilization of user assignments * @param string hash a hash for the returned hashList * @param array users an array of user_ids calculating their assignment capacity * @return array returns hashList of extent of utilization for assignment of the users */ public function getAllocation($hash = null, $users = null, $get_user_list = false) { /* * TODO: The core of this function has been simplified to always return 100% * free capacity available. The allocation checking (aka resource * management) is a complex subject which is currently not even close to be * handled properly. */ global $AppUI; if (!w2PgetConfig('check_overallocation', false)) { if ($get_user_list) { $users_list = w2PgetUsersHashList(); foreach ($users_list as $key => $user) { $users_list[$key]['userFC'] = $user['contact_name']; } $hash = $users_list; } else { $hash = array(); } } else { $q = new w2p_Database_Query(); // retrieve the systemwide default preference for the assignment maximum $q->addTable('user_preferences'); $q->addQuery('pref_value'); $q->addWhere('pref_user = 0 AND pref_name = \'' . TASKASSIGNMAX . '\''); $sysChargeMax = $q->loadHash(); $q->clear(); if (!$sysChargeMax) { $scm = 0; } else { $scm = $sysChargeMax['pref_value']; } /* * provide actual assignment charge, individual chargeMax * and freeCapacity of users' assignments to tasks */ $q->addTable('users', 'u'); $q->addJoin('contacts', 'c', 'c.contact_id = u.user_contact', 'inner'); $q->leftJoin('user_tasks', 'ut', 'ut.user_id = u.user_id'); $q->leftJoin('user_preferences', 'up', 'up.pref_user = u.user_id'); $q->addWhere("up.pref_name = 'TASKASSIGNMAX'"); $q->addQuery('u.user_id, CONCAT(CONCAT_WS(\' [\', CONCAT_WS(\' \', contact_first_name, contact_last_name), IF(IFNULL((IFNULL(up.pref_value, ' . $scm . ') - SUM(ut.perc_assignment)), up.pref_value) > 0, IFNULL((IFNULL(up.pref_value, ' . $scm . ') - SUM(ut.perc_assignment)), up.pref_value), 0)), \'%]\') AS userFC, IFNULL(SUM(ut.perc_assignment), 0) AS charge'); $q->addQuery('u.user_username, IFNULL(up.pref_value,' . $scm . ') AS chargeMax'); $q->addQuery('IFNULL(up.pref_value, ' . $scm . ') AS freeCapacity'); if (!empty($users)) { // use userlist if available otherwise pull data for all users $q->addWhere('u.user_id IN (' . implode(',', $users) . ')'); } $q->addGroup('u.user_id'); $q->addOrder('contact_first_name, contact_last_name'); // get CCompany() to filter by company $obj = new CCompany(); $companies = $obj->getAllowedSQL($AppUI->user_id, 'company_id'); $q->addJoin('companies', 'com', 'company_id = contact_company'); if ($companies) { $q->addWhere('(' . implode(' OR ', $companies) . ' OR contact_company=\'\' OR contact_company IS NULL OR contact_company = 0)'); } $dpt = new CDepartment(); $depts = $dpt->getAllowedSQL($AppUI->user_id, 'dept_id'); $q->addJoin('departments', 'dep', 'dept_id = contact_department'); if ($depts) { $q->addWhere('(' . implode(' OR ', $depts) . ' OR contact_department=0)'); } $hash = $q->loadHashList($hash); $q->clear(); } return $hash; }
?> /> </td> </tr> </table> </form> <?php if ($do_report) { echo $AppUI->getTheme()->styleRenderBoxBottom(); echo '<br />'; echo $AppUI->getTheme()->styleRenderBoxTop(); echo '<table class="std"> <tr> <td align="center">'; // Let's figure out which users we have $user_list = w2PgetUsersHashList(); if ($log_userfilter != 0) { $user_list = array($log_userfilter => $user_list[$log_userfilter]); } $ss = "'" . $start_date->format(FMT_DATETIME_MYSQL) . "'"; $se = "'" . $end_date->format(FMT_DATETIME_MYSQL) . "'"; $and = false; $where = false; $q = new w2p_Database_Query(); $q->addTable('tasks', 't'); $q->addQuery('t.*'); $q->addJoin('projects', '', 'projects.project_id = task_project', 'inner'); $q->addJoin('project_departments', '', 'project_departments.project_id = projects.project_id'); $q->addJoin('departments', '', 'department_id = dept_id'); $q->addWhere('project_active = 1'); if (($template_status = w2PgetConfig('template_projects_status_id')) != '') {
function getUsersArray() { return w2PgetUsersHashList(); }