This repository has been archived by the owner on Feb 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
tiki-accounting_account.php
157 lines (146 loc) · 4.76 KB
/
tiki-accounting_account.php
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/**
* @package tikiwiki
*/
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
$section = 'accounting';
require_once('tiki-setup.php');
$access->checkAuthenticity();
// Feature available?
if ($prefs['feature_accounting'] != 'y') {
$smarty->assign('msg', tra("This feature is disabled") . ": feature_accounting");
$smarty->display("error.tpl");
die;
}
if (! isset($_REQUEST['bookId'])) {
$smarty->assign('msg', tra("Missing book id"));
$smarty->display("error.tpl");
die;
}
$bookId = $_REQUEST['bookId'];
$smarty->assign('bookId', $bookId);
$accountinglib = TikiLib::lib('accounting');
$book = $accountinglib->getBook($bookId);
$smarty->assign('book', $book);
$globalperms = Perms::get();
$objectperms = Perms::get([ 'type' => 'accounting book', 'object' => $bookId ]);
if (! isset($_REQUEST['action'])) {
$_REQUEST['action'] = '';
}
if ($_REQUEST['action'] != 'new' and ! isset($_REQUEST['accountId'])) {
$smarty->assign('msg', tra("Missing account id"));
$smarty->display("error.tpl");
die;
}
$smarty->assign('action', $_REQUEST['action']);
if ($_REQUEST['action'] == '' or $_REQUEST['action'] == 'view') {
if (! ($globalperms->acct_view or $objectperms->acct_view or
$globalperms->acct_book or $objectperms->acct_book)) {
$smarty->assign('msg', tra("You do not have the rights to view this account"));
$smarty->display("error.tpl");
die;
}
} else {
if (! ($globalperms->acct_manage_accounts or $objectperms->acct_manage_accounts)) {
$smarty->assign('msg', tra("You do not have the rights to manage accounts"));
$smarty->display("error.tpl");
die;
}
}
$accountId = $_REQUEST['accountId'];
$smarty->assign('accountId', $accountId);
$journal = $accountinglib->getJournal($bookId, $accountId);
$smarty->assign('journal', $journal);
if ($access->ticketMatch()) {
switch ($_REQUEST['action']) {
case 'edit':
$template = "tiki-accounting_account_form.tpl";
if (isset($_REQUEST['accountName'])) {
if (! isset($_REQUEST['newAccountId'])) {
$_REQUEST['newAccountId'] = $accountId;
}
$result = $accountinglib->updateAccount(
$bookId,
$accountId,
$_REQUEST['newAccountId'],
$_REQUEST['accountName'],
$_REQUEST['accountNotes'],
$_REQUEST['accountBudget'],
$_REQUEST['accountLocked'],
0 /*$_REQUEST['accountTax'] */
);
if ($result !== true) {
$smarty->assign('errors', $result);
} else {
$smarty->assign('action', 'view');
$template = "tiki-accounting_account_view.tpl";
}
}
$account = $accountinglib->getAccount($bookId, $accountId, true);
$smarty->assign('account', $account);
break;
case 'new':
$template = "tiki-accounting_account_form.tpl";
if (isset($_REQUEST['accountName'])) {
$result = $accountinglib->createAccount(
$bookId,
$_REQUEST['newAccountId'],
$_REQUEST['accountName'],
$_REQUEST['accountNotes'],
$_REQUEST['accountBudget'],
$_REQUEST['accountLocked'],
0 /*$_REQUEST['accountTax'] */
);
if ($result !== true) {
$smarty->assign('errors', $result);
} else {
$smarty->assign('action', 'view');
$template = "tiki-accounting_account_view.tpl";
}
$account = [
'accountBookId' => $bookId,
'accountId' => $_REQUEST['newAccountId'],
'accountName' => $_REQUEST['accountName'],
'accountNotes' => $_REQUEST['accountNotes'],
'accountBudget' => $_REQUEST['accountBudget'],
'accountLocked' => $_REQUEST['accountLocked'],
'accountTax' => $_REQUEST['accountTax'],
'changeable' => true
];
} else {
$account = ['changeable' => true];
}
$smarty->assign('account', $account);
break;
case 'lock':
$accountinglib->changeAccountLock($bookId, $accountId);
$account = $accountinglib->getAccount($bookId, $accountId, true);
$smarty->assign('account', $account);
$template = "tiki-accounting_account_view.tpl";
break;
case 'delete':
$account = $accountinglib->getAccount($bookId, $accountId, true);
$smarty->assign('account', $account);
$result = $accountinglib->deleteAccount($bookId, $accountId);
if ($result === true) {
$template = "tiki-accounting_account_deleted.tpl";
} else {
$smarty->assign('errors', $result);
$account = $accountinglib->getAccount($bookId, $accountId, true);
$smarty->assign('account', $account);
$template = "tiki-accounting_account_form.tpl";
}
break;
}
}
$account = $accountinglib->getAccount($bookId, $accountId, true);
$smarty->assign('account', $account);
if (! $template) {
$template = "tiki-accounting_account_view.tpl";
}
$smarty->assign('mid', $template);
$smarty->display("tiki.tpl");