From 2fb24e4e132f8d57a2a440d7ea1f1d08378e4ce7 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 13 Feb 2020 02:41:32 +0000 Subject: [PATCH 01/67] Add validation for mobile phone number. #339 --- .../CustomerHandler/CMBCustomerHandler.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Service/CustomerHandler/CMBCustomerHandler.php b/src/Service/CustomerHandler/CMBCustomerHandler.php index d8107514..20dd7734 100644 --- a/src/Service/CustomerHandler/CMBCustomerHandler.php +++ b/src/Service/CustomerHandler/CMBCustomerHandler.php @@ -320,7 +320,11 @@ class CMBCustomerHandler implements CustomerHandlerInterface $nerror_array = []; $verror_array = []; - // TODO: validate mobile numbers + if (!($this->validateMobileNumber($req->request->get('phone_mobile')))) + { + $error_array['phone_mobile'] = 'Invalid mobile phone number.' + } + // TODO: validate vehicles // custom validation for vehicles @@ -685,6 +689,18 @@ class CMBCustomerHandler implements CustomerHandlerInterface } } + protected function validateMobileNumber($mobile_number) + { + if (empty($mobile_number)) + return true; + + // parse string in case multiple numbers are entered separated by + // either a space, a slash, a backslash, a pipe or a comma + $delimiters = [',', ' ', '\\', '/', '|']; + $clean_mobile = str_replace($delimiters, $delimiters[0], $mobile_number); + $mnumber_array = explode($delimiters[0], $clean_mobile); + } + // check if datatable filter is present and append to query protected function setQueryFilters($datatable, &$query) { if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { From 62edf0f12ceeca60cc20e22003ba5cf0efa7bb6c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 13 Feb 2020 04:04:28 +0000 Subject: [PATCH 02/67] Tweak validation for mobile phone number. #339 --- src/Service/CustomerHandler/CMBCustomerHandler.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Service/CustomerHandler/CMBCustomerHandler.php b/src/Service/CustomerHandler/CMBCustomerHandler.php index 20dd7734..f66a8e30 100644 --- a/src/Service/CustomerHandler/CMBCustomerHandler.php +++ b/src/Service/CustomerHandler/CMBCustomerHandler.php @@ -321,9 +321,7 @@ class CMBCustomerHandler implements CustomerHandlerInterface $verror_array = []; if (!($this->validateMobileNumber($req->request->get('phone_mobile')))) - { - $error_array['phone_mobile'] = 'Invalid mobile phone number.' - } + $error_array['phone_mobile'] = 'Invalid mobile phone number.'; // TODO: validate vehicles @@ -693,12 +691,12 @@ class CMBCustomerHandler implements CustomerHandlerInterface { if (empty($mobile_number)) return true; + if (strlen($mobile_number) != 9) + return false; + if(preg_match('/^\d+$/',$mobile_number)) + return true; - // parse string in case multiple numbers are entered separated by - // either a space, a slash, a backslash, a pipe or a comma - $delimiters = [',', ' ', '\\', '/', '|']; - $clean_mobile = str_replace($delimiters, $delimiters[0], $mobile_number); - $mnumber_array = explode($delimiters[0], $clean_mobile); + return false; } // check if datatable filter is present and append to query From 60203cc7b5cd6ab14b28909023fe66da7fd2ef00 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 13 Feb 2020 05:11:01 +0000 Subject: [PATCH 03/67] Add routes for walk-in form. #340 --- config/acl.yaml | 4 ++++ config/menu.yaml | 4 ++++ config/routes/job_order.yaml | 20 ++++++++++++++++++++ src/Ramcar/TransactionOrigin.php | 3 +++ 4 files changed, 31 insertions(+) diff --git a/config/acl.yaml b/config/acl.yaml index 90b2f06d..21f09775 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -246,6 +246,10 @@ access_keys: label: One-step Process - id: jo_onestep.edit label: One-step Process Edit + - id: jo_walkin.form + label: Walk-in + - id: jo_walkin.edit + label: Walk-in Edit - id: support label: Customer Support Access diff --git a/config/menu.yaml b/config/menu.yaml index a64dd8b4..1f90e314 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -102,6 +102,10 @@ main_menu: acl: jo_onestep.form label: One-step Process parent: joborder + - id: jo_walkin_form + acl: jo_walkin.form + label: Walk-in + parent: joborder - id: jo_in acl: jo_in.list label: Incoming diff --git a/config/routes/job_order.yaml b/config/routes/job_order.yaml index bfd41df9..d3ce6834 100644 --- a/config/routes/job_order.yaml +++ b/config/routes/job_order.yaml @@ -206,3 +206,23 @@ jo_tracker: controller: App\Controller\JobOrderController::tracker methods: [GET] +jo_walkin_form: + path: /job-order/walk-in + controller: App\Controller\JobOrderController::walkinForm + methods: [GET] + +jo_walkin_submit: + path: /job-order/walk-in + controller: App\Controller\JobOrderController::walkinSubmit + methods: [POST] + +jo_walkin_edit_form: + path: /job-order/walk-in/{id} + controller: App\Controller\JobOrderController::walkinEditForm + methods: [GET] + +jo_walkin_edit_submit: + path: /job-order/walk-in/{id} + controller: App\Controller\JobOrderController::walkinEditSubmit + methods: [POST] + diff --git a/src/Ramcar/TransactionOrigin.php b/src/Ramcar/TransactionOrigin.php index baf412f1..c4d69ad2 100644 --- a/src/Ramcar/TransactionOrigin.php +++ b/src/Ramcar/TransactionOrigin.php @@ -9,12 +9,15 @@ class TransactionOrigin extends NameValue const FACEBOOK = 'facebook'; const VIP = 'vip'; const MOBILE_APP = 'mobile_app'; + const WALK_IN = 'walk_in'; + // TODO: for now, resq also gets the walk-in option const COLLECTION = [ 'call' => 'Hotline', 'online' => 'Online', 'facebook' => 'Facebook', 'vip' => 'VIP', 'mobile_app' => 'Mobile App', + 'walk_in' => 'Walk-in', ]; } From 7e116d8d3eb11d19a226e6ed6ec2a1e32f7e181f Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 13 Feb 2020 07:32:18 +0000 Subject: [PATCH 04/67] Add function to load walk-in form. #340 --- src/Controller/JobOrderController.php | 22 + .../JobOrderHandler/CMBJobOrderHandler.php | 16 + templates/job-order/cmb.form.walkin.html.twig | 1087 +++++++++++++++++ 3 files changed, 1125 insertions(+) create mode 100644 templates/job-order/cmb.form.walkin.html.twig diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index f70d5484..02b5fcce 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -12,6 +12,7 @@ use App\Entity\Battery; use App\Entity\JobOrder; use App\Entity\VehicleManufacturer; use App\Entity\Vehicle; +use App\Entity\Hub; use App\Service\InvoiceGeneratorInterface; use App\Service\JobOrderHandlerInterface; @@ -962,4 +963,25 @@ class JobOrderController extends Controller return $this->render('job-order/tracker.html.twig', $params); } + + /** + * @Menu(selected="jo_walkin_form") + */ + public function walkinForm(EntityManagerInterface $em, JobOrderHandlerInterface $jo_handler) + { + $this->denyAccessUnlessGranted('jo_walkin.form', null, 'No access.'); + + $params = $jo_handler->initializeWalkinForm(); + $params['submit_url'] = $this->generateUrl('jo_walkin_submit'); + $params['return_url'] = $this->generateUrl('jo_walkin_form'); + $params['vmfgs'] = $em->getRepository(VehicleManufacturer::class)->findAll(); + $params['vmakes'] = $em->getRepository(Vehicle::class)->findAll(); + $params['hubs'] = $em->getRepository(Hub::class)->findAll(); + + $template = $params['template']; + + // response + return $this->render($template, $params); + } + } diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 40f428ee..60856414 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -2345,6 +2345,21 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface return false; } + public function initializeWalkinForm() + { + $params['obj'] = new JobOrder(); + $params['mode'] = 'onestep'; + + $this->fillDropdownParameters($params); + $this->fillFormTags($params); + + // get template to display + $params['template'] = $this->getTwigTemplate('jo_walkin'); + + // return params + return $params; + } + protected function fillDropdownParameters(&$params) { $em = $this->em; @@ -2450,6 +2465,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $this->template_hash['jo_list_all'] = 'job-order/list.all.html.twig'; $this->template_hash['jo_onestep'] = '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'] = 'job-order/cmb.form.walkin.html.twig'; } protected function checkTier($tier) diff --git a/templates/job-order/cmb.form.walkin.html.twig b/templates/job-order/cmb.form.walkin.html.twig new file mode 100644 index 00000000..f3c8d224 --- /dev/null +++ b/templates/job-order/cmb.form.walkin.html.twig @@ -0,0 +1,1087 @@ +{% extends 'base.html.twig' %} + +{% block body %} + + + +
+ +
+
+
+
+
+
+ + + +

+ Walk-in Job Order +

+
+
+
+
+ + +
+ {%if ftags.vehicle_dropdown %} +
+
+
+ + + +
+ +
+
+
+
+
+ + + +
+
+
+ {% else %} + + {% endif %} + {% if obj.getReferenceJO %} +
+
+
+ + + +
+
+
+ {% endif %} + +
+
+

+ Customer Details +

+ + + +
+
+
+ + + +
+
+ + + +
+
+
+
+ +
+ {% trans %}country_code_prefix{% endtrans %} + + +
+
+
+ +
+ {% trans %}country_code_prefix{% endtrans %} + + +
+
+
+
+
+ +
+ {% trans %}country_code_prefix{% endtrans %} + + +
+
+
+ +
+ {% trans %}country_code_prefix{% endtrans %} + + +
+
+
+
+
+ + + +
+
+
+
+
+

+ Vehicle Details +

+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+
+
+ + + +
+ +
+
+
+
+

+ Battery Details +

+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+
+
+
+
+

+ Transaction Details +

+ + + +
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+
+
+ + + +
+
+ +
+ + + + +
+ +
+
+ +
+ + + + +
+ +
+
+
+
+ + + +
+
+ + + +
+
+
+
+
+ + + +
+
+
+ + +
+
+
+
+ + + +
+
+
+
+
+
+
+
+

+ Hubs +

+
+
+
+ + + +
+ + + + + + + + + + + + {% for hub in hubs %} + + + + + + + {% endfor %} + +
HubBranchContact NumbersDistance in KMAction
{{ hub.getName }}{{ hub.getBranch }}{{ hub.getContactNumbers }}
+
+
+
+
+
+
+
+

+ Invoice +

+
+
+
+ + + +
+
+ + + +
+
+
+
+ + {% if ftags.invoice_edit %} + + + {% else %} + + {% endif %} +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + + + + + + + + + + {% if not obj.getInvoice or (obj.getInvoice and obj.getInvoice.getItems|length == 0) %} + + + + {% else %} + {% for item in obj.getInvoice.getItems %} + + + + + + + {% endfor %} + {% endif %} + +
ItemQuantityUnit PriceAmount
+ No items to display. +
{{ item.getTitle }}{{ item.getQuantity|number_format }}{{ item.getPrice|number_format(2) }}{{ (item.getPrice * item.getQuantity)|number_format(2) }}
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + + +
+
+
+
+
+
+
+
+ + {% if ftags.set_map_coordinate and is_granted('joborder.cancel') and not obj.isCancelled %} + Cancel Job Order + {% endif %} + Back +
+
+
+
+ +
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} + From d07adc606b6a4e84e36bdbc522090d383c951344 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 13 Feb 2020 08:53:57 +0000 Subject: [PATCH 05/67] Add saving of walkin form. #340 --- src/Controller/JobOrderController.php | 46 ++- .../JobOrderHandler/CMBJobOrderHandler.php | 283 +++++++++++++++++- templates/job-order/cmb.form.walkin.html.twig | 5 - 3 files changed, 327 insertions(+), 7 deletions(-) diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 02b5fcce..08b6dbe0 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -881,7 +881,6 @@ class JobOrderController extends Controller return $this->json([ 'success' => 'Changes have been saved!' ]); - } /** @@ -984,4 +983,49 @@ class JobOrderController extends Controller return $this->render($template, $params); } + public function walkinSubmit(Request $req, JobOrderHandlerInterface $jo_handler) + { + $this->denyAccessUnlessGranted('jo_walkin.form', null, 'No access.'); + + // initialize error list + $error_array = []; + $id = -1; + $error_array = $jo_handler->processWalkinJobOrder($req, $id); + + // check if any errors were found + if (!empty($error_array)) { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + + /** + * @Menu(selected="jo_walkin_edit_form") + */ + public function walkinEditForm($id, EntityManagerInterface $em, JobOrderHandlerInterface $jo_handler) + { + $this->denyAccessUnlessGranted('jo_walkin.edit', null, 'No access.'); + + $params = $jo_handler->initializeWalkinEditForm($id); + $params['submit_url'] = $this->generateUrl('jo_walkin_edit_submit', ['id' => $id]); + $params['return_url'] = $this->generateUrl('jo_open'); + $params['vmfgs'] = $em->getRepository(VehicleManufacturer::class)->findAll(); + $params['vmakes'] = $em->getRepository(Vehicle::class)->findAll(); + $params['hubs'] = $em->getRepository(Hub::class)->findAll(); + + $template = $params['template']; + + // response + return $this->render($template, $params); + } + + } diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 60856414..0e1a4e27 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -2348,7 +2348,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface public function initializeWalkinForm() { $params['obj'] = new JobOrder(); - $params['mode'] = 'onestep'; + $params['mode'] = 'walk-in'; $this->fillDropdownParameters($params); $this->fillFormTags($params); @@ -2360,6 +2360,274 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface return $params; } + public function processWalkinJobOrder(Request $req, $id) + { + // initialize error list + $error_array = []; + + $em = $this->em; + + $jo = $em->getRepository(JobOrder::class)->find($id); + if (empty($jo)) + { + // new job order + $jo = new JobOrder(); + } + + // check if new customer + if ($req->request->get('new_customer')) + { + if (empty($req->request->get('customer_customer_notes'))) + { + $error_array['customer_customer_notes'] = 'Customer notes cannot be null.'; + } + + $new_cust = new Customer(); + $new_cv = new CustomerVehicle(); + + // find the vehicle using vid + $new_vehicle = $em->getRepository(Vehicle::class)->find($req->request->get('vid')); + if (empty($new_vehicle)) + { + $error_array['cv_mfg'] = 'Invalid manufacturer specified.'; + $error_array['cv_make'] = 'Invalid make specified.'; + } + else + { + + $new_cust->setLastName($req->request->get('customer_last_name')) + ->setFirstName($req->request->get('customer_first_name')) + ->setPhoneMobile($req->request->get('customer_phone_mobile')) + ->setPhoneLandline($req->request->get('customer_phone_landline')) + ->setPhoneOffice($req->request->get('customer_phone_office')) + ->setPhoneFax($req->request->get('customer_phone_fax')) + ->setCustomerNotes($req->request->get('customer_customer_notes')); + + $new_cv->setCustomer($new_cust) + ->setVehicle($new_vehicle) + ->setPlateNumber($req->request->get('cv_plate')) + ->setModelYear($req->request->get('cv_year')) + ->setColor('') + ->setStatusCondition('') + ->setFuelType('') + ->setActive() + ->setWarrantyCode($req->request->get('warranty_code')); + + if (($req->request->get('service_type')) == CMBServiceType::BATTERY_REPLACEMENT_NEW) + { + $new_cv->setHasMotoliteBattery(true); + } + else + { + $new_cv->setHasMotoliteBattery(false); + } + + // link JO to new customer + $jo->setCustomer($new_cust); + $jo->setCustomerVehicle($new_cv); + + $em->persist($new_cust); + $em->persist($new_cv); + } + } + else + { + // check if customer vehicle is set + if (empty($req->request->get('customer_vehicle'))) { + $error_array['customer_vehicle'] = 'No vehicle selected.'; + } else + { + // get customer vehicle + $cust_vehicle = $em->getRepository(CustomerVehicle::class)->find($req->request->get('customer_vehicle')); + + if (empty($cust_vehicle)) { + $error_array['customer_vehicle'] = 'Invalid vehicle specified.'; + } + else + { + $jo->setCustomerVehicle($cust_vehicle); + $jo->setCustomer($cust_vehicle->getCustomer()); + + // save serial into cv + $cust_vehicle->setWarrantyCode($req->request->get('warranty_code')); + + $em->persist($cust_vehicle); + } + } + } + + // check if hub is selected + if (empty($req->request->get('hub_id'))) + $error_array['hub'] = 'No hub selected.'; + else + { + // get hub + $hub = $em->getRepository(Hub::class)->find($req->request->get('hub_id')); + + if (empty($hub)) + $error_array['hub'] = 'Invalid hub specified.'; + + // get hub coordinates + $hub_coordinates = $hub->getCoordinates(); + } + + if (empty($error_array)) + { + // get current user + $user = $this->security->getUser(); + + $stype = $req->request->get('service_type'); + + // set and save values + $jo->setDateSchedule(DateTime::createFromFormat("d M Y h:i A", $req->request->get('date_schedule_date') . " " . $req->request->get('date_schedule_time'))) + ->setAdvanceOrder($req->request->get('flag_advance') ?? false) + ->setServiceType($stype) + ->setWarrantyClass($req->request->get('warranty_class')) + ->setSource($req->request->get('source')) + ->setStatus(JOStatus::FULFILLED) + ->setTier1Notes($req->request->get('tier1_notes')) + ->setTier2Notes($req->request->get('tier2_notes')) + ->setORName($req->request->get('or_name')) + ->setPromoDetail($req->request->get('promo_detail')) + ->setModeOfPayment($req->request->get('mode_of_payment')) + ->setLandmark($req->request->get('landmark')) + ->setDeliveryAddress('Walk-in') + ->setLandmark('Walk-in') + ->setCoordinates($hub_coordinates) + ->setHub($hub); + + // check if user is null, meaning call to create came from API + if ($user != null) + { + $jo->setCreatedBy($user); + } + + // check if reference JO is set and validate + if (!empty($req->request->get('ref_jo'))) { + // get reference JO + $ref_jo = $em->getRepository(JobOrder::class)->find($req->request->get('ref_jo')); + + if (empty($ref_jo)) { + $error_array['ref_jo'] = 'Invalid reference job order specified.'; + } else { + $jo->setReferenceJO($ref_jo); + } + } + + // call service to generate job order and invoice + $invoice_items = $req->request->get('invoice_items', []); + $promo_id = $req->request->get('invoice_promo'); + $invoice_change = $req->request->get('invoice_change', 0); + + // check if invoice changed + if ($invoice_change) + { + $this->ic->generateInvoiceCriteria($jo, $promo_id, $invoice_items, $error_array); + } + + // validate + $errors = $this->validator->validate($jo); + + // add errors to list + foreach ($errors as $error) { + $error_array[$error->getPropertyPath()] = $error->getMessage(); + } + + // check if errors are found + if (empty($error_array)) + { + // validated, no error. save the job order + $em->persist($jo); + + // save to customer vehicle battery record + $this->updateVehicleBattery($jo); + + // save serial to customer vehicle + $cust_vehicle = $jo->getCustomerVehicle(); + $cust_vehicle->setWarrantyCode($req->request->get('warranty_code')); + + $em->persist($cust_vehicle); + $em->flush(); + + // create the warranty if new battery only + if ($this->checkIfNewBattery($jo)) + { + $serial = $req->request->get('warranty_code') ; + $warranty_class = $jo->getWarrantyClass(); + $first_name = $jo->getCustomer()->getFirstName(); + $last_name = $jo->getCustomer()->getLastName(); + $mobile_number = $jo->getCustomer()->getPhoneMobile(); + + // check if date fulfilled is null + if ($jo->getDateFulfill() == null) + $date_purchase = $jo->getDateCreate(); + else + $date_purchase = $jo->getDateFulfill(); + + // validate plate number + // $plate_number = $this->wh->cleanPlateNumber($jo->getCustomerVehicle()->getPlateNumber()); + $plate_number = Warranty::cleanPlateNumber($jo->getCustomerVehicle()->getPlateNumber()); + if ($plate_number != false) + { + $batt_list = array(); + $invoice = $jo->getInvoice(); + if (!empty($invoice)) + { + // get battery + $invoice_items = $invoice->getItems(); + foreach ($invoice_items as $item) + { + $battery = $item->getBattery(); + if ($battery != null) + { + $batt_list[] = $item->getBattery(); + } + } + } + + $this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class); + } + } + + // the event + $event = new JOEvent(); + $event->setDateHappen(new DateTime()) + ->setTypeID(JOEventType::CREATE) + ->setJobOrder($jo); + + if ($user != null) + { + $event->setUser($user); + } + + $em->persist($event); + $em->flush(); + } + } + + return $error_array; + } + + public function initializeWalkinEditForm($id) + { + $em = $this->em; + $obj = $em->getRepository(JobOrder::class)->find($id); + + $params['obj'] = $obj; + $params['mode'] = 'walk-in-edit'; + $params['cvid'] = $obj->getCustomerVehicle()->getID(); + $params['vid'] = $obj->getCustomerVehicle()->getVehicle()->getID(); + + $this->fillDropdownParameters($params); + $this->fillFormTags($params); + + // get template to display + $params['template'] = $this->getTwigTemplate('jo_walkin_edit'); + + // return params + return $params; + } + protected function fillDropdownParameters(&$params) { $em = $this->em; @@ -2437,6 +2705,18 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $params['ftags']['invoice_edit'] = true; $params['ftags']['preset_vehicle'] = true; break; + case 'walk-in': + $params['ftags']['vehicle_dropdown'] = true; + $params['ftags']['set_map_coordinate'] = false; + $params['ftags']['invoice_edit'] = true; + $params['ftags']['ticket_table'] = false; + $params['ftags']['cancel_button'] = false; + break; + case 'walk-in-edit': + $params['ftags']['invoice_edit'] = true; + $params['ftags']['preset_vehicle'] = true; + break; + } } @@ -2466,6 +2746,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $this->template_hash['jo_onestep'] = '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'] = 'job-order/cmb.form.walkin.html.twig'; + $this->template_hash['jo_walkin_edit'] = 'job-order/cmb.form.walkin.html.twig'; } protected function checkTier($tier) diff --git a/templates/job-order/cmb.form.walkin.html.twig b/templates/job-order/cmb.form.walkin.html.twig index f3c8d224..1e3d8f9b 100644 --- a/templates/job-order/cmb.form.walkin.html.twig +++ b/templates/job-order/cmb.form.walkin.html.twig @@ -321,11 +321,6 @@
-
-
- - -
From 034ae108e0031fdc92626ff4de2cb96bddaa2e04 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 14 Feb 2020 01:47:08 +0000 Subject: [PATCH 06/67] Fix saving issue for JOEvent. #340 --- .../JobOrderHandler/CMBJobOrderHandler.php | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 0e1a4e27..44714f44 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -2539,6 +2539,19 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface // validated, no error. save the job order $em->persist($jo); + // the event + $event = new JOEvent(); + $event->setDateHappen(new DateTime()) + ->setTypeID(JOEventType::CREATE) + ->setJobOrder($jo); + + if ($user != null) + { + $event->setUser($user); + } + + $em->persist($event); + // save to customer vehicle battery record $this->updateVehicleBattery($jo); @@ -2547,7 +2560,6 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $cust_vehicle->setWarrantyCode($req->request->get('warranty_code')); $em->persist($cust_vehicle); - $em->flush(); // create the warranty if new battery only if ($this->checkIfNewBattery($jo)) @@ -2589,18 +2601,6 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface } } - // the event - $event = new JOEvent(); - $event->setDateHappen(new DateTime()) - ->setTypeID(JOEventType::CREATE) - ->setJobOrder($jo); - - if ($user != null) - { - $event->setUser($user); - } - - $em->persist($event); $em->flush(); } } From bea5d72d13d80d4ea1fd6f19dd528abeb9950eef Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 14 Feb 2020 03:07:42 +0000 Subject: [PATCH 07/67] Modify the function names for walkin. #340 --- config/routes/job_order.yaml | 8 ++++---- src/Controller/JobOrderController.php | 29 ++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/config/routes/job_order.yaml b/config/routes/job_order.yaml index d3ce6834..d5cd8dfc 100644 --- a/config/routes/job_order.yaml +++ b/config/routes/job_order.yaml @@ -208,21 +208,21 @@ jo_tracker: jo_walkin_form: path: /job-order/walk-in - controller: App\Controller\JobOrderController::walkinForm + controller: App\Controller\JobOrderController::walkInForm methods: [GET] jo_walkin_submit: path: /job-order/walk-in - controller: App\Controller\JobOrderController::walkinSubmit + controller: App\Controller\JobOrderController::walkInSubmit methods: [POST] jo_walkin_edit_form: path: /job-order/walk-in/{id} - controller: App\Controller\JobOrderController::walkinEditForm + controller: App\Controller\JobOrderController::walkInEditForm methods: [GET] jo_walkin_edit_submit: path: /job-order/walk-in/{id} - controller: App\Controller\JobOrderController::walkinEditSubmit + controller: App\Controller\JobOrderController::walkInEditSubmit methods: [POST] diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 08b6dbe0..15d44e1d 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -966,7 +966,7 @@ class JobOrderController extends Controller /** * @Menu(selected="jo_walkin_form") */ - public function walkinForm(EntityManagerInterface $em, JobOrderHandlerInterface $jo_handler) + public function walkInForm(EntityManagerInterface $em, JobOrderHandlerInterface $jo_handler) { $this->denyAccessUnlessGranted('jo_walkin.form', null, 'No access.'); @@ -983,7 +983,7 @@ class JobOrderController extends Controller return $this->render($template, $params); } - public function walkinSubmit(Request $req, JobOrderHandlerInterface $jo_handler) + public function walkInSubmit(Request $req, JobOrderHandlerInterface $jo_handler) { $this->denyAccessUnlessGranted('jo_walkin.form', null, 'No access.'); @@ -1010,7 +1010,7 @@ class JobOrderController extends Controller /** * @Menu(selected="jo_walkin_edit_form") */ - public function walkinEditForm($id, EntityManagerInterface $em, JobOrderHandlerInterface $jo_handler) + public function walkInEditForm($id, EntityManagerInterface $em, JobOrderHandlerInterface $jo_handler) { $this->denyAccessUnlessGranted('jo_walkin.edit', null, 'No access.'); @@ -1027,5 +1027,28 @@ class JobOrderController extends Controller return $this->render($template, $params); } + public function walkInEditSubmit(Request $req, JobOrderHandlerInterface $jo_handler) + { + $this->denyAccessUnlessGranted('jo_walkin.edit', null, 'No access.'); + + $error_array = []; + $error_array = $jo_handler->processOneStepJobOrder($req, $id); + + // check if any errors were found + if (!empty($error_array)) { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } + + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + } From ac91960bd7140b4c1aba729e70f21cfa7b6deac9 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 14 Feb 2020 03:38:37 +0000 Subject: [PATCH 08/67] Add mobile phone validation for JO when new customer is created. #340 --- .../CustomerHandler/CMBCustomerHandler.php | 2 +- .../JobOrderHandler/CMBJobOrderHandler.php | 39 ++++++++++++++----- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/Service/CustomerHandler/CMBCustomerHandler.php b/src/Service/CustomerHandler/CMBCustomerHandler.php index f66a8e30..371f674b 100644 --- a/src/Service/CustomerHandler/CMBCustomerHandler.php +++ b/src/Service/CustomerHandler/CMBCustomerHandler.php @@ -687,7 +687,7 @@ class CMBCustomerHandler implements CustomerHandlerInterface } } - protected function validateMobileNumber($mobile_number) + public function validateMobileNumber($mobile_number) { if (empty($mobile_number)) return true; diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 44714f44..a2727fea 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -42,6 +42,7 @@ use App\Ramcar\JORejectionReason; use App\Service\InvoiceGeneratorInterface; use App\Service\JobOrderHandlerInterface; use App\Service\RiderAssignmentHandlerInterface; +use App\Service\CustomerHandlerInterface; use App\Service\WarrantyHandler; use App\Service\MQTTClient; use App\Service\APNSClient; @@ -66,13 +67,15 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface protected $rah; protected $country_code; protected $wh; + protected $cust_handler; protected $template_hash; public function __construct(Security $security, EntityManagerInterface $em, InvoiceGeneratorInterface $ic, ValidatorInterface $validator, TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah, - string $country_code, WarrantyHandler $wh) + string $country_code, WarrantyHandler $wh, + CustomerHandlerInterface $cust_handler) { $this->em = $em; $this->ic = $ic; @@ -82,6 +85,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $this->rah = $rah; $this->country_code = $country_code; $this->wh = $wh; + $this->cust_handler = $cust_handler; $this->loadTemplates(); } @@ -416,8 +420,10 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $error_array['customer_customer_notes'] = 'Customer notes cannot be null.'; } - $new_cust = new Customer(); - $new_cv = new CustomerVehicle(); + // validate mobile phone + $valid_mobile = $this->cust_handler->validateMobileNumber($req->request->get('customer_phone_mobile')); + if (!($valid_mobile)) + $error_array['customer_phone_mobile'] = 'Invalid mobile phone number.'; // find the vehicle using vid $new_vehicle = $em->getRepository(Vehicle::class)->find($req->request->get('vid')); @@ -426,8 +432,10 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $error_array['cv_mfg'] = 'Invalid manufacturer specified.'; $error_array['cv_make'] = 'Invalid make specified.'; } - else + if (empty($error_array)) { + $new_cust = new Customer(); + $new_cv = new CustomerVehicle(); $new_cust->setLastName($req->request->get('customer_last_name')) ->setFirstName($req->request->get('customer_first_name')) @@ -918,7 +926,11 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface // create the warranty if new battery only if ($this->checkIfNewBattery($obj)) { - $serial = $req->request->get('warranty_code') ; + if (empty($req->request->get('warranty_code'))) + $serial = null; + else + $serial = $req->request->get('warranty_code'); + $warranty_class = $obj->getWarrantyClass(); $first_name = $obj->getCustomer()->getFirstName(); $last_name = $obj->getCustomer()->getLastName(); @@ -2382,8 +2394,10 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $error_array['customer_customer_notes'] = 'Customer notes cannot be null.'; } - $new_cust = new Customer(); - $new_cv = new CustomerVehicle(); + // validate mobile phone + $valid_mobile = $this->cust_handler->validateMobileNumber($req->request->get('customer_phone_mobile')); + if (!($valid_mobile)) + $error_array['customer_phone_mobile'] = 'Invalid mobile phone number.'; // find the vehicle using vid $new_vehicle = $em->getRepository(Vehicle::class)->find($req->request->get('vid')); @@ -2392,8 +2406,11 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $error_array['cv_mfg'] = 'Invalid manufacturer specified.'; $error_array['cv_make'] = 'Invalid make specified.'; } - else + + if (empty($error_array)) { + $new_cust = new Customer(); + $new_cv = new CustomerVehicle(); $new_cust->setLastName($req->request->get('customer_last_name')) ->setFirstName($req->request->get('customer_first_name')) @@ -2564,7 +2581,11 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface // create the warranty if new battery only if ($this->checkIfNewBattery($jo)) { - $serial = $req->request->get('warranty_code') ; + if (empty($req->request->get('warranty_code'))) + $serial = null; + else + $serial = $req->request->get('warranty_code'); + $warranty_class = $jo->getWarrantyClass(); $first_name = $jo->getCustomer()->getFirstName(); $last_name = $jo->getCustomer()->getLastName(); From d439a411a8180b0f3d30636d79c21cd34e84148e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 14 Feb 2020 09:40:08 +0000 Subject: [PATCH 09/67] Change computation of discount for CMB. #343 --- src/Controller/JobOrderController.php | 2 +- src/Entity/Invoice.php | 3 +- src/Ramcar/InvoiceCriteria.php | 14 +++++ .../InvoiceGenerator/CMBInvoiceGenerator.php | 54 +++++++------------ .../JobOrderHandler/CMBJobOrderHandler.php | 1 - .../job-order/cmb.form.onestep.html.twig | 15 ++---- 6 files changed, 40 insertions(+), 49 deletions(-) diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 15d44e1d..bdd0b2a0 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -736,7 +736,7 @@ class JobOrderController extends Controller */ // TODO: this snippet should be in the invoice generator - $error = $ic->invoicePromo($criteria, $promo_id); + $error = $ic->validateDiscount($criteria, $promo_id); if (!$error) $error = $ic->invoiceBatteries($criteria, $items); diff --git a/src/Entity/Invoice.php b/src/Entity/Invoice.php index 305c7d84..2353b925 100644 --- a/src/Entity/Invoice.php +++ b/src/Entity/Invoice.php @@ -59,7 +59,8 @@ class Invoice */ protected $items; - // total discount (amount, not %) + // total discount (amount, not %) for resq + // for cmb, discount is the percentage /** * @ORM\Column(type="decimal", precision=9, scale=2) */ diff --git a/src/Ramcar/InvoiceCriteria.php b/src/Ramcar/InvoiceCriteria.php index 5ea5e623..a1fb2568 100644 --- a/src/Ramcar/InvoiceCriteria.php +++ b/src/Ramcar/InvoiceCriteria.php @@ -12,6 +12,8 @@ class InvoiceCriteria protected $promos; protected $cv; protected $flag_coolant; + // for discount and other info + protected $meta; // entries are battery and trade-in combos protected $entries; @@ -23,6 +25,7 @@ class InvoiceCriteria $this->entries = []; $this->cv = null; $this->flag_coolant = false; + $this->meta = []; } public function setServiceType($stype) @@ -125,4 +128,15 @@ class InvoiceCriteria { return $this->flag_coolant; } + + public function addMeta($id, $value) + { + $this->meta[$id] = $value; + return $this; + } + + public function getMeta() + { + return $this->meta; + } } diff --git a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php index f25348a4..fa13b752 100644 --- a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php @@ -17,7 +17,6 @@ use App\Ramcar\FuelType; use App\Entity\Invoice; use App\Entity\InvoiceItem; use App\Entity\Battery; -use App\Entity\Promo; use App\Entity\User; use App\Service\InvoiceGeneratorInterface; @@ -106,10 +105,6 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface // break; } - // TODO: check if any promo is applied - // apply discounts - $promos = $criteria->getPromos(); - // get current user $user = $this->security->getUser(); if ($user != null) @@ -140,7 +135,8 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface $criteria->setServiceType($jo->getServiceType()) ->setCustomerVehicle($jo->getCustomerVehicle()); - $ierror = $this->invoicePromo($criteria, $promo_id); + $discount = $promo_id; + $ierror = $this->validateDiscount($criteria, $discount); if (!$ierror && !empty($invoice_items)) { @@ -224,8 +220,9 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface return 0; } - public function invoicePromo(InvoiceCriteria $criteria, $promo_id) + public function validateDiscount(InvoiceCriteria $criteria, $discount) { + // return error if there's a problem, false otherwise // check service type $stype = $criteria->getServiceType(); @@ -233,18 +230,17 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface return null; - if (empty($promo_id)) + // check if discount is blank or 0 + if ((empty($discount)) || ($discount == 0)) { return false; } - // check if this is a valid promo - $promo = $this->em->getRepository(Promo::class)->find($promo_id); + // check if discount is greater than 50 + if ($discount > 50) + return 'Invalid discount specified'; - if (empty($promo)) - return 'Invalid promo specified.'; - - $criteria->addPromo($promo); + $criteria->addMeta('discount', $discount); return false; } @@ -389,33 +385,23 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface protected function processDiscount(&$total, InvoiceCriteria $criteria, Invoice $invoice) { - $promos = $criteria->getPromos(); - if (count($promos) < 1) + $rate = 0; + $meta = $criteria->getMeta(); + if (isset($meta['discount'])) + $rate = $meta['discount']; + else return; - // NOTE: only get first promo because only one is applicable anyway - $promo = $promos[0]; - - $rate = $promo->getDiscountRate(); - $apply_to = $promo->getDiscountApply(); - - switch ($apply_to) - { - case DiscountApply::SRP: - $discount = round($total['sell_price'] * $rate, 2); - break; - case DiscountApply::OPL: - // $discount = round($total['sell_price'] * 0.6 / 0.7 * $rate, 2); - $discount = round($total['sell_price'] * (1 - 1.5 / 0.7 * $rate), 2); - break; - } + // compute discount + $rate = $rate * 0.01; + $discount = round($total['sell_price'] * $rate, 2); // if discount is higher than 0, display in invoice if ($discount > 0) { $item = new InvoiceItem(); $item->setInvoice($invoice) - ->setTitle('Promo discount') + ->setTitle('Discount') ->setQuantity(1) ->setPrice(-1 * $discount); $invoice->addItem($item); @@ -425,7 +411,7 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface $total['total_price'] -= $discount; // process - $invoice->setPromo($promo); + $invoice->setDiscount($discount); } protected function processJumpstart(&$total, $invoice) diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index a2727fea..ee83970f 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -2670,7 +2670,6 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $params['warranty_classes'] = CMBWarrantyClass::getCollection(); $params['modes_of_payment'] = CMBModeOfPayment::getCollection(); $params['statuses'] = JOStatus::getCollection(); - $params['discount_apply'] = DiscountApply::getCollection(); $params['trade_in_types'] = CMBTradeInType::getCollection(); $params['facilitated_types'] = FacilitatedType::getCollection(); $params['facilitated_hubs'] = $fac_hubs; diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index e0714676..b91c0a2c 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -500,22 +500,13 @@
{% if ftags.invoice_edit %} - + {% else %} - + {% endif %}
-
- - -
-
+
From a15b45173c660f0d33a10490e18d0068c44ad50e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 17 Feb 2020 01:02:41 +0000 Subject: [PATCH 10/67] Fix discount computation. #343 --- src/Entity/Invoice.php | 3 +-- src/Service/InvoiceGenerator/CMBInvoiceGenerator.php | 8 ++------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Entity/Invoice.php b/src/Entity/Invoice.php index 2353b925..305c7d84 100644 --- a/src/Entity/Invoice.php +++ b/src/Entity/Invoice.php @@ -59,8 +59,7 @@ class Invoice */ protected $items; - // total discount (amount, not %) for resq - // for cmb, discount is the percentage + // total discount (amount, not %) /** * @ORM\Column(type="decimal", precision=9, scale=2) */ diff --git a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php index fa13b752..f1563d63 100644 --- a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php @@ -385,17 +385,13 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface protected function processDiscount(&$total, InvoiceCriteria $criteria, Invoice $invoice) { - $rate = 0; + $discount = 0; $meta = $criteria->getMeta(); if (isset($meta['discount'])) - $rate = $meta['discount']; + $discount = $meta['discount']; else return; - // compute discount - $rate = $rate * 0.01; - $discount = round($total['sell_price'] * $rate, 2); - // if discount is higher than 0, display in invoice if ($discount > 0) { From 984b0428d0538d4e1a35a76a72fe9549ac0d26a3 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 17 Feb 2020 06:19:09 +0000 Subject: [PATCH 11/67] Fix for cmb to retain battery in invoice when editing JO. #343 --- src/Controller/JobOrderController.php | 4 ++- src/Entity/JobOrder.php | 19 ++++++++++++ src/Ramcar/InvoiceCriteria.php | 13 ++++---- .../InvoiceGenerator/CMBInvoiceGenerator.php | 14 +++------ .../InvoiceGenerator/ResqInvoiceGenerator.php | 1 + .../JobOrderHandler/CMBJobOrderHandler.php | 21 ++++++++++++- .../job-order/cmb.form.onestep.html.twig | 15 ++++++++++ templates/job-order/cmb.form.walkin.html.twig | 30 +++++++++++-------- 8 files changed, 86 insertions(+), 31 deletions(-) diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index bdd0b2a0..d50471fe 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -605,7 +605,7 @@ class JobOrderController extends Controller * @Menu(selected="jo_all") */ public function allForm($id, JobOrderHandlerInterface $jo_handler, - GISManagerInterface $gis) + GISManagerInterface $gis, EntityManagerInterface $em) { $this->denyAccessUnlessGranted('jo_all.list', null, 'No access.'); @@ -618,6 +618,8 @@ class JobOrderController extends Controller throw $this->createNotFoundException($e->getMessage()); } + $params['vmfgs'] = $em->getRepository(VehicleManufacturer::class)->findAll(); + $params['vmakes'] = $em->getRepository(Vehicle::class)->findAll(); $params['return_url'] = $this->generateUrl('jo_all'); $params['submit_url'] = ''; $params['map_js_file'] = $gis->getJSJOFile(); diff --git a/src/Entity/JobOrder.php b/src/Entity/JobOrder.php index 36834cc1..08a1f15a 100644 --- a/src/Entity/JobOrder.php +++ b/src/Entity/JobOrder.php @@ -280,6 +280,12 @@ class JobOrder */ protected $hub_rejections; + // meta + /** + * @ORM\Column(type="json") + */ + protected $meta; + public function __construct() { $this->date_create = new DateTime(); @@ -297,6 +303,8 @@ class JobOrder $this->trade_in_type = null; $this->flag_rider_rating = false; $this->flag_coolant = false; + + $this->meta = []; } public function getID() @@ -802,4 +810,15 @@ class JobOrder { return $this->hub_rejections; } + + public function addMeta($id, $value) + { + $this->meta[$id] = $value; + return $this; + } + + public function getMeta($id) + { + return $this->meta[$id]; + } } diff --git a/src/Ramcar/InvoiceCriteria.php b/src/Ramcar/InvoiceCriteria.php index a1fb2568..49290e33 100644 --- a/src/Ramcar/InvoiceCriteria.php +++ b/src/Ramcar/InvoiceCriteria.php @@ -12,8 +12,7 @@ class InvoiceCriteria protected $promos; protected $cv; protected $flag_coolant; - // for discount and other info - protected $meta; + protected $discount; // entries are battery and trade-in combos protected $entries; @@ -25,7 +24,7 @@ class InvoiceCriteria $this->entries = []; $this->cv = null; $this->flag_coolant = false; - $this->meta = []; + $this->discount = 0; } public function setServiceType($stype) @@ -129,14 +128,14 @@ class InvoiceCriteria return $this->flag_coolant; } - public function addMeta($id, $value) + public function setDiscount($discount) { - $this->meta[$id] = $value; + $this->discount = $discount; return $this; } - public function getMeta() + public function getDiscount() { - return $this->meta; + return $this->discount; } } diff --git a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php index f1563d63..73f4524e 100644 --- a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php @@ -229,18 +229,17 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface if ($stype != CMBServiceType::BATTERY_REPLACEMENT_NEW) return null; - // check if discount is blank or 0 if ((empty($discount)) || ($discount == 0)) { return false; } - // check if discount is greater than 50 - if ($discount > 50) + // check if discount is greater than 50 or negative number + if (($discount > 50) || ($discount < 0)) return 'Invalid discount specified'; - $criteria->addMeta('discount', $discount); + $criteria->setDiscount($discount); return false; } @@ -385,12 +384,7 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface protected function processDiscount(&$total, InvoiceCriteria $criteria, Invoice $invoice) { - $discount = 0; - $meta = $criteria->getMeta(); - if (isset($meta['discount'])) - $discount = $meta['discount']; - else - return; + $discount = $criteria->getDiscount(); // if discount is higher than 0, display in invoice if ($discount > 0) diff --git a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php index c5e9c81c..f9aad46a 100644 --- a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php @@ -18,6 +18,7 @@ use App\Entity\Invoice; use App\Entity\InvoiceItem; use App\Entity\User; use App\Entity\Battery; +use App\Entity\Promo; use App\Service\InvoiceGeneratorInterface; diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index ee83970f..cfdab814 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -522,6 +522,13 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface } } + // get discount and set to meta + $discount = $req->request->get('invoice_promo'); + + // check if discount is greater than 50 or negative number + if (($discount > 50) || ($discount < 0)) + $error_array['invoice_promo'] = 'Invalid discount specified'; + if (empty($error_array)) { // get current user @@ -551,7 +558,9 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface ->setHub($hub) ->setRider($rider); - // check if user is null, meaning call to create came from API + $jo->addMeta('discount', $discount); + + // check if user is null, meaning call to create came from API if ($user != null) { $jo->setCreatedBy($user); @@ -2488,6 +2497,13 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $hub_coordinates = $hub->getCoordinates(); } + // get discount and set to meta + $discount = $req->request->get('invoice_promo'); + + // check if discount is greater than 50 or negative number + if (($discount > 50) || ($discount < 0)) + $error_array['invoice_promo'] = 'Invalid discount specified'; + if (empty($error_array)) { // get current user @@ -2513,6 +2529,8 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface ->setCoordinates($hub_coordinates) ->setHub($hub); + $jo->addMeta('discount', $discount); + // check if user is null, meaning call to create came from API if ($user != null) { @@ -2670,6 +2688,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $params['warranty_classes'] = CMBWarrantyClass::getCollection(); $params['modes_of_payment'] = CMBModeOfPayment::getCollection(); $params['statuses'] = JOStatus::getCollection(); + $params['discount_apply'] = DiscountApply::getCollection(); $params['trade_in_types'] = CMBTradeInType::getCollection(); $params['facilitated_types'] = FacilitatedType::getCollection(); $params['facilitated_hubs'] = $fac_hubs; diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index b91c0a2c..34fe7af4 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -1268,6 +1268,21 @@ $(function() { var invoiceItems = []; + // populate invoiceItems if editing so that we don't lose the battery + {% if mode in ['open-edit', 'onestep-edit', 'walk-in-edit'] %} + {% if (obj.getInvoice and obj.getInvoice.getItems|length > 0) %} + {% for item in obj.getInvoice.getItems %} + {% if item.getBattery() %} + invoiceItems.push({ + battery: {{ item.getBattery().getID() }}, + quantity: {{ item.getQuantity() }}, + trade_in: {{ obj.getInvoice().getTradeIn }}, + }); + {% endif %} + {% endfor %} + {% endif %} + {% endif %} + // add to invoice $("#btn-add-to-invoice").click(function() { var bmfg = $("#invoice-bmfg").val(); diff --git a/templates/job-order/cmb.form.walkin.html.twig b/templates/job-order/cmb.form.walkin.html.twig index 1e3d8f9b..8f764956 100644 --- a/templates/job-order/cmb.form.walkin.html.twig +++ b/templates/job-order/cmb.form.walkin.html.twig @@ -395,22 +395,13 @@
{% if ftags.invoice_edit %} - + {% else %} - + {% endif %}
-
- - -
-
+
@@ -892,6 +883,21 @@ var vdata = false; var invoiceItems = []; + // populate invoiceItems if editing so that we don't lose the battery + {% if mode in ['open-edit', 'onestep-edit', 'walk-in-edit'] %} + {% if (obj.getInvoice and obj.getInvoice.getItems|length > 0) %} + {% for item in obj.getInvoice.getItems %} + {% if item.getBattery() %} + invoiceItems.push({ + battery: {{ item.getBattery().getID() }}, + quantity: {{ item.getQuantity() }}, + trade_in: {{ obj.getInvoice().getTradeIn }}, + }); + {% endif %} + {% endfor %} + {% endif %} + {% endif %} + // add to invoice $("#btn-add-to-invoice").click(function() { var bmfg = $("#invoice-bmfg").val(); From 6c11650b25fdd70cb1a05230c047849787d32cb6 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 17 Feb 2020 07:20:37 +0000 Subject: [PATCH 12/67] Add service charge entity. #341 --- src/Entity/ServiceCharge.php | 64 ++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/Entity/ServiceCharge.php diff --git a/src/Entity/ServiceCharge.php b/src/Entity/ServiceCharge.php new file mode 100644 index 00000000..8ba224cf --- /dev/null +++ b/src/Entity/ServiceCharge.php @@ -0,0 +1,64 @@ +amount = 0; + } + + public function getID() + { + return $this->id; + } + + public function setName($name) + { + $this->name = $name; + return $this; + } + + public function getName() + { + return $this->name; + } + + public function setAmount($amount) + { + $this->amount = $amount; + return $this; + } + + public function getAmount() + { + return $this->amount; + } +} From 147e949aff3df08658b1b2e58f2d9424a39f8f2c Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Mon, 17 Feb 2020 15:25:12 +0800 Subject: [PATCH 13/67] Add initial UI for service charge support in one step job order form #341 --- .../job-order/cmb.form.onestep.html.twig | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 34fe7af4..08d20ee3 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -477,6 +477,38 @@
+
+
+
+

