Ejemplo n.º 1
0
 public function success(Request $request, Reservation $reservation)
 {
     //change reservation status to complete
     $payment_id = Session::get('paypal_payment_id');
     $reservation->status = 1;
     $reservation->payment_id = $payment_id;
     $cruise = Cruise::find($reservation->cruise_id);
     $cabin = Cabin::find($reservation->cabin_id);
     //deduct cabin number in the cruise
     DB::table('cruises_cabins')->where('cruise_id', $reservation->cruise_id)->where('cabin_id', $reservation->cabin_id)->increment('cabin_booked');
     $reservation->save();
     Session::forget('paypal_payment_id');
     $full = 0;
     foreach ($cruise->cabins as $cabin) {
         if ($cabin->pivot->cabin_number == $cabin->pivot->cabin_booked) {
             $full++;
         }
     }
     if ($full == Cabin::all()->count()) {
         $cruise->status = 1;
         $cruise->save();
     }
     return view('user.reservation', ['cruise' => $cruise, 'cabin' => $cabin, 'amenities' => $reservation->amenities()->get(), 'reservation' => $reservation])->with('status', 'Payment succcess!');
 }
Ejemplo n.º 2
0
 public function postNewPromotion(Request $request)
 {
     $this->validate($request, ['name' => 'required|max:50', 'discount' => 'required|numeric|min:1|max:100', 'type' => 'required|numeric|min:1|max:100', 'image' => 'image', 'promo_date' => 'max:23']);
     //create a new promotion
     $promotion = Promotion::create(['name' => $request->name, 'discount' => $request->discount, 'type' => $request->type, 'description' => $request->description]);
     //process dates
     if (!empty($request->promo_date)) {
         $dates = explode(" - ", $request->promo_date);
         $promotion->start_date = DateTime::createFromFormat('m/d/Y', $dates[0])->format('Y-m-d');
         $promotion->end_date = DateTime::createFromFormat('m/d/Y', $dates[1])->format('Y-m-d');
         //check if promotion is activated on create
         if ($dates[0] <= new DateTime("now") && $dates[1] > new DateTime("now")) {
             $promotion_status = 1;
         } else {
             $promotion_status = 0;
         }
     }
     if (Input::hasFile('image')) {
         $file = Input::file('image');
         $imagename = 'promotion_' . $promotion->id . '.' . Input::file('image')->getClientOriginalExtension();
         $file->move('uploads', $imagename);
         $promotion->image = $imagename;
     }
     $promotion->save();
     //attach promotion to selected items
     $cruises = Input::get('cruises');
     $cabins = Input::get('cabins');
     $amenities = Input::get('amenities');
     if (!empty($cruises)) {
         foreach ($cruises as $key => $val) {
             $cruise = Cruise::find($val);
             $cruise->promotion_id = $promotion->id;
             $cruise->save();
         }
     } else {
         if (!empty($cabins)) {
             foreach ($cabins as $key => $val) {
                 $cabin = Cabin::find($val);
                 $cabin->promotion_id = $promotion->id;
                 $cabin->save();
             }
         } else {
             if (!empty($amenities)) {
                 foreach ($amenities as $key => $val) {
                     $amenity = Amenity::find($val);
                     $amenity->promotion_id = $promotion->id;
                     $amenity->save();
                 }
             }
         }
     }
     return redirect('/admin/promotion/' . $promotion->id)->with('status', 'Promotion created!');
 }