Have invoice creator recognize motolite batteries in vehicles and give free services for them
This commit is contained in:
parent
317ac19c52
commit
63a3136d77
1 changed files with 51 additions and 24 deletions
|
|
@ -17,6 +17,7 @@ use Doctrine\Common\Util\Debug;
|
|||
class InvoiceCreator
|
||||
{
|
||||
const VAT_RATE = 0.12;
|
||||
const SERVICE_FEE = 300;
|
||||
|
||||
// creates invoice based on the criteria sent
|
||||
public function __construct()
|
||||
|
|
@ -269,13 +270,19 @@ class InvoiceCreator
|
|||
$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->setInvoice($invoice)
|
||||
->setTitle('Service - Overheat Assitance')
|
||||
->setQuantity(1)
|
||||
->setPrice(200.00);
|
||||
->setPrice($fee);
|
||||
$invoice->addItem($item);
|
||||
|
||||
$coolant = new InvoiceItem();
|
||||
|
|
@ -285,39 +292,57 @@ class InvoiceCreator
|
|||
->setPrice(1600);
|
||||
$invoice->addItem($coolant);
|
||||
|
||||
$total['total_price'] = 1800;
|
||||
$total['vat_ex_price'] = 1584;
|
||||
$total['vat'] = 216;
|
||||
$total_price = $fee + 1600;
|
||||
|
||||
$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->setInvoice($invoice)
|
||||
->setTitle('Service - Flat Tire')
|
||||
->setQuantity(1)
|
||||
->setPrice(200.00);
|
||||
->setPrice($fee);
|
||||
$invoice->addItem($item);
|
||||
$total_price = $fee;
|
||||
|
||||
$total['total_price'] = 200;
|
||||
$total['vat_ex_price'] = 176;
|
||||
$total['vat'] = 24;
|
||||
$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 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();
|
||||
|
||||
// service charge
|
||||
$item->setInvoice($invoice)
|
||||
->setTitle('Service - ' . ServiceType::getName(ServiceType::EMERGENCY_REFUEL))
|
||||
->setQuantity(1)
|
||||
->setPrice(200.00);
|
||||
->setPrice($fee);
|
||||
$invoice->addItem($item);
|
||||
$total['total_price'] = 200.00;
|
||||
$total_price = $fee;
|
||||
// $total['total_price'] = 200.00;
|
||||
|
||||
$fuel = new InvoiceItem();
|
||||
$sfee = new InvoiceItem();
|
||||
error_log('fuel type - ' . $ftype);
|
||||
switch ($ftype)
|
||||
{
|
||||
|
|
@ -327,30 +352,31 @@ class InvoiceCreator
|
|||
->setQuantity(1)
|
||||
->setPrice(240);
|
||||
$invoice->addItem($fuel);
|
||||
$total['total_price'] += 240.00;
|
||||
$total['vat'] = 52.80;
|
||||
$total['vat_ex_price'] = 387.20;
|
||||
$total_price += 240.00;
|
||||
break;
|
||||
case FuelType::DIESEL:
|
||||
$fuel->setInvoice($invoice)
|
||||
->setTitle('4L Fuel - Diesel')
|
||||
->setQuantity(1)
|
||||
->setPrice(200);
|
||||
$total['total_price'] += 200.00;
|
||||
$total['vat'] = 48.00;
|
||||
$total['vat_ex_price'] = 352.00;
|
||||
$total_price += 200.00;
|
||||
$invoice->addItem($fuel);
|
||||
break;
|
||||
default:
|
||||
// should never get to this point
|
||||
$fuel->setInvoice($invoice)
|
||||
->setTitle('Fuel - Unknown')
|
||||
->setQuantity(1)
|
||||
->setPrice(0);
|
||||
$total['total_price'] += 0.00;
|
||||
$total_price += 0.00;
|
||||
$invoice->addItem($fuel);
|
||||
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)
|
||||
|
|
@ -367,6 +393,7 @@ class InvoiceCreator
|
|||
];
|
||||
|
||||
$stype = $criteria->getServiceType();
|
||||
$cv = $criteria->getCustomerVehicle();
|
||||
// error_log($stype);
|
||||
switch ($stype)
|
||||
{
|
||||
|
|
@ -395,16 +422,16 @@ class InvoiceCreator
|
|||
$this->processReplacement($total, $invoice);
|
||||
break;
|
||||
case ServiceType::TIRE_REPAIR:
|
||||
$this->processTireRepair($total, $invoice);
|
||||
$this->processTireRepair($total, $invoice, $cv);
|
||||
// $this->processOtherServices($total, $invoice, $stype);
|
||||
break;
|
||||
case ServiceType::OVERHEAT_ASSISTANCE:
|
||||
$this->processOverheat($total, $invoice);
|
||||
$this->processOverheat($total, $invoice, $cv);
|
||||
break;
|
||||
case ServiceType::EMERGENCY_REFUEL:
|
||||
error_log('processing refuel');
|
||||
$ftype = $criteria->getCustomerVehicle()->getFuelType();
|
||||
$this->processRefuel($total, $invoice, $ftype);
|
||||
$this->processRefuel($total, $invoice, $cv);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue