/**
  * make Reservation
  * @param  User     $issuer   Requested by User as issuer
  * @param  Business $business For Business
  * @param  Contact  $contact  On behalf of Contact
  * @param  Service  $service  For Service
  * @param  Carbon   $datetime     for Date and Time
  * @param  string   $comments     optional issuer comments for the appointment
  * @return Appointment|boolean             Generated Appointment or false
  */
 public function makeReservation(User $issuer, Business $business, Contact $contact, Service $service, Carbon $datetime, $comments = null)
 {
     $bookingStrategy = new BookingStrategy($business->strategy);
     $appointment = $bookingStrategy->generateAppointment($issuer, $business, $contact, $service, $datetime, $comments);
     if ($appointment->duplicates()) {
         return $appointment;
     }
     $availability = new AvailabilityServiceLayer($business);
     $vacancy = $availability->getSlotFor($appointment);
     if (null !== $vacancy) {
         if ($vacancy->hasRoom()) {
             $appointment->vacancy()->associate($vacancy);
             $appointment->save();
             return $appointment;
         }
     }
     return false;
 }
 /**
  * @covers  App\BookingStrategy::generateAppointment
  * @covers  App\BookingDateslotStrategy::generateAppointment
  * @test
  */
 public function it_generates_a_timeslot_appointment()
 {
     $owner = $this->createUser();
     $contact = $this->makeContact($owner);
     $contact->save();
     $business = $this->makeBusiness($owner, ['strategy' => 'timeslot']);
     $business->save();
     $service = $this->makeService();
     $business->services()->save($service);
     $bookingStrategy = new BookingStrategy($business->strategy);
     $dateTime = Carbon::now()->addDays(5);
     $appointment = $bookingStrategy->generateAppointment($owner, $business, $contact, $service, $dateTime, 'test comments');
     $this->assertInstanceOf(Appointment::class, $appointment);
     $this->assertEquals($appointment->issuer->id, $owner->id);
     $this->assertEquals($appointment->contact->name, $contact->name);
     $this->assertEquals($appointment->service->name, $service->name);
     $this->assertEquals($appointment->date, $dateTime->toDateString());
     $this->assertEquals($appointment->comments, 'test comments');
     $this->assertEquals(32, strlen($appointment->hash));
 }
Example #3
0
 /**
  * Build timetable.
  *
  * @param Illuminate\Database\Eloquent\Collection $vacancies
  * @param string                                  $starting
  * @param int                                     $days
  *
  * @return array
  */
 public function buildTimetable($vacancies, $starting = 'today', $days = 10)
 {
     return $this->strategy->buildTimetable($vacancies, $starting, $days);
 }
Example #4
0
 /**
  * make Reservation.
  *
  * @param User     $issuer   Requested by User as issuer
  * @param Business $business For Business
  * @param Contact  $contact  On behalf of Contact
  * @param Service  $service  For Service
  * @param Carbon   $datetime for Date and Time
  * @param string   $comments optional issuer comments for the appointment
  *
  * @return Appointment|bool Generated Appointment or false
  */
 public function makeReservation(User $issuer, Business $business, Contact $contact, Service $service, Carbon $datetime, $comments = null)
 {
     //////////////////
     // FOR REFACTOR //
     //////////////////
     $this->setBusiness($business);
     $bookingStrategy = new BookingStrategy($business->strategy);
     $appointment = $bookingStrategy->generateAppointment($issuer, $business, $contact, $service, $datetime, $comments);
     if ($appointment->duplicates()) {
         return $appointment;
         # throw new \Exception('Duplicated Appointment Attempted');
     }
     $vacancy = $this->vacancyService->getSlotFor($appointment->start_at, $appointment->service);
     if (null !== $vacancy) {
         if ($vacancy->hasRoom()) {
             $appointment->vacancy()->associate($vacancy);
             $appointment->save();
             return $appointment;
         }
     }
     return false;
 }