-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrental.php
189 lines (150 loc) · 5.36 KB
/
rental.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
<?php
session_start();
include 'db_connection.php';
include 'gvar.php';
$conn=OpenCon();
$car="";
$user="";
$car_ex="";
?>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Renting</title>
<link rel="stylesheet" href="rental.css">
</head>
</head>
<body>
<?php
if(isset($_SESSION['role'])&&($_SESSION['role']==$manager || $_SESSION['role']==$employee ))
{
$lno=$_SESSION['licno'];
$numplate=$_SESSION['numplate'];
//echo $lno." ".$numplate;
$data=Findusers($conn,$lno);
$info=Findcars($conn,$numplate);
$info1=Displaycardata($conn,$numplate);
if(isset($data) && isset($info) && isset($info1))
{
$user=mysqli_fetch_assoc($data);
$car=mysqli_fetch_assoc($info);
$car_ex=mysqli_fetch_array($info1); //fetched as normal array
echo "<script> var price = ".$car['price'] ."</script>";
}
else
{
echo "user or car does not exist";
}
?>
<form class="box" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="post">
<div class="title">
Booking Page
</div>
<div class="form">
<div class="inputfield">
<label>Renter Name</label>
<input type="text" class="input" value="<?php echo $user['clientname'];?>" readonly>    
<label>Mobile Number</label>
<input type="text" class="input" value="<?php echo $user['clientmobile'];?>" readonly>
</div>
<div class="inputfield">
<label>License Number</label>
<input type="text" class="input" value="<?php echo $user['clientlicense'];?>" readonly>    
<label>Number Plate</label>
<input type="text" class="input" value="<?php echo $car['numberplate'];?>" readonly>
</div>
<div class="inputfield">
<label>Kms</label>
<input type="text" class="input" value="<?php echo $car_ex[3];?>" readonly>    
<label>Date of Rental</label>
<input type="date" id="datePickerId" name='da_rental' class="input" readonly>
</div>
<br>
<div class="inputfield">
<label>Date of Return</label>
<input type="date" id="datePickerId2" name='da_return' class="input" required>
</div>
<div class="inputfield">
<label>Advance</label>
<input type="number" name="advance" id='Advance' class="input" required>
</div>
<div class="inputfield">
<label>Total</label>
<input type="text" name='total' id='Total' class="input" readonly>
</div>
<div class="inputfield terms">
<label class="check">
<input type="checkbox" required>
<span class="checkmark"></span>
</label>
<p>Entered data is correct</p>
</div>
<div class="inputfield">
<input type="submit" name='submit' value="Register" class="btn">
</div>
</div>
<?php
if(isset($_SERVER['REQUEST_METHOD']))
{
if(isset($_REQUEST['submit']))
{
$flag=Givenrentals($conn,$user['clientname'],$user['clientmobile'],$_SESSION['licno'],$_SESSION['numplate'],$_SESSION['eid'],$car_ex[3],$_REQUEST['da_rental'],$_REQUEST['da_return'],$_REQUEST['advance'],$_REQUEST['total']);
if($flag)
{
echo "Car with $numplate rented Successfullyt to customer with $lno license no.<br>";
sleep(3); //after 3 sec redirection will be happen
if($_SESSION['role']==$manager)
{
header("Location:manager.php");
}
else if($_SESSION['role']==$employee)
{
header("Location:employee.php");
}
}
else
{
echo "Error occured";
}
}
}
?>
<?php
}
else
{
echo "you got anauthorized access";
}
?>
<script>
datePickerId2.min = new Date().toISOString().split("T")[0];
datePickerId.value = new Date().toISOString().split("T")[0];
var advance = document.getElementById('Advance');
var total = document.getElementById('Total');
var dor = document.getElementById('datePickerId2');
// finds total rent from two dates
dor.addEventListener('input' ,function(){
const date1= new Date(document.getElementById('datePickerId').value);
const date2= new Date(document.getElementById('datePickerId2').value);
const diffTime = Math.abs(date2 - date1);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
total.value= diffDays * price;
});
// alerts if advance is greater than total
advance.addEventListener('input', function(){
const date1= new Date(document.getElementById('datePickerId').value);
const date2= new Date(document.getElementById('datePickerId2').value);
const diffTime = Math.abs(date2 - date1);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
var t = diffDays * price;
if(this.value>t)
{
alert("Advance is greater than total ");
this.value=0;
}
//total.value=total.value-this.value;
} );
</script>
</body>
</html>