Add rules for trade in and other service types. Add test scenarios. #744
This commit is contained in:
parent
e3ec6148df
commit
9bac6df2df
10 changed files with 813 additions and 32 deletions
|
|
@ -15,6 +15,7 @@ use App\InvoiceCriteria;
|
||||||
use App\Ramcar\ServiceType;
|
use App\Ramcar\ServiceType;
|
||||||
|
|
||||||
use App\Entity\Battery;
|
use App\Entity\Battery;
|
||||||
|
use App\Entity\CustomerVehicle;
|
||||||
|
|
||||||
class TestInvoiceManagerCommand extends Command
|
class TestInvoiceManagerCommand extends Command
|
||||||
{
|
{
|
||||||
|
|
@ -38,14 +39,52 @@ class TestInvoiceManagerCommand extends Command
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
|
// battery sales
|
||||||
$this->testBatterySalesNoTradeInNoDiscount();
|
$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
|
||||||
// TEST SCENARIO: new battery with discount and trade-in
|
// 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,7 +108,514 @@ class TestInvoiceManagerCommand extends Command
|
||||||
|
|
||||||
foreach ($invoice_items as $invoice_item)
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace App\Invoice;
|
||||||
use App\InvoiceInterface;
|
use App\InvoiceInterface;
|
||||||
|
|
||||||
use App\Ramcar\FuelType;
|
use App\Ramcar\FuelType;
|
||||||
|
use App\Ramcar\ServiceType;
|
||||||
|
|
||||||
class Fuel implements InvoiceInterface
|
class Fuel implements InvoiceInterface
|
||||||
{
|
{
|
||||||
|
|
@ -41,17 +42,17 @@ class Fuel implements InvoiceInterface
|
||||||
else
|
else
|
||||||
$fee = $stype_fees['service_fee'];
|
$fee = $stype_fees['service_fee'];
|
||||||
|
|
||||||
|
$ftype = $cv->getFuelType();
|
||||||
|
|
||||||
// add the service fee to items
|
// add the service fee to items
|
||||||
$qty = 1;
|
$qty = 1;
|
||||||
$items[] = [
|
$items[] = [
|
||||||
'qty' => $qty,
|
'qty' => $qty,
|
||||||
'title' => $this->getTitle($ftype),
|
'title' => $this->getServiceTitle($ftype),
|
||||||
'price' => $fee,
|
'price' => $fee,
|
||||||
];
|
];
|
||||||
|
|
||||||
$ftype = $cv->getFuelType();
|
$stype_fees_id = $this->getID() . '_fee_' . $ftype;
|
||||||
|
|
||||||
$stype_fees_id = $this->getID() . '_' . $ftype;
|
|
||||||
|
|
||||||
switch ($ftype)
|
switch ($ftype)
|
||||||
{
|
{
|
||||||
|
|
@ -83,7 +84,14 @@ class Fuel implements InvoiceInterface
|
||||||
|
|
||||||
protected function getTitle($fuel_type)
|
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;
|
return $title;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,32 @@ class Jumpstart implements InvoiceInterface
|
||||||
|
|
||||||
public function compute($criteria, $stype_fees)
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,32 @@ class JumpstartWarranty implements InvoiceInterface
|
||||||
|
|
||||||
public function compute($criteria, $stype_fees)
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ namespace App\Invoice;
|
||||||
|
|
||||||
use App\InvoiceInterface;
|
use App\InvoiceInterface;
|
||||||
|
|
||||||
|
USE App\Ramcar\ServiceType;
|
||||||
|
|
||||||
class Overheat implements InvoiceInterface
|
class Overheat implements InvoiceInterface
|
||||||
{
|
{
|
||||||
public function check($criteria)
|
public function check($criteria)
|
||||||
|
|
@ -25,6 +27,53 @@ class Overheat implements InvoiceInterface
|
||||||
|
|
||||||
public function compute($criteria, $stype_fees)
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,30 @@ class PostRecharged implements InvoiceInterface
|
||||||
|
|
||||||
public function compute($criteria, $stype_fees)
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,30 @@ class PostReplacement implements InvoiceInterface
|
||||||
|
|
||||||
public function compute($criteria, $stype_fees)
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,35 @@ class TireRepair implements InvoiceInterface
|
||||||
|
|
||||||
public function compute($criteria, $stype_fees)
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ namespace App\Invoice;
|
||||||
|
|
||||||
use App\InvoiceInterface;
|
use App\InvoiceInterface;
|
||||||
|
|
||||||
|
use App\Ramcar\TradeInType;
|
||||||
|
|
||||||
class TradeIn implements InvoiceInterface
|
class TradeIn implements InvoiceInterface
|
||||||
{
|
{
|
||||||
public function check($criteria)
|
public function check($criteria)
|
||||||
|
|
@ -13,7 +15,7 @@ class TradeIn implements InvoiceInterface
|
||||||
|
|
||||||
foreach($entries as $entry)
|
foreach($entries as $entry)
|
||||||
{
|
{
|
||||||
if ($this->getID() == $entry['trade_in'])
|
if ($entry['trade_in'])
|
||||||
{
|
{
|
||||||
// just need to find one trade-in entry
|
// just need to find one trade-in entry
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -33,9 +35,60 @@ class TradeIn implements InvoiceInterface
|
||||||
return 'trade_in';
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,8 +52,8 @@ class InvoiceManager
|
||||||
return [
|
return [
|
||||||
'service_fee' => 300,
|
'service_fee' => 300,
|
||||||
'coolant_fee' => 1600,
|
'coolant_fee' => 1600,
|
||||||
'recharge_fee' => 300,
|
'post_recharged_fee' => 300,
|
||||||
'jumpstart_fee' => 150,
|
'jumpstart_troubleshoot_fee' => 150,
|
||||||
'jumpstart_warranty_fee' => 0,
|
'jumpstart_warranty_fee' => 0,
|
||||||
'battery_replacement_fee' => 0,
|
'battery_replacement_fee' => 0,
|
||||||
'battery_warranty_fee' => 0,
|
'battery_warranty_fee' => 0,
|
||||||
|
|
@ -116,24 +116,22 @@ class InvoiceManager
|
||||||
$computed_items = $active_rule->compute($criteria, $stype_fees);
|
$computed_items = $active_rule->compute($criteria, $stype_fees);
|
||||||
foreach ($computed_items as $computed_item)
|
foreach ($computed_items as $computed_item)
|
||||||
{
|
{
|
||||||
$items[] = $computed_item;
|
if (!empty($computed_item))
|
||||||
|
$items[] = $computed_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($items as $item)
|
foreach ($items as $item)
|
||||||
{
|
{
|
||||||
if (isset($item['title']))
|
$invoice_item = new InvoiceItem();
|
||||||
{
|
|
||||||
$invoice_item = new InvoiceItem();
|
|
||||||
|
|
||||||
$invoice_item->setTitle($item['title'])
|
$invoice_item->setTitle($item['title'])
|
||||||
->setQuantity($item['qty'])
|
->setQuantity($item['qty'])
|
||||||
->setPrice($item['price']);
|
->setPrice($item['price']);
|
||||||
|
|
||||||
if (isset($item['battery']))
|
if (isset($item['battery']))
|
||||||
$invoice_item->setBattery($item['battery']);
|
$invoice_item->setBattery($item['battery']);
|
||||||
|
|
||||||
$invoice_items[] = $invoice_item;
|
$invoice_items[] = $invoice_item;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue