Fix issues found during testing. #782
This commit is contained in:
parent
57fd7fe5ac
commit
c136b0666b
4 changed files with 62 additions and 10 deletions
|
|
@ -9,14 +9,19 @@ use App\InvoiceRuleInterface;
|
||||||
use App\Ramcar\ServiceType;
|
use App\Ramcar\ServiceType;
|
||||||
|
|
||||||
use App\Entity\ServiceOffering;
|
use App\Entity\ServiceOffering;
|
||||||
|
use App\Entity\ItemType;
|
||||||
|
|
||||||
|
use App\Service\PriceTierManager;
|
||||||
|
|
||||||
class Tax implements InvoiceRuleInterface
|
class Tax implements InvoiceRuleInterface
|
||||||
{
|
{
|
||||||
protected $em;
|
protected $em;
|
||||||
|
protected $pt_manager;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em)
|
public function __construct(EntityManagerInterface $em, PriceTierManager $pt_manager)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
|
$this->pt_manager = $pt_manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getID()
|
public function getID()
|
||||||
|
|
@ -40,6 +45,7 @@ class Tax implements InvoiceRuleInterface
|
||||||
|
|
||||||
// compute tax per item if service type is battery sales
|
// compute tax per item if service type is battery sales
|
||||||
$stype = $criteria->getServiceType();
|
$stype = $criteria->getServiceType();
|
||||||
|
$pt = $criteria->getPriceTier();
|
||||||
|
|
||||||
if ($stype == ServiceType::BATTERY_REPLACEMENT_NEW)
|
if ($stype == ServiceType::BATTERY_REPLACEMENT_NEW)
|
||||||
{
|
{
|
||||||
|
|
@ -58,7 +64,13 @@ class Tax implements InvoiceRuleInterface
|
||||||
$battery = $entry['battery'];
|
$battery = $entry['battery'];
|
||||||
$qty = $entry['qty'];
|
$qty = $entry['qty'];
|
||||||
|
|
||||||
|
// check if price tier has item price for battery
|
||||||
|
$pt_price = $this->getPriceTierItemPrice($pt, $battery);
|
||||||
|
|
||||||
|
if ($pt_price == null)
|
||||||
$price = $battery->getSellingPrice();
|
$price = $battery->getSellingPrice();
|
||||||
|
else
|
||||||
|
$price = $pt_price;
|
||||||
|
|
||||||
$vat = $this->getTaxAmount($price, $tax_rate);
|
$vat = $this->getTaxAmount($price, $tax_rate);
|
||||||
|
|
||||||
|
|
@ -96,6 +108,25 @@ class Tax implements InvoiceRuleInterface
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getPriceTierItemPrice($pt_id, $batt)
|
||||||
|
{
|
||||||
|
// price tier is default
|
||||||
|
if ($pt_id == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// find the item type battery
|
||||||
|
$item_type = $this->em->getRepository(ItemType::class)->findOneBy(['code' => 'battery']);
|
||||||
|
if ($item_type == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
$item_type_id = $item_type->getID();
|
||||||
|
$item_id = $batt->getID();
|
||||||
|
|
||||||
|
$price = $this->pt_manager->getItemPrice($pt_id, $item_type_id, $item_id);
|
||||||
|
|
||||||
|
return $price;
|
||||||
|
}
|
||||||
|
|
||||||
protected function getTaxAmount($price, $tax_rate)
|
protected function getTaxAmount($price, $tax_rate)
|
||||||
{
|
{
|
||||||
$vat_ex_price = $this->getTaxExclusivePrice($price, $tax_rate);
|
$vat_ex_price = $this->getTaxExclusivePrice($price, $tax_rate);
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ class InvoiceManager implements InvoiceGeneratorInterface
|
||||||
new InvoiceRule\TireRepair($this->em, $this->pt_manager),
|
new InvoiceRule\TireRepair($this->em, $this->pt_manager),
|
||||||
new InvoiceRule\DiscountType($this->em),
|
new InvoiceRule\DiscountType($this->em),
|
||||||
new InvoiceRule\TradeIn(),
|
new InvoiceRule\TradeIn(),
|
||||||
new InvoiceRule\Tax($this->em),
|
new InvoiceRule\Tax($this->em, $this->pt_manager),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -588,7 +588,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
{
|
{
|
||||||
$source = $jo->getSource();
|
$source = $jo->getSource();
|
||||||
|
|
||||||
// TODO: set the price tier according to location.
|
// get the price tier according to location.
|
||||||
$price_tier = $this->pt_manager->getPriceTier($jo->getCoordinates());
|
$price_tier = $this->pt_manager->getPriceTier($jo->getCoordinates());
|
||||||
$this->ic->generateInvoiceCriteria($jo, $promo_id, $invoice_items, $source, $price_tier, $error_array);
|
$this->ic->generateInvoiceCriteria($jo, $promo_id, $invoice_items, $source, $price_tier, $error_array);
|
||||||
}
|
}
|
||||||
|
|
@ -822,7 +822,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
{
|
{
|
||||||
$source = $obj->getSource();
|
$source = $obj->getSource();
|
||||||
|
|
||||||
$this->ic->generateInvoiceCriteria($obj, $promo_id, $invoice_items, $source, $error_array);
|
// get the price tier according to location.
|
||||||
|
$price_tier = $this->pt_manager->getPriceTier($obj->getCoordinates());
|
||||||
|
$this->ic->generateInvoiceCriteria($obj, $promo_id, $invoice_items, $source, $price_tier, $error_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
|
|
@ -2170,7 +2172,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
// NOTE: this is CMB code but for compilation purposes we need to add this
|
// NOTE: this is CMB code but for compilation purposes we need to add this
|
||||||
$source = $jo->getSource();
|
$source = $jo->getSource();
|
||||||
|
|
||||||
$this->ic->generateInvoiceCriteria($jo, $promo_id, $invoice_items, $source, $error_array);
|
// get the price tier according to location.
|
||||||
|
$price_tier = $this->pt_manager->getPriceTier($jo->getCoordinates());
|
||||||
|
$this->ic->generateInvoiceCriteria($jo, $promo_id, $invoice_items, $source, $price_tier, $error_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
|
|
|
||||||
|
|
@ -51,10 +51,27 @@ class PriceTierManager
|
||||||
return $actual_price;
|
return $actual_price;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPriceTier(Point $point)
|
public function getPriceTier(Point $coordinates)
|
||||||
{
|
{
|
||||||
// TODO: get location's price tier, given a set of coordinates
|
$price_tier_id = 0;
|
||||||
// for now, hardcoded for testing purposes
|
|
||||||
return 1;
|
$long = $coordinates->getLongitude();
|
||||||
|
$lat = $coordinates->getLatitude();
|
||||||
|
|
||||||
|
// get location's price tier, given a set of coordinates
|
||||||
|
$query = $this->em->createQuery('SELECT s from App\Entity\SupportedArea s where st_contains(s.coverage_area, point(:long, :lat)) = true');
|
||||||
|
$area = $query->setParameter('long', $long)
|
||||||
|
->setParameter('lat', $lat)
|
||||||
|
->setMaxResults(1)
|
||||||
|
->getOneOrNullResult();
|
||||||
|
|
||||||
|
if ($area != null)
|
||||||
|
{
|
||||||
|
$price_tier = $area->getPriceTier();
|
||||||
|
if ($price_tier != null)
|
||||||
|
$price_tier_id = $price_tier->getID();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $price_tier_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue