Add price tier for battery replacement warranty. #782
This commit is contained in:
parent
b6763bfd3e
commit
c5b395d720
4 changed files with 43 additions and 6 deletions
|
|
@ -11,14 +11,19 @@ use App\Ramcar\TradeInType;
|
||||||
|
|
||||||
use App\Entity\Battery;
|
use App\Entity\Battery;
|
||||||
use App\Entity\ServiceOffering;
|
use App\Entity\ServiceOffering;
|
||||||
|
use App\Entity\ItemType;
|
||||||
|
|
||||||
|
use App\Service\PriceTierManager;
|
||||||
|
|
||||||
class BatteryReplacementWarranty implements InvoiceRuleInterface
|
class BatteryReplacementWarranty implements InvoiceRuleInterface
|
||||||
{
|
{
|
||||||
protected $em;
|
protected $em;
|
||||||
|
protected $pt_manager;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em)
|
public function __construct(EntityManagerInterface $em, PriceTierManager $pt_manager)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
|
$this->pt_manager = $pt_manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getID()
|
public function getID()
|
||||||
|
|
@ -29,6 +34,7 @@ class BatteryReplacementWarranty implements InvoiceRuleInterface
|
||||||
public function compute($criteria, &$total)
|
public function compute($criteria, &$total)
|
||||||
{
|
{
|
||||||
$stype = $criteria->getServiceType();
|
$stype = $criteria->getServiceType();
|
||||||
|
$pt_id = $criteria->getPriceTier();
|
||||||
|
|
||||||
$items = [];
|
$items = [];
|
||||||
if ($stype == $this->getID())
|
if ($stype == $this->getID())
|
||||||
|
|
@ -40,7 +46,14 @@ class BatteryReplacementWarranty implements InvoiceRuleInterface
|
||||||
{
|
{
|
||||||
$batt = $entry['battery'];
|
$batt = $entry['battery'];
|
||||||
$qty = 1;
|
$qty = 1;
|
||||||
$price = $this->getServiceTypeFee();
|
|
||||||
|
// check if price tier has item price
|
||||||
|
$pt_price = $this->getPriceTierItemPrice($pt_id);
|
||||||
|
|
||||||
|
if ($pt_price == null)
|
||||||
|
$price = $this->getServiceTypeFee();
|
||||||
|
else
|
||||||
|
$price = $pt_price;
|
||||||
|
|
||||||
$items[] = [
|
$items[] = [
|
||||||
'service_type' => $this->getID(),
|
'service_type' => $this->getID(),
|
||||||
|
|
@ -117,6 +130,30 @@ class BatteryReplacementWarranty implements InvoiceRuleInterface
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getPriceTierItemPrice($pt_id)
|
||||||
|
{
|
||||||
|
// price_tier is default
|
||||||
|
if ($pt_id == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// find the item type for service offering
|
||||||
|
$item_type = $this->em->getRepository(ItemType::class)->findOneBy(['code' => 'service_offering']);
|
||||||
|
if ($item_type == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// find the service offering
|
||||||
|
$code = 'battery_replacement_warranty_fee';
|
||||||
|
$service = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
|
||||||
|
|
||||||
|
$item_type_id = $item_type->getID();
|
||||||
|
$item_id = $service->getID();
|
||||||
|
|
||||||
|
$price = $this->pt_manager->getItemPrice($pt_id, $item_type_id, $item_id);
|
||||||
|
|
||||||
|
return $price;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function getTitle($battery)
|
protected function getTitle($battery)
|
||||||
{
|
{
|
||||||
$title = $battery->getModel()->getName() . ' ' . $battery->getSize()->getName() . ' - Service Unit';
|
$title = $battery->getModel()->getName() . ' ' . $battery->getSize()->getName() . ' - Service Unit';
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,6 @@ class BatterySales implements InvoiceRuleInterface
|
||||||
$stype = $criteria->getServiceType();
|
$stype = $criteria->getServiceType();
|
||||||
$pt = $criteria->getPriceTier();
|
$pt = $criteria->getPriceTier();
|
||||||
|
|
||||||
error_log('price tier ' . $pt);
|
|
||||||
|
|
||||||
$items = [];
|
$items = [];
|
||||||
if ($stype == $this->getID())
|
if ($stype == $this->getID())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ class InvoiceManager implements InvoiceGeneratorInterface
|
||||||
// TODO: get list of invoice rules from .env or a json file?
|
// TODO: get list of invoice rules from .env or a json file?
|
||||||
return [
|
return [
|
||||||
new InvoiceRule\BatterySales($this->em, $this->pt_manager),
|
new InvoiceRule\BatterySales($this->em, $this->pt_manager),
|
||||||
new InvoiceRule\BatteryReplacementWarranty($this->em),
|
new InvoiceRule\BatteryReplacementWarranty($this->em, $this->pt_manager),
|
||||||
new InvoiceRule\Jumpstart($this->em),
|
new InvoiceRule\Jumpstart($this->em),
|
||||||
new InvoiceRule\JumpstartWarranty($this->em),
|
new InvoiceRule\JumpstartWarranty($this->em),
|
||||||
new InvoiceRule\PostRecharged($this->em),
|
new InvoiceRule\PostRecharged($this->em),
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,9 @@ class PriceTierManager
|
||||||
|
|
||||||
$ip_result = $ip_stmt->executeQuery();
|
$ip_result = $ip_stmt->executeQuery();
|
||||||
|
|
||||||
$actual_price = 0;
|
// results found
|
||||||
|
$actual_price = null;
|
||||||
|
|
||||||
// go through rows
|
// go through rows
|
||||||
while ($row = $ip_result->fetchAssociative())
|
while ($row = $ip_result->fetchAssociative())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue