Exemplo n.º 1
0
 /**
  * Define the application's command schedule.
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     $schedule->call(function () {
         $trip_ids = Trip::where('departure_date', Carbon::today())->lists('id')->toArray();
         Booking::where('status', 'reserved')->whereIn('trip_id', $trip_ids)->delete();
     })->everyMinute();
 }
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     view()->composer('coordinates._form', function ($view) {
         $view->with('trips', Trip::lists('name', 'id'));
         $view->with('coordinate_types', CoordinateType::lists('name', 'id'));
     });
 }
Exemplo n.º 3
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $trip = Trip::findOrFail($request->trip_id);
     if (!$trip) {
         return redirect()->back();
     }
     return $next($request);
 }
Exemplo n.º 4
0
 /**
  * A cron that will delete all reservations 24hours to the trip departure date
  */
 public function clean()
 {
     $start = Carbon::today()->startOfDay();
     $end = Carbon::today()->endOfDay();
     $trip_ids = Trip::whereBetween('departure_date', [$start, $end])->lists('id')->toArray();
     $cleaned = Booking::where('status', 'reserved')->whereIn('trip_id', $trip_ids)->delete();
     return $cleaned;
 }
Exemplo n.º 5
0
 /**
  * @return \Illuminate\View\View
  */
 public function dashboard()
 {
     $company_id = Auth::travel_company_staff()->get()->travel_company->id;
     $number_of_trips = Trip::whereraw('travel_company_id = ?', [$company_id])->count();
     $number_of_stations = Station::whereraw('travel_company_id = ?', [$company_id])->count();
     $number_of_paid_bookings = Booking::whereraw('travel_company_id = ? AND status = ?', [$company_id, 'paid'])->count();
     $number_of_travel_bookings = Booking::whereraw('travel_company_id = ? AND status = ? AND updated_at > ?', [$company_id, 'paid', Carbon::today()])->count();
     return view('companies.account.dashboard', ['number_of_trips' => $number_of_trips, 'number_of_stations' => $number_of_stations, 'number_of_paid_bookings' => $number_of_paid_bookings, 'number_of_travel_bookings' => $number_of_travel_bookings]);
 }
Exemplo n.º 6
0
 public function index()
 {
     $totalTrips = Trip::all()->count();
     $totalTravelCompanies = TravelCompany::all()->count();
     $totalUsers = User::all()->count();
     $totalPaidBookings = Booking::where('status', 'paid')->count();
     $totalBus = Rental::all()->count();
     return view('admin.dashboard', ['tT' => $totalTrips, 'tU' => $totalUsers, 'tP' => $totalPaidBookings, 'tC' => $totalTravelCompanies, 'tB' => $totalBus]);
 }
Exemplo n.º 7
0
 public function reservation()
 {
     if (!Session::has('r_trip_id', 'r_passengers', 'r_data')) {
         return redirect()->route('welcome');
     }
     $trip = Trip::find(Session::get('r_trip_id'));
     $passengers = Session::get('r_passengers');
     $data = Session::get('r_data');
     return view('payment.reserved_page', ['passengers' => $passengers, 'trip' => $trip, 'data' => $data]);
 }
Exemplo n.º 8
0
 public function bookTrip($id)
 {
     $trip = Trip::findOrFail($id);
     $user = User::find(1);
     // TODOget curent user
     if ($trip::freeSets(1)) {
         return view('registration', ['trips' => $trips], ['user' => $user]);
     }
     return view('startpage', ['trips' => $trips]);
     // TODO SRY over boocked
 }
Exemplo n.º 9
0
 /**
  * @param int $courier_id
  * @param int $region_id
  * @param Carbon | string $departure_date
  * @return Trip
  */
 public function createTrip($courier_id, $region_id, $departure_date)
 {
     if (!$departure_date instanceof Carbon) {
         $departure_date = Carbon::createFromFormat('Y-m-d', $departure_date);
     }
     $regions = Region::all();
     $arrivalDate = clone $departure_date;
     $arrivalDate->addHours($regions->find($region_id)->time_to);
     $returnDate = clone $arrivalDate;
     $returnDate->addHours($regions->find($region_id)->time_back);
     return Trip::create(['courier_id' => $courier_id, 'region_id' => $region_id, 'departure_date' => $departure_date, 'arrival_date' => $arrivalDate, 'return_date' => $returnDate]);
 }
