Improved new export-import by adding time log.
authorNik Okuntseff <support@anuko.com>
Sat, 10 Nov 2018 23:02:08 +0000 (23:02 +0000)
committerNik Okuntseff <support@anuko.com>
Sat, 10 Nov 2018 23:02:08 +0000 (23:02 +0000)
WEB-INF/lib/ttGroupExportHelper.class.php
WEB-INF/lib/ttOrgImportHelper.class.php
WEB-INF/templates/footer.tpl

index 91a36ce..fecfba8 100644 (file)
@@ -46,6 +46,7 @@ class ttGroupExportHelper {
   var $projectMap = array(); // Project ids.
   var $clientMap  = array(); // Client ids.
   var $invoiceMap = array(); // Invoice ids.
+  var $logMap     = array(); // Time log ids.
 
   // Constructor.
   function __construct($group_id, $file, $indentation) {
@@ -343,6 +344,35 @@ class ttGroupExportHelper {
     }
     fwrite($this->file, $this->indentation."  </invoices>\n");
 
+    // Write time log entries and build logMap at the same time.
+    fwrite($this->file, $this->indentation."  <log>\n");
+    $key = 0;
+    foreach ($users as $user_item) {
+      $records = ttTimeHelper::getAllRecords($user_item['id']);
+      foreach ($records as $record) {
+        $key++;
+        $this->logMap[$record['id']] = $key;
+        $log_part = $this->indentation.'    '."<log_item id=\"$key\"";
+        $log_part .= " user_id=\"".$this->userMap[$record['user_id']]."\"";
+        $log_part .= " date=\"".$record['date']."\"";
+        $log_part .= " start=\"".$record['start']."\"";
+        $log_part .= " finish=\"".$record['finish']."\"";
+        $log_part .= " duration=\"".($record['start']?"":$record['duration'])."\"";
+        $log_part .= " client_id=\"".$this->clientMap[$record['client_id']]."\"";
+        $log_part .= " project_id=\"".$this->projectMap[$record['project_id']]."\"";
+        $log_part .= " task_id=\"".$this->taskMap[$record['task_id']]."\"";
+        $log_part .= " invoice_id=\"".$this->invoiceMap[$record['invoice_id']]."\"";
+        $log_part .= " comment=\"".htmlentities($record['comment'])."\"";
+        $log_part .= " billable=\"".$record['billable']."\"";
+        $log_part .= " paid=\"".$record['paid']."\"";
+        $log_part .= " status=\"".$record['status']."\"";
+        $log_part .= "></log_item>\n";
+        fwrite($this->file, $log_part);
+      }
+    }
+    fwrite($this->file, $this->indentation."  </log>\n");
+    unset($records);
+
     // Call self recursively for all subgroups.
     foreach ($this->subgroups as $subgroup) {
       $subgroup_helper = new ttGroupExportHelper($subgroup['id'], $this->file, $this->indentation.'  ');
index 0156688..622b3fe 100644 (file)
@@ -54,6 +54,7 @@ class ttOrgImportHelper {
   var $currentGroupClientMap  = array();
   var $currentGroupUserMap    = array();
   var $currentGroupInvoiceMap = array();
+  var $currentGroupLogMap     = array();
 
   // Constructor.
   function __construct(&$errors) {
@@ -279,6 +280,37 @@ class ttOrgImportHelper {
           $this->currentGroupInvoiceMap[$attrs['ID']] = $invoice_id;
         } else $this->errors->add($i18n->get('error.db'));
       }
+
+      if ($name == 'LOG') {
+        // If we get here, we have to recycle $currentGroupLogMap.
+        unset($this->currentGroupLogMap);
+        $this->currentGroupLogMap = array();
+        // Log map is reconstructed after processing <log_item> elements in XML. See below.
+      }
+
+      if ($name == 'LOG_ITEM') {
+        // We get here when processing <log_item> tags for the current group.
+        $log_item_id = ttTimeHelper::insert(array(
+          'user_id' => $this->currentGroupUserMap[$attrs['USER_ID']],
+          'group_id' => $this->current_group_id,
+          'org_id' => $this->org_id,
+          'date' => $attrs['DATE'],
+          'start' => $attrs['START'],
+          'finish' => $attrs['FINISH'],
+          'duration' => $attrs['DURATION'],
+          'client' => $this->currentGroupClientMap[$attrs['CLIENT_ID']],
+          'project' => $this->currentGroupProjectMap[$attrs['PROJECT_ID']],
+          'task' => $this->currentGroupTaskMap[$attrs['TASK_ID']],
+          'invoice' => $this->currentGroupInvoiceMap[$attrs['INVOICE_ID']],
+          'note' => (isset($attrs['COMMENT']) ? $attrs['COMMENT'] : ''),
+          'billable' => $attrs['BILLABLE'],
+          'paid' => $attrs['PAID'],
+          'status' => $attrs['STATUS']));
+        if ($log_item_id) {
+          // Add a mapping.
+          $this->currentGroupLogMap[$attrs['ID']] = $log_item_id;
+        } else $this->errors->add($i18n->get('error.db'));
+      }
     }
   }
 
index 8995b12..a93f706 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.4410 | 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.4411 | 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>