diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 03216a17..023ebd35 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -808,6 +808,7 @@ class APIController extends Controller ->setErrorMessage('Invalid customer vehicle id'); return $res->getReturnResponse(); } + $icrit->setCustomerVehicle($cv); $jo->setCustomerVehicle($cv); // check if customer owns vehicle @@ -946,6 +947,7 @@ class APIController extends Controller ->setErrorMessage('Invalid customer vehicle id'); return $res->getReturnResponse(); } + $icrit->setCustomerVehicle($cv); // check if customer owns vehicle if ($cust->getID() != $cv->getCustomer()->getID()) diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index bf700b57..4ba6e7e0 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -278,7 +278,8 @@ class JobOrderController extends BaseController { // instantiate invoice criteria $criteria = new InvoiceCriteria(); - $criteria->setServiceType($stype); + $criteria->setServiceType($stype) + ->setCustomerVehicle($obj->getCustomerVehicle()); $ierror = $this->invoicePromo($em, $criteria, $req->request->get('invoice_promo')); @@ -456,7 +457,8 @@ class JobOrderController extends BaseController // instantiate invoice criteria $criteria = new InvoiceCriteria(); - $criteria->setServiceType($stype); + $criteria->setServiceType($stype) + ->setCustomerVehicle($cust_vehicle); $ierror = $this->invoicePromo($em, $criteria, $req->request->get('invoice_promo')); $invoice_items = $req->request->get('invoice_items'); @@ -1946,12 +1948,21 @@ class JobOrderController extends BaseController $stype = $req->request->get('stype'); $items = $req->request->get('items'); $promo_id = $req->request->get('promo'); + $cvid = $req->request->get('cvid'); + + $em = $this->getDoctrine()->getManager(); + + // get customer vehicle + $cv = $em->getRepository(CustomerVehicle::class)->find($cvid); + if ($cv == null) + throw new \Exception('Could not get customer vehicle'); + // instantiate invoice criteria $criteria = new InvoiceCriteria(); - $criteria->setServiceType($stype); + $criteria->setServiceType($stype) + ->setCustomerVehicle($cv); - $em = $this->getDoctrine()->getManager(); /* // if it's a jumpstart or troubleshoot only, we know what to charge already diff --git a/src/Ramcar/InvoiceCriteria.php b/src/Ramcar/InvoiceCriteria.php index 9d4ce652..e02e3706 100644 --- a/src/Ramcar/InvoiceCriteria.php +++ b/src/Ramcar/InvoiceCriteria.php @@ -4,11 +4,13 @@ namespace App\Ramcar; use App\Entity\Battery; use App\Entity\Promo; +use App\Entity\CustomerVehicle; class InvoiceCriteria { protected $stype; protected $promos; + protected $cv; // entries are battery and trade-in combos protected $entries; @@ -18,6 +20,7 @@ class InvoiceCriteria $this->stype = 0; $this->promos = []; $this->entries = []; + $this->cv = null; } public function setServiceType($stype) @@ -98,4 +101,15 @@ class InvoiceCriteria { return $this->entries; } + + public function setCustomerVehicle(CustomerVehicle $cv) + { + $this->cv = $cv; + return $this; + } + + public function getCustomerVehicle() + { + return $this->cv; + } } diff --git a/src/Service/InvoiceCreator.php b/src/Service/InvoiceCreator.php index b0588dc8..db36a53b 100644 --- a/src/Service/InvoiceCreator.php +++ b/src/Service/InvoiceCreator.php @@ -6,6 +6,7 @@ use App\Ramcar\InvoiceCriteria; use App\Ramcar\TradeInType; use App\Ramcar\DiscountApply; use App\Ramcar\ServiceType; +use App\Ramcar\FuelType; use App\Entity\Invoice; use App\Entity\InvoiceItem; @@ -267,6 +268,49 @@ class InvoiceCreator $total['total_price'] = 200.00; } + + public function processRefuel(&$total, $invoice, $ftype) + { + $item = new InvoiceItem(); + + // service charge + $item->setInvoice($invoice) + ->setTitle('Service - ' . ServiceType::getName(ServiceType::EMERGENCY_REFUEL)) + ->setQuantity(1) + ->setPrice(200.00); + $invoice->addItem($item); + $total['total_price'] = 200.00; + + $fuel = new InvoiceItem(); + switch ($ftype) + { + case FuelType::GAS: + $fuel->setInvoice($invoice) + ->setTitle('Fuel - Gas') + ->setQuantity(1) + ->setPrice(200); + $invoice->addItem($fuel); + $total['total_price'] += 200.00; + break; + case FuelType::DIESEL: + $fuel->setInvoice($invoice) + ->setTitle('Fuel - Diesel') + ->setQuantity(1) + ->setPrice(150); + $total['total_price'] += 150.00; + $invoice->addItem($fuel); + break; + default: + $fuel->setInvoice($invoice) + ->setTitle('Fuel - Unknown') + ->setQuantity(1) + ->setPrice(0); + $total['total_price'] += 0.00; + $invoice->addItem($fuel); + break; + } + + } public function processCriteria(InvoiceCriteria $criteria) { @@ -311,8 +355,12 @@ class InvoiceCreator break; case ServiceType::TIRE_REPAIR: case ServiceType::OVERHEAT_ASSISTANCE: - case ServiceType::EMERGENCY_REFUEL: $this->processOtherServices($total, $invoice, $stype); + break; + case ServiceType::EMERGENCY_REFUEL: + $ftype = $criteria->getCustomerVehicle()->getFuelType(); + $this->processRefuel($total, $invoice, $ftype); + break; } // TODO: check if any promo is applied diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index d0bec637..01ff0ba7 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -1246,6 +1246,7 @@ $(function() { var promo = $("#invoice-promo").val(); var table = $("#invoice-table tbody"); var stype = $("#service_type").val(); + var cvid = $("#customer-vehicle").val(); // generate invoice values $.ajax({ @@ -1254,7 +1255,8 @@ $(function() { data: { 'stype': stype, 'items': invoiceItems, - 'promo': promo + 'promo': promo, + 'cvid': cvid } }).done(function(response) { var invoice = response.invoice;