-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexpenses.php
321 lines (266 loc) · 13 KB
/
expenses.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
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<?php
include_once('lock.php');
include_once('config.db.php');
include_once('date_handler.php');
include_once('dbplugin.php');
include_once('plugins/html_table.class.php');
include_once('plugins/KLogger.php');
$deleteB = "<button class=\"ui-state-default ui-corner-all\" title=\"edit record\"><span class=\"ui-icon ui-icon-trash\"></span></button>";
$editB = "<button class=\"ui-state-default ui-corner-all\" title=\"delete record\"><span class=\"ui-icon ui-icon-pencil\"></span></button>";
$error = $_GET['error'];
$success = $_GET['success'];
// number of rows per page
$page_rows = 10;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>expense tracker | Expense Management</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen"/>
<link rel="stylesheet" href="css/pagination.css" type="text/css" media="screen"/>
<!-- calender -->
<link type="text/css" href="scripts/jquery/css/smoothness/jquery-ui-1.10.3.custom.css" rel="stylesheet"/>
<script type="text/javascript" src="scripts/jquery/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="scripts/jquery/js/jquery-ui-1.10.3.custom.js"></script>
<style type="text/css">
table.demoTbl {
border-collapse: collapse;
border-spacing: 0;
}
#tblCap {
font-weight: bold;
font-size: 15px;
margin: 1em auto .4em;
}
table.demoTbl .desc {
width: 250px;
}
table.demoTbl .category {
width: 150px;
}
table.demoTbl .amount {
width: 100px;
}
table.demoTbl .actions {
width: 50px;
}
table.demoTbl td, table.demoTbl th {
padding: 1px;
}
table.demoTbl th.first {
text-align: center;
padding: 3px;
background-color: #CCCCCC;
border: 2px solid #FFFFFF;
}
table.demoTbl td.num {
text-align: right;
padding-right: 5px;
}
table.demoTbl td.cat {
text-align: center;
}
table.demoTbl td.foot {
text-align: center;
}
</style>
<script type="text/javascript">
$(function () {
// Datepicker
$('#datepickerd').datepicker({
inline: true,
altField: '#datepicker_send'
});
// Button
$("#button").button();
});
</script>
</head>
<body>
<div id="container">
<?php include("header.php"); ?>
<?php include("menu.php"); ?>
<div id="content">
<div id="main_content">
<h2>Expense Management</h2><br>
<div id="form_content">
<form id="addexpense" action='expense_handler.php' method='post'>
<div id="form_left">
<div name="datepickerd" id="datepickerd"></div>
<input type="hidden" id="datepicker_send" name="datepicker_send">
</div>
<table width='300px' border='0' cellpadding='5' cellspacing='0'>
<tr>
<td style="text-align:right;"><label>Description :</label></td>
<td style="text-align:left;"><input id="desc" name="desc" type="text"
style="width: 175px; height: 20px"></td>
</tr>
<tr>
<td style="text-align:right;"><label>Category :</label></td>
<td style="text-align:left;">
<?php
$getcatsql = "SELECT id,category from category WHERE status='ACTIVE'";
$cat_result = mysqli_query($db, $getcatsql);
echo "<select name=\"cat\" style=\"width: 175px; height: 25px\">";
while ($row = mysqli_fetch_array($cat_result)) {
$id = $row['id'];
$ctgry = $row['category'];
echo "<option value='" . $id . "'>" . $ctgry . "</option>";
}
echo "</select>";
?>
</td>
</tr>
<tr>
<td style="text-align:right;"><label>Amount :</label></td>
<td style="text-align:left;"><input id="aamount" name="aamount" type="text"
style="width: 175px; height: 20px"></td>
</tr>
<tr>
<td></td>
<td style="text-align:left;">
<button id="button" type="submit">Add Expense</button>
</td>
</tr>
</table>
</form>
<br><br>
<div style="padding-left:50px; font-size:15px; color:#FF0000;"><?php echo $error; ?></div>
<div style="padding-left:50px; font-size:15px; color:#19aa2f;"><?php echo $success; ?></div>
<br><br>
<?php
$log = new KLogger ("/var/www/extracker/logs/", KLogger::DEBUG);
$crntYear = getYear();
$crntMonth = getMonth();
$crntDay = getDay();
// pagination
$pagenum = $_GET['pagenum'];
// populate table
$fill = "SELECT id,description,category_id,amount FROM expences WHERE year='$crntYear' AND month='$crntMonth' AND day='$crntDay'";
$result = mysqli_query($db, $fill);
$rowcount = mysqli_num_rows($result);
if ($rowcount >= 1) {
// arguments: id, class, border,
// can include associative array of optional additional attributes
$tbl = new HTML_Table('', 'demoTbl', 0);
$tbl->addCaption('Today\'s Expenses', 'cap', array('id' => 'tblCap'));
$tbl->addColgroup();
// span, class
$tbl->addCol(0, 'desc');
$tbl->addCol(1, 'category');
$tbl->addCol(2, 'amount');
$tbl->addCol(3, 'actions');
// thead
$tbl->addTSection('thead');
$tbl->addRow();
// arguments: cell content, class, type (default is 'data' for td, pass 'header' for th)
// can include associative array of optional additional attributes
$tbl->addCell('Description', 'first', 'header');
$tbl->addCell('Category', 'first', 'header');
$tbl->addCell('Amount (Rs)', 'first', 'header');
$tbl->addCell('Actions', 'first', 'header');
// tfoot
$tbl->addTSection('tfoot');
$tbl->addRow();
// span all 3 columns
$tbl->addCell('', 'foot', 'data', array('colspan' => 4));
// tbody
$tbl->addTSection('tbody');
if (!(isset($pagenum))) {
$pagenum = 1;
}
//This tells us the page number of our last page
$last = ceil($rowcount / $page_rows);
//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1) {
$pagenum = 1;
} elseif ($pagenum > $last) {
$pagenum = $last;
}
//This sets the range to display in our query
$max = 'limit ' . ($pagenum - 1) * $page_rows . ',' . $page_rows;
//This is your query again, the same one... the only difference is we add $max into it
$data_p = mysqli_query($db, $fill . $max) or die(mysql_error());
while ($row = mysqli_fetch_array($data_p)) {
$desc = $row['description'];
$cats = getCategoryName($db, $row['category_id']);
$amount = number_format($row['amount'], 2);
$recId = $row['id'];
$actions = "<a href=\"javascript:void(null);\" onclick=\"document.getElementById('myform" . $recId . "').submit();\"><button class=\"ui-state-default ui-corner-all\" title=\"delete record\" onclick=\"deleteRecord($recId)\"><span class=\"ui-icon ui-icon-trash\"></span></button></a>";
echo "<form id=\"myform" . $recId . "\" action=\"expense_handler.php\" method=\"post\"><input type=\"hidden\" name=\"recId\" value=\"" . $recId . "\" /><input type=\"hidden\" name=\"amount\" value=\"" . $amount . "\" /></form>";
$tbl->addRow();
$tbl->addCell($desc);
$tbl->addCell($cats, 'cat');
$tbl->addCell($amount, 'num');
$tbl->addCell($actions, 'cat');
}
echo $tbl->display();
echo "<br>";
$html = '';
$current_page = $pagenum;
if ($current_page != 1) {
$html .= '<a class="first" title="First" href="expenses.php?pagenum=1">«</a>';
$previousPageNumber = $current_page - 1;
$previousPage = "expenses.php?pagenum=" . $previousPageNumber;
$html .= '<a class="first" title="Previous" href=' . $previousPage . '>Previous</a>';
} else {
$html .= '<span class="disabled first" title="First">«</span>';
$html .= '<span class="disabled first" title="Previous">Previous</span>';
}
for ($i = 1; $i <= $last; $i++) {
if ($i != $current_page) {
$pageNumber = "expenses.php?pagenum=" . $i;
$html .= '<a title="' . $i . '" href=' . $pageNumber . '>' . $i . '</a>';
} else {
$html .= '<span class="current">' . $i . '</span>';
}
}
if ($current_page != $last) {
$nextPageNumber = $current_page + 1;
$nextPage = "expenses.php?pagenum=" . $nextPageNumber;
$html .= '<a class="next" title="Next" href=' . $nextPage . '>Next</a>';
$lastPage = "expenses.php?pagenum=" . $last;
$html .= '<a class="last" title="Last" href=' . $lastPage . '>»</a>';
} else {
$html .= '<span class="disabled next" title="Next">Next</span>';
$html .= '<span class="disabled last" title="Last">»</span>';
}
echo '<div class="pagination">' . $html . '</div>';
} else {
$tbl = new HTML_Table('', 'demoTbl', 0);
$tbl->addCaption('Today\'s Expenses', 'cap', array('id' => 'tblCap'));
$tbl->addColgroup();
// span, class
$tbl->addCol(0, 'desc');
$tbl->addCol(1, 'category');
$tbl->addCol(2, 'amount');
$tbl->addCol(3, 'actions');
// thead
$tbl->addTSection('thead');
$tbl->addRow();
// arguments: cell content, class, type (default is 'data' for td, pass 'header' for th)
// can include associative array of optional additional attributes
$tbl->addCell('Description', 'first', 'header');
$tbl->addCell('Category', 'first', 'header');
$tbl->addCell('Amount (Rs)', 'first', 'header');
$tbl->addCell('Actions', 'first', 'header');
$tbl->addTSection('tbody');
$tbl->addRow();
// span all 3 columns
$tbl->addCell('<br><br><b>No Data to Display</b>', 'foot', 'data', array('colspan' => 4));
echo $tbl->display();
}
?>
</div>
</div>
<div id="summary_content">
<?php include("stats.php"); ?>
</div>
<div id="clearfix"></div>
</div>
<?php include("footer.php"); ?>
</div>
</body>
</html>