Merge branch '270-final-cmb-fixes' of gitlab.com:jankstudio/resq into 270-final-cmb-fixes

This commit is contained in:
Kendrick Chan 2020-03-05 23:53:24 +08:00
commit e4b8e44b06
25 changed files with 549 additions and 56 deletions

View file

@ -110,10 +110,6 @@ main_menu:
acl: jo_walkin.form acl: jo_walkin.form
label: Walk-in label: Walk-in
parent: joborder parent: joborder
- id: jo_fulfill
acl: jo_fulfill.list
label: Fulfillment
parent: joborder
- id: jo_open - id: jo_open
acl: jo_open.list acl: jo_open.list
label: Open label: Open

View file

@ -110,10 +110,6 @@ main_menu:
acl: jo_walkin.form acl: jo_walkin.form
label: Walk-in label: Walk-in
parent: joborder parent: joborder
- id: jo_fulfill
acl: jo_fulfill.list
label: Fulfillment
parent: joborder
- id: jo_open - id: jo_open
acl: jo_open.list acl: jo_open.list
label: Open label: Open

View file

@ -46,3 +46,13 @@ rider_active_jo:
path: /riders/{id}/activejo/{jo_id} path: /riders/{id}/activejo/{jo_id}
controller: App\Controller\RiderController::riderActiveJO controller: App\Controller\RiderController::riderActiveJO
methods: [GET] methods: [GET]
rider_priority_up_jo:
path: /riders/{id}/priority_up/{jo_id}
controller: App\Controller\RiderController::priorityUpJO
methods: [GET]
rider_priority_down_jo:
path: /riders/{id}/priority_down/{jo_id}
controller: App\Controller\RiderController::priorityDownJO
methods: [GET]

View file

