diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index d50471fe..bdd0b2a0 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, EntityManagerInterface $em) + GISManagerInterface $gis) { $this->denyAccessUnlessGranted('jo_all.list', null, 'No access.'); @@ -618,8 +618,6 @@ 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/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/Entity/JobOrder.php b/src/Entity/JobOrder.php index 08a1f15a..36834cc1 100644 --- a/src/Entity/JobOrder.php +++ b/src/Entity/JobOrder.php @@ -280,12 +280,6 @@ class JobOrder */ protected $hub_rejections; - // meta - /** - * @ORM\Column(type="json") - */ - protected $meta; - public function __construct() { $this->date_create = new DateTime(); @@ -303,8 +297,6 @@ class JobOrder $this->trade_in_type = null; $this->flag_rider_rating = false; $this->flag_coolant = false; - - $this->meta = []; } public function getID() @@ -810,15 +802,4 @@ 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 49290e33..a1fb2568 100644 --- a/src/Ramcar/InvoiceCriteria.php +++ b/src/Ramcar/InvoiceCriteria.php @@ -12,7 +12,8 @@ class InvoiceCriteria protected $promos; protected $cv; protected $flag_coolant; - protected $discount; + // for discount and other info + protected $meta; // entries are battery and trade-in combos protected $entries; @@ -24,7 +25,7 @@ class InvoiceCriteria $this->entries = []; $this->cv = null; $this->flag_coolant = false; - $this->discount = 0; + $this->meta = []; } public function setServiceType($stype) @@ -128,14 +129,14 @@ class InvoiceCriteria return $this->flag_coolant; } - public function setDiscount($discount) + public function addMeta($id, $value) { - $this->discount = $discount; + $this->meta[$id] = $value; return $this; } - public function getDiscount() + public function getMeta() { - return $this->discount; + return $this->meta; } } diff --git a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php index 73f4524e..fa13b752 100644 --- a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php @@ -229,17 +229,18 @@ 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 or negative number - if (($discount > 50) || ($discount < 0)) + // check if discount is greater than 50 + if ($discount > 50) return 'Invalid discount specified'; - $criteria->setDiscount($discount); + $criteria->addMeta('discount', $discount); return false; } @@ -384,7 +385,16 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface protected function processDiscount(&$total, InvoiceCriteria $criteria, Invoice $invoice) { - $discount = $criteria->getDiscount(); + $rate = 0; + $meta = $criteria->getMeta(); + if (isset($meta['discount'])) + $rate = $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) diff --git a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php index f9aad46a..c5e9c81c 100644 --- a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php @@ -18,7 +18,6 @@ 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 cfdab814..ee83970f 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -522,13 +522,6 @@ 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 @@ -558,9 +551,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface ->setHub($hub) ->setRider($rider); - $jo->addMeta('discount', $discount); - - // check if user is null, meaning call to create came from API + // check if user is null, meaning call to create came from API if ($user != null) { $jo->setCreatedBy($user); @@ -2497,13 +2488,6 @@ 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 @@ -2529,8 +2513,6 @@ 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) { @@ -2688,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 34fe7af4..b91c0a2c 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -1268,21 +1268,6 @@ $(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 8f764956..1e3d8f9b 100644 --- a/templates/job-order/cmb.form.walkin.html.twig +++ b/templates/job-order/cmb.form.walkin.html.twig @@ -395,13 +395,22 @@
{% if ftags.invoice_edit %} - +
{% else %} - + {% endif %}
-
+
+ + +
+
@@ -883,21 +892,6 @@ 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();