Add fulfillment job order list and form #15

This commit is contained in:
Ramon Gutierrez 2018-02-19 23:28:50 +08:00
parent 61a5a988cc
commit db2904f4de
6 changed files with 414 additions and 86 deletions

View file

@ -189,6 +189,8 @@ access_keys:
label: Processing label: Processing
- id: jo_assign.list - id: jo_assign.list
label: Assigning label: Assigning
- id: jo_fulfill.list
label: Fulfillment
- id: support - id: support
label: Customer Support Access label: Customer Support Access

View file

@ -93,6 +93,10 @@ main_menu:
acl: jo_assign.list acl: jo_assign.list
label: Assigning label: Assigning
parent: joborder parent: joborder
- id: jo_fulfill
acl: jo_fulfill.list
label: Fulfillment
parent: joborder
- id: support - id: support
acl: support.menu acl: support.menu

View file

@ -58,3 +58,25 @@ jo_gen_invoice:
path: /job-order/generate-invoice path: /job-order/generate-invoice
controller: App\Controller\JobOrderController::generateInvoice controller: App\Controller\JobOrderController::generateInvoice
methods: [POST] methods: [POST]
jo_fulfill:
path: /job-order/fulfillment
controller: App\Controller\JobOrderController::listFulfillment
methods: [GET]
jo_fulfill_rows:
path: /job-order/fulfillment-rows
controller: App\Controller\JobOrderController::getRows
methods: [POST]
defaults:
tier: "fulfill"
jo_fulfill_form:
path: /job-order/fulfillment/{id}
controller: App\Controller\JobOrderController::fulfillmentForm
methods: [GET]
jo_fulfill_submit:
path: /job-order/fulfillment/{id}
controller: App\Controller\JobOrderController::fulfillmentSubmit
methods: [POST]

View file

@ -194,6 +194,16 @@ class JobOrderController extends BaseController
$edit_route = 'jo_assign_form'; $edit_route = 'jo_assign_form';
$jo_status = JOStatus::RIDER_ASSIGN; $jo_status = JOStatus::RIDER_ASSIGN;
break; break;
case 'fulfill':
$tier_key = 'jo_fulfill';
$tier_name = 'Fullfillment';
$rows_route = 'jo_fulfill_rows';
$edit_route = 'jo_fulfill_form';
$jo_status = [
JOStatus::ASSIGNED,
JOStatus::IN_PROGRESS
];
break;
default: default:
$exception = $this->createAccessDeniedException('No access.'); $exception = $this->createAccessDeniedException('No access.');
throw $exception; throw $exception;
@ -221,6 +231,15 @@ class JobOrderController extends BaseController
return $this->render('job-order/list.assigning.html.twig', $params); return $this->render('job-order/list.assigning.html.twig', $params);
} }
public function listFulfillment()
{
$params = $this->initParameters('jo_fulfill');
$params['table_refresh_rate'] = $this->container->getParameter('job_order_refresh_interval');
return $this->render('job-order/list.fulfillment.html.twig', $params);
}
public function listRows($tier) public function listRows($tier)
{ {
// check which job order tier is being called for and confirm access // check which job order tier is being called for and confirm access
@ -597,37 +616,6 @@ class JobOrderController extends BaseController
$params['discount_apply'] = DiscountApply::getCollection(); $params['discount_apply'] = DiscountApply::getCollection();
$params['trade_in_types'] = TradeInType::getCollection(); $params['trade_in_types'] = TradeInType::getCollection();
// get closest hubs
$hubs = $map_tools->getClosestHubs($obj->getCoordinates(), 10, date("H:i:s"));
$params['hubs'] = [];
// format duration and distance into friendly time
foreach ($hubs as $hub) {
// duration
$seconds = $hub['duration'];
if (!empty($seconds) && $seconds > 0) {
$hours = floor($seconds / 3600);
$minutes = ceil(($seconds / 60) % 60);
$hub['duration'] = ($hours > 0 ? number_format($hours) . " hr" . ($hours > 1 ? "s" : '') . ($minutes > 0 ? ", " : '') : '') . ($minutes > 0 ? number_format($minutes) . " min" . ($minutes > 1 ? "s" : '') : '');
} else {
$hub['duration'] = false;
}
// distance
$meters = $hub['distance'];
if (!empty($meters) && $meters > 0) {
$hub['distance'] = round($meters / 1000) . " km";
} else {
$hub['distance'] = false;
}
$params['hubs'][] = $hub;
}
$params['obj'] = $obj; $params['obj'] = $obj;
$params['submit_url'] = $this->generateUrl('jo_assign_submit', ['id' => $obj->getID()]); $params['submit_url'] = $this->generateUrl('jo_assign_submit', ['id' => $obj->getID()]);
$params['return_url'] = $this->generateUrl('jo_assign'); $params['return_url'] = $this->generateUrl('jo_assign');
@ -715,19 +703,155 @@ class JobOrderController extends BaseController
} }
public function fulfillmentForm(MapTools $map_tools, $id)
{
$this->denyAccessUnlessGranted('jo_assign.list', null, 'No access.');
$em = $this->getDoctrine()->getManager();
$params = $this->initParameters('jo_assign');
$params['mode'] = 'update-fulfillment';
// get row data
$obj = $em->getRepository(JobOrder::class)->find($id);
// make sure this row exists
if (empty($obj))
{
throw $this->createNotFoundException('The job order does not exist');
}
// check status
if (!in_array($obj->getStatus(), [JOStatus::ASSIGNED, JOStatus::IN_PROGRESS]))
{
throw $this->createNotFoundException('The job order does not have a fulfillment status');
}
// check if hub is assigned to current user
$user_hubs = $this->getUser()->getHubs();
if (!in_array($obj->getHub()->getID(), $user_hubs))
{
throw $this->createNotFoundException('The job order is not on a hub assigned to this user');
}
// get parent associations
$params['bmfgs'] = $em->getRepository(BatteryManufacturer::class)->findAll();
$params['customers'] = $em->getRepository(Customer::class)->findAll();
$params['service_types'] = ServiceType::getCollection();
$params['warranty_classes'] = WarrantyClass::getCollection();
$params['statuses'] = JOStatus::getCollection();
$params['promos'] = $em->getRepository(Promo::class)->findAll();
$params['discount_apply'] = DiscountApply::getCollection();
$params['trade_in_types'] = TradeInType::getCollection();
$params['obj'] = $obj;
$params['submit_url'] = $this->generateUrl('jo_fulfill_submit', ['id' => $obj->getID()]);
$params['return_url'] = $this->generateUrl('jo_fulfill');
// response
return $this->render('job-order/form.html.twig', $params);
}
public function fulfillmentSubmit(Request $req, ValidatorInterface $validator, $id)
{
$this->denyAccessUnlessGranted('jo_assign.list', null, 'No access.');
// initialize error list
$error_array = [];
// get object data
$em = $this->getDoctrine()->getManager();
$obj = $em->getRepository(JobOrder::class)->find($id);
// make sure this object exists
if (empty($obj))
throw $this->createNotFoundException('The item does not exist');
// check if lat and lng are provided
if (empty($req->request->get('coord_lng')) || empty($req->request->get('coord_lat'))) {
$error_array['coordinates'] = 'No map coordinates provided. Please click on a location on the map.';
}
if (empty($error_array)) {
// coordinates
$point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat'));
// set and save values
$obj->setDateSchedule(DateTime::createFromFormat("d M Y h:i A", $req->request->get('date_schedule_date') . " " . $req->request->get('date_schedule_time')))
->setCoordinates($point)
->setAdvanceOrder($req->request->get('flag_advance') ?? false)
->setServiceType($req->request->get('service_type'))
->setWarrantyClass($req->request->get('warranty_class'))
->setSource('web')
->setStatus(JOStatus::FULFILLED)
->setDeliveryInstructions($req->request->get('delivery_instructions'))
->setAgentNotes($req->request->get('agent_notes'))
->setDeliveryAddress($req->request->get('delivery_address'));
// validate
$errors = $validator->validate($obj);
// add errors to list
foreach ($errors as $error) {
$error_array[$error->getPropertyPath()] = $error->getMessage();
}
}
// check if any errors were found
if (!empty($error_array)) {
// return validation failure response
return $this->json([
'success' => false,
'errors' => $error_array
], 422);
}
// validated! save the entity
$em->flush();
// return successful response
return $this->json([
'success' => 'Changes have been saved!'
]);
}
// TODO: re-enable search, figure out how to group the orWhere filters into one, so can execute that plus the pending filter // TODO: re-enable search, figure out how to group the orWhere filters into one, so can execute that plus the pending filter
// check if datatable filter is present and append to query // check if datatable filter is present and append to query
protected function setQueryFilters($datatable, &$query, $qb, $hubs, $tier, $status) protected function setQueryFilters($datatable, &$query, $qb, $hubs, $tier, $status)
{ {
switch ($tier)
{
case 'fulfill':
$query->where('q.status IN (:statuses)')
->andWhere('q.hub IN (:hubs)')
->setParameter('statuses', $status, Connection::PARAM_STR_ARRAY)
->setParameter('hubs', $hubs, Connection::PARAM_STR_ARRAY);
break;
case 'assign':
$query->where('q.status = :status')
->andWhere('q.hub IN (:hubs)')
->setParameter('status', $status)
->setParameter('hubs', $hubs, Connection::PARAM_STR_ARRAY);
break;
default:
$query->where('q.status = :status') $query->where('q.status = :status')
->setParameter('status', $status); ->setParameter('status', $status);
// on assigning, filter by assigned hub
if ($tier == 'assign')
{
$query->andWhere('q.hub IN (:hubs)')
->setParameter('hubs', $hubs, Connection::PARAM_STR_ARRAY);
} }
// get only pending rows // get only pending rows

View file

@ -425,7 +425,7 @@
<div id="hub_map" style="height:600px;"></div> <div id="hub_map" style="height:600px;"></div>
{% endif %} {% endif %}
{% if mode == 'update-assigning' %} {% if mode in ['update-assigning', 'update-fulfillment'] %}
<div class="m-form__seperator m-form__seperator--dashed"></div> <div class="m-form__seperator m-form__seperator--dashed"></div>
{% if obj.getHub %} {% if obj.getHub %}
<div class="m-form__section"> <div class="m-form__section">
@ -469,7 +469,10 @@
</div> </div>
</div> </div>
{% endif %} {% endif %}
<div class="m-form__seperator m-form__seperator--dashed"></div> <div class="m-form__seperator m-form__seperator--dashed"></div>
{% if mode == 'update-assigning' %}
<div class="m-form__section m-form__section--last"> <div class="m-form__section m-form__section--last">
<div class="m-form__heading"> <div class="m-form__heading">
<h3 class="m-form__heading-title"> <h3 class="m-form__heading-title">
@ -521,12 +524,53 @@
</div> </div>
{% endif %} {% endif %}
{% if mode == 'update-fulfillment' %}
<div class="m-form__section m-form__section--last">
<div class="m-form__heading">
<h3 class="m-form__heading-title">
Rider Details
</h3>
</div>
<div class="form-group m-form__group row">
<div class="col-lg-6">
<label data-field="rider_first_name">First Name</label>
<input type="text" name="rider_first_name" id="rider-first-name" class="form-control m-input" value="{{ obj.getRider.getFirstName }}" disabled>
<div class="form-control-feedback hide" data-field="rider_first_name"></div>
</div>
<div class="col-lg-6">
<label data-field="rider_last_name">Last Name</label>
<input type="text" name="rider_last_name" id="rider-last-name" class="form-control m-input" value="{{obj.getRider.getLastName }}" disabled>
<div class="form-control-feedback hide" data-field="rider_last_name"></div>
</div>
</div>
<div class="form-group m-form__group row">
<div class="col-lg-6">
<label data-field="rider_contact_no">Contact Number</label>
<input type="text" name="rider_contact_no" id="rider-contact-no" class="form-control m-input" value="{{ obj.getRider.getContactNumber }}" disabled>
<div class="form-control-feedback hide" data-field="rider_contact_no"></div>
</div>
<div class="col-lg-6">
<label data-field="rider_plate_number">Plate Number</label>
<input type="text" name="rider_plate_number" id="rider-plate-number" class="form-control m-input" value="{{obj.getRider.getPlateNumber }}" disabled>
<div class="form-control-feedback hide" data-field="rider_plate_number"></div>
</div>
</div>
<div class="form-group m-form__group row">
<div class="col-lg-12">
<label data-field="rider_picture">Picture</label>
<div class="portrait-box" style="background-image: url('{{ obj.getRider.getImageFile ? '/uploads/' ~ obj.getRider.getImageFile : '/assets/images/user.gif' }}');"></div>
</div>
</div>
</div>
{% endif %}
{% endif %}
</div> </div>
<div class="m-portlet__foot m-portlet__foot--fit"> <div class="m-portlet__foot m-portlet__foot--fit">
<div class="m-form__actions m-form__actions--solid m-form__actions--right"> <div class="m-form__actions m-form__actions--solid m-form__actions--right">
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
<button type="submit" class="btn btn-success">Submit</button> <button type="submit" class="btn btn-success">{{ mode == 'update-fulfillment' ? 'Fulfill' : 'Submit' }}</button>
{% if mode != 'create' %} {% if mode != 'create' %}
<a href="{{ return_url }}" class="btn btn-secondary">Cancel</a> <a href="{{ return_url }}" class="btn btn-secondary">Cancel</a>
{% endif %} {% endif %}

View file

@ -0,0 +1,132 @@
{% 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 (Fulfillment)
</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>
</div>
</div>
</div>
<!--begin: Datatable -->
<div id="data-rows"></div>
<!--end: Datatable -->
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
$(function() {
var options = {
data: {
type: 'remote',
source: {
read: {
url: '{{ url('jo_fulfill_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: 'delivery_address',
title: 'Customer Area'
},
{
field: 'service_type',
title: 'Type of Transaction'
},
{
field: 'date_schedule',
title: 'Scheduled Date'
},
{
field: 'status',
title: 'Status'
},
{
field: 'processor',
title: 'Processor'
},
{
field: 'assignor',
title: 'Assignor'
},
{
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 / Edit"><i class="la la-edit"></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 }});
});
</script>
{% endblock %}