@ -51,6 +51,32 @@ class DashboardMap {
return this.map; return this.map;
} }
switchRiderStatus(rider_id, rider_status) {
console.log('switching rider ' + rider_id + ' to ' + rider_status);
// find the marker
console.log(this.rider_markers);
if (this.rider_markers.hasOwnProperty(rider_id)) {
var marker = this.rider_markers[rider_id];
} else {
// TODO: call ajax to get location and create marker
console.log('marker not found for rider');
return true;
}
// add it to proper layer group
console.log(rider_status);
if (rider_status == 'available') {
this.layer_groups.rider_active_jo.removeLayer(marker);
this.layer_groups.rider_available.addLayer(marker);
marker.setIcon(this.options.icons.rider_available);
} else if (rider_status == 'jo') {
this.layer_groups.rider_available.removeLayer(marker);
this.layer_groups.rider_active_jo.addLayer(marker);
marker.setIcon(this.options.icons.rider_active_jo);
}
}
putMarker(id, lat, lng, markers, icon, layer_group, popup_url) { putMarker(id, lat, lng, markers, icon, layer_group, popup_url) {
var my = this; var my = this;
// existing marker // existing marker
@ -131,6 +157,19 @@ class DashboardMap {
); );
} }
removeRiderMarker(id) {
console.log('removing rider marker for ' + id);
var markers = this.rider_markers;
if (!markers.hasOwnProperty(id)) {
console.log('no such marker to remove');
return;
}
this.layer_groups.rider_active_jo.removeLayer(markers[id]);
this.layer_groups.rider_available.removeLayer(markers[id]);
}
loadLocations(location_url) { loadLocations(location_url) {
console.log(this.rider_markers); console.log(this.rider_markers);
var my = this; var my = this;

View file

@ -27,18 +27,26 @@ class MapEventHandler {
console.log('mqtt connected!'); console.log('mqtt connected!');
var my = icontext.invocationContext; var my = icontext.invocationContext;
// subscribe to rider locations
if (my.options.track_rider) { if (my.options.track_rider) {
// subscribe to rider locations
console.log('subscribing to ' + my.options.channels.rider_location); console.log('subscribing to ' + my.options.channels.rider_location);
my.mqtt.subscribe(my.options.channels.rider_location); my.mqtt.subscribe(my.options.channels.rider_location);
// subscribe to rider status
console.log('subscribing to ' + my.options.channels.rider_status);
my.mqtt.subscribe(my.options.channels.rider_status);
} }
// subscribe to jo locations
if (my.options.track_jo) { if (my.options.track_jo) {
// subscribe to jo locations
console.log('subscribing to ' + my.options.channels.jo_location); console.log('subscribing to ' + my.options.channels.jo_location);
my.mqtt.subscribe(my.options.channels.jo_location); my.mqtt.subscribe(my.options.channels.jo_location);
// subscribe to jo status
console.log('subscribing to ' + my.options.channels.jo_status);
my.mqtt.subscribe(my.options.channels.jo_status); my.mqtt.subscribe(my.options.channels.jo_status);
} }
} }
onMessage(msg) { onMessage(msg) {
@ -75,8 +83,24 @@ class MapEventHandler {
var lat = parseFloat(pl_split[0]); var lat = parseFloat(pl_split[0]);
var lng = parseFloat(pl_split[1]); var lng = parseFloat(pl_split[1]);
// TODO: check if available or not
this.dashmap.putRiderAvailableMarker(chan_split[1], lat, lng); this.dashmap.putRiderAvailableMarker(chan_split[1], lat, lng);
break; break;
case "status":
console.log("got status for rider " + chan_split[1] + " - " + payload);
switch (payload) {
case 'available':
this.dashmap.switchRiderStatus(chan_split[1], 'available');
break;
case 'jo':
console.log('jo status');
this.dashmap.switchRiderStatus(chan_split[1], 'jo');
break;
case 'logout':
this.dashmap.removeRiderMarker(chan_split[1]);
break;
}
break;
} }
} }
@ -102,6 +126,7 @@ class MapEventHandler {
this.dashmap.putCustomerMarker(id, lat, lng); this.dashmap.putCustomerMarker(id, lat, lng);
break; break;
case "status": case "status":
console.log("got status for jo " + payload);
switch (payload) { switch (payload) {
case 'cancel': case 'cancel':
case 'fulfill': case 'fulfill':

View file

@ -277,13 +277,13 @@ class JobOrderController extends Controller
$rows[$key]['meta']['reassign_hub_url'] = $this->generateUrl('jo_open_hub_form', ['id' => $jo_id]); $rows[$key]['meta']['reassign_hub_url'] = $this->generateUrl('jo_open_hub_form', ['id' => $jo_id]);
$rows[$key]['meta']['reassign_rider_url'] = $this->generateUrl('jo_open_rider_form', ['id' => $jo_id]); $rows[$key]['meta']['reassign_rider_url'] = $this->generateUrl('jo_open_rider_form', ['id' => $jo_id]);
// $rows[$key]['meta']['edit_url'] = $this->generateUrl('jo_open_edit_form', ['id' => $jo_id]); // $rows[$key]['meta']['edit_url'] = $this->generateUrl('jo_open_edit_form', ['id' => $jo_id]);
$rows[$key]['meta']['edit_url'] = $this->generateUrl($jo_handler->getEditRoute(), ['id' => $jo_id]); $rows[$key]['meta']['edit_url'] = $this->generateUrl($jo_handler->getEditRoute($jo_id, $tier_params['edit_route']), ['id' => $jo_id]);
$rows[$key]['meta']['onestep_edit_url'] = $this->generateUrl('jo_onestep_edit_form', ['id' => $jo_id]); $rows[$key]['meta']['onestep_edit_url'] = $this->generateUrl('jo_onestep_edit_form', ['id' => $jo_id]);
} }
else else
{ {
// $rows[$key]['meta']['update_url'] = $this->generateUrl($tier_params['edit_route'], ['id' => $jo_id]); // $rows[$key]['meta']['update_url'] = $this->generateUrl($tier_params['edit_route'], ['id' => $jo_id]);
$rows[$key]['meta']['update_url'] = $this->generateUrl($jo_handler->getEditRoute(), ['id' => $jo_id]); $rows[$key]['meta']['update_url'] = $this->generateUrl($jo_handler->getEditRoute($jo_id, $tier_params['edit_route']), ['id' => $jo_id]);
$rows[$key]['meta']['onestep_edit_url'] = $this->generateUrl('jo_onestep_edit_form', ['id' => $jo_id]); $rows[$key]['meta']['onestep_edit_url'] = $this->generateUrl('jo_onestep_edit_form', ['id' => $jo_id]);
$rows[$key]['meta']['pdf_url'] = $this->generateUrl('jo_pdf_form', ['id' => $jo_id]); $rows[$key]['meta']['pdf_url'] = $this->generateUrl('jo_pdf_form', ['id' => $jo_id]);
} }
@ -698,7 +698,7 @@ class JobOrderController extends Controller
$items = $req->request->get('items'); $items = $req->request->get('items');
$promo_id = $req->request->get('promo'); $promo_id = $req->request->get('promo');
$cvid = $req->request->get('cvid'); $cvid = $req->request->get('cvid');
$service_charges = $req->request->get('service_charges'); $service_charges = $req->request->get('service_charges', []);
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
@ -742,14 +742,7 @@ class JobOrderController extends Controller
} }
*/ */
// TODO: this snippet should be in the invoice generator $error = $ic->generateDraftInvoice($criteria, $promo_id, $service_charges, $items);
$error = $ic->validateDiscount($criteria, $promo_id);
// process service charges
$error = $ic->invoiceServiceCharges($criteria, $service_charges);
if (!$error)
$error = $ic->invoiceBatteries($criteria, $items);
if ($error) if ($error)
{ {
@ -1037,12 +1030,12 @@ class JobOrderController extends Controller
return $this->render($template, $params); return $this->render($template, $params);
} }
public function walkInEditSubmit(Request $req, JobOrderHandlerInterface $jo_handler) public function walkInEditSubmit(Request $req, JobOrderHandlerInterface $jo_handler, $id)
{ {
$this->denyAccessUnlessGranted('jo_walkin.edit', null, 'No access.'); $this->denyAccessUnlessGranted('jo_walkin.edit', null, 'No access.');
$error_array = []; $error_array = [];
$error_array = $jo_handler->processOneStepJobOrder($req, $id); $error_array = $jo_handler->processWalkinJobOrder($req, $id);
// check if any errors were found // check if any errors were found
if (!empty($error_array)) { if (!empty($error_array)) {

View file

@ -534,6 +534,66 @@ class RiderController extends Controller
$mclient->sendRiderEvent($jo, $payload); $mclient->sendRiderEvent($jo, $payload);
return $this->redirecttoRoute('rider_update', ['id' => $rider->getID()]);
}
/**
* @ParamConverter("rider", class="App\Entity\Rider")
* @ParamConverter("jo", class="App\Entity\JobOrder", options={"id": "jo_id"})
*/
public function priorityUpJO(EntityManagerInterface $em, Rider $rider, JobOrder $jo)
{
$jos = $rider->getOpenJobOrders();
// set new priority
$old_prio = $jo->getPriority();
$new_prio = $old_prio - 1;
$jo->setPriority($new_prio);
// go through all rider open JOs and set priority when needed
foreach ($jos as $rider_jo)
{
// check if it's the same
if ($rider_jo->getID() == $jo->getID())
continue;
// if priority is the same as old priority, move it down
if ($new_prio == $rider_jo->getPriority())
$rider_jo->setPriority($rider_jo->getPriority() + 1);
}
$em->flush();
return $this->redirecttoRoute('rider_update', ['id' => $rider->getID()]);
}
/**
* @ParamConverter("rider", class="App\Entity\Rider")
* @ParamConverter("jo", class="App\Entity\JobOrder", options={"id": "jo_id"})
*/
public function priorityDownJO(EntityManagerInterface $em, Rider $rider, JobOrder $jo)
{
$jos = $rider->getOpenJobOrders();
// set new priority
$old_prio = $jo->getPriority();
$new_prio = $old_prio + 1;
$jo->setPriority($new_prio);
// go through all rider open JOs and set priority when needed
foreach ($jos as $rider_jo)
{
// check if it's the same
if ($rider_jo->getID() == $jo->getID())
continue;
// if priority is the same as old priority, move it down
if ($new_prio == $rider_jo->getPriority())
$rider_jo->setPriority($rider_jo->getPriority() - 1);
}
$em->flush();
return $this->redirecttoRoute('rider_update', ['id' => $rider->getID()]); return $this->redirecttoRoute('rider_update', ['id' => $rider->getID()]);
} }
} }

