forked from Ben0it-T/timetracker
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathttPredefinedExpenseHelper.class.php
More file actions
128 lines (106 loc) · 4.2 KB
/
ttPredefinedExpenseHelper.class.php
File metadata and controls
128 lines (106 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
// +----------------------------------------------------------------------+
// | Anuko Time Tracker
// +----------------------------------------------------------------------+
// | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
// +----------------------------------------------------------------------+
// | LIBERAL FREEWARE LICENSE: This source code document may be used
// | by anyone for any purpose, and freely redistributed alone or in
// | combination with other software, provided that the license is obeyed.
// |
// | There are only two ways to violate the license:
// |
// | 1. To redistribute this code in source form, with the copyright
// | notice or license removed or altered. (Distributing in compiled
// | forms without embedded copyright notices is permitted).
// |
// | 2. To redistribute modified versions of this code in *any* form
// | that bears insufficient indications that the modifications are
// | not the work of the original author(s).
// |
// | This license applies to this document only, not any other software
// | that it may be combined with.
// |
// +----------------------------------------------------------------------+
// | Contributors:
// | https://www.anuko.com/time-tracker/credits.htm
// +----------------------------------------------------------------------+
// Class ttPredefinedExpenseHelper is used to help with predefined expense related tasks.
class ttPredefinedExpenseHelper {
// get - gets predefined expense details.
static function get($id) {
global $user;
$mdb2 = getConnection();
$group_id = $user->getGroup();
$org_id = $user->org_id;
$sql = "select id, name, cost from tt_predefined_expenses".
" where id = $id and group_id = $group_id and org_id = $org_id";
$res = $mdb2->query($sql);
if (!is_a($res, 'PEAR_Error')) {
$val = $res->fetchRow();
if ($val && $val['id']) {
if ('.' != $user->getDecimalMark())
$val['cost'] = str_replace('.', $user->getDecimalMark(), $val['cost']);
return $val;
}
}
return false;
}
// delete - deletes a predefined expense from tt_predefined_expenses table.
static function delete($id) {
global $user;
$mdb2 = getConnection();
$group_id = $user->getGroup();
$org_id = $user->org_id;
$sql = "delete from tt_predefined_expenses".
" where id = $id and group_id = $group_id and org_id = $org_id";
$affected = $mdb2->exec($sql);
if (is_a($affected, 'PEAR_Error'))
return false;
// Update entities_modified, too.
if (!ttGroupHelper::updateEntitiesModified())
return false;
return true;
}
// insert function inserts a new predefined expense into database.
static function insert($fields) {
global $user;
$mdb2 = getConnection();
$group_id = $user->getGroup();
$org_id = $user->org_id;
$name = $fields['name'];
$cost = $fields['cost'];
if ('.' != $user->getDecimalMark())
$cost = str_replace($user->getDecimalMark(), '.', $cost);
$sql = "insert into tt_predefined_expenses (group_id, org_id, name, cost)".
" values ($group_id, $org_id, ".$mdb2->quote($name).", ".$mdb2->quote($cost).")";
$affected = $mdb2->exec($sql);
if (is_a($affected, 'PEAR_Error'))
return false;
// Update entities_modified, too.
if (!ttGroupHelper::updateEntitiesModified())
return false;
return true;
}
// update function - updates a predefined expense in database.
static function update($fields) {
global $user;
$mdb2 = getConnection();
$group_id = $user->getGroup();
$org_id = $user->org_id;
$predefined_expense_id = (int) $fields['id'];
$name = $fields['name'];
$cost = $fields['cost'];
if ('.' != $user->getDecimalMark())
$cost = str_replace($user->getDecimalMark(), '.', $cost);
$sql = "update tt_predefined_expenses set name = ".$mdb2->quote($name).", cost = ".$mdb2->quote($cost).
" where id = $predefined_expense_id and group_id = $group_id and org_id = $org_id";
$affected = $mdb2->exec($sql);
if (is_a($affected, 'PEAR_Error'))
return false;
// Update entities_modified, too.
if (!ttGroupHelper::updateEntitiesModified())
return false;
return true;
}
}