Added monthly quotas to new export-import.
authorNik Okuntseff <support@anuko.com>
Sun, 11 Nov 2018 15:09:54 +0000 (15:09 +0000)
committerNik Okuntseff <support@anuko.com>
Sun, 11 Nov 2018 15:09:54 +0000 (15:09 +0000)
WEB-INF/lib/ttGroupExportHelper.class.php
WEB-INF/lib/ttOrgImportHelper.class.php
WEB-INF/templates/footer.tpl

index e18f8c9..b1aa35c 100644 (file)
@@ -445,6 +445,18 @@ class ttGroupExportHelper {
     fwrite($this->file, $this->indentation."  </expense_items>\n");
     unset($expense_items);
 
+    // Write monthly quotas.
+    $quotas = ttTeamHelper::getMonthlyQuotas($this->group_id);
+    fwrite($this->file, $this->indentation."  <monthly_quotas>\n");
+    foreach ($quotas as $quota) {
+      $quota_part = $this->indentation.'    '."<monthly_quota year=\"".$quota['year']."\"";
+      $quota_part .= " month=\"".$quota['month']."\"";
+      $quota_part .= " minutes=\"".$quota['minutes']."\"";
+      $quota_part .= "></monthly_quota>\n";
+      fwrite($this->file, $quota_part);
+    }
+    fwrite($this->file, $this->indentation."  </monthly_quotas>\n");
+
     // Call self recursively for all subgroups.
     foreach ($this->subgroups as $subgroup) {
       $subgroup_helper = new ttGroupExportHelper($subgroup['id'], $this->file, $this->indentation.'  ');
index 89428c4..cc632f1 100644 (file)
@@ -388,6 +388,16 @@ class ttOrgImportHelper {
           'status' => $attrs['STATUS']));
         if (!$expense_item_id) $this->errors->add($i18n->get('error.db'));
       }
+
+      if ($name == 'MONTHLY_QUOTA') {
+        if (!$this->insertMonthlyQuota($this->current_group_id,
+          // 'org_id' => $this->org_id, TODO: add this when org_id field is added to the table.
+          $attrs['YEAR'],
+          $attrs['MONTH'],
+          $attrs['MINUTES'])) {
+          $this->errors->add($i18n->get('error.db'));
+        }
+      }
     }
   }
 
@@ -548,4 +558,12 @@ class ttOrgImportHelper {
     $group_id = $mdb2->lastInsertID('tt_groups', 'id');
     return $group_id;
   }
+
+  // insertMonthlyQuota - a helper function to insert a monthly quota.
+  private function insertMonthlyQuota($group_id, $year, $month, $minutes) {
+    $mdb2 = getConnection();
+    $sql = "INSERT INTO tt_monthly_quotas (group_id, year, month, minutes) values ($group_id, $year, $month, $minutes)";
+    $affected = $mdb2->exec($sql);
+    return (!is_a($affected, 'PEAR_Error'));
+  }
 }
index dbce25f..338b37b 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.18.12.4415 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.18.12.4416 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
             <a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
             <a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
             <a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>