View file

@ -280,6 +280,14 @@ class JobOrder
*/ */
protected $hub_rejections; 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;
// meta // meta
/** /**
* @ORM\Column(type="json") * @ORM\Column(type="json")
@ -304,6 +312,7 @@ class JobOrder
$this->flag_rider_rating = false; $this->flag_rider_rating = false;
$this->flag_coolant = false; $this->flag_coolant = false;
$this->priority = 0;
$this->meta = []; $this->meta = [];
} }
@ -811,6 +820,17 @@ class JobOrder
return $this->hub_rejections; return $this->hub_rejections;
} }
public function setPriority($priority)
{
$this->priority = $priority;
return $this;
}
public function getPriority()
{
return $this->priority;
}
public function addMeta($id, $value) public function addMeta($id, $value)
{ {
$this->meta[$id] = $value; $this->meta[$id] = $value;
@ -825,5 +845,4 @@ class JobOrder
return $this->meta[$id]; return $this->meta[$id];
} }
} }

View file

@ -61,6 +61,7 @@ class Rider
// job orders that the rider has done // job orders that the rider has done
/** /**
* @ORM\OneToMany(targetEntity="JobOrder", mappedBy="rider") * @ORM\OneToMany(targetEntity="JobOrder", mappedBy="rider")
* @ORM\OrderBy({"priority" = "ASC"})
*/ */
protected $job_orders; protected $job_orders;
@ -319,7 +320,18 @@ class Rider
{ {
// check if we have set a custom active // check if we have set a custom active
if ($this->active_job_order != null) if ($this->active_job_order != null)
return $this->active_job_order; {
switch ($this->active_job_order->getStatus())
{
// if jo is open, return it
case JOStatus::ASSIGNED:
case JOStatus::IN_TRANSIT:
case JOStatus::IN_PROGRESS:
return $this->active_job_order;
}
// if active jo is not open, get the next open one
}
// no custom active job order // no custom active job order
$active_status = [ $active_status = [

View file

@ -35,6 +35,7 @@ class JobOrderActiveCacheListener
$this->processActiveJO($jo); $this->processActiveJO($jo);
break; break;
// inactive // inactive
// NOTE: should never really get here since it's creation
case JOStatus::CANCELLED: case JOStatus::CANCELLED:
$this->processInactiveJO($jo, 'cancel'); $this->processInactiveJO($jo, 'cancel');
break; break;
@ -84,22 +85,55 @@ class JobOrderActiveCacheListener
$coords = $jo->getCoordinates(); $coords = $jo->getCoordinates();
// TODO: do we put the key in config? // TODO: do we put the key in config?
// send jo location
$this->mqtt->publish( $this->mqtt->publish(
'jo/' . $jo->getID() . '/location', 'jo/' . $jo->getID() . '/location',
$coords->getLatitude() . ':' . $coords->getLongitude() $coords->getLatitude() . ':' . $coords->getLongitude()
); );
// TODO: do we still need to send jo status?
// send rider status
$rider = $jo->getRider();
if ($rider != null)
{
$this->mqtt->publish(
'rider/' . $rider->getID() . '/status',
'jo'
);
}
} }
protected function processInactiveJO($jo, $status = 'cancel') protected function processInactiveJO($jo, $status = 'cancel')
{ {
error_log('got inactive jo, sending mqtt message for ' . $jo->getID());
// remove from redis cache // remove from redis cache
$this->jo_cache->removeActiveJobOrder($jo); $this->jo_cache->removeActiveJobOrder($jo);
// TODO: publich to mqtt // publish to mqtt
// send jo status
$this->mqtt->publish( $this->mqtt->publish(
'jo/' . $jo->getID() . '/status', 'jo/' . $jo->getID() . '/status',
$status $status
); );
// send rider status
$rider = $jo->getRider();
if ($rider != null)
{
// check if rider has any queued jobs
$open_jos = $rider->getOpenJobOrders();
if (count($open_jos) > 0)
$rider_status = 'jo';
else
$rider_status = 'available';
// send status
$this->mqtt->publish(
'rider/' . $rider->getID() . '/status',
$rider_status
);
}
} }
} }

