Have invoice creator recognize motolite batteries in vehicles and give free services for them

This commit is contained in:
Kendrick Chan 2018-08-20 04:01:38 +08:00
parent 317ac19c52
commit 63a3136d77

View file

@ -17,6 +17,7 @@ use Doctrine\Common\Util\Debug;
class InvoiceCreator class InvoiceCreator
{ {
const VAT_RATE = 0.12; const VAT_RATE = 0.12;
const SERVICE_FEE = 300;
// creates invoice based on the criteria sent // creates invoice based on the criteria sent
public function __construct() public function __construct()
@ -269,13 +270,19 @@ class InvoiceCreator
$total['total_price'] = 200.00; $total['total_price'] = 200.00;
} }
public function processOverheat(&$total, $invoice) public function processOverheat(&$total, $invoice, $cv)
{ {
// free if they have a motolite battery
if ($cv->hasMotoliteBattery())
$fee = 0;
else
$fee = self::SERVICE_FEE;
$item = new InvoiceItem(); $item = new InvoiceItem();
$item->setInvoice($invoice) $item->setInvoice($invoice)
->setTitle('Service - Overheat Assitance') ->setTitle('Service - Overheat Assitance')
->setQuantity(1) ->setQuantity(1)
->setPrice(200.00); ->setPrice($fee);
$invoice->addItem($item); $invoice->addItem($item);
$coolant = new InvoiceItem(); $coolant = new InvoiceItem();
@ -285,39 +292,57 @@ class InvoiceCreator
->setPrice(1600); ->setPrice(1600);
$invoice->addItem($coolant); $invoice->addItem($coolant);
$total['total_price'] = 1800; $total_price = $fee + 1600;
$total['vat_ex_price'] = 1584;
$total['vat'] = 216; $vat = round($total_price * self::VAT_RATE, 2);
$total['total_price'] = $total_price;
$total['vat_ex_price'] = $total_price - $vat;
$total['vat'] = $vat;
} }
public function processTireRepair(&$total, $invoice) public function processTireRepair(&$total, $invoice, $cv)
{ {
// free if they have a motolite battery
if ($cv->hasMotoliteBattery())
$fee = 0;
else
$fee = self::SERVICE_FEE;
$item = new InvoiceItem(); $item = new InvoiceItem();
$item->setInvoice($invoice) $item->setInvoice($invoice)
->setTitle('Service - Flat Tire') ->setTitle('Service - Flat Tire')
->setQuantity(1) ->setQuantity(1)
->setPrice(200.00); ->setPrice($fee);
$invoice->addItem($item); $invoice->addItem($item);
$total_price = $fee;
$total['total_price'] = 200; $vat = round($total_price * self::VAT_RATE, 2);
$total['vat_ex_price'] = 176; $total['total_price'] = $total_price;
$total['vat'] = 24; $total['vat_ex_price'] = $total_price - $vat;
$total['vat'] = $vat;
} }
public function processRefuel(&$total, $invoice, $ftype) public function processRefuel(&$total, $invoice, $cv)
{ {
// free if they have a motolite battery
if ($cv->hasMotoliteBattery())
$fee = 0;
else
$fee = self::SERVICE_FEE;
$ftype = $cv->getFuelType();
$item = new InvoiceItem(); $item = new InvoiceItem();
// service charge // service charge
$item->setInvoice($invoice) $item->setInvoice($invoice)
->setTitle('Service - ' . ServiceType::getName(ServiceType::EMERGENCY_REFUEL)) ->setTitle('Service - ' . ServiceType::getName(ServiceType::EMERGENCY_REFUEL))
->setQuantity(1) ->setQuantity(1)
->setPrice(200.00); ->setPrice($fee);
$invoice->addItem($item); $invoice->addItem($item);
$total['total_price'] = 200.00; $total_price = $fee;
// $total['total_price'] = 200.00;
$fuel = new InvoiceItem(); $fuel = new InvoiceItem();
$sfee = new InvoiceItem();
error_log('fuel type - ' . $ftype); error_log('fuel type - ' . $ftype);
switch ($ftype) switch ($ftype)
{ {
@ -327,30 +352,31 @@ class InvoiceCreator
->setQuantity(1) ->setQuantity(1)
->setPrice(240); ->setPrice(240);
$invoice->addItem($fuel); $invoice->addItem($fuel);
$total['total_price'] += 240.00; $total_price += 240.00;
$total['vat'] = 52.80;
$total['vat_ex_price'] = 387.20;
break; break;
case FuelType::DIESEL: case FuelType::DIESEL:
$fuel->setInvoice($invoice) $fuel->setInvoice($invoice)
->setTitle('4L Fuel - Diesel') ->setTitle('4L Fuel - Diesel')
->setQuantity(1) ->setQuantity(1)
->setPrice(200); ->setPrice(200);
$total['total_price'] += 200.00; $total_price += 200.00;
$total['vat'] = 48.00;
$total['vat_ex_price'] = 352.00;
$invoice->addItem($fuel); $invoice->addItem($fuel);
break; break;
default: default:
// should never get to this point
$fuel->setInvoice($invoice) $fuel->setInvoice($invoice)
->setTitle('Fuel - Unknown') ->setTitle('Fuel - Unknown')
->setQuantity(1) ->setQuantity(1)
->setPrice(0); ->setPrice(0);
$total['total_price'] += 0.00; $total_price += 0.00;
$invoice->addItem($fuel); $invoice->addItem($fuel);
break; break;
} }
$vat = round($total_price * self::VAT_RATE, 2);
$total['total_price'] = $total_price;
$total['vat_ex_price'] = $total_price - $vat;
$total['vat'] = $vat;
} }
public function processCriteria(InvoiceCriteria $criteria) public function processCriteria(InvoiceCriteria $criteria)
@ -367,6 +393,7 @@ class InvoiceCreator
]; ];
$stype = $criteria->getServiceType(); $stype = $criteria->getServiceType();
$cv = $criteria->getCustomerVehicle();
// error_log($stype); // error_log($stype);
switch ($stype) switch ($stype)
{ {
@ -395,16 +422,16 @@ class InvoiceCreator
$this->processReplacement($total, $invoice); $this->processReplacement($total, $invoice);
break; break;
case ServiceType::TIRE_REPAIR: case ServiceType::TIRE_REPAIR:
$this->processTireRepair($total, $invoice); $this->processTireRepair($total, $invoice, $cv);
// $this->processOtherServices($total, $invoice, $stype); // $this->processOtherServices($total, $invoice, $stype);
break; break;
case ServiceType::OVERHEAT_ASSISTANCE: case ServiceType::OVERHEAT_ASSISTANCE:
$this->processOverheat($total, $invoice); $this->processOverheat($total, $invoice, $cv);
break; break;
case ServiceType::EMERGENCY_REFUEL: case ServiceType::EMERGENCY_REFUEL:
error_log('processing refuel'); error_log('processing refuel');
$ftype = $criteria->getCustomerVehicle()->getFuelType(); $ftype = $criteria->getCustomerVehicle()->getFuelType();
$this->processRefuel($total, $invoice, $ftype); $this->processRefuel($total, $invoice, $cv);
break; break;
} }