273 lines
5.8 KiB
PHP
273 lines
5.8 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Ramcar\Location;
|
|
use App\Ramcar\JOStatus;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Criteria;
|
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
use DateTime;
|
|
|
|
/**
|
|
* @ORM\Entity
|
|
* @ORM\Table(name="hub")
|
|
*/
|
|
class Hub
|
|
{
|
|
use Location;
|
|
|
|
// riders assigned to this hub
|
|
/**
|
|
* @ORM\OneToMany(targetEntity="Rider", mappedBy="hub")
|
|
*/
|
|
protected $riders;
|
|
|
|
// job orders assigned to hub
|
|
/**
|
|
* @ORM\OneToMany(targetEntity="JobOrder", mappedBy="hub")
|
|
*/
|
|
protected $job_orders;
|
|
|
|
/**
|
|
* @ORM\ManyToMany(targetEntity="User", mappedBy="hubs", fetch="EXTRA_LAZY")
|
|
*/
|
|
protected $users;
|
|
|
|
// hub outlets
|
|
/**
|
|
* @ORM\OneToMany(targetEntity="Outlet", mappedBy="hub")
|
|
*/
|
|
protected $outlets;
|
|
|
|
// branch code
|
|
/**
|
|
* @ORM\Column(type="string", length=80)
|
|
*/
|
|
protected $branch_code;
|
|
|
|
// is hub open
|
|
/**
|
|
* @ORM\Column(type="boolean")
|
|
*/
|
|
protected $status_open;
|
|
|
|
// number of rider slots per day
|
|
/**
|
|
* @ORM\Column(type="integer")
|
|
*/
|
|
protected $rider_slots;
|
|
|
|
// flag to see if hub will be displayed in Hub View
|
|
/**
|
|
* @ORM\Column(type="boolean")
|
|
*/
|
|
protected $flag_hub_view;
|
|
|
|
// notification number to send SMS to if hub doesn't have item
|
|
/**
|
|
* @ORM\Column(type="string", length=30)
|
|
*/
|
|
protected $notif_number;
|
|
|
|
// payment methods
|
|
/**
|
|
* @ORM\Column(type="array", nullable=true)
|
|
*/
|
|
protected $payment_methods;
|
|
|
|
// flag if hub can be auto assigned
|
|
/**
|
|
* @ORM\Column(type="boolean", options={"default"=false})
|
|
*/
|
|
protected $flag_hub_auto_assign;
|
|
|
|
// flag if riders assigned to hub can be auto assigned
|
|
/**
|
|
* @ORM\Column(type="boolean", options={"default"=false})
|
|
*/
|
|
protected $flag_rider_auto_assign;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->time_open = new DateTime();
|
|
$this->time_close = new DateTime();
|
|
$this->riders = new ArrayCollection();
|
|
$this->outlets = new ArrayCollection();
|
|
$this->status_open = true;
|
|
$this->flag_hub_view = false;
|
|
$this->notif_number = '';
|
|
$this->payment_methods = new ArrayCollection();
|
|
$this->flag_hub_auto_assign = false;
|
|
$this->flag_rider_auto_assign = false;
|
|
}
|
|
|
|
public function getRiders()
|
|
{
|
|
return $this->riders;
|
|
}
|
|
|
|
public function getAvailableRiders()
|
|
{
|
|
$crit = Criteria::create();
|
|
$crit->where(Criteria::expr()->eq('flag_available', true));
|
|
|
|
return $this->riders->matching($crit);
|
|
}
|
|
|
|
public function getActiveRiders()
|
|
{
|
|
$crit = Criteria::create();
|
|
$crit->where(Criteria::expr()->eq('flag_active', true));
|
|
|
|
return $this->riders->matching($crit);
|
|
}
|
|
|
|
public function getUsers()
|
|
{
|
|
return $this->users;
|
|
}
|
|
|
|
public function getUsersCount()
|
|
{
|
|
return $this->users->count();
|
|
}
|
|
|
|
public function getJobOrders()
|
|
{
|
|
return $this->job_orders;
|
|
}
|
|
|
|
public function getOngoingJobOrders()
|
|
{
|
|
$crit = Criteria::create();
|
|
$crit->where(Criteria::expr()->notIn('status', [JOStatus::CANCELLED, JOStatus::FULFILLED]));
|
|
|
|
return $this->job_orders->matching($crit);
|
|
}
|
|
|
|
public function getForAssignmentJobOrders()
|
|
{
|
|
$crit = Criteria::create();
|
|
$crit->where(Criteria::expr()->eq('status', JOStatus::RIDER_ASSIGN));
|
|
|
|
return $this->job_orders->matching($crit);
|
|
}
|
|
|
|
public function addOutlet(Outlet $outlet)
|
|
{
|
|
$this->outlets[] = $outlet;
|
|
return $this;
|
|
}
|
|
|
|
public function getOutlets()
|
|
{
|
|
return $this->outlets;
|
|
}
|
|
|
|
public function setBranchCode($branch_code)
|
|
{
|
|
$this->branch_code = $branch_code;
|
|
return $this;
|
|
}
|
|
|
|
public function getBranchCode()
|
|
{
|
|
return $this->branch_code;
|
|
}
|
|
|
|
public function setStatusOpen($status = true)
|
|
{
|
|
$this->status_open = $status;
|
|
return $this;
|
|
}
|
|
|
|
public function isStatusOpen()
|
|
{
|
|
return $this->status_open;
|
|
}
|
|
|
|
public function setRiderSlots($rider_slots)
|
|
{
|
|
$this->rider_slots = $rider_slots;
|
|
return $this;
|
|
}
|
|
|
|
public function getRiderSlots()
|
|
{
|
|
return $this->rider_slots;
|
|
}
|
|
|
|
public function setHubViewFlag($flag_hub_view = true)
|
|
{
|
|
$this->flag_hub_view = $flag_hub_view;
|
|
return $this;
|
|
}
|
|
|
|
public function isHubView()
|
|
{
|
|
return $this->flag_hub_view;
|
|
}
|
|
|
|
public function setNotifNumber($notif_number)
|
|
{
|
|
$this->notif_number = $notif_number;
|
|
return $this;
|
|
}
|
|
|
|
public function getNotifNumber()
|
|
{
|
|
return $this->notif_number;
|
|
}
|
|
|
|
public function getPaymentMethods()
|
|
{
|
|
return $this->payment_methods;
|
|
}
|
|
|
|
public function setPaymentMethods(array $payment_methods)
|
|
{
|
|
$this->payment_methods = new ArrayCollection();
|
|
|
|
foreach ($payment_methods as $payment_method)
|
|
{
|
|
$this->payment_methods->add($payment_method);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function clearPaymentMethods()
|
|
{
|
|
$this->payment_methods = new ArrayCollection();
|
|
return $this;
|
|
}
|
|
|
|
public function setHubAutoAssign($flag_hub_auto_assign = true)
|
|
{
|
|
$this->flag_hub_auto_assign = $flag_hub_auto_assign;
|
|
return $this;
|
|
}
|
|
|
|
public function isHubAutoAssign()
|
|
{
|
|
return $this->flag_hub_auto_assign;
|
|
}
|
|
|
|
public function setRiderAutoAssign($flag_rider_auto_assign = true)
|
|
{
|
|
$this->flag_rider_auto_assign = $flag_rider_auto_assign;
|
|
return $this;
|
|
}
|
|
|
|
public function isRiderAutoAssign()
|
|
{
|
|
return $this->flag_rider_auto_assign;
|
|
}
|
|
|
|
|
|
}
|