View file

@ -204,6 +204,25 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface
} }
} }
// prepare draft for invoice
public function generateDraftInvoice($criteria, $discount, $service_charges, $items)
{
$ierror = $this->validateDiscount($criteria, $discount);
if (!$ierror)
{
// process service charges
$ierror = $this->invoiceServiceCharges($criteria, $service_charges);
if (!$ierror)
{
$ierror = $this->invoiceBatteries($criteria, $items);
}
}
return $ierror;
}
protected function getTaxAmount($price) protected function getTaxAmount($price)
{ {
$vat_ex_price = $this->getTaxExclusivePrice($price); $vat_ex_price = $this->getTaxExclusivePrice($price);

View file

@ -194,6 +194,20 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface
} }
} }
// prepare draft for invoice
public function generateDraftInvoice($criteria, $promo_id, $service_charges, $items)
{
$ierror = $this->invoicePromo($criteria, $promo_id);
if (!$ierror)
{
$ierror = $this->invoiceBatteries($criteria, $items);
}
return $ierror;
}
protected function getTaxAmount($price) protected function getTaxAmount($price)
{ {
$vat_ex_price = $this->getTaxExclusivePrice($price); $vat_ex_price = $this->getTaxExclusivePrice($price);
@ -227,7 +241,7 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface
return 0; return 0;
} }
public function invoicePromo(InvoiceCriteria $criteria, $promo_id) protected function invoicePromo(InvoiceCriteria $criteria, $promo_id)
{ {
// return error if there's a problem, false otherwise // return error if there's a problem, false otherwise
// check service type // check service type

View file

@ -15,4 +15,7 @@ interface InvoiceGeneratorInterface
// generate invoice criteria // generate invoice criteria
public function generateInvoiceCriteria(JobOrder $jo, int $promo_id, array $invoice_items, array &$error_array); public function generateInvoiceCriteria(JobOrder $jo, int $promo_id, array $invoice_items, array &$error_array);
// prepare draft for invoice
public function generateDraftInvoice(InvoiceCriteria $criteria, int $promo_id, array $service_charges, array $items);
} }

View file