+ Service Charges +

+
+
+
+ +
+
+
+
+
+ + +
+
+
+ +
+
+ +
+
+
+
@@ -1607,6 +1639,41 @@ $(function() { }); }); }); + + // service charge add + $('#btn-sc-add').click(function(e) { + console.log('adding service charge'); + // add dropdown before the button + var html = '
'; + html += '
'; + html += '
'; + html += ''; + html += ''; + html += '
'; + html += '
'; + html += '
'; + html += ''; + html += '
'; + html += '
'; + html += ''; + html += '
'; + html += '
'; + + $('#sc-section').append(html); + return false; + }); + + // service charge remove + $('body').on('click', '.btn-sc-remove', function(e) { + console.log('removing service charge'); + + $(this).closest('.row').remove(); + return false; + }); }); {% endblock %} From 11bf116e683bc7b2eb93f89c9cb1c84fe845abe7 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 17 Feb 2020 07:44:04 +0000 Subject: [PATCH 14/67] Add sql file to populate service charge table. #341 --- initial_sql/sql_insert_service_charge_data.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 initial_sql/sql_insert_service_charge_data.sql diff --git a/initial_sql/sql_insert_service_charge_data.sql b/initial_sql/sql_insert_service_charge_data.sql new file mode 100644 index 00000000..bab3fdf5 --- /dev/null +++ b/initial_sql/sql_insert_service_charge_data.sql @@ -0,0 +1 @@ +INSERT INTO `service_charge` VALUES(1,'Bangi',20),(2,'Banting',30),(3,'Bdr Saujana Utama',20),(4,'Bdr Seri Coalfields',30),(5,'Bdr Baru Bangi',20),(6,'Bdr Saujana Putra',20),(7,'Bukit Beruntung',30),(8,'Cyberjaya',20),(9,'Dengkil',30),(10,'Hulu Langat',20),(11,'Jenjarom',30),(12,'Klia',30),(13,'Meru',20),(14,'Port Klang',20),(15,'Pulau Indah',30),(16,'Puncak Alam',20),(17,'Putrajaya',20),(18,'Rawang',30),(19,'Salak Tinggi',30),(20,'Semenyih',20),(21,'Sepang',30),(22,'Serendah',30),(23,'Sungai Buloh',20),(24,'Teluk Panglima Garang',30),(25,'Uitm Puncak Alam',20),(26,'12am - 7am',10),(27,'Out of define Klg Valley',20),(28,'Airport',35),(29,'Jump start',50),(30,'Product warranty service charge - existing BA customer',20),(31,'Product warranty service charge - non BA customer',40); From 34e90912973bb215c99761d6ac2bd49aafccc22f Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Mon, 17 Feb 2020 16:12:35 +0800 Subject: [PATCH 15/67] Fix dropdown for service charges in one-step JO form #341 --- .../JobOrderHandler/CMBJobOrderHandler.php | 2 ++ .../job-order/cmb.form.onestep.html.twig | 29 ++++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index cfdab814..a7712042 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -26,6 +26,7 @@ use App\Entity\Rider; use App\Entity\JORejection; use App\Entity\Warranty; use App\Entity\Customer; +use App\Entity\ServiceCharge; use App\Ramcar\InvoiceCriteria; use App\Ramcar\CMBServiceType; @@ -2674,6 +2675,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface // db loaded $params['bmfgs'] = $em->getRepository(BatteryManufacturer::class)->findAll(); $params['promos'] = $em->getRepository(Promo::class)->findAll(); + $params['service_charges'] = $em->getRepository(ServiceCharge::class)->findAll(); // list of hubs $hubs = $em->getRepository(Hub::class)->findBy([], ['name' => 'ASC']); diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 08d20ee3..6662facf 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -489,24 +489,26 @@
+ +
@@ -1647,16 +1649,15 @@ $(function() { var html = '
'; html += '
'; html += '
'; - html += ''; + {% for key, sc in service_charges %} + html += ''; {% endfor %} html += ''; - html += ''; html += '
'; html += '
'; html += '
'; - html += ''; + html += ''; html += '
'; html += '
'; html += ''; @@ -1664,6 +1665,9 @@ $(function() { html += '
'; $('#sc-section').append(html); + + // trigger change in select + $('#sc-section').find('.sc-select').last().change(); return false; }); @@ -1674,6 +1678,11 @@ $(function() { $(this).closest('.row').remove(); return false; }); + + $('body').on('change', '.sc-select', function(e) { + var amount = $(this).children('option:selected').data('amount'); + $(this).closest('.row').find('.sc-amount').val(amount); + }); }); {% endblock %} From 663698f0873af944e05fcb087f5f756da3aeb76d Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 17 Feb 2020 08:12:51 +0000 Subject: [PATCH 16/67] Rename promo to discount in JO service, JO forms, and invoice generator. #341 --- .../InvoiceGenerator/CMBInvoiceGenerator.php | 3 +-- .../JobOrderHandler/CMBJobOrderHandler.php | 22 ++++++++++--------- .../job-order/cmb.form.onestep.html.twig | 18 +++++++-------- templates/job-order/cmb.form.walkin.html.twig | 20 ++++++++--------- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php index 73f4524e..cb404c6c 100644 --- a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php @@ -126,7 +126,7 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface } // generate invoice criteria - public function generateInvoiceCriteria($jo, $promo_id, $invoice_items, &$error_array) + public function generateInvoiceCriteria($jo, $discount, $invoice_items, &$error_array) { $em = $this->em; @@ -135,7 +135,6 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface $criteria->setServiceType($jo->getServiceType()) ->setCustomerVehicle($jo->getCustomerVehicle()); - $discount = $promo_id; $ierror = $this->validateDiscount($criteria, $discount); if (!$ierror && !empty($invoice_items)) diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index cfdab814..df9834a0 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -351,13 +351,13 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface // call service to generate job order and invoice $invoice_items = $req->request->get('invoice_items', []); - $promo_id = $req->request->get('invoice_promo'); + $discount = $req->request->get('invoice_discount'); $invoice_change = $req->request->get('invoice_change', 0); // check if invoice changed if ($invoice_change) { - $this->ic->generateInvoiceCriteria($jo, $promo_id, $invoice_items, $error_array); + $this->ic->generateInvoiceCriteria($jo, $discount, $invoice_items, $error_array); } // validate @@ -523,11 +523,13 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface } // get discount and set to meta - $discount = $req->request->get('invoice_promo'); + $discount = $req->request->get('invoice_discount'); // check if discount is greater than 50 or negative number if (($discount > 50) || ($discount < 0)) - $error_array['invoice_promo'] = 'Invalid discount specified'; + $error_array['invoice_discount'] = 'Invalid discount specified'; + + // get list of service charges if (empty($error_array)) { @@ -580,13 +582,13 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface // call service to generate job order and invoice $invoice_items = $req->request->get('invoice_items', []); - $promo_id = $req->request->get('invoice_promo'); + $discount = $req->request->get('invoice_discount'); $invoice_change = $req->request->get('invoice_change', 0); // check if invoice changed if ($invoice_change) { - $this->ic->generateInvoiceCriteria($jo, $promo_id, $invoice_items, $error_array); + $this->ic->generateInvoiceCriteria($jo, $discount, $invoice_items, $error_array); } // validate @@ -2498,11 +2500,11 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface } // get discount and set to meta - $discount = $req->request->get('invoice_promo'); + $discount = $req->request->get('invoice_discount'); // check if discount is greater than 50 or negative number if (($discount > 50) || ($discount < 0)) - $error_array['invoice_promo'] = 'Invalid discount specified'; + $error_array['invoice_discount'] = 'Invalid discount specified'; if (empty($error_array)) { @@ -2551,13 +2553,13 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface // call service to generate job order and invoice $invoice_items = $req->request->get('invoice_items', []); - $promo_id = $req->request->get('invoice_promo'); + $discount = $req->request->get('invoice_discount'); $invoice_change = $req->request->get('invoice_change', 0); // check if invoice changed if ($invoice_change) { - $this->ic->generateInvoiceCriteria($jo, $promo_id, $invoice_items, $error_array); + $this->ic->generateInvoiceCriteria($jo, $discount, $invoice_items, $error_array); } // validate diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 08d20ee3..0653d85a 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -530,12 +530,12 @@
- + {% if ftags.invoice_edit %} - - + + {% else %} - + {% endif %}
@@ -1354,7 +1354,7 @@ $(function() { }); // update invoice when promo is changed - $("#invoice-promo").change(function() { + $("#invoice-discount").change(function() { generateInvoice(); }); @@ -1365,7 +1365,7 @@ $(function() { // reset the invoice table $("#btn-reset-invoice").click(function() { - $("#invoice-promo").prop('selectedIndex', 0); + $("#invoice-discount").prop('selectedIndex', 0); invoiceItems = []; generateInvoice(); }); @@ -1376,7 +1376,7 @@ $(function() { }); function generateInvoice() { - var promo = $("#invoice-promo").val(); + var discount = $("#invoice-discount").val(); var table = $("#invoice-table tbody"); var stype = $("#service_type").val(); var cvid = $("#customer-vehicle").val(); @@ -1388,7 +1388,7 @@ $(function() { data: { 'stype': stype, 'items': invoiceItems, - 'promo': promo, + 'promo': discount, 'cvid': cvid } }).done(function(response) { @@ -1397,7 +1397,7 @@ $(function() { var invoice = response.invoice; // populate totals - $("#invoice-promo-discount").val(invoice.discount); + $("#invoice-discount").val(invoice.discount); $("#invoice-price").val(invoice.price); $("#invoice-trade-in").val(invoice.trade_in); $("#invoice-vat").val(invoice.vat); diff --git a/templates/job-order/cmb.form.walkin.html.twig b/templates/job-order/cmb.form.walkin.html.twig index 8f764956..1a833e63 100644 --- a/templates/job-order/cmb.form.walkin.html.twig +++ b/templates/job-order/cmb.form.walkin.html.twig @@ -393,12 +393,12 @@
- + {% if ftags.invoice_edit %} - - + + {% else %} - + {% endif %}
@@ -936,8 +936,8 @@ var vdata = false; generateInvoice(); }); - // update invoice when promo is changed - $("#invoice-promo").change(function() { + // update invoice when discount is changed + $("#invoice-discount").change(function() { generateInvoice(); }); @@ -948,7 +948,7 @@ var vdata = false; // reset the invoice table $("#btn-reset-invoice").click(function() { - $("#invoice-promo").prop('selectedIndex', 0); + $("#invoice-discount").prop('selectedIndex', 0); invoiceItems = []; generateInvoice(); }); @@ -959,7 +959,7 @@ var vdata = false; }); function generateInvoice() { - var promo = $("#invoice-promo").val(); + var discount = $("#invoice-discount").val(); var table = $("#invoice-table tbody"); var stype = $("#service_type").val(); var cvid = $("#customer-vehicle").val(); @@ -971,7 +971,7 @@ var vdata = false; data: { 'stype': stype, 'items': invoiceItems, - 'promo': promo, + 'promo': discount, 'cvid': cvid } }).done(function(response) { @@ -980,7 +980,7 @@ var vdata = false; var invoice = response.invoice; // populate totals - $("#invoice-promo-discount").val(invoice.discount); + $("#invoice-discount").val(invoice.discount); $("#invoice-price").val(invoice.price); $("#invoice-trade-in").val(invoice.trade_in); $("#invoice-vat").val(invoice.vat); From 115c207868943853a14cdccffd9569772e90a923 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 17 Feb 2020 12:21:18 +0000 Subject: [PATCH 17/67] Add sending of service charge ids to generate invoice. #341 --- .../job-order/cmb.form.onestep.html.twig | 56 +++++++++++++------ 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 1c1074e7..7d0e3f31 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -1301,6 +1301,7 @@ $(function() { }); var invoiceItems = []; + var sc_array = []; // populate invoiceItems if editing so that we don't lose the battery {% if mode in ['open-edit', 'onestep-edit', 'walk-in-edit'] %} @@ -1377,26 +1378,31 @@ $(function() { generateInvoice(); }); - function generateInvoice() { - var discount = $("#invoice-discount").val(); - var table = $("#invoice-table tbody"); + function generateInvoice() { + var discount = $("#invoice-discount").val(); + var table = $("#invoice-table tbody"); var stype = $("#service_type").val(); var cvid = $("#customer-vehicle").val(); - // generate invoice values - $.ajax({ - method: "POST", - url: "{{ url('jo_gen_invoice') }}", - data: { + $.each(sc_array, function(index){ + console.log('generateInvoice ' + this.id); + }); + + // generate invoice values + $.ajax({ + method: "POST", + url: "{{ url('jo_gen_invoice') }}", + data: { 'stype': stype, - 'items': invoiceItems, - 'promo': discount, - 'cvid': cvid - } - }).done(function(response) { + 'items': invoiceItems, + 'promo': discount, + 'cvid': cvid, + 'service_charges': sc_array, + } + }).done(function(response) { // mark as invoice changed $("#invoice-change").val(1); - var invoice = response.invoice; + var invoice = response.invoice; // populate totals $("#invoice-discount").val(invoice.discount); @@ -1649,9 +1655,9 @@ $(function() { var html = '
'; html += '
'; html += '
'; - html += ''; {% for key, sc in service_charges %} - html += ''; + html += ''; {% endfor %} html += ''; html += '
'; @@ -1666,6 +1672,9 @@ $(function() { $('#sc-section').append(html); + // clear the sc_array + sc_array.length = 0; + // trigger change in select $('#sc-section').find('.sc-select').last().change(); return false; @@ -1682,7 +1691,22 @@ $(function() { $('body').on('change', '.sc-select', function(e) { var amount = $(this).children('option:selected').data('amount'); $(this).closest('.row').find('.sc-amount').val(amount); + + // clear the sc_array + sc_array.length = 0; + + // get the service charges + $('.sc-select').each(function() { + var id = $(this).children('option:selected').val(); + sc_array.push({ + id: id, + }); + + }); + + generateInvoice(); }); + }); {% endblock %} From f3f941e0a002aee867f26619136d33d87be19304 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 17 Feb 2020 13:24:32 +0000 Subject: [PATCH 18/67] Add service charges to invoice generation. #341 --- src/Controller/JobOrderController.php | 4 ++ src/Ramcar/InvoiceCriteria.php | 15 ++++++ .../InvoiceGenerator/CMBInvoiceGenerator.php | 49 +++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index d50471fe..c06383c7 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -694,6 +694,7 @@ class JobOrderController extends Controller $items = $req->request->get('items'); $promo_id = $req->request->get('promo'); $cvid = $req->request->get('cvid'); + $service_charges = $req->request->get('service_charges'); $em = $this->getDoctrine()->getManager(); @@ -740,6 +741,9 @@ class JobOrderController extends Controller // TODO: this snippet should be in the invoice generator $error = $ic->validateDiscount($criteria, $promo_id); + // process service charges + $error = $ic->invoiceServiceCharges($criteria, $service_charges); + if (!$error) $error = $ic->invoiceBatteries($criteria, $items); diff --git a/src/Ramcar/InvoiceCriteria.php b/src/Ramcar/InvoiceCriteria.php index 49290e33..6665226d 100644 --- a/src/Ramcar/InvoiceCriteria.php +++ b/src/Ramcar/InvoiceCriteria.php @@ -5,6 +5,7 @@ namespace App\Ramcar; use App\Entity\Battery; use App\Entity\Promo; use App\Entity\CustomerVehicle; +use App\Entity\ServiceCharge; class InvoiceCriteria { @@ -13,6 +14,7 @@ class InvoiceCriteria protected $cv; protected $flag_coolant; protected $discount; + protected $service_charges; // entries are battery and trade-in combos protected $entries; @@ -25,6 +27,7 @@ class InvoiceCriteria $this->cv = null; $this->flag_coolant = false; $this->discount = 0; + $this->service_charges = []; } public function setServiceType($stype) @@ -138,4 +141,16 @@ class InvoiceCriteria { return $this->discount; } + + public function addServiceCharge(ServiceCharge $service_charge) + { + $this->service_charges[] = $service_charge; + return $this; + } + + public function getServiceCharges() + { + return $this->service_charges; + } + } diff --git a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php index cb404c6c..405dfe33 100644 --- a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php @@ -18,6 +18,7 @@ use App\Entity\Invoice; use App\Entity\InvoiceItem; use App\Entity\Battery; use App\Entity\User; +use App\Entity\ServiceCharge; use App\Service\InvoiceGeneratorInterface; @@ -105,6 +106,13 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface // break; } + // process service charges if any + $service_charges = $criteria->getServiceCharges(); + if (count($service_charges) > 0) + { + $this->processServiceCharges($total, $criteria, $invoice); + } + // get current user $user = $this->security->getUser(); if ($user != null) @@ -286,6 +294,28 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface return null; } + public function invoiceServiceCharges(InvoiceCriteria $criteria, $service_charges) + { + if (!empty($service_charges)) + { + foreach ($service_charges as $service_charge) + { + // check if valid service charge + $sc = $this->em->getRepository(ServiceCharge::class)->find($service_charge['id']); + + if (empty($sc)) + { + $error = 'Invalid service charge specified.'; + return $error; + } + + $criteria->addServiceCharge($sc); + } + } + + return null; + } + protected function processEntries(&$total, InvoiceCriteria $criteria, Invoice $invoice) { @@ -604,4 +634,23 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface $total['vat'] = $vat; } + protected function processServiceCharges(&$total, InvoiceCriteria $criteria, Invoice $invoice) + { + $service_charges = $criteria->getServiceCharges(); + + foreach ($service_charges as $service_charge) + { + $amount = $service_charge->getAmount(); + + $total['total_price'] += $amount; + // add item + $item = new InvoiceItem(); + $item->setInvoice($invoice) + ->setTitle('Service Charge - ' . $service_charge->getName()) + ->setQuantity(1) + ->setPrice($amount); + + $invoice->addItem($item); + } + } } From 0cff722c6a2b2a6c39fffcd4188e6f844f42576d Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 17 Feb 2020 14:18:19 +0000 Subject: [PATCH 19/67] Add saving of service charges to JO and Invoice Item. #341 --- .../InvoiceGenerator/CMBInvoiceGenerator.php | 14 ++++++++++++-- src/Service/JobOrderHandler/CMBJobOrderHandler.php | 6 ++++++ templates/job-order/cmb.form.onestep.html.twig | 3 +++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php index 405dfe33..dcd6946d 100644 --- a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php @@ -161,11 +161,20 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface $ierror = $this->invoiceBatteries($criteria, $invoice_items); } + // get the meta for service charges + $service_charges = $jo->getMeta('service_charges'); + if ($service_charges != null) + { + $service_charges = $jo->getMeta('service_charges'); + + $this->invoiceServiceCharges($criteria, $service_charges); + } + + if ($ierror) { $error_array['invoice'] = $ierror; } - else { // generate the invoice @@ -641,12 +650,13 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface foreach ($service_charges as $service_charge) { $amount = $service_charge->getAmount(); + $title = 'Service Charge - ' . $service_charge->getName(); $total['total_price'] += $amount; // add item $item = new InvoiceItem(); $item->setInvoice($invoice) - ->setTitle('Service Charge - ' . $service_charge->getName()) + ->setTitle($title) ->setQuantity(1) ->setPrice($amount); diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index adb0447d..bcef0c59 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -531,6 +531,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $error_array['invoice_discount'] = 'Invalid discount specified'; // get list of service charges + $service_charges = $req->request->get('service_charges'); if (empty($error_array)) { @@ -563,6 +564,11 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $jo->addMeta('discount', $discount); + if (!empty($service_charges)) + { + $jo->addMeta('service_charges', $service_charges); + } + // check if user is null, meaning call to create came from API if ($user != null) { diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 7d0e3f31..2f25a8cc 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -994,6 +994,9 @@ $(function() { // add invoice items to data fields['invoice_items'] = invoiceItems; + // add service charges to data + fields['service_charges'] = sc_array; + {% if mode in ['update-processing', 'update-reassign-hub'] %} // add selected hub to data fields['hub'] = selectedHub; From f9c304422cc63088b058208c348c04becd030e7b Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 17 Feb 2020 14:43:21 +0000 Subject: [PATCH 20/67] Add fix when saving an invoice with no service charges. #341 --- src/Entity/JobOrder.php | 5 +++++ .../InvoiceGenerator/CMBInvoiceGenerator.php | 9 ++++++--- templates/job-order/cmb.form.onestep.html.twig | 15 ++++++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Entity/JobOrder.php b/src/Entity/JobOrder.php index 08a1f15a..ed60c7ac 100644 --- a/src/Entity/JobOrder.php +++ b/src/Entity/JobOrder.php @@ -821,4 +821,9 @@ class JobOrder { return $this->meta[$id]; } + + public function getAllMeta() + { + return $this->meta; + } } diff --git a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php index dcd6946d..180f7d1f 100644 --- a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php @@ -162,12 +162,15 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface } // get the meta for service charges - $service_charges = $jo->getMeta('service_charges'); - if ($service_charges != null) + if (array_key_exists('service_charges', $jo->getAllMeta())) { $service_charges = $jo->getMeta('service_charges'); + if ($service_charges != null) + { + $service_charges = $jo->getMeta('service_charges'); - $this->invoiceServiceCharges($criteria, $service_charges); + $this->invoiceServiceCharges($criteria, $service_charges); + } } diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 2f25a8cc..3b87f59e 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -1373,6 +1373,7 @@ $(function() { $("#btn-reset-invoice").click(function() { $("#invoice-discount").prop('selectedIndex', 0); invoiceItems = []; + sc_array = []; generateInvoice(); }); @@ -1688,6 +1689,19 @@ $(function() { console.log('removing service charge'); $(this).closest('.row').remove(); + + sc_array.length = 0; + + // get the service charges + $('.sc-select').each(function() { + var id = $(this).children('option:selected').val(); + sc_array.push({ + id: id, + }); + }); + + generateInvoice(); + return false; }); @@ -1704,7 +1718,6 @@ $(function() { sc_array.push({ id: id, }); - }); generateInvoice(); From 504d91062195deb17a1c7f843e589af1fa4bca37 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 17 Feb 2020 14:56:35 +0000 Subject: [PATCH 21/67] Add saving to meta even if service charges are blank. #341 --- src/Entity/JobOrder.php | 4 ---- src/Service/InvoiceGenerator/CMBInvoiceGenerator.php | 10 +++------- src/Service/JobOrderHandler/CMBJobOrderHandler.php | 6 +----- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/Entity/JobOrder.php b/src/Entity/JobOrder.php index ed60c7ac..8484ac8d 100644 --- a/src/Entity/JobOrder.php +++ b/src/Entity/JobOrder.php @@ -822,8 +822,4 @@ class JobOrder return $this->meta[$id]; } - public function getAllMeta() - { - return $this->meta; - } } diff --git a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php index 180f7d1f..cc1cb020 100644 --- a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php @@ -162,18 +162,14 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface } // get the meta for service charges - if (array_key_exists('service_charges', $jo->getAllMeta())) + $service_charges = $jo->getMeta('service_charges'); + if (!empty($service_charges)) { $service_charges = $jo->getMeta('service_charges'); - if ($service_charges != null) - { - $service_charges = $jo->getMeta('service_charges'); - $this->invoiceServiceCharges($criteria, $service_charges); - } + $this->invoiceServiceCharges($criteria, $service_charges); } - if ($ierror) { $error_array['invoice'] = $ierror; diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index bcef0c59..67880513 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -563,11 +563,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface ->setRider($rider); $jo->addMeta('discount', $discount); - - if (!empty($service_charges)) - { - $jo->addMeta('service_charges', $service_charges); - } + $jo->addMeta('service_charges', $service_charges); // check if user is null, meaning call to create came from API if ($user != null) From def4ed0357a27bce19665d37c7fde630038ada7e Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Tue, 18 Feb 2020 01:00:19 +0800 Subject: [PATCH 22/67] Add active job order feature for rider #344 --- config/routes/rider.yaml | 5 +++ src/Controller/RiderController.php | 26 +++++++++++++++ src/Entity/Rider.php | 34 +++++++++++++++++++ templates/rider/form.html.twig | 52 +++++++++++++++++++++++++++++- 4 files changed, 116 insertions(+), 1 deletion(-) diff --git a/config/routes/rider.yaml b/config/routes/rider.yaml index 70ddd91d..16a56993 100644 --- a/config/routes/rider.yaml +++ b/config/routes/rider.yaml @@ -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] diff --git a/src/Controller/RiderController.php b/src/Controller/RiderController.php index 838b558b..ace84582 100644 --- a/src/Controller/RiderController.php +++ b/src/Controller/RiderController.php @@ -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()]); + } } diff --git a/src/Entity/Rider.php b/src/Entity/Rider.php index f9331c03..53731475 100644 --- a/src/Entity/Rider.php +++ b/src/Entity/Rider.php @@ -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; diff --git a/templates/rider/form.html.twig b/templates/rider/form.html.twig index c08c250c..a9b0264c 100644 --- a/templates/rider/form.html.twig +++ b/templates/rider/form.html.twig @@ -13,7 +13,7 @@
-
+
@@ -150,6 +150,56 @@ {% endif %}
+
+
+
+

