<?php
namespace AdminBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints\DateTime;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping\OrderBy;
#[ORM\Table(name: 'booking_request')]
#[ORM\Index(name: 'status_date_index', columns: ['booking_status', 'pick_up_date', 'pick_up_time'])]
#[ORM\Index(name: 'pickup_address_index', columns: ['pick_up_address', 'booking_status'])]
#[ORM\Index(name: 'destination_address_index', columns: ['destination_address', 'booking_status'])]
#[ORM\Index(name: 'client_first_name_index', columns: ['client_first_name', 'booking_status'])]
#[ORM\Index(name: 'client_last_name_index', columns: ['client_last_name', 'booking_status'])]
#[ORM\Index(name: 'client_email_index', columns: ['client_email', 'booking_status'])]
#[ORM\Index(name: 'client_phone_index', columns: ['client_phone', 'booking_status'])]
#[ORM\Entity(repositoryClass: \AdminBundle\Repository\BookingRequestRepository::class)]
class BookingRequest extends BaseEntity
{
const STATUS_DELETED = 0;
const STATUS_NEW_BOOKING = 1; //New booking in the web app system - not allocated/not dispatched
const STATUS_DISPATCHED = 10; //Booking Dispatched to specific driver X
const STATUS_DRIVER_REJECT = 11; //Driver X reject booking
const STATUS_DRIVER_ACCEPT = 12; // Driver X accept booking
const STATUS_ON_THE_WAY = 13; // The driver is on the way
const STATUS_ARRIVED_AND_WAITING = 14; // The driver arrived and waiting passenger
const STATUS_PASSENGER_ON_BOARD = 15; // Passenger up to car
const STATUS_ABOUT_TO_DROP = 16; // almost at destination
const STATUS_COMPLETED = 17;
const STATUS_BROADCAST = 20; // booking sent to all available / qualified drivers
const STATUS_ARCHIVED = 21; // booking sent to archive
const STATUS_DEALLOCATED_ON_DEMAND = 25; //Before pick up
const STATUS_DEALLOCATED_LATE_PICKUP = 26; //Before pick up
const STATUS_DEALLOCATED_NO_LONGER_AVAILABLE = 27; //Before pick up
const STATUS_DEALLOCATED_CAR_BROKE_DOWN = 28; //Before pick up
const STATUS_DEALLOCATED_OFFICE = 29; //Before pick up
const STATUS_CANCELLED_OTHER_REASON = 30; //Cancellation with no defined reason
const STATUS_CLIENT_CANCELLATION = 31;
const STATUS_CLIENT_NOT_SHOW_UP = 32;
const STATUS_CAR_BROKE_DOWN = 33; // the part with timer
const STATUS_OFFICE_CANCELLATION = 34; //headquarter initiated cancellation
const STATUS_PENDING = 90; //New booking but not paid ( external sources - website )
const STATUS_PENDING_CANCELLATION = 91; //Special status from the office due to non payment
static $statusTypes = [
self::STATUS_DELETED => 'Deleted',
self::STATUS_NEW_BOOKING => 'New booking',
self::STATUS_DISPATCHED => 'Dispatched',
self::STATUS_DRIVER_REJECT => 'Dispatched reject',
self::STATUS_DRIVER_ACCEPT => 'Dispatched accept',
self::STATUS_ON_THE_WAY => 'On the way',
self::STATUS_ARRIVED_AND_WAITING => 'Arrived and waiting',
self::STATUS_PASSENGER_ON_BOARD => 'Passenger on board',
self::STATUS_ABOUT_TO_DROP => 'About to drop',
self::STATUS_COMPLETED => 'Completed',
self::STATUS_ARCHIVED => 'Archived',
self::STATUS_BROADCAST => 'ASAP Notification',
self::STATUS_DEALLOCATED_ON_DEMAND => 'Deallocated on demand',
self::STATUS_DEALLOCATED_LATE_PICKUP => 'Deallocated - Late for pickup',
self::STATUS_DEALLOCATED_NO_LONGER_AVAILABLE => 'Deallocated - No longer available',
self::STATUS_DEALLOCATED_CAR_BROKE_DOWN => 'Deallocated - Car broke down',
self::STATUS_DEALLOCATED_OFFICE => 'Deallocated - Office Deallocation',
self::STATUS_CANCELLED_OTHER_REASON => 'Cancelled Other Reason',
self::STATUS_CLIENT_CANCELLATION => 'Client cancellation',
self::STATUS_CLIENT_NOT_SHOW_UP => 'Client didn’t show up',
self::STATUS_CAR_BROKE_DOWN => 'Car broke down',
self::STATUS_OFFICE_CANCELLATION => 'Office cancellation',
self::STATUS_PENDING => 'Pending',
self::STATUS_PENDING_CANCELLATION => 'Pending Cancellation'
];
/**
* @var integer
*/
#[ORM\Column(name: 'id', type: 'integer', nullable: false)]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
protected $id;
/**
* @var string
*/
#[ORM\Column(name: 'booking_key', type: 'string', length: 255, nullable: false, unique: true)]
protected $key;
/**
* @var string
*/
#[ORM\Column(name: 'booking_created_key', type: 'string', length: 255, nullable: true)]
protected $bookingCreatedKey;
/**
* @var integer
*/
#[ORM\Column(name: 'booking_status', type: 'integer')]
protected $status = self::STATUS_BROADCAST;
/**
* @var integer
*/
#[ORM\Column(name: 'drivers_confirmed_number', type: 'integer')]
protected $driversConfirmedNumber = 0;
/**
* @var CarType
*/
#[ORM\JoinColumn(name: 'car_type_id', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: \AdminBundle\Entity\CarType::class)]
protected $carType;
/**
* @var float
*/
#[ORM\Column(name: 'quote_price', type: 'decimal', precision: 7, scale: 2, nullable: true)]
#[Assert\NotBlank]
protected $quotePrice = 0;
/**
* @var float
*/
#[ORM\Column(name: 'override_price', type: 'decimal', precision: 7, scale: 2, nullable: true)]
protected $overridePrice = 0;
/**
* @var string
*/
#[ORM\Column(name: 'flight_number', type: 'string', length: 260, nullable: true)]
protected $flightNumber;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'flight_landing_time', type: 'time', nullable: true)]
protected $flightLandingTime;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'waiting_time', type: 'time', nullable: true)]
protected $waitingTime;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'job_waiting_time', type: 'time', nullable: true)]
protected $jobWaitingTime;
/**
* @var string
*/
#[ORM\Column(name: 'return_flight_number', type: 'string', length: 260, nullable: true)]
protected $returnFlightNumber;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'return_flight_landing_time', type: 'time', nullable: true)]
protected $returnFlightLandingTime;
/**
* @var float
*/
#[ORM\Column(name: 'driver_price', type: 'decimal', precision: 7, scale: 2, nullable: true)]
protected $driverPrice;
/**
* @var float
*/
#[ORM\Column(name: 'return_driver_price', type: 'decimal', precision: 7, scale: 2, nullable: true)]
protected $returnDriverPrice;
/**
* @var float
*/
#[ORM\Column(name: 'distance_unit', type: 'float', nullable: true)]
#[Assert\NotBlank]
protected $distanceUnit;
/**
* @var string
*/
#[Assert\NotBlank]
#[ORM\Column(name: 'estimated_time', type: 'text', nullable: true, length: 255)]
protected $estimatedTime;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'booking_date', type: 'datetime', nullable: true)]
protected $bookingDate;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'expire_broadcast_date', type: 'datetime', nullable: true)]
protected $expireBroadcastDate;
/**
* @var Driver
*/
#[ORM\JoinColumn(name: 'driver_id', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: \Driver::class, inversedBy: 'bookings_request')]
protected $driver;
/**
* @var Car
*/
#[ORM\JoinColumn(name: 'car_id', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: \Car::class)]
protected $car;
/**
* @var string
*/
#[ORM\Column(name: 'pick_up_address', type: 'string', length: 255, nullable: false)]
protected $pickUpAddress;
/**
* @var float
*/
#[ORM\Column(name: 'pmg', type: 'decimal', precision: 7, scale: 2, nullable: true)]
protected $pmg;
/**
* @var float
*/
#[ORM\Column(name: 'return_pmg', type: 'decimal', precision: 7, scale: 2, nullable: true)]
protected $returnPmg;
/**
* @var float
*/
#[ORM\Column(name: 'pick_up_lat', type: 'float', precision: 10, scale: 6, nullable: true)]
protected $pickUpLat;
/**
* @var float
*/
#[ORM\Column(name: 'pick_up_lng', type: 'float', precision: 10, scale: 6, nullable: true)]
protected $pickUpLng;
/**
* @var string
*/
#[ORM\Column(name: 'pick_up_post_code', type: 'string', length: 10)]
protected $pickUpPostCode;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'pick_up_date', type: 'datetime', nullable: false)]
protected $pickUpDate;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'pick_up_time', type: 'time', nullable: false)]
protected $pickUpTime;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'pick_up_date_time', type: 'datetime', nullable: true)]
protected $pickUpDateTime;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'return_pick_up_date', type: 'datetime', nullable: true)]
protected $returnPickUpDate;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'return_pick_up_time', type: 'time', nullable: true)]
protected $returnPickUpTime;
/**
* @var string
*/
#[ORM\Column(name: 'destination_address', type: 'string', length: 255, nullable: false)]
protected $destinationAddress;
/**
* @var float
*/
#[ORM\Column(name: 'destination_lat', type: 'float', precision: 10, scale: 6, nullable: true)]
protected $destinationLat;
/**
* @var float
*/
#[ORM\Column(name: 'destination_lng', type: 'float', precision: 10, scale: 6, nullable: true)]
protected $destinationLng;
/**
* @var string
*/
#[ORM\Column(name: 'destination_post_code', type: 'string', length: 10)]
protected $destinationPostCode;
/**
* @var integer
*/
#[ORM\Column(name: 'passengers_number', type: 'integer', nullable: true)]
protected $passengersNumber = 1;
/**
* @var string
*/
#[ORM\Column(name: 'hand_luggage', type: 'string', length: 64, nullable: true)]
protected $handLuggage = 0;
/**
* @var string
*/
#[ORM\Column(name: 'checkin_luggage', type: 'string', length: 64, nullable: true)]
protected $checkinLuggage = 0;
/**
* @var string
*/
#[ORM\Column(name: 'notes', type: 'text', nullable: true)]
protected $notes;
/**
* @var string
*/
#[ORM\Column(name: 'return_booking_notes', type: 'text', nullable: true)]
protected $returnBookingNotes;
/**
* @var string
*/
#[ORM\Column(name: 'client_first_name', type: 'string', length: 64, nullable: true)]
protected $clientFirstName;
/**
* @var string
*/
#[ORM\Column(name: 'client_last_name', type: 'string', length: 64, nullable: true)]
protected $clientLastName;
/**
* @var string
*/
#[ORM\Column(name: 'client_phone', type: 'string', length: 64, nullable: true)]
protected $clientPhone;
/**
* @var string
*/
#[ORM\Column(name: 'client_email', type: 'string', length: 64, nullable: true)]
protected $clientEmail;
/**
* @var string
*/
#[ORM\Column(name: 'client_alternative_phone', type: 'string', length: 64, nullable: true)]
protected $clientAlternativePhone;
/**
* @var string
*/
#[ORM\Column(name: 'client_alternative_email', type: 'string', length: 64, nullable: true)]
protected $clientAlternativeEmail;
/**
* @var ArrayCollection
*/
#[ORM\OneToMany(targetEntity: \BookingViasAddress::class, mappedBy: 'bookingRequest', cascade: ['persist', 'remove'], orphanRemoval: true)]
protected $vias;
#[ORM\OneToMany(targetEntity: \BookingBookingExtra::class, mappedBy: 'bookingRequest', cascade: ['persist'])]
protected $extras;
/**
* @var User
*/
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: true)]
#[ORM\ManyToOne(targetEntity: \User::class, cascade: ['all'])]
protected $clientUser;
/**
* @var string
*/
#[ORM\Column(name: 'voucher_code', type: 'string', length: 64, nullable: true)]
protected $voucherCode;
/**
* @var string
*/
#[ORM\Column(name: 'voucher_value', type: 'decimal', precision: 7, scale: 2, nullable: true)]
protected $voucherValue;
/**
* @var boolean
*/
#[ORM\Column(name: 'create_account', type: 'boolean')]
private $createAccount = true;
/**
* @var BookingRequest
*/
#[ORM\JoinColumn(name: 'return_booking_request_id', referencedColumnName: 'id')]
#[ORM\OneToOne(targetEntity: \BookingRequest::class, inversedBy: 'parentBooking', cascade: ['persist', 'remove'])]
protected $returnBooking;
/**
* @var BookingRequest
*/
#[ORM\OneToOne(targetEntity: \BookingRequest::class, mappedBy: 'returnBooking')]
protected $parentBooking;
/**
* @var string
*/
#[ORM\Column(name: 'booking_data_serialized', type: 'json', nullable: true)]
private $bookingDataSerialized;
/**
* @var string
*/
#[ORM\Column(name: 'notified_drivers', type: 'text', nullable: true)]
protected $notifiedDrivers;
public function __construct()
{
$this->driversConfirmedNumber = 0;
$this->bookingDate = new \DateTime();
$this->vias = new ArrayCollection();
$this->extras = new ArrayCollection();
$this->generateKey();
}
public function generateKey()
{
$length = 8;
$this->setKey(strtoupper(substr(md5(uniqid()), mt_rand(0,31 - $length), $length)));
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return string
*/
public function getKey()
{
return $this->key;
}
/**
* @param string $key
*/
public function setKey($key)
{
$this->key = $key;
}
/**
* @return \DateTime
*/
public function getExpireBroadcastDate()
{
return $this->expireBroadcastDate;
}
/**
* @param \DateTime $expireBroadcastDate
*/
public function setExpireBroadcastDate($expireBroadcastDate)
{
$this->expireBroadcastDate = $expireBroadcastDate;
}
/**
* @return float
*/
public function getQuotePrice()
{
return $this->quotePrice;
}
/**
* @param float $quotePrice
*/
public function setQuotePrice($quotePrice)
{
$this->quotePrice = $quotePrice;
}
/**
* @return float
*/
public function getOverridePrice()
{
return $this->overridePrice;
}
/**
* @param float $overridePrice
*/
public function setOverridePrice($overridePrice)
{
$this->overridePrice = $overridePrice;
}
/**
* @return float
*/
public function getDriverPrice()
{
return $this->driverPrice;
}
/**
* @param float $driverPrice
*/
public function setDriverPrice($driverPrice)
{
$this->driverPrice = $driverPrice;
}
/**
* @return float
*/
public function getReturnDriverPrice()
{
return $this->returnDriverPrice;
}
/**
* @param float $returnDriverPrice
*/
public function setReturnDriverPrice($returnDriverPrice)
{
$this->returnDriverPrice = $returnDriverPrice;
}
/**
* @return \DateTime
*/
public function getBookingDate()
{
return $this->bookingDate;
}
/**
* @param \DateTime $bookingDate
*/
public function setBookingDate($bookingDate)
{
$this->bookingDate = $bookingDate;
}
/**
* @return int
*/
public function getStatus()
{
return $this->status;
}
/**
* @param int $status
*/
public function setStatus($status)
{
$this->status = $status;
}
/**
* @return int
*/
public function getDriversConfirmedNumber()
{
return $this->driversConfirmedNumber;
}
/**
* @param int $driversConfirmedNumber
*/
public function setDriversConfirmedNumber($driversConfirmedNumber)
{
$this->driversConfirmedNumber = $driversConfirmedNumber;
}
public function incrementDriversConfirmedNumber()
{
$this->driversConfirmedNumber++;
}
/**
* @return mixed
*/
public function getRoundTripBookingId()
{
return $this->roundTripBookingId;
}
/**
* @param mixed $roundTripBookingId
*/
public function setRoundTripBookingId($roundTripBookingId)
{
$this->roundTripBookingId = $roundTripBookingId;
}
/**
* @return Driver
*/
public function getDriver()
{
return $this->driver;
}
/**
* @param mixed $driver
*/
public function setDriver($driver)
{
$this->driver = $driver;
}
/**
* @return Car
*/
public function getCar()
{
return $this->car;
}
/**
* @param mixed $car
*/
public function setCar($car)
{
$this->car = $car;
}
/**
* @return mixed
*/
public function getExtras()
{
return $this->extras;
}
/**
* @param ArrayCollection $extras
*/
public function setExtras($extras)
{
$this->extras = $extras;
}
public function addExtra($extra)
{
$this->extras->add($extra);
}
/**
* @return string
*/
public function getPickUpAddress()
{
return $this->pickUpAddress;
}
/**
* @param string $pickUpAddress
*/
public function setPickUpAddress($pickUpAddress)
{
$this->pickUpAddress = $pickUpAddress;
}
/**
* @return string
*/
public function getPickUpTime($timeFormat = 'H:i')
{
if (! $this->pickUpTime) {
return ;
}
return $this->pickUpTime->format($timeFormat);
}
/**
* @param \DateTime|string $pickUpTime
*/
public function setPickUpTime($pickUpTime)
{
if (is_string($pickUpTime)) {
$timeArray = explode(':', $pickUpTime);
$pickUpTime = new \DateTime();
$pickUpTime->setTime($timeArray[0], $timeArray[1]);
}
$this->pickUpTime = $pickUpTime;
$this->updatePickUpDateTime();
}
/**
* @return \DateTime
*/
public function getPickUpDateTime()
{
return $this->pickUpDateTime;
}
/**
* @return string
*/
public function getDestinationAddress()
{
return $this->destinationAddress;
}
/**
* @param string $destinationAddress
*/
public function setDestinationAddress($destinationAddress)
{
$this->destinationAddress = $destinationAddress;
}
/**
* @return int
*/
public function getPassengersNumber()
{
return $this->passengersNumber;
}
/**
* @param int $passengersNumber
*/
public function setPassengersNumber($passengersNumber)
{
$this->passengersNumber = $passengersNumber;
}
public function getStringStatus($statusType)
{
return self::$statusTypes[$statusType];
}
/**
* @return string
*/
public function getHandLuggage()
{
return $this->handLuggage;
}
/**
* @param string $handLuggage
*/
public function setHandLuggage($handLuggage)
{
$this->handLuggage = $handLuggage;
}
/**
* @return string
*/
public function getCheckinLuggage()
{
return $this->checkinLuggage;
}
/**
* @param string $checkinLuggage
*/
public function setCheckinLuggage($checkinLuggage)
{
$this->checkinLuggage = $checkinLuggage;
}
/**
* @return string
*/
public function getNotes()
{
return $this->notes;
}
/**
* @param string $notes
*/
public function setNotes($notes)
{
$this->notes = $notes;
}
/**
* @return User
*/
public function getClientUser()
{
return $this->clientUser;
}
/**
* @param User $clientUser
*/
public function setClientUser($clientUser)
{
$this->clientUser = $clientUser;
}
/**
* @return string
*/
public function getReturnFlightNumber()
{
return $this->returnFlightNumber;
}
/**
* @param string $returnFlightNumber
*/
public function setReturnFlightNumber($returnFlightNumber)
{
$this->returnFlightNumber = $returnFlightNumber;
}
/**
* @return string
*/
public function getReturnFlightLandingTime()
{
if (! $this->returnFlightLandingTime) {
return ;
}
return $this->returnFlightLandingTime->format('H:i');
}
/**
* @param \DateTime|string $returnFlightLandingTime
*/
public function setReturnFlightLandingTime($returnFlightLandingTime)
{
if (is_string($returnFlightLandingTime)) {
$timeArray = explode(':', $returnFlightLandingTime);
$returnFlightLandingTime = new \DateTime();
$returnFlightLandingTime->setTime($timeArray[0], $timeArray[1]);
}
$this->returnFlightLandingTime = $returnFlightLandingTime;
}
/**
* @return \DateTime
*/
public function getReturnPickUpDate()
{
return $this->returnPickUpDate;
}
/**
* @param \DateTime $returnPickUpDate
*/
public function setReturnPickUpDate($returnPickUpDate)
{
$this->returnPickUpDate = $returnPickUpDate;
}
/**
* @return string
*/
public function getReturnPickUpTime()
{
if (! $this->returnPickUpTime) {
return ;
}
return $this->returnPickUpTime->format('H:i');
}
/**
* @param \DateTime $returnPickUpTime
*/
public function setReturnPickUpTime($returnPickUpTime)
{
if (is_string($returnPickUpTime)) {
$timeArray = explode(':', $returnPickUpTime);
$returnPickUpTime = new \DateTime();
$returnPickUpTime->setTime($timeArray[0], $timeArray[1]);
}
$this->returnPickUpTime = $returnPickUpTime;
}
/**
* @return string
*/
public function getReturnBookingNotes()
{
return $this->returnBookingNotes;
}
/**
* @param string $returnBookingNotes
*/
public function setReturnBookingNotes($returnBookingNotes)
{
$this->returnBookingNotes = $returnBookingNotes;
}
/**
* @param boolean $toSecond
* @return \DateTime|int
*/
public function getWaitingTime($toSecond = false)
{
if ($toSecond) {
return empty($this->waitingTime) ? 0 : (intval($this->waitingTime->format('H')) * 3600) +
(intval($this->waitingTime->format('i')) * 60) +
intval($this->waitingTime->format('s'));
}
return $this->waitingTime;
}
public function getMgMinutes()
{
if (! $this->flightLandingTime) {
return 0;
}
$pickUpTimeComponents = explode(':', $this->pickUpTime->format('H:i'));
$pickUpTimeInMinutes = intval($pickUpTimeComponents[1]) + (intval($pickUpTimeComponents[0]) * 60);
$flightLandingTimeComponents = explode(':', $this->flightLandingTime->format('H:i'));
$flightLandingTimeInMinutes = intval($flightLandingTimeComponents[1]) + (intval($flightLandingTimeComponents[0]) * 60);
if ($flightLandingTimeInMinutes <= $pickUpTimeInMinutes ) {
return 0;
}
return ($flightLandingTimeInMinutes - $pickUpTimeInMinutes);
}
/**
* @param \DateTime $waitingTime
*/
public function setWaitingTime($waitingTime)
{
$this->waitingTime = $waitingTime;
}
/**
* @param bool $toSecond
* @return \DateTime
*/
public function getJobWaitingTime($toSecond = false)
{
if ($toSecond) {
return empty($this->jobWaitingTime) ? 0 : (intval($this->jobWaitingTime->format('H')) * 3600) +
(intval($this->jobWaitingTime->format('i')) * 60) +
intval($this->jobWaitingTime->format('s'));
}
return $this->jobWaitingTime;
}
/**
* @param \DateTime $jobWaitingTime
*/
public function setJobWaitingTime($jobWaitingTime)
{
$this->jobWaitingTime = $jobWaitingTime;
}
/**
* @return string
*/
public function getFlightNumber()
{
return $this->flightNumber;
}
/**
* @param string $flightNumber
*/
public function setFlightNumber($flightNumber)
{
$this->flightNumber = $flightNumber;
}
/**
* @return string
*/
public function getFlightLandingTime()
{
if (! $this->flightLandingTime) {
return ;
}
return $this->flightLandingTime->format('H:i');
}
/**
* @param \DateTime $flightLandingTime
*/
public function setFlightLandingTime($flightLandingTime)
{
if (is_string($flightLandingTime)) {
$timeArray = explode(':', $flightLandingTime);
$flightLandingTime = new \DateTime();
$flightLandingTime->setTime($timeArray[0], $timeArray[1]);
}
$this->flightLandingTime = $flightLandingTime;
}
/**
* @return string
*/
public function getClientFirstName()
{
return $this->clientFirstName;
}
/**
* @param string $clientFirstName
*/
public function setClientFirstName($clientFirstName)
{
$this->clientFirstName = $clientFirstName;
}
/**
* @return string
*/
public function getClientLastName()
{
return $this->clientLastName;
}
/**
* @param string $clientLastName
*/
public function setClientLastName($clientLastName)
{
$this->clientLastName = $clientLastName;
}
/**
* @return string
*/
public function getClientPhone()
{
return $this->clientPhone;
}
/**
* @param string $clientPhone
*/
public function setClientPhone($clientPhone)
{
$this->clientPhone = $clientPhone;
}
/**
* @return string
*/
public function getClientEmail()
{
return $this->clientEmail;
}
/**
* @param string $clientEmail
*/
public function setClientEmail($clientEmail)
{
$this->clientEmail = $clientEmail;
}
public function getVias()
{
return $this->vias;
}
public function setVias($vias)
{
$this->vias = $vias;
}
public function deleteVias($vias)
{
$this->vias->remove($vias);
$vias->setBookingRequest(null);
}
public function addVias(BookingViasAddress $bookingViasAddress)
{
$this->vias->add($bookingViasAddress);
}
public function getViasAsArray() {
$vias = [];
/** @var BookingViasAddress $via */
foreach ($this->vias as $via) {
$vias[] = $via->getAddress();
}
return $vias;
}
public function getCountVias()
{
return count($this->vias)>0?count($this->vias):' ';
}
public function getObjectivesAsArray()
{
$objectives = [];
$bookingData = json_decode($this->getBookingDataSerialized());
$selectedObjectivesIds = $bookingData->selectedObjectives;
if (! $selectedObjectivesIds) {
return ;
}
$selectedObjectivesHours = $bookingData->selectedObjectivesHours;
$tours = $bookingData->tours;
$selectedObjectiveArrayById = [];
foreach ($tours as $tour) {
foreach ($tour->objectives as $objective) {
$selectedObjectiveArrayById[$objective->id.'-'.$tour->tourId] = $objective;
}
}
foreach ($selectedObjectivesIds as $selectedObjectiveId) {
$objectives[] = [
'name' => $selectedObjectiveArrayById[$selectedObjectiveId]->title,
'price' => $selectedObjectiveArrayById[$selectedObjectiveId]->price,
'hour' => $selectedObjectivesHours->$selectedObjectiveId
];
}
return $objectives;
}
public function getReturnObjectivesAsArray()
{
$returnObjectives = [];
$bookingData = json_decode($this->getBookingDataSerialized());
$selectedObjectivesIds = $bookingData->returnSelectedObjectives;
if (! $selectedObjectivesIds) {
return ;
}
$selectedObjectivesHours = $bookingData->returnSelectedObjectivesHours;
$tours = $bookingData->tours;
$selectedObjectiveArrayById = [];
foreach ($tours as $tour) {
foreach ($tour->objectives as $objective) {
$selectedObjectiveArrayById[$objective->id.'-'.$tour->tourId] = $objective;
}
}
foreach ($selectedObjectivesIds as $selectedObjectiveId) {
$returnObjectives[] = [
'name' => $selectedObjectiveArrayById[$selectedObjectiveId]->title,
'price' => $selectedObjectiveArrayById[$selectedObjectiveId]->price,
'hour' => $selectedObjectivesHours->$selectedObjectiveId
];
}
return $returnObjectives;
}
public function getPaymentString()
{
return Payment::TYPE[$this->getPaymentType()];
}
/**
* @return \DateTime
*/
public function getPickUpDate()
{
return $this->pickUpDate;
}
public function setPickUpDate($pickUpDate)
{
$this->pickUpDate = $pickUpDate;
$this->updatePickUpDateTime();
}
public function updatePickUpDateTime()
{
$pickUpDateTime = $this->pickUpDateTime;
if (! $pickUpDateTime) {
$pickUpDateTime = new \DateTime();
if ($this->pickUpDate) {
$pickUpDateTime = clone($this->pickUpDate);
}
}
if ($this->pickUpDate) {
$pickUpDateTime->setDate(
$this->pickUpDate->format('Y'),
$this->pickUpDate->format('m'),
$this->pickUpDate->format('d')
);
}
if ($this->pickUpTime) {
$pickUpDateTime->setTime(
$this->pickUpTime->format('H'),
$this->pickUpTime->format('i')
);
}
$this->pickUpDateTime = clone($pickUpDateTime);
}
public function getPickUpFullDateTime()
{
$date = clone $this->getPickUpDate();
$pickUpTimeComponents = explode(':', $this->getPickUpTime());
$date->setTime($pickUpTimeComponents[0], $pickUpTimeComponents[1]);
return $date;
}
public function estimateEndDateTime()
{
$interval = $this->getEstimatedTime();
$intervalComponents = explode(':', $interval);
$minutes = intval($intervalComponents[0]) * 60 + intval($intervalComponents[1]);
$pickUp = clone $this->pickUpDateTime;
$pickUp->add(new \DateInterval('PT' . $minutes . 'M'));
return $pickUp;
}
public function estimateEndHourString()
{
return $this->estimateEndDateTime()->format('H:i');
}
/**
* @return CarType|null
*/
public function getCarType()
{
return $this->carType;
}
/**
* @param CarType|null $carType
*/
public function setCarType($carType)
{
$this->carType = $carType;
}
/**
* @return float
*/
public function getDistanceUnit()
{
return $this->distanceUnit;
}
/**
* @param float $distanceUnit
*/
public function setDistanceUnit($distanceUnit)
{
$this->distanceUnit = $distanceUnit;
}
/**
* @return string
*/
public function getEstimatedTime()
{
return $this->estimatedTime;
}
/**
* @param string $estimatedTime
*/
public function setEstimatedTime($estimatedTime)
{
$this->estimatedTime = $estimatedTime;
}
/**
* @param bool $seconds
* @return string
*/
public function getEstimatedTimePrettyFormat($seconds = false) {
$prettyEstimatedTime = '0 minutes';
if (!empty($this->estimatedTime)) {
$eT = explode(":", $this->estimatedTime);
if (count($eT) === 3) {
$estimatedTime = "";
if (intval($eT[0]) > 0) {
$estimatedTime .= intval($eT[0]) . "h ";
}
if (intval($eT[1]) > 0) {
$estimatedTime .= intval($eT[1]) . "min ";
}
if (
($seconds || empty($estimatedTime)) &&
intval($eT[2]) > 0
) {
$estimatedTime .= intval($eT[2]) . "s";
}
if (!empty($estimatedTime)) {
$prettyEstimatedTime = $estimatedTime;
}
}
}
return $prettyEstimatedTime;
}
/**
* @return bool
*/
public function isCreateAccount()
{
return $this->createAccount;
}
/**
* @param bool $createAccount
*/
public function setCreateAccount($createAccount)
{
$this->createAccount = $createAccount;
}
/**
* @return BookingRequest|null
*/
public function getReturnBooking()
{
return $this->returnBooking;
}
/**
* @param BookingRequest|null $returnBooking
*/
public function setReturnBooking($returnBooking)
{
$this->returnBooking = $returnBooking;
}
public function __toString()
{
return $this->getId() ? (string) $this->getId() : 'n\a';
}
/**
* @return BookingRequest
*/
public function getParentBooking()
{
return $this->parentBooking;
}
/**
* @param BookingRequest $parentBooking
*/
public function setParentBooking($parentBooking)
{
$this->parentBooking = $parentBooking;
}
/**
* @return string
*/
public function getPickUpPostCode()
{
return $this->pickUpPostCode;
}
/**
* @param string $pickUpPostCode
*/
public function setPickUpPostCode($pickUpPostCode)
{
$this->pickUpPostCode = $pickUpPostCode;
}
/**
* @return string
*/
public function getDestinationPostCode()
{
return $this->destinationPostCode;
}
/**
* @param string $destinationPostCode
*/
public function setDestinationPostCode($destinationPostCode)
{
$this->destinationPostCode = $destinationPostCode;
}
/**
* @return string
*/
public function getClientAlternativePhone()
{
return $this->clientAlternativePhone;
}
/**
* @param string $clientAlternativePhone
*/
public function setClientAlternativePhone($clientAlternativePhone)
{
$this->clientAlternativePhone = $clientAlternativePhone;
}
/**
* @return string
*/
public function getClientAlternativeEmail()
{
return $this->clientAlternativeEmail;
}
/**
* @param string $clientAlternativeEmail
*/
public function setClientAlternativeEmail($clientAlternativeEmail)
{
$this->clientAlternativeEmail = $clientAlternativeEmail;
}
/**
* @return string
*/
public function getVoucherCode()
{
return $this->voucherCode;
}
/**
* @param string $voucherCode
*/
public function setVoucherCode($voucherCode)
{
$this->voucherCode = $voucherCode;
}
/**
* @return string
*/
public function getVoucherValue()
{
return $this->voucherValue;
}
/**
* @param string $voucherValue
*/
public function setVoucherValue($voucherValue)
{
$this->voucherValue = $voucherValue;
}
public function isCancel()
{
$cancelBooking = [
self::STATUS_DELETED,
self::STATUS_OFFICE_CANCELLATION,
self::STATUS_CANCELLED_OTHER_REASON,
self::STATUS_CLIENT_CANCELLATION
];
if (in_array($this->status, $cancelBooking)) {
return true;
}
return false;
}
public function canBroadcast()
{
if ($this->getDriver()) {
return false;
}
return ! $this->isExpireBroadcast();
}
public function isExpireBroadcast()
{
if (! $this->expireBroadcastDate) {
return false;
}
$currentDate = new \DateTime();
if ($currentDate > $this->expireBroadcastDate) {
return false;
}
return true;
}
public function __clone() {
$this->id = null;
$this->pickUpDateTime = null;
$this->pickUpDate = null;
$this->pickUpTime = null;
}
public function formatAddressForListing($address)
{
$addressArray = explode(',', $address);
return [
array_slice($addressArray, 0, (count($addressArray)-2)),
array_slice($addressArray, -2)
];
}
public function getMeetAndGreetTimePrettyFormat() {
if (!empty($this->getFlightLandingTime())) {
$pickUpTime = explode(":", $this->getPickUpTime());
$landingTime = explode(":", $this->getFlightLandingTime());
$date1 = new \DateTime();
$date2 = new \DateTime();
if ($landingTime[0] > $pickUpTime[0]) {
// the landing time & pick up Time is different day
// example: landing time 23:50, pick up time: 00:10
$date1->modify("+1 day");
}
$date1->setTime($pickUpTime[0], $pickUpTime[1]);
$date2->setTime($landingTime[0], $landingTime[1]);
$difference = date_diff($date1, $date2);
return ($difference->h ? $difference->h.'H' : '').
($difference->i.'M');
}
return null;
}
/**
* Set pickUpLat
*
* @param float $pickUpLat
*
* @return BookingRequest
*/
public function setPickUpLat($pickUpLat)
{
$this->pickUpLat = $pickUpLat;
return $this;
}
/**
* Get pickUpLat
*
* @return float
*/
public function getPickUpLat()
{
return $this->pickUpLat;
}
/**
* Set pickUpLng
*
* @param float $pickUpLng
*
* @return BookingRequest
*/
public function setPickUpLng($pickUpLng)
{
$this->pickUpLng = $pickUpLng;
return $this;
}
/**
* Get pickUpLng
*
* @return float
*/
public function getPickUpLng()
{
return $this->pickUpLng;
}
/**
* Set destinationLat
*
* @param float $destinationLat
*
* @return BookingRequest
*/
public function setDestinationLat($destinationLat)
{
$this->destinationLat = $destinationLat;
return $this;
}
/**
* Get destinationLat
*
* @return float
*/
public function getDestinationLat()
{
return $this->destinationLat;
}
/**
* Set destinationLng
*
* @param float $destinationLng
*
* @return BookingRequest
*/
public function setDestinationLng($destinationLng)
{
$this->destinationLng = $destinationLng;
return $this;
}
/**
* Get destinationLng
*
* @return float
*/
public function getDestinationLng()
{
return $this->destinationLng;
}
public function getFullname()
{
return sprintf("%s %s", $this->getClientFirstName(), $this->getClientLastName());
}
public function getTotalCost()
{
return $this->getOverridePrice()?$this->overridePrice:$this->getQuotePrice();
}
public function getDriverNameAndInternal()
{
if(null!=$this->getDriver() && null!=$this->getDriver()->getUser()) {
return $this->getDriver()->getUser()->getFirstname() . ' ' . $this->getDriver()->getUser()->getLastname() . ' (' . $this->getDriver()->getInternalName() . ')';
}else{
return $this->getDriver();
}
}
public function getBookingDateFormated()
{
return $this->getBookingDate()->format('d/m/Y');
}
public function getBookingTimeFormated()
{
return $this->getBookingDate()->format('H:i');
}
public function getPickUpDateFormated()
{
return $this->getPickUpDate()->format('d/m/Y');
}
public function getTotalCostWithCurrency($currencySymbol = null)
{
if($currencySymbol == null){
$currencySymbol = chr(163);
}
return $currencySymbol.' '.$this->getTotalCost();
}
public function getStatusAsText()
{
return $this->getStringStatus($this->status);
}
/**
* @return string
*/
public function getNotifiedDrivers()
{
return $this->notifiedDrivers;
}
/**
* @param string $notifiedDrivers
*/
public function setNotifiedDrivers(string $notifiedDrivers): void
{
$this->notifiedDrivers = $notifiedDrivers;
}
/**
* @return string
*/
public function getBookingCreatedKey()
{
return $this->bookingCreatedKey;
}
/**
* @param string $bookingCreatedKey
*/
public function setBookingCreatedKey(string $bookingCreatedKey)
{
$this->bookingCreatedKey = $bookingCreatedKey;
}
/**
* @return float
*/
public function getPmg()
{
return $this->pmg;
}
/**
* @param float $pmg
*/
public function setPmg($pmg)
{
$this->pmg = $pmg;
}
/**
* @return float
*/
public function getReturnPmg()
{
return $this->returnPmg;
}
/**
* @param float $returnPmg
*/
public function setReturnPmg($returnPmg)
{
$this->returnPmg = $returnPmg;
}
/**
* @return string
*/
public function getBookingDataSerialized()
{
return $this->bookingDataSerialized;
}
/**
* @param string $bookingDataSerialized
*/
public function setBookingDataSerialized($bookingDataSerialized)
{
$this->bookingDataSerialized = $bookingDataSerialized;
}
public function getBookingDataSerializedDecoded()
{
return json_decode($this->bookingDataSerialized);
}
}