From fa05834dbdd4f642cac9c83773cd755ab5791e25 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sun, 24 Jul 2016 17:03:05 +0000 Subject: [PATCH] Added export of monthly quotas data. --- WEB-INF/lib/ttExportHelper.class.php | 12 +++++++++++- WEB-INF/lib/ttTeamHelper.class.php | 17 +++++++++++++++++ WEB-INF/lib/ttUser.class.php | 4 +++- plugins/MonthlyQuota.class.php | 16 ++-------------- quotas.php | 2 +- 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/WEB-INF/lib/ttExportHelper.class.php b/WEB-INF/lib/ttExportHelper.class.php index 912ac38a..7fbab198 100644 --- a/WEB-INF/lib/ttExportHelper.class.php +++ b/WEB-INF/lib/ttExportHelper.class.php @@ -61,7 +61,9 @@ class ttExportHelper { fwrite($file, "\n"); // Write team info. - fwrite($file, "currency."\" lock_spec=\"".$user->lock_spec."\" lang=\"".$user->lang."\" decimal_mark=\"".$user->decimal_mark."\" date_format=\"".$user->date_format."\" time_format=\"".$user->time_format."\" week_start=\"".$user->week_start. + fwrite($file, "currency."\" lock_spec=\"".$user->lock_spec."\" lang=\"".$user->lang. + "\" decimal_mark=\"".$user->decimal_mark."\" date_format=\"".$user->date_format."\" time_format=\"".$user->time_format. + "\" week_start=\"".$user->week_start."\" workday_hours=\"".$user->workday_hours. "\" plugins=\"".$user->plugins."\" tracking_mode=\"".$user->tracking_mode."\" record_type=\"".$user->record_type."\">\n"); fwrite($file, " team."]]>\n"); fwrite($file, "
address."]]>
\n"); @@ -199,6 +201,14 @@ class ttExportHelper { fwrite($file, "\n"); unset($custom_field_options); + // Write monthly quotas. + $quotas = ttTeamHelper::getMonthlyQuotas($user->team_id); + fwrite($file, "\n"); + foreach ($quotas as $quota) { + fwrite($file, " \n"); + } + fwrite($file, "\n"); + // Write time log entries. fwrite($file, "\n"); $key = 0; diff --git a/WEB-INF/lib/ttTeamHelper.class.php b/WEB-INF/lib/ttTeamHelper.class.php index f3763c20..fa785903 100644 --- a/WEB-INF/lib/ttTeamHelper.class.php +++ b/WEB-INF/lib/ttTeamHelper.class.php @@ -517,6 +517,23 @@ class ttTeamHelper { return false; } + // getNotifications - obtains monthly quotas for team. + static function getMonthlyQuotas($team_id) { + $mdb2 = getConnection(); + + $result = array(); + $sql = "select year, month, quota from tt_monthly_quotas where team_id = $team_id"; + $res = $mdb2->query($sql); + $result = array(); + if (!is_a($res, 'PEAR_Error')) { + while ($val = $res->fetchRow()) { + $result[] = $val; + } + return $result; + } + return false; + } + // The getTeams function returns an array of all active teams on the server. static function getTeams() { $result = array(); diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index 53ddb484..1566a485 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -49,6 +49,7 @@ class ttUser { var $custom_logo = 0; // Whether to use a custom logo for team. var $address = null; // Address for invoices. var $lock_spec = null; // Cron specification for record locking. + var $workday_hours = 8; // Number of work hours in a regular day. var $rights = 0; // A mask of user rights. // Constructor. @@ -62,7 +63,7 @@ class ttUser { $sql = "SELECT u.id, u.login, u.name, u.team_id, u.role, u.client_id, u.email, t.name as team_name, t.address, t.currency, t.lang, t.decimal_mark, t.date_format, t.time_format, t.week_start, - t.tracking_mode, t.record_type, t.plugins, t.lock_spec, t.custom_logo + t.tracking_mode, t.record_type, t.plugins, t.lock_spec, t.workday_hours, t.custom_logo FROM tt_users u LEFT JOIN tt_teams t ON (u.team_id = t.id) WHERE "; if ($id) $sql .= "u.id = $id"; @@ -96,6 +97,7 @@ class ttUser { $this->currency = $val['currency']; $this->plugins = $val['plugins']; $this->lock_spec = $val['lock_spec']; + $this->workday_hours = $val['workday_hours']; $this->custom_logo = $val['custom_logo']; // Set "on behalf" id and name. diff --git a/plugins/MonthlyQuota.class.php b/plugins/MonthlyQuota.class.php index 4e5b8dca..a42b7824 100644 --- a/plugins/MonthlyQuota.class.php +++ b/plugins/MonthlyQuota.class.php @@ -60,19 +60,6 @@ class MonthlyQuota { return $this->getSingle($year, $month); } - // getWorkdayHours - obtains workday_hours value for a team from the database. - public function getWorkdayHours(){ - $teamId = $this->team_id; - $sql = "SELECT workday_hours FROM tt_teams where id = $teamId"; - $reader = $this->db->query($sql); - if (is_a($reader, 'PEAR_Error')) { - return false; - } - - $row = $reader->fetchRow(); - return $row['workday_hours']; - } - // getSingle - obtains a quota for a single month. private function getSingle($year, $month) { $teamId = $this->team_id; @@ -88,7 +75,8 @@ class MonthlyQuota { // If we did not find a record, return a calculated monthly quota. $numWorkdays = $this->getNumWorkdays($month, $year); - return $numWorkdays * $this->getWorkdayHours(); + global $user; + return $numWorkdays * $user->workday_hours; } // getMany - returns an array of quotas for a given year for team. diff --git a/quotas.php b/quotas.php index 1dfa06fa..68b8a619 100644 --- a/quotas.php +++ b/quotas.php @@ -97,7 +97,7 @@ if ($request->isPost()){ $monthsData = $quota->get($selectedYear); $form = new Form('monthlyQuotasForm'); -$form->addInput(array('type'=>'text', 'name'=>'workdayHours', 'value'=>$quota->getWorkdayHours(), 'style'=>'width:50px')); +$form->addInput(array('type'=>'text', 'name'=>'workdayHours', 'value'=>$user->workday_hours, 'style'=>'width:50px')); $form->addInput(array('type'=>'combobox','name'=>'year','data'=>$years,'datakeys'=>array('id','name'),'value'=>$selectedYear,'onchange'=>'yearChange(this.value);')); for ($i=0; $i < count($months); $i++) { $value = ""; -- 2.20.1