+ Active Job Orders +

+
+
+
+ + + + + + + + + + + + + {% set active_jo_id = obj.getActiveJobOrder.getID|default(0) %} + {% for jo in obj.getOpenJobOrders %} + + + + + + + + + {% else %} + + + + {% endfor %} + +
IDDateCustomerLocationQ StatusAction
{{ jo.getID }}{{ jo.getDateSchedule.format('Y-m-d H:i:s') }}{{ jo.getCustomer.getNameDisplay }}{{ jo.getDeliveryAddress|default('') }}{% if jo.getID == active_jo_id %}Active{% endif %} + {% if jo.getID != active_jo_id %} + + + + + + + {% endif %} +
No assigned job orders.
+
+
+
From 9a24b08bdd5a48ecab0ee770fe3727324fca7429 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 18 Feb 2020 01:15:14 +0000 Subject: [PATCH 23/67] Display existing service charges when editing one step JO. #341 --- .../JobOrderHandler/CMBJobOrderHandler.php | 1 + .../job-order/cmb.form.onestep.html.twig | 36 +++++++++---------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 67880513..72fd4883 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -1407,6 +1407,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $params['mode'] = 'onestep-edit'; $params['cvid'] = $obj->getCustomerVehicle()->getID(); $params['vid'] = $obj->getCustomerVehicle()->getVehicle()->getID(); + $params['jo_service_charges'] = $obj->getMeta('service_charges'); $this->fillDropdownParameters($params); $this->fillFormTags($params); diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 3b87f59e..d58b707a 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -490,25 +490,25 @@
- +
+ +
+
+ +
+
+ {% endfor %}
From ebc6867c8f250b4b0ace81e39ed4d91c83b6da7a Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 18 Feb 2020 01:42:16 +0000 Subject: [PATCH 24/67] Edit for one step JO with service charges. #341 --- src/Service/JobOrderHandler/CMBJobOrderHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 72fd4883..36062f7e 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -524,14 +524,14 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface } // get discount and set to meta - $discount = $req->request->get('invoice_discount'); + $discount = $req->request->get('invoice_discount', []); // check if discount is greater than 50 or negative number if (($discount > 50) || ($discount < 0)) $error_array['invoice_discount'] = 'Invalid discount specified'; // get list of service charges - $service_charges = $req->request->get('service_charges'); + $service_charges = $req->request->get('service_charges', []); if (empty($error_array)) { From 0f106ea7900fa84baf4a7edd08e4f254d77414a3 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Tue, 18 Feb 2020 09:52:51 +0800 Subject: [PATCH 25/67] Fix service charges bug in one step form #270 --- templates/job-order/cmb.form.onestep.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index d58b707a..cc89b4d6 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -490,7 +490,7 @@
- {% for jo_sc_key, jo_sc in jo_service_charges %} + {% for jo_sc_key, jo_sc in obj.getMeta('service_charges')|default([]) %}
From 39fdf318d4979926db25b8c60656637836ab8321 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Tue, 18 Feb 2020 09:55:13 +0800 Subject: [PATCH 26/67] Make getMeta in JobOrder entity return null if meta key is not found #270 --- src/Entity/JobOrder.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Entity/JobOrder.php b/src/Entity/JobOrder.php index 8484ac8d..9e902e98 100644 --- a/src/Entity/JobOrder.php +++ b/src/Entity/JobOrder.php @@ -819,6 +819,10 @@ class JobOrder public function getMeta($id) { + // return null if we don't have it + if (!isset($this->meta[$id])) + return null; + return $this->meta[$id]; } From 77fe7e8521509199916ae7957011bf5d3f722e55 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Tue, 18 Feb 2020 10:03:43 +0800 Subject: [PATCH 27/67] Remove service charges when invoice is reset in one step form #270 --- templates/job-order/cmb.form.onestep.html.twig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index cc89b4d6..f411fa3e 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -1372,8 +1372,9 @@ $(function() { // reset the invoice table $("#btn-reset-invoice").click(function() { $("#invoice-discount").prop('selectedIndex', 0); + $(.sc-select').nearest('.row').remove(); invoiceItems = []; - sc_array = []; + sc_array = []; generateInvoice(); }); From 8e73c16b74fa3f8552f561cf61f00bcff4b60a2e Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Tue, 18 Feb 2020 10:05:59 +0800 Subject: [PATCH 28/67] Fix typo in js for one step form #270 --- templates/job-order/cmb.form.onestep.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index f411fa3e..33c3796e 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -1372,7 +1372,7 @@ $(function() { // reset the invoice table $("#btn-reset-invoice").click(function() { $("#invoice-discount").prop('selectedIndex', 0); - $(.sc-select').nearest('.row').remove(); + $('.sc-select').nearest('.row').remove(); invoiceItems = []; sc_array = []; generateInvoice(); From e48e86340a7dce7a701c58ebf0b4f4bb26735861 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Tue, 18 Feb 2020 10:06:44 +0800 Subject: [PATCH 29/67] Fix bug in one step form #270 --- templates/job-order/cmb.form.onestep.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 33c3796e..d59172dd 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -1372,7 +1372,7 @@ $(function() { // reset the invoice table $("#btn-reset-invoice").click(function() { $("#invoice-discount").prop('selectedIndex', 0); - $('.sc-select').nearest('.row').remove(); + $('.sc-select').closest('.row').remove(); invoiceItems = []; sc_array = []; generateInvoice(); From 688ccd8a91a97a5cc1268490d011f15b518e8062 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 18 Feb 2020 02:29:22 +0000 Subject: [PATCH 30/67] Fix display of discount when reset button for invoice is clicked. #270 --- .../job-order/cmb.form.onestep.html.twig | 109 ++++++++---------- 1 file changed, 45 insertions(+), 64 deletions(-) diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index d59172dd..8a266b63 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -1369,14 +1369,13 @@ $(function() { generateInvoice(); }); - // reset the invoice table - $("#btn-reset-invoice").click(function() { - $("#invoice-discount").prop('selectedIndex', 0); + // reset the invoice table + $("#btn-reset-invoice").click(function() { + $("#invoice-discount").val(0); $('.sc-select').closest('.row').remove(); - invoiceItems = []; - sc_array = []; - generateInvoice(); - }); + invoiceItems = []; + generateInvoice(); + }); // recompute $("#btn-recompute-invoice").click(function() { @@ -1389,8 +1388,14 @@ $(function() { var stype = $("#service_type").val(); var cvid = $("#customer-vehicle").val(); - $.each(sc_array, function(index){ - console.log('generateInvoice ' + this.id); + sc_array = []; + + // get the service charges + $('.sc-select').each(function() { + var id = $(this).children('option:selected').val(); + sc_array.push({ + id: id, + }); }); // generate invoice values @@ -1409,39 +1414,39 @@ $(function() { $("#invoice-change").val(1); var invoice = response.invoice; - // populate totals - $("#invoice-discount").val(invoice.discount); - $("#invoice-price").val(invoice.price); - $("#invoice-trade-in").val(invoice.trade_in); - $("#invoice-vat").val(invoice.vat); - $("#invoice-total-amount").val(invoice.total_price); + // populate totals + $("#invoice-discount").val(invoice.discount); + $("#invoice-price").val(invoice.price); + $("#invoice-trade-in").val(invoice.trade_in); + $("#invoice-vat").val(invoice.vat); + $("#invoice-total-amount").val(invoice.total_price); - // populate rows - var html = ''; + // populate rows + var html = ''; - if (invoice.items.length > 0) { - $.each(invoice.items, function(key, item) { - html += '' + - '' + item.title + '' + - '' + item.quantity + '' + - '' + item.unit_price + '' + - '' + item.amount + '' + - /* - '' + - */ - ''; - }); - } else { - html = '' + - '' + - 'No items to display.' + - '' + - ''; - } - - table.html(html); - }); - } + if (invoice.items.length > 0) { + $.each(invoice.items, function(key, item) { + html += '' + + '' + item.title + '' + + '' + item.quantity + '' + + '' + item.unit_price + '' + + '' + item.amount + '' + + /* + '' + + */ + ''; + }); + } else { + html = '' + + '' + + 'No items to display.' + + '' + + ''; + } + + table.html(html); + }); + } // remove from invoice table // TODO: figure out a way to delete rows, and should deleting trade ins be allowed since they count as items on the table? @@ -1677,9 +1682,6 @@ $(function() { $('#sc-section').append(html); - // clear the sc_array - sc_array.length = 0; - // trigger change in select $('#sc-section').find('.sc-select').last().change(); return false; @@ -1691,16 +1693,6 @@ $(function() { $(this).closest('.row').remove(); - sc_array.length = 0; - - // get the service charges - $('.sc-select').each(function() { - var id = $(this).children('option:selected').val(); - sc_array.push({ - id: id, - }); - }); - generateInvoice(); return false; @@ -1710,17 +1702,6 @@ $(function() { var amount = $(this).children('option:selected').data('amount'); $(this).closest('.row').find('.sc-amount').val(amount); - // clear the sc_array - sc_array.length = 0; - - // get the service charges - $('.sc-select').each(function() { - var id = $(this).children('option:selected').val(); - sc_array.push({ - id: id, - }); - }); - generateInvoice(); }); From 8306e9db4f5892de52cabd577f8bd006475b7f7b Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 18 Feb 2020 03:35:34 +0000 Subject: [PATCH 31/67] Create separate menu.yaml files for Resq and CMB. #349 --- config/cmb.menu.yaml | 179 +++++++++++++++++++++++++++++++++++++++++ config/menu.yaml | 12 --- config/resq.menu.yaml | 183 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 362 insertions(+), 12 deletions(-) create mode 100644 config/cmb.menu.yaml create mode 100644 config/resq.menu.yaml diff --git a/config/cmb.menu.yaml b/config/cmb.menu.yaml new file mode 100644 index 00000000..c209ba0c --- /dev/null +++ b/config/cmb.menu.yaml @@ -0,0 +1,179 @@ +main_menu: + - id: home + acl: dashboard.menu + label: Dashboard + icon: flaticon-line-graph + - id: user + acl: user.menu + label: User + icon: flaticon-users + - id: user_list + acl: user.list + label: Users + parent: user + - id: role_list + acl: role.list + label: Roles + parent: user + + - id: apiuser + acl: apiuser.menu + label: API User + icon: flaticon-users + - id: api_user_list + acl: apiuser.list + label: API Users + parent: apiuser + - id: api_role_list + acl: apirole.list + label: API Roles + parent: apiuser + + - id: logistics + acl: logistics.menu + label: Logistics + icon: fa fa-truck + - id: rider_list + acl: rider.list + label: Riders + parent: logistics + + - id: battery + acl: battery.menu + label: Battery + icon: fa fa-battery-3 + - id: battery_list + acl: battery.list + label: Batteries + parent: battery + - id: bmfg_list + acl: bmfg.list + label: Manufacturers + parent: battery + - id: bmodel_list + acl: bmodel.list + label: Models + parent: battery + - id: bsize_list + acl: bsize.list + label: Sizes + parent: battery + - id: promo_list + acl: promo.list + label: Promos + parent: battery + + - id: vehicle + acl: vehicle.menu + label: Vehicle + icon: fa fa-car + - id: vehicle_list + acl: vehicle.list + label: Vehicles + parent: vehicle + - id: vmfg_list + acl: vmfg.list + label: Manufacturers + parent: vehicle + + - id: location + acl: location.menu + label: Location + icon: fa fa-home + - id: outlet_list + acl: outlet.menu + label: Outlet + parent: location + - id: hub_list + acl: hub.menu + label: Hub + parent: location + - id: geofence_list + acl: geofence.menu + label: Geofence + parent: location + + + - id: joborder + acl: joborder.menu + label: Job Order + icon: flaticon-calendar-3 + - id: jo_onestep_form + acl: jo_onestep.form + label: One-step Process + parent: joborder + - id: jo_walkin_form + acl: jo_walkin.form + label: Walk-in + parent: joborder + - id: jo_fulfill + acl: jo_fulfill.list + label: Fulfillment + parent: joborder + - id: jo_open + acl: jo_open.list + label: Open + parent: joborder + - id: jo_all + acl: jo_all.list + label: View All + parent: joborder + + - id: support + acl: support.menu + label: Customer Support + icon: flaticon-support + - id: customer_list + acl: customer.list + label: Customers + parent: support + - id: ticket_list + acl: ticket.list + label: Tickets + parent: support + - id: general_search + acl: general.search + label: Search + parent: support + - id: warranty_search + acl: warranty.search + label: Customer Battery Search + parent: support + - id: privacy_policy_list + acl: privacy_policy.list + label: Privacy Policy + parent: support + - id: warranty_list + acl: warranty.list + label: Warranty + parent: support + - id: warranty_upload + acl: warranty.upload + label: Warranty Upload + parent: support + - id: static_content_list + acl: static_content.list + label: Static Content + parent: support + + - id: service + acl: service.menu + label: Other Services + icon: flaticon-squares + - id: service_list + acl: service.list + label: Services + parent: service + + - id: partner + acl: partner.menu + label: Partners + icon: flaticon-network + - id: partner_list + acl: partner.list + label: Partners + parent: partner + - id: review_list + acl: review.list + label: Reviews + parent: partner diff --git a/config/menu.yaml b/config/menu.yaml index 1f90e314..c209ba0c 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -106,18 +106,6 @@ main_menu: acl: jo_walkin.form label: Walk-in parent: joborder - - id: jo_in - acl: jo_in.list - label: Incoming - parent: joborder - - id: jo_proc - acl: jo_proc.list - label: Dispatch - parent: joborder - - id: jo_assign - acl: jo_assign.list - label: Rider Assignment - parent: joborder - id: jo_fulfill acl: jo_fulfill.list label: Fulfillment diff --git a/config/resq.menu.yaml b/config/resq.menu.yaml new file mode 100644 index 00000000..b0096cf5 --- /dev/null +++ b/config/resq.menu.yaml @@ -0,0 +1,183 @@ +main_menu: + - id: home + acl: dashboard.menu + label: Dashboard + icon: flaticon-line-graph + - id: user + acl: user.menu + label: User + icon: flaticon-users + - id: user_list + acl: user.list + label: Users + parent: user + - id: role_list + acl: role.list + label: Roles + parent: user + + - id: apiuser + acl: apiuser.menu + label: API User + icon: flaticon-users + - id: api_user_list + acl: apiuser.list + label: API Users + parent: apiuser + - id: api_role_list + acl: apirole.list + label: API Roles + parent: apiuser + + - id: logistics + acl: logistics.menu + label: Logistics + icon: fa fa-truck + - id: rider_list + acl: rider.list + label: Riders + parent: logistics + + - id: battery + acl: battery.menu + label: Battery + icon: fa fa-battery-3 + - id: battery_list + acl: battery.list + label: Batteries + parent: battery + - id: bmfg_list + acl: bmfg.list + label: Manufacturers + parent: battery + - id: bmodel_list + acl: bmodel.list + label: Models + parent: battery + - id: bsize_list + acl: bsize.list + label: Sizes + parent: battery + - id: promo_list + acl: promo.list + label: Promos + parent: battery + + - id: vehicle + acl: vehicle.menu + label: Vehicle + icon: fa fa-car + - id: vehicle_list + acl: vehicle.list + label: Vehicles + parent: vehicle + - id: vmfg_list + acl: vmfg.list + label: Manufacturers + parent: vehicle + + - id: location + acl: location.menu + label: Location + icon: fa fa-home + - id: outlet_list + acl: outlet.menu + label: Outlet + parent: location + - id: hub_list + acl: hub.menu + label: Hub + parent: location + - id: geofence_list + acl: geofence.menu + label: Geofence + parent: location + + + - id: joborder + acl: joborder.menu + label: Job Order + icon: flaticon-calendar-3 + - id: jo_in + acl: jo_in.list + label: Incoming + parent: joborder + - id: jo_proc + acl: jo_proc.list + label: Dispatch + parent: joborder + - id: jo_assign + acl: jo_assign.list + label: Rider Assignment + parent: joborder + - id: jo_fulfill + acl: jo_fulfill.list + label: Fulfillment + parent: joborder + - id: jo_open + acl: jo_open.list + label: Open + parent: joborder + - id: jo_all + acl: jo_all.list + label: View All + parent: joborder + + - id: support + acl: support.menu + label: Customer Support + icon: flaticon-support + - id: customer_list + acl: customer.list + label: Customers + parent: support + - id: ticket_list + acl: ticket.list + label: Tickets + parent: support + - id: general_search + acl: general.search + label: Search + parent: support + - id: warranty_search + acl: warranty.search + label: Customer Battery Search + parent: support + - id: privacy_policy_list + acl: privacy_policy.list + label: Privacy Policy + parent: support + - id: warranty_list + acl: warranty.list + label: Warranty + parent: support + - id: warranty_upload + acl: warranty.upload + label: Warranty Upload + parent: support + - id: static_content_list + acl: static_content.list + label: Static Content + parent: support + + - id: service + acl: service.menu + label: Other Services + icon: flaticon-squares + - id: service_list + acl: service.list + label: Services + parent: service + + - id: partner + acl: partner.menu + label: Partners + icon: flaticon-network + - id: partner_list + acl: partner.list + label: Partners + parent: partner + - id: review_list + acl: review.list + label: Reviews + parent: partner From 15fa7aafc6e780b97fec1d4ff246eb147a11258d Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 18 Feb 2020 03:55:11 +0000 Subject: [PATCH 32/67] Fix display of discount for walkin form when reset button for invoice is clicked. #270 --- templates/job-order/cmb.form.walkin.html.twig | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/job-order/cmb.form.walkin.html.twig b/templates/job-order/cmb.form.walkin.html.twig index 1a833e63..5af0a7cf 100644 --- a/templates/job-order/cmb.form.walkin.html.twig +++ b/templates/job-order/cmb.form.walkin.html.twig @@ -946,12 +946,12 @@ var vdata = false; generateInvoice(); }); - // reset the invoice table - $("#btn-reset-invoice").click(function() { - $("#invoice-discount").prop('selectedIndex', 0); - invoiceItems = []; - generateInvoice(); - }); + // reset the invoice table + $("#btn-reset-invoice").click(function() { + $("#invoice-discount").val(0); + invoiceItems = []; + generateInvoice(); + }); // recompute $("#btn-recompute-invoice").click(function() { From a62476a8338b4446f22a724741ddf0adabad4cdd Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 19 Feb 2020 03:16:27 +0000 Subject: [PATCH 33/67] Add create, update, list, and delete for service charges. #348 --- config/acl.yaml | 14 ++ config/cmb.menu.yaml | 4 + config/menu.yaml | 4 + config/routes/service_charge.yaml | 34 +++ src/Controller/ServiceChargeController.php | 268 +++++++++++++++++++++ src/Entity/ServiceCharge.php | 2 + templates/service-charge/form.html.twig | 143 +++++++++++ templates/service-charge/list.html.twig | 142 +++++++++++ 8 files changed, 611 insertions(+) create mode 100644 config/routes/service_charge.yaml create mode 100644 src/Controller/ServiceChargeController.php create mode 100644 templates/service-charge/form.html.twig create mode 100644 templates/service-charge/list.html.twig diff --git a/config/acl.yaml b/config/acl.yaml index 21f09775..c6ccc243 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -215,6 +215,20 @@ access_keys: - id: rider.delete label: Delete + - id: servicecharge + label: Service Charge + acls: + - id: service_charge.menu + label: Menu + - id: service_charge.list + label: List + - id: service_charge.add + label: Add + - id: service_charge.update + label: Update + - id: service_charge.delete + label: Delete + - id: joborder label: Job Order acls: diff --git a/config/cmb.menu.yaml b/config/cmb.menu.yaml index c209ba0c..7c6b4d82 100644 --- a/config/cmb.menu.yaml +++ b/config/cmb.menu.yaml @@ -37,6 +37,10 @@ main_menu: acl: rider.list label: Riders parent: logistics + - id: service_charge_list + acl: service_charge.list + label: Service Charges + parent: logistics - id: battery acl: battery.menu diff --git a/config/menu.yaml b/config/menu.yaml index c209ba0c..7c6b4d82 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -37,6 +37,10 @@ main_menu: acl: rider.list label: Riders parent: logistics + - id: service_charge_list + acl: service_charge.list + label: Service Charges + parent: logistics - id: battery acl: battery.menu diff --git a/config/routes/service_charge.yaml b/config/routes/service_charge.yaml new file mode 100644 index 00000000..c6206371 --- /dev/null +++ b/config/routes/service_charge.yaml @@ -0,0 +1,34 @@ +service_charge_list: + path: /service_charges + controller: App\Controller\ServiceChargeController::index + +service_charge_rows: + path: /service_charges/rows + controller: App\Controller\ServiceChargeController::rows + methods: [POST] + +service_charge_create: + path: /service_charges/create + controller: App\Controller\ServiceChargeController::addForm + methods: [GET] + +service_charge_create_submit: + path: /service_charges/create + controller: App\Controller\ServiceChargeController::addSubmit + methods: [POST] + +service_charge_update: + path: /service_charges/{id} + controller: App\Controller\ServiceChargeController::updateForm + methods: [GET] + +service_charge_update_submit: + path: /service_charges/{id} + controller: App\Controller\ServiceChargeController::updateSubmit + methods: [POST] + +service_charge_delete: + path: /service_charges/{id} + controller: App\Controller\ServiceChargeController::destroy + methods: [DELETE] + diff --git a/src/Controller/ServiceChargeController.php b/src/Controller/ServiceChargeController.php new file mode 100644 index 00000000..7208e306 --- /dev/null +++ b/src/Controller/ServiceChargeController.php @@ -0,0 +1,268 @@ +denyAccessUnlessGranted('service_charge.list', null, 'No access.'); + + return $this->render('service-charge/list.html.twig'); + } + + public function rows(Request $req) + { + $this->denyAccessUnlessGranted('service_charge.list', null, 'No access.'); + + // build query + $qb = $this->getDoctrine() + ->getRepository(ServiceCharge::class) + ->createQueryBuilder('q'); + + // get datatable params + $datatable = $req->request->get('datatable'); + + // count total records + $tquery = $qb->select('COUNT(q)'); + + // add fitlers to count query + $this->setQueryFilters($datatable, $tquery); + + $total = $tquery->getQuery() + ->getSingleScalarResult(); + + // get current page number + $page = $datatable['pagination']['page'] ?? 1; + + $perpage = $datatable['pagination']['perpage']; + $offset = ($page - 1) * $perpage; + + // add metadata + $meta = [ + 'page' => $page, + 'perpage' => $perpage, + 'pages' => ceil($total / $perpage), + 'total' => $total, + 'sort' => 'asc', + 'field' => 'id' + ]; + + // build query + $query = $qb->select('q'); + + // add filters to query + $this->setQueryFilters($datatable, $query); + + // check if sorting is present, otherwise use default + if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) { + $order = $datatable['sort']['sort'] ?? 'asc'; + $query->orderBy('q.' . $datatable['sort']['field'], $order); + } else { + $query->orderBy('q.id', 'asc'); + } + + // get rows for this page + $obj_rows = $query->setFirstResult($offset) + ->setMaxResults($perpage) + ->getQuery() + ->getResult(); + + // process rows + $rows = []; + foreach ($obj_rows as $orow) { + // add row data + $row['id'] = $orow->getID(); + $row['name'] = $orow->getName(); + + // add row metadata + $row['meta'] = [ + 'update_url' => '', + 'delete_url' => '' + ]; + + // add crud urls + if ($this->isGranted('service_charge.update')) + $row['meta']['update_url'] = $this->generateUrl('service_charge_update', ['id' => $row['id']]); + if ($this->isGranted('service.delete')) + $row['meta']['delete_url'] = $this->generateUrl('service_charge_delete', ['id' => $row['id']]); + + $rows[] = $row; + } + + // response + return $this->json([ + 'meta' => $meta, + 'data' => $rows + ]); + } + + /** + * @Menu(selected="service_charge_list") + */ + public function addForm() + { + $this->denyAccessUnlessGranted('service_charge.add', null, 'No access.'); + + $params = []; + $params['obj'] = new ServiceCharge(); + $params['mode'] = 'create'; + + // response + return $this->render('service-charge/form.html.twig', $params); + } + + public function addSubmit(Request $req, ValidatorInterface $validator, EntityManagerInterface $em) + { + $this->denyAccessUnlessGranted('service_charge.add', null, 'No access.'); + + // create new object + $row = new ServiceCharge(); + + // set and save values + $row->setName($req->request->get('name')); + $row->setAmount($req->request->get('amount')); + + // validate + $errors = $validator->validate($row); + + // initialize error list + $error_array = []; + + // 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); + } else { + // validated! save the entity + $em->persist($row); + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + } + + /** + * @Menu(selected="service_charge_list") + * @ParamConverter("sc", class="App\Entity\ServiceCharge") + */ + public function updateForm(ServiceCharge $sc) + { + $this->denyAccessUnlessGranted('service_charge.update', null, 'No access.'); + + $params = []; + $params['mode'] = 'update'; + + if ($sc == null) + throw $this->createNotFoundException('The item does not exist'); + + $params['obj'] = $sc; + + // response + return $this->render('service-charge/form.html.twig', $params); + } + + /** + * @ParamConverter("sc", class="App\Entity\ServiceCharge") + */ + public function updateSubmit(Request $req, ValidatorInterface $validator, + ServiceCharge $sc, EntityManagerInterface $em) + { + $this->denyAccessUnlessGranted('service_charge.update', null, 'No access.'); + + // make sure this row exists + if ($sc == null) + throw $this->createNotFoundException('The item does not exist'); + + // set and save values + $sc->setName($req->request->get('name')); + $sc->setAmount($req->request->get('amount')); + + // validate + $errors = $validator->validate($sc); + + // initialize error list + $error_array = []; + + // 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); + } else { + // validated! save the entity + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + } + + /** + * @Menu(selected="service_list") + * @ParamConverter("sc", class="App\Entity\ServiceCharge") + */ + public function destroy(ServiceCharge $sc, EntityManagerInterface $em) + { + $this->denyAccessUnlessGranted('service_charge.delete', null, 'No access.'); + + $params = []; + + if ($sc == null) + throw $this->createNotFoundException('The item does not exist'); + + // delete this row + $em->remove($sc); + $em->flush(); + + // response + $response = new Response(); + $response->setStatusCode(Response::HTTP_OK); + $response->send(); + } + + protected function setQueryFilters($datatable, &$query) + { + if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { + $query->where('q.name LIKE :filter') + ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); + } + } + +} diff --git a/src/Entity/ServiceCharge.php b/src/Entity/ServiceCharge.php index 8ba224cf..98f96c77 100644 --- a/src/Entity/ServiceCharge.php +++ b/src/Entity/ServiceCharge.php @@ -3,6 +3,7 @@ namespace App\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; /** * @ORM\Entity @@ -21,6 +22,7 @@ class ServiceCharge // name /** * @ORM\Column(type="string", length=80) + * @Assert\NotBlank() */ protected $name; diff --git a/templates/service-charge/form.html.twig b/templates/service-charge/form.html.twig new file mode 100644 index 00000000..73b5750a --- /dev/null +++ b/templates/service-charge/form.html.twig @@ -0,0 +1,143 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

