745 lines
15 KiB
PHP
745 lines
15 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;
|
|
|
|
/**
|
|
* @ORM\Entity
|
|
* @ORM\Table(name="job_order")
|
|
*/
|
|
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;
|
|
|
|
// 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;
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
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;
|
|
return $this;
|
|
}
|
|
|
|
public function getCustomer()
|
|
{
|
|
return $this->customer;
|
|
}
|
|
|
|
public function setCustomerVehicle(CustomerVehicle $cus_vehicle)
|
|
{
|
|
$this->cus_vehicle = $cus_vehicle;
|
|
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::ASSIGNED)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
}
|