Exemplo n.º 10
0
 /**
  * deletes item and according image, also updates trip and entry that use this picture as featured image
  *
  * @param $user_id
  * @throws \Exception
  */
 public function deleteWithImage($user_id)
 {
     if ($entry = TripEntry::where('pic', $this->id)->first()) {
         $entry->pic = null;
         $entry->save();
     }
     if ($trip = Trip::where('pic', $this->id)->first()) {
         $trip->pic = null;
         $trip->save();
     }
     //deleting image as well
     File::delete(public_path('img') . '/' . $user_id . '/' . $this->filename);
     $this->delete();
 }
Exemplo n.º 11
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     foreach (range(1, 40) as $i) {
         $date = Carbon::create(2015, 5, 1, 0, 0, 0);
         $courier = Courier::find(rand(1, 10));
         $region = Region::find(rand(1, 10));
         $start_date = $date->addDays(rand(1, 210));
         $end_date = Carbon::create($start_date->year, $start_date->month, $start_date->day + $region->long, 0, 0, 0);
         $trips = Trip::with('courier')->where('courier_id', $courier->id)->get();
         $filtered = $trips->filter(function ($trip) use($start_date, $end_date) {
             $trip_start = Carbon::createFromFormat('Y-m-d', $trip->start)->startOfDay();
             $trip_end = Carbon::createFromFormat('Y-m-d', $trip->end)->startOfDay();
             $trip_in_range = $trip_start->between($start_date, $end_date) || $trip_end->between($start_date, $end_date);
             $trip_over_range = $start_date->lte($trip_start) && $end_date->gte($trip_end);
             return $trip_in_range || $trip_over_range;
         });
         if ($filtered->isEmpty()) {
             Trip::create(array('courier_id' => $courier->id, 'region_id' => $region->id, 'start' => $start_date->format('Y-m-d'), 'end' => $end_date->format('Y-m-d')));
         }
     }
 }
