Add discount support to invoice generation
This commit is contained in:
parent
1125eba1bc
commit
f79aa12fbc
1 changed files with 25 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ namespace App\Service;
|
|||
|
||||
use App\Ramcar\InvoiceCriteria;
|
||||
use App\Ramcar\TradeInType;
|
||||
use App\Ramcar\DiscountApply;
|
||||
|
||||
use App\Entity\Invoice;
|
||||
use App\Entity\InvoiceItem;
|
||||
|
|
@ -126,6 +127,28 @@ class InvoiceCreator
|
|||
|
||||
protected function processDiscount(&$total, InvoiceCriteria $criteria, Invoice $invoice)
|
||||
{
|
||||
$promos = $criteria->getPromos();
|
||||
if (count($promos) < 1)
|
||||
return;
|
||||
|
||||
// NOTE: only get first promo because only one is applicable anyway
|
||||
$promo = $promos[0];
|
||||
|
||||
$rate = $promo->getDiscountRate();
|
||||
$apply_to = $promo->getDiscountApply();
|
||||
|
||||
switch ($apply_to)
|
||||
{
|
||||
case DiscountApply::SRP:
|
||||
$discount = round($total['sell_price'] * $rate, 2);
|
||||
break;
|
||||
case DiscountApply::OPL:
|
||||
$discount = round($total['sell_price'] * 0.6 / 0.7 * $rate, 2);
|
||||
break;
|
||||
}
|
||||
|
||||
$total['discount'] = $discount;
|
||||
$total['total_price'] -= $discount;
|
||||
}
|
||||
|
||||
public function processCriteria(InvoiceCriteria $criteria)
|
||||
|
|
@ -138,6 +161,7 @@ class InvoiceCreator
|
|||
'vat_ex_price' => 0.0,
|
||||
'ti_rate' => 0.0,
|
||||
'total_price' => 0.0,
|
||||
'discount' => 0.0,
|
||||
];
|
||||
|
||||
$this->processBatteries($total, $criteria, $invoice);
|
||||
|
|
@ -151,6 +175,7 @@ class InvoiceCreator
|
|||
$invoice->setTotalPrice($total['total_price'])
|
||||
->setVATExclusivePrice($total['vat_ex_price'])
|
||||
->setVAT($total['vat'])
|
||||
->setDiscount($total['discount'])
|
||||
->setTradeIn($total['ti_rate']);
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue