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

Customer my Booking #247

Merged
merged 1 commit into from
Apr 27, 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
17 changes: 17 additions & 0 deletions app/controllers/API/GuideBookings.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,23 @@ public function getGuideAllBookings(int $packageId): void{


}

public function getAllMyBookings(): void
{
$response = new JSONResponse;

$GuideBookingsModel = new GuideBookingsModel();
$bookingDetails = $GuideBookingsModel->getAllMyBookings(UserMiddleware::getUser()['id']);
$guideDetails = $GuideBookingsModel->getGuideDetailsByBookingID($bookingDetails[0]->id);
$response->success(true)
->data([
'bookingDetails' => $bookingDetails,
'guideDetails' => $guideDetails
])
->message('Booking details fetched successfully')
->statusCode(200)
->send();
}
public function deleteBooking($date): void
{
$response = new JSONResponse;
Expand Down
16 changes: 16 additions & 0 deletions app/models/GuideBookings.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ public function getCustomerDetailsByBookingID(int $bookingId): mixed {
return $this->query($q->getQuery(), $q->getData())[0];
}

public function getGuideDetailsByBookingID(int $bookingId): mixed {
$q = new QueryBuilder();
$q->setTable('guides');
$q->select('guides.*')->join('guide_booking', 'guides.id', 'guide_booking.guide_id')->where('guide_booking.id', $bookingId);
return $this->query($q->getQuery(), $q->getData())[0];
}

public function getAllBookings(int $userId): mixed {

$userId = $_SESSION['USER']->id;
Expand All @@ -99,6 +106,15 @@ public function getAllBookings(int $userId): mixed {
return $this->query($q->getQuery(), $q->getData());
}

public function getAllMyBookings(int $userId): mixed {

$userId = $_SESSION['USER']->id;
$q = new QueryBuilder();
$q->setTable($this->table);
$q->select('guide_booking.*')->where('customer_id', $userId);
return $this->query($q->getQuery(), $q->getData());
}

public function getGuideIdByPackageId(int $packageId): mixed {
$q = "CALL GetGuideIdByPackageId(:package_id)";
$params = [
Expand Down
44 changes: 21 additions & 23 deletions app/models/RentComplaint.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,35 @@ public function resolveComplaint($id)
//$table
$this->update($id, ['status' => 'resolved']);
}
public function getComplaints(array $data) {
return $this->where($data);
}
public function getComplaints(array $data)
{
return $this->where($data);
}

public function getComplaintsByCustomer(array $data) {
$q = new QueryBuilder;
$q->setTable('rent_complaint');
$q->select('rent.customer_id as customer_id, rent.id as rent_id, complaint_no as complaint_no, rent_complaint.status as status, rent_complaint.description as description, rent_complaint.created_at as created_at')
->join('rent', 'rent_complaint.rent_id','rent.id')
public function getComplaintsByCustomer(array $data)
{
$q = new QueryBuilder;
$q->setTable('rent_complaint');
$q->select('rent.customer_id as customer_id, rent.id as rent_id, complaint_no as complaint_no, rent_complaint.status as status, rent_complaint.description as description, rent_complaint.created_at as created_at')
->join('rent', 'rent_complaint.rent_id', 'rent.id')
->where('rent.customer_id', $data['customer_id']);

return $this->query($q->getQuery(), $q->getData());
}
return $this->query($q->getQuery(), $q->getData());
}

public function getRentComplaint($id) {
$q = new QueryBuilder;
$q->setTable('rent_complaint');
$q->select('rent_complaint.complaint_no as complaint_no, rent.id as rent_id,rent.created_at as rent_date, rent.customer_id as customer_id, rent.paid_amount as paid_amount, rent.created_at as paid_date, rent.start_date as start_date, rent.end_date as end_date,
public function getRentComplaint($id)
{
$q = new QueryBuilder;
$q->setTable('rent_complaint');
$q->select('rent_complaint.complaint_no as complaint_no, rent.id as rent_id,rent.created_at as rent_date, rent.customer_id as customer_id, rent.paid_amount as paid_amount, rent.created_at as paid_date, rent.start_date as start_date, rent.end_date as end_date,
rent.status as rent_status, rent.total as total_amount,rental_services.id as rental_id, rental_services.name as rental_name, rental_services.mobile as rental_mobile,
rent_complaint.title as title, rent_complaint.description as description, rent_complaint.created_at as created_at, rent_complaint.status as status')
->join('rent','rent_complaint.rent_id', 'rent.id')
->join('rental_services', 'rent.rentalservice_id','rental_services.id')
->join('rent', 'rent_complaint.rent_id', 'rent.id')
->join('rental_services', 'rent.rentalservice_id', 'rental_services.id')
->where('rent_complaint.complaint_no', $id);

return $this->query($q->getQuery(), $q->getData());
}

return $this->query($q->getQuery(), $q->getData());
}


public function getComplaints(array $data)
{
return $this->where($data);
}
}
81 changes: 66 additions & 15 deletions app/views/customer/myBookings.view.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
require_once('../app/views/layout/header.php');
require_once('../app/views/navbar/customer-navbar.php');

?>



?>

<div class="dashboard">
Expand All @@ -18,17 +14,72 @@

<div class="info-data mt-5 ml-5 mr-5">
<div class="guide-card-new">
<div class="guide-profile" id="guide-profile">
<div class="guide-profile-img">
<img src="<?= ROOT_DIR ?>/assets/images/7.png" alt="guide">
</div>
<div class="guide-profile-content" id="guide-details">
<span>Nirmal Savinda</span>
<p>Places: Sigiriya, Anuradhapura, Polonnaruwa, Dambulla, Kandy, Nuwara Eliya, Ella, Yala, Galle, Colombo</p>
<p>Packages
<p>
</div>
<div class="booking-list" id="booking-list">
<h2>Booking Details</h2>

<!-- Booking list will be displayed here -->
</div>
</div>
</div>
</div>
</div>
</div>


<script>
$(document).ready(function() {
function bookingList() {
$.ajax({
headers: {
Authorization: "Bearer " + getCookie('jwt_auth_token')
},
url: '<?= ROOT_DIR ?>/api/guideBookings/getAllMyBookings/',
type: 'GET',
success: function(data) {
console.log("Booking List")
console.log(data.data.bookingDetails)
console.log(data.data.guideDetails)
bookingHTML(data.data.guideDetails, data.data.bookingDetails);
}

});
}

function bookingHTML(userDetails, bookingDetails) {
const modalContent = document.getElementById("booking-list");
modalContent.innerHTML = "";

const userHTML = `
<div class="user-details">
<h2>User Details</h2>
<p>Name: ${userDetails.name}</p>
<p>Mobile No: ${userDetails.mobile}</p>
<!-- Add more user details as needed -->
</div>
`;

const bookingHTML = `
<div class="booking-details">
${bookingDetails.map(booking => `
<div class="guide-card-new booking-history">
<span class="label">Recent Bookings</span>
<div class=".flex-d mt-4 mb-2">
<p> Date: ${booking.date}</p>
<p> Place: ${booking.location}</p>
<p> Group Size: ${booking.no_of_people}</p>
<p> Status: ${booking.status}</p>

</div>
</div>

`).join('')}
</div>
`;

modalContent.innerHTML = userHTML + bookingHTML;
}
bookingList();
});
</script>


<?php require_once('../app/views/layout/footer.php'); ?>
51 changes: 49 additions & 2 deletions app/views/guide/package.view.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<div class="modal" id="edit-package-modal" style="display: none;">
<div class="modal-content">
<span class="modal-close close">&times;</span>
<form id="update-package-form" packageId="<?php echo htmlspecialchars($package->id);?>" class="form" method="POST" enctype="multipart/form-data">
<form id="update-package-form" packageId="<?php echo htmlspecialchars($package->id); ?>" class="form" method="POST" enctype="multipart/form-data">
<h2 class="guide-h2-title">Update Package</h2>

<div class="col-lg-5 col-md-12 p-2 flex-d-c gap-2">
Expand All @@ -62,7 +62,7 @@
<input type="text" id="price" class="form-control-lg" name="price" required value="<?php echo htmlspecialchars($package->price); ?>">

<label for="max_group_size">Maximum Group Size</label>
<input type="number" id="max_group_size" class="form-control-lg" name="max_group_size" required value="<?php echo htmlspecialchars($package->max_group_size); ?>">
<input type="number" id="max_group_size" class="form-control-lg" name="max_group_size" required value="<?php echo htmlspecialchars($package->max_group_size); ?>">


<label for="max_distance">Maximum Distance</label>
Expand All @@ -83,6 +83,53 @@
</div>
</div>


<script>
document.addEventListener("DOMContentLoaded", function() {
const placesContainer = document.getElementById('places-container');
const addPlaceFieldBtn = document.getElementById('add-place-field');

// Function to add a new place field
function addPlaceField() {
const newPlaceField = document.createElement('div');
newPlaceField.classList.add('place-fields');
newPlaceField.innerHTML = `
<select class="form-control-lg place-dropdown" name="places" required>
<option value="">Select a place</option>
<option value="place1">Place 1</option>
<option value="place2">Place 2</option>
<option value="place3">Place 3</option>
</select>
<input type="text" class="form-control place-details" placeholder="Enter details for selected place" disabled>
<button type="button" class="remove-place-field" onclick="removePlaceField(this)">Remove</button>
`;
placesContainer.appendChild(newPlaceField);

// Add event listener to new place dropdown
newPlaceField.querySelector('.place-dropdown').addEventListener('change', function() {
if (this.value !== '') {
enablePlaceDetailsField(this);
}
});
}

// Function to enable place details field
function enablePlaceDetailsField(selectElement) {
const placeDetailsField = selectElement.parentElement.querySelector('.place-details');
placeDetailsField.disabled = false;
}

// Function to remove a place field
function removePlaceField(button) {
button.parentElement.remove();
}

// Add event listener to "Add Place Field" button
addPlaceFieldBtn.addEventListener('click', addPlaceField);
});

</script>

<div id="delete-package-modal" class="delete-package-modal modal">
<div class="modal-content ">
<span class="close ">&times;</span>
Expand Down
Loading
Loading