Exemplo n.º 12
0
 /**
  * @param $code
  * @param $trip_id
  * @param $passengers
  *
  * @return bool
  */
 public function checkIfCashCardCodeIsValid($code, $trip_id, $passengers)
 {
     $trip = Trip::find($trip_id);
     $card = CashCode::whereraw('code = ?', [$code])->first();
     if ($card) {
         $price = $card->price;
         $card_id = $card->id;
         if ($price == $trip->fare * $passengers) {
             Session::put('card_id', $card_id);
             $this->useCard($card_id);
             return true;
         } elseif ($price > $trip->fare * $passengers) {
             Session::put('card_id', $card_id);
             $this->useCard($card_id);
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Exemplo n.º 13
0
 public function postCreate(Request $request)
 {
     $this->validate($request, ['start' => 'required']);
     $courier = Courier::find($request->get('courier_id'));
     $region = Region::find($request->get('region_id'));
     $start_date = Carbon::createFromFormat('d.m.Y', $request->get('start'));
     $end_date = Carbon::create($start_date->year, $start_date->month, $start_date->day + $region->long, 0, 0, 0);
     $trips = Trip::with('courier')->where('courier_id', $courier->id)->get();
     $filtered = $trips->filter(function ($trip) use($start_date, $end_date) {
         $trip_start = Carbon::createFromFormat('Y-m-d', $trip->start)->startOfDay();
         $trip_end = Carbon::createFromFormat('Y-m-d', $trip->end)->startOfDay();
         $trip_in_range = $trip_start->between($start_date, $end_date) || $trip_end->between($start_date, $end_date);
         $trip_over_range = $start_date->lte($trip_start) && $end_date->gte($trip_end);
         return $trip_in_range || $trip_over_range;
     });
     if ($filtered->isEmpty()) {
         Trip::create(array('courier_id' => $courier->id, 'region_id' => $region->id, 'start' => $start_date->format('Y-m-d'), 'end' => $end_date->format('Y-m-d')));
         return $request->ajax() ? 'Поездка успешно добавлена' : redirect()->to('/');
     } else {
         return $request->ajax() ? 'В указанный период уже есть поездки' : redirect()->back()->withInput();
     }
 }
Exemplo n.º 14
0
 public function home()
 {
     $trips = Trip::getRandomTrips(4);
     return view('index', compact('trips'));
 }
Exemplo n.º 15
0
 public function showRanges($id)
 {
     return view('trips.index', ['trips' => Trip::where('range_id', $id)->get()]);
 }
Exemplo n.º 16
0
 public function getIndex()
 {
     return view('schedule')->with('schedules', Trip::all());
     // TODO: lazy loading!
 }
Exemplo n.º 17
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $trips = Trip::all();
     return view('trips.index', compact('trips'));
 }
Exemplo n.º 18
0
 /**
  * create Trip with user id
  *
  * @param $attr
  * @param $id
  * @return static
  */
 public static function createWithUserId($attr, $id)
 {
     $attr['user_id'] = $id;
     return Trip::create($attr);
 }
Exemplo n.º 19
0
 /**
  * Remove the specified resource from storage.
  *
  * @param $trip_id
  * @param $entry_id
  * @return Response
  * @internal param int $id
  */
 public function destroy($trip_id, $entry_id)
 {
     $trip = Trip::findOrFail($trip_id);
     $entry = TripEntry::findOrFail($entry_id);
     if (Auth::user()->id == $trip->user_id) {
         $entry->delete();
         return redirect(url('trip') . '/' . $trip_id);
     } else {
         return 'You are not authorized to delete this entry!';
     }
 }
Exemplo n.º 20
0
 /**
  * Delete a given trip and redirect with a flash message.
  *
  * @param Trip $trip
  */
 public function destroy(Trip $trip)
 {
     $trip->delete();
     return redirect('admin/trips')->with(['flash_message' => 'Viagem deletada.', 'flash_message_level' => 'success']);
 }
Exemplo n.º 21
0
 /**
  * @param $from
  * @param $to
  *
  * @return array
  */
 private function getTodayOneWayTrips($from, $to)
 {
     //		dd($this->time->currentTimeFrame());
     if ($this->time->currentTimeFrame() == "Morning") {
         $trips = Trip::whereraw('departure_date = ? AND departure_station = ? AND destination_station = ?', [Carbon::today(), $from, $to])->whereIn('departure_time', ['Afternoon', 'Evening'])->get();
     } elseif ($this->time->currentTimeFrame() == "Afternoon" or $this->time->currentTimeFrame() == "Evening") {
         //		    $trips = Trip::whereraw('departure_date = ? AND departure_station = ? AND destination_station = ?',
         //			    [Carbon::today(), $from, $to])
         //			    ->where('departure_time', 'Evening')
         //			    ->get();
         $trips = [];
     } else {
         $trips = [];
     }
     return $trips;
 }
Exemplo n.º 22
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $tripID, $id)
 {
     // create the new Order
     $shoot = Shoot::find($id);
     $trip = Trip::find($tripID);
     $bullet = Bullet::find($request->bullet_id);
     // Get the data
     $shoot->rounds = $request->rounds;
     $shoot->firearm_id = $request->firearm_id;
     $shoot->notes = $request->notes;
     $shoot->trip()->associate($trip);
     $shoot->bullet()->associate($bullet);
     // Save the Order
     $shoot->save();
     // Update inventory for all Bullets
     Bullet::updateInventory();
     session()->flash('message', 'Shoot has been Saved');
     session()->flash('message-type', 'success');
     return redirect()->action('ShootController@show', [$trip->id, $shoot->id]);
 }
Exemplo n.º 23
0
 /**
  * @param $trip_id
  *
  * @return mixed
  */
 private function checkIfTripIsAvailable($trip_id)
 {
     $trip = Trip::find($trip_id);
     return $trip;
 }
Exemplo n.º 24
0
 /**
  * @param $reporting_time
  * @param $time_frame
  *
  * @return bool
  */
 public function isTimeCorrect($reporting_time, $time_frame, $trip_id)
 {
     $trip = Trip::find($trip_id);
     //			dd($trip);
     $realTime = $this->carbonDate($trip_id, $this->carbonize($this->timeStringtify($reporting_time)));
     $from = $time_frame['from'];
     $to = $time_frame['to'];
     if ($from <= $realTime and $realTime <= $to) {
         //				dd('cool');
         return true;
     } else {
         //				dd($realTime);
         return false;
     }
 }
Exemplo n.º 25
0
 public function show($id)
 {
     $trip = Trip::findOrFail($id)->first();
     return view('trajetos.show', compact('trip'));
 }
Exemplo n.º 26
0
 public function tripById($tripId)
 {
     $tripDetails = Trip::getTripbyId($tripId);
     $tripInfo = $tripDetails[0]->trip_object;
     return json_encode(json_decode($tripInfo));
 }
Exemplo n.º 27
0
 /**
  * @param Request $request
  *
  * @return $this|\Illuminate\View\View
  */
 public function pay_reserve_booking_now(Request $request)
 {
     $booking = Booking::find($request->booking_id);
     $trip = Trip::find($booking->trip_id);
     $trip_id = $trip->id;
     $passengers = 1;
     $travel_company_id = $trip->travel_company_id;
     if ($request->has('cashcard_code')) {
         $code = strtoupper($request->cashcard_code);
         if ($this->cashCard->checkIfCashCardCodeIsValid($code, $trip->id, $passengers)) {
             $status = "paid";
             $booking->status = $status;
             $booking->ticket_number = rand() . time();
             $booking->save();
             Payment::create(['trip_id' => $booking->trip->id, 'amount' => $booking->trip->fare, 'user_id' => Auth::user()->get()->id, 'booking_id' => $booking->id, 'travel_company_id' => $travel_company_id]);
             $user = Auth::user()->get();
             //				$mail = view('mails.ticket')->render();
             Session::put('r_b_c_data', $booking);
             Session::put('r_b_c_passengers', $passengers);
             Session::put('r_b_c_trip_id', $trip_id);
             //				Mail::send('mails.new', ['user' => $user], function ($m) use ($user) {
             //		            $m->to($user->email, $user->name)->subject('Passenger name booking detail');
             //		        });
             return redirect()->route('reserved-trip-paid');
         } else {
             return redirect()->back()->withErrors('There was a problem processing the payment');
         }
     } elseif ($request->has('speedBanking_code')) {
         $code = $request->speed_banking_code;
         if ($this->cashCard->checkIfCashCardCodeIsValid($code, $trip->id, $passengers)) {
             dd('paying speedBanking');
             $status = "paid";
             //				$this->insert($passengers, $request->all(), $user_id, $trip_id, $status);
             return view('payment.success');
         } else {
             return redirect()->back()->withErrors('There was a problem processing the payment');
         }
     }
 }
Exemplo n.º 28
0
 public function editTrips($id)
 {
     $trip = Trip::findOrDie($id);
     return view('adminTripEdit', ['trip' => $trip]);
 }
Exemplo n.º 29
0
 public function home()
 {
     $trips = Trip::all();
     $routes = Route::all();
     return view('home', compact('trips', 'routes'));
 }
Exemplo n.º 30
0
 /**
  * Remove the specified resource from storage.
  *
  * @param $trip_id
  * @param $entry_id
  * @param $pic_id
  * @return Response
  * @internal param int $id
  */
 public function destroy($trip_id, $entry_id, $pic_id)
 {
     $pic = Picture::findOrFail($pic_id);
     $trip = Trip::findOrFail($trip_id);
     $entry = TripEntry::findOrFail($entry_id);
     $user = Auth::user();
     if (Auth::user()->id == $trip->user_id && $trip->id == $entry->trip_id && $pic->trip_entry_id == $entry->id) {
         $pic->deleteWithImage($user->id);
         return redirect(url('trip') . '/' . $trip_id . '/entry/' . $entry->id);
     } else {
         return 'You are not authorized to delete this picture!';
     }
 }