Skip to content

Commit

Permalink
Update all functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dilan032 committed Jun 3, 2024
1 parent 3655665 commit b7dc1a9
Show file tree
Hide file tree
Showing 67 changed files with 1,168 additions and 456 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_TIMEZONE=Asia/Colombo
APP_URL=http://localhost

APP_LOCALE=en
Expand Down
126 changes: 114 additions & 12 deletions app/Http/Controllers/BookingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,54 @@ public function index()
return view('profile.booking', compact('bookings')); // Pass data to the view

}

// this function show details for admin
public function showAllBookingData()
{
$userId = Auth::id(); // Retrieve logged-in user ID
$bookings = Booking::withUserAndPackage()
->orderBy('created_at', 'DESC')
->get();

return view('admin.bookingDetails', compact('bookings')); // Pass data to the view

}

// for Admin
public function showOneUserBookingDataAll($id)
{
$bookings = Booking::withUserAndPackage(['user', 'package'])
->where('id', $id)
->orderBy('created_at', 'DESC')
->get();
// dd($bookings); // Dump the bookings to check data //this is used for data correckly pass to the view
return view('admin.adminBookingDetailsPage', compact('bookings')); // Pass data to the view
}

/**
* Display a invoice massage.
*/
public function indexInvoice()
{
return view('profile.invoice');
$userId = Auth::id(); // Retrieve logged-in user ID
$bookings = Booking::withUserAndPackage()
->where('user_id', $userId)
->orderBy('created_at', 'DESC')
->get();

return view('profile.invoice', compact('bookings')); // Pass data to the view
}

//show user invoice details
public function invoiceDetails($id)
{
$booking = Booking::withUserAndPackage(['user', 'package'])
->where('id', $id)
->orderBy('created_at', 'DESC')
->first();

// dd($bookings); // Dump the bookings to check data //this is used for data correckly pass to the view
return view('profile.profileInvoiceDetails', compact('booking')); // Pass data to the view
}

