resq/src/InvoiceRule/IsSubscription.php
2024-10-26 08:28:17 +08:00

69 lines
1.5 KiB
PHP

<?php
namespace App\InvoiceRule;
use Doctrine\ORM\EntityManagerInterface;
use App\InvoiceRuleInterface;
use App\Ramcar\ServiceType;
class IsSubscription implements InvoiceRuleInterface
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function getID()
{
return 'discount';
}
public function compute($criteria, &$total)
{
$items = [];
// set the discount to the total selling price
$discount = $total['sell_price'];
$qty = 1;
$price = bcmul(-1, $discount, 2);
$items[] = [
'title' => $this->getTitle(),
'qty' => $qty,
'price' => $price,
];
$total['discount'] = $discount;
$total['total_price'] = bcsub($total['total_price'], $discount, 2);
return $items;
}
public function validatePromo($criteria, $promo_id)
{
// only applies to battery sales
if ($criteria->getServiceType() != ServiceType::BATTERY_REPLACEMENT_NEW)
return null;
// only applies if this is a subscription order
if ($criteria->isSubscription() === false)
return null;
return false;
}
public function validateInvoiceItems($criteria, $invoice_items)
{
return null;
}
protected function getTitle()
{
$title = 'Waived for subscription';
return $title;
}
}