diff --git a/config/routes/job_order.yaml b/config/routes/job_order.yaml index b9e44c16..1ba355a2 100644 --- a/config/routes/job_order.yaml +++ b/config/routes/job_order.yaml @@ -24,6 +24,6 @@ jo_proc_form: methods: [GET] jo_proc_submit: - path: /job-order/processing + path: /job-order/processing/{id} controller: App\Controller\JobOrderController::processingSubmit methods: [POST] diff --git a/public/assets/css/style.css b/public/assets/css/style.css index c6ec12a6..c3219708 100644 --- a/public/assets/css/style.css +++ b/public/assets/css/style.css @@ -110,6 +110,10 @@ span.has-danger, text-align: center; } +.table-clickable tr { + cursor: pointer; +} + @media (min-width: 995px) { .modal-lg { max-width: 1024px; diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 17d438f7..69c40415 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -12,6 +12,8 @@ use App\Entity\CustomerVehicle; use App\Entity\Outlet; use App\Entity\Rider; +use App\Service\MapTools; + use Doctrine\ORM\Query; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -235,6 +237,82 @@ class JobOrderController extends BaseController ]); } + public function processingForm(MapTools $map_tools, $id) + { + $this->denyAccessUnlessGranted('jo_proc.list', null, 'No access.'); + + $params = $this->initParameters('jo_proc'); + $params['mode'] = 'update'; + + // get row data + $em = $this->getDoctrine()->getManager(); + $obj = $em->getRepository(JobOrder::class)->find($id); + + // make sure this row exists + if (empty($obj)) + throw $this->createNotFoundException('The item does not exist'); + + // get parent associations + $params['bmfgs'] = $em->getRepository(BatteryManufacturer::class)->findAll(); + $params['customers'] = $em->getRepository(Customer::class)->findAll(); + $params['outlet'] = $em->getRepository(Outlet::class)->findAll(); + $params['rider'] = $em->getRepository(Rider::class)->findAll(); + $params['service_types'] = ServiceType::getCollection(); + $params['statuses'] = JOStatus::getCollection(); + + // get closest outlets + $outlets = $map_tools->getClosestOutlets($obj->getCoordinates(), 10); + + $params['outlets'] = []; + + // format seconds into friendly time + foreach ($outlets as $outlet) { + $seconds = $outlet['duration']; + + if (!empty($seconds) && $seconds > 0) { + $hours = floor($seconds / 3600); + $minutes = floor(($seconds / 60) % 60); + $seconds = $seconds % 60; + + $outlet['duration'] = $hours . "hrs, " . $minutes . " mins, " . $seconds . " secs"; + } else { + $outlet['duration'] = false; + } + + $params['outlets'][] = $outlet; + } + + $params['obj'] = $obj; + + // response + return $this->render('job-order/form.html.twig', $params); + } + + public function processingSubmit(Request $req, ValidatorInterface $validator, $id) + { + $this->denyAccessUnlessGranted('jo_in.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'); + + error_log(print_r($req->request->all(), true)); + + // TODO: validation and saving of updated job order + + // 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 // check if datatable filter is present and append to query diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index 7659cce5..4607ee85 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -22,23 +22,32 @@

- Incoming + {% if mode == 'update' %} + Processing + {{ obj.getID() }} + {% else %} + Incoming + {% endif %}

-
+
-
-
-
- - - + + {% if mode == 'create' %} +
+
+
+ + + +
-
-
+ {% endif %} + +

Customer Details @@ -228,7 +237,7 @@

-
+

Invoice @@ -305,6 +314,60 @@

+ + {% if mode == 'update' %} +
+
+
+

+ Nearest Outlets +

+
+
+
+ + + + + + + + + + + + + + + + + + + + + {% for outlet in outlets %} + + + + + + + + + + + + + {% endfor %} + +
NameAddressNumbersOpeningClosingSales CountSales AmountService CountDistanceTravel Time
+ No items to display. +
{{ outlet.outlet.getName }}{{ outlet.outlet.getAddress }}{{ outlet.outlet.getContactNumbers }}{{ outlet.outlet.getTimeOpen|date("g:i A") }}{{ outlet.outlet.getTimeClose|date("g:i A") }}0.000.000{{ outlet.distance ? outlet.distance|number_format ~ ' m' : '-' }}{{ outlet.duration ? outlet.duration : '-' }}
+
+
+
+ {% endif %} +
@@ -404,6 +467,11 @@ $(function() { // add invoice items to data fields['invoice_items'] = invoiceItems; + {% if mode == 'update' %} + // add selected outlet to data + fields['outlet'] = selectedOutlet; + {% endif %} + e.preventDefault(); $.ajax({ @@ -418,7 +486,7 @@ $(function() { text: 'Your changes have been saved!', type: 'success', onClose: function() { - window.location.href = "{{ url('jo_in') }}"; + window.location.href = "{{ mode == 'create' ? url('jo_in') : url('jo_proc') }}"; } }); }).fail(function(response) { @@ -719,6 +787,33 @@ $(function() { tbody.find('.placeholder-row').removeClass('hide'); } }); + + {% if mode == 'update' %} + + var selectedOutlet = false; + + $("#outlets-table tbody tr").click(function() { + var id = $(this).data('id'); + + if (id != selectedOutlet) { + // highlight this row, set outlet value + $("#outlets-table") + .find('.m-table__row--primary') + .removeClass('.m-table__row--primary'); + + $(this).addClass('m-table__row--primary'); + + // set value + selectedOutlet = id; + } else { + // unhighlight this row + $(this).removeClass('m-table__row--primary'); + + // remove id value + selectedOutlet = false; + } + }); + {% endif %} }); {% endblock %}