From 9bac6df2dfefe0726b63568b28c73fbab18e183c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 29 May 2023 06:05:59 -0400 Subject: [PATCH] Add rules for trade in and other service types. Add test scenarios. #744 --- src/Command/TestInvoiceManagerCommand.php | 556 +++++++++++++++++++++- src/Invoice/Fuel.php | 18 +- src/Invoice/Jumpstart.php | 28 +- src/Invoice/JumpstartWarranty.php | 27 +- src/Invoice/Overheat.php | 51 +- src/Invoice/PostRecharged.php | 26 +- src/Invoice/PostReplacement.php | 26 +- src/Invoice/TireRepair.php | 30 +- src/Invoice/TradeIn.php | 59 ++- src/Service/InvoiceManager.php | 24 +- 10 files changed, 813 insertions(+), 32 deletions(-) diff --git a/src/Command/TestInvoiceManagerCommand.php b/src/Command/TestInvoiceManagerCommand.php index 14c8ff90..68051147 100644 --- a/src/Command/TestInvoiceManagerCommand.php +++ b/src/Command/TestInvoiceManagerCommand.php @@ -15,6 +15,7 @@ use App\InvoiceCriteria; use App\Ramcar\ServiceType; use App\Entity\Battery; +use App\Entity\CustomerVehicle; class TestInvoiceManagerCommand extends Command { @@ -38,14 +39,52 @@ class TestInvoiceManagerCommand extends Command protected function execute(InputInterface $input, OutputInterface $output) { + // battery sales $this->testBatterySalesNoTradeInNoDiscount(); + $this->testBatterySalesQuantityNoTradeInNoDiscount(); + + // battery sales with trade in + $this->testBatterySalesTradeInSameBatteryPremiumNoDiscount(); + $this->testBatterySalesTradeInSameBatteryMotoliteNoDiscount(); + $this->testBatterySalesTradeInSameBatteryOtherNoDiscount(); + $this->testBatterySalesTradeInDifferentBatteryPremiumNoDiscount(); + $this->testBatterySalesTradeInDifferentBatteryMotoliteNoDiscount(); + $this->testBatterySalesTradeInDifferentBatteryOtherNoDiscount(); + $this->testBatterySalesTradeInQuantityNoDiscount(); + + // battery sales with discount + + // battery replacement warranty + $this->testBatteryReplacementWarranty(); + + // fuel + $this->testFuelGasWithServiceFee(); + $this->testFuelDieselWithServiceFee(); + $this->testFuelGasWithNoServiceFee(); + $this->testFuelDieselWithNoServiceFee(); + + // jumpstart + $this->testJumpstart(); + + // jumpstart warranty + $this->testJumpstartWarranty(); + + // overheat + $this->testOverheatAssistanceWithCoolant(); + $this->testOverheatAssistanceWithoutCoolant(); + + // post-recharged + $this->testPostRecharged(); + + // post replacement + $this->testPostReplacement(); + + // tire repair + $this->testTireRepairWithServiceFee(); + $this->testTireRepairWithNoServiceFee(); - // TEST SCENARIO: new battery with trade in // TEST SCENARIO: new battery with discount // TEST SCENARIO: new battery with discount and trade-in - // TEST SCENARIO: fuel, gas - // TEST SCENARIO: fuel, diesel - // TEST SCENARIO: fuel, gas, with discount return 0; } @@ -69,7 +108,514 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log($invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . ServiceType::BATTERY_REPLACEMENT_NEW . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } } + + protected function testBatterySalesQuantityNoTradeInNoDiscount() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: new battery, more than 1, no trade-in, no discount + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + $criteria->addEntry($battery, null, 2); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::BATTERY_REPLACEMENT_NEW . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testBatterySalesTradeInSameBatteryPremiumNoDiscount() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: new battery, trade-in same battery, premium, no discount + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + // add battery + $criteria->addEntry($battery, null, 1); + + // add battery for trade in + $criteria->addEntry($battery, 'premium', 1); + + $rules = $this->inv_manager->check($criteria); + + error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::BATTERY_REPLACEMENT_NEW . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testBatterySalesTradeInSameBatteryMotoliteNoDiscount() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: new battery, trade-in same battery, motolite, no discount + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + // add battery + $criteria->addEntry($battery, null, 1); + + // add battery for trade in + $criteria->addEntry($battery, 'motolite', 1); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::BATTERY_REPLACEMENT_NEW . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testBatterySalesTradeInSameBatteryOtherNoDiscount() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: new battery, trade-in same battery, other, no discount + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + // add battery + $criteria->addEntry($battery, null, 1); + + // add battery for trade in + $criteria->addEntry($battery, 'other', 1); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::BATTERY_REPLACEMENT_NEW . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testBatterySalesTradeInDifferentBatteryPremiumNoDiscount() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: new battery, trade-in different battery, premium, no discount + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + // add battery + $criteria->addEntry($battery, null, 1); + + $trade_battery_id = 1037; + $trade_battery = $this->em->getRepository(Battery::class)->find($trade_battery_id); + + // add battery for trade in + $criteria->addEntry($trade_battery, 'premium', 1); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::BATTERY_REPLACEMENT_NEW . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testBatterySalesTradeInDifferentBatteryMotoliteNoDiscount() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: new battery, trade-in different battery, premium, no discount + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + // add battery + $criteria->addEntry($battery, null, 1); + + $trade_battery_id = 1037; + $trade_battery = $this->em->getRepository(Battery::class)->find($trade_battery_id); + + // add battery for trade in + $criteria->addEntry($trade_battery, 'motolite', 1); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::BATTERY_REPLACEMENT_NEW . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testBatterySalesTradeInDifferentBatteryOtherNoDiscount() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: new battery, trade-in different battery, premium, no discount + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + // add battery + $criteria->addEntry($battery, null, 1); + + $trade_battery_id = 1037; + $trade_battery = $this->em->getRepository(Battery::class)->find($trade_battery_id); + + // add battery for trade in + $criteria->addEntry($trade_battery, 'other', 1); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::BATTERY_REPLACEMENT_NEW . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testBatterySalesTradeInQuantityNoDiscount() + { + } + + protected function testBatteryReplacementWarranty() + { + // TEST SCENARIO: battery replacement warranty + $criteria = new InvoiceCriteria(); + + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_WARRANTY); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + $criteria->addEntry($battery, null, 1); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::BATTERY_REPLACEMENT_WARRANTY . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testFuelGasWithServiceFee() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: fuel, gas, service fee + $criteria->setServiceType(ServiceType::EMERGENCY_REFUEL); + + // set customer vehicle + $cv_id = 1306614; + $cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id); + + $criteria->setCustomerVehicle($cv); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::EMERGENCY_REFUEL . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testFuelDieselWithServiceFee() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: fuel, diesel, service fee + $criteria->setServiceType(ServiceType::EMERGENCY_REFUEL); + + // set customer vehicle + $cv_id = 1306612; + $cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id); + + $criteria->setCustomerVehicle($cv); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::EMERGENCY_REFUEL . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testFuelGasWithNoServiceFee() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: fuel, gas, no service fee + $criteria->setServiceType(ServiceType::EMERGENCY_REFUEL); + + // set customer vehicle + $cv_id = 1306604; + $cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id); + + $criteria->setCustomerVehicle($cv); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::EMERGENCY_REFUEL . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testFuelDieselWithNoServiceFee() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: fuel, diesel, no service fee + $criteria->setServiceType(ServiceType::EMERGENCY_REFUEL); + + // set customer vehicle + $cv_id = 1306599; + $cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id); + + $criteria->setCustomerVehicle($cv); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::EMERGENCY_REFUEL . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testJumpstart() + { + // TEST SCENARIO: jumpstart + $criteria = new InvoiceCriteria(); + + $criteria->setServiceType(ServiceType::JUMPSTART_TROUBLESHOOT); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::JUMPSTART_TROUBLESHOOT . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testJumpstartWarranty() + { + // TEST SCENARIO: jumpstart warranty + $criteria = new InvoiceCriteria(); + + $criteria->setServiceType(ServiceType::JUMPSTART_WARRANTY); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::JUMPSTART_WARRANTY . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testOverheatAssistanceWithCoolant() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: overheat assistance with coolant + $criteria->setServiceType(ServiceType::OVERHEAT_ASSISTANCE); + + // set customer vehicle + $cv_id = 1306614; + $cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id); + + $criteria->setCustomerVehicle($cv); + $criteria->setHasCoolant(); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::OVERHEAT_ASSISTANCE . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testOverheatAssistanceWithoutCoolant() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: overheat assistance with coolant + $criteria->setServiceType(ServiceType::OVERHEAT_ASSISTANCE); + + // set customer vehicle + $cv_id = 1306614; + $cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id); + + $criteria->setCustomerVehicle($cv); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::OVERHEAT_ASSISTANCE . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testPostRecharged() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: post recharged + $criteria->setServiceType(ServiceType::POST_RECHARGED); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::POST_RECHARGED . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testPostReplacement() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: post replacement + $criteria->setServiceType(ServiceType::POST_REPLACEMENT); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::POST_REPLACEMENT . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testTireRepairWithServiceFee() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: tire repair with service fee + $criteria->setServiceType(ServiceType::TIRE_REPAIR); + + // set customer vehicle + $cv_id = 1306612; + $cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id); + + $criteria->setCustomerVehicle($cv); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::TIRE_REPAIR . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + + protected function testTireRepairWithNoServiceFee() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: tire repair no service fee + $criteria->setServiceType(ServiceType::TIRE_REPAIR); + + // set customer vehicle + $cv_id = 1306604; + $cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id); + + $criteria->setCustomerVehicle($cv); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_items = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . ServiceType::TIRE_REPAIR . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + } + } diff --git a/src/Invoice/Fuel.php b/src/Invoice/Fuel.php index ad0680a1..6c892615 100644 --- a/src/Invoice/Fuel.php +++ b/src/Invoice/Fuel.php @@ -5,6 +5,7 @@ namespace App\Invoice; use App\InvoiceInterface; use App\Ramcar\FuelType; +use App\Ramcar\ServiceType; class Fuel implements InvoiceInterface { @@ -41,17 +42,17 @@ class Fuel implements InvoiceInterface else $fee = $stype_fees['service_fee']; + $ftype = $cv->getFuelType(); + // add the service fee to items $qty = 1; $items[] = [ 'qty' => $qty, - 'title' => $this->getTitle($ftype), + 'title' => $this->getServiceTitle($ftype), 'price' => $fee, ]; - $ftype = $cv->getFuelType(); - - $stype_fees_id = $this->getID() . '_' . $ftype; + $stype_fees_id = $this->getID() . '_fee_' . $ftype; switch ($ftype) { @@ -83,7 +84,14 @@ class Fuel implements InvoiceInterface protected function getTitle($fuel_type) { - $title = '4L - ' . $fuel_type; + $title = '4L - ' . ucfirst($fuel_type); + + return $title; + } + + protected function getServiceTitle($fuel_type) + { + $title = 'Service - ' . ServiceType::getName(ServiceType::EMERGENCY_REFUEL); return $title; } diff --git a/src/Invoice/Jumpstart.php b/src/Invoice/Jumpstart.php index 84ac7ff6..622e5e3f 100644 --- a/src/Invoice/Jumpstart.php +++ b/src/Invoice/Jumpstart.php @@ -25,6 +25,32 @@ class Jumpstart implements InvoiceInterface public function compute($criteria, $stype_fees) { - return []; + $stype = $criteria->getServiceType(); + + $items = []; + + if ($stype == $this->getID()) + { + $stype_fees_id = $this->getID() . '_fee'; + + $fee = $stype_fees[$stype_fees_id]; + + // add the service fee to items + $qty = 1; + $items[] = [ + 'qty' => $qty, + 'title' => $this->getServiceTitle(), + 'price' => $fee, + ]; + } + + return $items; + } + + protected function getServiceTitle() + { + $title = 'Service - Troubleshooting fee'; + + return $title; } } diff --git a/src/Invoice/JumpstartWarranty.php b/src/Invoice/JumpstartWarranty.php index dc322036..ae15170c 100644 --- a/src/Invoice/JumpstartWarranty.php +++ b/src/Invoice/JumpstartWarranty.php @@ -25,7 +25,32 @@ class JumpstartWarranty implements InvoiceInterface public function compute($criteria, $stype_fees) { - return []; + $stype = $criteria->getServiceType(); + + $items = []; + + if ($stype == $this->getID()) + { + $stype_fees_id = $this->getID() . '_fee'; + + $fee = $stype_fees[$stype_fees_id]; + + // add the service fee to items + $qty = 1; + $items[] = [ + 'qty' => $qty, + 'title' => $this->getServiceTitle(), + 'price' => $fee, + ]; + } + + return $items; } + protected function getServiceTitle() + { + $title = 'Service - Troubleshooting fee'; + + return $title; + } } diff --git a/src/Invoice/Overheat.php b/src/Invoice/Overheat.php index 5e8e0aae..70b48bc7 100644 --- a/src/Invoice/Overheat.php +++ b/src/Invoice/Overheat.php @@ -4,6 +4,8 @@ namespace App\Invoice; use App\InvoiceInterface; +USE App\Ramcar\ServiceType; + class Overheat implements InvoiceInterface { public function check($criteria) @@ -25,6 +27,53 @@ class Overheat implements InvoiceInterface public function compute($criteria, $stype_fees) { - return []; + $stype = $criteria->getServiceType(); + $has_coolant = $criteria->hasCoolant(); + + $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']; + + // add the service fee to items + $qty = 1; + $items[] = [ + 'qty' => $qty, + 'title' => $this->getServiceTitle(), + 'price' => $fee, + ]; + + if ($has_coolant) + { + $coolant_fee = $stype_fees['coolant_fee']; + $items[] = [ + 'qty' => $qty, + 'title' => $this->getServiceCoolantTitle(), + 'price' => $coolant_fee, + ]; + } + } + + return $items; + } + + protected function getServiceTitle() + { + $title = 'Service - ' . ServiceType::getName(ServiceType::OVERHEAT_ASSISTANCE) . ' Assistance' ; + + return $title; + } + + protected function getServiceCoolantTitle() + { + $title = '4L Coolant'; + + return $title; } } diff --git a/src/Invoice/PostRecharged.php b/src/Invoice/PostRecharged.php index 546736fd..d974798a 100644 --- a/src/Invoice/PostRecharged.php +++ b/src/Invoice/PostRecharged.php @@ -25,6 +25,30 @@ class PostRecharged implements InvoiceInterface public function compute($criteria, $stype_fees) { - return []; + $stype = $criteria->getServiceType(); + + $items = []; + + if ($stype == $this->getID()) + { + $fee = $stype_fees[$this->getID() . '_fee']; + + $qty = 1; + $items[] = [ + 'qty' => $qty, + 'title' => $this->getServiceTitle(), + 'price' => $fee, + ]; + + } + + return $items; + } + + protected function getServiceTitle() + { + $title = 'Recharge fee'; + + return $title; } } diff --git a/src/Invoice/PostReplacement.php b/src/Invoice/PostReplacement.php index 3d891ffb..76316d49 100644 --- a/src/Invoice/PostReplacement.php +++ b/src/Invoice/PostReplacement.php @@ -25,6 +25,30 @@ class PostReplacement implements InvoiceInterface public function compute($criteria, $stype_fees) { - return []; + $stype = $criteria->getServiceType(); + + $items = []; + + if ($stype == $this->getID()) + { + $fee = $stype_fees['battery_replacement_fee']; + + $qty = 1; + $items[] = [ + 'qty' => $qty, + 'title' => $this->getServiceTitle(), + 'price' => $fee, + ]; + + } + + return $items; + } + + protected function getServiceTitle() + { + $title = 'Battery replacement'; + + return $title; } } diff --git a/src/Invoice/TireRepair.php b/src/Invoice/TireRepair.php index 3a903bab..1d019ebf 100644 --- a/src/Invoice/TireRepair.php +++ b/src/Invoice/TireRepair.php @@ -25,7 +25,35 @@ class TireRepair implements InvoiceInterface public function compute($criteria, $stype_fees) { - return []; + $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']; + + // add the service fee to items + $qty = 1; + $items[] = [ + 'qty' => $qty, + 'title' => $this->getServiceTitle(), + 'price' => $fee, + ]; + } + + return $items; } + protected function getServiceTitle() + { + $title = 'Service - Flat Tire'; + + return $title; + } } diff --git a/src/Invoice/TradeIn.php b/src/Invoice/TradeIn.php index ffb1ffc9..7e3fd2c1 100644 --- a/src/Invoice/TradeIn.php +++ b/src/Invoice/TradeIn.php @@ -4,6 +4,8 @@ namespace App\Invoice; use App\InvoiceInterface; +use App\Ramcar\TradeInType; + class TradeIn implements InvoiceInterface { public function check($criteria) @@ -13,7 +15,7 @@ class TradeIn implements InvoiceInterface foreach($entries as $entry) { - if ($this->getID() == $entry['trade_in']) + if ($entry['trade_in']) { // just need to find one trade-in entry return true; @@ -33,9 +35,60 @@ class TradeIn implements InvoiceInterface return 'trade_in'; } - public function compute($criteria, $stype_fees) + public function compute($criteria) { - return []; + $items = []; + + // get the entries + $entries = $criteria->getEntries(); + foreach($entries as $entry) + { + $batt = $entry['battery']; + $qty = $entry['qty']; + $trade_in_type = null; + + if (isset($entry['trade_in'])) + $trade_in_type = $entry['trade_in']; + + if ($trade_in_type != null) + { + $ti_rate = $this->getTradeInRate($batt, $trade_in_type); + + $price = bcmul($ti_rate, -1, 2); + + $items[] = [ + 'qty' => $qty, + 'title' => $this->getTitle($batt, $trade_in_type), + 'price' => $price, + ]; + } + } + + return $items; + } + + protected function getTradeInRate($battery, $trade_in_type) + { + $size = $battery->getSize(); + + switch ($trade_in_type) + { + case TradeInType::MOTOLITE: + return $size->getTIPriceMotolite(); + case TradeInType::PREMIUM: + return $size->getTIPricePremium(); + case TradeInType::OTHER: + return $size->getTIPriceOther(); + } + + return 0; + } + + protected function getTitle($battery, $trade_in_type) + { + $title = 'Trade-in ' . TradeInType::getName($trade_in_type) . ' ' . $battery->getSize()->getName() . ' battery'; + + return $title; } } diff --git a/src/Service/InvoiceManager.php b/src/Service/InvoiceManager.php index bfbaa7eb..f1db5a73 100644 --- a/src/Service/InvoiceManager.php +++ b/src/Service/InvoiceManager.php @@ -52,8 +52,8 @@ class InvoiceManager return [ 'service_fee' => 300, 'coolant_fee' => 1600, - 'recharge_fee' => 300, - 'jumpstart_fee' => 150, + 'post_recharged_fee' => 300, + 'jumpstart_troubleshoot_fee' => 150, 'jumpstart_warranty_fee' => 0, 'battery_replacement_fee' => 0, 'battery_warranty_fee' => 0, @@ -116,24 +116,22 @@ class InvoiceManager $computed_items = $active_rule->compute($criteria, $stype_fees); foreach ($computed_items as $computed_item) { - $items[] = $computed_item; + if (!empty($computed_item)) + $items[] = $computed_item; } foreach ($items as $item) { - if (isset($item['title'])) - { - $invoice_item = new InvoiceItem(); + $invoice_item = new InvoiceItem(); - $invoice_item->setTitle($item['title']) - ->setQuantity($item['qty']) - ->setPrice($item['price']); + $invoice_item->setTitle($item['title']) + ->setQuantity($item['qty']) + ->setPrice($item['price']); - if (isset($item['battery'])) - $invoice_item->setBattery($item['battery']); + if (isset($item['battery'])) + $invoice_item->setBattery($item['battery']); - $invoice_items[] = $invoice_item; - } + $invoice_items[] = $invoice_item; } } }