]> wagnertech.de Git - timetracker.git/blobdiff - WEB-INF/lib/ttOrgImportHelper.class.php
Improved new export-import by adding invoices.
[timetracker.git] / WEB-INF / lib / ttOrgImportHelper.class.php
index ccdc05b20f8c4665094894c5b90a6e557ec326b7..015668807ba8130598b15c362bd31719f856f1fe 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'));
+      }
     }
   }