X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttInvoiceHelper.class.php;h=9fa7e58c38017f67338c10a30a9443718eb0e943;hb=c50a47de724212e47c2ed8badecaff4c50aaeb40;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..9fa7e58c 100644 --- a/WEB-INF/lib/ttInvoiceHelper.class.php +++ b/WEB-INF/lib/ttInvoiceHelper.class.php @@ -80,8 +80,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 +123,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;