X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttInvoiceHelper.class.php;h=fd701fe51c288ef0ed9da9b1fb109dbbc033df7c;hb=3f7ed883e1c7d75aacc49900b403f8e84a68dc3f;hp=c30776c05abc5b5dee4ba4f18f4d4c68f1c5f110;hpb=df8a6c4cd909701bef9e6b58a71271846c527148;p=timetracker.git diff --git a/WEB-INF/lib/ttInvoiceHelper.class.php b/WEB-INF/lib/ttInvoiceHelper.class.php index c30776c0..fd701fe5 100644 --- a/WEB-INF/lib/ttInvoiceHelper.class.php +++ b/WEB-INF/lib/ttInvoiceHelper.class.php @@ -69,7 +69,9 @@ class ttInvoiceHelper { global $user; $mdb2 = getConnection(); - $sql = "select * from tt_invoices where id = $invoice_id and team_id = $user->team_id and status = 1"; + if ($user->isClient()) $client_part = " and client_id = $user->client_id"; + + $sql = "select * from tt_invoices where id = $invoice_id and team_id = $user->team_id $client_part and status = 1"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { if ($val = $res->fetchRow()) @@ -80,8 +82,10 @@ class ttInvoiceHelper { // The getInvoiceByName looks up an invoice by name. static function getInvoiceByName($invoice_name) { + $mdb2 = getConnection(); global $user; + $sql = "select id from tt_invoices where team_id = $user->team_id and name = ".$mdb2->quote($invoice_name)." and status = 1"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { @@ -121,6 +125,24 @@ class ttInvoiceHelper { return false; } + // markPaid marks invoice items as paid. + static function markPaid($invoice_id, $mark_paid = true) { + + global $user; + $mdb2 = getConnection(); + + $paid_status = $mark_paid ? 1 : 0; + $sql = "update tt_log set paid = $paid_status where invoice_id = $invoice_id and status = 1"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) return false; + + $sql = "update tt_expense_items set paid = $paid_status where invoice_id = $invoice_id and status = 1"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) return false; + + return true; + } + // The getInvoiceItems retrieves tt_log items associated with the invoice. static function getInvoiceItems($invoice_id) { global $user;