Service Charges

+
+
+
+ +
+ +
+
+
+
+
+
+ + + +

+ {% if mode == 'update' %} + Edit Service Charge + {{ obj.getID() }} + {% else %} + New Service Charge + {% endif %} +

+
+
+
+
+
+
+
+ + + +
+
+
+
+ + + +
+
+ +
+
+
+
+
+ + Back +
+
+
+
+
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/service-charge/list.html.twig b/templates/service-charge/list.html.twig new file mode 100644 index 00000000..6f92e838 --- /dev/null +++ b/templates/service-charge/list.html.twig @@ -0,0 +1,142 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Service Charges +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} From 1374a91dd4be372d4c9c69c68555083f5984079d Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 19 Feb 2020 05:02:21 +0000 Subject: [PATCH 34/67] Add checking for transaction origin. #347 --- .../JobOrderHandler/CMBJobOrderHandler.php | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 36062f7e..5c12492d 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -1392,7 +1392,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $this->fillFormTags($params); // get template to display - $params['template'] = $this->getTwigTemplate('jo_onestep'); + $params['template'] = $this->getTwigTemplate('jo_onestep_form'); // return params return $params; @@ -1529,8 +1529,12 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $this->fillDropdownParameters($params); $this->fillFormTags($params); - // get template to display - $params['template'] = $this->getTwigTemplate('jo_all_form'); + // get template to display + // check transaction origin if walkin + if ($obj->getSource() == TransactionOrigin::WALK_IN) + $params['template'] = $this->getTwigTemplate('jo_walkin_form'); + else + $params['template'] = $this->getTwigTemplate('jo_onestep_form'); $params['obj'] = $obj; $params['status_cancelled'] = JOStatus::CANCELLED; @@ -2381,7 +2385,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $this->fillFormTags($params); // get template to display - $params['template'] = $this->getTwigTemplate('jo_walkin'); + $params['template'] = $this->getTwigTemplate('jo_walkin_form'); // return params return $params; @@ -2667,7 +2671,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $this->fillFormTags($params); // get template to display - $params['template'] = $this->getTwigTemplate('jo_walkin_edit'); + $params['template'] = $this->getTwigTemplate('jo_walkin_edit_form'); // return params return $params; @@ -2789,10 +2793,10 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $this->template_hash['jo_list_fulfillment'] = 'job-order/list.fulfillment.html.twig'; $this->template_hash['jo_list_open'] = 'job-order/list.open.html.twig'; $this->template_hash['jo_list_all'] = 'job-order/list.all.html.twig'; - $this->template_hash['jo_onestep'] = '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_walkin'] = 'job-order/cmb.form.walkin.html.twig'; - $this->template_hash['jo_walkin_edit'] = 'job-order/cmb.form.walkin.html.twig'; + $this->template_hash['jo_walkin_form'] = 'job-order/cmb.form.walkin.html.twig'; + $this->template_hash['jo_walkin_edit_form'] = 'job-order/cmb.form.walkin.html.twig'; } protected function checkTier($tier) From 5ab6514a86d82f298e2995385c4e5c85dabd4b3c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 19 Feb 2020 06:29:31 +0000 Subject: [PATCH 35/67] Fixed form for onestep when JO is loaded from View All. #347 --- .../JobOrderHandler/CMBJobOrderHandler.php | 2 +- .../job-order/cmb.form.onestep.html.twig | 192 +++++++++++------- 2 files changed, 122 insertions(+), 72 deletions(-) diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 5c12492d..80e4158e 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -1517,7 +1517,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface { $em = $this->em; - $params['mode'] = 'update-all'; + $params['mode'] = 'view-all'; // get row data $obj = $em->getRepository(JobOrder::class)->find($id); diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 8a266b63..0d9bac9f 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -389,14 +389,20 @@

- Nearest Hubs + {% if mode == 'view-all' %} + Assigned Hub + {% else %} + Nearest Hubs + {% endif %}

- + {% if mode != 'view-all' %} + + {% endif %}
@@ -430,14 +436,20 @@

- Rider Assignment + {% if mode == 'view-all' %} + Assigned Rider + {% else %} + Rider Assignment + {% endif %}

- + {% if mode != 'view-all' %} + + {% endif %}
@@ -452,7 +464,7 @@ - {% if mode in ['onestep-edit'] %} + {% if mode in ['onestep-edit', 'view-all'] %} {% set avail_riders = obj.getHub.getAvailableRiders|default([]) %} @@ -462,7 +474,11 @@ {% if obj.getHub %} {% for rider in avail_riders %} - + {% if mode == 'view-all' %} + + {% else %} + + {% endif %} {{ rider.getFirstName }} {{ rider.getLastName }} {{ rider.getContactNumber }} @@ -485,11 +501,13 @@
-
- -
+ {% if mode != 'view-all' %} +
+ +
+ {% endif %}
- + {% for jo_sc_key, jo_sc in obj.getMeta('service_charges')|default([]) %}
@@ -634,9 +652,11 @@
- - {% if ftags.set_map_coordinate and is_granted('joborder.cancel') and not obj.isCancelled %} - Cancel Job Order + {% if mode != 'view-all' %} + + {% if ftags.set_map_coordinate and is_granted('joborder.cancel') and not obj.isCancelled %} + Cancel Job Order + {% endif %} {% endif %} Back
@@ -781,6 +801,32 @@ $(function() { }); {% endif %} + {% if mode in ['view-all'] %} + var hub_table = ''; + $.getJSON("{{ url('hub_nearest') }}?lat=" + lat + "&long=" + lng, function(data) { + var hubs = data['hubs']; + var hub_marker; + for (i in hubs) { + var hub = hubs[i]; + + if(selected_hub == hub['id']) { + hub_table += ''; + hub_marker = L.marker([hub['lat'], hub['long']], { icon: icon_hub }); + hubLayerGroup.addLayer(hub_marker); + + hub_table += '' + hub['name'] + ''; + hub_table += '' + hub['branch'] + ''; + hub_table += '' + hub['cnum'] + ''; + hub_table += '' + hub['distance'] + ''; + hub_table += ''; + hub_table += ''; + } + } + + $('#nearest_hubs').html(hub_table); + }); + {% endif %} + // add marker to layer group markerLayerGroup.addLayer(marker); @@ -844,76 +890,80 @@ $(function() { }); $(function() { - $('#hubs-table').on('click', 'tr', function() { - var id = $(this).data('id'); + {% if mode != 'view-all' %} + $('#hubs-table').on('click', 'tr', function() { + var id = $(this).data('id'); - riderLayerGroup.clearLayers(); + riderLayerGroup.clearLayers(); - if (id != selected_hub) { + if (id != selected_hub) { - // highlight this row - $('#hubs-table').find('.m-table__row--primary').removeClass('m-table__row--primary'); + // highlight this row + $('#hubs-table').find('.m-table__row--primary').removeClass('m-table__row--primary'); - $(this).addClass('m-table__row--primary'); + $(this).addClass('m-table__row--primary'); - // set hub - selected_hub = id; - $('#hub-field').val(selected_hub); + // set hub + selected_hub = id; + $('#hub-field').val(selected_hub); - // clear rider field - $('#rider-field').val(''); - selected_rider = ''; + // clear rider field + $('#rider-field').val(''); + selected_rider = ''; - // get riders of hub - // get hub riders ajax - // TODO: add latitude and longitude of delivery location to ajax request - var rider_table = ''; - $.getJSON("{{ url('hub_riders') }}?id=" + selected_hub, function(data) { - var riders = data['riders']; - for (i in riders) { - var rider = riders[i]; - var rider_lat = rider['location'][0]; - var rider_lng = rider['location'][1]; - var rider_marker = L.marker([rider_lat, rider_lng], { icon: icon_rider_available }); - riderLayerGroup.addLayer(rider_marker); + // get riders of hub + // get hub riders ajax + // TODO: add latitude and longitude of delivery location to ajax request + var rider_table = ''; + $.getJSON("{{ url('hub_riders') }}?id=" + selected_hub, function(data) { + var riders = data['riders']; + for (i in riders) { + var rider = riders[i]; + var rider_lat = rider['location'][0]; + var rider_lng = rider['location'][1]; + var rider_marker = L.marker([rider_lat, rider_lng], { icon: icon_rider_available }); + riderLayerGroup.addLayer(rider_marker); - rider_table += ''; - rider_table += '' + rider['first_name'] + ''; - rider_table += '' + rider['last_name'] + ''; - rider_table += '' + rider['contact_num'] + ''; - rider_table += '' + rider['plate_num'] + ''; - rider_table += ''; - rider_table += ''; - } + rider_table += ''; + rider_table += '' + rider['first_name'] + ''; + rider_table += '' + rider['last_name'] + ''; + rider_table += '' + rider['contact_num'] + ''; + rider_table += '' + rider['plate_num'] + ''; + rider_table += ''; + rider_table += ''; + } - $('#riders').html(rider_table); - }); - } else { - // unhighlight this row - $(this).removeClass('m-table__row--primary'); - - // remove id value - selected_hub = ''; - } - }); + $('#riders').html(rider_table); + }); + } else { + // unhighlight this row + $(this).removeClass('m-table__row--primary'); + + // remove id value + selected_hub = ''; + } + }); + {% endif %} }); $(function() { - $('#rider-table').on('click', 'tr', function() { - var id = $(this).data('id'); + {% if mode != 'view-all' %} + $('#rider-table').on('click', 'tr', function() { + var id = $(this).data('id'); - // highlight this row - $('#rider-table').find('.m-table__row--primary').removeClass('m-table__row--primary'); + // highlight this row + $('#rider-table').find('.m-table__row--primary').removeClass('m-table__row--primary'); - $(this).addClass('m-table__row--primary'); + $(this).addClass('m-table__row--primary'); - // set rider - selected_rider = id; - $('#rider-field').val(selected_rider); - }); + // set rider + selected_rider = id; + $('#rider-field').val(selected_rider); + }); + {% endif %} }); - {% if mode in ['onestep-edit'] %} + {% if mode in ['onestep-edit', 'view-all'] %} var lat = {{ obj.getCoordinates.getLatitude }}; var lng = {{ obj.getCoordinates.getLongitude }}; @@ -1307,7 +1357,7 @@ $(function() { var sc_array = []; // populate invoiceItems if editing so that we don't lose the battery - {% if mode in ['open-edit', 'onestep-edit', 'walk-in-edit'] %} + {% if mode in ['view-all', 'open-edit', 'onestep-edit', 'walk-in-edit'] %} {% if (obj.getInvoice and obj.getInvoice.getItems|length > 0) %} {% for item in obj.getInvoice.getItems %} {% if item.getBattery() %} From cbd9f429d4b021f189378524d40e359e61a21ee7 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 19 Feb 2020 06:46:26 +0000 Subject: [PATCH 36/67] Fixed form for walkin when JO is loaded from View All. #347 --- templates/job-order/cmb.form.walkin.html.twig | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/templates/job-order/cmb.form.walkin.html.twig b/templates/job-order/cmb.form.walkin.html.twig index 5af0a7cf..f2e02e44 100644 --- a/templates/job-order/cmb.form.walkin.html.twig +++ b/templates/job-order/cmb.form.walkin.html.twig @@ -341,9 +341,11 @@
- + {% if mode != 'view-all' %} + + {% endif %}
@@ -358,14 +360,23 @@ - {% for hub in hubs %} - - {{ hub.getName }} - {{ hub.getBranch }} - {{ hub.getContactNumbers }} + {% if mode == 'view-all' %} + + {{ obj.getHub.getName }} + {{ obj.getHub.getBranch }} + {{ obj.getHub.getContactNumbers }} - {% endfor %} + {% else %} + {% for hub in hubs %} + + {{ hub.getName }} + {{ hub.getBranch }} + {{ hub.getContactNumbers }} + + + {% endfor %} + {% endif %}
@@ -495,9 +506,11 @@
- - {% if ftags.set_map_coordinate and is_granted('joborder.cancel') and not obj.isCancelled %} - Cancel Job Order + {% if mode != 'view-all' %} + + {% if ftags.set_map_coordinate and is_granted('joborder.cancel') and not obj.isCancelled %} + Cancel Job Order + {% endif %} {% endif %} Back
From 4a12fb6eb2762215774b5080d434c2dc4462866c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 20 Feb 2020 04:12:12 +0000 Subject: [PATCH 37/67] Change edit to edit onestep edit and walkin. #353 --- src/Controller/JobOrderController.php | 6 +- .../JobOrderHandler/CMBJobOrderHandler.php | 16 +- .../job-order/cmb.form.onestep.html.twig | 20 +- .../job-order/cmb.list.fulfillment.html.twig | 183 +++++++++++++++++ templates/job-order/cmb.list.open.html.twig | 190 ++++++++++++++++++ 5 files changed, 391 insertions(+), 24 deletions(-) create mode 100644 templates/job-order/cmb.list.fulfillment.html.twig create mode 100644 templates/job-order/cmb.list.open.html.twig diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index c06383c7..44265309 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -282,7 +282,7 @@ class JobOrderController extends Controller else { $rows[$key]['meta']['update_url'] = $this->generateUrl($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($tier_params['edit_route'], ['id' => $jo_id]); $rows[$key]['meta']['pdf_url'] = $this->generateUrl('jo_pdf_form', ['id' => $jo_id]); } @@ -430,7 +430,7 @@ class JobOrderController extends Controller * @Menu(selected="jo_fulfill") */ public function fulfillmentForm(JobOrderHandlerInterface $jo_handler, $id, - GISManagerInterface $gis) + GISManagerInterface $gis, EntityManagerInterface $em) { $this->denyAccessUnlessGranted('jo_fulfill.list', null, 'No access.'); @@ -443,6 +443,8 @@ class JobOrderController extends Controller throw $this->createNotFoundException($e->getMessage()); } + $params['vmfgs'] = $em->getRepository(VehicleManufacturer::class)->findAll(); + $params['vmakes'] = $em->getRepository(Vehicle::class)->findAll(); $params['submit_url'] = $this->generateUrl('jo_fulfill_submit', ['id' => $id]); $params['return_url'] = $this->generateUrl('jo_fulfill'); $params['map_js_file'] = $gis->getJSJOFile(); diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 80e4158e..06f1fb72 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -2779,19 +2779,11 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface // $this->template_hash = [ // 'blah' => 'blah', // ]; - $this->template_hash['jo_incoming_form'] = 'job-order/cmb.form.html.twig'; - $this->template_hash['jo_open_edit_form'] = 'job-order/cmb.form.html.twig'; $this->template_hash['jo_incoming_vehicle_form'] = 'job-order/cmb.form.html.twig'; - $this->template_hash['jo_processing_form'] = 'job-order/cmb.form.html.twig'; - $this->template_hash['jo_assigning_form'] = 'job-order/cmb.form.html.twig'; - $this->template_hash['jo_fulfillment_form'] = 'job-order/cmb.form.html.twig'; - $this->template_hash['jo_open_hub_form'] = 'job-order/cmb.form.html.twig'; - $this->template_hash['jo_open_rider_form'] = 'job-order/cmb.form.html.twig'; - $this->template_hash['jo_all_form'] = 'job-order/cmb.form.html.twig'; - $this->template_hash['jo_list_processing'] = 'job-order/list.processing.html.twig'; - $this->template_hash['jo_list_assigning'] = 'job-order/list.assigning.html.twig'; - $this->template_hash['jo_list_fulfillment'] = 'job-order/list.fulfillment.html.twig'; - $this->template_hash['jo_list_open'] = 'job-order/list.open.html.twig'; + $this->template_hash['jo_fulfillment_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_open'] = 'job-order/cmb.list.open.html.twig'; $this->template_hash['jo_list_all'] = 'job-order/list.all.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'; diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 0d9bac9f..4c913bca 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -389,7 +389,7 @@

- {% if mode == 'view-all' %} + {% if mode in ['view-all', 'update-fulfillment'] %} Assigned Hub {% else %} Nearest Hubs @@ -436,7 +436,7 @@

