Resolve "Aggregate Rider Rating" #1689
10 changed files with 386 additions and 256 deletions
|
|
@ -145,6 +145,10 @@ class BatteryReplacementWarranty implements InvoiceRuleInterface
|
|||
$code = 'battery_replacement_warranty_fee';
|
||||
$service = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
|
||||
|
||||
// check if service is null. If null, return null
|
||||
if ($service == null)
|
||||
return null;
|
||||
|
||||
$item_type_id = $item_type->getID();
|
||||
$item_id = $service->getID();
|
||||
|
||||
|
|
|
|||
|
|
@ -11,14 +11,19 @@ use App\Ramcar\ServiceType;
|
|||
|
||||
use App\Entity\ServiceOffering;
|
||||
use App\Entity\CustomerVehicle;
|
||||
use App\Entity\ItemType;
|
||||
|
||||
use App\Service\PriceTierManager;
|
||||
|
||||
class Fuel implements InvoiceRuleInterface
|
||||
{
|
||||
protected $em;
|
||||
protected $pt_manager;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
public function __construct(EntityManagerInterface $em, PriceTierManager $pt_manager)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->pt_manager = $pt_manager;
|
||||
}
|
||||
|
||||
public function getID()
|
||||
|
|
@ -29,6 +34,7 @@ class Fuel implements InvoiceRuleInterface
|
|||
public function compute($criteria, &$total)
|
||||
{
|
||||
$stype = $criteria->getServiceType();
|
||||
$pt_id = $criteria->getPriceTier();
|
||||
|
||||
$items = [];
|
||||
|
||||
|
|
@ -36,7 +42,13 @@ class Fuel implements InvoiceRuleInterface
|
|||
{
|
||||
$cv = $criteria->getCustomerVehicle();
|
||||
|
||||
$fee = $this->getServiceTypeFee($cv);
|
||||
// check if price tier has item price
|
||||
$pt_price = $this->getPriceTierItemPrice($pt_id, $cv);
|
||||
|
||||
if ($pt_price == null)
|
||||
$service_price = $this->getServiceTypeFee($cv);
|
||||
else
|
||||
$service_price = $pt_price;
|
||||
|
||||
$ftype = $cv->getFuelType();
|
||||
|
||||
|
|
@ -46,10 +58,10 @@ class Fuel implements InvoiceRuleInterface
|
|||
'service_type' => $this->getID(),
|
||||
'qty' => $qty,
|
||||
'title' => $this->getServiceTitle($ftype),
|
||||
'price' => $fee,
|
||||
'price' => $service_price,
|
||||
];
|
||||
|
||||
$qty_fee = bcmul($qty, $fee, 2);
|
||||
$qty_fee = bcmul($qty, $service_price, 2);
|
||||
$total_price = $qty_fee;
|
||||
|
||||
switch ($ftype)
|
||||
|
|
@ -57,7 +69,15 @@ class Fuel implements InvoiceRuleInterface
|
|||
case FuelType::GAS:
|
||||
case FuelType::DIESEL:
|
||||
$qty = 1;
|
||||
$price = $this->getFuelFee($ftype);
|
||||
|
||||
// check if price tier has item price for fuel type
|
||||
$pt_price = $this->getPriceTierFuelItemPrice($pt_id, $ftype);
|
||||
|
||||
if ($pt_price == null)
|
||||
$price = $this->getFuelFee($ftype);
|
||||
else
|
||||
$price = $pt_price;
|
||||
|
||||
$items[] = [
|
||||
'service_type' => $this->getID(),
|
||||
'qty' => $qty,
|
||||
|
|
@ -138,6 +158,70 @@ class Fuel implements InvoiceRuleInterface
|
|||
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
|
||||
// check if customer vehicle has a motolite battery
|
||||
// if yes, set the code to the motolite user service fee
|
||||
if ($cv->hasMotoliteBattery())
|
||||
$code = 'motolite_user_service_fee';
|
||||
else
|
||||
$code = 'fuel_service_fee';
|
||||
|
||||
$service = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
|
||||
|
||||
// check if service is null. If null, return null
|
||||
if ($service == null)
|
||||
return null;
|
||||
|
||||
$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 getPriceTierFuelItemPrice($pt_id, $fuel_type)
|
||||
{
|
||||
// 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 = '';
|
||||
if ($fuel_type == FuelType::GAS)
|
||||
$code = 'fuel_gas_fee';
|
||||
if ($fuel_type == FuelType::DIESEL)
|
||||
$code = 'fuel_diesel_fee';
|
||||
$service = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
|
||||
|
||||
// check if service is null. If null, return null
|
||||
if ($service == null)
|
||||
return null;
|
||||
|
||||
$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($fuel_type)
|
||||
{
|
||||
$title = '4L - ' . ucfirst($fuel_type);
|
||||
|
|
|
|||
|
|
@ -8,16 +8,21 @@ use App\InvoiceRuleInterface;
|
|||
|
||||
use App\Entity\ServiceOffering;
|
||||
use App\Entity\CustomerVehicle;
|
||||
use App\Entity\ItemType;
|
||||
|
||||
use App\Ramcar\TransactionOrigin;
|
||||
|
||||
use App\Service\PriceTierManager;
|
||||
|
||||
class Jumpstart implements InvoiceRuleInterface
|
||||
{
|
||||
protected $em;
|
||||
protected $pt_manager;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
public function __construct(EntityManagerInterface $em, PriceTierManager $pt_manager)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->pt_manager = $pt_manager;
|
||||
}
|
||||
|
||||
public function getID()
|
||||
|
|
@ -29,13 +34,21 @@ class Jumpstart implements InvoiceRuleInterface
|
|||
{
|
||||
$stype = $criteria->getServiceType();
|
||||
$source = $criteria->getSource();
|
||||
$pt_id = $criteria->getPriceTier();
|
||||
|
||||
$items = [];
|
||||
|
||||
if ($stype == $this->getID())
|
||||
{
|
||||
$cv = $criteria->getCustomerVehicle();
|
||||
$fee = $this->getServiceTypeFee($source, $cv);
|
||||
|
||||
// check if price tier has item price
|
||||
$pt_price = $this->getPriceTierItemPrice($pt_id, $source, $cv);
|
||||
|
||||
if ($pt_price == null)
|
||||
$price = $this->getServiceTypeFee($source, $cv);
|
||||
else
|
||||
$price = $pt_price;
|
||||
|
||||
// add the service fee to items
|
||||
$qty = 1;
|
||||
|
|
@ -43,10 +56,10 @@ class Jumpstart implements InvoiceRuleInterface
|
|||
'service_type' => $this->getID(),
|
||||
'qty' => $qty,
|
||||
'title' => $this->getServiceTitle(),
|
||||
'price' => $fee,
|
||||
'price' => $price,
|
||||
];
|
||||
|
||||
$qty_price = bcmul($fee, $qty, 2);
|
||||
$qty_price = bcmul($price, $qty, 2);
|
||||
$total['total_price'] = bcadd($total['total_price'], $qty_price, 2);
|
||||
}
|
||||
|
||||
|
|
@ -86,6 +99,45 @@ class Jumpstart implements InvoiceRuleInterface
|
|||
return null;
|
||||
}
|
||||
|
||||
protected function getPriceTierItemPrice($pt_id, $source, $cv)
|
||||
{
|
||||
// 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
|
||||
// check the source of JO
|
||||
// (1) if from app, service fee is 0 if motolite user. jumpstart fee for app if non-motolite user.
|
||||
// (2) any other source, jumpstart fees are charged whether motolite user or not
|
||||
if ($source == TransactionOrigin::MOBILE_APP)
|
||||
{
|
||||
if ($cv->hasMotoliteBattery())
|
||||
$code = 'motolite_user_service_fee';
|
||||
else
|
||||
$code = 'jumpstart_fee_mobile_app';
|
||||
}
|
||||
else
|
||||
$code = 'jumpstart_fee';
|
||||
|
||||
$service = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
|
||||
|
||||
// check if service is null. If null, return null
|
||||
if ($service == null)
|
||||
return null;
|
||||
|
||||
$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 getServiceTitle()
|
||||
{
|
||||
$title = 'Service - Troubleshooting fee';
|
||||
|
|
|
|||
|
|
@ -7,14 +7,19 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||
use App\InvoiceRuleInterface;
|
||||
|
||||
use App\Entity\ServiceOffering;
|
||||
use App\Entity\ItemType;
|
||||
|
||||
use App\Service\PriceTierManager;
|
||||
|
||||
class JumpstartWarranty implements InvoiceRuleInterface
|
||||
{
|
||||
protected $em;
|
||||
protected $pt_manager;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
public function __construct(EntityManagerInterface $em, PriceTierManager $pt_manager)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->pt_manager = $pt_manager;
|
||||
}
|
||||
|
||||
public function getID()
|
||||
|
|
@ -25,12 +30,19 @@ class JumpstartWarranty implements InvoiceRuleInterface
|
|||
public function compute($criteria, &$total)
|
||||
{
|
||||
$stype = $criteria->getServiceType();
|
||||
$pt_id = $criteria->getPriceTier();
|
||||
|
||||
$items = [];
|
||||
|
||||
if ($stype == $this->getID())
|
||||
{
|
||||
$fee = $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;
|
||||
|
||||
// add the service fee to items
|
||||
$qty = 1;
|
||||
|
|
@ -38,10 +50,10 @@ class JumpstartWarranty implements InvoiceRuleInterface
|
|||
'service_type' => $this->getID(),
|
||||
'qty' => $qty,
|
||||
'title' => $this->getServiceTitle(),
|
||||
'price' => $fee,
|
||||
'price' => $price,
|
||||
];
|
||||
|
||||
$qty_price = bcmul($fee, $qty, 2);
|
||||
$qty_price = bcmul($price, $qty, 2);
|
||||
$total['total_price'] = bcadd($total['total_price'], $qty_price, 2);
|
||||
}
|
||||
|
||||
|
|
@ -72,6 +84,33 @@ class JumpstartWarranty implements InvoiceRuleInterface
|
|||
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 = 'jumpstart_warranty_fee';
|
||||
$service = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
|
||||
|
||||
// check if service is null. If null, return null
|
||||
if ($service == null)
|
||||
return null;
|
||||
|
||||
$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 getServiceTitle()
|
||||
{
|
||||
$title = 'Service - Troubleshooting fee';
|
||||
|
|
|
|||
|
|
@ -10,14 +10,19 @@ use App\Ramcar\ServiceType;
|
|||
|
||||
use App\Entity\ServiceOffering;
|
||||
use App\Entity\CustomerVehicle;
|
||||
use App\Entity\ItemType;
|
||||
|
||||
use App\Service\PriceTierManager;
|
||||
|
||||
class Overheat implements InvoiceRuleInterface
|
||||
{
|
||||
protected $em;
|
||||
protected $pt_manager;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
public function __construct(EntityManagerInterface $em, PriceTierManager $pt_manager)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->pt_manager = $pt_manager;
|
||||
}
|
||||
|
||||
public function getID()
|
||||
|
|
@ -29,13 +34,22 @@ class Overheat implements InvoiceRuleInterface
|
|||
{
|
||||
$stype = $criteria->getServiceType();
|
||||
$has_coolant = $criteria->hasCoolant();
|
||||
$pt_id = $criteria->getPriceTier();
|
||||
|
||||
$items = [];
|
||||
|
||||
if ($stype == $this->getID())
|
||||
{
|
||||
$cv = $criteria->getCustomerVehicle();
|
||||
$fee = $this->getServiceTypeFee($cv);
|
||||
|
||||
// check if price tier has item price
|
||||
$pt_price = $this->getPriceTierItemPrice($pt_id, $cv);
|
||||
|
||||
if ($pt_price == null)
|
||||
$price = $this->getServiceTypeFee($cv);
|
||||
else
|
||||
|
||||
$price = $pt_price;
|
||||
|
||||
// add the service fee to items
|
||||
$qty = 1;
|
||||
|
|
@ -43,10 +57,10 @@ class Overheat implements InvoiceRuleInterface
|
|||
'service_type' => $this->getID(),
|
||||
'qty' => $qty,
|
||||
'title' => $this->getServiceTitle(),
|
||||
'price' => $fee,
|
||||
'price' => $price,
|
||||
];
|
||||
|
||||
$qty_fee = bcmul($qty, $fee, 2);
|
||||
$qty_fee = bcmul($qty, $price, 2);
|
||||
$total_price = $qty_fee;
|
||||
|
||||
if ($has_coolant)
|
||||
|
|
@ -112,6 +126,39 @@ class Overheat implements InvoiceRuleInterface
|
|||
return null;
|
||||
}
|
||||
|
||||
protected function getPriceTierItemPrice($pt_id, CustomerVehicle $cv)
|
||||
{
|
||||
// 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 = 'overheat_fee';
|
||||
|
||||
// check if customer vehicle has a motolite battery
|
||||
// if yes, set the code to the motolite user service fee
|
||||
if ($cv->hasMotoliteBattery())
|
||||
$code = 'motolite_user_service_fee';
|
||||
|
||||
$service = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
|
||||
|
||||
// check if service is null. If null, return null
|
||||
if ($service == null)
|
||||
return null;
|
||||
|
||||
$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 getServiceTitle()
|
||||
{
|
||||
$title = 'Service - ' . ServiceType::getName(ServiceType::OVERHEAT_ASSISTANCE);
|
||||
|
|
|
|||
|
|
@ -7,14 +7,19 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||
use App\InvoiceRuleInterface;
|
||||
|
||||
use App\Entity\ServiceOffering;
|
||||
use App\Entity\ItemType;
|
||||
|
||||
use App\Service\PriceTierManager;
|
||||
|
||||
class PostRecharged implements InvoiceRuleInterface
|
||||
{
|
||||
protected $em;
|
||||
protected $pt_manager;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
public function __construct(EntityManagerInterface $em, PriceTierManager $pt_manager)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->pt_manager = $pt_manager;
|
||||
}
|
||||
|
||||
public function getID()
|
||||
|
|
@ -25,22 +30,29 @@ class PostRecharged implements InvoiceRuleInterface
|
|||
public function compute($criteria, &$total)
|
||||
{
|
||||
$stype = $criteria->getServiceType();
|
||||
$pt_id = $criteria->getPriceTier();
|
||||
|
||||
$items = [];
|
||||
|
||||
if ($stype == $this->getID())
|
||||
{
|
||||
$fee = $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;
|
||||
|
||||
$qty = 1;
|
||||
$items[] = [
|
||||
'service_type' => $this->getID(),
|
||||
'qty' => $qty,
|
||||
'title' => $this->getServiceTitle(),
|
||||
'price' => $fee,
|
||||
'price' => $price,
|
||||
];
|
||||
|
||||
$qty_price = bcmul($fee, $qty, 2);
|
||||
$qty_price = bcmul($price, $qty, 2);
|
||||
$total['total_price'] = bcadd($total['total_price'], $qty_price, 2);
|
||||
|
||||
}
|
||||
|
|
@ -72,6 +84,33 @@ class PostRecharged implements InvoiceRuleInterface
|
|||
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 = 'post_recharged_fee';
|
||||
$service = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
|
||||
|
||||
// check if service is null. If null, return null
|
||||
if ($service == null)
|
||||
return null;
|
||||
|
||||
$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 getServiceTitle()
|
||||
{
|
||||
$title = 'Recharge fee';
|
||||
|
|
|
|||
|
|
@ -7,14 +7,19 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||
use App\InvoiceRuleInterface;
|
||||
|
||||
use App\Entity\ServiceOffering;
|
||||
use App\Entity\ItemType;
|
||||
|
||||
use App\Service\PriceTierManager;
|
||||
|
||||
class PostReplacement implements InvoiceRuleInterface
|
||||
{
|
||||
protected $em;
|
||||
protected $pt_manager;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
public function __construct(EntityManagerInterface $em, PriceTierManager $pt_manager)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->pt_manager = $pt_manager;
|
||||
}
|
||||
|
||||
public function getID()
|
||||
|
|
@ -25,22 +30,29 @@ class PostReplacement implements InvoiceRuleInterface
|
|||
public function compute($criteria, &$total)
|
||||
{
|
||||
$stype = $criteria->getServiceType();
|
||||
$pt_id = $criteria->getPriceTier();
|
||||
|
||||
$items = [];
|
||||
|
||||
if ($stype == $this->getID())
|
||||
{
|
||||
$fee = $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;
|
||||
|
||||
$qty = 1;
|
||||
$items[] = [
|
||||
'service_type' => $this->getID(),
|
||||
'qty' => $qty,
|
||||
'title' => $this->getServiceTitle(),
|
||||
'price' => $fee,
|
||||
'price' => $price,
|
||||
];
|
||||
|
||||
$qty_price = bcmul($fee, $qty, 2);
|
||||
$qty_price = bcmul($price, $qty, 2);
|
||||
$total['total_price'] = bcadd($total['total_price'], $qty_price, 2);
|
||||
}
|
||||
|
||||
|
|
@ -71,6 +83,33 @@ class PostReplacement implements InvoiceRuleInterface
|
|||
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 = 'post_replacement_fee';
|
||||
$service = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
|
||||
|
||||
// check if service is null. If null, return null
|
||||
if ($service == null)
|
||||
return null;
|
||||
|
||||
$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 getServiceTitle()
|
||||
{
|
||||
$title = 'Battery replacement';
|
||||
|
|
|
|||
|
|
@ -1,220 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\InvoiceRule;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use App\InvoiceRuleInterface;
|
||||
|
||||
use App\Ramcar\ServiceType;
|
||||
use App\Ramcar\TradeInType;
|
||||
|
||||
use App\Entity\PriceTier as PTEntity;
|
||||
|
||||
class PriceTier implements InvoiceRuleInterface
|
||||
{
|
||||
protected $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function getID()
|
||||
{
|
||||
return 'price_tier';
|
||||
}
|
||||
|
||||
public function compute($criteria, &$total)
|
||||
{
|
||||
$pt_id = $criteria->getPriceTier();
|
||||
|
||||
// get the service type
|
||||
$service_type = $criteria->getServiceType();
|
||||
|
||||
// get price tier
|
||||
$pt = $em->getRepository(PTEntity::class)->find($pt_id);
|
||||
|
||||
// price tier is default
|
||||
if ($pt == null)
|
||||
{
|
||||
// check if service type is battery sales and battery warranty (sometimes they add a battery
|
||||
// for battery warranty
|
||||
if (($service_type == ServiceType::BATTERY_REPLACEMENT_NEW) ||
|
||||
($service_type == ServiceType::BATTERY_REPLACEMENT_WARRANTY))
|
||||
{
|
||||
$items = $this->processBatteryEntries($criteria, $total);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: process the service fees
|
||||
$items = $this->processServiceEntries($criteria, $total);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// get items in price tier
|
||||
$pt_items = $pt->getItemPrices();
|
||||
|
||||
foreach ($pt_items as $pt_item)
|
||||
{
|
||||
// make item price hash
|
||||
$pt_prices[$pt_item->getItemID()] = $pt_item->getPrice();
|
||||
}
|
||||
|
||||
// TODO: finish this
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
public function validatePromo($criteria, $promo_id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function validateInvoiceItems($criteria, $invoice_items)
|
||||
{
|
||||
// check service type. Only battery sales and battery warranty should have invoice items.
|
||||
$stype = $criteria->getServiceType();
|
||||
if (($stype != ServiceType::BATTERY_REPLACEMENT_NEW) &&
|
||||
($stype != ServiceType::BATTERY_REPLACEMENT_WARRANTY))
|
||||
return null;
|
||||
|
||||
// return error if there's a problem, false otherwise
|
||||
if (!empty($invoice_items))
|
||||
{
|
||||
// check if this is a valid battery
|
||||
foreach ($invoice_items as $item)
|
||||
{
|
||||
$battery = $this->em->getRepository(Battery::class)->find($item['battery']);
|
||||
|
||||
if (empty($battery))
|
||||
{
|
||||
$error = 'Invalid battery specified.';
|
||||
return $error;
|
||||
}
|
||||
|
||||
// quantity
|
||||
$qty = $item['quantity'];
|
||||
if ($qty < 1)
|
||||
continue;
|
||||
|
||||
// if this is a trade in, add trade in
|
||||
if (!empty($item['trade_in']) && TradeInType::validate($item['trade_in']))
|
||||
$trade_in = $item['trade_in'];
|
||||
else
|
||||
$trade_in = null;
|
||||
|
||||
$criteria->addEntry($battery, $trade_in, $qty);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function processBatteryEntries($criteria, &$total)
|
||||
{
|
||||
$items = [];
|
||||
|
||||
// get the entries
|
||||
$entries = $criteria->getEntries();
|
||||
foreach($entries as $entry)
|
||||
{
|
||||
$batt = $entry['battery'];
|
||||
$qty = $entry['qty'];
|
||||
$trade_in = null;
|
||||
|
||||
if (isset($entry['trade_in']))
|
||||
$trade_in = $entry['trade_in'];
|
||||
|
||||
$size = $batt->getSize();
|
||||
|
||||
if ($trade_in == null)
|
||||
{
|
||||
// check if battery purchase or battery replacement
|
||||
if ($service_type == ServiceType::BATTERY_REPLACEMENT_NEW)
|
||||
$price = $batt->getSellingPrice();
|
||||
else
|
||||
$price = 0;
|
||||
|
||||
$items[] = [
|
||||
'service_type' => $this->getID(),
|
||||
'battery' => $batt,
|
||||
'qty' => $qty,
|
||||
'title' => $this->getItemTitle($criteria->getServiceType(), $batt),
|
||||
'price' => $price,
|
||||
];
|
||||
|
||||
$qty_price = bcmul($price, $qty, 2);
|
||||
|
||||
$total['sell_price'] = bcadd($total['sell_price'], $qty_price, 2);
|
||||
$total['total_price'] = bcadd($total['total_price'], $qty_price, 2);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
protected function processServiceEntries($criteria, &$total)
|
||||
{
|
||||
}
|
||||
|
||||
protected function getItemTitle($service_type, $battery)
|
||||
{
|
||||
$title ='';
|
||||
|
||||
// TODO: check for service type
|
||||
switch ($service_type) {
|
||||
case (ServiceType::BATTERY_REPLACEMENT_NEW):
|
||||
$title = $battery->getModel()->getName() . ' ' . $battery->getSize()->getName();
|
||||
break;
|
||||
case (ServiceType::BATTERY_REPLACEMENT_WARRANTY):
|
||||
$title = $battery->getModel()->getName() . ' ' . $battery->getSize()->getName() . ' - Service Unit';
|
||||
break;
|
||||
default:
|
||||
$title = '';
|
||||
break;
|
||||
}
|
||||
|
||||
return $title;
|
||||
|
||||
protected function getServiceTitle($service_type, $fuel_type)
|
||||
{
|
||||
$title = '';
|
||||
|
||||
switch ($service_type) {
|
||||
case (ServiceType::JUMPSTART_TROUBLESHOOT):
|
||||
case (ServiceType::JUMPSTART_WARRANTY):
|
||||
$title = 'Service - Troubleshooting fee';
|
||||
break;
|
||||
case (ServiceType::OVERHEAT_ASSISTANCE):
|
||||
$title = 'Service - ' . ServiceType::getName(ServiceType::OVERHEAT_ASSISTANCE);
|
||||
break;
|
||||
case (ServiceType::POST_RECHARGED):
|
||||
$title = 'Recharge fee';
|
||||
break;
|
||||
case (ServiceType::POST_REPLACEMENT):
|
||||
$title = 'Battery replacement';
|
||||
break;
|
||||
case (ServiceType::TIRE_REPAIR):
|
||||
$title = 'Service - Flat Tire';
|
||||
break;
|
||||
case (ServiceType::EMERGENCY_REFUEL):
|
||||
$title = '4L - ' . ucfirst($fuel_type);
|
||||
break;
|
||||
default:
|
||||
$title = '';
|
||||
}
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
protected function getServiceCoolantTitle()
|
||||
{
|
||||
$title = '4L Coolant';
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -8,14 +8,19 @@ use App\InvoiceRuleInterface;
|
|||
|
||||
use App\Entity\ServiceOffering;
|
||||
use App\Entity\CustomerVehicle;
|
||||
use App\Entity\ItemType;
|
||||
|
||||
use App\Service\PriceTierManager;
|
||||
|
||||
class TireRepair implements InvoiceRuleInterface
|
||||
{
|
||||
protected $em;
|
||||
protected $pt_manager;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
public function __construct(EntityManagerInterface $em, PriceTierManager $pt_manager)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->pt_manager = $pt_manager;
|
||||
}
|
||||
|
||||
public function getID()
|
||||
|
|
@ -26,13 +31,21 @@ class TireRepair implements InvoiceRuleInterface
|
|||
public function compute($criteria, &$total)
|
||||
{
|
||||
$stype = $criteria->getServiceType();
|
||||
$pt_id = $criteria->getPriceTier();
|
||||
|
||||
$items = [];
|
||||
|
||||
if ($stype == $this->getID())
|
||||
{
|
||||
$cv = $criteria->getCustomerVehicle();
|
||||
$fee = $this->getServiceTypeFee($cv);
|
||||
|
||||
// check if price tier has item price
|
||||
$pt_price = $this->getPriceTierItemPrice($pt_id, $cv);
|
||||
|
||||
if ($pt_price == null)
|
||||
$price = $this->getServiceTypeFee($cv);
|
||||
else
|
||||
$price = $pt_price;
|
||||
|
||||
// add the service fee to items
|
||||
$qty = 1;
|
||||
|
|
@ -40,10 +53,10 @@ class TireRepair implements InvoiceRuleInterface
|
|||
'service_type' => $this->getID(),
|
||||
'qty' => $qty,
|
||||
'title' => $this->getServiceTitle(),
|
||||
'price' => $fee,
|
||||
'price' => $price,
|
||||
];
|
||||
|
||||
$qty_price = bcmul($fee, $qty, 2);
|
||||
$qty_price = bcmul($price, $qty, 2);
|
||||
$total['total_price'] = bcadd($total['total_price'], $qty_price, 2);
|
||||
}
|
||||
|
||||
|
|
@ -79,6 +92,39 @@ class TireRepair implements InvoiceRuleInterface
|
|||
return null;
|
||||
}
|
||||
|
||||
protected function getPriceTierItemPrice($pt_id, CustomerVehicle $cv)
|
||||
{
|
||||
// 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 = 'tire_repair_fee';
|
||||
|
||||
// check if customer vehicle has a motolite battery
|
||||
// if yes, set the code to the motolite user service fee
|
||||
if ($cv->hasMotoliteBattery())
|
||||
$code = 'motolite_user_service_fee';
|
||||
|
||||
$service = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
|
||||
|
||||
// check if service is null. If null, return null
|
||||
if ($service == null)
|
||||
return null;
|
||||
|
||||
$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 getServiceTitle()
|
||||
{
|
||||
$title = 'Service - Flat Tire';
|
||||
|
|
|
|||
|
|
@ -47,13 +47,13 @@ class InvoiceManager implements InvoiceGeneratorInterface
|
|||
return [
|
||||
new InvoiceRule\BatterySales($this->em, $this->pt_manager),
|
||||
new InvoiceRule\BatteryReplacementWarranty($this->em, $this->pt_manager),
|
||||
new InvoiceRule\Jumpstart($this->em),
|
||||
new InvoiceRule\JumpstartWarranty($this->em),
|
||||
new InvoiceRule\PostRecharged($this->em),
|
||||
new InvoiceRule\PostReplacement($this->em),
|
||||
new InvoiceRule\Overheat($this->em),
|
||||
new InvoiceRule\Fuel($this->em),
|
||||
new InvoiceRule\TireRepair($this->em),
|
||||
new InvoiceRule\Jumpstart($this->em, $this->pt_manager),
|
||||
new InvoiceRule\JumpstartWarranty($this->em, $this->pt_manager),
|
||||
new InvoiceRule\PostRecharged($this->em, $this->pt_manager),
|
||||
new InvoiceRule\PostReplacement($this->em, $this->pt_manager),
|
||||
new InvoiceRule\Overheat($this->em, $this->pt_manager),
|
||||
new InvoiceRule\Fuel($this->em, $this->pt_manager),
|
||||
new InvoiceRule\TireRepair($this->em, $this->pt_manager),
|
||||
new InvoiceRule\DiscountType($this->em),
|
||||
new InvoiceRule\TradeIn(),
|
||||
new InvoiceRule\Tax($this->em),
|
||||
|
|
|
|||
Loading…
Reference in a new issue