Improved new export-import by adding invoices.
authorNik Okuntseff <support@anuko.com>
Sat, 10 Nov 2018 21:20:54 +0000 (21:20 +0000)
committerNik Okuntseff <support@anuko.com>
Sat, 10 Nov 2018 21:20:54 +0000 (21:20 +0000)
WEB-INF/lib/ttGroupExportHelper.class.php
WEB-INF/lib/ttImportHelper.class.php
WEB-INF/lib/ttOrgImportHelper.class.php
WEB-INF/templates/footer.tpl

index 125df0f..91a36ce 100644 (file)
@@ -45,6 +45,7 @@ class ttGroupExportHelper {
   var $taskMap    = array(); // Task ids.
   var $projectMap = array(); // Project ids.
   var $clientMap  = array(); // Client ids.
+  var $invoiceMap = array(); // Invoice ids.
 
   // Constructor.
   function __construct($group_id, $file, $indentation) {
@@ -224,6 +225,11 @@ class ttGroupExportHelper {
     foreach ($clients as $key=>$client_item)
       $this->clientMap[$client_item['id']] = $key + 1;
 
+    // Prepare invoice map.
+    $invoices = ttTeamHelper::getAllInvoices();
+    foreach ($invoices as $key=>$invoice_item)
+      $this->invoiceMap[$invoice_item['id']] = $key + 1;
+
     // Write roles.
     fwrite($this->file, $this->indentation."  <roles>\n");
     foreach ($roles as $role) {
@@ -324,6 +330,19 @@ class ttGroupExportHelper {
     }
     fwrite($this->file, $this->indentation."  </user_project_binds>\n");
 
+    // Write invoices.
+    fwrite($this->file, $this->indentation."  <invoices>\n");
+    foreach ($invoices as $invoice_item) {
+      $invoice_part = $this->indentation.'    '."<invoice id=\"".$this->invoiceMap[$invoice_item['id']]."\"";
+      $invoice_part .= " name=\"".htmlentities($invoice_item['name'])."\"";
+      $invoice_part .= " date=\"".$invoice_item['date']."\"";
+      $invoice_part .= " client_id=\"".$this->clientMap[$invoice_item['client_id']]."\"";
+      $invoice_part .= " status=\"".$invoice_item['status']."\"";
+      $invoice_part .= "></invoice>\n";
+      fwrite($this->file, $invoice_part);
+    }
+    fwrite($this->file, $this->indentation."  </invoices>\n");
+
     // Call self recursively for all subgroups.
     foreach ($this->subgroups as $subgroup) {
       $subgroup_helper = new ttGroupExportHelper($subgroup['id'], $this->file, $this->indentation.'  ');
index ea89982..7fa1e28 100644 (file)
@@ -247,7 +247,6 @@ class ttImportHelper {
           'name' => $this->currentElement['NAME'],
           'date' => $this->currentElement['DATE'],
           'client_id' => $this->clientMap[$this->currentElement['CLIENT_ID']],
-          'discount' => $this->currentElement['DISCOUNT'],
           'status' => $this->currentElement['STATUS']));
     }
 
index ccdc05b..0156688 100644 (file)
@@ -31,6 +31,7 @@ import('ttRoleHelper');
 import('ttTaskHelper');
 import('ttProjectHelper');
 import('ttClientHelper');
+import('ttInvoiceHelper');
 
 // ttOrgImportHelper - this class is a future replacement for ttImportHelper.
 // Currently, it is work in progress.
@@ -52,6 +53,7 @@ class ttOrgImportHelper {
   var $currentGroupProjectMap = array();
   var $currentGroupClientMap  = array();
   var $currentGroupUserMap    = array();
+  var $currentGroupInvoiceMap = array();
 
   // Constructor.
   function __construct(&$errors) {
@@ -255,6 +257,28 @@ class ttOrgImportHelper {
           $this->errors->add($i18n->get('error.db'));
         }
       }
+
+      if ($name == 'INVOICES') {
+        // If we get here, we have to recycle $currentGroupInvoiceMap.
+        unset($this->currentGroupInvoiceMap);
+        $this->currentGroupInvoiceMap = array();
+        // Invoice map is reconstructed after processing <invoice> elements in XML. See below.
+      }
+
+      if ($name == 'INVOICE') {
+        // We get here when processing <invoice> tags for the current group.
+        $invoice_id = ttInvoiceHelper::insert(array(
+          'group_id' => $this->current_group_id,
+          'org_id' => $this->org_id,
+          'name' => $attrs['NAME'],
+          'date' => $attrs['DATE'],
+          'client_id' => $this->currentGroupClientMap[$attrs['CLIENT_ID']],
+          'status' => $attrs['STATUS']));
+        if ($invoice_id) {
+          // Add a mapping.
+          $this->currentGroupInvoiceMap[$attrs['ID']] = $invoice_id;
+        } else $this->errors->add($i18n->get('error.db'));
+      }
     }
   }
 
index cff8822..8995b12 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.4409 | 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.4410 | 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>