-
Notifications
You must be signed in to change notification settings - Fork 0
/
apartmentDetails.php
309 lines (269 loc) · 11.6 KB
/
apartmentDetails.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
<?php
require("session.php");
require "connect.php";
$apartment = "";
if (isset($_POST["delete"])) {
$id_to_delete = mysqli_real_escape_string($conn, $_POST['id_to_delete']);
$sql = "DELETE FROM apartment WHERE apartment_id='$id_to_delete'";
if (mysqli_query($conn, $sql)) {
//successfullt deleted
header("Location: index.php");
} else {
//failure
echo 'query error:' . mysqli_error($conn);
}
}
if (isset($_GET["id"])) {
$id = mysqli_real_escape_string($conn, $_GET['id']);
$sql = "SELECT apartment_id,
apartment.name AS 'name',
owner.owner_id as 'owner_id',
owner.name AS owner_name,
owner.phone AS owner_phone,
type,
town,
location,
description
FROM
apartment
JOIN owner ON
owner.owner_id = apartment.owner_id
WHERE apartment_id='$id';";
$result = mysqli_query($conn, $sql);
$apartment = mysqli_fetch_assoc($result);
$sql = "SELECT
house.house_id,
house_no,
house.type,
rent,
house.description,
apartment.town,
apartment.location,
apartment.apartment_id,
apartment.name AS 'apartment_name',
owner.owner_id,
owner.name AS 'owner_name',
assigned.tenant_id
FROM
house
JOIN apartment ON house.apartment_id='$id' AND apartment.apartment_id = house.apartment_id
JOIN owner ON apartment.owner_id = owner.owner_id
LEFT JOIN assigned ON assigned.house_id = house.house_id
ORDER BY house_no;";
$result = mysqli_query($conn, $sql);
$houses = mysqli_fetch_all($result, MYSQLI_ASSOC);
$isVacant = false;
foreach ($houses as $house) {
if (!isset($house["tenant_id"])) {
$isVacant = true;
break;
}
}
}
?>
<?php include "header.php" ?>
<div class="banner_blur ">
<div class="flex-1 min-w-0 p-5">
<div class=" flex items-center ">
<div class=" bg-purple-100 rounded-full p-3 text-purple-600 mr-4">
<svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
</svg>
</div>
<h1 class="text-4xl text-gray-900 sm:truncate">
Apartments Information
</h1>
</div>
</div>
<div class="p-5">
<a href="/rms/addHouse.php?apartment_id=<?php echo $apartment['apartment_id']; ?>" class="btn primary ">Add House</a>
</div>
</div>
<div class="flex items-start gap-5 p-5">
<div class="bg-white shadow overflow-hidden sm:rounded-lg w-full max-w-xl">
<?php if ($apartment) { ?>
<div class="p-6 bg-gray-900">
<h3 class="text-3xl font-medium text-gray-300 overflow-hidden overflow-ellipsis">
<?php echo htmlspecialchars($apartment["name"]); ?>
</h3>
</div>
<div class="border-t border-gray-200 px-6 py-4">
<!-- apartment -->
<h4 class=" font-medium text-base text-gray-900 uppercase mb-2 ">Apartment Detail</h4>
<div class="bg-white px-4 py-1.5 sm:grid sm:grid-cols-3 sm:gap-2 sm:px-6 items-end">
<dt class="text-sm font-medium text-gray-500">
Apartment name
</dt>
<dd class="mt-1 text-base font-medium text-gray-900 sm:mt-0 sm:col-span-2">
<?php echo htmlspecialchars($apartment["name"]); ?>
</dd>
</div>
<div class="bg-white px-4 py-1.5 sm:grid sm:grid-cols-3 sm:gap-2 sm:px-6">
<dt class="text-sm font-medium text-gray-500">
Vacancy status
</dt>
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
<?php if ($isVacant) { ?>
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800 ">● available
</span>
<?php } else { ?>
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-yellow-100 text-red-800">
● fully occupied
</span>
<?php } ?>
</dd>
</div>
<div class="bg-white px-4 py-1.5 sm:grid sm:grid-cols-3 sm:gap-2 sm:px-6">
<dt class="text-sm font-medium text-gray-500">
Description
</dt>
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2 max-w-xs break-words">
<?php echo htmlspecialchars($apartment["description"]); ?>
</dd>
</div>
<div class="bg-white px-4 py-1.5 sm:grid sm:grid-cols-3 sm:gap-2 sm:px-6">
<dt class="text-sm font-medium text-gray-500">
Apartment Type
</dt>
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
<?php echo htmlspecialchars($apartment["type"]); ?>
</dd>
</div>
<!-- location -->
<h4 class=" font-medium text-base text-gray-900 uppercase pt-4 mt-4 mb-2 ">Location Detail</h4>
<div class="bg-white px-4 py-1.5 sm:grid sm:grid-cols-3 sm:gap-2 sm:px-6">
<dt class="text-sm font-medium text-gray-500">
Town
</dt>
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
<?php echo htmlspecialchars($apartment["town"]); ?>
</dd>
</div>
<div class="bg-white px-4 py-1.5 sm:grid sm:grid-cols-3 sm:gap-2 sm:px-6">
<dt class="text-sm font-medium text-gray-500">
Location
</dt>
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2 max-w-xs break-words">
<?php echo htmlspecialchars($apartment["location"]); ?>
</dd>
</div>
<!-- owner -->
<h4 class=" font-medium text-base text-gray-900 uppercase pt-4 mt-4 mb-2 ">Owner Detail</h4>
<div class="bg-white px-4 py-1.5 sm:grid sm:grid-cols-3 sm:gap-2 sm:px-6">
<dt class="text-sm font-medium text-gray-500">
Owner
</dt>
<dd class="mt-1 text-base text-gray-900 hover:underline sm:mt-0 sm:col-span-2">
<a href="/rms/ownerDetails.php?id=<?php echo $apartment["owner_id"]; ?>" class="link">
<?php echo htmlspecialchars($apartment["owner_name"]); ?>
</a>
</dd>
</div>
<div class="bg-white px-4 py-1.5 sm:grid sm:grid-cols-3 sm:gap-2 sm:px-6">
<dt class="text-sm font-medium text-gray-500">
Owner Contact
</dt>
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
<?php echo htmlspecialchars($apartment["owner_phone"]); ?>
</dd>
</div>
<div class="flex justify-end gap-4">
<form action="apartmentDetails.php" method="POST" onsubmit="return confirm('Are you really want to delete the Apartment Data, its Houses\' details and Payment History as well?')" class="mt-3 flex justify-end">
<input type="hidden" name="id_to_delete" value="<?php echo htmlspecialchars($apartment["apartment_id"]); ?>">
<input type="submit" name="delete" value="DELETE" class="btn secondary danger small">
</form>
<form action="editApartment.php" method="POST" class="mt-3 flex justify-end">
<input type="hidden" name="apartment_id" value="<?php echo htmlspecialchars($apartment["apartment_id"]); ?>">
<input type="submit" name="submit" value="Edit Details" class="btn primary small">
</form>
</div>
</div>
<?php } else { ?>
<div class="px-4 py-5 sm:px-6">
<h3 class="text-lg leading-6 font-medium text-gray-900">
Apartment Information missing
</h3>
<p class="mt-1 max-w-2xl text-sm text-gray-500">
Apartment do not exist
</p>
</div>
<?php } ?>
</div>
<?php if ($apartment) { ?>
<div class="flex flex-col w-full max-w-xl ">
<div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
<div class="shadow overflow-hidden sm:rounded-lg">
<div class="px-4 py-5 sm:px-6 bg-gray-900 border-b">
<h3 class="text-xl leading-6 font-medium text-gray-300">
House Information
</h3>
<p class="mt-1 max-w-2xl text-sm text-gray-400">
Houses included in
<span class="text-gray-300 font-medium">
<?php echo $apartment["name"]; ?>
</span>
</p>
</div>
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="pl-6 pr-2 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
House
</th>
<th scope="col" class="px-2 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Rent <span class="capitalize">(Rs.)</span>
</th>
<th scope="col" class="px-2 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider ">
Status
</th>
<th scope="col" class="relative pl-2 pr-6 py-3">
<a href="/rms/addHouse.php?apartment_id=<?php echo $apartment['apartment_id']; ?>" class="btn primary small">Add House</a>
</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
<?php foreach ($houses as $house) { ?>
<tr>
<td class="pl-6 pr-2 py-4">
<div class="flex items-center ">
<div class="max-w-xs w-52 break-words">
<div class="text-base font-medium text-gray-900">
<?php echo htmlspecialchars($house["house_no"]) ?>
</div>
<div class="text-sm text-gray-500 mt-1">
<?php echo htmlspecialchars($house["description"]) ?>
</div>
</div>
</div>
</td>
<td class="px-2 py-4">
<div class="text-sm text-gray-900">
<?php echo htmlspecialchars($house["rent"]) ?>
</div>
</td>
<td class="px-2 py-4">
<?php if (!isset($house["tenant_id"])) { ?>
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800 ">vacant
</span>
<?php } else { ?>
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-yellow-100 text-red-800">
occupied
</span>
<?php } ?>
</td>
<td class="pl-2 pr-6 py-4 text-right text-sm font-medium">
<a href="houseDetails.php?id=<?php echo $house['house_id']; ?>" class="text-indigo-600 hover:text-indigo-900">Details</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
<?php include "footer.php" ?>
</html>