-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkin.php
144 lines (77 loc) · 4.05 KB
/
checkin.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
<?php
session_start();
if(!$_SESSION['user']=='admin' || !$_SESSION['user']=='staff'){
header("Location: index.php");
}
//$checkin_time= date('h:g:s');
header('Content-type: application/json; charset=UTF-8');
require 'dbconnection.php';
$obj =new checkin();
$obj->checkinCustomer();
class checkin{
private $customerID;
private $inDate;
public $response;
private $conn;
private $roomID;
private $curTime;
public function __construct() {
$this->customerID = filter_input(INPUT_POST, id) ;
$this->inDate = date('d-m-Y');
$this->response = array();
$this->curTime = date('G:i:s');
$this->conn = new dbconnection();
$this->roomID = filter_input(INPUT_POST, roomid) ;
}
public function checkinCustomer(){
header('Content-type: application/json; charset=UTF-8');
if (!empty($this->customerID) && !empty($this->roomID)) {
$checkBookin="SELECT * FROM customers INNER JOIN bookings ON customers.c_id = bookings.c_id WHERE date(customers.checkin_date)<=date(:in) AND date(customers.checkout_date)> date(:in) AND customers.c_id=:c_id AND customers.room=:room ";
$this->conn->query($checkBookin);
$this->conn->bind(':in', $this->inDate);
$this->conn->bind(':c_id', $this->customerID);
$this->conn->bind(':room', $this->roomID);
$this->conn->execute();
$resulSet=$this->conn->resultSet();
if($resulSet){
$checkinCustomer= "INSERT INTO checkin (c_id,checkin_time) VALUES (:c_id,:time) ";
$this->conn->query($checkinCustomer);
$this->conn->bind(':c_id', $this->customerID);
$this->conn->bind(':time', $this->curTime);
$this->conn->execute();
$rs=$this->conn->resultSet();
$updateCheckOutDate="UPDATE customers SET checkin_date=:inDate WHERE c_id=:c_id";
$this->conn->query($updateCheckOutDate);
$this->conn->bind(':inDate', $this->inDate);
$this->conn->bind(':c_id', $this->customerID);
$this->conn->execute();
$rs1=$this->conn->resultSet();
$deleteEntry="DELETE FROM bookings WHERE c_id = :c_id";
$this->conn->query($deleteEntry);
$this->conn->bind(':c_id', $this->customerID);
$this->conn->execute();
$rs2=$this->conn->resultSet();
$paidCustomer= "INSERT INTO paid (c_id) VALUES (:c_id) ";
$this->conn->query($paidCustomer);
$this->conn->bind(':c_id', $this->customerID);
$this->conn->execute();
$rs3=$this->conn->resultSet();
if($rs && $rs1 && $rs2 && $rs3){
$response['status'] = 'success';
$response['message'] = ' Check-in Successfull' ;
}else{
$response['status'] = 'error';
$response['message'] = 'Unable to Check-in ...';
}
}else{
$response['status'] = 'error';
$response['message'] = 'Customer did not book for the current date ' ;
}
}else{
$response['status'] = 'error';
$response['message'] = 'Customer not found!';
}
echo json_encode($response);
}
}
?>