resq/src/Entity/JobOrder.php
2021-12-03 05:54:22 +00:00

1064 lines
22 KiB
PHP

<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
use DateTime;
use App\Ramcar\ModeOfPayment;
use App\Ramcar\JOStatus;
use App\Ramcar\ServiceType;
use App\Ramcar\WillingToWaitContent;
/**
* @ORM\Entity
* @ORM\Table(name="job_order", indexes={
* @ORM\Index(name="date_schedule_idx", columns={"date_schedule"}),
* @ORM\Index(name="plate_number_idx", columns={"plate_number"}),
* @ORM\Index(name="first_name_idx", columns={"first_name"}),
* @ORM\Index(name="last_name_idx", columns={"last_name"}),
* @ORM\Index(name="phone_mobile_idx", columns={"phone_mobile"}),
* @ORM\Index(name="status_idx", columns={"status"}),
* })
*/
class JobOrder
{
// unique id
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
// date job order was created
/**
* @ORM\Column(type="datetime")
*/
protected $date_create;
// date and time of schedule
// defaults to current date / time
/**
* @ORM\Column(type="datetime")
*/
protected $date_schedule;
// date that the job order was fulfilled / delivered
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $date_fulfill;
// date that the job order was cancelled
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $date_cancel;
// date job order was assigned to a rider
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $date_assign;
// coordinates of the customer vehicle that needs service
/**
* @ORM\Column(type="point")
*/
protected $coordinates;
// we split up coordinates into long / lat for reports purposes
/**
* @ORM\Column(type="decimal", precision=11, scale=8)
*/
protected $coord_long;
// we split up coordinates into long / lat for reports purposes
/**
* @ORM\Column(type="decimal", precision=11, scale=8)
*/
protected $coord_lat;
// is it an advanced order (future date)
/**
* @ORM\Column(type="boolean")
*/
protected $flag_advance;
// user that created the job order
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="job_orders_created")
* @ORM\JoinColumn(name="create_user_id", referencedColumnName="id", nullable=true)
*/
protected $created_by;
// user that assigned the job order to a rider
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="job_orders_assigned")
* @ORM\JoinColumn(name="assign_user_id", referencedColumnName="id", nullable=true)
*/
protected $assigned_by;
// user that processed or is processing the job order
// used to determine lock
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="job_orders_processed")
* @ORM\JoinColumn(name="process_user_id", referencedColumnName="id", nullable=true)
*/
protected $processed_by;
// service type
/**
* @ORM\Column(type="string", length=25)
*/
protected $service_type;
// warranty class
/**
* @ORM\Column(type="string", length=25)
*/
protected $warranty_class;
// customer that requested job order
/**
* @ORM\ManyToOne(targetEntity="Customer", inversedBy="job_orders")
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
* @Assert\NotBlank()
*/
protected $customer;
// customer vehicle that needs servicing
/**
* @ORM\ManyToOne(targetEntity="CustomerVehicle", inversedBy="job_orders")
* @ORM\JoinColumn(name="cvehicle_id", referencedColumnName="id")
* @Assert\NotBlank()
*/
protected $cus_vehicle;
// assigned hub
/**
* @ORM\ManyToOne(targetEntity="Hub", inversedBy="job_orders")
* @ORM\JoinColumn(name="hub_id", referencedColumnName="id")
*/
protected $hub;
// assigned rider
/**
* @ORM\ManyToOne(targetEntity="Rider", inversedBy="job_orders")
* @ORM\JoinColumn(name="rider_id", referencedColumnName="id")
*/
protected $rider;
// where requested job order came from (transaction origin)
/**
* @ORM\Column(type="string", length=15)
*/
protected $source;
// status of the job order
/**
* @ORM\Column(type="string", length=15)
*/
protected $status;
// delivery instructions
/**
* @ORM\Column(type="text", nullable=true)
*/
protected $delivery_instructions;
// agent tier I notes
/**
* @ORM\Column(type="text", nullable=true)
*/
protected $tier1_notes;
// agent tier II notes
/**
* @ORM\Column(type="text", nullable=true)
*/
protected $tier2_notes;
// delivery address
/**
* @ORM\Column(type="text")
* @Assert\NotBlank()
*/
protected $delivery_address;
// landmark
/**
* @ORM\Column(type="text")
*/
protected $landmark;
// invoice
/**
* @ORM\OneToOne(targetEntity="Invoice", mappedBy="job_order")
*/
protected $invoice;
// reason for cancel
/**
* @ORM\Column(type="string", length=200, nullable=true)
*/
protected $cancel_reason;
// tickets associated with job order
/**
* @ORM\OneToMany(targetEntity="Ticket", mappedBy="job_order")
*/
protected $tickets;
// reference job order
/**
* @ORM\OneToOne(targetEntity="JobOrder")
* @ORM\JoinColumn(name="ref_jo_id", referencedColumnName="id")
*/
protected $ref_jo;
// mode of payment
/**
* @ORM\Column(type="string", length=50)
*/
protected $mode_of_payment;
// OR number
/**
* @ORM\Column(type="string", length=80, nullable=true)
*/
protected $or_num;
// name to put in OR
/**
* @ORM\Column(type="string", length=80)
*/
protected $or_name;
// details needed by promo - employee id / card number / refered by
/**
* @ORM\Column(type="string", length=80)
*/
protected $promo_detail;
// events triggered
/**
* @ORM\OneToMany(targetEntity="JOEvent", mappedBy="job_order")
*/
protected $events;
/**
* @ORM\Column(type="string", length=25, nullable=true)
*/
protected $trade_in_type;
// if the user has left a rating for the rider
/**
* @ORM\Column(type="boolean", nullable=true)
*/
protected $flag_rider_rating;
// only for overheat service, if it requires coolant or not
/**
* @ORM\Column(type="boolean")
*/
protected $flag_coolant;
// facilitated by hub, non-hub, annex
/**
* @ORM\Column(type="string", length=8, nullable=true)
*/
protected $facilitated_type;
// the location that facilitated the job order
/**
* @ORM\ManyToOne(targetEntity="Hub", inversedBy="job_orders")
* @ORM\JoinColumn(name="facilitated_hub_id", referencedColumnName="id", nullable=true)
*/
protected $facilitated_by;
// hubs rejected for this job order
/**
* @ORM\OneToMany(targetEntity="JORejection", mappedBy="job_order")
*/
protected $hub_rejections;
// priority order for riders
// NOTE: this is a workaround since changeing rider to jo rider assignment with details requires
// too many changes and may break too many things.
/**
* @ORM\Column(type="integer", options={"default": 0}))
*/
protected $priority;
// autoassign status
/**
* @ORM\Column(type="string", length=30, nullable=true)
*/
protected $status_autoassign;
// meta
/**
* @ORM\Column(type="json")
*/
protected $meta;
// for search purposes
// first name
/**
* @ORM\Column(type="string", length=80)
* @Assert\NotBlank()
*/
protected $first_name;
// last name
/**
* @ORM\Column(type="string", length=80)
* @Assert\NotBlank()
*/
protected $last_name;
// plate number
/**
* @ORM\Column(type="string", length=100)
* @Assert\NotBlank()
*/
protected $plate_number;
// mobile phone
/**
* @ORM\Column(type="string", length=30)
*/
protected $phone_mobile;
// customer is willing to wait or not
/**
* @ORM\Column(type="string", length=30)
*/
protected $will_wait;
// reason for not willing to wait
/**
* @ORM\Column(type="string", length=80, nullable=true)
*/
protected $reason_not_waiting;
// more notes on why not willing to wait
/**
* @ORM\Column(type="text", nullable=true)
*/
protected $not_waiting_notes;
// reason for not trading in battery
/**
* @ORM\Column(type="string", length=80, nullable=true)
*/
protected $no_trade_in_reason;
// delivery status of the job order
/**
* @ORM\Column(type="string", length=30, nullable=true)
*/
protected $delivery_status;
// rider rating
/**
* @ORM\OneToOne(targetEntity="RiderRating", mappedBy="job_order")
*/
protected $rating;
public function __construct()
{
$this->date_create = new DateTime();
$this->date_schedule = new DateTime();
$this->flag_advance = false;
$this->source = 'mobile';
$this->mode_of_payment = ModeOfPayment::CASH;
$this->or_name = '';
$this->or_num = '';
$this->landmark = '';
$this->promo_detail = '';
$this->events = new ArrayCollection();
$this->trade_in_type = null;
$this->flag_rider_rating = false;
$this->flag_coolant = false;
$this->priority = 0;
$this->meta = [];
$this->phone_mobile = '';
$this->will_wait = WillingToWaitContent::WILLING_TO_WAIT;
}
public function getID()
{
return $this->id;
}
public function setDateCreate(DateTime $date_create)
{
$this->date_create = $date_create;
return $this;
}
public function getDateCreate()
{
return $this->date_create;
}
public function setDateSchedule(DateTime $date_schedule)
{
$this->date_schedule = $date_schedule;
return $this;
}
public function getDateSchedule()
{
return $this->date_schedule;
}
public function setDateCancel(DateTime $date_cancel)
{
$this->date_cancel = $date_cancel;
return $this;
}
public function getDateCancel()
{
return $this->date_cancel;
}
public function setDateFulfill(DateTime $date_fulfill)
{
$this->date_fulfill = $date_fulfill;
return $this;
}
public function getDateFulfill()
{
return $this->date_fulfill;
}
public function setDateAssign(DateTime $date_assign)
{
$this->date_assign = $date_assign;
return $this;
}
public function getDateAssign()
{
return $this->date_assign;
}
public function setCoordinates(Point $point)
{
$this->coordinates = $point;
$this->coord_lat = $point->getLatitude();
$this->coord_long = $point->getLongitude();
return $this;
}
public function getCoordinates()
{
return $this->coordinates;
}
public function setAdvanceOrder($flag_advance = true)
{
$this->flag_advance = $flag_advance;
return $this;
}
public function isAdvanceOrder()
{
return $this->flag_advance;
}
public function setCreatedBy(User $created_by)
{
$this->created_by = $created_by;
return $this;
}
public function getCreatedBy()
{
return $this->created_by;
}
public function setAssignedBy(User $assigned_by = null)
{
$this->assigned_by = $assigned_by;
return $this;
}
public function getAssignedBy()
{
return $this->assigned_by;
}
public function setProcessedBy(User $user = null)
{
$this->processed_by = $user;
return $this;
}
public function getProcessedBy()
{
return $this->processed_by;
}
public function setServiceType($service_type)
{
$this->service_type = $service_type;
return $this;
}
public function getServiceType()
{
return $this->service_type;
}
public function getServiceTypeName()
{
return ServiceType::getName($this->service_type);
}
public function setWarrantyClass($warranty_class)
{
$this->warranty_class = $warranty_class;
return $this;
}
public function getWarrantyClass()
{
return $this->warranty_class;
}
public function setCustomer(Customer $customer)
{
$this->customer = $customer;
// set the search fields for first name, last name, and mobile
$this->setFirstName($customer->getFirstName());
$this->setLastName($customer->getLastName());
$this->setPhoneMobile($customer->getPhoneMobile());
return $this;
}
public function getCustomer()
{
return $this->customer;
}
public function setCustomerVehicle(CustomerVehicle $cus_vehicle)
{
$this->cus_vehicle = $cus_vehicle;
// set the search field for plate number
$this->setPlateNumber($cus_vehicle->getPlateNumber());
return $this;
}
public function getCustomerVehicle()
{
return $this->cus_vehicle;
}
public function setHub(Hub $hub)
{
$this->hub = $hub;
return $this;
}
public function clearHub()
{
return $this->hub = null;
}
public function getHub()
{
return $this->hub;
}
public function setRider(Rider $rider)
{
$this->rider = $rider;
return $this;
}
public function clearRider()
{
return $this->rider = null;
}
public function getRider()
{
return $this->rider;
}
public function setSource($source)
{
// TODO: validate TransactionOrigin
$this->source = $source;
return $this;
}
public function getSource()
{
return $this->source;
}
public function setStatus($status)
{
// TODO: validate status
$this->status = $status;
return $this;
}
public function getStatus()
{
return $this->status;
}
public function getStatusText()
{
return JOStatus::getName($this->status);
}
public function setDeliveryInstructions($delivery_instructions)
{
$this->delivery_instructions = $delivery_instructions;
return $this;
}
public function getDeliveryInstructions()
{
return $this->delivery_instructions;
}
public function setTier1Notes($notes)
{
$this->tier1_notes = $notes;
return $this;
}
public function getTier1Notes()
{
return $this->tier1_notes;
}
public function setTier2Notes($notes)
{
$this->tier2_notes = $notes;
return $this;
}
public function getTier2Notes()
{
return $this->tier2_notes;
}
public function setDeliveryAddress($delivery_address)
{
$this->delivery_address = $delivery_address;
return $this;
}
public function getDeliveryAddress()
{
return $this->delivery_address;
}
public function setLandmark($landmark)
{
$this->landmark = $landmark;
return $this;
}
public function getLandmark()
{
return $this->landmark;
}
public function setInvoice(Invoice $invoice)
{
$this->invoice = $invoice;
$invoice->setJobOrder($this);
return $this;
}
public function getInvoice()
{
return $this->invoice;
}
public function setCancelReason($reason)
{
$this->cancel_reason = $reason;
return $this;
}
public function getCancelReason()
{
return $this->cancel_reason;
}
public function getTickets()
{
return $this->tickets;
}
public function setReferenceJO(JobOrder $ref_jo)
{
$this->ref_jo = $ref_jo;
return $this;
}
public function getReferenceJO()
{
return $this->ref_jo;
}
public function setModeOfPayment($mode)
{
$this->mode_of_payment = $mode;
return $this;
}
public function getModeOfPayment()
{
return $this->mode_of_payment;
}
public function setORNum($num)
{
$this->or_num = $num;
return $this;
}
public function getORNum()
{
return $this->or_num;
}
public function setORName($name)
{
$this->or_name = $name;
return $this;
}
public function getORName()
{
return $this->or_name;
}
public function setPromoDetail($detail)
{
$this->promo_detail = $detail;
return $this;
}
public function getPromoDetail()
{
return $this->promo_detail;
}
public function getEvents()
{
return $this->events;
}
public function isClosed()
{
if ($this->status == JOStatus::CANCELLED)
return true;
if ($this->status == JOStatus::FULFILLED)
return true;
return false;
}
public function isOpen()
{
return !$this->isClosed();
}
public function isCancelled()
{
return $this->status == JOStatus::CANCELLED;
}
public function setTradeInType($type)
{
$this->trade_in_type = $type;
return $this;
}
public function getTradeInType()
{
return $this->trade_in_type;
}
protected function makeRiderAvailable()
{
$rider = $this->getRider();
if ($rider != null)
$rider->setAvailable();
}
public function requeue()
{
// set status back to 'for rider assignment'
$this->setStatus(JOStatus::RIDER_ASSIGN);
$this->makeRiderAvailable();
}
public function cancel($reason)
{
// set status to cancelled
$this->setStatus(JOStatus::CANCELLED)
->setDateCancel(new DateTime())
->setCancelReason($reason);
$this->makeRiderAvailable();
}
public function fulfill()
{
$this->setStatus(JOStatus::FULFILLED)
->setDateFulfill(new DateTime());
$this->makeRiderAvailable();
}
public function setHasRiderRating($flag = true)
{
$this->flag_rider_rating = $flag;
return $this;
}
public function hasRiderRating()
{
if ($this->flag_rider_rating == null)
return false;
return $this->flag_rider_rating;
}
public function setHasCoolant($flag = true)
{
$this->flag_coolant = $flag;
return $this;
}
public function hasCoolant()
{
return $this->flag_coolant;
}
public function canDispatch()
{
if ($this->status == JOStatus::PENDING)
return true;
return false;
}
public function canAssign()
{
if ($this->status == JOStatus::RIDER_ASSIGN)
return true;
return false;
}
public function setFacilitatedType($type = null)
{
$this->facilitated_type = $type;
return $this;
}
public function getFacilitatedType()
{
return $this->facilitated_type;
}
public function setFacilitatedBy(Hub $hub = null)
{
$this->facilitated_by = $hub;
return $this;
}
public function getFacilitatedBy()
{
return $this->facilitated_by;
}
public function getHubRejections()
{
return $this->hub_rejections;
}
public function setPriority($priority)
{
$this->priority = $priority;
return $this;
}
public function getPriority()
{
return $this->priority;
}
public function addMeta($id, $value)
{
$this->meta[$id] = $value;
return $this;
}
public function getMeta($id)
{
// return null if we don't have it
if (!isset($this->meta[$id]))
return null;
return $this->meta[$id];
}
public function setStatusAutoAssign($status_autoassign)
{
$this->status_autoassign = $status_autoassign;
return $this;
}
public function getStatusAutoAssign()
{
return $this->status_autoassign;
}
public function setFirstName($first_name)
{
$this->first_name = $first_name;
return $this;
}
public function getFirstName()
{
return $this->first_name;
}
public function setLastName($last_name)
{
$this->last_name = $last_name;
return $this;
}
public function getLastName()
{
return $this->last_name;
}
public function setPlateNumber($plate_number)
{
// make it upper case
$plate_number = trim(strtoupper($plate_number));
// remove spaces
$plate_number = str_replace(' ', '', $plate_number);
// upper case
$plate_number = strtoupper($plate_number);
$this->plate_number = $plate_number;
return $this;
}
public function getPlateNumber()
{
return strtoupper($this->plate_number);
}
public function setPhoneMobile($phone)
{
$this->phone_mobile = $phone;
return $this;
}
public function getPhoneMobile()
{
return $this->phone_mobile;
}
public function setWillWait($will_wait)
{
$this->will_wait = $will_wait;
return $this;
}
public function getWillWait()
{
return $this->will_wait;
}
public function setReasonNotWait($reason)
{
$this->reason_not_waiting = $reason;
return $this;
}
public function getReasonNotWait()
{
return $this->reason_not_waiting;
}
public function setNotWaitingNotes($notes)
{
$this->not_waiting_notes = $notes;
return $this;
}
public function getNotWaitingNotes()
{
return $this->not_waiting_notes;
}
public function setNoTradeInReason($reason)
{
$this->no_trade_in_reason = $reason;
return $this;
}
public function getNoTradeInReason()
{
return $this->no_trade_in_reason;
}
public function setDeliveryStatus($delivery_status)
{
$this->delivery_status = $delivery_status;
return $this;
}
public function getDeliveryStatus()
{
return $this->delivery_status;
}
public function getRating()
{
return $this->rating;
}
}