-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexpense_reports.php
More file actions
290 lines (273 loc) · 13.2 KB
/
expense_reports.php
File metadata and controls
290 lines (273 loc) · 13.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/global.inc.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/expense_reports.inc.php";
connectToDatabase();
if(!isset($_SESSION['role'])) {
unauthorized();
}
if($_SESSION['role'] !== COLLABORATOR_ROLE && $_SESSION['role'] !== MANAGER_ROLE && $_SESSION['role'] !== FINANCIAL_APPROVER_ROLE) {
forbidden();
}
if(isset($_POST['create_expense']) && $_POST['create_expense'] === "create_expense") {
createExpense($_POST['amount'], $_POST['comment'], $_POST['csrf_token']);
}
if(isset($_POST['action'])) {
saveActionExpenseReport($_POST['id'], $_POST['action'], $_POST['csrf_token']);
}
if(isset($_POST['confirmActionExpenseReport']) && $_POST['confirmActionExpenseReport'] === 'yes') {
switch ($_SESSION['action']) {
case "deleteExpenseReport":
deleteExpense($_POST['csrf_token']);
break;
case "submitExpenseReport":
submitExpense($_POST['csrf_token']);
break;
case "refuseExpenseReport":
refuseExpense($_POST['csrf_token']);
break;
case "validateExpenseReport":
validateExpense($_POST['csrf_token']);
break;
case "sentForPaymentExpenseReport":
sendForPaymentExpense($_POST['csrf_token']);
break;
}
unset($_SESSION['id_action']);
unset($_SESSION['action']);
}
if(isset($_POST['confirmActionExpenseReport']) && $_POST['confirmActionExpenseReport'] !== 'yes') {
unset($_SESSION['id_action']);
unset($_SESSION['action']);
}
$expense_reports = retrieveExpenseReports();
if(isset($_SESSION['role']) && ($_SESSION['role'] === MANAGER_ROLE || $_SESSION['role'] === FINANCIAL_APPROVER_ROLE)) {
$expense_reports_collabs = retrieveExpenseReportsCollaborators();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="/css/bootstrap.css"/>
<link rel="stylesheet" href="/css/style.css"/>
<title>Futura Business Informatique GROUPE - Conseil en ingénierie</title>
<link rel="icon" type="image/png" sizes="32x32" href="/img/favicon-32x32.png">
</head>
<body>
<div class="container-fluid">
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . "/includes/header.inc.php";
include_once $_SERVER['DOCUMENT_ROOT'] . "/includes/messages_dialog.inc.php";
?>
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
<?php
if(isset($_POST['action'])) {
?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Confirm your action</h3>
</div>
<div class="panel-body">
<form class="col-md-4 col-md-offset-4" action="/expense_reports.php" method="POST">
<?php
if(isset($_POST['action'])) {
$action = 1;
switch ($_POST['action']) {
case "deleteExpenseReport":
echo '<legend>Are you sure to want to delete this expense report ?</legend>';
break;
case "submitExpenseReport":
echo '<legend>Are you sure to want to submit this expense report ?</legend>';
break;
case "refuseExpenseReport":
echo '<legend>Are you sure to want to refuse this expense report ?</legend>';
break;
case "validateExpenseReport":
echo '<legend>Are you sure to want to validate this expense report ?</legend>';
break;
case "sentForPaymentExpenseReport":
echo '<legend>Are you sure to want to send for payment this expense report ?</legend>';
break;
default:
$action = 0;
}
}
if($action === 1) {
?>
<div class="form-group">
<button type="submit" class="btn btn-success form-control" name="confirmActionExpenseReport" value="yes">Yes</button>
</div>
<div class="form-group">
<button type="submit" class="btn btn-danger form-control" name="confirmActionExpenseReport" value="no">No</button>
</div>
<?php
echo '<input id="csrf_token" type="hidden" name="csrf_token" value=' . $_SESSION['csrf_token'] . ' autocomplete="off">';
?>
</form>
<?php
}
?>
</div>
</div>
<?php
}
?>
<?php
if($_SESSION['role'] === MANAGER_ROLE || $_SESSION['role'] === FINANCIAL_APPROVER_ROLE) {
?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Collaborators Expense reports</h3>
</div>
<div class="panel-body">
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th class="text-center">Date</th>
<th class="text-center">Collaborator's name</th>
<th class="text-center">Amount</th>
<th class="text-center">Comment</th>
<th class="text-center">Status</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
<?php
foreach ($expense_reports_collabs as $row) {
?>
<tr>
<?php
echo '<td class="text-center col-md-2">' . htmlspecialchars($row['expense_date']) . '</td>';
echo '<td class="text-center col-md-2">' . htmlspecialchars($row['firstname']) . ' ' . htmlspecialchars($row['lastname']) . '</td>';
echo '<td class="text-center col-md-2">' . htmlspecialchars($row['amount']) . ' €' . '</td>';
echo '<td>' . htmlspecialchars($row['comment']) . '</td>';
echo '<td class="text-center col-md-2">' . htmlspecialchars($row['status']) . '</td>';
if(isset($row['status']) && $row['status'] === SUBMITTED) {
?>
<td class="text-center col-md-1" style="vertical-align: middle;">
<form action="/expense_reports.php" method="POST">
<?php
echo '<input type="hidden" name="id" value="' . htmlspecialchars($row['id']) . '" />';
?>
<?php
echo '<input id="csrf_token" type="hidden" name="csrf_token" value=' . $_SESSION['csrf_token'] . ' autocomplete="off">';
?>
<button type="submit" class="btn btn-danger btn-xs" name="action" value="refuseExpenseReport" title="Refuse Expense Report"><span class="glyphicon glyphicon-remove"></span></button>
<button type="submit" class="btn btn-success btn-xs" name="action" value="validateExpenseReport" title="Validate Expense Report"><span class="glyphicon glyphicon-ok"></span></button>
</form>
</td>
<?php
}
if(isset($row['status']) && $row['status'] === VALIDATED && isset($_SESSION['role']) && $_SESSION['role'] === FINANCIAL_APPROVER_ROLE) {
?>
<td class="text-center col-md-1" style="vertical-align: middle;">
<form action="/expense_reports.php" method="POST">
<?php
echo '<input type="hidden" name="id" value="' . htmlspecialchars($row['id']) . '" />';
?>
<?php
echo '<input id="csrf_token" type="hidden" name="csrf_token" value=' . $_SESSION['csrf_token'] . ' autocomplete="off">';
?>
<button type="submit" class="btn btn-danger btn-xs" name="action" value="refuseExpenseReport" title="Refuse Expense Report"><span class="glyphicon glyphicon-remove"></span></button>
<button type="submit" class="btn btn-success btn-xs" name="action" value="sentForPaymentExpenseReport" title="Sent For Payment Expense Report"><span class="glyphicon glyphicon-euro"></span></button>
</form>
</td>
<?php
}
?>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<?php
}
?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">My Expense reports</h3>
</div>
<div class="panel-body">
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th class="text-center">Date</th>
<th class="text-center">Amount</th>
<th class="text-center">Comment</th>
<th class="text-center">Status</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
<?php
foreach ($expense_reports as $row) {
?>
<tr>
<?php
echo '<td class="text-center col-md-2">' . htmlspecialchars($row['expense_date']) . '</td>';
echo '<td class="text-center col-md-2">' . htmlspecialchars($row['amount']) . ' €' . '</td>';
echo '<td>' . htmlspecialchars($row['comment']) . '</td>';
echo '<td class="text-center col-md-2">' . htmlspecialchars($row['status']) . '</td>';
if(isset($row['status']) && $row['status'] === OPENED) {
?>
<td class="text-center col-md-1" style="vertical-align: middle;">
<form action="/expense_reports.php" method="POST">
<?php
echo '<input type="hidden" name="id" value="' . htmlspecialchars($row['id']) . '" />';
?>
<?php
echo '<input id="csrf_token" type="hidden" name="csrf_token" value=' . $_SESSION['csrf_token'] . ' autocomplete="off">';
?>
<button type="submit" class="btn btn-danger btn-xs" name="action" value="deleteExpenseReport" title="Delete Exepense Report"><span class="glyphicon glyphicon-trash"></span></button>
<button type="submit" class="btn btn-success btn-xs" name="action" value="submitExpenseReport" title="Submit Exepense Report"><span class="glyphicon glyphicon-ok"></span></button>
</form>
</td>
<?php
}
?>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<?php
if(isset($_SESSION['role'])) {
?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">New expense report</h3>
</div>
<div class="panel-body">
<form class="form-inline text-center" action="/expense_reports.php" method="POST">
<div class="form-group">
<label for="amount">Amount (€) :</label>
<input id="amount" type="text" name="amount" class="form-control" size="5" placeholder="300">
</div>
<div class="form-group">
<label for="comment">Comment: </label>
<input id="comment" name="comment" class="form-control" size="30" placeholder="Séminaire du 12/06/2018">
</div>
<?php
echo '<input id="csrf_token" type="hidden" name="csrf_token" value=' . $_SESSION['csrf_token'] . ' autocomplete="off">';
?>
<button type="submit" class="btn btn-primary" name="create_expense" value="create_expense">Create</button>
</form>
</div>
</div>
<?php
}
?>
</div>
</div>
</div>
</body>
</html>