@ -165,6 +165,25 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
// process rows // process rows
$rows = []; $rows = [];
foreach ($obj_rows as $orow) { foreach ($obj_rows as $orow) {
// get car model
$cv = $orow->getCustomerVehicle();
$cv_manufacturer = $cv->getVehicle()->getManufacturer()->getName();
$cv_make = $cv->getVehicle()->getMake();
$year = $cv->getModelYear();
$car_model = $cv_manufacturer . ' ' . $cv_make . ' ' . $year;
// get rider information
$rider_name = '';
$rider_plate_number = '';
$rider = $orow->getRider();
if (!empty($rider))
{
$rider_name = $rider->getFullName();
$rider_plate_number = $rider->getPlateNumber();
}
// add row data // add row data
$row['id'] = $orow->getID(); $row['id'] = $orow->getID();
$row['customer_name'] = $orow->getCustomer()->getFirstName() . ' ' . $orow->getCustomer()->getLastName(); $row['customer_name'] = $orow->getCustomer()->getFirstName() . ' ' . $orow->getCustomer()->getLastName();
@ -176,6 +195,9 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
$row['flag_advance'] = $orow->isAdvanceOrder(); $row['flag_advance'] = $orow->isAdvanceOrder();
$row['plate_number'] = $orow->getCustomerVehicle()->getPlateNumber(); $row['plate_number'] = $orow->getCustomerVehicle()->getPlateNumber();
$row['is_mobile'] = $orow->getSource() == TransactionOrigin::MOBILE_APP; $row['is_mobile'] = $orow->getSource() == TransactionOrigin::MOBILE_APP;
$row['car_model'] = $car_model;
$row['rider_name'] = $rider_name;
$row['rider_plate_number'] = $rider_plate_number;
$processor = $orow->getProcessedBy(); $processor = $orow->getProcessedBy();
if ($processor == null) if ($processor == null)
@ -523,6 +545,19 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
} }
} }
// set priority based on rider's existing open job orders
$rider_jos = $rider->getOpenJobOrders();
// get maximum priority then add 1
// NOTE: this can be a bit buggy due to concurrency issues
// ideally have to lock jo table, but that isn't feasible right now
$priority = 0;
foreach ($rider_jos as $rider_jo)
{
if ($priority < $rider_jo->getPriority())
$priority = $rider_jo->getPriority() + 1;
}
// get discount and set to meta // get discount and set to meta
$discount = $req->request->get('invoice_discount', []); $discount = $req->request->get('invoice_discount', []);
@ -560,7 +595,8 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
->setModeOfPayment($req->request->get('mode_of_payment')) ->setModeOfPayment($req->request->get('mode_of_payment'))
->setLandmark($req->request->get('landmark')) ->setLandmark($req->request->get('landmark'))
->setHub($hub) ->setHub($hub)
->setRider($rider); ->setRider($rider)
->setPriority($priority);
$jo->addMeta('discount', $discount); $jo->addMeta('discount', $discount);
$jo->addMeta('service_charges', $service_charges); $jo->addMeta('service_charges', $service_charges);
@ -2069,13 +2105,6 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
$pdf->Cell($label_width, $line_height, 'Plate Number:'); $pdf->Cell($label_width, $line_height, 'Plate Number:');
$pdf->MultiCell($val_width, $line_height, $cv ? $cv->getPlateNumber() : '', 0, 'L'); $pdf->MultiCell($val_width, $line_height, $cv ? $cv->getPlateNumber() : '', 0, 'L');
// get Y after left cell
$y1 = $pdf->GetY();
$pdf->SetXY($col2_x, $y);
$pdf->Cell($label_width, $line_height, 'Vehicle Color:');
$pdf->MultiCell(0, $line_height, $cv ? $cv->getColor() : '', 0, 'L');
// get Y after right cell // get Y after right cell
$y2 = $pdf->GetY(); $y2 = $pdf->GetY();
@ -2800,7 +2829,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
$this->template_hash['jo_all_form'] = 'job-order/cmb.form.onestep.html.twig'; $this->template_hash['jo_all_form'] = 'job-order/cmb.form.onestep.html.twig';
$this->template_hash['jo_list_fulfillment'] = 'job-order/cmb.list.fulfillment.html.twig'; $this->template_hash['jo_list_fulfillment'] = 'job-order/cmb.list.fulfillment.html.twig';
$this->template_hash['jo_list_open'] = 'job-order/cmb.list.open.html.twig'; $this->template_hash['jo_list_open'] = 'job-order/cmb.list.open.html.twig';
$this->template_hash['jo_list_all'] = 'job-order/list.all.html.twig'; $this->template_hash['jo_list_all'] = 'job-order/cmb.list.all.html.twig';
$this->template_hash['jo_onestep_form'] = 'job-order/cmb.form.onestep.html.twig'; $this->template_hash['jo_onestep_form'] = 'job-order/cmb.form.onestep.html.twig';
$this->template_hash['jo_onestep_edit_form'] = 'job-order/cmb.form.onestep.html.twig'; $this->template_hash['jo_onestep_edit_form'] = 'job-order/cmb.form.onestep.html.twig';
$this->template_hash['jo_walkin_form'] = 'job-order/cmb.form.walkin.html.twig'; $this->template_hash['jo_walkin_form'] = 'job-order/cmb.form.walkin.html.twig';
@ -2997,8 +3026,16 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
} }
} }
public function getEditRoute() public function getEditRoute($jo_id, $tier = null)
{ {
return 'jo_onestep_edit_form'; $jo = $this->em->getRepository(JobOrder::class)->find($jo_id);
if (empty($jo))
throw new NotFoundHttpException('The item does not exist');
// check transaction origin
if ($jo->getSource() == TransactionOrigin::WALK_IN)
return 'jo_walkin_edit_form';
else
return 'jo_onestep_edit_form';
} }
} }

View file

@ -314,6 +314,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
} }
} }
// TODO: check status before saving since JO might already
// have a status that needs to be retained
if (empty($error_array)) { if (empty($error_array)) {
// get current user // get current user
$user = $this->security->getUser(); $user = $this->security->getUser();
@ -2588,7 +2591,11 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
} }
} }
public function getEditRoute() public function getEditRoute($jo_id, $tier)
{ {
if (empty($tier))
return 'jo_open_edit_form';
return $tier;
} }
} }

View file

@ -98,4 +98,7 @@ interface JobOrderHandlerInterface
// check if service type is new battery // check if service type is new battery
public function checkIfNewBattery(JobOrder $jo); public function checkIfNewBattery(JobOrder $jo);
// return the edit route, based on tier and form
public function getEditRoute(int $jo_id, $tier);
} }

View file

