Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View recent transactions of the parking #281

Merged
merged 2 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function enterExitParking($land_ID = null){
if($parking_status){
// If the driver is already parked, then exit the parking
$this->driverModel->exitParking($data);
redirect('driver/index/'.$land_ID);
redirect('driver/index');
}
else{
// If the driver is not parked, then select the vehicle type
Expand All @@ -164,7 +164,7 @@ public function enterParking(){
$vehicle_type = $_POST['vehicle_type'];

$this->driverModel->enterParking($land_ID, $vehicle_type);
redirect('driver/index/'.$land_ID);
redirect('driver/index');
}
}

Expand Down
6 changes: 4 additions & 2 deletions app/controllers/ParkingOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function lands(){
public function gotoLand($land_ID = null){
$data = [
'id' => $land_ID,
'name' => $this->landModel->getLandName($land_ID),
'name' => $this->landModel->getLandName($land_ID)
];

$notifications['lands'] = $this->landModel->viewLands();
Expand All @@ -66,6 +66,7 @@ public function gotoLand($land_ID = null){
'security_count' => $this->securityModel->getSecurityCount($land_ID),
'availability' => $this->landModel->getAvailability($land_ID),
'capacity' => $this->landModel->getCapacity($land_ID),
'today_transactions' => $this->landModel->getTodayTransactions($land_ID)
];

$this->view('parkingOwner/land', $data, $notifications);
Expand Down Expand Up @@ -105,7 +106,8 @@ public function parkingCapacity($parking_ID = null, $parking_name = null){
// -------------------------------------- Report ---------------------------------------
public function viewReport(){
$data = [
'title' => 'Home page'
'title' => 'Home page',
'lands' => $this->landModel->viewLands()
];

$other_data['notification_count'] = 0;
Expand Down
15 changes: 13 additions & 2 deletions app/controllers/Vehicle.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ public function vehicleRegister()
$data = [
'name' => trim($_POST['name']),
'vehicle_type' => trim($_POST['vehicle_type']),
'vehicle_number' => trim($_POST['vehicle_number']),
'err' => ''
];

// Validate data
// Validate email
// Validate name
if (empty($data['name'])) {
$data['err'] = 'Please enter name';
} else {
Expand All @@ -34,10 +35,20 @@ public function vehicleRegister()
}
}

// Validate vehicle number
if (empty($data['vehicle_number'])) {
$data['err'] = 'Please enter vehicle number';
} else {
// Check vehicle_number
if ($this->driverModel->findVehicleByNumber($data['vehicle_number'])) {
$data['err'] = 'Vehicle number cannot be duplicate';
}
}

// Validate user type
if (empty($data['vehicle_type'])) {
$data['err'] = 'Please select vehicle type';
} else if ($data['vehicle_type'] != 'car' and $data['vehicle_type'] != 'bike' and $data['vehicle_type'] != '3wheel') {
} else if ($data['vehicle_type'] != 'car' and $data['vehicle_type'] != 'bike' and $data['vehicle_type'] != 'threeWheel') {
$data['err'] = 'Invalid vehicle type';
}

Expand Down
88 changes: 81 additions & 7 deletions app/models/DriverModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ public function __construct(){
public function registerVehicle($data): bool
{
// Prepare statement
$this->db->query('INSERT INTO vehicle (name, vehicleType, id) VALUES (:name, :vehicleType, :id)');
$this->db->query('INSERT INTO vehicle (name, vehicleType, id, vehicleNumber) VALUES (:name, :vehicleType, :id, :vehicleNumber)');

// Bind values
$this->db->bind(':name', $data['name']);
$this->db->bind(':vehicleType', $data['vehicle_type']);
$this->db->bind(':id', $_SESSION['user_id']);
$this->db->bind(':vehicleNumber', $data['vehicle_number']);

// Execute
if ($this->db->execute()){
Expand Down Expand Up @@ -44,6 +45,22 @@ public function findVehicleByName($name): bool
}
}

// Find vehicle
public function findVehicleByNumber($number): bool
{
$this->db->query('SELECT * FROM vehicle WHERE vehicleNumber = :vehicleNumber');
$this->db->bind(':vehicleNumber', $number);

$row = $this->db->single();

// Check row
if ($this->db->rowCount() > 0){
return true;
} else {
return false;
}
}

// View vehicles
public function viewVehicles(){
$this->db->query('SELECT * FROM vehicle WHERE id = :id');
Expand Down Expand Up @@ -99,6 +116,27 @@ public function updateVehicle($data): bool
}

// ------------------------- Parking Functionalities -------------------------
// Get landowner id by land id
public function getLandownerID($landID){
$this->db->query('SELECT uid FROM land WHERE id = :id');
$this->db->bind(':id', $landID);

$row = $this->db->single();

return $row->uid;
}

// Get vehicleType using landID driverID and status
public function getVehicleType($landID){
$this->db->query('SELECT vehicleType FROM driver_land WHERE landID = :landID and driverID = :driverID and status = 1');
$this->db->bind(':landID', $landID);
$this->db->bind(':driverID', $_SESSION['user_id']);

$row = $this->db->single();

return $row->vehicleType;
}

// Check parking status
public function checkParkingStatus($landID){
$this->db->query('SELECT * FROM driver_land WHERE landID = :landID and driverID = :driverID and status = 1');
Expand All @@ -115,14 +153,32 @@ public function checkParkingStatus($landID){

// Enter parking
public function enterParking($land_ID, $vehicle_type){
$this->db->query('INSERT INTO driver_land (landID, driverID, status, vehicleType, startTime) VALUES (:landID, :driverID, :status, :vehivleType, :startTime)');
// Update driver_land table
$this->db->query('INSERT INTO driver_land (landID, driverID, status, vehicleType, startTime) VALUES (:landID, :driverID, :status, :vehicleType, :startTime)');
$this->db->bind(':landID', $land_ID);
$this->db->bind(':driverID', $_SESSION['user_id']);
$this->db->bind(':status', 1);
$this->db->bind(':vehivleType', $vehicle_type);
$this->db->bind(':startTime', date("Y-m-d H:i:s"));
$this->db->bind(':vehicleType', $vehicle_type);

if ($this->db->execute()){
// End time
$startTime = date("Y-m-d H:i:s");
$this->db->bind(':startTime', $startTime);

$result1 = $this->db->execute();

// Update land_transaction table
$ownerID = $this->getLandOwnerID($land_ID);
$this->db->query('INSERT INTO land_transaction (ownerID, landID, driverID, status, vehicleType, transactionTime) VALUES (:ownerID, :landID, :driverID, :status, :vehicleType, :transactionTime)');
$this->db->bind(':ownerID', $ownerID);
$this->db->bind(':landID', $land_ID);
$this->db->bind(':driverID', $_SESSION['user_id']);
$this->db->bind(':status', 1);
$this->db->bind(':vehicleType', $vehicle_type);
$this->db->bind(':transactionTime', $startTime);

$result2 = $this->db->execute();

if ($result1 && $result2){
return true;
}
else {
Expand All @@ -135,9 +191,27 @@ public function exitParking($data){
$this->db->query('UPDATE driver_land SET endTime = :endTime WHERE landID = :landID and driverID = :driverID');
$this->db->bind(':landID', $data['id']);
$this->db->bind(':driverID', $_SESSION['user_id']);
$this->db->bind(':endTime', date("Y-m-d H:i:s"));

if ($this->db->execute() && $this->updateCost($data)){
// End time
$startTime = date("Y-m-d H:i:s");
$this->db->bind(':endTime', $startTime);

$result1 = $this->db->execute();

// Update land_transaction table
$ownerID = $this->getLandOwnerID($data['id']);
$vehicleType = $this->getVehicleType($data['id']);
$this->db->query('INSERT INTO land_transaction (ownerID, landID, driverID, status, vehicleType, transactionTime) VALUES (:ownerID, :landID, :driverID, :status, :vehicleType, :transactionTime)');
$this->db->bind(':ownerID', $ownerID);
$this->db->bind(':landID', $data['id']);
$this->db->bind(':driverID', $_SESSION['user_id']);
$this->db->bind(':status', 0);
$this->db->bind(':vehicleType', $vehicleType);
$this->db->bind(':transactionTime', $startTime);

$result2 = $this->db->execute();

if ($result1 && $result2 && $this->updateCost($data)){
return true;
}
else {
Expand Down
22 changes: 22 additions & 0 deletions app/models/LandModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,26 @@ public function unassignedMySelf($landID, $adminID): bool
return false;
}
}

// Get today transactions
public function getTodayTransactions($landID){
$this->db->query('SELECT lt.*, v.vehicleNumber FROM land_transaction lt JOIN vehicle v ON lt.driverID = v.id AND lt.vehicleType = v.vehicleType WHERE lt.landID = :landID AND lt.transactionTime >= :transactionTime ORDER BY lt.transactionTime DESC LIMIT 8');
$this->db->bind(':landID', $landID);
$this->db->bind(':transactionTime', date('Y-m-d'));

$row = $this->db->resultSet();

return $row;
}

// Get yesterday transactions
public function getYesterdayTransactions($landID){
$this->db->query('SELECT * FROM driver_land WHERE landID = :landID AND transactionTime = :transactionTime');
$this->db->bind(':landID', $landID);
$this->db->bind(':transactionTime', date('Y-m-d', strtotime("-1 days")));

$row = $this->db->resultSet();

return $row;
}
}
1 change: 0 additions & 1 deletion app/models/ParkingOwnerModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public function __construct(){
$this->db = new Database();
}


// ------------------------- package Functionalities -------------------------
// Register package
public function registerPackage($data): bool
Expand Down
8 changes: 4 additions & 4 deletions app/models/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ public function getBanTime($username){
// Unban according to the time
public function UnbanAccordingTime(){
$this->db->query('UPDATE user
SET status = :status
WHERE (banCount = 1 OR banCount = 2)
AND (banCount = 1 AND DATE_ADD(banTime, INTERVAL 1 DAY) <= NOW()
OR banCount = 2 AND DATE_ADD(banTime, INTERVAL 7 DAY) <= NOW());');
SET status = :status
WHERE (banCount = 1 OR banCount = 2)
AND (banCount = 1 AND DATE_ADD(banTime, INTERVAL 1 DAY) <= NOW()
OR banCount = 2 AND DATE_ADD(banTime, INTERVAL 7 DAY) <= NOW());');

$this->db->bind(':status', 1);

Expand Down
6 changes: 5 additions & 1 deletion app/views/driver/vehicles/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@
<div class="form-input-title">Name:</div>
<input type="text" name="name" id="name" required value="" />

<!-- Number -->
<div class="form-input-title">Vehicle Number:</div>
<input type="text" name="vehicle_number" id="vehicle_number" required value="" />

<br><br>
<!-- Vehicle Type -->
<div class="form-input-title">User Type:</div>
<div class="user-selection-container">
<ul class="user-selection-list">
<li data-user-type="car">Car</li>
<li data-user-type="bike">Bike</li>
<li data-user-type="3wheel">3wheel</li>
<li data-user-type="threeWheel">3wheel</li>
</ul>
</div>

Expand Down
65 changes: 64 additions & 1 deletion app/views/driver/viewParking.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<main class="page-container">
<section class="section" id="main">
<div class="container">
<h1>Dashboard</h1>

<div class="cover-img">
<img class="cover-photo" src="<?php echo URLROOT ?>/images/parking_bg1.jpg" alt="Phone">
</div>
Expand All @@ -22,10 +24,71 @@
<p>Car: <?php echo $data->car?></p>
<p>Bike: <?php echo $data->bike?></p>
<p>Three wheel: <?php echo $data->threeWheel?></p>
<!-- <a href="--><?php //echo URLROOT?><!--/deeds/--><?php //echo $data->deed ?><!--" style="background-color: #fcd426; border-radius: 10px; padding: 10px 20px 10px 20px">Directions</a>-->
<!-- <a href="--><?php //echo URLROOT?><!--/deeds/--><?php //echo $data->deed ?><!--" style="background-color: #fcd426; border-radius: 10px; padding: 10px 20px 10px 20px">Directions</a>-->
<a href="<?php echo URLROOT?>/driver/startAndStopTimer/<?php echo $data->id?>" style="background-color: #fcd426; border-radius: 10px; padding: 10px 20px 10px 20px">Enter Parking</a>
</div>

</div>

<div class="" style="position: absolute; top: 52px; right: 50px; padding: 10px 20px; box-shadow: 0 0 10px 0.1px rgba(0,0,0,0.16); border-radius: 10px;" onclick="closeRightCard()">View Transaction</div>

<div class="side-cards">
<div class="close-btn" onclick="closeRightCard()">X</div>
<h2>Packages</h2>

<p><span>&#9632;</span>Today</p>

<div class="side-card">
<div class="date-time">2023.11.22</div>
<div class="parking">Nolimit</div>
<div class="transaction-type in">In</div>
</div>

<div class="side-card">
<div class="date-time">2023.11.22</div>
<div class="parking">Keels</div>
<div class="transaction-type out">Out</div>
</div>

<div class="side-card">
<div class="date-time">2023.11.22</div>
<div class="parking">Nolimit</div>
<div class="transaction-type in">In</div>
</div>

<div class="side-card">
<div class="date-time">2023.11.22</div>
<div class="parking">Keels</div>
<div class="transaction-type out">Out</div>
</div>

<p><span>&#9632;</span>Yesterday</p>

<div class="side-card">
<div class="date-time">2023.11.22</div>
<div class="parking">Nolimit</div>
<div class="transaction-type in">In</div>
</div>

<div class="side-card">
<div class="date-time">2023.11.22</div>
<div class="parking">Keels</div>
<div class="transaction-type out">Out</div>
</div>

<div class="side-card">
<div class="date-time">2023.11.22</div>
<div class="parking">Nolimit</div>
<div class="transaction-type in">In</div>
</div>

<div class="side-card">
<div class="date-time">2023.11.22</div>
<div class="parking">Keels</div>
<div class="transaction-type out">Out</div>
</div>
</div>
</section>
</main>

<?php require APPROOT.'/views/inc/footer.php'; ?>
Loading