<?php
namespace AdminBundle\Entity;
use AdminBundle\Utils\DateTimeUtils;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\OrderBy;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Constraints\DateTime;
#[ORM\Table(name: 'booking')]
#[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\BookingRepository::class)]
class Booking 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_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
public 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_BROADCAST => 'Broadcast',
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',
];
const CREATED_BY_DISPATCH = 'DISPATCH';
const CREATED_BY_APP = 'APP';
const CREATED_BY_CLIENT = 'CLIENT';
const SOURCE_TYPE_FORM = 0;
const SOURCE_TYPE_MOBILE = 1;
const SOURCE_TYPE_ADMIN = 2;
public static $sourceTypes = [
self::SOURCE_TYPE_FORM => 'Booking Form',
self::SOURCE_TYPE_MOBILE => 'Mobile',
self::SOURCE_TYPE_ADMIN => 'Admin',
];
/**
* @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 integer
*/
#[ORM\Column(name: 'booking_status', type: 'integer')]
protected $status = self::STATUS_PENDING;
/**
* @var integer
*/
#[ORM\Column(name: 'return_booking_id', type: 'integer')]
protected $returnBookingId;
/**
* @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 integer
*/
#[ORM\Column(name: 'payment_type', type: 'integer', nullable: false)]
protected $paymentType = Payment::TYPE_CARD;
/**
* @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: 'original_price', type: 'decimal', precision: 7, scale: 2, nullable: true)]
protected $originalPrice = 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: 'initial_amount_payment', type: 'decimal', precision: 7, scale: 2, nullable: true)]
protected $initialAmountPayment;
/**
* @var string
*/
#[ORM\Column(name: 'payment_reference', type: 'string', nullable: true, length: 255)]
protected $paymentReference;
/**
* @var float
*/
#[ORM\Column(name: 'cc_fee', type: 'decimal', precision: 7, scale: 2, nullable: true)]
protected $ccFee;
/**
* @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')]
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 string
*/
#[ORM\Column(name: 'pick_up_map_address', type: 'string', length: 255, nullable: true)]
protected $pickUpMapAddress;
/**
* @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 string
*/
#[ORM\Column(name: 'destination_map_address', type: 'string', length: 255, nullable: true)]
protected $destinationMapAddress;
/**
* @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 integer
*/
#[ORM\Column(name: 'match_job', type: 'integer', nullable: true)]
protected $matchJob;
/**
* @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: 'operator_notes', type: 'text', nullable: true)]
protected $operatorNotes;
/**
* @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: 'booking', cascade: ['persist', 'remove'], orphanRemoval: true)]
protected $vias;
#[ORM\OneToMany(targetEntity: \BookingBookingExtra::class, mappedBy: 'booking', cascade: ['persist'])]
protected $extras;
/**
* @var User
*/
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: true)]
#[ORM\ManyToOne(targetEntity: \User::class, inversedBy: 'clientBookings', 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 Payment
*/
#[ORM\JoinColumn(name: 'payment_id', referencedColumnName: 'id', onDelete: 'SET NULL', nullable: true)]
#[ORM\OneToOne(targetEntity: \AdminBundle\Entity\Payment::class, inversedBy: 'booking')]
private $payment;
/**
* @var boolean
*/
#[ORM\Column(name: 'create_account', type: 'boolean')]
private $createAccount = true;
/**
* @var boolean
*/
#[ORM\Column(name: 'flight_landing_time_was_changed', type: 'boolean')]
private $flightLandingTimeWasChanged = false;
/**
* @var boolean
*/
#[ORM\Column(name: 'automatic_assignment', type: 'boolean')]
private $automaticAssignment = false;
/**
* @var boolean
*/
#[ORM\Column(name: 'need_send_to_driver', type: 'boolean')]
private $needSendToDriver = false;
/**
* @var Booking
*/
#[ORM\JoinColumn(name: 'return_booking_id', referencedColumnName: 'id')]
#[ORM\OneToOne(targetEntity: \Booking::class, inversedBy: 'parentBooking', cascade: ['persist', 'remove'])]
protected $returnBooking;
/**
* @var Booking
*/
#[ORM\OneToOne(targetEntity: \Booking::class, mappedBy: 'returnBooking')]
protected $parentBooking;
/**
* @var float
*/
#[ORM\Column(name: 'cancel_refund', type: 'decimal', precision: 7, scale: 2, nullable: true)]
protected $cancelRefund;
/**
* @var string
*/
#[ORM\Column(name: 'cancel_reason', type: 'string', nullable: true)]
protected $cancelReason;
/**
* @var ArrayCollection
*/
#[ORM\OneToMany(targetEntity: \BroadcastedDriver::class, mappedBy: 'booking', cascade: ['persist', 'remove'], orphanRemoval: true)]
protected $broadcastedDrivers;
/**
* @var ArrayCollection
*/
#[ORM\OneToMany(targetEntity: \UnassignedBookingsDriverRequests::class, mappedBy: 'booking', cascade: ['persist', 'remove'], orphanRemoval: true)]
protected $unassignedDriverRequests;
/**
* @var ArrayCollection
*/
#[ORM\OneToMany(targetEntity: \BookingHistory::class, mappedBy: 'booking', cascade: ['persist', 'remove'], orphanRemoval: true)]
#[OrderBy(['date' => 'ASC'])]
public $bookingHistory;
/**
* @var ArrayCollection
*/
#[ORM\OneToMany(targetEntity: \AdminBundle\Entity\NotificationBookingUpdate::class, mappedBy: 'booking', cascade: ['persist', 'remove'], orphanRemoval: true)]
public $notificationBooking;
/**
* @var string
*/
#[ORM\Column(name: 'booking_data_serialized', type: 'json', nullable: true)]
private $bookingDataSerialized;
/**
* @var ClientInvoices
*/
#[ORM\OneToOne(targetEntity: \AdminBundle\Entity\ClientInvoices::class, mappedBy: 'booking')]
protected $clientInvoice;
/**
* @var ArrayCollection
*/
#[ORM\OneToMany(targetEntity: \AdminBundle\Entity\VoipRecord::class, mappedBy: 'booking')]
protected $voipRecords;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'last_opened_date', type: 'datetime', nullable: true)]
protected $lastOpenedDate;
/**
* @var string
*/
#[ORM\Column(name: 'last_opened_user', type: 'string', nullable: true)]
protected $lastOpenedUser;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'send_notification_undispatched', type: 'datetime', nullable: true)]
protected $sendNotificationUndispatched;
public $linked_booking;
/**
* @var float
*/
#[ORM\Column(name: 'booking_form_cc_fee', type: 'float', nullable: false, options: ['default' => 0])]
protected $bookingformCCFee = 0;
/**
* @var string
*/
#[ORM\Column(name: 'pickup_address_category', type: 'string', nullable: true, length: 255)]
protected $pickupAddressCategory;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'unassigned_hide_at', type: 'datetime', nullable: true)]
protected $unassignedHideAt;
/**
* @var string
*/
#[ORM\Column(name: 'dropoff_address_category', type: 'string', nullable: true, length: 255)]
protected $dropoffAddressCategory;
#[ORM\OneToMany(targetEntity: \Ticket::class, mappedBy: 'booking', cascade: ['remove'])]
protected $tickets;
/**
* @var int
*/
#[ORM\Column(name: 'booking_source_type', type: 'integer', nullable: true)]
protected $bookingSourceType;
/**
* unmapped property
*
* @var bool
*/
protected $isLiveUpdateNotificationSent = false;
public function __construct()
{
$this->driversConfirmedNumber = 0;
$this->bookingformCCFee = 0;
$this->bookingDate = new \DateTime();
$this->vias = new ArrayCollection();
$this->extras = new ArrayCollection();
$this->broadcastedDrivers = new ArrayCollection();
$this->bookingHistory = new ArrayCollection();
$this->notificationBooking = new ArrayCollection();
$this->tickets = 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
*
* @return Booking
*/
public function setQuotePrice($quotePrice): self
{
$this->quotePrice = $quotePrice;
return $this;
}
/**
* @return float
*/
public function getOriginalPrice()
{
return $this->originalPrice;
}
/**
* @param float $originalPrice
*/
public function setOriginalPrice($originalPrice)
{
$this->originalPrice = $originalPrice;
}
/**
* @return float
*/
public function getOverridePrice()
{
return $this->overridePrice;
}
/**
* @param float $overridePrice
*
* @return Booking
*/
public function setOverridePrice($overridePrice): self
{
$this->overridePrice = $overridePrice;
return $this;
}
/**
* @return float
*/
public function getDriverPrice()
{
return $this->driverPrice;
}
/**
* @return bool
*/
public function isFlightLandingTimeWasChanged()
{
return $this->flightLandingTimeWasChanged;
}
public function changeFlightLandingTime()
{
$this->flightLandingTimeWasChanged = true;
}
/**
* @param bool $flightLandingTimeWasChanged
*/
public function setFlightLandingTimeWasChanged($flightLandingTimeWasChanged)
{
$this->flightLandingTimeWasChanged = $flightLandingTimeWasChanged;
}
/**
* @param float $driverPrice
*
* @return Booking
*/
public function setDriverPrice($driverPrice): self
{
$this->driverPrice = $driverPrice;
return $this;
}
/**
* @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);
}
public function deleteExtra($extra)
{
$this->extras->remove($extra);
$extra->setBooking(null);
}
/**
* @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);
}
public function getPickUpFullDateTime()
{
$date = clone $this->getPickUpDate();
$pickUpTimeComponents = explode(':', $this->getPickUpTime());
$date->setTime($pickUpTimeComponents[0], $pickUpTimeComponents[1]);
return $date;
}
/**
* @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
*
* @return Booking
*/
public function setDestinationAddress($destinationAddress)
{
$this->destinationAddress = $destinationAddress;
return $this;
}
/**
* @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 getPickUpMapAddress()
{
return $this->pickUpMapAddress;
}
/**
* @param string $pickUpMapAddress
*/
public function setPickUpMapAddress($pickUpMapAddress)
{
$this->pickUpMapAddress = $pickUpMapAddress;
}
/**
* @return string
*/
public function getDestinationMapAddress()
{
return $this->destinationMapAddress;
}
/**
* @param string $destinationMapAddress
*
* @return Booking
*/
public function setDestinationMapAddress($destinationMapAddress)
{
$this->destinationMapAddress = $destinationMapAddress;
return $this;
}
/**
* @return ArrayCollection
*/
public function getBookingHistory()
{
return $this->bookingHistory;
}
/**
* @param ArrayCollection $bookingHistory
*/
public function setBookingHistory($bookingHistory)
{
$this->bookingHistory = $bookingHistory;
}
/**
* @param BookingHistory $bookingHistory
*
* @return Booking
*/
public function addBookingHistory(BookingHistory $bookingHistory): self
{
$this->bookingHistory[] = $bookingHistory;
return $this;
}
/**
* @param BookingHistory $bookingHistory
*
* @return Booking
*/
public function removeBookingHistory(BookingHistory $bookingHistory): self
{
$this->bookingHistory->removeElement($bookingHistory);
return $this;
}
/**
* @return int
*/
public function getMatchJob()
{
return $this->matchJob;
}
/**
* @param int $matchJob
*/
public function setMatchJob($matchJob)
{
$this->matchJob = $matchJob;
}
/**
* @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 float
*/
public function getInitialAmountPayment()
{
return $this->initialAmountPayment;
}
/**
* @param float $initialAmountPayment
*/
public function setInitialAmountPayment($initialAmountPayment)
{
$this->initialAmountPayment = $initialAmountPayment;
}
/**
* @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 string
*/
public function getOperatorNotes() {
return $this->operatorNotes;
}
/**
* @param string $var
*/
public function setOperatorNotes($var) {
$this->operatorNotes = $var;
}
/**
* @return float
*/
public function getCcFee()
{
return $this->ccFee;
}
/**
* @param float $ccFee
*/
public function setCcFee($ccFee)
{
$this->ccFee = $ccFee;
}
/**
* @return User
*/
public function getClientUser()
{
return $this->clientUser;
}
/**
* @param User $clientUser
*/
public function setClientUser($clientUser)
{
$this->clientUser = $clientUser;
}
/**
* @return bool
*/
public function isAutomaticAssignment()
{
return $this->automaticAssignment;
}
/**
* @param bool $automaticAssignment
*/
public function setAutomaticAssignment($automaticAssignment)
{
$this->automaticAssignment = $automaticAssignment;
}
/**
* @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');
}
public function automaticAssignment($driver)
{
$this->automaticAssignment = true;
$this->setDriver($driver);
$this->needSendToDriver = true;
}
public function setNeedSendToDriver($needSendToDriver)
{
$this->needSendToDriver = $needSendToDriver;
}
public function getNeedSendToDriver()
{
return $this->needSendToDriver;
}
/**
* @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;
}
/**
* @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->setBooking(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());
if (is_null($bookingData)) {
return $objectives;
}
$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());
if (is_null($bookingData)) {
return $returnObjectives;
}
$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);
}
/**
* @return Payment
*/
public function getPayment()
{
return $this->payment;
}
/**
* @param Payment $payment
* @return Booking
*/
public function setPayment($payment)
{
$this->payment = $payment;
return $this;
}
/**
* @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
*
* @return Booking
*/
public function setDistanceUnit($distanceUnit): self
{
$this->distanceUnit = $distanceUnit;
return $this;
}
/**
* @return string
*/
public function getEstimatedTime()
{
return $this->estimatedTime;
}
/**
* @param string $estimatedTime
*
* @return Booking
*/
public function setEstimatedTime($estimatedTime): self
{
$this->estimatedTime = $estimatedTime;
return $this;
}
/**
* @return int|null
*/
public function getEstimatedTimeInSeconds(): ?int
{
return $this->getEstimatedTime()
? DateTimeUtils::convertTimeToSeconds($this->getEstimatedTime())
: null
;
}
/**
* @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 int
*/
public function getPaymentType()
{
return $this->paymentType;
}
/**
* @param int $paymentType
*/
public function setPaymentType($paymentType)
{
$this->paymentType = $paymentType;
}
/**
* @return Booking|null
*/
public function getReturnBooking()
{
return $this->returnBooking;
}
/**
* @param Booking|null $returnBooking
*/
public function setReturnBooking($returnBooking)
{
$this->returnBooking = $returnBooking;
}
public function __toString()
{
return $this->getId() ? (string) $this->getId() : 'n\a';
}
/**
* @return float
*/
public function getCancelRefund()
{
return $this->cancelRefund;
}
/**
* @param float $cancelRefund
*/
public function setCancelRefund($cancelRefund)
{
$this->cancelRefund = $cancelRefund;
}
/**
* @return string
*/
public function getCancelReason()
{
return $this->cancelReason;
}
/**
* @param string $cancelReason
*/
public function setCancelReason($cancelReason)
{
$this->cancelReason = $cancelReason;
}
/**
* @return Booking
*/
public function getParentBooking()
{
return $this->parentBooking;
}
/**
* @param Booking $parentBooking
*/
public function setParentBooking($parentBooking)
{
$this->parentBooking = $parentBooking;
}
/**
* @return string
*/
public function getPaymentReference()
{
return $this->paymentReference;
}
/**
* @param string $paymentReference
*/
public function setPaymentReference($paymentReference)
{
$this->paymentReference = $paymentReference;
}
/**
* @return ArrayCollection
*/
public function getBroadcastedDrivers()
{
return $this->broadcastedDrivers;
}
/**
* @param ArrayCollection $broadcastedDrivers
*/
public function setBroadcastedDrivers($broadcastedDrivers)
{
$this->broadcastedDrivers = $broadcastedDrivers;
}
/**
* @return ArrayCollection
*/
public function getUnassignedDriverRequests()
{
return $this->unassignedDriverRequests;
}
/**
* @param ArrayCollection $unassignedDriverRequests;
*/
public function setUnassignedDriverRequests($unassignedDriverRequests)
{
$this->unassignedDriverRequests = $unassignedDriverRequests;
}
/**
* @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
*
* @return Booking
*/
public function setDestinationPostCode($destinationPostCode)
{
$this->destinationPostCode = $destinationPostCode;
return $this;
}
/**
* @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;
}
/**
* @return ArrayCollection
*/
public function getNotificationBooking()
{
return $this->notificationBooking;
}
/**
* @param ArrayCollection $notificationBooking
* @return Booking
*/
public function setNotificationBooking(ArrayCollection $notificationBooking): Booking
{
$this->notificationBooking = $notificationBooking;
return $this;
}
/**
* @param NotificationBookingUpdate $notificationBooking
* @return Booking
*/
public function addNotificationBooking(NotificationBookingUpdate $notificationBooking): Booking
{
$this->notificationBooking->add($notificationBooking);
return $this;
}
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;
}
/**
* check if have update notificaitons
*
* @return bool
*/
public function isUpdated()
{
$criteria = Criteria::create()->where(Criteria::expr()->neq('seen', true))
->andWhere(Criteria::expr()->eq('driver', $this->driver));
return $this->getNotificationBooking()->matching($criteria)->count() >= 1;
}
/**
* mark as read all notifications
*/
public function returnUnSeenUpdated()
{
$criteria = Criteria::create()->where(Criteria::expr()->neq('seen', true))
->andWhere(Criteria::expr()->eq('driver', $this->driver));
return $this->getNotificationBooking()->matching($criteria);
}
/**
* @return string
*/
public function getBookingDataSerialized()
{
return $this->bookingDataSerialized;
}
/**
* @param string $bookingDataSerialized
*/
public function setBookingDataSerialized($bookingDataSerialized)
{
$this->bookingDataSerialized = $bookingDataSerialized;
}
public function __clone()
{
$this->id = null;
$this->pickUpDateTime = null;
$this->pickUpDate = null;
$this->pickUpTime = null;
}
/**
* @return ClientInvoices
*/
public function getClientInvoice()
{
return $this->clientInvoice;
}
/**
* @param ClientInvoices $clientInvoice
*/
public function setClientInvoice($clientInvoice)
{
$this->clientInvoice = $clientInvoice;
}
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 Booking
*/
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 Booking
*/
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 Booking
*/
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 Booking
*/
public function setDestinationLng($destinationLng)
{
$this->destinationLng = $destinationLng;
return $this;
}
/**
* Get destinationLng
*
* @return float
*/
public function getDestinationLng()
{
return $this->destinationLng;
}
/**
* Add voipRecord
*
* @param \AdminBundle\Entity\VoipRecord $voipRecord
*
* @return Booking
*/
public function addVoipRecord(\AdminBundle\Entity\VoipRecord $voipRecord)
{
$this->voipRecords[] = $voipRecord;
return $this;
}
/**
* Remove voipRecord
*
* @param \AdminBundle\Entity\VoipRecord $voipRecord
*/
public function removeVoipRecord(\AdminBundle\Entity\VoipRecord $voipRecord)
{
$this->voipRecords->removeElement($voipRecord);
}
/**
* Get voipRecords
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getVoipRecords()
{
return $this->voipRecords;
}
public function isOpen($userEmail)
{
$this->lastOpenedUser = $userEmail;
$this->lastOpenedDate = new \DateTime();
}
/**
* @return \DateTime
*/
public function getLastOpenedDate()
{
return $this->lastOpenedDate;
}
/**
* @param \DateTime $lastOpenedDate
*/
public function setLastOpenedDate($lastOpenedDate)
{
$this->lastOpenedDate = $lastOpenedDate;
}
/**
* @return string
*/
public function getLastOpenedUser()
{
return $this->lastOpenedUser;
}
/**
* @param string $lastOpenedUser
*/
public function setLastOpenedUser($lastOpenedUser)
{
$this->lastOpenedUser = $lastOpenedUser;
}
public function getBookingDataSerializedDecoded()
{
return json_decode($this->bookingDataSerialized);
}
/**
* @return string
*/
public function getFullname()
{
$firstName = $this->getClientFirstName() ?: 'n/a';
$lastName = $this->getClientLastName() ?: 'n/a';
return "{$firstName} {$lastName}";
}
public function getTotalCost()
{
return $this->getOverridePrice() ? $this->overridePrice : $this->getQuotePrice();
}
/**
* @return string
*/
public function getFirstBookingCreatedBy()
{
$firstBookingHistory = $this->getBookingHistory()->first();
if ($firstBookingHistory && $user = $firstBookingHistory->getUser()) {
if ($user->getEmail() === 'online@ctlf.co.uk') {
return self::CREATED_BY_APP;
}
if ($user->hasRole('ROLE_CLIENT')) {
return self::CREATED_BY_CLIENT;
}
}
return self::CREATED_BY_DISPATCH;
}
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);
}
public function convertInMinutesPickUpTime()
{
$components = explode(':', $this->pickUpTime->format('H:i'));
return intval($components[1]) + (intval($components[0]) * 60);
}
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');
}
public function convertInMinutesEndTime()
{
$pickUpTimeComponents = explode(':', $this->pickUpTime->format('H:i'));
$pickUpTimeInMinutes = intval($pickUpTimeComponents[1]) + (intval($pickUpTimeComponents[0]) * 60);
$interval = $this->estimatedTime;
$intervalComponents = explode(':', $interval);
$endMinutes = intval($intervalComponents[0]) * 60 + intval($intervalComponents[1]);
$total = $pickUpTimeInMinutes + $endMinutes;
if ($total > 1440) {
return 1440;
}
return $total;
}
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);
}
public function getMgTime()
{
if (!$this->flightLandingTime) {
return null;
}
$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);
$difference = $pickUpTimeInMinutes < $flightLandingTimeInMinutes
? $pickUpTimeInMinutes + ((24 * 60) - $flightLandingTimeInMinutes)
: $pickUpTimeInMinutes - $flightLandingTimeInMinutes
;
// mg time return in minutes
return "{$difference}";
}
public function bookingCode($type = null, $main_location = null)
{
$resultPostcode = '';
if ($main_location !== null) {
if ($main_location == 'US') {
$pickUpCodeComponents = substr($this->pickUpPostCode, 0, 3);
$destinationCodeComponents = substr($this->destinationPostCode, 0, 3);
$resultPostcode = $pickUpCodeComponents . '-' . $destinationCodeComponents;
}
if ($main_location == 'UK') {
$pickUpCodeComponents = explode(' ', $this->pickUpPostCode);
$destinationCodeComponents = explode(' ', $this->destinationPostCode);
$resultPostcode = $pickUpCodeComponents[0] . '-' . $destinationCodeComponents[0];
}
} else {
$pickUpCodeComponents = explode(' ', $this->pickUpPostCode);
$destinationCodeComponents = explode(' ', $this->destinationPostCode);
$resultPostcode = $pickUpCodeComponents[0] . '-' . $destinationCodeComponents[0];
}
$result = '';
if ($type == null) {
$result .= $this->key;
}
$result .= ' ' . $resultPostcode;
return $result;
}
/**
* @return \DateTime
*/
public function getSendNotificationUndispatched()
{
return $this->sendNotificationUndispatched;
}
/**
* @param \DateTime $sendNotificationUndispatched
*/
public function setSendNotificationUndispatched($sendNotificationUndispatched)
{
$this->sendNotificationUndispatched = $sendNotificationUndispatched;
}
/**
* @return float
*/
public function getBookingformCCFee()
{
return $this->bookingformCCFee;
}
/**
* @param float $bookingformCCFee
*/
public function setBookingformCCFee($bookingformCCFee)
{
$this->bookingformCCFee = (float) $bookingformCCFee;
}
/**
* @return string
*/
public function getPickupAddressCategory()
{
return $this->pickupAddressCategory;
}
/**
* @param string $pickupAddressCategory
*/
public function setPickupAddressCategory($pickupAddressCategory)
{
$this->pickupAddressCategory = $pickupAddressCategory;
}
/**
* @return string
*/
public function getDropoffAddressCategory()
{
return $this->dropoffAddressCategory;
}
/**
* @param string $dropoffAddressCategory
*/
public function setDropoffAddressCategory($dropoffAddressCategory)
{
$this->dropoffAddressCategory = $dropoffAddressCategory;
}
/**
* @return \DateTime
*/
public function getUnassignedHideAt()
{
return $this->unassignedHideAt;
}
/**
* @param \DateTime $unassignedHideAt
*/
public function setUnassignedHideAt($unassignedHideAt)
{
$this->unassignedHideAt = $unassignedHideAt;
return $this;
}
/**
* @param Ticket $ticket
*
* @return Booking
*/
public function addQuestion(Ticket $ticket)
{
$ticket->setBooking($this);
$this->tickets->add($ticket);
return $this;
}
/**
* @param Ticket $ticket
*
* @return Booking
*/
public function removeTicket(Ticket $ticket)
{
if (!$this->tickets->contains($ticket)) {
return;
}
$this->tickets->removeElement($ticket);
$ticket->setBooking(null);
return $this;
}
/**
* @return ArrayCollection
*/
public function getTickets()
{
return $this->tickets;
}
/**
* @param int $bookingSourceType
*/
public function setBookingSourceType($bookingSourceType)
{
$this->bookingSourceType = $bookingSourceType;
}
/**
* @return int
*/
public function getBookingSourceType()
{
return $this->bookingSourceType;
}
public function getBookingSourceTypeName()
{
if (
$this->bookingSourceType &&
isset(self::$sourceTypes[$this->bookingSourceType])
) {
return self::$sourceTypes[$this->bookingSourceType];
}
}
public function isBeforeOnTheWay()
{
return in_array($this->getStatus(), [
Booking::STATUS_NEW_BOOKING,
Booking::STATUS_DISPATCHED,
Booking::STATUS_DRIVER_REJECT,
Booking::STATUS_DRIVER_ACCEPT,
]);
}
public function getClientCancellationCase()
{
$status = $this->getStatus();
if ($this->isBeforeOnTheWay()) {
return ClientCancellationFee::CANCELLATION_CASE_BEFORE_ON_THE_WAY;
}
if ($status === Booking::STATUS_ON_THE_WAY) {
foreach ($this->getBookingHistory() as $history) {
if ($history->getActionType() !== BookingHistory::ACTION_TYPE_CHANGED_STATUS) {
continue;
}
$payload = $history->getPayload();
if (intval($payload['old_status']) !== self::STATUS_DISPATCHED && intval($payload['current_status']) !== self::STATUS_ON_THE_WAY) {
continue;
}
$now = new \DateTime();
$diff = $history->getDate()->getTimestamp() - $now->getTimestamp();
// 2 mins difference
return $diff <= 120 ? ClientCancellationFee::CANCELLATION_CASE_ON_THE_WAY_STARTED : ClientCancellationFee::CANCELLATION_CASE_ON_THE_WAY;
}
}
if ($status === Booking::STATUS_ARRIVED_AND_WAITING) {
return ClientCancellationFee::CANCELLATION_CASE_ARRIVED_AND_WAITING;
}
return null;
}
/**
* @return bool
*/
public function hasReturn(): bool
{
return null !== $this->getReturnBooking();
}
/**
* @return bool
*/
public function isPmg(): bool
{
return !empty($this->getPmg());
}
/**
* @return bool
*/
public function isReturnPmg(): bool
{
return !empty($this->getReturnPmg());
}
public function isPickupAddressCategoryPOI()
{
return in_array($this->getPickupAddressCategory(), Area::$categories);
}
public function isDropoffAddressCategoryPOI()
{
return in_array($this->getDropoffAddressCategory(), Area::$categories);
}
/**
* @return bool
*/
public function isFixedPrice(): bool
{
if (null === $this->getBookingDataSerialized()) {
return false;
}
$data = \json_decode($this->getBookingDataSerialized());
if (JSON_ERROR_NONE !== \json_last_error()) {
return false;
}
if (!isset($data->result)) {
return false;
}
$result = $data->result;
if (empty($result->route)) {
return false;
}
$route = $result->route[0];
return isset($route->fixedPrice) && $route->fixedPrice;
}
/**
* @return bool
*/
public function isLiveUpdateNotificationSent(): bool
{
return $this->isLiveUpdateNotificationSent;
}
/**
* @param bool $isLiveUpdateNotificationSent
*
* @return self
*/
public function setIsLiveUpdatedNotificationSent(bool $isLiveUpdateNotificationSent): self
{
$this->isLiveUpdateNotificationSent = $isLiveUpdateNotificationSent;
return $this;
}
}