@ -51,6 +51,7 @@ function initEventHandler(dashmap) {
'track_rider': true, 'track_rider': true,
'channels': { 'channels': {
'rider_location': 'rider/+/location', 'rider_location': 'rider/+/location',
'rider_status': 'rider/+/status',
'jo_location': 'jo/+/location', 'jo_location': 'jo/+/location',
'jo_status': 'jo/+/status' 'jo_status': 'jo/+/status'
}, },

View file

@ -206,17 +206,17 @@
<div class="form-group m-form__group row"> <div class="form-group m-form__group row">
<div class="col-lg-3"> <div class="col-lg-3">
<label data-field="current_battery">Current Battery</label> <label data-field="current_battery">Current Battery</label>
<input type="text" name="current_battery" id="current-battery" class="form-control m-input" value="{{ obj.getCustomerVehicle and obj.getCustomerVehicle.getCurrentBattery ? obj.getCustomerVehicle.getCurrentBattery.getManufacturer.getName ~ ' ' ~ obj.getCustomerVehicle.getCurrentBattery.getModel.getName ~ ' ' ~ obj.getCustomerVehicle.getCurrentBattery.getSize.getName ~ ' (' ~ obj.getCustomerVehicle.getCurrentBattery.getProductCode ~ ')' }}" data-vehicle-field="1" disabled> <input type="text" name="current_battery" id="current-battery" class="form-control m-input battery_field" value="{{ obj.getCustomerVehicle and obj.getCustomerVehicle.getCurrentBattery ? obj.getCustomerVehicle.getCurrentBattery.getManufacturer.getName ~ ' ' ~ obj.getCustomerVehicle.getCurrentBattery.getModel.getName ~ ' ' ~ obj.getCustomerVehicle.getCurrentBattery.getSize.getName ~ ' (' ~ obj.getCustomerVehicle.getCurrentBattery.getProductCode ~ ')' }}" data-vehicle-field="1" disabled>
<div class="form-control-feedback hide" data-field="current_battery"></div> <div class="form-control-feedback hide" data-field="current_battery"></div>
</div> </div>
<div class="col-lg-3"> <div class="col-lg-3">
<label data-field="warranty_code">Serial Number</label> <label data-field="warranty_code">Serial Number</label>
<input type="text" name="warranty_code" id="warranty-code" class="form-control m-input" value="{{ obj.getCustomerVehicle ? obj.getCustomerVehicle.getWarrantyCode }}"> <input type="text" name="warranty_code" id="warranty-code" class="form-control m-input battery_field" value="{{ obj.getCustomerVehicle ? obj.getCustomerVehicle.getWarrantyCode }}">
<div class="form-control-feedback hide" data-field="warranty_code"></div> <div class="form-control-feedback hide" data-field="warranty_code"></div>
</div> </div>
<div class="col-lg-3"> <div class="col-lg-3">
<label data-field="warranty_expiration">Warranty Expiration Date</label> <label data-field="warranty_expiration">Warranty Expiration Date</label>
<input type="text" name="warranty_expiration" id="warranty-expiration" class="form-control m-input" value="{{ obj.getCustomerVehicle.getCurrentBattery|default(false) ? obj.getCustomerVehicle.getWarrantyExpiration|date("d M Y") : '' }}" data-vehicle-field="1" disabled> <input type="text" name="warranty_expiration" id="warranty-expiration" class="form-control m-input battery_field" value="{{ obj.getCustomerVehicle.getCurrentBattery|default(false) ? obj.getCustomerVehicle.getWarrantyExpiration|date("d M Y") : '' }}" data-vehicle-field="1" disabled>
<div class="form-control-feedback hide" data-field="warranty_expiration"></div> <div class="form-control-feedback hide" data-field="warranty_expiration"></div>
</div> </div>
</div> </div>
@ -1270,6 +1270,7 @@ $(function() {
$('.cust_field').val(''); $('.cust_field').val('');
$('.cv_field').val(''); $('.cv_field').val('');
$('#cv-make').val(''); $('#cv-make').val('');
$('.battery_field').val('');
} else { } else {
$('.cust_field').prop('disabled', true); $('.cust_field').prop('disabled', true);
$('.cv_field').prop('disabled', true); $('.cv_field').prop('disabled', true);

View file

@ -206,17 +206,17 @@
<div class="form-group m-form__group row"> <div class="form-group m-form__group row">
<div class="col-lg-3"> <div class="col-lg-3">
<label data-field="current_battery">Current Battery</label> <label data-field="current_battery">Current Battery</label>
<input type="text" name="current_battery" id="current-battery" class="form-control m-input" value="{{ obj.getCustomerVehicle and obj.getCustomerVehicle.getCurrentBattery ? obj.getCustomerVehicle.getCurrentBattery.getManufacturer.getName ~ ' ' ~ obj.getCustomerVehicle.getCurrentBattery.getModel.getName ~ ' ' ~ obj.getCustomerVehicle.getCurrentBattery.getSize.getName ~ ' (' ~ obj.getCustomerVehicle.getCurrentBattery.getProductCode ~ ')' }}" data-vehicle-field="1" disabled> <input type="text" name="current_battery" id="current-battery" class="form-control m-input battery_field" value="{{ obj.getCustomerVehicle and obj.getCustomerVehicle.getCurrentBattery ? obj.getCustomerVehicle.getCurrentBattery.getManufacturer.getName ~ ' ' ~ obj.getCustomerVehicle.getCurrentBattery.getModel.getName ~ ' ' ~ obj.getCustomerVehicle.getCurrentBattery.getSize.getName ~ ' (' ~ obj.getCustomerVehicle.getCurrentBattery.getProductCode ~ ')' }}" data-vehicle-field="1" disabled>
<div class="form-control-feedback hide" data-field="current_battery"></div> <div class="form-control-feedback hide" data-field="current_battery"></div>
</div> </div>
<div class="col-lg-3"> <div class="col-lg-3">
<label data-field="warranty_code">Serial Number</label> <label data-field="warranty_code">Serial Number</label>
<input type="text" name="warranty_code" id="warranty-code" class="form-control m-input" value="{{ obj.getCustomerVehicle ? obj.getCustomerVehicle.getWarrantyCode }}"> <input type="text" name="warranty_code" id="warranty-code" class="form-control m-input battery_field" value="{{ obj.getCustomerVehicle ? obj.getCustomerVehicle.getWarrantyCode }}">
<div class="form-control-feedback hide" data-field="warranty_code"></div> <div class="form-control-feedback hide" data-field="warranty_code"></div>
</div> </div>
<div class="col-lg-3"> <div class="col-lg-3">
<label data-field="warranty_expiration">Warranty Expiration Date</label> <label data-field="warranty_expiration">Warranty Expiration Date</label>
<input type="text" name="warranty_expiration" id="warranty-expiration" class="form-control m-input" value="{{ obj.getCustomerVehicle.getCurrentBattery|default(false) ? obj.getCustomerVehicle.getWarrantyExpiration|date("d M Y") : '' }}" data-vehicle-field="1" disabled> <input type="text" name="warranty_expiration" id="warranty-expiration" class="form-control m-input battery_field" value="{{ obj.getCustomerVehicle.getCurrentBattery|default(false) ? obj.getCustomerVehicle.getWarrantyExpiration|date("d M Y") : '' }}" data-vehicle-field="1" disabled>
<div class="form-control-feedback hide" data-field="warranty_expiration"></div> <div class="form-control-feedback hide" data-field="warranty_expiration"></div>
</div> </div>
</div> </div>
@ -347,7 +347,7 @@
</label> </label>
{% endif %} {% endif %}
<div class="form-control-feedback hide" data-field="hub"></div> <div class="form-control-feedback hide" data-field="hub"></div>
<input type="hidden" id="hub-field" name="hub_id" value=""> <input type="hidden" id="hub-field" name="hub_id" value="{{ obj.getHub ? obj.getHub.getID : "" }}">
<div class="table-frame" data-name="hub"> <div class="table-frame" data-name="hub">
<table id="hubs-table" class="table table-compact table-hover table-clickable m-table"> <table id="hubs-table" class="table table-compact table-hover table-clickable m-table">
<thead> <thead>
@ -557,7 +557,7 @@ function get_vehicle_makes(mfg_id, vid = 0) {
$(function() { $(function() {
var form_in_process = false; var form_in_process = false;
var selected_hub = ''; var selected_hub = '{{ obj.getHub ? obj.getHub.getID : "" }}';
$(function() { $(function() {
$('#hubs-table').on('click', 'tr', function() { $('#hubs-table').on('click', 'tr', function() {
@ -592,11 +592,6 @@ $(function() {
// add invoice items to data // add invoice items to data
fields['invoice_items'] = invoiceItems; fields['invoice_items'] = invoiceItems;
{% if mode in ['update-processing', 'update-reassign-hub'] %}
// add selected hub to data
fields['hub'] = selectedHub;
{% endif %}
e.preventDefault(); e.preventDefault();
$.ajax({ $.ajax({
@ -811,6 +806,7 @@ var vdata = false;
$('.cust_field').val(''); $('.cust_field').val('');
$('.cv_field').val(''); $('.cv_field').val('');
$('#cv-make').val(''); $('#cv-make').val('');
$('.battery_field').val('');
} else { } else {
$('.cust_field').prop('disabled', true); $('.cust_field').prop('disabled', true);
$('.cv_field').prop('disabled', true); $('.cv_field').prop('disabled', true);

View file

@ -0,0 +1,202 @@
{% extends 'base.html.twig' %}
{% block body %}
<!-- BEGIN: Subheader -->
<div class="m-subheader">
<div class="d-flex align-items-center">
<div class="mr-auto">
<h3 class="m-subheader__title">
Job Orders (All)
</h3>
</div>
</div>
</div>
<!-- END: Subheader -->
<div class="m-content">
<!--Begin::Section-->
<div class="row">
<div class="col-xl-12">
<div class="m-portlet m-portlet--mobile">
<div class="m-portlet__body">
<div class="m-form m-form--label-align-right m--margin-top-20 m--margin-bottom-30">
<div class="row align-items-center">
<div class="col-xl-12">
<div class="form-group m-form__group row align-items-center">
<div class="col-md-4">
<div class="m-input-icon m-input-icon--left">
<input type="text" class="form-control m-input m-input--solid" placeholder="Search..." id="data-rows-search">
<span class="m-input-icon__icon m-input-icon__icon--left">
<span><i class="la la-search"></i></span>
</span>
</div>
</div>
<div class="col-md-4">
<div class="m-input-icon m-input-icon--left">
<div class="input-group">
<select class="form-control m-input" id="rider_list" name="rider_list">
<option value="">All Riders</option>
{% for rider in riders %}
<option value="{{ rider.getID }}">{{ rider.getFirstName ~ ' ' ~ rider.getLastName }} </option>
{% endfor %}
</select>
</div>
</div>
</div>
<div class="col-md-4">
<div class="m-input-icon m-input-icon--left">
<div class="input-daterange input-group" id="date-range">
<input role="presentation" type="text" class="form-control m-input" id="date_start" name="date_start" placeholder="Start date" />
<div class="input-group-append">
<span class="input-group-text"><i class="la la-ellipsis-h"></i></span>
</div>
<input role="presentation" type="text" class="form-control" id="date_end" name="date_end" placeholder="End date" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!--begin: Datatable -->
<div id="data-rows"></div>
<!--end: Datatable -->
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
$(function() {
$("#date-range").datepicker({
orientation: "bottom"
});
var options = {
data: {
type: 'remote',
source: {
read: {
url: '{{ url('jo_all_rows') }}',
method: 'POST'
}
},
saveState: {
cookie: false,
webstorage: false
},
pageSize: 10,
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
rows: {
beforeTemplate: function (row, data, index) {
if (data.flag_advance) {
$(row).addClass('m-table__row--danger');
}
}
},
columns: [
{
field: 'id',
title: 'JO Number'
},
{
field: 'plate_number',
title: 'Plate #'
},
{
field: 'car_model',
title: 'Car Model'
},
{
field: 'customer_name',
title: 'Customer'
},
{
field: 'service_type',
title: 'Service Type',
},
{
field: 'delivery_address',
title: 'Customer Area'
},
{
field: 'type',
title: 'Schedule'
},
{
field: 'date_schedule',
title: 'Scheduled Date'
},
{
field: 'rider_name',
title: 'Rider'
},
{
field: 'rider_plate_number',
title: 'Rider Plate #'
},
{
field: 'status',
title: 'Status'
},
{
field: 'processor',
title: 'Dispatcher'
},
{
field: 'Actions',
width: 110,
title: 'Actions',
sortable: false,
overflow: 'visible',
template: function (row, index, datatable) {
var actions = '<a href="' + row.meta.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" title="View"><i class="la la-edit"></i></a>';
actions += '<a href="' + row.meta.pdf_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" title="PDF" target="_blank"><i class="la la-file-o"></i></a>';
return actions;
},
}
],
search: {
onEnter: false,
input: $('#data-rows-search'),
delay: 400
}
};
var table = $("#data-rows").mDatatable(options);
// auto refresh table
setInterval(function() {
table.reload();
}, {{ table_refresh_rate }});
$("#rider_list").on("change", function() {
table.search($(this).val(), "rider");
});
$("#date_start").on("change", function() {
var date_start = $(this).val();
var date_end = $("[name='date_end']").val();
var date_array = [date_start, date_end];
table.search(date_array, "schedule_date");
});
$("#date_end").on("change", function() {
console.log($(this).val());
var date_end = $(this).val();
var date_start = $("[name='date_start']").val();
var date_array = [date_start, date_end];
table.search(date_array, "schedule_date");
});
});
</script>
{% endblock %}

View file

@ -111,10 +111,18 @@
field: 'plate_number', field: 'plate_number',
title: 'Plate #' title: 'Plate #'
}, },
{
field: 'car_model',
title: 'Car Model'
},
{ {
field: 'customer_name', field: 'customer_name',
title: 'Customer' title: 'Customer'
}, },
{
field: 'service_type',
title: 'Service Type',
},
{ {
field: 'delivery_address', field: 'delivery_address',
title: 'Area' title: 'Area'
@ -127,6 +135,14 @@
field: 'date_schedule', field: 'date_schedule',
title: 'Scheduled Date' title: 'Scheduled Date'
}, },
{
field: 'rider_name',
title: 'Rider'
},
{
field: 'rider_plate_number',
title: 'Rider Plate #'
},
{ {
field: 'status', field: 'status',
title: 'Status' title: 'Status'

View file

@ -47,6 +47,9 @@
<form id="row-form" class="m-form m-form--fit m-form--label-align-right" method="post" action="{{ submit_url }}"> <form id="row-form" class="m-form m-form--fit m-form--label-align-right" method="post" action="{{ submit_url }}">
<input type="hidden" id="invoice-change" name="invoice_change" value="0"> <input type="hidden" id="invoice-change" name="invoice_change" value="0">
<input type="hidden" id="cid" name="cid" value="0"> <input type="hidden" id="cid" name="cid" value="0">
{% if mode in ['update-assigning', 'update-processing', 'update-reassign-hub', 'update-reassign-rider', 'update-all', 'open_edit'] %}
<input type="hidden" id="cid" name="cid" value="{{ obj.getCustomer.getID }}">
{% endif %}
<div class="m-portlet__body"> <div class="m-portlet__body">
{% if ftags.vehicle_dropdown %} {% if ftags.vehicle_dropdown %}

View file

@ -135,7 +135,7 @@
sortable: false, sortable: false,
overflow: 'visible', overflow: 'visible',
template: function (row, index, datatable) { template: function (row, index, datatable) {
var actions = '<a href="' + row.meta.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" title="View / Edit"><i class="la la-edit"></i></a>' + '<a href="' + row.meta.onestep_edit_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" title="One Step Edit"><i class="la la-edit"></i></a>'; var actions = '<a href="' + row.meta.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" title="View / Edit"><i class="la la-edit"></i></a>';
return actions; return actions;
}, },

View file

@ -148,9 +148,6 @@
{% if is_granted('jo_open.edit') %} {% if is_granted('jo_open.edit') %}
actions += '<a href="' + row.meta.edit_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-reassign-hub" title="Edit"><i class="fa fa-file"></i></a>'; actions += '<a href="' + row.meta.edit_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-reassign-hub" title="Edit"><i class="fa fa-file"></i></a>';
{% endif %} {% endif %}
{% if is_granted('jo_onestep.edit') %}
actions += '<a href="' + row.meta.onestep_edit_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-reassign-hub" title="One Step Edit"><i class="fa fa-file"></i></a>';
{% endif %}
return actions; return actions;
}, },

View file

@ -180,6 +180,16 @@
<td>{{ jo.getDeliveryAddress|default('') }}</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 %}<span class="m-badge m-badge--success m-badge--wide">Active</span>{% endif %}</td>
<td> <td>
<a href="{{ url('rider_priority_up_jo', {'id': obj.getID, 'jo_id': jo.getID}) }}" class="btn m-btn m-btn--icon">
<span>
<i class="fa fa-angle-up"></i>
</span>
</a>
<a href="{{ url('rider_priority_down_jo', {'id': obj.getID, 'jo_id': jo.getID}) }}" class="btn m-btn m-btn--icon">
<span>
<i class="fa fa-angle-down"></i>
</span>
</a>
{% if jo.getID != active_jo_id %} {% if jo.getID != active_jo_id %}
<!-- TODO: make this submit via ajax post --> <!-- 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"> <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">