Add function to check what rules to use. #744
This commit is contained in:
parent
0bb32f47b5
commit
0063f10f93
15 changed files with 565 additions and 10 deletions
37
src/Invoice/1
Normal file
37
src/Invoice/1
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Invoice;
|
||||||
|
|
||||||
|
use App\InvoiceInterface;
|
||||||
|
|
||||||
|
class Overheat implements InvoiceInterface
|
||||||
|
{
|
||||||
|
public function check($settings, $criteria)
|
||||||
|
{
|
||||||
|
$type_id = $settings['service_type'];
|
||||||
|
if ($type_id == $criteria->getServiceType())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return 'overheat';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount($battery = null, $service_type_fees)
|
||||||
|
{
|
||||||
|
if ($battery != null)
|
||||||
|
return $battery->getSellingPrice();
|
||||||
|
|
||||||
|
if (isset($service_type_fees[$this->getID()]))
|
||||||
|
return $service_type_fees[$this->getID()];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/Invoice/BatteryReplacementWarranty.php
Normal file
39
src/Invoice/BatteryReplacementWarranty.php
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Invoice;
|
||||||
|
|
||||||
|
use App\InvoiceInterface;
|
||||||
|
|
||||||
|
class BatteryReplacementWarranty implements InvoiceInterface
|
||||||
|
{
|
||||||
|
public function check($settings, $criteria)
|
||||||
|
{
|
||||||
|
$type_id = $settings['service_type'];
|
||||||
|
if ($type_id == $criteria->getServiceType())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplate()
|
||||||
|
{
|
||||||
|
return 'invoice/battery.html.twig';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return 'battery_warranty';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount($battery = null, $service_type_fees, $id)
|
||||||
|
{
|
||||||
|
if ($battery != null)
|
||||||
|
return $battery->getSellingPrice();
|
||||||
|
|
||||||
|
if (isset($service_type_fees[$id))
|
||||||
|
return $service_type_fees[$id];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
38
src/Invoice/BatterySales.php
Normal file
38
src/Invoice/BatterySales.php
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Invoice;
|
||||||
|
|
||||||
|
use App\InvoiceInterface;
|
||||||
|
|
||||||
|
class BatterySales implements InvoiceInterface
|
||||||
|
{
|
||||||
|
public function check($settings, $criteria)
|
||||||
|
{
|
||||||
|
$type_id = $settings['service_type'];
|
||||||
|
if ($type_id == $criteria->getServiceType())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplate()
|
||||||
|
{
|
||||||
|
return 'invoice/battery.html.twig';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return 'battery_new';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount($battery = null, $service_type_fees, $id)
|
||||||
|
{
|
||||||
|
if ($battery != null)
|
||||||
|
return $battery->getSellingPrice();
|
||||||
|
|
||||||
|
if (isset($service_type_fees[$id]))
|
||||||
|
return $service_type_fees[$id];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
34
src/Invoice/Discount.php
Normal file
34
src/Invoice/Discount.php
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
37
src/Invoice/Fuel.php
Normal file
37
src/Invoice/Fuel.php
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Invoice;
|
||||||
|
|
||||||
|
use App\InvoiceInterface;
|
||||||
|
|
||||||
|
class Fuel implements InvoiceInterface
|
||||||
|
{
|
||||||
|
public function check($settings, $criteria)
|
||||||
|
{
|
||||||
|
$type_id = $settings['service_type'];
|
||||||
|
if ($type_id == $criteria->getServiceType())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return 'fuel';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount($battery = null, $service_type_fees, $id)
|
||||||
|
{
|
||||||
|
if ($battery != null)
|
||||||
|
return $battery->getSellingPrice();
|
||||||
|
|
||||||
|
if (isset($service_type_fees[$id]))
|
||||||
|
return $service_type_fees[$id];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
37
src/Invoice/Jumpstart.php
Normal file
37
src/Invoice/Jumpstart.php
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Invoice;
|
||||||
|
|
||||||
|
use App\InvoiceInterface;
|
||||||
|
|
||||||
|
class Jumpstart implements InvoiceInterface
|
||||||
|
{
|
||||||
|
public function check($settings, $criteria)
|
||||||
|
{
|
||||||
|
$type_id = $settings['service_type'];
|
||||||
|
if ($type_id == $criteria->getServiceType())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return 'jumpstart_troubleshoot';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount($battery = null, $service_type_fees, $id)
|
||||||
|
{
|
||||||
|
if ($battery != null)
|
||||||
|
return $battery->getSellingPrice();
|
||||||
|
|
||||||
|
if (isset($service_type_fees[$id]))
|
||||||
|
return $service_type_fees[$id];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
37
src/Invoice/JumpstartWarranty.php
Normal file
37
src/Invoice/JumpstartWarranty.php
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Invoice;
|
||||||
|
|
||||||
|
use App\InvoiceInterface;
|
||||||
|
|
||||||
|
class JumpstartWarranty implements InvoiceInterface
|
||||||
|
{
|
||||||
|
public function check($settings, $criteria)
|
||||||
|
{
|
||||||
|
$type_id = $settings['service_type'];
|
||||||
|
if ($type_id == $criteria->getServiceType())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return 'jumpstart_warranty';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount($battery = null, $service_type_fees, $id)
|
||||||
|
{
|
||||||
|
if ($battery != null)
|
||||||
|
return $battery->getSellingPrice();
|
||||||
|
|
||||||
|
if (isset($service_type_fees[$id))
|
||||||
|
return $service_type_fees[$id];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
37
src/Invoice/Overheat.php
Normal file
37
src/Invoice/Overheat.php
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Invoice;
|
||||||
|
|
||||||
|
use App\InvoiceInterface;
|
||||||
|
|
||||||
|
class Overheat implements InvoiceInterface
|
||||||
|
{
|
||||||
|
public function check($settings, $criteria)
|
||||||
|
{
|
||||||
|
$type_id = $settings['service_type'];
|
||||||
|
if ($type_id == $criteria->getServiceType())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return 'overheat';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount($battery = null, $service_type_fees, $id)
|
||||||
|
{
|
||||||
|
if ($battery != null)
|
||||||
|
return $battery->getSellingPrice();
|
||||||
|
|
||||||
|
if (isset($service_type_fees[$id]))
|
||||||
|
return $service_type_fees[$id];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
37
src/Invoice/PostRecharged.php
Normal file
37
src/Invoice/PostRecharged.php
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Invoice;
|
||||||
|
|
||||||
|
use App\InvoiceInterface;
|
||||||
|
|
||||||
|
class PostRecharged implements InvoiceInterface
|
||||||
|
{
|
||||||
|
public function check($settings, $criteria)
|
||||||
|
{
|
||||||
|
$type_id = $settings['service_type'];
|
||||||
|
if ($type_id == $criteria->getServiceType())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return 'post_recharged';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount($battery = null, $service_type_fees, $id)
|
||||||
|
{
|
||||||
|
if ($battery != null)
|
||||||
|
return $battery->getSellingPrice();
|
||||||
|
|
||||||
|
if (isset($service_type_fees[$id))
|
||||||
|
return $service_type_fees[$id];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
37
src/Invoice/PostReplacement.php
Normal file
37
src/Invoice/PostReplacement.php
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Invoice;
|
||||||
|
|
||||||
|
use App\InvoiceInterface;
|
||||||
|
|
||||||
|
class PostReplacement implements InvoiceInterface
|
||||||
|
{
|
||||||
|
public function check($settings, $criteria)
|
||||||
|
{
|
||||||
|
$type_id = $settings['service_type'];
|
||||||
|
if ($type_id == $criteria->getServiceType())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return 'post_replacement';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount($battery = null, $service_type_fees, $id)
|
||||||
|
{
|
||||||
|
if ($battery != null)
|
||||||
|
return $battery->getSellingPrice();
|
||||||
|
|
||||||
|
if (isset($service_type_fees[$id]))
|
||||||
|
return $service_type_fees[$id];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,13 +8,8 @@ class ServiceType implements InvoiceInterface
|
||||||
{
|
{
|
||||||
public function check($settings, $criteria)
|
public function check($settings, $criteria)
|
||||||
{
|
{
|
||||||
// compare specified type ids with service type of criteria
|
if (isset($settings['service_type']))
|
||||||
$stypes = $settings['type_id'];
|
return true;
|
||||||
foreach ($stypes as $type_id)
|
|
||||||
{
|
|
||||||
if ($type_id == $criteria->getServiceType())
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -23,4 +18,14 @@ class ServiceType implements InvoiceInterface
|
||||||
{
|
{
|
||||||
return 'invoice/service_type.html.twig';
|
return 'invoice/service_type.html.twig';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return 'service_type';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount($battery = null, $service_type_fees, $id)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
37
src/Invoice/TireRepair.php
Normal file
37
src/Invoice/TireRepair.php
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Invoice;
|
||||||
|
|
||||||
|
use App\InvoiceInterface;
|
||||||
|
|
||||||
|
class TireRepair implements InvoiceInterface
|
||||||
|
{
|
||||||
|
public function check($settings, $criteria)
|
||||||
|
{
|
||||||
|
$type_id = $settings['service_type'];
|
||||||
|
if ($type_id == $criteria->getServiceType())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return 'tire';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount($battery = null, $service_type_fees, $id)
|
||||||
|
{
|
||||||
|
if ($battery != null)
|
||||||
|
return $battery->getSellingPrice();
|
||||||
|
|
||||||
|
if (isset($service_type_fees[$id))
|
||||||
|
return $service_type_fees[$id];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
58
src/Invoice/TradeIn.php
Normal file
58
src/Invoice/TradeIn.php
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Invoice;
|
||||||
|
|
||||||
|
use App\InvoiceInterface;
|
||||||
|
|
||||||
|
class TradeIn implements InvoiceInterface
|
||||||
|
{
|
||||||
|
public function check($settings, $criteria)
|
||||||
|
{
|
||||||
|
// compare specified type ids with trade in entry of criteria
|
||||||
|
$trade_ins = $settings['trade_ins'];
|
||||||
|
$entries = $criteria->getEntries();
|
||||||
|
|
||||||
|
foreach ($trade_ins as $type_id)
|
||||||
|
{
|
||||||
|
foreach($entries as $entry)
|
||||||
|
{
|
||||||
|
if ($type_id == $entry['trade_in'])
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplate()
|
||||||
|
{
|
||||||
|
return 'invoice/trade_in.html.twig';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return 'trade_in';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount($battery = null, $trade_in_types, $id)
|
||||||
|
{
|
||||||
|
if (isset($trade_in_types[$id]))
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Ramcar;
|
namespace App;
|
||||||
|
|
||||||
use App\Entity\Battery;
|
use App\Entity\Battery;
|
||||||
use App\Entity\Promo;
|
use App\Entity\Promo;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,91 @@ use App\Entity\Battery;
|
||||||
|
|
||||||
class InvoiceManager
|
class InvoiceManager
|
||||||
{
|
{
|
||||||
// TODO: get list of invoice rules from .env
|
protected $em;
|
||||||
// TODO: get the service type fees
|
protected $available_rules;
|
||||||
|
|
||||||
|
public function __construct(EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$this->em = $em;
|
||||||
|
|
||||||
|
$this->available_rules = $this->getAllRules();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAvailableRules()
|
||||||
|
{
|
||||||
|
// TODO: get list of invoice rules from .env
|
||||||
|
return [
|
||||||
|
new Invoice\ServiceType(),
|
||||||
|
new Invoice\BatterySales(),
|
||||||
|
new Invoice\BatteryReplacementWarranty(),
|
||||||
|
new Invoice\Jumpstart(),
|
||||||
|
new Invoice\JumstartWarranty(),
|
||||||
|
new Invoice\PostRecharged(),
|
||||||
|
new Invoice\PostReplacement(),
|
||||||
|
new Invoice\Overheat(),
|
||||||
|
new Invoice\Fuel(),
|
||||||
|
new Invoice\TireRepair(),
|
||||||
|
new Invoice\Discount(),
|
||||||
|
new Invoice\TradeIn(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// check what rules to use given the 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 = [];
|
||||||
|
foreach ($this->available_rules as $rule)
|
||||||
|
{
|
||||||
|
$is_active = $rule->check($settings, $criteria);
|
||||||
|
if ($is_active)
|
||||||
|
$active_rules[$rule->getID()] = $rule;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $active_rules;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function compute($invoice, $criteria, $active_rules)
|
||||||
|
{
|
||||||
|
// get what is in criteria
|
||||||
|
$stype = $criteria->getServiceType();
|
||||||
|
$discount = $criteria->getDiscount();
|
||||||
|
$entries = $criteria->getEntries();
|
||||||
|
|
||||||
|
// TODO: need to find out how to call the correct rule
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue