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())
// 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();
// 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();
}
}
- // sql part for project id.
- if ($project_id) $project_part = " and ei.project_id = $project_id";
-
- $sql = "select count(*) as num from tt_expense_items ei
- where ei.client_id = $client_id $project_part and ei.invoice_id is NULL
- and ei.date >= ".$mdb2->quote($start)." and ei.date <= ".$mdb2->quote($end)."
- and ei.cost <> 0 and ei.status = 1";
- $res = $mdb2->query($sql);
- if (!is_a($res, 'PEAR_Error')) {
- $val = $res->fetchRow();
- if ($val['num']) {
- return true;
+ if ($user->isPluginEnabled('ex')) {
+ // sql part for project id.
+ if ($project_id) $project_part = " and ei.project_id = $project_id";
+
+ $sql = "select count(*) as num from tt_expense_items ei
+ where ei.client_id = $client_id $project_part and ei.invoice_id is NULL
+ and ei.date >= ".$mdb2->quote($start)." and ei.date <= ".$mdb2->quote($end)."
+ and ei.cost <> 0 and ei.status = 1";
+ $res = $mdb2->query($sql);
+ if (!is_a($res, 'PEAR_Error')) {
+ $val = $res->fetchRow();
+ if ($val['num']) {
+ return true;
+ }
}
}