- {% if mode == 'view-all' %} + {% if mode in ['view-all', 'update-fulfillment'] %} Assigned Rider {% else %} Rider Assignment @@ -464,7 +464,7 @@ - {% if mode in ['onestep-edit', 'view-all'] %} + {% if mode in ['onestep-edit', 'view-all', 'update-fulfillment'] %} {% set avail_riders = obj.getHub.getAvailableRiders|default([]) %} @@ -474,7 +474,7 @@ {% if obj.getHub %} {% for rider in avail_riders %} - {% if mode == 'view-all' %} + {% if mode in ['view-all', 'update-fulfillment'] %} {% else %} @@ -512,9 +512,9 @@
- {% for key, sc in service_charges %} - + {% endfor %}
@@ -653,7 +653,7 @@
{% if mode != 'view-all' %} - + {% if ftags.set_map_coordinate and is_granted('joborder.cancel') and not obj.isCancelled %} Cancel Job Order {% endif %} @@ -801,7 +801,7 @@ $(function() { }); {% endif %} - {% if mode in ['view-all'] %} + {% if mode in ['view-all', 'update-fulfillment'] %} var hub_table = ''; $.getJSON("{{ url('hub_nearest') }}?lat=" + lat + "&long=" + lng, function(data) { var hubs = data['hubs']; @@ -963,7 +963,7 @@ $(function() { {% endif %} }); - {% if mode in ['onestep-edit', 'view-all'] %} + {% if mode in ['onestep-edit', 'view-all', 'update-fulfillment'] %} var lat = {{ obj.getCoordinates.getLatitude }}; var lng = {{ obj.getCoordinates.getLongitude }}; @@ -1357,7 +1357,7 @@ $(function() { var sc_array = []; // populate invoiceItems if editing so that we don't lose the battery - {% if mode in ['view-all', 'open-edit', 'onestep-edit', 'walk-in-edit'] %} + {% if mode in ['view-all', 'open-edit', 'onestep-edit', 'walk-in-edit', 'update-fulfillment'] %} {% if (obj.getInvoice and obj.getInvoice.getItems|length > 0) %} {% for item in obj.getInvoice.getItems %} {% if item.getBattery() %} diff --git a/templates/job-order/cmb.list.fulfillment.html.twig b/templates/job-order/cmb.list.fulfillment.html.twig new file mode 100644 index 00000000..7cd98ad3 --- /dev/null +++ b/templates/job-order/cmb.list.fulfillment.html.twig @@ -0,0 +1,183 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Job Orders (Fulfillment) +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+
+ +
+
+
+
+
+
+ +
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/job-order/cmb.list.open.html.twig b/templates/job-order/cmb.list.open.html.twig new file mode 100644 index 00000000..bffdfd6c --- /dev/null +++ b/templates/job-order/cmb.list.open.html.twig @@ -0,0 +1,190 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Job Orders (Open) +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+
+ +
+
+
+
+
+
+ +
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} From 9125a0d2faf4c8b2cf0978e0fc185c0b6bcc7a5c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 21 Feb 2020 03:22:17 +0000 Subject: [PATCH 38/67] Moved invoice code out of JO controller. #354 --- src/Controller/JobOrderController.php | 11 ++--------- .../InvoiceGenerator/CMBInvoiceGenerator.php | 19 +++++++++++++++++++ .../InvoiceGenerator/ResqInvoiceGenerator.php | 16 +++++++++++++++- src/Service/InvoiceGeneratorInterface.php | 3 +++ 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 44265309..3c8ad158 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -696,7 +696,7 @@ class JobOrderController extends Controller $items = $req->request->get('items'); $promo_id = $req->request->get('promo'); $cvid = $req->request->get('cvid'); - $service_charges = $req->request->get('service_charges'); + $service_charges = $req->request->get('service_charges', []); $em = $this->getDoctrine()->getManager(); @@ -740,14 +740,7 @@ class JobOrderController extends Controller } */ - // TODO: this snippet should be in the invoice generator - $error = $ic->validateDiscount($criteria, $promo_id); - - // process service charges - $error = $ic->invoiceServiceCharges($criteria, $service_charges); - - if (!$error) - $error = $ic->invoiceBatteries($criteria, $items); + $error = $ic->generateDraftInvoice($criteria, $promo_id, $service_charges, $items); if ($error) { diff --git a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php index cc1cb020..534600fb 100644 --- a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php @@ -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) { $vat_ex_price = $this->getTaxExclusivePrice($price); diff --git a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php index f9aad46a..2999d622 100644 --- a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php @@ -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) { $vat_ex_price = $this->getTaxExclusivePrice($price); @@ -227,7 +241,7 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface 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 // check service type diff --git a/src/Service/InvoiceGeneratorInterface.php b/src/Service/InvoiceGeneratorInterface.php index 85407c30..3e1c5f88 100644 --- a/src/Service/InvoiceGeneratorInterface.php +++ b/src/Service/InvoiceGeneratorInterface.php @@ -15,4 +15,7 @@ interface InvoiceGeneratorInterface // generate invoice criteria 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); + } From e93e0dd9431d83290ee3d815a4f614b291dba132 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 21 Feb 2020 05:10:11 +0000 Subject: [PATCH 39/67] Bug fix for loading JO form for edit. #354 --- templates/job-order/form.html.twig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index a0e5985c..bba70b39 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -47,6 +47,9 @@
+ {% if mode in ['update-assigning', 'update-processing', 'update-reassign-hub', 'update-reassign-rider', 'update-all', 'open_edit'] %} + + {% endif %}
{% if ftags.vehicle_dropdown %} From 4b9b3622d5232a6647b0d90685e5dfb588f7bde4 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 24 Feb 2020 03:06:47 +0000 Subject: [PATCH 40/67] Fix to display service charge amount when loading an existing JO. #355 --- .../JobOrderHandler/CMBJobOrderHandler.php | 17 ++++++++++++++++- templates/job-order/cmb.form.onestep.html.twig | 6 +++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 06f1fb72..e61108bf 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -1407,7 +1407,22 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $params['mode'] = 'onestep-edit'; $params['cvid'] = $obj->getCustomerVehicle()->getID(); $params['vid'] = $obj->getCustomerVehicle()->getVehicle()->getID(); - $params['jo_service_charges'] = $obj->getMeta('service_charges'); + + // get service charges + $sc_array = []; + $jo_service_charges = $obj->getMeta('service_charges'); + if (!(empty($jo_service_charges))) + { + foreach ($jo_service_charges as $jo_sc_id) + { + // find service charge + $sc_obj = $em->getRepository(ServiceCharge::class)->find($jo_sc_id); + + $sc_array[] = $sc_obj; + } + } + + $params['jo_service_charges'] = $sc_array; $this->fillDropdownParameters($params); $this->fillFormTags($params); diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 4c913bca..c5246ddb 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -508,19 +508,19 @@ {% endif %}
- {% for jo_sc_key, jo_sc in obj.getMeta('service_charges')|default([]) %} + {% for jo_sc in jo_service_charges %}
- +
From 230dd4105545079b6df93405936092e7bfe98525 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 24 Feb 2020 07:57:43 +0000 Subject: [PATCH 41/67] Add jo_service_charges to one step form. #355 --- src/Service/JobOrderHandler/CMBJobOrderHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index e61108bf..3e2d85b1 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -1387,6 +1387,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface { $params['obj'] = new JobOrder(); $params['mode'] = 'onestep'; + $params['jo_service_charges'] = []; $this->fillDropdownParameters($params); $this->fillFormTags($params); From 1a0fb13268addf1d9a41c1720c9b69f37099676b Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Mon, 24 Feb 2020 16:43:27 +0800 Subject: [PATCH 42/67] Fix view all edit button to use one step edit for CMB #270 --- src/Controller/JobOrderController.php | 6 ++++-- src/Service/JobOrderHandler/CMBJobOrderHandler.php | 5 +++++ src/Service/JobOrderHandler/ResqJobOrderHandler.php | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index c06383c7..f04ba047 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -276,12 +276,14 @@ class JobOrderController extends Controller { $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']['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']['onestep_edit_url'] = $this->generateUrl('jo_onestep_edit_form', ['id' => $jo_id]); } 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']['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]); } diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 36062f7e..7e4c9bb6 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -2984,4 +2984,9 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface ->setParameter('status', $status); } } + + public function getEditRoute() + { + return 'jo_onestep_edit_form'; + } } diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index c6a6fa01..12995e56 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -2587,4 +2587,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setParameter('status', $status); } } + + public function getEditRoute() + { + } } From 4700d2b84035597828d90a4b1e103832aa7fa0ec Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 24 Feb 2020 09:28:38 +0000 Subject: [PATCH 43/67] Remove link to list of JOs ready to be fulfilled. #270 --- config/cmb.menu.yaml | 4 ---- config/menu.yaml | 4 ---- 2 files changed, 8 deletions(-) diff --git a/config/cmb.menu.yaml b/config/cmb.menu.yaml index 7c6b4d82..9f28b315 100644 --- a/config/cmb.menu.yaml +++ b/config/cmb.menu.yaml @@ -110,10 +110,6 @@ main_menu: acl: jo_walkin.form label: Walk-in parent: joborder - - id: jo_fulfill - acl: jo_fulfill.list - label: Fulfillment - parent: joborder - id: jo_open acl: jo_open.list label: Open diff --git a/config/menu.yaml b/config/menu.yaml index 7c6b4d82..9f28b315 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -110,10 +110,6 @@ main_menu: acl: jo_walkin.form label: Walk-in parent: joborder - - id: jo_fulfill - acl: jo_fulfill.list - label: Fulfillment - parent: joborder - id: jo_open acl: jo_open.list label: Open From 22be1eaf5a29938d9fda1348a79d456935abe874 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 24 Feb 2020 10:33:13 +0000 Subject: [PATCH 44/67] Fix edit for walkin JOs. #270 --- src/Controller/JobOrderController.php | 8 ++++---- src/Service/JobOrderHandler/CMBJobOrderHandler.php | 12 ++++++++++-- templates/job-order/cmb.form.walkin.html.twig | 9 ++------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index edddc3f1..dad6a8d4 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -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_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_handler->getEditRoute(), ['id' => $jo_id]); + $rows[$key]['meta']['edit_url'] = $this->generateUrl($jo_handler->getEditRoute($jo_id), ['id' => $jo_id]); $rows[$key]['meta']['onestep_edit_url'] = $this->generateUrl('jo_onestep_edit_form', ['id' => $jo_id]); } else { // $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), ['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]); } @@ -1037,12 +1037,12 @@ class JobOrderController extends Controller 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.'); $error_array = []; - $error_array = $jo_handler->processOneStepJobOrder($req, $id); + $error_array = $jo_handler->processWalkinJobOrder($req, $id); // check if any errors were found if (!empty($error_array)) { diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index d109d4c3..2e16f2e9 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -2997,8 +2997,16 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface } } - public function getEditRoute() + public function getEditRoute($jo_id) { - 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'; } } diff --git a/templates/job-order/cmb.form.walkin.html.twig b/templates/job-order/cmb.form.walkin.html.twig index f2e02e44..667d84e3 100644 --- a/templates/job-order/cmb.form.walkin.html.twig +++ b/templates/job-order/cmb.form.walkin.html.twig @@ -347,7 +347,7 @@ {% endif %} - +
@@ -557,7 +557,7 @@ function get_vehicle_makes(mfg_id, vid = 0) { $(function() { var form_in_process = false; - var selected_hub = ''; + var selected_hub = '{{ obj.getHub ? obj.getHub.getID : "" }}'; $(function() { $('#hubs-table').on('click', 'tr', function() { @@ -592,11 +592,6 @@ $(function() { // add invoice items to data fields['invoice_items'] = invoiceItems; - {% if mode in ['update-processing', 'update-reassign-hub'] %} - // add selected hub to data - fields['hub'] = selectedHub; - {% endif %} - e.preventDefault(); $.ajax({ From d534ce3241ab440d30646068e8da81cd8d798bd4 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 25 Feb 2020 03:37:58 +0000 Subject: [PATCH 45/67] Add getEditRoute for resq. #357 --- src/Controller/JobOrderController.php | 4 +-- .../JobOrderHandler/ResqJobOrderHandler.php | 27 ++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index dad6a8d4..da68cf5a 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -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_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_handler->getEditRoute($jo_id), ['id' => $jo_id]); + $rows[$key]['meta']['edit_url'] = $this->generateUrl($jo_handler->getEditRoute($jo_id, $tier_params), ['id' => $jo_id]); $rows[$key]['meta']['onestep_edit_url'] = $this->generateUrl('jo_onestep_edit_form', ['id' => $jo_id]); } else { // $rows[$key]['meta']['update_url'] = $this->generateUrl($tier_params['edit_route'], ['id' => $jo_id]); - $rows[$key]['meta']['update_url'] = $this->generateUrl($jo_handler->getEditRoute($jo_id), ['id' => $jo_id]); + $rows[$key]['meta']['update_url'] = $this->generateUrl($jo_handler->getEditRoute($jo_id, $tier_params), ['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]); } diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 12995e56..9372b8a5 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -2588,7 +2588,32 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface } } - public function getEditRoute() + public function getEditRoute($jo_id, $tier) { + $edit_route = ''; + + if (empty($tier)) + return $edit_route; + + switch ($tier) + { + case 'proc': + $edit_route = 'jo_proc_form'; + break; + case 'assign': + $edit_route = 'jo_assign_form'; + break; + case 'fulfill': + $edit_route = 'jo_fulfill_form'; + break; + case 'all': + $edit_route = 'jo_all_form'; + break; + default: + // do nothing + // for 'open', edit route is blank + } + + return $edit_route; } } From 3d40bc62383f28982363681f0213bc9299d47ee2 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 25 Feb 2020 07:18:55 +0000 Subject: [PATCH 46/67] Remove links to onestep edit from templates for resq. Fix for getEditRoute issues found during testing. #357 --- src/Controller/JobOrderController.php | 4 +-- .../JobOrderHandler/ResqJobOrderHandler.php | 25 ++----------------- .../job-order/list.fulfillment.html.twig | 2 +- templates/job-order/list.open.html.twig | 3 --- 4 files changed, 5 insertions(+), 29 deletions(-) diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 9388de32..1d1d84c1 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -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_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_handler->getEditRoute($jo_id, $tier_params), ['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]); } else { // $rows[$key]['meta']['update_url'] = $this->generateUrl($tier_params['edit_route'], ['id' => $jo_id]); - $rows[$key]['meta']['update_url'] = $this->generateUrl($jo_handler->getEditRoute($jo_id, $tier_params), ['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']['pdf_url'] = $this->generateUrl('jo_pdf_form', ['id' => $jo_id]); } diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 9372b8a5..e98eaa45 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -2590,30 +2590,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface public function getEditRoute($jo_id, $tier) { - $edit_route = ''; - if (empty($tier)) - return $edit_route; + return 'jo_open_edit_form'; - switch ($tier) - { - case 'proc': - $edit_route = 'jo_proc_form'; - break; - case 'assign': - $edit_route = 'jo_assign_form'; - break; - case 'fulfill': - $edit_route = 'jo_fulfill_form'; - break; - case 'all': - $edit_route = 'jo_all_form'; - break; - default: - // do nothing - // for 'open', edit route is blank - } - - return $edit_route; + return $tier; } } diff --git a/templates/job-order/list.fulfillment.html.twig b/templates/job-order/list.fulfillment.html.twig index 8115866d..66d3c837 100644 --- a/templates/job-order/list.fulfillment.html.twig +++ b/templates/job-order/list.fulfillment.html.twig @@ -135,7 +135,7 @@ sortable: false, overflow: 'visible', template: function (row, index, datatable) { - var actions = '' + ''; + var actions = ''; return actions; }, diff --git a/templates/job-order/list.open.html.twig b/templates/job-order/list.open.html.twig index 451d8492..3a407009 100644 --- a/templates/job-order/list.open.html.twig +++ b/templates/job-order/list.open.html.twig @@ -148,9 +148,6 @@ {% if is_granted('jo_open.edit') %} actions += ''; {% endif %} - {% if is_granted('jo_onestep.edit') %} - actions += ''; - {% endif %} return actions; }, From 164e091c1571f0235666714efa90e36887d91070 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 25 Feb 2020 08:39:30 +0000 Subject: [PATCH 47/67] Remove color field from pdf form. #359 --- src/Service/JobOrderHandler/CMBJobOrderHandler.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 2e16f2e9..1d06a1c8 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -2069,13 +2069,6 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $pdf->Cell($label_width, $line_height, 'Plate Number:'); $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 $y2 = $pdf->GetY(); From 2ab0055286bdbe6b5504873875ac54223cece0e0 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 25 Feb 2020 09:09:51 +0000 Subject: [PATCH 48/67] Clear battery details when New Customer toggle is on. #358 --- templates/job-order/cmb.form.onestep.html.twig | 7 ++++--- templates/job-order/cmb.form.walkin.html.twig | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index c5246ddb..acd88d56 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -206,17 +206,17 @@
- +
- +
- +
@@ -1270,6 +1270,7 @@ $(function() { $('.cust_field').val(''); $('.cv_field').val(''); $('#cv-make').val(''); + $('.battery_field').val(''); } else { $('.cust_field').prop('disabled', true); $('.cv_field').prop('disabled', true); diff --git a/templates/job-order/cmb.form.walkin.html.twig b/templates/job-order/cmb.form.walkin.html.twig index 667d84e3..a72973bd 100644 --- a/templates/job-order/cmb.form.walkin.html.twig +++ b/templates/job-order/cmb.form.walkin.html.twig @@ -206,17 +206,17 @@
- +
- +
- +
@@ -806,6 +806,7 @@ var vdata = false; $('.cust_field').val(''); $('.cv_field').val(''); $('#cv-make').val(''); + $('.battery_field').val(''); } else { $('.cust_field').prop('disabled', true); $('.cv_field').prop('disabled', true); From a0f7ca6abed210df3a6009c0119cf1f73ff0668c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 27 Feb 2020 02:07:30 +0000 Subject: [PATCH 49/67] Fix editRoute parameters for CMB. #357 --- src/Service/JobOrderHandler/CMBJobOrderHandler.php | 2 +- src/Service/JobOrderHandler/ResqJobOrderHandler.php | 3 +++ src/Service/JobOrderHandlerInterface.php | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 2e16f2e9..422f5fb7 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -2997,7 +2997,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface } } - public function getEditRoute($jo_id) + public function getEditRoute($jo_id, $tier = null) { $jo = $this->em->getRepository(JobOrder::class)->find($jo_id); if (empty($jo)) diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index e98eaa45..a12e09d5 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -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)) { // get current user $user = $this->security->getUser(); diff --git a/src/Service/JobOrderHandlerInterface.php b/src/Service/JobOrderHandlerInterface.php index 5593d10c..590a0926 100644 --- a/src/Service/JobOrderHandlerInterface.php +++ b/src/Service/JobOrderHandlerInterface.php @@ -98,4 +98,7 @@ interface JobOrderHandlerInterface // check if service type is new battery public function checkIfNewBattery(JobOrder $jo); + + // return the edit route, based on tier and form + public function getEditRoute(int $jo_id, $tier); } From 1ab5909dfd6722b03369abbec45764f1ad659ff1 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Sat, 29 Feb 2020 23:38:05 +0800 Subject: [PATCH 50/67] Add priority field for JobOrder #360 --- src/Entity/JobOrder.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Entity/JobOrder.php b/src/Entity/JobOrder.php index 36834cc1..faa427b0 100644 --- a/src/Entity/JobOrder.php +++ b/src/Entity/JobOrder.php @@ -280,6 +280,14 @@ class JobOrder */ 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; + public function __construct() { $this->date_create = new DateTime(); @@ -297,6 +305,8 @@ class JobOrder $this->trade_in_type = null; $this->flag_rider_rating = false; $this->flag_coolant = false; + + $this->priority = 0; } public function getID() @@ -802,4 +812,15 @@ class JobOrder { return $this->hub_rejections; } + + public function setPriority($priority) + { + $this->priority = $priority; + return $this; + } + + public function getPriority() + { + return $this->priority; + } } From 07753274c33d8e6acd879b8e5481ebaa5bd5af4a Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Sun, 1 Mar 2020 22:14:13 +0800 Subject: [PATCH 51/67] Add initial job order prioritization features #360 --- config/routes/rider.yaml | 10 +++++++ src/Controller/RiderController.php | 45 ++++++++++++++++++++++++++++++ src/Entity/Rider.php | 1 + templates/rider/form.html.twig | 10 +++++++ 4 files changed, 66 insertions(+) diff --git a/config/routes/rider.yaml b/config/routes/rider.yaml index 16a56993..1934a1b1 100644 --- a/config/routes/rider.yaml +++ b/config/routes/rider.yaml @@ -46,3 +46,13 @@ rider_active_jo: path: /riders/{id}/activejo/{jo_id} controller: App\Controller\RiderController::riderActiveJO 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] diff --git a/src/Controller/RiderController.php b/src/Controller/RiderController.php index ace84582..184a649d 100644 --- a/src/Controller/RiderController.php +++ b/src/Controller/RiderController.php @@ -534,6 +534,51 @@ class RiderController extends Controller $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) + { + error_log("HERE"); + error_log($rider->getID()); + error_log($jo->getID()); + + $jos = $rider->getOpenJobOrders(); + + $old_prio = $jo->getPriority(); + $new_prio = $old_prio - 1; + $jo->setPriority($new_prio); + + 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) + { + error_log("HERE"); + error_log($rider->getID()); + error_log($jo->getID()); + return $this->redirecttoRoute('rider_update', ['id' => $rider->getID()]); } } diff --git a/src/Entity/Rider.php b/src/Entity/Rider.php index 53731475..c588cc77 100644 --- a/src/Entity/Rider.php +++ b/src/Entity/Rider.php @@ -61,6 +61,7 @@ class Rider // job orders that the rider has done /** * @ORM\OneToMany(targetEntity="JobOrder", mappedBy="rider") + * @ORM\OrderBy({"priority" = "ASC"}) */ protected $job_orders; diff --git a/templates/rider/form.html.twig b/templates/rider/form.html.twig index a9b0264c..c1c52708 100644 --- a/templates/rider/form.html.twig +++ b/templates/rider/form.html.twig @@ -180,6 +180,16 @@
{{ jo.getDeliveryAddress|default('') }} {% if jo.getID == active_jo_id %}Active{% endif %} + + + + + + + + + + {% if jo.getID != active_jo_id %} From 977559b88dd732279cdd7bbb77f8f3a8fed55461 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Mon, 2 Mar 2020 08:33:50 +0800 Subject: [PATCH 52/67] Set priority properly for job order and handle priority down button #360 --- src/Controller/RiderController.php | 29 ++++++++++++++----- .../JobOrderHandler/CMBJobOrderHandler.php | 16 +++++++++- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/Controller/RiderController.php b/src/Controller/RiderController.php index 184a649d..43f5d6d6 100644 --- a/src/Controller/RiderController.php +++ b/src/Controller/RiderController.php @@ -543,16 +543,14 @@ class RiderController extends Controller */ public function priorityUpJO(EntityManagerInterface $em, Rider $rider, JobOrder $jo) { - error_log("HERE"); - error_log($rider->getID()); - error_log($jo->getID()); - $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 @@ -575,9 +573,26 @@ class RiderController extends Controller */ public function priorityDownJO(EntityManagerInterface $em, Rider $rider, JobOrder $jo) { - error_log("HERE"); - error_log($rider->getID()); - error_log($jo->getID()); + $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()]); } diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 0e676014..50ef719f 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -523,6 +523,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 $discount = $req->request->get('invoice_discount', []); @@ -560,7 +573,8 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface ->setModeOfPayment($req->request->get('mode_of_payment')) ->setLandmark($req->request->get('landmark')) ->setHub($hub) - ->setRider($rider); + ->setRider($rider) + ->setPriority($priority); $jo->addMeta('discount', $discount); $jo->addMeta('service_charges', $service_charges); From 2e3c879fd58470ebb5cc2b9cded4d1bf20e837b7 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Thu, 5 Mar 2020 07:15:26 +0800 Subject: [PATCH 53/67] Support rider status changes in dashboard map #362 --- public/assets/js/dashboard_map.js | 39 +++++++++++++++++++ public/assets/js/map_mqtt.js | 29 +++++++++++++- .../JobOrderActiveCacheListener.php | 1 + templates/home.html.twig | 1 + 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/public/assets/js/dashboard_map.js b/public/assets/js/dashboard_map.js index 4691a11d..6cba7d68 100644 --- a/public/assets/js/dashboard_map.js +++ b/public/assets/js/dashboard_map.js @@ -51,6 +51,32 @@ class DashboardMap { 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) { var my = this; // 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) { console.log(this.rider_markers); var my = this; diff --git a/public/assets/js/map_mqtt.js b/public/assets/js/map_mqtt.js index 6eac1f65..8cf3a6af 100644 --- a/public/assets/js/map_mqtt.js +++ b/public/assets/js/map_mqtt.js @@ -27,18 +27,26 @@ class MapEventHandler { console.log('mqtt connected!'); var my = icontext.invocationContext; - // subscribe to rider locations if (my.options.track_rider) { + // subscribe to rider locations console.log('subscribing to ' + 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) { + // subscribe to jo locations console.log('subscribing to ' + 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); } + } onMessage(msg) { @@ -75,8 +83,24 @@ class MapEventHandler { var lat = parseFloat(pl_split[0]); var lng = parseFloat(pl_split[1]); + // TODO: check if available or not this.dashmap.putRiderAvailableMarker(chan_split[1], lat, lng); 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); break; case "status": + console.log("got status for jo " + payload); switch (payload) { case 'cancel': case 'fulfill': diff --git a/src/EventListener/JobOrderActiveCacheListener.php b/src/EventListener/JobOrderActiveCacheListener.php index 541ce158..b5dbbd83 100644 --- a/src/EventListener/JobOrderActiveCacheListener.php +++ b/src/EventListener/JobOrderActiveCacheListener.php @@ -92,6 +92,7 @@ class JobOrderActiveCacheListener protected function processInactiveJO($jo, $status = 'cancel') { + error_log('got inactive jo, sending mqtt message for ' . $jo->getID()); // remove from redis cache $this->jo_cache->removeActiveJobOrder($jo); diff --git a/templates/home.html.twig b/templates/home.html.twig index b7ac2c24..19e99011 100644 --- a/templates/home.html.twig +++ b/templates/home.html.twig @@ -51,6 +51,7 @@ function initEventHandler(dashmap) { 'track_rider': true, 'channels': { 'rider_location': 'rider/+/location', + 'rider_status': 'rider/+/status', 'jo_location': 'jo/+/location', 'jo_status': 'jo/+/status' }, From de9e803ad460f12b8ed8add3c74dec06478d2cb8 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Thu, 5 Mar 2020 08:57:32 +0800 Subject: [PATCH 54/67] Update rider status when job order status is changed #362 --- .../JobOrderActiveCacheListener.php | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/EventListener/JobOrderActiveCacheListener.php b/src/EventListener/JobOrderActiveCacheListener.php index b5dbbd83..89eedd01 100644 --- a/src/EventListener/JobOrderActiveCacheListener.php +++ b/src/EventListener/JobOrderActiveCacheListener.php @@ -35,6 +35,7 @@ class JobOrderActiveCacheListener $this->processActiveJO($jo); break; // inactive + // NOTE: should never really get here since it's creation case JOStatus::CANCELLED: $this->processInactiveJO($jo, 'cancel'); break; @@ -84,10 +85,23 @@ class JobOrderActiveCacheListener $coords = $jo->getCoordinates(); // TODO: do we put the key in config? + // send jo location $this->mqtt->publish( 'jo/' . $jo->getID() . '/location', $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') @@ -96,11 +110,30 @@ class JobOrderActiveCacheListener // remove from redis cache $this->jo_cache->removeActiveJobOrder($jo); - // TODO: publich to mqtt + // publish to mqtt + // send jo status $this->mqtt->publish( 'jo/' . $jo->getID() . '/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 + ); + } } } From bf535e37f5be0c3d919131043af40beee12ccff0 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Thu, 5 Mar 2020 09:20:16 +0800 Subject: [PATCH 55/67] Make sure rider's active jo is in an open status #362 --- src/Entity/Rider.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Entity/Rider.php b/src/Entity/Rider.php index c588cc77..502d93bc 100644 --- a/src/Entity/Rider.php +++ b/src/Entity/Rider.php @@ -320,7 +320,18 @@ class Rider { // check if we have set a custom active 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 $active_status = [ From e93b6432b0faa1d67e58ba0b061d0bcb1ee2c2f9 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 5 Mar 2020 06:26:50 +0000 Subject: [PATCH 56/67] Add view all form for cmb. #365 --- .../JobOrderHandler/CMBJobOrderHandler.php | 2 +- templates/job-order/cmb.list.all.html.twig | 202 ++++++++++++++++++ 2 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 templates/job-order/cmb.list.all.html.twig diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 50ef719f..61eb09b5 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -2807,7 +2807,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $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_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_edit_form'] = 'job-order/cmb.form.onestep.html.twig'; $this->template_hash['jo_walkin_form'] = 'job-order/cmb.form.walkin.html.twig'; diff --git a/templates/job-order/cmb.list.all.html.twig b/templates/job-order/cmb.list.all.html.twig new file mode 100644 index 00000000..1e8b6511 --- /dev/null +++ b/templates/job-order/cmb.list.all.html.twig @@ -0,0 +1,202 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Job Orders (All) +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+
+ +
+
+
+
+
+
+ +
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} From dafe7e6b1c8a8621e1a4dbde9a7f9630ef025354 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 5 Mar 2020 06:53:26 +0000 Subject: [PATCH 57/67] Modify access to getCustomerVehicles. #366 --- src/Controller/CustomerController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Controller/CustomerController.php b/src/Controller/CustomerController.php index 7421fec0..dcbecc28 100644 --- a/src/Controller/CustomerController.php +++ b/src/Controller/CustomerController.php @@ -181,7 +181,10 @@ class CustomerController extends Controller public function getCustomerVehicles(Request $req, CustomerHandlerInterface $cust_handler) { - if (!$this->isGranted('jo_in.list')) { + if ((!$this->isGranted('jo_onestep.form')) || + (!$this->isGranted('jo_walkin.form')) || + (!$this->isGranted('jo_onestep.edit')) || + (!$this->isGranted('jo_walkin.edit'))) { $exception = $this->createAccessDeniedException('No access.'); throw $exception; } From 624cf2fb7d0df61377c0a0cf9dd6ced463e91822 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 5 Mar 2020 07:17:03 +0000 Subject: [PATCH 58/67] Return the additional values to template. #365 --- .../JobOrderHandler/CMBJobOrderHandler.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 61eb09b5..f0c4437a 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -165,6 +165,25 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface // process rows $rows = []; 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 $row['id'] = $orow->getID(); $row['customer_name'] = $orow->getCustomer()->getFirstName() . ' ' . $orow->getCustomer()->getLastName(); @@ -176,6 +195,9 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $row['flag_advance'] = $orow->isAdvanceOrder(); $row['plate_number'] = $orow->getCustomerVehicle()->getPlateNumber(); $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(); if ($processor == null) From 2e884ff577034828465232ee6695a8da09d73617 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 5 Mar 2020 07:22:38 +0000 Subject: [PATCH 59/67] Add additional columns to list of open JOs. #365 --- templates/job-order/cmb.list.open.html.twig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/templates/job-order/cmb.list.open.html.twig b/templates/job-order/cmb.list.open.html.twig index bffdfd6c..a575e645 100644 --- a/templates/job-order/cmb.list.open.html.twig +++ b/templates/job-order/cmb.list.open.html.twig @@ -111,10 +111,18 @@ 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: 'Area' @@ -127,6 +135,14 @@ field: 'date_schedule', title: 'Scheduled Date' }, + { + field: 'rider_name', + title: 'Rider' + }, + { + field: 'rider_plate_number', + title: 'Rider Plate #' + }, { field: 'status', title: 'Status' From 6a7cb9788e2b2e567d16015810761ff74cde4733 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 5 Mar 2020 08:36:24 +0000 Subject: [PATCH 60/67] Fix access to customer vehicle search for walkin and one step. #366 --- src/Controller/CustomerController.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Controller/CustomerController.php b/src/Controller/CustomerController.php index dcbecc28..9b62df8c 100644 --- a/src/Controller/CustomerController.php +++ b/src/Controller/CustomerController.php @@ -182,9 +182,7 @@ class CustomerController extends Controller public function getCustomerVehicles(Request $req, CustomerHandlerInterface $cust_handler) { if ((!$this->isGranted('jo_onestep.form')) || - (!$this->isGranted('jo_walkin.form')) || - (!$this->isGranted('jo_onestep.edit')) || - (!$this->isGranted('jo_walkin.edit'))) { + (!$this->isGranted('jo_walkin.form'))) { $exception = $this->createAccessDeniedException('No access.'); throw $exception; } From 60fb331b476ea47f592ff4dcbd40458a06d12cc5 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Thu, 5 Mar 2020 23:52:40 +0800 Subject: [PATCH 61/67] Fix role controller issue on saving #270 --- src/Controller/RoleController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/RoleController.php b/src/Controller/RoleController.php index 754ab40c..da4de74c 100644 --- a/src/Controller/RoleController.php +++ b/src/Controller/RoleController.php @@ -248,7 +248,7 @@ class RoleController extends Controller if (!$row->isSuperAdmin()) { // clear first - $row->clearACLAttributes(); + $row->clearACLAccess(); // then add $acl_attribs = $req->request->get('acl'); From 8e3df8f1c44ab04cc5044a5a96fdd0e6f214c6f9 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Fri, 6 Mar 2020 07:42:00 +0800 Subject: [PATCH 62/67] Treat blank serial as null to avoid unique exception in db #270 --- src/Entity/Warranty.php | 2 +- src/Service/WarrantyHandler.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Entity/Warranty.php b/src/Entity/Warranty.php index 113fbb93..d2143966 100644 --- a/src/Entity/Warranty.php +++ b/src/Entity/Warranty.php @@ -149,7 +149,7 @@ class Warranty return $this->id; } - public function setSerial($serial) + public function setSerial($serial = null) { $this->serial = $serial; return $this; diff --git a/src/Service/WarrantyHandler.php b/src/Service/WarrantyHandler.php index 281464bf..6d01eb10 100644 --- a/src/Service/WarrantyHandler.php +++ b/src/Service/WarrantyHandler.php @@ -73,8 +73,11 @@ class WarrantyHandler } // set and save values - $warranty->setSerial($serial) - ->setPlateNumber($plate_number) + if (trim($serial) == '') + $warranty->setSerial(null); + else + $warranty->setSerial($serial); + $warranty->setPlateNumber($plate_number) ->setFirstName($first_name) ->setLastName($last_name) ->setMobileNumber($mobile_number) From c4da604ac83a3506ba51dd9403505bd359d984c3 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 10 Mar 2020 06:07:29 +0000 Subject: [PATCH 63/67] Made plate number a required field if new customer. #367 --- src/Service/JobOrderHandler/CMBJobOrderHandler.php | 8 ++++++++ templates/job-order/cmb.form.onestep.html.twig | 4 +++- templates/job-order/cmb.form.walkin.html.twig | 4 +++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index f0c4437a..4d9d5cab 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -448,6 +448,10 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface if (!($valid_mobile)) $error_array['customer_phone_mobile'] = 'Invalid mobile phone number.'; + // check if plate number is in request + if (empty($req->request->get('cv_plate'))) + $error_array['cv_plate'] = 'Plate number is required.'; + // find the vehicle using vid $new_vehicle = $em->getRepository(Vehicle::class)->find($req->request->get('vid')); if (empty($new_vehicle)) @@ -2463,6 +2467,10 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface if (!($valid_mobile)) $error_array['customer_phone_mobile'] = 'Invalid mobile phone number.'; + // check if plate number is in request + if (empty($req->request->get('cv_plate'))) + $error_array['cv_plate'] = 'Plate number is required.'; + // find the vehicle using vid $new_vehicle = $em->getRepository(Vehicle::class)->find($req->request->get('vid')); if (empty($new_vehicle)) diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index acd88d56..0285813f 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -184,7 +184,9 @@
- +
diff --git a/templates/job-order/cmb.form.walkin.html.twig b/templates/job-order/cmb.form.walkin.html.twig index a72973bd..e628d93b 100644 --- a/templates/job-order/cmb.form.walkin.html.twig +++ b/templates/job-order/cmb.form.walkin.html.twig @@ -184,7 +184,9 @@
- +
From d61d82b6e7d233d02adcd2ca49c855850f6c3930 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 10 Mar 2020 06:22:25 +0000 Subject: [PATCH 64/67] Add default value false to checking for new customer. #367 --- src/Service/JobOrderHandler/CMBJobOrderHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 4d9d5cab..d490ce56 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -436,7 +436,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface } // check if new customer - if ($req->request->get('new_customer')) + if ($req->request->get('new_customer', false)) { if (empty($req->request->get('customer_customer_notes'))) { @@ -2455,7 +2455,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface } // check if new customer - if ($req->request->get('new_customer')) + if ($req->request->get('new_customer', false)) { if (empty($req->request->get('customer_customer_notes'))) { From 63210ab4639bfa645978607e2b00eafe3c996aa1 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 10 Mar 2020 08:16:53 +0000 Subject: [PATCH 65/67] Rename Delivery Instructions to CarFix Details. #369 --- templates/job-order/cmb.form.onestep.html.twig | 2 +- translations/cmb.messages.en.yaml | 2 +- translations/messages.en.yaml | 10 ++++------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 0285813f..7d2344f2 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -321,7 +321,7 @@

- +
diff --git a/translations/cmb.messages.en.yaml b/translations/cmb.messages.en.yaml index 7856b0c8..3e12543b 100644 --- a/translations/cmb.messages.en.yaml +++ b/translations/cmb.messages.en.yaml @@ -11,7 +11,7 @@ battery_size_tradein_other: Trade-in Other add_cust_vehicle_battery_info: This vehicle is using a Motolite battery jo_title_pdf: Res-Q for CMB Job Order country_code_prefix: '+60' -delivery_instructions_label: 'Delivery Instructions - CarFix Job Order No.' +delivery_instructions_label: 'CarFix Details' # images image_logo_login: /assets/images/black-text-logo-01.png diff --git a/translations/messages.en.yaml b/translations/messages.en.yaml index 992f8de9..3e12543b 100644 --- a/translations/messages.en.yaml +++ b/translations/messages.en.yaml @@ -11,7 +11,7 @@ battery_size_tradein_other: Trade-in Other add_cust_vehicle_battery_info: This vehicle is using a Motolite battery jo_title_pdf: Res-Q for CMB Job Order country_code_prefix: '+60' -delivery_instructions_label: 'Delivery Instructions - CarFix Job Order No.' +delivery_instructions_label: 'CarFix Details' # images image_logo_login: /assets/images/black-text-logo-01.png @@ -22,8 +22,6 @@ image_dashboard: /assets/images/century_logo.png image_jo_pdf: /public/assets/images/black-text-logo-01-115x115.png # default point for maps -default_lat: 14.6091 -default_long: 121.0223 -#default_lat: 3.084216 -#default_long: 101.6129996 -default_region: ph +default_lat: 3.084216 +default_long: 101.6129996 +default_region: my From 9327f02623c5e8e0a07c92f7d17a1182a5b9061d Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 10 Mar 2020 09:07:01 +0000 Subject: [PATCH 66/67] Display active job orders of rider. #368 --- templates/rider/popup.html.twig | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/templates/rider/popup.html.twig b/templates/rider/popup.html.twig index 13b201d0..1a9f6e09 100644 --- a/templates/rider/popup.html.twig +++ b/templates/rider/popup.html.twig @@ -1,13 +1,13 @@ {{ rider.getFullName }} -{% set jo = rider.getActiveJobOrder %} -{% if jo is not null %} -{% set cust = jo.getCustomer %} -{% set cv = jo.getCustomerVehicle %} -
-
Job Order #{{ jo.getID }}
-{{ jo.getServiceTypeName }}
-{{ jo.getStatusText }}

-{{ cust.getNameDisplay }}
-{{ cv.getPlateNumber }} +{% set job_orders = rider.getOpenJobOrders %} +{% if job_orders is not empty %} + {% for jo in job_orders %} + {% set cust = jo.getCustomer %} + {% set cv = jo.getCustomerVehicle %} +
+ Job Order #{{ jo.getID }}
+ {{ cust.getNameDisplay }}
+ {{ cv.getPlateNumber }} + {% endfor %} {% endif %} From a3c9c16d51344571c9db9c3931228c08f9012e21 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 10 Mar 2020 09:15:11 +0000 Subject: [PATCH 67/67] Restore active job order for rider. #368 --- templates/rider/popup.html.twig | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/templates/rider/popup.html.twig b/templates/rider/popup.html.twig index 1a9f6e09..15cdc26a 100644 --- a/templates/rider/popup.html.twig +++ b/templates/rider/popup.html.twig @@ -1,13 +1,25 @@ {{ rider.getFullName }} +{% set jo = rider.getActiveJobOrder %} +{% if jo is not null %} +{% set cust = jo.getCustomer %} +{% set cv = jo.getCustomerVehicle %} +
+Job Order #{{ jo.getID }}
+{{ jo.getServiceTypeName }}
+{{ jo.getStatusText }}

+{{ cust.getNameDisplay }}
+{{ cv.getPlateNumber }} +{% endif %} +
{% set job_orders = rider.getOpenJobOrders %} {% if job_orders is not empty %} - {% for jo in job_orders %} - {% set cust = jo.getCustomer %} - {% set cv = jo.getCustomerVehicle %} + {% for job_order in job_orders %} + {% set customer = job_order.getCustomer %} + {% set cust_vehicle = job_order.getCustomerVehicle %}
- Job Order #{{ jo.getID }}
- {{ cust.getNameDisplay }}
- {{ cv.getPlateNumber }} + Job Order #{{ job_order.getID }}
+ {{ customer.getNameDisplay }}
+ {{ cust_vehicle.getPlateNumber }} {% endfor %} {% endif %}