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\ServiceOffering;
|
||||
use App\Entity\ItemType;
|
||||
|
||||
use App\Service\PriceTierManager;
|
||||
|
||||
class BatteryReplacementWarranty 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 BatteryReplacementWarranty implements InvoiceRuleInterface
|
|||
public function compute($criteria, &$total)
|
||||
{
|
||||
$stype = $criteria->getServiceType();
|
||||
$pt_id = $criteria->getPriceTier();
|
||||
|
||||
$items = [];
|
||||
if ($stype == $this->getID())
|
||||
|
|
@ -40,7 +46,14 @@ class BatteryReplacementWarranty implements InvoiceRuleInterface
|
|||
{
|
||||
$batt = $entry['battery'];
|
||||
$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[] = [
|
||||
'service_type' => $this->getID(),
|
||||
|
|
@ -117,6 +130,30 @@ class BatteryReplacementWarranty 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 = '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)
|
||||
{
|
||||
$title = $battery->getModel()->getName() . ' ' . $battery->getSize()->getName() . ' - Service Unit';
|
||||
|
|
|
|||
|
|
@ -35,8 +35,6 @@ class BatterySales implements InvoiceRuleInterface
|
|||
$stype = $criteria->getServiceType();
|
||||
$pt = $criteria->getPriceTier();
|
||||
|
||||
error_log('price tier ' . $pt);
|
||||
|
||||
$items = [];
|
||||
if ($stype == $this->getID())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class InvoiceManager implements InvoiceGeneratorInterface
|
|||
// TODO: get list of invoice rules from .env or a json file?
|
||||
return [
|
||||
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\JumpstartWarranty($this->em),
|
||||
new InvoiceRule\PostRecharged($this->em),
|
||||
|
|
|
|||
|
|
@ -35,7 +35,9 @@ class PriceTierManager
|
|||
|
||||
$ip_result = $ip_stmt->executeQuery();
|
||||
|
||||
$actual_price = 0;
|
||||
// results found
|
||||
$actual_price = null;
|
||||
|
||||
// go through rows
|
||||
while ($row = $ip_result->fetchAssociative())
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue