-
Notifications
You must be signed in to change notification settings - Fork 0
/
branch.php
453 lines (417 loc) · 18.9 KB
/
branch.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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
<?php
include 'includes/header.php';
include('functions.php');
include('database_connection.php');
if ($_SESSION["User_type"] == "Admin") {
$statement = $connect->prepare("
SELECT
Branch.id,
Branch.Name,
Branch.Address,
Branch.Phone,
Branch.PAN,
Branch.Branch_type,
accounts.username
FROM
Branch
JOIN accounts ON Branch.Linked_account = accounts.id
");
$statement->execute();
$all_result = $statement->fetchAll();
$total_rows = $statement->rowCount();
$name = $_SESSION['name'];
if (isset($_POST["Add"])) {
try {
echo
"<hr> Date: " . trim($_POST["Date"]) .
"<br> Bill_no: " . trim($_POST["Bill_no"]) .
"<br> Customers_name: " . trim($_POST["Customers_name"]) .
"<br> Customers_PAN_no: " . trim($_POST["Customers_PAN_no"]) .
"<br> Total_sales_amount: " . trim($_POST["Total_sales_amount"]) .
"<br> VAT_included_sales_amount: " . trim($_POST["VAT_included_sales_amount"]) .
"<br> VAT_included_sales_VAT: " . trim($_POST["VAT_included_sales_VAT"]) .
"<br> Branch: " . trim($_POST["Branch"]) .
"<hr>";
$statement = $connect->prepare("
INSERT INTO `Branch`(
`Name`,
`Address`,
`Phone`,
`PAN`,
`Branch_type`,
`Linked_account`
)
VALUES(
:Name,
:Address,
:Phone,
:PAN,
:Branch_type,
:Linked_account
);
");
$statement->execute(
array(
':Name' => trim($_POST["Name"]),
':Address' => trim($_POST["Address"]),
':Phone' => trim($_POST["Phone"]),
':PAN' => trim($_POST["PAN"]),
':Branch_type' => trim($_POST["Branch_type"]),
':Linked_account' => trim($_POST["Linked_account"])
)
);
$statement = $connect->query("SELECT LAST_INSERT_ID()");
$Linked_branch = $statement->fetchColumn();
$statement = $connect->prepare("
UPDATE
`accounts`
SET
`Linked_branch` = :Linked_branch
WHERE
`id` = :id
");
$statement->execute(
array(
':id' => trim($_POST["Linked_account"]),
':Linked_branch' => trim($Linked_branch)
)
);
echo "Added Sucessfully";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
header("location:branch.php");
}
if (isset($_GET["update"])) {
if (isset($_POST["Update"])) {
$id = $_GET["id"];
$statement = $connect->prepare("
UPDATE
`Branch`
SET
`Name` = :Name,
`Address` = :Address,
`Phone` = :Phone
WHERE
`id` = :id
");
$statement->execute(
array(
':Name' => trim($_POST["Name"]),
':Address' => trim($_POST["Address"]),
':Phone' => trim($_POST["Phone"]),
':id' => trim($id)
)
);
echo "Values updated sucessfully!";
header("location:branch.php");
}
}
if (isset($_GET["delete"]) && isset($_GET["id"])) {
$statement = $connect->prepare(
"DELETE FROM Branch WHERE id = :id"
);
$statement->execute(
array(
':id' => $_GET["id"]
)
);
header("location:branch.php");
}
} else {
echo '
<script>
alert("😡😡You are not allowed to view this page😡😡!");
window.top.location="index.php";
</script>
';
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Sales's List</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<meta name="robots" content="noindex, nofollow">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.20/js/dataTables.bootstrap4.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.20/css/dataTables.bootstrap4.min.css">
<!-- Custom fonts for this template-->
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
<link href="css/sb-admin-2.min.css" rel="stylesheet">
<style>
/* Remove the navbar's default margin-bottom and rounded borders */
.navbar {
margin-bottom: 4px;
border-radius: 0;
}
/* Add a gray background color and some padding to the footer */
footer {
background-color: #f2f2f2;
padding: 25px;
}
.carousel-inner img {
width: 100%;
/* Set width to 100% */
margin: auto;
min-height: 200px;
}
.navbar-brand {
padding: 5px 40px;
}
.navbar-brand:hover {
background-color: #ffffff;
}
/* Hide the carousel text when the screen is less than 600 pixels wide */
@media (max-width: 600px) {
.carousel-caption {
display: none;
}
}
</style>
</head>
<body>
<!-- Page Wrapper -->
<div id="wrapper">
<?php include("includes/sidebar.php"); ?>
<!-- Content Wrapper -->
<div id="content-wrapper" class="d-flex flex-column">
<!-- Main Content -->
<div id="content">
<?php include("includes/topbar.php"); ?>
<div class="container-fluid">
<?php
if (isset($_GET["add"])) {
?>
<div class="page-header">
<h2>Add Records</h2>
</div>
<p>Please fill this form and submit to add Branch record to the database.!</p>
<form id="Cheque_form" method="post">
<table id="data-table" class='table table-bordered table-striped'>
<tr>
<th>
<label for="name">Name</label>
</th>
<td>
<input type="text" name="Name" required class="form-control Name">
</td>
</tr>
<tr>
<th>
<label for="name">Address</label>
</th>
<td>
<input type="text" name="Address" class="form-control Address">
</td>
</tr>
<tr>
<th>
<label for="panno">Phone No</label>
</th>
<td>
<input type="number" name="Phone" id="Phone" class="form-control Phone">
</td>
</tr>
<tr>
<th>
<label for="panno">PAN No</label>
</th>
<td>
<input type="number" name="PAN" id="PAN" class="form-control PAN">
</td>
</tr>
<tr>
<th>
<label for="phone">Branch Type</label>
</th>
<td>
<select name="Branch_type" id="Branch" required class="form-control Branch">
<option value="Main Branch">Main Branch</option>
<option value="Sub Branch">Sub Branch</option>
</select>
</td>
</tr>
<tr>
<th>
<label for="phone">Linked Account</label>
</th>
<td>
<select name="Linked_account" id="Linked_account" required class="form-control Linked_account">
<?php
$statement = $connect->prepare("
SELECT id, username FROM accounts
");
$statement->execute();
$all_result = $statement->fetchAll();
foreach ($all_result as $row) {
echo '
<option value="' . $row["id"] . '">' . $row["username"] . '</option>
';
}
?>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" id="Add" class="btn btn-primary" value="Add" name="Add">
<a href="branch.php" class="btn btn-default">Cancel</a>
</td>
</tr>
</table>
</form>
<script>
$(document).ready(function() {
$('#Add').click(function() {
$('#Cheque_form').submit();
alert('Record added sucessfully!');
});
});
</script>
<?php
} elseif (isset($_GET["update"]) && isset($_GET["id"])) {
$statement = $connect->prepare("
SELECT * FROM Branch
WHERE id = :id
LIMIT 1
");
$statement->execute(
array(
':id' => $_GET["id"]
)
);
$result = $statement->fetchAll();
foreach ($result as $row) {
?>
<div class="page-header">
<h2>UpDate Branch</h2>
</div>
<p>Please fill this form and submit to UpDate Branch record to the database.</p>
<form id="Cheque_form" method="post">
<table id="data-table" class='table table-bordered table-striped'>
<tr>
<th>
<label for="name">Name</label>
</th>
<td>
<input type="text" name="Name" required class="form-control Name" value="<?php echo $row["Name"]; ?>">
</td>
</tr>
<tr>
<th>
<label for="name">Address</label>
</th>
<td>
<input type="text" name="Address" class="form-control Address" value="<?php echo $row["Address"]; ?>">
</td>
</tr>
<tr>
<th>
<label for="panno">Phone No</label>
</th>
<td>
<input type="number" name="Phone" id="Phone" class="form-control Phone" value="<?php echo $row["Phone"]; ?>">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" id="Update" class="btn btn-primary" value="Update" name="Update">
<a href="branch.php" class="btn btn-default">Cancel</a>
</td>
</tr>
</table>
</form>
<script>
$(document).ready(function() {
$('#Update').click(function() {
$('#Cheque_form').submit();
alert('Record Updated sucessfully!');
});
});
</script>
<?php
}
} else {
?>
<div class="page-header clearfix">
<h2 class="pull-left">Branch's List</h2>
<a href="branch.php?add=1" class="btn btn-success pull-right">Add New Record</a><br><br>
</div>
<div id="Ratelist" class="table-responsive">
<table id="data-table" class='table table-bordered table-striped'>
<thead>
<tr>
<td>#</td>
<td>Name</td>
<td>Address</td>
<td>Phone</td>
<td>PAN no</td>
<td>Branch Type</td>
<td>Linked Account</td>
<td>Edit</td>
<td>Delete</td>
</tr>
</thead>
<tbody>
<?php
if ($total_rows > 0) {
$sum = 0;
foreach ($all_result as $row) {
$sum = $sum + $row["Total_sales_amount"];
echo '
<tr>
<td>' . $row["id"] . '</td>
<td>' . $row['Name'] . '</td>
<td>' . $row['Address'] . '</td>
<td>' . $row['Phone'] . '</td>
<td>' . $row['PAN'] . '</td>
<td>' . $row['Branch_type'] . '</td>
<td>' . $row['username'] . '</td>
<td><a href="branch.php?update=1&id=' . $row["id"] . '">Edit</a></td>
<td><a href="branch.php?delete=1&id=' . $row["id"] . '">Delete</a></td>
</tr>
';
}
}
?>
</tbody>
</table>
</div>
<?php } ?>
</div>
</div>
<?php include("includes/footer.php"); ?>
</div>
</div>
</body>
</html>
<script type="text/javascript">
$(document).ready(function() {
$('#Name').chosen();
$('#data-table').DataTable();
$('#date').datepicker({
format: "yyyy-mm-dd",
autoclose: true
});
});
</script>
<!-- Bootstrap core JavaScript-->
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Core plugin JavaScript-->
<script src="vendor/jquery-easing/jquery.easing.min.js"></script>
<!-- Custom scripts for all pages-->
<script src="js/sb-admin-2.min.js"></script>