Started to populate org_id during import of expense items.
authorNik Okuntseff <support@anuko.com>
Sat, 17 Nov 2018 18:24:14 +0000 (18:24 +0000)
committerNik Okuntseff <support@anuko.com>
Sat, 17 Nov 2018 18:24:14 +0000 (18:24 +0000)
WEB-INF/lib/ttOrgImportHelper.class.php
WEB-INF/templates/footer.tpl

index 9f5dd78..6764ba5 100644 (file)
@@ -415,11 +415,11 @@ class ttOrgImportHelper {
 
       if ($name == 'EXPENSE_ITEM') {
         // We get here when processing <expense_item> tags for the current group.
-        $expense_item_id = ttExpenseHelper::insert(array(
+        $expense_item_id = $this->insertExpense(array(
           'date' => $attrs['DATE'],
           'user_id' => $this->currentGroupUserMap[$attrs['USER_ID']],
           'group_id' => $this->current_group_id,
-          // 'org_id' => $this->org_id, TODO: add this when org_id field is added to the table.
+          'org_id' => $this->org_id,
           'client_id' => $this->currentGroupClientMap[$attrs['CLIENT_ID']],
           'project_id' => $this->currentGroupProjectMap[$attrs['PROJECT_ID']],
           'name' => $attrs['NAME'],
@@ -679,4 +679,30 @@ class ttOrgImportHelper {
     $affected = $mdb2->exec($sql);
     return (!is_a($affected, 'PEAR_Error'));
   }
+
+  // insertExpense - a helper function to insert an expense item.
+  private function insertExpense($fields) {
+    global $user;
+    $mdb2 = getConnection();
+
+    $group_id = (int) $fields['group_id'];
+    $org_id = (int) $fields['org_id'];
+    $date = $fields['date'];
+    $user_id = (int) $fields['user_id'];
+    $client_id = $fields['client_id'];
+    $project_id = $fields['project_id'];
+    $name = $fields['name'];
+    $cost = str_replace(',', '.', $fields['cost']);
+    $invoice_id = $fields['invoice_id'];
+    $status = $fields['status'];
+    $paid = (int) $fields['paid'];
+    $created = ', now(), '.$mdb2->quote($_SERVER['REMOTE_ADDR']).', '.$mdb2->quote($user->id);
+
+    $sql = "insert into tt_expense_items".
+      " (date, user_id, group_id, org_id, client_id, project_id, name, cost, invoice_id, paid, created, created_ip, created_by, status)".
+      " values (".$mdb2->quote($date).", $user_id, $group_id, $org_id, ".$mdb2->quote($client_id).", ".$mdb2->quote($project_id).
+      ", ".$mdb2->quote($name).", ".$mdb2->quote($cost).", ".$mdb2->quote($invoice_id).", $paid $created, ".$mdb2->quote($status).")";
+    $affected = $mdb2->exec($sql);
+    return (!is_a($affected, 'PEAR_Error'));
+  }
 }
index 0911789..58b036c 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.17.4443 | 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.17.4444 | 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>