/**
Expand All @@ -53,18 +95,13 @@ public function create()
*/
public function store(Request $request)
{
$rules =[

$rules =[
'date' => 'required|date',
'number_of_adult' => 'required|integer',
'number_of_child' => 'required|integer',
'pick_up_location' => 'required|string',
'pick_up_location_details' => 'required|string',
'accommodation_type' => 'required|string',
'transport_method' => 'required|string',
'aditional_requarement' => 'nullable|string',
'total_fee' => 'required|numeric',

];

$validator = Validator::make($request->all(), $rules);
Expand All @@ -90,9 +127,6 @@ public function store(Request $request)
$bookings->number_of_child = $request->number_of_child;
$bookings->pick_up_location = $request->pick_up_location;
$bookings->pick_up_location_details = $request->pick_up_location_details;
$bookings->accommodation_type = $request->accommodation_type;
$bookings->transport_method = $request->transport_method;
$bookings->aditional_requarement = $request->aditional_requarement;
$bookings->total_fee = $request->total_fee;
$bookings->save();

Expand All @@ -101,13 +135,81 @@ public function store(Request $request)

}

//user payment_receipt upload
public function paymentReceiptImage(Request $request, $id)
{
$rules =[
'payment_receipt' => 'nullable|image|mimes:jpeg,svg,png,jpg,webp|max:10240', // Ensure image file, max 10MB
];

$validator = Validator::make($request->all(), $rules);
//to show massages | check validate
if ($validator->fails()) {
return redirect()->route('profile.profileInvoiceDetails', ['id' => $id])->withErrors($validator)->withInput();
}

// Find the existing booking record
$booking = Booking::find($id);

$booking->payment_status = 'Success';
$booking->save();

//set the attribute for images
if ($request->hasFile('payment_receipt')) {
$payment_receipt = $request->file('payment_receipt');
$ext = $payment_receipt->getClientOriginalExtension();
$imageName = time() . '.' . $ext;
$payment_receipt->move(public_path('image/uploads/payment-recipt'), $imageName);
$booking->payment_receipt = $imageName;
$booking->save();
}


// Process the validated data, such as saving it to the database
return redirect()->route('profile.showInvoiceDetails', ['id' => $id])->with('success', 'Payment has been made successfully');

}

//user payment_receipt accept and conform booking for admin function
public function paymentReceiptImageAcccept(Request $request, $id)
{

// Find the existing booking record
$booking = Booking::find($id);
$booking->payment_status = 'Success';
$booking->reservation_status = 'Conform';
$booking->save();

// Process the validated data, such as saving it to the database
return redirect()->route('admin.showOneUserBookingDataAll', ['id' => $id])->with('success', 'Booking confirmed');

}

//user payment_receipt reject and reject booking for admin function
public function paymentReceiptImageReject(Request $request, $id)
{

// Find the existing booking record
$booking = Booking::find($id);
$booking->payment_status = 'Reject';
$booking->reservation_status = 'Reject';
$booking->save();

// Process the validated data, such as saving it to the database
return redirect()->route('admin.showOneUserBookingDataAll', ['id' => $id])->with('success', 'Booking Rejected');

}





/**
* Display the specified resource.
*/
public function show(booking $booking)
{
// $bookings = booking::orderBy('created_at','DESC')->get();
// return view('profile.booking', compact('bookings')); // Pass data to the view
//
}

/**
Expand Down
52 changes: 23 additions & 29 deletions app/Http/Controllers/TravelPackageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Http\Controllers;

use App\Models\booking;
use App\Models\ServiceForTravelPackage;
use App\Models\travelPackage;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
Expand Down Expand Up @@ -36,18 +38,13 @@ public function store(Request $request)
'image_2' => 'nullable|image|mimes:jpeg,svg,png,jpg,gif,webp|max:10240', // Ensure image file, max 10MB
'image_3' => 'nullable|image|mimes:jpeg,svg,png,jpg,gif,webp|max:10240', // Ensure image file, max 10MB
'duration' => 'required|string|max:255',
'duration_type' => 'required|in:Days,Weeks',
'tour_type' => 'required|in:Adventure Tour,Beach Holiday Tour,Cultural Tour,Business Trip Tour, Wildlife Safaris',
'package_type' => 'required|in:Full package,Half package',
'price_start_from' => 'required|numeric|min:0',
'overview' => 'required|string',
'included_things' => 'required|string',
'Excludes_things' => 'required|string',
'tour_plane_description' => 'required|string',
'per_adult_fee' => 'required|numeric|min:0',
'per_child_fee' => 'required|numeric|min:0',
'service_fee' => 'required|numeric|min:0',
'booking_fee' => 'required|numeric|min:0',
];

$validator = Validator::make($request->all(), $rules);
Expand All @@ -63,50 +60,50 @@ public function store(Request $request)
//set the attribute
$travelPackage->package_name = $request->package_name;
$travelPackage->duration = $request->duration;
$travelPackage->duration_type = $request->duration_type;
$travelPackage->tour_type = $request->tour_type;
$travelPackage->package_type = $request->package_type;
$travelPackage->price_start_from = $request->price_start_from;
$travelPackage->overview = $request->overview;
$travelPackage->included_things = $request->included_things;
$travelPackage->Excludes_things = $request->Excludes_things;
$travelPackage->tour_plane_description = $request->tour_plane_description;
$travelPackage->per_adult_fee = $request->per_adult_fee;
$travelPackage->per_child_fee = $request->per_child_fee;
$travelPackage->service_fee = $request->service_fee;
$travelPackage->booking_fee = $request->booking_fee;
$travelPackage->save();

//set the attribute for images
//for image 1
if ($request->hasFile('image_1')) {


$image_1 = $request->file('image_1');
$ext = $image_1->getClientOriginalExtension();
$imageName = time() . '.' . $ext;
$imageName = time() . uniqid('_img1_', true) . '.' . $ext;
$image_1->move(public_path('image/uploads/travelPackage'), $imageName);
$travelPackage->image_1 = $imageName;
$travelPackage->save();
}
//for image 2
if ($request->hasFile('image_2')) {


//for image 2
if ($request->hasFile('image_2')) {

$image_2 = $request->file('image_2');
$ext = $image_2->getClientOriginalExtension();
$imageName = time() . '.' . $ext;
$imageName = time() . uniqid('_img2_', true) . '.' . $ext;
$image_2->move(public_path('image/uploads/travelPackage'), $imageName);
$travelPackage->image_2 = $imageName;
$travelPackage->save();
}
//for image 3
if ($request->hasFile('image_3')) {
//for image 3
if ($request->hasFile('image_3')) {


$image_3 = $request->file('image_3');
$ext = $image_3->getClientOriginalExtension();
$imageName = time() . '.' . $ext;
$imageName = time() . uniqid('_img3_', true) . '.' . $ext;
$image_3->move(public_path('image/uploads/travelPackage'), $imageName);
$travelPackage->image_3 = $imageName;
$travelPackage->save();
}


// Process the validated data, such as saving it to the database
return redirect()->route('admin.travelPackage.show')->with('success', 'Travel Package created successfully');
Expand All @@ -128,7 +125,7 @@ public function showForUser(travelPackage $travelPackage)
return view('user.package', compact('travelPackage')); // Pass data to the view
}

// for user showBlog page
// for user travel package page
public function showTravelPackagePage($id){
$travelPackage = travelPackage::findOrFail($id);
return view('user.packagePage',[ 'travelPackage' => $travelPackage
Expand Down Expand Up @@ -161,18 +158,13 @@ public function update($id, Request $request)
'image_2' => 'nullable|image|mimes:jpeg,svg,png,jpg,gif,webp|max:10240', // Ensure image file, max 10MB
'image_3' => 'nullable|image|mimes:jpeg,svg,png,jpg,gif,webp|max:10240', // Ensure image file, max 10MB
'duration' => 'required|string|max:255',
'duration_type' => 'required|in:Days,Weeks',
'tour_type' => 'required|in:Adventure Tour,Beach Holiday Tour,Cultural Tour,Business Trip Tour, Wildlife Safaris',
'package_type' => 'required|in:Full package,Half package',
'price_start_from' => 'required|numeric|min:0',
'overview' => 'required|string',
'included_things' => 'required|string',
'Excludes_things' => 'required|string',
'tour_plane_description' => 'required|string',
'per_adult_fee' => 'required|numeric|min:0',
'per_child_fee' => 'required|numeric|min:0',
'service_fee' => 'required|numeric|min:0',
'booking_fee' => 'required|numeric|min:0',
];

$validator = Validator::make($request->all(), $rules);
Expand All @@ -186,18 +178,13 @@ public function update($id, Request $request)
//set the attribute
$travelPackage->package_name = $request->package_name;
$travelPackage->duration = $request->duration;
$travelPackage->duration_type = $request->duration_type;
$travelPackage->tour_type = $request->tour_type;
$travelPackage->package_type = $request->package_type;
$travelPackage->price_start_from = $request->price_start_from;
$travelPackage->overview = $request->overview;
$travelPackage->included_things = $request->included_things;
$travelPackage->Excludes_things = $request->Excludes_things;
$travelPackage->tour_plane_description = $request->tour_plane_description;
$travelPackage->per_adult_fee = $request->per_adult_fee;
$travelPackage->per_child_fee = $request->per_child_fee;
$travelPackage->service_fee = $request->service_fee;
$travelPackage->booking_fee = $request->booking_fee;
$travelPackage->save();


Expand Down Expand Up @@ -267,6 +254,13 @@ public function update($id, Request $request)
*/
public function destroy($id)
{
//start booking delete ( delete relationShip)
$bookings = booking::where('package_id', $id)->get();
foreach ($bookings as $booking) {
$booking->delete();
}

//start travel package delete
$travelPackage = travelPackage::findOrFail($id);

//delete image 1
Expand Down
7 changes: 4 additions & 3 deletions app/Models/booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ class booking extends Model
'number_of_child',
'pick_up_location',
'pick_up_location_details',
'accommodation_type',
'transport_method',
'aditional_requarement',
'total_fee',
'Reservation Status',
'Invoice Status',
'Payment Status',
'payment_receipt',
];


Expand Down
11 changes: 0 additions & 11 deletions app/Models/travelPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,21 @@ class travelPackage extends Model
'image_2',
'image_3',
'duration',
'duration_type',
'tour_type',
'package_type',
'price_start_from',
'overview',
'included_things',
'Excludes_things',
'tour_plane_description',
'per_adult_fee',
'per_child_fee',
'service_fee',
'booking_fee',
];

// Optionally, specify the attributes that should be cast to native types
protected $casts = [
'price_start_from' => 'decimal:2',
'per_adult_fee' => 'decimal:2',
'per_child_fee' => 'decimal:2',
'service_fee' => 'decimal:2',
'booking_fee' => 'decimal:2',
];

// Define the relationship with the Booking model
// public function bookings()
// {
// return $this->hasMany(Booking::class, 'travel_packages_id');
// }
}
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
|
*/

'timezone' => env('APP_TIMEZONE', 'UTC'),
'timezone' => env('APP_TIMEZONE', 'Asia/Colombo'),

/*
|--------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit b7dc1a9

Please sign in to comment.