98 lines
2.3 KiB
PHP
98 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Invoice;
|
|
|
|
use App\InvoiceInterface;
|
|
|
|
use App\Ramcar\FuelType;
|
|
use App\Ramcar\ServiceType;
|
|
|
|
class Fuel implements InvoiceInterface
|
|
{
|
|
public function check($criteria)
|
|
{
|
|
if ($this->getID() == $criteria->getServiceType())
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
public function getTemplate()
|
|
{
|
|
}
|
|
|
|
public function getID()
|
|
{
|
|
return 'fuel';
|
|
}
|
|
|
|
public function compute($criteria, $stype_fees)
|
|
{
|
|
$stype = $criteria->getServiceType();
|
|
|
|
$items = [];
|
|
|
|
|
|
if ($stype == $this->getID())
|
|
{
|
|
// check if customer vehicle has a motolite battery
|
|
$cv = $criteria->getCustomerVehicle();
|
|
if ($cv->hasMotoliteBattery())
|
|
$fee = 0;
|
|
else
|
|
$fee = $stype_fees['service_fee'];
|
|
|
|
$ftype = $cv->getFuelType();
|
|
|
|
// add the service fee to items
|
|
$qty = 1;
|
|
$items[] = [
|
|
'qty' => $qty,
|
|
'title' => $this->getServiceTitle($ftype),
|
|
'price' => $fee,
|
|
];
|
|
|
|
$stype_fees_id = $this->getID() . '_fee_' . $ftype;
|
|
|
|
switch ($ftype)
|
|
{
|
|
case FuelType::GAS:
|
|
case FuelType::DIESEL:
|
|
$qty = 1;
|
|
$price = $stype_fees[$stype_fees_id];
|
|
$items[] = [
|
|
'qty' => $qty,
|
|
'title' => $this->getTitle($ftype),
|
|
'price' => $price,
|
|
];
|
|
|
|
break;
|
|
default:
|
|
$qty = 1;
|
|
$price = 0;
|
|
$items[] = [
|
|
'qty' => $qty,
|
|
'title' => $this->getTitle('Unknown'),
|
|
'price' => $price,
|
|
];
|
|
break;
|
|
}
|
|
}
|
|
|
|
return $items;
|
|
}
|
|
|
|
protected function getTitle($fuel_type)
|
|
{
|
|
$title = '4L - ' . ucfirst($fuel_type);
|
|
|
|
return $title;
|
|
}
|
|
|
|
protected function getServiceTitle($fuel_type)
|
|
{
|
|
$title = 'Service - ' . ServiceType::getName(ServiceType::EMERGENCY_REFUEL);
|
|
|
|
return $title;
|
|
}
|
|
}
|