-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbills.php
More file actions
296 lines (234 loc) · 8.12 KB
/
bills.php
File metadata and controls
296 lines (234 loc) · 8.12 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
291
292
293
294
295
296
<?php
session_start();
if (!isset($_SESSION['auth'])) {
$_SESSION['msg'] = "You must log in first";
header('location: login.php');
}
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['auth']);
header("location: login.php");
}
include('functions.php');
update_accounts();
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css">
</head>
<body>
<div class="header" style="border-bottom: 8px solid #f2e711;">
<h2 class="Welcome">Nigga rigged accounting (beta)</h2>
<div class="relative">
<style>
a {
text-decoration: none;
color: #ffffff;
}
</style>
</div>
<?php $site = basename(__FILE__, '.php');
include('server.php');
home_bar($site);
?>
<h2 style="text-align:center" class="Welcome">Summary of bills</h2>
<!-- table style -->
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
<!-- Test table with db data -->
<table style="margin-left:0%; width: 100%; border-radius:0px; text-align:center;" border="2">
<tbody>
<tr>
<strong>
<td><strong>Bill Name</strong></td>
<td><strong>Bill Amount</strong></td>
<td><strong>Bill D.O.M</strong></td>
<td><strong>Bill Category</strong></td>
<td><strong>Delete ?</strong></td>
</tr>
<?php
summary_bills();
?>
</tbody>
</table>
</br>
<h2 style="text-align:center" class="Welcome">Update bills</h2>
<div>
<form style="height:100%; width:90%; margin: auto;" method="post" action="bills.php" enctype="multipart/form-data">
<?php include('errors.php'); ?>
<!-- event head -->
<div class="input-group" style="width:50%; margin:auto;">
<label>Select the bill</label>
<select style="width:100%; height:70%;" name="bill_name" id="bill_name">
<?php
$query = "SELECT * FROM Budget.Bills WHERE Bill_owner = '$user'";
$result = mysqli_query($db, $query);
// Counting system
$x = 1;
while($row = mysqli_fetch_assoc($result)) {
$name = $row['Bill_title'];
echo " <option value=\"$name\"> $x. $name </option>";
$x++;
}
?>
</select>
</div>
<!-- event head email -->
<div class="input-group" style="width:50%; margin:auto;">
<label>Set new amount</label>
<input type="text" name="bill_amount">
</div>
<div class="input-group">
<button style="margin-left:25%;" type="submit" class="btn-login" name="bill_update">Submit Change</button>
</div>
</form>
<!-- THE FOR FOR CREATING THE BUDGET DATE -->
<h2 style="text-align:center" class="Welcome">Setting your budget timeframe</h2>
<div>
<form style="height:100%; width:90%; margin: auto;" method="post" action="bills.php" enctype="multipart/form-data">
<?php include('errors.php'); ?>
<!-- event head -->
<div class="input-group" style="width:50%; margin:auto;">
<label>number of days in your pay cycle</label>
<select style="width:100%; height:70%;" name="budget_day" id="budget_day">
<?php
$size = 30;
for($i = 0; $i < $size; $i++) {
echo " <option value=\"$i\"> $i </option>";
}
?>
</select>
</div>
<!-- event head email -->
<div class="input-group" style="width:50%; margin:auto;">
<label>Last pay day</label>
<input type="date" name="last_day">
</div>
<!-- event head email -->
<div class="input-group" style="width:50%; margin:auto;">
<label>Last check</label>
<input type="text" name="last_pay">
</div>
<div class="input-group">
<button style="margin-left:25%;" type="submit" class="btn-login" name="budget_update">Submit Change</button>
</div>
</form>
<!-- Creating New bills -->
<h2 style="text-align:center" class="Welcome">Adding new bills</h2>
<div>
<form style="height:100%; width:90%; margin: auto;" method="post" action="bills.php" enctype="multipart/form-data">
<?php include('errors.php'); ?>
<div class="input-group" style="width:50%; margin:auto;">
<label>Name of the bill</label>
<input type="text" name="name">
</div>
<div class="input-group" style="width:50%; margin:auto;">
<label>Description</label>
<input type="text" name="description">
</div>
<div class="input-group" style="width:50%; margin:auto;">
<label>Account</label>
<select style="width:100%; height:70%;" name="account" id="account">
<?php
$query = "SELECT * FROM Budget.Accounts WHERE Account_Owner = '$user' ";
$result = mysqli_query($db, $query);
// Counting system
$x = 1;
while($row = mysqli_fetch_assoc($result)) {
$account_name = $row['Account_name'];
echo " <option value=\"$account_name\"> $x. $account_name </option>";
$x++;
}
?>
</select>
</div>
<!-- Selecting category -->
<div class="input-group" style="width:50%; margin:auto;">
<label>Bill Category</label>
<select style="width:100%; height:70%;" name="charge_catg" id="charge_catg">
<?php
$query = "SELECT * FROM Budget.Budget_$user ";
$result = mysqli_query($db, $query);
// Counting system
$x = 1;
while($row = mysqli_fetch_assoc($result)) {
$category = $row['Category'];
$san_category = display_category($category);
echo " <option value=\"$category\"> $x. $san_category </option>";
$x++;
}
?>
</select>
</div>
<div class="input-group" style="width:50%; margin:auto;">
<label> Amount </label>
<input type="number" name="amount" step="0.25" min="0">
</div>
<!-- event head -->
<div class="input-group" style="width:50%; margin:auto;">
<label>Day of the month charged</label>
<select style="width:100%; height:70%;" name="charge_day" id="charge_day">
<?php
$size = 31;
for($i = 1; $i < $size; $i++) {
echo " <option value=\"$i\"> $i </option>";
}
?>
</select>
</div>
<!-- event head email -->
<div class="input-group" style="width:50%; margin:auto;">
<label>Split between check ?</label>
<input style="left:0;" type="checkbox" name="split">
</div>
<div class="input-group">
<button style="margin-left:25%;" type="submit" class="btn-login" name="budget_bill">Submit Bill</button>
</div>
</form>
<!-- DONE -->
</body>
<?php
if (isset($_POST['bill_update'])) {
$name = mysqli_real_escape_string($db, $_POST['bill_name']);
$price = mysqli_real_escape_string($db, $_POST['bill_amount']);
$query = "SELECT uid FROM Budget.Bills WHERE Bill_title = '$name'";
$result = mysqli_query($db, $query);
$data = mysqli_fetch_assoc($result);
$bill_id = $data['uid'];
update_bill($name, $price, $bill_id);
}
if (isset($_POST['budget_update'])) {
$term_num = mysqli_real_escape_string($db, $_POST['budget_day']);
$term = "$term_num days";
$date = mysqli_real_escape_string($db, $_POST['last_day']);
$paid = mysqli_real_escape_string($db, $_POST['last_pay']);
// echo "$user $date $term $term_num $paid";
create_budget_entry($user, $date, $term, $term_num, $paid);
}
if (isset($_POST['budget_bill'])) {
$charge_day = mysqli_real_escape_string($db, $_POST['charge_day']);
$charge_amnt = mysqli_real_escape_string($db, $_POST['amount']);
$charge_acnt = mysqli_real_escape_string($db, $_POST['account']);
$charge_desc = mysqli_real_escape_string($db, $_POST['description']);
$charge_name = mysqli_real_escape_string($db, $_POST['name']);
$charge_catg = mysqli_real_escape_string($db, $_POST['catg']);
if ( $_POST['split'] == 'Yes' ) {
$split = 1;
} else {
$split = 0;
}
if (add_bill($charge_name,$charge_desc,$charge_acnt,$charge_amnt,$charge_day,$charge_catg,$split) == 'true') {
echo '<script type="text/javascript">';
echo "alert('Bill created ".$charge_name." !');";
echo 'window.location.href = "bills.php";';
echo '</script>';
}
}
?>