Merge branch '135-fix-fuel-pricing' into 'master'

Resolve "Fix fuel pricing"

Closes #135

See merge request jankstudio/resq!121
This commit is contained in:
Kendrick Chan 2018-06-03 23:49:21 +00:00
commit 07dbaed89e
5 changed files with 83 additions and 6 deletions

View file

@ -815,6 +815,7 @@ class APIController extends Controller
->setErrorMessage('Invalid customer vehicle id'); ->setErrorMessage('Invalid customer vehicle id');
return $res->getReturnResponse(); return $res->getReturnResponse();
} }
$icrit->setCustomerVehicle($cv);
$jo->setCustomerVehicle($cv); $jo->setCustomerVehicle($cv);
// check if customer owns vehicle // check if customer owns vehicle
@ -953,6 +954,7 @@ class APIController extends Controller
->setErrorMessage('Invalid customer vehicle id'); ->setErrorMessage('Invalid customer vehicle id');
return $res->getReturnResponse(); return $res->getReturnResponse();
} }
$icrit->setCustomerVehicle($cv);
// check if customer owns vehicle // check if customer owns vehicle
if ($cust->getID() != $cv->getCustomer()->getID()) if ($cust->getID() != $cv->getCustomer()->getID())

View file

@ -278,7 +278,8 @@ class JobOrderController extends BaseController
{ {
// instantiate invoice criteria // instantiate invoice criteria
$criteria = new InvoiceCriteria(); $criteria = new InvoiceCriteria();
$criteria->setServiceType($stype); $criteria->setServiceType($stype)
->setCustomerVehicle($obj->getCustomerVehicle());
$ierror = $this->invoicePromo($em, $criteria, $req->request->get('invoice_promo')); $ierror = $this->invoicePromo($em, $criteria, $req->request->get('invoice_promo'));
@ -456,7 +457,8 @@ class JobOrderController extends BaseController
// instantiate invoice criteria // instantiate invoice criteria
$criteria = new InvoiceCriteria(); $criteria = new InvoiceCriteria();
$criteria->setServiceType($stype); $criteria->setServiceType($stype)
->setCustomerVehicle($cust_vehicle);
$ierror = $this->invoicePromo($em, $criteria, $req->request->get('invoice_promo')); $ierror = $this->invoicePromo($em, $criteria, $req->request->get('invoice_promo'));
$invoice_items = $req->request->get('invoice_items'); $invoice_items = $req->request->get('invoice_items');
@ -1946,12 +1948,21 @@ class JobOrderController extends BaseController
$stype = $req->request->get('stype'); $stype = $req->request->get('stype');
$items = $req->request->get('items'); $items = $req->request->get('items');
$promo_id = $req->request->get('promo'); $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 // instantiate invoice criteria
$criteria = new InvoiceCriteria(); $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 // if it's a jumpstart or troubleshoot only, we know what to charge already

View file

@ -4,11 +4,13 @@ namespace App\Ramcar;
use App\Entity\Battery; use App\Entity\Battery;
use App\Entity\Promo; use App\Entity\Promo;
use App\Entity\CustomerVehicle;
class InvoiceCriteria class InvoiceCriteria
{ {
protected $stype; protected $stype;
protected $promos; protected $promos;
protected $cv;
// entries are battery and trade-in combos // entries are battery and trade-in combos
protected $entries; protected $entries;
@ -18,6 +20,7 @@ class InvoiceCriteria
$this->stype = 0; $this->stype = 0;
$this->promos = []; $this->promos = [];
$this->entries = []; $this->entries = [];
$this->cv = null;
} }
public function setServiceType($stype) public function setServiceType($stype)
@ -98,4 +101,15 @@ class InvoiceCriteria
{ {
return $this->entries; return $this->entries;
} }
public function setCustomerVehicle(CustomerVehicle $cv)
{
$this->cv = $cv;
return $this;
}
public function getCustomerVehicle()
{
return $this->cv;
}
} }

View file

@ -6,6 +6,7 @@ use App\Ramcar\InvoiceCriteria;
use App\Ramcar\TradeInType; use App\Ramcar\TradeInType;
use App\Ramcar\DiscountApply; use App\Ramcar\DiscountApply;
use App\Ramcar\ServiceType; use App\Ramcar\ServiceType;
use App\Ramcar\FuelType;
use App\Entity\Invoice; use App\Entity\Invoice;
use App\Entity\InvoiceItem; use App\Entity\InvoiceItem;
@ -267,6 +268,49 @@ class InvoiceCreator
$total['total_price'] = 200.00; $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) public function processCriteria(InvoiceCriteria $criteria)
{ {
@ -311,8 +355,12 @@ class InvoiceCreator
break; break;
case ServiceType::TIRE_REPAIR: case ServiceType::TIRE_REPAIR:
case ServiceType::OVERHEAT_ASSISTANCE: case ServiceType::OVERHEAT_ASSISTANCE:
case ServiceType::EMERGENCY_REFUEL:
$this->processOtherServices($total, $invoice, $stype); $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 // TODO: check if any promo is applied

View file

@ -1246,6 +1246,7 @@ $(function() {
var promo = $("#invoice-promo").val(); var promo = $("#invoice-promo").val();
var table = $("#invoice-table tbody"); var table = $("#invoice-table tbody");
var stype = $("#service_type").val(); var stype = $("#service_type").val();
var cvid = $("#customer-vehicle").val();
// generate invoice values // generate invoice values
$.ajax({ $.ajax({
@ -1254,7 +1255,8 @@ $(function() {
data: { data: {
'stype': stype, 'stype': stype,
'items': invoiceItems, 'items': invoiceItems,
'promo': promo 'promo': promo,
'cvid': cvid
} }
}).done(function(response) { }).done(function(response) {
var invoice = response.invoice; var invoice = response.invoice;