From 005295b05a6f3418db5dc3fb79fe73e2c7d01d2f Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Thu, 6 Dec 2018 20:54:00 +0000 Subject: [PATCH] More refactoring of invoices for subgroups. --- WEB-INF/lib/ttInvoiceHelper.class.php | 31 +++++++++++++++++---------- WEB-INF/templates/footer.tpl | 2 +- invoices.php | 1 + 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/WEB-INF/lib/ttInvoiceHelper.class.php b/WEB-INF/lib/ttInvoiceHelper.class.php index 042acd82..445c02c2 100644 --- a/WEB-INF/lib/ttInvoiceHelper.class.php +++ b/WEB-INF/lib/ttInvoiceHelper.class.php @@ -37,10 +37,13 @@ class ttInvoiceHelper { global $user; $mdb2 = getConnection(); - if ($user->isClient()) $client_part = " and client_id = $user->client_id"; + $group_id = $user->getGroup(); + $org_id = $user->org_id; - $sql = "select * from tt_invoices where id = $invoice_id and group_id = ". - $user->getGroup()."$client_part and status = 1"; + if ($user->isClient()) $client_part = "and client_id = $user->client_id"; + + $sql = "select * from tt_invoices". + " where id = $invoice_id and group_id = $group_id and org_id = $org_id $client_part and status = 1"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { if ($val = $res->fetchRow()) @@ -51,12 +54,14 @@ class ttInvoiceHelper { // The getInvoiceByName looks up an invoice by name. static function getInvoiceByName($invoice_name) { - - $mdb2 = getConnection(); global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; - $sql = "select id from tt_invoices where group_id = ". - $user->getGroup()." and name = ".$mdb2->quote($invoice_name)." and status = 1"; + $sql = "select id from tt_invoices where group_id = $group_id and org_id = $org_id". + " and name = ".$mdb2->quote($invoice_name)." and status = 1"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { $val = $res->fetchRow(); @@ -72,18 +77,22 @@ class ttInvoiceHelper { // Therefore, the paid status of the invoice is a calculated value. // This is because we maintain the paid status on individual item level. static function isPaid($invoice_id) { - - $mdb2 = getConnection(); global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; - $sql = "select count(*) as count from tt_log where invoice_id = $invoice_id and status = 1 and paid < 1"; + $sql = "select count(*) as count from tt_log". + " where invoice_id = $invoice_id and group_id = $group_id and org_id = $org_id and status = 1 and paid < 1"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { $val = $res->fetchRow(); if ($val['count'] > 0) return false; // A non-paid time item exists. } - $sql = "select count(*) as count from tt_expense_items where invoice_id = $invoice_id and status = 1 and paid < 1"; + $sql = "select count(*) as count from tt_expense_items". + " where invoice_id = $invoice_id and group_id = $group_id and org_id = $org_id and status = 1 and paid < 1"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { $val = $res->fetchRow(); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index dbb5b1c4..39b3280f 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.29.4599 | Copyright © Anuko | +  Anuko Time Tracker 1.18.29.4600 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/invoices.php b/invoices.php index eb89e0ea..ba1cad46 100644 --- a/invoices.php +++ b/invoices.php @@ -39,6 +39,7 @@ if (!$user->isPluginEnabled('iv')) { header('Location: feature_disabled.php'); exit(); } +// End of access checks. $invoices = ttGroupHelper::getActiveInvoices(); -- 2.20.1