Repository navigation
Expand file tree
/
Copy pathexpense_distribution.php
More file actions
148 lines (123 loc) · 4.99 KB
/
Copy pathexpense_distribution.php
File metadata and controls
148 lines (123 loc) · 4.99 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
<?php
require 'includes/common.php';
if (isset($_GET['id']))
{
$id = mysqli_real_escape_string($con, $_GET['id']);
$sql = "SELECT * FROM plan_details WHERE id=$id";
$result = mysqli_query($con, $sql);
$plan = mysqli_fetch_assoc($result);
$stmt= "SELECT * FROM names WHERE plan_id=$id ";
$rows = mysqli_query($con,$stmt);
$persons = mysqli_fetch_all($rows, MYSQLI_ASSOC);
$sql1 = "SELECT title, spent, id, by_person,date FROM new_expense WHERE plan_id = $id";
$res = mysqli_query($con,$sql1);
$expenses = mysqli_fetch_all($res, MYSQLI_ASSOC);
$query=mysqli_query($con,"SELECT SUM(spent) AS total FROM new_expense WHERE plan_id=$id");
$row = mysqli_fetch_assoc($query);
$sum = $row['total'];
$remaining= htmlspecialchars($plan['initial_budget'])-htmlspecialchars($sum);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Expense Distribution</title>
<link rel="stylesheet" href="styles.css" type="text/css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<?php
include 'includes/header.php';
?>
<div class="container" style="margin-top: 100px;">
<div class="panel panel-default" style="margin:auto; width: 50%;">
<div class="panel-heading" style="background-color: #00bca0; color:white; text-align:center;">
<?php echo htmlspecialchars($plan['title']); ?> <span class="glyphicon glyphicon-user" style="float: right;"> <?php echo htmlspecialchars($plan['no_of_people']); ?> </span>
</div>
<br>
<table style="width:100%; margin:20px; line-height:250%;">
<tr>
<td>Initial Budget</td>
<td> ₹ <?php echo htmlspecialchars($plan['initial_budget']); ?> </td>
</tr>
<?php
foreach ($persons as $person)
{
$name= htmlspecialchars($person['name']);
$necessary= mysqli_query($con, "SELECT SUM(spent) AS tot FROM new_expense WHERE by_person= '$name' AND plan_id=$id");
$rw = mysqli_fetch_assoc($necessary);
$req = $rw['tot'];
?>
<tr>
<td> <?php echo htmlspecialchars($person['name']); ?></td>
<td> ₹ <?php echo htmlspecialchars($req); ?></td>
</tr>
<?php }
?>
<tr>
<td>Total Amount Spent</td>
<td> ₹ <?php if($sum != NULL) echo htmlspecialchars($sum);
else echo 0; ?> </td>
</tr>
<td>Remaining Amount</>
<td> <?php if($remaining>0)
{
?>
<p style="color:#19FF19; display:inline"> ₹ <?php echo $remaining; ?></p>
<?php
}
else if ($remaining<0)
{
?>
<p style="color: red; display:inline;">₹ <?php echo $remaining; ?></p>
<?php }
else
{ ?>
<p style="color: black; display:inline;">₹ <?php echo $remaining; ?></p>
<?php } ?>
</td>
</tr>
<tr>
<td>Individual Shares</td>
<td>₹ <?php echo round($sum/ htmlspecialchars($plan['no_of_people'])); ?></td>
</tr>
<?php foreach ($persons as $person)
{ $name= htmlspecialchars($person['name']);
$necessary= mysqli_query($con, "SELECT SUM(spent) AS tot FROM new_expense WHERE by_person= '$name' AND plan_id=$id");
$rw = mysqli_fetch_assoc($necessary);
$req = $rw['tot'];
$display= htmlspecialchars($req)- round($sum/ htmlspecialchars($plan['no_of_people']));
?>
<tr>
<td> <?php echo htmlspecialchars($person['name']); ?></td>
<td> <?php
if ($display >0) { ?>
<p style="color:#19FF19; display:inline;"> <?php
echo 'Get back ₹'.$display; ?></p>
<?php
}
elseif ($display <0) {
?>
<p style="color: red; display:inline;"><?php echo 'Owes ₹'.abs($display); ?></p>
<?php }
else echo 'All Settled up.'?>
</td>
</tr>
<?php } ?>
</table>
<center><a href="viewplan.php?id=<?php echo htmlspecialchars($id);?>" class="btn" style="background-color: white; color:#00bca0; border: 1px solid #00bca0;"> <span class="glyphicon glyphicon-arrow-left"></span> Go Back </a></center>
<br>
</div>
</div>
<?php
include 'includes/footer.php';
?>
</body>
</html>