Add command to test invoice manager. #744
This commit is contained in:
parent
15830924e2
commit
e3ec6148df
16 changed files with 269 additions and 233 deletions
75
src/Command/TestInvoiceManagerCommand.php
Normal file
75
src/Command/TestInvoiceManagerCommand.php
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
|
use App\Service\InvoiceManager;
|
||||||
|
use App\InvoiceCriteria;
|
||||||
|
|
||||||
|
use App\Ramcar\ServiceType;
|
||||||
|
|
||||||
|
use App\Entity\Battery;
|
||||||
|
|
||||||
|
class TestInvoiceManagerCommand extends Command
|
||||||
|
{
|
||||||
|
protected $inv_manager;
|
||||||
|
protected $em;
|
||||||
|
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this->setName('test:generateinvoice')
|
||||||
|
->setDescription('Test invoice manager service.')
|
||||||
|
->setHelp('Test invoice manager service.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __construct(InvoiceManager $inv_manager, EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$this->em = $em;
|
||||||
|
$this->inv_manager = $inv_manager;
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$this->testBatterySalesNoTradeInNoDiscount();
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function testBatterySalesNoTradeInNoDiscount()
|
||||||
|
{
|
||||||
|
$criteria = new InvoiceCriteria();
|
||||||
|
|
||||||
|
// TEST SCENARIO: new battery, 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, 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($invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,10 +6,9 @@ use App\InvoiceInterface;
|
||||||
|
|
||||||
class BatteryReplacementWarranty implements InvoiceInterface
|
class BatteryReplacementWarranty implements InvoiceInterface
|
||||||
{
|
{
|
||||||
public function check($settings, $criteria)
|
public function check($criteria)
|
||||||
{
|
{
|
||||||
$type_id = $settings['service_type'];
|
if ($this->getID() == $criteria->getServiceType())
|
||||||
if ($type_id == $criteria->getServiceType())
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -25,8 +24,7 @@ class BatteryReplacementWarranty implements InvoiceInterface
|
||||||
return 'battery_warranty';
|
return 'battery_warranty';
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: need to add service type fees as a parameter
|
public function compute($criteria, $stype_fees)
|
||||||
public function compute($criteria)
|
|
||||||
{
|
{
|
||||||
$stype = $criteria->getServiceType();
|
$stype = $criteria->getServiceType();
|
||||||
|
|
||||||
|
|
@ -35,11 +33,13 @@ class BatteryReplacementWarranty implements InvoiceInterface
|
||||||
{
|
{
|
||||||
// get the entries
|
// get the entries
|
||||||
$entries = $criteria->getEntries();
|
$entries = $criteria->getEntries();
|
||||||
|
|
||||||
|
$stype_fee_id = $this->getID() . '_fee';
|
||||||
foreach($entries as $entry)
|
foreach($entries as $entry)
|
||||||
{
|
{
|
||||||
$batt = $entry['battery'];
|
$batt = $entry['battery'];
|
||||||
$qty = 1;
|
$qty = 1;
|
||||||
$price = 0; // need to put this in a config or something
|
$price = $stype_fees[$stype_fee_id];
|
||||||
|
|
||||||
$items[] = [
|
$items[] = [
|
||||||
'battery' => $batt,
|
'battery' => $batt,
|
||||||
|
|
@ -55,7 +55,7 @@ class BatteryReplacementWarranty implements InvoiceInterface
|
||||||
|
|
||||||
protected function getTitle($battery)
|
protected function getTitle($battery)
|
||||||
{
|
{
|
||||||
$title = $battery->getModel()->getName() . ' ' . $battery->getSize()->getName() . ' - Service Unit');
|
$title = $battery->getModel()->getName() . ' ' . $battery->getSize()->getName() . ' - Service Unit';
|
||||||
|
|
||||||
return $title;
|
return $title;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,9 @@ use App\InvoiceInterface;
|
||||||
|
|
||||||
class BatterySales implements InvoiceInterface
|
class BatterySales implements InvoiceInterface
|
||||||
{
|
{
|
||||||
public function check($settings, $criteria)
|
public function check($criteria)
|
||||||
{
|
{
|
||||||
$type_id = $settings['service_type'];
|
if ($this->getID() == $criteria->getServiceType())
|
||||||
if ($type_id == $criteria->getServiceType())
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -25,8 +24,7 @@ class BatterySales implements InvoiceInterface
|
||||||
return 'battery_new';
|
return 'battery_new';
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: need to add service type fees as a parameter
|
public function compute($criteria, $stype_fees)
|
||||||
public function compute($criteria)
|
|
||||||
{
|
{
|
||||||
$stype = $criteria->getServiceType();
|
$stype = $criteria->getServiceType();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Invoice;
|
|
||||||
|
|
||||||
use App\InvoiceInterface;
|
|
||||||
|
|
||||||
class Discount implements InvoiceInterface
|
|
||||||
{
|
|
||||||
public function check($settings, $criteria)
|
|
||||||
{
|
|
||||||
$type_id = $settings['discount'];
|
|
||||||
if ($type_id == $criteria->getDiscount())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTemplate()
|
|
||||||
{
|
|
||||||
return 'invoice/discount.html.twig';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getID()
|
|
||||||
{
|
|
||||||
return 'discount';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAmount($battery = null, $discount_list, $id)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
33
src/Invoice/DiscountType.php
Normal file
33
src/Invoice/DiscountType.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Invoice;
|
||||||
|
|
||||||
|
use App\InvoiceInterface;
|
||||||
|
|
||||||
|
class DiscountType implements InvoiceInterface
|
||||||
|
{
|
||||||
|
public function check($criteria)
|
||||||
|
{
|
||||||
|
if (!empty($criteria->getPromos()))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplate()
|
||||||
|
{
|
||||||
|
return 'invoice/discount_type.html.twig';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return 'discount_type';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function compute($criteria, $stype_fees)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -4,12 +4,13 @@ namespace App\Invoice;
|
||||||
|
|
||||||
use App\InvoiceInterface;
|
use App\InvoiceInterface;
|
||||||
|
|
||||||
|
use App\Ramcar\FuelType;
|
||||||
|
|
||||||
class Fuel implements InvoiceInterface
|
class Fuel implements InvoiceInterface
|
||||||
{
|
{
|
||||||
public function check($settings, $criteria)
|
public function check($criteria)
|
||||||
{
|
{
|
||||||
$type_id = $settings['service_type'];
|
if ($this->getID() == $criteria->getServiceType())
|
||||||
if ($type_id == $criteria->getServiceType())
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -24,14 +25,66 @@ class Fuel implements InvoiceInterface
|
||||||
return 'fuel';
|
return 'fuel';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAmount($battery = null, $service_type_fees, $id)
|
public function compute($criteria, $stype_fees)
|
||||||
{
|
{
|
||||||
if ($battery != null)
|
$stype = $criteria->getServiceType();
|
||||||
return $battery->getSellingPrice();
|
|
||||||
|
|
||||||
if (isset($service_type_fees[$id]))
|
$items = [];
|
||||||
return $service_type_fees[$id];
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
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->getTitle($ftype),
|
||||||
|
'price' => $fee,
|
||||||
|
];
|
||||||
|
|
||||||
|
$ftype = $cv->getFuelType();
|
||||||
|
|
||||||
|
$stype_fees_id = $this->getID() . '_' . $ftype;
|
||||||
|
|
||||||
|
switch ($ftype)
|
||||||
|
{
|
||||||
|
case FuelType::GAS:
|
||||||
|
case FuelType::DIESEL:
|
||||||
|
$qty = 1;
|
||||||
|
$price = $stype_fees[$stype_fees_id];
|
||||||
|
$items[] = [
|
||||||
|
'qty' => $qty,
|
||||||
|
'title' => $this->getTitle($ftype),
|
||||||
|
'price' => $price,
|
||||||
|
];
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$qty = 1;
|
||||||
|
$price = 0;
|
||||||
|
$items[] = [
|
||||||
|
'qty' => $qty,
|
||||||
|
'title' => $this->getTitle('Unknown'),
|
||||||
|
'price' => $price,
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getTitle($fuel_type)
|
||||||
|
{
|
||||||
|
$title = '4L - ' . $fuel_type;
|
||||||
|
|
||||||
|
return $title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,9 @@ use App\InvoiceInterface;
|
||||||
|
|
||||||
class Jumpstart implements InvoiceInterface
|
class Jumpstart implements InvoiceInterface
|
||||||
{
|
{
|
||||||
public function check($settings, $criteria)
|
public function check($criteria)
|
||||||
{
|
{
|
||||||
$type_id = $settings['service_type'];
|
if ($this->getID() == $criteria->getServiceType())
|
||||||
if ($type_id == $criteria->getServiceType())
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -24,14 +23,8 @@ class Jumpstart implements InvoiceInterface
|
||||||
return 'jumpstart_troubleshoot';
|
return 'jumpstart_troubleshoot';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAmount($battery = null, $service_type_fees, $id)
|
public function compute($criteria, $stype_fees)
|
||||||
{
|
{
|
||||||
if ($battery != null)
|
return [];
|
||||||
return $battery->getSellingPrice();
|
|
||||||
|
|
||||||
if (isset($service_type_fees[$id]))
|
|
||||||
return $service_type_fees[$id];
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,9 @@ use App\InvoiceInterface;
|
||||||
|
|
||||||
class JumpstartWarranty implements InvoiceInterface
|
class JumpstartWarranty implements InvoiceInterface
|
||||||
{
|
{
|
||||||
public function check($settings, $criteria)
|
public function check($criteria)
|
||||||
{
|
{
|
||||||
$type_id = $settings['service_type'];
|
if ($this->getID() == $criteria->getServiceType())
|
||||||
if ($type_id == $criteria->getServiceType())
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -24,14 +23,9 @@ class JumpstartWarranty implements InvoiceInterface
|
||||||
return 'jumpstart_warranty';
|
return 'jumpstart_warranty';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAmount($battery = null, $service_type_fees, $id)
|
public function compute($criteria, $stype_fees)
|
||||||
{
|
{
|
||||||
if ($battery != null)
|
return [];
|
||||||
return $battery->getSellingPrice();
|
|
||||||
|
|
||||||
if (isset($service_type_fees[$id]))
|
|
||||||
return $service_type_fees[$id];
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,9 @@ use App\InvoiceInterface;
|
||||||
|
|
||||||
class Overheat implements InvoiceInterface
|
class Overheat implements InvoiceInterface
|
||||||
{
|
{
|
||||||
public function check($settings, $criteria)
|
public function check($criteria)
|
||||||
{
|
{
|
||||||
$type_id = $settings['service_type'];
|
if ($this->getID() == $criteria->getServiceType())
|
||||||
if ($type_id == $criteria->getServiceType())
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -24,14 +23,8 @@ class Overheat implements InvoiceInterface
|
||||||
return 'overheat';
|
return 'overheat';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAmount($battery = null, $service_type_fees, $id)
|
public function compute($criteria, $stype_fees)
|
||||||
{
|
{
|
||||||
if ($battery != null)
|
return [];
|
||||||
return $battery->getSellingPrice();
|
|
||||||
|
|
||||||
if (isset($service_type_fees[$id]))
|
|
||||||
return $service_type_fees[$id];
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,9 @@ use App\InvoiceInterface;
|
||||||
|
|
||||||
class PostRecharged implements InvoiceInterface
|
class PostRecharged implements InvoiceInterface
|
||||||
{
|
{
|
||||||
public function check($settings, $criteria)
|
public function check($criteria)
|
||||||
{
|
{
|
||||||
$type_id = $settings['service_type'];
|
if ($this->getID() == $criteria->getServiceType())
|
||||||
if ($type_id == $criteria->getServiceType())
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -24,14 +23,8 @@ class PostRecharged implements InvoiceInterface
|
||||||
return 'post_recharged';
|
return 'post_recharged';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAmount($battery = null, $service_type_fees, $id)
|
public function compute($criteria, $stype_fees)
|
||||||
{
|
{
|
||||||
if ($battery != null)
|
return [];
|
||||||
return $battery->getSellingPrice();
|
|
||||||
|
|
||||||
if (isset($service_type_fees[$id]))
|
|
||||||
return $service_type_fees[$id];
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,9 @@ use App\InvoiceInterface;
|
||||||
|
|
||||||
class PostReplacement implements InvoiceInterface
|
class PostReplacement implements InvoiceInterface
|
||||||
{
|
{
|
||||||
public function check($settings, $criteria)
|
public function check($criteria)
|
||||||
{
|
{
|
||||||
$type_id = $settings['service_type'];
|
if ($this->getID() == $criteria->getServiceType())
|
||||||
if ($type_id == $criteria->getServiceType())
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -24,14 +23,8 @@ class PostReplacement implements InvoiceInterface
|
||||||
return 'post_replacement';
|
return 'post_replacement';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAmount($battery = null, $service_type_fees, $id)
|
public function compute($criteria, $stype_fees)
|
||||||
{
|
{
|
||||||
if ($battery != null)
|
return [];
|
||||||
return $battery->getSellingPrice();
|
|
||||||
|
|
||||||
if (isset($service_type_fees[$id]))
|
|
||||||
return $service_type_fees[$id];
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ use App\InvoiceInterface;
|
||||||
|
|
||||||
class ServiceType implements InvoiceInterface
|
class ServiceType implements InvoiceInterface
|
||||||
{
|
{
|
||||||
public function check($settings, $criteria)
|
public function check($criteria)
|
||||||
{
|
{
|
||||||
if (isset($settings['service_type']))
|
if ($criteria->getServiceType() != null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -24,8 +24,7 @@ class ServiceType implements InvoiceInterface
|
||||||
return 'service_type';
|
return 'service_type';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAmount($battery = null, $service_type_fees, $id)
|
public function compute($criteria, $stype_fees)
|
||||||
{
|
{
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,9 @@ use App\InvoiceInterface;
|
||||||
|
|
||||||
class TireRepair implements InvoiceInterface
|
class TireRepair implements InvoiceInterface
|
||||||
{
|
{
|
||||||
public function check($settings, $criteria)
|
public function check($criteria)
|
||||||
{
|
{
|
||||||
$type_id = $settings['service_type'];
|
if ($this->getID() == $criteria->getServiceType())
|
||||||
if ($type_id == $criteria->getServiceType())
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -24,14 +23,9 @@ class TireRepair implements InvoiceInterface
|
||||||
return 'tire';
|
return 'tire';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAmount($battery = null, $service_type_fees, $id)
|
public function compute($criteria, $stype_fees)
|
||||||
{
|
{
|
||||||
if ($battery != null)
|
return [];
|
||||||
return $battery->getSellingPrice();
|
|
||||||
|
|
||||||
if (isset($service_type_fees[$id]))
|
|
||||||
return $service_type_fees[$id];
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,17 @@ use App\InvoiceInterface;
|
||||||
|
|
||||||
class TradeIn implements InvoiceInterface
|
class TradeIn implements InvoiceInterface
|
||||||
{
|
{
|
||||||
public function check($settings, $criteria)
|
public function check($criteria)
|
||||||
{
|
{
|
||||||
// compare specified type ids with trade in entry of criteria
|
// compare specified type ids with trade in entry of criteria
|
||||||
$trade_ins = $settings['trade_ins'];
|
|
||||||
$entries = $criteria->getEntries();
|
$entries = $criteria->getEntries();
|
||||||
|
|
||||||
foreach ($trade_ins as $type_id)
|
foreach($entries as $entry)
|
||||||
{
|
{
|
||||||
foreach($entries as $entry)
|
if ($this->getID() == $entry['trade_in'])
|
||||||
{
|
{
|
||||||
if ($type_id == $entry['trade_in'])
|
// just need to find one trade-in entry
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,25 +33,9 @@ class TradeIn implements InvoiceInterface
|
||||||
return 'trade_in';
|
return 'trade_in';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAmount($battery = null, $trade_in_types, $id)
|
public function compute($criteria, $stype_fees)
|
||||||
{
|
{
|
||||||
if (isset($trade_in_types[$id]))
|
return [];
|
||||||
{
|
|
||||||
if ($battery != null)
|
|
||||||
{
|
|
||||||
switch ($trade_in)
|
|
||||||
{
|
|
||||||
case TradeInType::MOTOLITE:
|
|
||||||
return $battery->getSize()->getTIPriceMotolite();
|
|
||||||
case TradeInType::PREMIUM:
|
|
||||||
return $battery0>getSize()->getTIPricePremium();
|
|
||||||
case TradeInType::OTHER:
|
|
||||||
return $battery->getSize()->getTIPriceOther();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ namespace App;
|
||||||
|
|
||||||
interface InvoiceInterface
|
interface InvoiceInterface
|
||||||
{
|
{
|
||||||
// check if the invoice rule aka settings is in the criteria
|
// check if the invoice rule is in the criteria
|
||||||
public function check($settings, $criteria);
|
public function check($criteria);
|
||||||
|
|
||||||
// display the html partial for the form
|
// display the html partial for the form
|
||||||
public function getTemplate();
|
public function getTemplate();
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,11 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
|
use App\Invoice;
|
||||||
|
|
||||||
use App\Ramcar\InvoiceCriteria;
|
use App\Ramcar\InvoiceCriteria;
|
||||||
use App\Ramcar\InvoiceStatus;
|
use App\Ramcar\InvoiceStatus;
|
||||||
|
|
||||||
use App\Entity\Invoice;
|
|
||||||
use App\Entity\InvoiceItem;
|
use App\Entity\InvoiceItem;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Entity\Battery;
|
use App\Entity\Battery;
|
||||||
|
|
@ -24,7 +25,7 @@ class InvoiceManager
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
|
|
||||||
$this->available_rules = $this->getAllRules();
|
$this->available_rules = $this->getAvailableRules();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAvailableRules()
|
public function getAvailableRules()
|
||||||
|
|
@ -35,13 +36,13 @@ class InvoiceManager
|
||||||
new Invoice\BatterySales(),
|
new Invoice\BatterySales(),
|
||||||
new Invoice\BatteryReplacementWarranty(),
|
new Invoice\BatteryReplacementWarranty(),
|
||||||
new Invoice\Jumpstart(),
|
new Invoice\Jumpstart(),
|
||||||
new Invoice\JumstartWarranty(),
|
new Invoice\JumpstartWarranty(),
|
||||||
new Invoice\PostRecharged(),
|
new Invoice\PostRecharged(),
|
||||||
new Invoice\PostReplacement(),
|
new Invoice\PostReplacement(),
|
||||||
new Invoice\Overheat(),
|
new Invoice\Overheat(),
|
||||||
new Invoice\Fuel(),
|
new Invoice\Fuel(),
|
||||||
new Invoice\TireRepair(),
|
new Invoice\TireRepair(),
|
||||||
new Invoice\Discount(),
|
new Invoice\DiscountType(),
|
||||||
new Invoice\TradeIn(),
|
new Invoice\TradeIn(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
@ -55,54 +56,20 @@ class InvoiceManager
|
||||||
'jumpstart_fee' => 150,
|
'jumpstart_fee' => 150,
|
||||||
'jumpstart_warranty_fee' => 0,
|
'jumpstart_warranty_fee' => 0,
|
||||||
'battery_replacement_fee' => 0,
|
'battery_replacement_fee' => 0,
|
||||||
'warranty_fee' => 0,
|
'battery_warranty_fee' => 0,
|
||||||
'other_services_fee' => 200,
|
'other_services_fee' => 200,
|
||||||
'refuel_fee_gas' => 320,
|
'fuel_fee_gas' => 320,
|
||||||
'refuel_fee_diesel' => 320,
|
'fuel_fee_diesel' => 320,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// check what rules to use given the criteria
|
// check what rules to use given the criteria
|
||||||
public function check($criteria)
|
public function check($criteria)
|
||||||
{
|
{
|
||||||
// get what is in criteria
|
|
||||||
$stype = $criteria->getServiceType();
|
|
||||||
$discount = $criteria->getDiscount();
|
|
||||||
$entries = $criteria->getEntries();
|
|
||||||
|
|
||||||
$batteries = [];
|
|
||||||
$trade_ins = [];
|
|
||||||
foreach ($entries as $entry)
|
|
||||||
{
|
|
||||||
if ($entry['trade_in'] == null)
|
|
||||||
{
|
|
||||||
// battery purchase
|
|
||||||
$batteries[] = [
|
|
||||||
'battery' => $entry['battery'],
|
|
||||||
'qty' => $entry['qty'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// trade in
|
|
||||||
$trade_ins[] = [
|
|
||||||
'battery' => $entry['battery'],
|
|
||||||
'qty' => $entry['qty'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$settings = [
|
|
||||||
'service_type' => $criteria->getServiceType(),
|
|
||||||
'discount' => $criteria->getDiscount(),
|
|
||||||
'batteries' => $batteries,
|
|
||||||
'trade_ins' => $trade_ins,
|
|
||||||
];
|
|
||||||
|
|
||||||
$active_rules = [];
|
$active_rules = [];
|
||||||
foreach ($this->available_rules as $rule)
|
foreach ($this->available_rules as $rule)
|
||||||
{
|
{
|
||||||
$is_active = $rule->check($settings, $criteria);
|
$is_active = $rule->check($criteria);
|
||||||
if ($is_active)
|
if ($is_active)
|
||||||
$active_rules[$rule->getID()] = $rule;
|
$active_rules[$rule->getID()] = $rule;
|
||||||
}
|
}
|
||||||
|
|
@ -111,13 +78,15 @@ class InvoiceManager
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compute($invoice, $criteria, $active_rules)
|
public function compute($criteria, $active_rules)
|
||||||
{
|
{
|
||||||
// get what is in criteria
|
// get what is in criteria
|
||||||
$stype = $criteria->getServiceType();
|
$stype = $criteria->getServiceType();
|
||||||
$discount = $criteria->getDiscount();
|
|
||||||
$entries = $criteria->getEntries();
|
$entries = $criteria->getEntries();
|
||||||
|
|
||||||
|
// get the service type fees
|
||||||
|
$stype_fees = $this->getServiceTypeFees();
|
||||||
|
|
||||||
$flag_trade_in = false;
|
$flag_trade_in = false;
|
||||||
foreach ($entries as $entry)
|
foreach ($entries as $entry)
|
||||||
{
|
{
|
||||||
|
|
@ -127,48 +96,48 @@ class InvoiceManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$invoice_items = [];
|
||||||
foreach ($active_rules as $id => $active_rule)
|
foreach ($active_rules as $id => $active_rule)
|
||||||
{
|
{
|
||||||
if ($id == $stype)
|
if ($id == $stype)
|
||||||
{
|
{
|
||||||
|
$items = [];
|
||||||
// process trade-ins by calling the trade-in rule if there are trade-ins
|
// process trade-ins by calling the trade-in rule if there are trade-ins
|
||||||
// since it's lumped with only the battery_new service type
|
// since it's lumped with only the battery_new service type
|
||||||
$trade_in_items = [];
|
|
||||||
if ($flag_trade_in)
|
if ($flag_trade_in)
|
||||||
{
|
{
|
||||||
$trade_in_items = $active_rules['trade_in']->compute($criteria);
|
$tradein_items = $active_rules['trade_in']->compute($criteria);
|
||||||
|
foreach ($tradein_items as $tradein_item)
|
||||||
|
{
|
||||||
|
$items[] = $tradein_item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: need to pass service type fees to compute
|
$computed_items = $active_rule->compute($criteria, $stype_fees);
|
||||||
$items = $active_rule->compute($criteria);
|
foreach ($computed_items as $computed_item)
|
||||||
|
{
|
||||||
|
$items[] = $computed_item;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($items as $item)
|
foreach ($items as $item)
|
||||||
{
|
{
|
||||||
$invoice_item = new InvoiceItem();
|
if (isset($item['title']))
|
||||||
|
{
|
||||||
|
$invoice_item = new InvoiceItem();
|
||||||
|
|
||||||
$invoice_item->setInvoice($invoice)
|
$invoice_item->setTitle($item['title'])
|
||||||
->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->addItem($invoice_item);
|
$invoice_items[] = $invoice_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($trade_in_items as $trade_in)
|
|
||||||
{
|
|
||||||
$invoice_item = new InvoiceItem();
|
|
||||||
|
|
||||||
$invoice_item->setInvoice($invoice)
|
|
||||||
->setTitle($trade_in_item['title'])
|
|
||||||
->setQuantity($trade_in_item['qty'])
|
|
||||||
->setPrice($trade_initem['price']);
|
|
||||||
|
|
||||||
$invoice->addItem($invoice_item);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $invoice_items;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue