Added export of monthly quotas data.
authorNik Okuntseff <support@anuko.com>
Sun, 24 Jul 2016 17:03:05 +0000 (17:03 +0000)
committerNik Okuntseff <support@anuko.com>
Sun, 24 Jul 2016 17:03:05 +0000 (17:03 +0000)
WEB-INF/lib/ttExportHelper.class.php
WEB-INF/lib/ttTeamHelper.class.php
WEB-INF/lib/ttUser.class.php
plugins/MonthlyQuota.class.php
quotas.php

index 912ac38..7fbab19 100644 (file)
@@ -61,7 +61,9 @@ class ttExportHelper {
     fwrite($file, "<pack>\n");
 
     // Write team info.
-    fwrite($file, "<team currency=\"".$user->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, "<team currency=\"".$user->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, "  <name><![CDATA[".$user->team."]]></name>\n");
     fwrite($file, "  <address><![CDATA[".$user->address."]]></address>\n");
@@ -199,6 +201,14 @@ class ttExportHelper {
     fwrite($file, "</custom_field_options>\n");
     unset($custom_field_options);
 
+    // Write monthly quotas.
+    $quotas = ttTeamHelper::getMonthlyQuotas($user->team_id);
+    fwrite($file, "<monthly_quotas>\n");
+    foreach ($quotas as $quota) {
+      fwrite($file, "  <monthly_quota year=\"".$quota['year']."\" month=\"".$quota['month']."\" quota=\"".$quota['quota']."\"/>\n");
+    }
+    fwrite($file, "</monthly_quotas>\n");
+
     // Write time log entries.
     fwrite($file, "<log>\n");
     $key = 0;
index f3763c2..fa78590 100644 (file)
@@ -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();
index 53ddb48..1566a48 100644 (file)
@@ -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.
index 4e5b8dc..a42b782 100644 (file)
@@ -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.
index 1dfa06f..68b8a61 100644 (file)
@@ -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 = "";