153 lines
3.1 KiB
PHP
153 lines
3.1 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;
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|