Implemented import of monthly quotas.
authorNik Okuntseff <support@anuko.com>
Sun, 24 Jul 2016 18:02:29 +0000 (18:02 +0000)
committerNik Okuntseff <support@anuko.com>
Sun, 24 Jul 2016 18:02:29 +0000 (18:02 +0000)
WEB-INF/lib/ttImportHelper.class.php
WEB-INF/lib/ttTeamHelper.class.php

index 29c537f..26cdfac 100644 (file)
@@ -75,6 +75,7 @@ class ttImportHelper {
       || $name == 'PROJECT'
       || $name == 'CLIENT'
       || $name == 'INVOICE'
+      || $name == 'MONTHLY_QUOTA'
       || $name == 'LOG_ITEM'
       || $name == 'CUSTOM_FIELD'
       || $name == 'CUSTOM_FIELD_OPTION'
@@ -118,6 +119,7 @@ class ttImportHelper {
           'address' => $this->teamData['ADDRESS'],
           'currency' => $this->teamData['CURRENCY'],
           'lock_spec' => $this->teamData['LOCK_SPEC'],
+          'workday_hours' => $this->teamData['WORKDAY_HOURS'],
           'lang' => $this->teamData['LANG'],
           'decimal_mark' => $this->teamData['DECIMAL_MARK'],
           'date_format' => $this->teamData['DATE_FORMAT'],
@@ -210,6 +212,10 @@ class ttImportHelper {
           'status' => $this->currentElement['STATUS']));
     }
 
+    if ($name == 'MONTHLY_QUOTA' && $this->canImport) {
+      $this->insertMonthlyQuota($this->team_id, $this->currentElement['YEAR'], $this->currentElement['MONTH'], $this->currentElement['QUOTA']);
+    }
+
     if ($name == 'LOG_ITEM' && $this->canImport) {
       $this->logMap[$this->currentElement['ID']] =
         ttTimeHelper::insert(array(
@@ -396,4 +402,12 @@ class ttImportHelper {
     fclose ($out_file);
     return true;
   }
+
+  // insertMonthlyQuota - a helper function to insert a monthly quota.
+  private function insertMonthlyQuota($team_id, $year, $month, $quota) {
+    $mdb2 = getConnection();
+    $sql = "INSERT INTO tt_monthly_quotas (team_id, year, month, quota) values ($team_id, $year, $month, $quota)";
+    $affected = $mdb2->exec($sql);
+    return (!is_a($affected, 'PEAR_Error'));
+  }
 }
index fa78590..4c1af14 100644 (file)
@@ -701,11 +701,20 @@ class ttTeamHelper {
       $record_type_v = '';
     }
 
-    $sql = "insert into tt_teams (name, address, currency $lockspec_f, lang $decimal_mark_f $date_format_f $time_format_f $week_start_f $plugins_f $tracking_mode_f $record_type_f)
+    $workday_hours = $fields['workday_hours'];
+    if ($workday_hours !== null) {
+      $workday_hours_f = ', workday_hours';
+      $workday_hours_v = ', ' . (int)$workday_hours;
+    } else {
+      $workday_hours_f = '';
+      $workday_hours_v = '';
+    }
+
+    $sql = "insert into tt_teams (name, address, currency $lockspec_f, lang $decimal_mark_f $date_format_f $time_format_f $week_start_f $plugins_f $tracking_mode_f $record_type_f $workday_hours_f)
       values(".$mdb2->quote(trim($fields['name'])).
       ", ".$mdb2->quote(trim($fields['address'])).
       ", ".$mdb2->quote(trim($fields['currency']))." $lockspec_v, ".$mdb2->quote($lang).
-      "$decimal_mark_v $date_format_v $time_format_v $week_start_v $plugins_v $tracking_mode_v $record_type_v)";
+      "$decimal_mark_v $date_format_v $time_format_v $week_start_v $plugins_v $tracking_mode_v $record_type_v $workday_hours_v)";
     $affected = $mdb2->exec($sql);
 
     if (!is_a($affected, 'PEAR_Error')) {