From d4e28cd3323adce7fdf67a6eadd17ef10555c617 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Tue, 27 Feb 2018 03:43:30 +0800 Subject: [PATCH] Add service type to invoice computation #27 --- src/Controller/JobOrderController.php | 25 +++++++++++++++++++++++++ src/Ramcar/ServiceType.php | 2 ++ templates/job-order/form.html.twig | 24 +++++++++++++++++------- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 7a2d4e1c..6f3fd3b1 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -925,11 +925,36 @@ class JobOrderController extends BaseController { $error = false; + $stype = $req->request->get('stype'); $items = $req->request->get('items'); $promo_id = $req->request->get('promo'); $em = $this->getDoctrine()->getManager(); + // if it's a jumpstart or troubleshoot only, we know what to charge already + if ($stype == ServiceType::JUMPSTART_TROUBLESHOOT) + { + $invoice = [ + 'price' => 150.00, + 'discount' => 0, + 'trade_in' => 0, + 'vat' => 0, + 'total_price' => 150.00, + 'items' => [] + ]; + $invoice['items'][] = [ + 'title' => 'Troubleshooting fee', + 'quantity' => 1, + 'unit_price' => 150.00, + 'amount' => 150.00 + ]; + + return $this->json([ + 'success' => true, + 'invoice' => $invoice + ]); + } + // instantiate invoice criteria $criteria = new InvoiceCriteria(); diff --git a/src/Ramcar/ServiceType.php b/src/Ramcar/ServiceType.php index c2d657e7..65fe5deb 100644 --- a/src/Ramcar/ServiceType.php +++ b/src/Ramcar/ServiceType.php @@ -6,6 +6,7 @@ class ServiceType extends NameValue { const BATTERY_REPLACEMENT_NEW = 'battery_new'; const BATTERY_REPLACEMENT_WARRANTY = 'battery_warranty'; + const JUMPSTART_TROUBLESHOOT = 'jumpstart_troubleshoot'; const TIRE_REPAIR = 'tire'; const OVERHEAT_ASSITANCE = 'overheat'; const EMERGENCY_REFUEL = 'fuel'; @@ -13,6 +14,7 @@ class ServiceType extends NameValue const COLLECTION = [ 'battery_new' => 'Battery Replacement (New)', 'battery_warranty' => 'Battery Replacement (Under Warranty)', + 'jumpstart_troubleshoot' => 'Jumpstart or Troubleshoot', 'tire' => 'Tire Repair', 'overheat' => 'Overheat Assistance', 'fuel' => 'Emergency Refuel', diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index 9ec1917f..b51d8c6c 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -151,7 +151,7 @@
- {% for key, service in service_types %} @@ -362,13 +362,11 @@
-
+
- -
-
-
- + + +
{% endif %} @@ -993,6 +991,11 @@ $(function() { generateInvoice(); }); + // trigger update when service type is changed + $("#service_type").change(function() { + generateInvoice(); + }); + // reset the invoice table $("#btn-reset-invoice").click(function() { $("#invoice-promo").prop('selectedIndex', 0); @@ -1000,15 +1003,22 @@ $(function() { generateInvoice(); }); + // recompute + $("#btn-recompute-invoice").click(function() { + generateInvoice(); + }); + function generateInvoice() { var promo = $("#invoice-promo").val(); var table = $("#invoice-table tbody"); + var stype = $("#service_type").val(); // generate invoice values $.ajax({ method: "POST", url: "{{ url('jo_gen_invoice') }}", data: { + 'stype': stype, 'items': invoiceItems, 'promo': promo }