Merge branch '344-cmb-rider-queue-management' into '270-final-cmb-fixes'

Add active job order feature for rider #344

See merge request jankstudio/resq!388
This commit is contained in:
Kendrick Chan 2020-02-17 17:01:50 +00:00
commit d2afb99f4f
4 changed files with 116 additions and 1 deletions

View file

@ -41,3 +41,8 @@ rider_ajax_popup:
path: /riders/{id}/popup
controller: App\Controller\RiderController::popupInfo
methods: [GET]
rider_active_jo:
path: /riders/{id}/activejo/{jo_id}
controller: App\Controller\RiderController::riderActiveJO
methods: [GET]

View file

@ -7,7 +7,10 @@ use App\Entity\Rider;
use App\Entity\RiderSchedule;
use App\Entity\Hub;
use App\Entity\User;
use App\Entity\JobOrder;
use App\Service\FileUploader;
use App\Service\MQTTClient;
use Doctrine\ORM\Query;
use Doctrine\ORM\EntityManagerInterface;
@ -18,6 +21,8 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Catalyst\MenuBundle\Annotation\Menu;
use DateTime;
@ -510,4 +515,25 @@ class RiderController extends Controller
return $this->render('rider/popup.html.twig', [ 'rider' => $rider ]);
}
/**
* @ParamConverter("rider", class="App\Entity\Rider")
*/
public function riderActiveJO(EntityManagerInterface $em, MQTTClient $mclient, Rider $rider, $jo_id)
{
$jo = $em->getRepository(JobOrder::class)->find($jo_id);
$rider->setActiveJobOrder($jo);
$em->flush();
// TODO: trigger what needs triggering in rider app
$payload = [
'event' => 'cancelled',
'reason' => 'Reprioritization',
'jo_id' => $jo->getID(),
];
$mclient->sendRiderEvent($jo, $payload);
return $this->redirecttoRoute('rider_update', ['id' => $rider->getID()]);
}
}

View file

@ -64,6 +64,13 @@ class Rider
*/
protected $job_orders;
// rider's active job order since we now support multiple job orders per rider
/**
* @ORM\OneToOne(targetEntity="JobOrder")
* @ORM\JoinColumn(name="active_jo_id", referencedColumnName="id")
*/
protected $active_job_order;
// picture of rider
/**
* @ORM\Column(type="string", nullable=true)
@ -122,6 +129,8 @@ class Rider
$this->flag_active = true;
$this->username = null;
$this->password = '';
$this->active_job_order = null;
}
public function getID()
@ -300,8 +309,19 @@ class Rider
return $this->password;
}
public function setActiveJobOrder(JobOrder $jo = null)
{
$this->active_job_order = $jo;
return $this;
}
public function getActiveJobOrder()
{
// check if we have set a custom active
if ($this->active_job_order != null)
return $this->active_job_order;
// no custom active job order
$active_status = [
JOStatus::ASSIGNED,
JOStatus::IN_TRANSIT,
@ -315,6 +335,20 @@ class Rider
return $this->job_orders->matching($criteria)[0];
}
public function getOpenJobOrders()
{
$active_status = [
JOStatus::ASSIGNED,
JOStatus::IN_TRANSIT,
JOStatus::IN_PROGRESS,
];
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->in('status', $active_status));
return $this->job_orders->matching($criteria);
}
public function getSessions()
{
return $this->sessions;

View file

@ -13,7 +13,7 @@
<div class="m-content">
<!--Begin::Section-->
<div class="row">
<div class="col-xl-8">
<div class="col-xl-12">
<div class="m-portlet m-portlet--mobile">
<div class="m-portlet__head">
<div class="m-portlet__head-caption">
@ -150,6 +150,56 @@
{% endif %}
</div>
</div>
<div class="m-form__seperator m-form__seperator--dashed"></div>
<div class="m-form__section">
<div class="m-form__heading">
<h3 class="m-form__heading-title">
Active Job Orders
</h3>
</div>
<div class="form-group m-form__group row">
<div class="col-lg-12">
<table id="jo-table" class="table m-table">
<thead>
<tr>
<th>ID</th>
<th>Date</th>
<th>Customer</th>
<th>Location</th>
<th>Q Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% set active_jo_id = obj.getActiveJobOrder.getID|default(0) %}
{% for jo in obj.getOpenJobOrders %}
<tr>
<td>{{ jo.getID }}</td>
<td>{{ jo.getDateSchedule.format('Y-m-d H:i:s') }}</td>
<td>{{ jo.getCustomer.getNameDisplay }}</td>
<td>{{ jo.getDeliveryAddress|default('') }}</td>
<td>{% if jo.getID == active_jo_id %}<span class="m-badge m-badge--success m-badge--wide">Active</span>{% endif %}</td>
<td>
{% if jo.getID != active_jo_id %}
<!-- TODO: make this submit via ajax post -->
<a href="{{ url('rider_active_jo', {'id': obj.getID, 'jo_id': jo.getID}) }}" class="btn btn-danger m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
<span>
<i class="la la-check"></i>
</span>
</a>
{% endif %}
</td>
</tr>
{% else %}
<tr>
<td colspan="6">No assigned job orders.</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<div class="m-form__seperator m-form__seperator--dashed"></div>
<div class="m-form__section m-form__section--last">
<div class="m-form__heading">