2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
11 // | There are only two ways to violate the license:
13 // | 1. To redistribute this code in source form, with the copyright
14 // | notice or license removed or altered. (Distributing in compiled
15 // | forms without embedded copyright notices is permitted).
17 // | 2. To redistribute modified versions of this code in *any* form
18 // | that bears insufficient indications that the modifications are
19 // | not the work of the original author(s).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
30 // Class ttPredefinedExpenseHelper is used to help with predefined expense related tasks.
31 class ttPredefinedExpenseHelper {
33 // get - gets predefined expense details.
34 static function get($id)
38 $mdb2 = getConnection();
40 $sql = "select id, name, cost from tt_predefined_expenses
41 where id = $id and team_id = $user->team_id";
42 $res = $mdb2->query($sql);
43 if (!is_a($res, 'PEAR_Error')) {
44 $val = $res->fetchRow();
45 if ($val && $val['id'])
51 // delete - deletes a predefined expense from tt_predefined_expenses table.
52 static function delete($id) {
55 $mdb2 = getConnection();
57 $sql = "delete from tt_predefined_expenses where id = $id and team_id = $user->team_id";
58 $affected = $mdb2->exec($sql);
59 if (is_a($affected, 'PEAR_Error'))
65 // insert function inserts a new predefined expense into database.
66 static function insert($fields)
68 $mdb2 = getConnection();
70 $team_id = (int) $fields['team_id'];
71 $name = $fields['name'];
72 $cost = $fields['cost'];
74 $sql = "insert into tt_predefined_expenses (team_id, name, cost)
75 values ($team_id, ".$mdb2->quote($name).", ".$mdb2->quote($cost).")";
76 $affected = $mdb2->exec($sql);
77 if (is_a($affected, 'PEAR_Error'))
83 // update function - updates a predefined expense in database.
84 static function update($fields)
86 $mdb2 = getConnection();
88 $predefined_expense_id = (int) $fields['id'];
89 $team_id = (int) $fields['team_id'];
90 $name = $fields['name'];
91 $cost = $fields['cost'];
93 $sql = "update tt_predefined_expenses set name = ".$mdb2->quote($name).", cost = ".$mdb2->quote($cost).
94 " where id = $predefined_expense_id and team_id = $team_id";
95 $affected = $mdb2->exec($sql);
96 return (!is_a($affected, 'PEAR_Error'));