From aa8ffdcec75ded579362d1274e985b4b35a9ac95 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Mon, 10 Dec 2018 16:00:40 +0000 Subject: [PATCH] Refactored monthly quota config for subgroups. --- WEB-INF/lib/ttGroup.class.php | 2 +- WEB-INF/lib/ttTimeHelper.class.php | 17 ++++++++++------- WEB-INF/lib/ttUser.class.php | 5 +++++ WEB-INF/templates/footer.tpl | 2 +- plugins/MonthlyQuota.class.php | 19 +++++++++++-------- quotas.php | 4 ++-- 6 files changed, 30 insertions(+), 19 deletions(-) diff --git a/WEB-INF/lib/ttGroup.class.php b/WEB-INF/lib/ttGroup.class.php index 1aa422c7..f85f9097 100644 --- a/WEB-INF/lib/ttGroup.class.php +++ b/WEB-INF/lib/ttGroup.class.php @@ -101,8 +101,8 @@ class ttGroup { $this->currency = $val['currency']; $this->plugins = $val['plugins']; $this->lock_spec = $val['lock_spec']; - /* $this->workday_minutes = $val['workday_minutes']; + /* $this->custom_logo = $val['custom_logo']; */ $this->config = $val['config']; diff --git a/WEB-INF/lib/ttTimeHelper.class.php b/WEB-INF/lib/ttTimeHelper.class.php index 6ddedc45..f48ecc8a 100644 --- a/WEB-INF/lib/ttTimeHelper.class.php +++ b/WEB-INF/lib/ttTimeHelper.class.php @@ -147,9 +147,9 @@ class ttTimeHelper { // Handle localized fractional hours. global $user; - $localizedPattern = '/^(\d{1,3})?['.$user->decimal_mark.'][0-9]{1,4}h?$/'; + $localizedPattern = '/^(\d{1,3})?['.$user->getDecimalMark().'][0-9]{1,4}h?$/'; if (preg_match($localizedPattern, $duration )) { // decimal values like .5, 1.25h, ... .. 999.9999h (or with comma) - if ($user->decimal_mark == ',') + if ($user->getDecimalMark() == ',') $duration = str_replace (',', '.', $duration); $minutes = (int)round(60 * floatval($duration)); @@ -691,13 +691,15 @@ class ttTimeHelper { // getRecords - returns time records for a user for a given date. static function getRecords($user_id, $date) { global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + $sql_time_format = "'%k:%i'"; // 24 hour format. - if ('%I:%M %p' == $user->time_format) + if ('%I:%M %p' == $user->getTimeFormat()) $sql_time_format = "'%h:%i %p'"; // 12 hour format for MySQL TIME_FORMAT function. - $result = array(); - $mdb2 = getConnection(); - $client_field = null; if ($user->isPluginEnabled('cl')) $client_field = ", c.name as client"; @@ -707,12 +709,13 @@ class ttTimeHelper { if ($user->isPluginEnabled('cl')) $left_joins .= " left join tt_clients c on (l.client_id = c.id)"; + $result = array(); $sql = "select l.id as id, TIME_FORMAT(l.start, $sql_time_format) as start, TIME_FORMAT(sec_to_time(time_to_sec(l.start) + time_to_sec(l.duration)), $sql_time_format) as finish, TIME_FORMAT(l.duration, '%k:%i') as duration, p.name as project, t.name as task, l.comment, l.billable, l.invoice_id $client_field from tt_log l $left_joins - where l.date = '$date' and l.user_id = $user_id and l.status = 1 + where l.date = '$date' and l.user_id = $user_id and l.group_id = $group_id and l.org_id = $org_id and l.status = 1 order by l.start, l.id"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index e6f271df..5a328917 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -214,6 +214,11 @@ class ttUser { return ($this->behalfGroup ? $this->behalfGroup->lock_spec : $this->lock_spec); } + // getWorkdayMinutes returns workday_minutes for active group. + function getWorkdayMinutes() { + return ($this->behalfGroup ? $this->behalfGroup->workday_minutes : $this->workday_minutes); + } + // getConfig returns config string for active group. function getConfig() { return ($this->behalfGroup ? $this->behalfGroup->config : $this->config); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index d68ab3df..98e8e1c9 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.29.4630 | Copyright © Anuko | +  Anuko Time Tracker 1.18.29.4631 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/plugins/MonthlyQuota.class.php b/plugins/MonthlyQuota.class.php index 36f2d8cb..29d8cfb7 100644 --- a/plugins/MonthlyQuota.class.php +++ b/plugins/MonthlyQuota.class.php @@ -44,10 +44,11 @@ class MonthlyQuota { // update - deletes a quota, then inserts a new one. public function update($year, $month, $minutes) { - $deleteSql = "DELETE FROM tt_monthly_quotas WHERE year = $year AND month = $month AND group_id = $this->group_id"; + $deleteSql = "delete from tt_monthly_quotas". + " where year = $year and month = $month and group_id = $this->group_id and org_id = $this->org_id"; $this->db->exec($deleteSql); if ($minutes){ - $insertSql = "INSERT INTO tt_monthly_quotas (group_id, org_id, year, month, minutes)". + $insertSql = "insert into tt_monthly_quotas (group_id, org_id, year, month, minutes)". " values ($this->group_id, $this->org_id, $year, $month, $minutes)"; $affected = $this->db->exec($insertSql); return (!is_a($affected, 'PEAR_Error')); @@ -66,7 +67,8 @@ class MonthlyQuota { // getSingle - obtains a quota for a single month. private function getSingle($year, $month) { - $sql = "SELECT minutes FROM tt_monthly_quotas WHERE year = $year AND month = $month AND group_id = $this->group_id"; + $sql = "select minutes from tt_monthly_quotas". + " where year = $year and month = $month and group_id = $this->group_id and org_id = $this->org_id"; $reader = $this->db->query($sql); if (is_a($reader, 'PEAR_Error')) { return false; @@ -79,12 +81,13 @@ class MonthlyQuota { // If we did not find a record, return a calculated monthly quota. $numWorkdays = $this->getNumWorkdays($month, $year); global $user; - return $numWorkdays * $user->workday_minutes; + return $numWorkdays * $user->getWorkdayMinutes(); } // getMany - returns an array of quotas for a given year for group. private function getMany($year){ - $sql = "SELECT month, minutes FROM tt_monthly_quotas WHERE year = $year AND group_id = $this->group_id"; + $sql = "select month, minutes from tt_monthly_quotas". + " where year = $year and group_id = $this->group_id and org_id = $this->org_id"; $result = array(); $res = $this->db->query($sql); if (is_a($res, 'PEAR_Error')) { @@ -128,7 +131,7 @@ class MonthlyQuota { } global $user; - $localizedPattern = '/^([0-9]{1,3})?['.$user->decimal_mark.'][0-9]{1,4}h?$/'; + $localizedPattern = '/^([0-9]{1,3})?['.$user->getDecimalMark().'][0-9]{1,4}h?$/'; if (preg_match($localizedPattern, $value )) { // decimal values like 000.5, 999.25h, ... .. 999.9999h (or with comma) return true; } @@ -149,11 +152,11 @@ class MonthlyQuota { } global $user; - $localizedPattern = '/^([0-9]{1,3})?['.$user->decimal_mark.'][0-9]{1,4}h?$/'; + $localizedPattern = '/^([0-9]{1,3})?['.$user->getDecimalMark().'][0-9]{1,4}h?$/'; if (preg_match($localizedPattern, $value )) { // decimal values like 000.5, 999.25h, ... .. 999.9999h (or with comma) // Strip optional h in the end. $value = trim($value, 'h'); - if ($user->decimal_mark == ',') + if ($user->getDecimalMark() == ',') $value = str_replace(',', '.', $value); return (float) $value; } diff --git a/quotas.php b/quotas.php index 8381c3b6..1f376190 100644 --- a/quotas.php +++ b/quotas.php @@ -88,7 +88,7 @@ if ($request->isPost()){ // Handle workday hours. $workday_minutes = ttTimeHelper::postedDurationToMinutes($request->getParameter('workdayHours')); - if ($workday_minutes != $user->workday_minutes) { + if ($workday_minutes != $user->getWorkdayMinutes()) { if (!$user->updateGroup(array('workday_minutes'=>$workday_minutes))) $err->add($i18n->get('error.db')); } @@ -111,7 +111,7 @@ if ($request->isPost()){ // Get monthly quotas for the entire year. $monthsData = $quota->get($selectedYear); -$workdayHours = ttTimeHelper::toAbsDuration($user->workday_minutes, true); +$workdayHours = ttTimeHelper::toAbsDuration($user->getWorkdayMinutes(), true); $form = new Form('monthlyQuotasForm'); $form->addInput(array('type'=>'text', 'name'=>'workdayHours', 'value'=>$workdayHours, 'style'=>'width:60px')); -- 2.20.1