// Class ttInvoiceHelper is used for help with invoices.
class ttInvoiceHelper {
- // insert - inserts an invoice in database.
- static function insert($fields)
- {
- $mdb2 = getConnection();
-
- $group_id = (int) $fields['group_id'];
- $org_id = (int) $fields['org_id'];
- $name = $fields['name'];
- if (!$name) return false;
-
- $client_id = (int) $fields['client_id'];
- $date = $fields['date'];
- if (array_key_exists('status', $fields)) { // Key exists and may be NULL during migration of data.
- $status_f = ', status';
- $status_v = ', '.$mdb2->quote($fields['status']);
- }
-
- // Insert a new invoice record.
- $sql = "insert into tt_invoices (group_id, org_id, name, date, client_id $status_f)".
- " values($group_id, $org_id, ".$mdb2->quote($name).", ".$mdb2->quote($date).", $client_id $status_v)";
- $affected = $mdb2->exec($sql);
-
- if (is_a($affected, 'PEAR_Error')) return false;
-
- $last_id = 0;
- $sql = "select last_insert_id() as last_insert_id";
- $res = $mdb2->query($sql);
- $val = $res->fetchRow();
- $last_id = $val['last_insert_id'];
-
- return $last_id;
- }
-
// getInvoice - obtains invoice data from the database.
static function getInvoice($invoice_id) {
global $user;
}
}
- // 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;
+ }
}
}
if (is_a($affected, 'PEAR_Error')) return false;
// Mark associated invoice items with invoice id.
- $last_id = 0;
- $sql = "select last_insert_id() as last_insert_id";
- $res = $mdb2->query($sql);
- $val = $res->fetchRow();
- $last_id = $val['last_insert_id'];
+ $last_id = $mdb2->lastInsertID('tt_invoices', 'id');
// Our update sql is different depending on tracking mode.
if (MODE_TIME == $user->getTrackingMode()) {