From a2f024d2184505a889e51d92337d9f40e392a1be Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Fri, 30 Nov 2018 18:32:47 +0000 Subject: [PATCH] More refactoring on decoupling import. --- WEB-INF/lib/ttOrgImportHelper.class.php | 41 +++++++++++++++++++++---- WEB-INF/templates/footer.tpl | 2 +- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index cbf7d28a..34933411 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -27,7 +27,6 @@ // +----------------------------------------------------------------------+ import('ttUserHelper'); -import('ttInvoiceHelper'); // ttOrgImportHelper class is used to import organization data from an XML file // prepared by ttOrgExportHelper and consisting of nested groups with their info. @@ -160,7 +159,9 @@ class ttOrgImportHelper { if ($role_id) { // Add a mapping. $this->currentGroupRoleMap[$attrs['ID']] = $role_id; - } else $this->errors->add($i18n->get('error.db')); + } else { + $this->errors->add($i18n->get('error.db')); + } return; } @@ -228,7 +229,9 @@ class ttOrgImportHelper { if ($client_id) { // Add a mapping. $this->currentGroupClientMap[$attrs['ID']] = $client_id; - } else $this->errors->add($i18n->get('error.db')); + } else { + $this->errors->add($i18n->get('error.db')); + } return; } @@ -251,7 +254,9 @@ class ttOrgImportHelper { if ($user_id) { // Add a mapping. $this->currentGroupUserMap[$attrs['ID']] = $user_id; - } else $this->errors->add($i18n->get('error.db')); + } else { + $this->errors->add($i18n->get('error.db')); + } return; } @@ -270,7 +275,7 @@ class ttOrgImportHelper { if ($name == 'INVOICE') { // We get here when processing tags for the current group. - $invoice_id = ttInvoiceHelper::insert(array( + $invoice_id = $this->insertInvoice(array( 'group_id' => $this->current_group_id, 'org_id' => $this->org_id, 'name' => $attrs['NAME'], @@ -280,7 +285,9 @@ class ttOrgImportHelper { if ($invoice_id) { // Add a mapping. $this->currentGroupInvoiceMap[$attrs['ID']] = $invoice_id; - } else $this->errors->add($i18n->get('error.db')); + } else { + $this->errors->add($i18n->get('error.db')); + } return; } @@ -781,6 +788,28 @@ class ttOrgImportHelper { return $last_id; } + // insertInvoice - inserts an invoice in database. + private function insertInvoice($fields) + { + $mdb2 = getConnection(); + + $group_id = (int) $fields['group_id']; + $org_id = (int) $fields['org_id']; + $name = $fields['name']; + $client_id = (int) $fields['client_id']; + $date = $fields['date']; + $status = $fields['status']; + + // Insert a new invoice record. + $sql = "insert into tt_invoices (group_id, org_id, name, date, client_id, status)". + " values($group_id, $org_id, ".$mdb2->quote($name).", ".$mdb2->quote($date).", $client_id, ".$mdb2->quote($fields['status']).")"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) return false; + + $last_id = $mdb2->lastInsertID('tt_invoices', 'id'); + return $last_id; + } + // The insertClient function inserts a new client as well as client to project binds. private function insertClient($fields) { diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 85ad89fe..9b68b6a8 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.28.4549 | Copyright © Anuko | +  Anuko Time Tracker 1.18.28.4550 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} -- 2.20.1